Revert "Factors out permissions check from User into PermissionManager service"
[lhc/web/wiklou.git] / tests / phpunit / includes / RevisionDbTestBase.php
index a2f2796..7501167 100644 (file)
@@ -26,6 +26,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                        [
                                'page',
                                'revision',
+                               'comment',
                                'ip_changes',
                                'text',
                                'archive',
@@ -90,8 +91,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                $this->setMwGlobals( [
                        'wgMultiContentRevisionSchemaMigrationStage' => $this->getMcrMigrationStage(),
                        'wgContentHandlerUseDB' => $this->getContentHandlerUseDB(),
-                       'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW,
-                       'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
+                       'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW,
                ] );
 
                $this->overrideMwServices();
@@ -182,7 +182,8 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                        ( $model === null || $model === CONTENT_MODEL_WIKITEXT )
                ) {
                        $ns = $this->getDefaultWikitextNS();
-                       $titleString = MWNamespace::getCanonicalName( $ns ) . ':' . $titleString;
+                       $titleString = MediaWikiServices::getInstance()->getNamespaceInfo()->
+                               getCanonicalName( $ns ) . ':' . $titleString;
                }
 
                $title = Title::newFromText( $titleString );
@@ -572,28 +573,6 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                );
        }
 
-       /**
-        * @covers Revision::fetchRevision
-        */
-       public function testFetchRevision() {
-               // Hidden process cache assertion below
-               $this->testPage->getRevision()->getId();
-
-               $this->testPage->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
-               $id = $this->testPage->getRevision()->getId();
-
-               $this->hideDeprecated( 'Revision::fetchRevision' );
-               $res = Revision::fetchRevision( $this->testPage->getTitle() );
-
-               # note: order is unspecified
-               $rows = [];
-               while ( ( $row = $res->fetchObject() ) ) {
-                       $rows[$row->rev_id] = $row;
-               }
-
-               $this->assertEmpty( $rows, 'expected empty set' );
-       }
-
        /**
         * @covers Revision::getPage
         */
@@ -647,6 +626,34 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                $this->assertEquals( $latestRevision, $newRevision->getPrevious()->getId() );
        }
 
+       /**
+        * @covers Title::getPreviousRevisionID
+        * @covers Title::getRelativeRevisionID
+        * @covers MediaWiki\Revision\RevisionStore::getPreviousRevision
+        * @covers MediaWiki\Revision\RevisionStore::getRelativeRevision
+        */
+       public function testTitleGetPreviousRevisionID() {
+               $oldestId = $this->testPage->getOldestRevision()->getId();
+               $latestId = $this->testPage->getLatest();
+
+               $title = $this->testPage->getTitle();
+
+               $this->assertFalse( $title->getPreviousRevisionID( $oldestId ) );
+
+               $this->testPage->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
+               $newId = $this->testPage->getRevision()->getId();
+
+               $this->assertEquals( $latestId, $title->getPreviousRevisionID( $newId ) );
+       }
+
+       /**
+        * @covers Title::getPreviousRevisionID
+        * @covers Title::getRelativeRevisionID
+        */
+       public function testTitleGetPreviousRevisionID_invalid() {
+               $this->assertFalse( $this->testPage->getTitle()->getPreviousRevisionID( 123456789 ) );
+       }
+
        /**
         * @covers Revision::getNext
         */
@@ -662,6 +669,33 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                $this->assertEquals( $rev2->getId(), $rev1->getNext()->getId() );
        }
 
+       /**
+        * @covers Title::getNextRevisionID
+        * @covers Title::getRelativeRevisionID
+        * @covers MediaWiki\Revision\RevisionStore::getNextRevision
+        * @covers MediaWiki\Revision\RevisionStore::getRelativeRevision
+        */
+       public function testTitleGetNextRevisionID() {
+               $title = $this->testPage->getTitle();
+
+               $origId = $this->testPage->getLatest();
+
+               $this->assertFalse( $title->getNextRevisionID( $origId ) );
+
+               $this->testPage->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
+               $newId = $this->testPage->getLatest();
+
+               $this->assertSame( $this->testPage->getLatest(), $title->getNextRevisionID( $origId ) );
+       }
+
+       /**
+        * @covers Title::getNextRevisionID
+        * @covers Title::getRelativeRevisionID
+        */
+       public function testTitleGetNextRevisionID_invalid() {
+               $this->assertFalse( $this->testPage->getTitle()->getNextRevisionID( 123456789 ) );
+       }
+
        /**
         * @covers Revision::newNullRevision
         */
@@ -680,7 +714,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                        'new null revision should have the same SHA1 as the original revision' );
                $this->assertTrue( $orig->getRevisionRecord()->hasSameContent( $rev->getRevisionRecord() ),
                        'new null revision should have the same content as the original revision' );
-               $this->assertEquals( __METHOD__, $rev->getContent()->getNativeData() );
+               $this->assertEquals( __METHOD__, $rev->getContent()->getText() );
        }
 
        /**
@@ -1402,7 +1436,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                );
                $rev = $this->testPage->getRevision();
 
-               $this->assertSame( $expectedText, $rev->getContent()->getNativeData() );
+               $this->assertSame( $expectedText, $rev->getContent()->getText() );
                $this->assertSame( $expectedText, $rev->getSerializedData() );
                $this->assertSame( $this->testPage->getContentModel(), $rev->getContentModel() );
                $this->assertSame( $this->testPage->getContent()->getDefaultFormat(), $rev->getContentFormat() );
@@ -1419,6 +1453,9 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                $this->setService( 'MainWANObjectCache', $cache );
                $db = wfGetDB( DB_MASTER );
 
+               $now = 1553893742;
+               $cache->setMockTime( $now );
+
                // Get a fresh revision to use during testing
                $this->testPage->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
                $rev = $this->testPage->getRevision();
@@ -1433,6 +1470,8 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                $cache->delete( $key, WANObjectCache::HOLDOFF_NONE );
                $this->assertFalse( $cache->get( $key ) );
 
+               ++$now;
+
                // Get the new revision and make sure it is in the cache and correct
                $newRev = Revision::newKnownCurrent( $db, $rev->getPage(), $rev->getId() );
                $this->assertRevEquals( $rev, $newRev );
@@ -1602,11 +1641,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                $this->assertSame( $expected, $rev->getTextId() );
        }
 
-       public function provideGetRevisionText() {
-               yield [
-                       [ 'text' ]
-               ];
-       }
+       abstract public function provideGetRevisionText();
 
        /**
         * @dataProvider provideGetRevisionText