Add test for Revision::insertOn
authoraddshore <addshorewiki@gmail.com>
Thu, 26 Oct 2017 12:03:43 +0000 (13:03 +0100)
committeraddshore <addshorewiki@gmail.com>
Thu, 26 Oct 2017 12:09:09 +0000 (13:09 +0100)
The success test indicates a change in behaviour
of the insertOn method once
I4f24e7fbb683cb51f3fd8b250732bae9c7541ba2
is applied.

Change-Id: I987d64c5bc3788b7d6b0a858ff39e97fae38de3c

tests/phpunit/includes/RevisionIntegrationTest.php

index 9dcd0cf..10186ed 100644 (file)
@@ -151,6 +151,78 @@ class RevisionIntegrationTest extends MediaWikiTestCase {
                $this->assertEquals( $orig->getSha1(), $rev->getSha1() );
        }
 
+       /**
+        * @covers Revision::insertOn
+        */
+       public function testInsertOn_success() {
+               $parentId = $this->testPage->getLatest();
+
+               // If an ExternalStore is set don't use it.
+               $this->setMwGlobals( 'wgDefaultExternalStore', false );
+
+               $rev = new Revision( [
+                       'page' => $this->testPage->getId(),
+                       'title' => $this->testPage->getTitle(),
+                       'text' => 'Revision Text',
+                       'comment' => 'Revision comment',
+               ] );
+
+               $revId = $rev->insertOn( wfGetDB( DB_MASTER ) );
+
+               $this->assertInternalType( 'integer', $revId );
+               $this->assertInternalType( 'integer', $rev->getTextId() );
+               $this->assertSame( $revId, $rev->getId() );
+
+               $this->assertSelect(
+                       'text',
+                       [ 'old_id', 'old_text' ],
+                       "old_id = {$rev->getTextId()}",
+                       [ [ strval( $rev->getTextId() ), 'Revision Text' ] ]
+               );
+               $this->assertSelect(
+                       'revision',
+                       [
+                               'rev_id',
+                               'rev_page',
+                               'rev_text_id',
+                               'rev_user',
+                               'rev_minor_edit',
+                               'rev_deleted',
+                               'rev_len',
+                               'rev_parent_id',
+                               'rev_sha1',
+                       ],
+                       "rev_id = {$rev->getId()}",
+                       [ [
+                               strval( $rev->getId() ),
+                               strval( $this->testPage->getId() ),
+                               strval( $rev->getTextId() ),
+                               '0',
+                               '0',
+                               '0',
+                               '13',
+                               strval( $parentId ),
+                               's0ngbdoxagreuf2vjtuxzwdz64n29xm',
+                       ] ]
+               );
+       }
+
+       /**
+        * @covers Revision::insertOn
+        */
+       public function testInsertOn_exceptionOnNoPage() {
+               // If an ExternalStore is set don't use it.
+               $this->setMwGlobals( 'wgDefaultExternalStore', false );
+               $this->setExpectedException(
+                       MWException::class,
+                       "Cannot insert revision: page ID must be nonzero"
+               );
+
+               $rev = new Revision( [] );
+
+               $rev->insertOn( wfGetDB( DB_MASTER ) );
+       }
+
        /**
         * @covers Revision::newFromTitle
         */