RevisionIntegrationTest for loadFromId & loadFromPageId
[lhc/web/wiklou.git] / tests / phpunit / includes / RevisionIntegrationTest.php
index 5d96abf..7713329 100644 (file)
@@ -225,10 +225,18 @@ class RevisionIntegrationTest extends MediaWikiTestCase {
                $this->assertRevEquals( $orig, $rev );
        }
 
+       public function provideTrueFalse() {
+               yield [ true ];
+               yield [ false ];
+       }
+
        /**
+        * @dataProvider provideTrueFalse
         * @covers Revision::newFromArchiveRow
         */
-       public function testNewFromArchiveRow() {
+       public function testNewFromArchiveRow( $contentHandlerUseDB ) {
+               $this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB );
+
                $page = $this->createPage(
                        'RevisionStorageTest_testNewFromArchiveRow',
                        'Lorem Ipsum',
@@ -260,6 +268,46 @@ class RevisionIntegrationTest extends MediaWikiTestCase {
                $this->assertRevEquals( $orig, $rev );
        }
 
+       /**
+        * @covers Revision::newFromPageId
+        */
+       public function testNewFromPageId() {
+               $rev = Revision::newFromPageId( $this->testPage->getId() );
+               $this->assertRevEquals(
+                       $this->testPage->getRevision(),
+                       $rev
+               );
+       }
+
+       /**
+        * @covers Revision::newFromPageId
+        */
+       public function testNewFromPageIdWithLatestId() {
+               $rev = Revision::newFromPageId(
+                       $this->testPage->getId(),
+                       $this->testPage->getLatest()
+               );
+               $this->assertRevEquals(
+                       $this->testPage->getRevision(),
+                       $rev
+               );
+       }
+
+       /**
+        * @covers Revision::newFromPageId
+        */
+       public function testNewFromPageIdWithNotLatestId() {
+               $this->testPage->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
+               $rev = Revision::newFromPageId(
+                       $this->testPage->getId(),
+                       $this->testPage->getRevision()->getPrevious()->getId()
+               );
+               $this->assertRevEquals(
+                       $this->testPage->getRevision()->getPrevious(),
+                       $rev
+               );
+       }
+
        /**
         * @covers Revision::fetchRevision
         */
@@ -743,4 +791,54 @@ class RevisionIntegrationTest extends MediaWikiTestCase {
                $this->assertSame( $content, $content2 );
        }
 
+       /**
+        * @covers Revision::loadFromId
+        */
+       public function testLoadFromId() {
+               $rev = $this->testPage->getRevision();
+               $this->assertRevEquals(
+                       $rev,
+                       Revision::loadFromId( wfGetDB( DB_MASTER ), $rev->getId() )
+               );
+       }
+
+       /**
+        * @covers Revision::loadFromPageId
+        */
+       public function testLoadFromPageId() {
+               $this->assertRevEquals(
+                       $this->testPage->getRevision(),
+                       Revision::loadFromPageId( wfGetDB( DB_MASTER ), $this->testPage->getId() )
+               );
+       }
+
+       /**
+        * @covers Revision::loadFromPageId
+        */
+       public function testLoadFromPageIdWithLatestRevId() {
+               $this->assertRevEquals(
+                       $this->testPage->getRevision(),
+                       Revision::loadFromPageId(
+                               wfGetDB( DB_MASTER ),
+                               $this->testPage->getId(),
+                               $this->testPage->getLatest()
+                       )
+               );
+       }
+
+       /**
+        * @covers Revision::loadFromPageId
+        */
+       public function testLoadFromPageIdWithNotLatestRevId() {
+               $this->testPage->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
+               $this->assertRevEquals(
+                       $this->testPage->getRevision()->getPrevious(),
+                       Revision::loadFromPageId(
+                               wfGetDB( DB_MASTER ),
+                               $this->testPage->getId(),
+                               $this->testPage->getRevision()->getPrevious()->getId()
+                       )
+               );
+       }
+
 }