RevisionTest: Use utf-8 as name in iconv
[lhc/web/wiklou.git] / tests / phpunit / includes / RevisionTest.php
index 80a690f..361984b 100644 (file)
 <?php
 
+use Wikimedia\TestingAccessWrapper;
+
 /**
- * @group ContentHandler
+ * Test cases in RevisionTest should not interact with the Database.
+ * For test cases that need Database interaction see RevisionDbTestBase.
  */
 class RevisionTest extends MediaWikiTestCase {
 
-       protected function setUp() {
-               global $wgContLang;
-
-               parent::setUp();
-
-               $this->setMwGlobals( [
-                       'wgContLang' => Language::factory( 'en' ),
-                       'wgLanguageCode' => 'en',
-                       'wgLegacyEncoding' => false,
-                       'wgCompressRevisions' => false,
+       public function provideConstructFromArray() {
+               yield 'with text' => [
+                       [
+                               'text' => 'hello world.',
+                               'content_model' => CONTENT_MODEL_JAVASCRIPT
+                       ],
+               ];
+               yield 'with content' => [
+                       [
+                               'content' => new JavaScriptContent( 'hellow world.' )
+                       ],
+               ];
+       }
 
-                       'wgContentHandlerTextFallback' => 'ignore',
-               ] );
+       /**
+        * @dataProvider provideConstructFromArray
+        * @covers Revision::__construct
+        * @covers Revision::constructFromRowArray
+        */
+       public function testConstructFromArray( array $rowArray ) {
+               $rev = new Revision( $rowArray );
+               $this->assertNotNull( $rev->getContent(), 'no content object available' );
+               $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContent()->getModel() );
+               $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() );
+       }
 
-               $this->mergeMwGlobalArrayValue(
-                       'wgExtraNamespaces',
+       public function provideConstructFromArray_userSetAsExpected() {
+               yield 'no user defaults to wgUser' => [
                        [
-                               12312 => 'Dummy',
-                               12313 => 'Dummy_talk',
-                       ]
-               );
-
-               $this->mergeMwGlobalArrayValue(
-                       'wgNamespaceContentModels',
+                               'content' => new JavaScriptContent( 'hello world.' ),
+                       ],
+                       null,
+                       null,
+               ];
+               yield 'user text and id' => [
                        [
-                               12312 => 'testing',
-                       ]
-               );
+                               'content' => new JavaScriptContent( 'hello world.' ),
+                               'user_text' => 'SomeTextUserName',
+                               'user' => 99,
 
-               $this->mergeMwGlobalArrayValue(
-                       'wgContentHandlers',
+                       ],
+                       99,
+                       'SomeTextUserName',
+               ];
+               // Note: the below XXX test cases are odd and probably result in unexpected behaviour if used
+               // in production code.
+               yield 'XXX: user text only' => [
                        [
-                               'testing' => 'DummyContentHandlerForTesting',
-                               'RevisionTestModifyableContent' => 'RevisionTestModifyableContentHandler',
-                       ]
-               );
-
-               MWNamespace::clearCaches();
-               // Reset namespace cache
-               $wgContLang->resetNamespaces();
+                               'content' => new JavaScriptContent( 'hello world.' ),
+                               'user_text' => '111.111.111.111',
+                       ],
+                       null,
+                       '111.111.111.111',
+               ];
+               yield 'XXX: user id only' => [
+                       [
+                               'content' => new JavaScriptContent( 'hello world.' ),
+                               'user' => 9989,
+                       ],
+                       9989,
+                       null,
+               ];
        }
 
-       protected function tearDown() {
-               global $wgContLang;
+       /**
+        * @dataProvider provideConstructFromArray_userSetAsExpected
+        * @covers Revision::__construct
+        * @covers Revision::constructFromRowArray
+        *
+        * @param array $rowArray
+        * @param mixed $expectedUserId null to expect the current wgUser ID
+        * @param mixed $expectedUserName null to expect the current wgUser name
+        */
+       public function testConstructFromArray_userSetAsExpected(
+               array $rowArray,
+               $expectedUserId,
+               $expectedUserName
+       ) {
+               $testUser = $this->getTestUser()->getUser();
+               $this->setMwGlobals( 'wgUser', $testUser );
+               if ( $expectedUserId === null ) {
+                       $expectedUserId = $testUser->getId();
+               }
+               if ( $expectedUserName === null ) {
+                       $expectedUserName = $testUser->getName();
+               }
+
+               $rev = new Revision( $rowArray );
+               $this->assertEquals( $expectedUserId, $rev->getUser() );
+               $this->assertEquals( $expectedUserName, $rev->getUserText() );
+       }
 
-               MWNamespace::clearCaches();
-               // Reset namespace cache
-               $wgContLang->resetNamespaces();
+       public function provideConstructFromArrayThrowsExceptions() {
+               yield 'content and text_id both not empty' => [
+                       [
+                               'content' => new WikitextContent( 'GOAT' ),
+                               'text_id' => 'someid',
+                               ],
+                       new MWException( "Text already stored in external store (id someid), " .
+                               "can't serialize content object" )
+               ];
+               yield 'with bad content object (class)' => [
+                       [ 'content' => new stdClass() ],
+                       new MWException( '`content` field must contain a Content object.' )
+               ];
+               yield 'with bad content object (string)' => [
+                       [ 'content' => 'ImAGoat' ],
+                       new MWException( '`content` field must contain a Content object.' )
+               ];
+               yield 'bad row format' => [
+                       'imastring, not a row',
+                       new MWException( 'Revision constructor passed invalid row format.' )
+               ];
+       }
 
-               parent::tearDown();
+       /**
+        * @dataProvider provideConstructFromArrayThrowsExceptions
+        * @covers Revision::__construct
+        * @covers Revision::constructFromRowArray
+        */
+       public function testConstructFromArrayThrowsExceptions( $rowArray, Exception $expectedException ) {
+               $this->setExpectedException(
+                       get_class( $expectedException ),
+                       $expectedException->getMessage(),
+                       $expectedException->getCode()
+               );
+               new Revision( $rowArray );
        }
 
-       public function provideConstruct() {
-               yield 'with text' => [
+       public function provideConstructFromRow() {
+               yield 'Full construction' => [
                        [
-                               'text' => 'hello world.',
-                               'content_model' => CONTENT_MODEL_JAVASCRIPT
+                               'rev_id' => '2',
+                               'rev_page' => '1',
+                               'rev_text_id' => '2',
+                               'rev_timestamp' => '20171017114835',
+                               'rev_user_text' => '127.0.0.1',
+                               'rev_user' => '0',
+                               'rev_minor_edit' => '0',
+                               'rev_deleted' => '0',
+                               'rev_len' => '46',
+                               'rev_parent_id' => '1',
+                               'rev_sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
+                               'rev_comment_text' => 'Goat Comment!',
+                               'rev_comment_data' => null,
+                               'rev_comment_cid' => null,
+                               'rev_content_format' => 'GOATFORMAT',
+                               'rev_content_model' => 'GOATMODEL',
                        ],
+                       function ( RevisionTest $testCase, Revision $rev ) {
+                               $testCase->assertSame( 2, $rev->getId() );
+                               $testCase->assertSame( 1, $rev->getPage() );
+                               $testCase->assertSame( 2, $rev->getTextId() );
+                               $testCase->assertSame( '20171017114835', $rev->getTimestamp() );
+                               $testCase->assertSame( '127.0.0.1', $rev->getUserText() );
+                               $testCase->assertSame( 0, $rev->getUser() );
+                               $testCase->assertSame( false, $rev->isMinor() );
+                               $testCase->assertSame( false, $rev->isDeleted( Revision::DELETED_TEXT ) );
+                               $testCase->assertSame( 46, $rev->getSize() );
+                               $testCase->assertSame( 1, $rev->getParentId() );
+                               $testCase->assertSame( 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z', $rev->getSha1() );
+                               $testCase->assertSame( 'Goat Comment!', $rev->getComment() );
+                               $testCase->assertSame( 'GOATFORMAT', $rev->getContentFormat() );
+                               $testCase->assertSame( 'GOATMODEL', $rev->getContentModel() );
+                       }
                ];
-               yield 'with content' => [
+               yield 'null fields' => [
                        [
-                               'content' => ContentHandler::makeContent(
-                                       'hello world.',
-                                       Title::newFromText( 'RevisionTest_testConstructWithContent' ),
-                                       CONTENT_MODEL_JAVASCRIPT
-                               ),
+                               'rev_id' => '2',
+                               'rev_page' => '1',
+                               'rev_text_id' => '2',
+                               'rev_timestamp' => '20171017114835',
+                               'rev_user_text' => '127.0.0.1',
+                               'rev_user' => '0',
+                               'rev_minor_edit' => '0',
+                               'rev_deleted' => '0',
+                               'rev_comment_text' => 'Goat Comment!',
+                               'rev_comment_data' => null,
+                               'rev_comment_cid' => null,
                        ],
+                       function ( RevisionTest $testCase, Revision $rev ) {
+                               $testCase->assertNull( $rev->getSize() );
+                               $testCase->assertNull( $rev->getParentId() );
+                               $testCase->assertNull( $rev->getSha1() );
+                               $testCase->assertSame( 'text/x-wiki', $rev->getContentFormat() );
+                               $testCase->assertSame( 'wikitext', $rev->getContentModel() );
+                       }
                ];
        }
 
        /**
-        * @dataProvider provideConstruct
+        * @dataProvider provideConstructFromRow
+        * @covers Revision::__construct
+        * @covers Revision::constructFromDbRowObject
         */
-       public function testConstruct( $rowArray ) {
-               $rev = new Revision( $rowArray );
-               $this->assertNotNull( $rev->getContent(), 'no content object available' );
-               $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContent()->getModel() );
-               $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() );
+       public function testConstructFromRow( array $arrayData, $assertions ) {
+               $row = (object)$arrayData;
+               $rev = new Revision( $row );
+               $assertions( $this, $rev );
        }
 
        public function provideGetRevisionText() {
@@ -95,6 +219,87 @@ class RevisionTest extends MediaWikiTestCase {
                ];
        }
 
+       public function provideGetId() {
+               yield [
+                       [],
+                       null
+               ];
+               yield [
+                       [ 'id' => 998 ],
+                       998
+               ];
+       }
+
+       /**
+        * @dataProvider provideGetId
+        * @covers Revision::getId
+        */
+       public function testGetId( $rowArray, $expectedId ) {
+               $rev = new Revision( $rowArray );
+               $this->assertEquals( $expectedId, $rev->getId() );
+       }
+
+       public function provideSetId() {
+               yield [ '123', 123 ];
+               yield [ 456, 456 ];
+       }
+
+       /**
+        * @dataProvider provideSetId
+        * @covers Revision::setId
+        */
+       public function testSetId( $input, $expected ) {
+               $rev = new Revision( [] );
+               $rev->setId( $input );
+               $this->assertSame( $expected, $rev->getId() );
+       }
+
+       public function provideSetUserIdAndName() {
+               yield [ '123', 123, 'GOaT' ];
+               yield [ 456, 456, 'GOaT' ];
+       }
+
+       /**
+        * @dataProvider provideSetUserIdAndName
+        * @covers Revision::setUserIdAndName
+        */
+       public function testSetUserIdAndName( $inputId, $expectedId, $name ) {
+               $rev = new Revision( [] );
+               $rev->setUserIdAndName( $inputId, $name );
+               $this->assertSame( $expectedId, $rev->getUser( Revision::RAW ) );
+               $this->assertEquals( $name, $rev->getUserText( Revision::RAW ) );
+       }
+
+       public function provideGetTextId() {
+               yield [ [], null ];
+               yield [ [ 'text_id' => '123' ], 123 ];
+               yield [ [ 'text_id' => 456 ], 456 ];
+       }
+
+       /**
+        * @dataProvider provideGetTextId
+        * @covers Revision::getTextId()
+        */
+       public function testGetTextId( $rowArray, $expected ) {
+               $rev = new Revision( $rowArray );
+               $this->assertSame( $expected, $rev->getTextId() );
+       }
+
+       public function provideGetParentId() {
+               yield [ [], null ];
+               yield [ [ 'parent_id' => '123' ], 123 ];
+               yield [ [ 'parent_id' => 456 ], 456 ];
+       }
+
+       /**
+        * @dataProvider provideGetParentId
+        * @covers Revision::getParentId()
+        */
+       public function testGetParentId( $rowArray, $expected ) {
+               $rev = new Revision( $rowArray );
+               $this->assertSame( $expected, $rev->getParentId() );
+       }
+
        /**
         * @covers Revision::getRevisionText
         * @dataProvider provideGetRevisionText
@@ -148,11 +353,16 @@ class RevisionTest extends MediaWikiTestCase {
         * @dataProvider provideGetRevisionTextWithLegacyEncoding
         */
        public function testGetRevisionWithLegacyEncoding( $expected, $encoding, $rowData ) {
-               $GLOBALS['wgLegacyEncoding'] = $encoding;
+               $this->setMwGlobals( 'wgLegacyEncoding', $encoding );
                $this->testGetRevisionText( $expected, $rowData );
        }
 
        public function provideGetRevisionTextWithGzipAndLegacyEncoding() {
+               /**
+                * WARNING!
+                * Do not set the external flag!
+                * Otherwise, getRevisionText will hit the live database (if ExternalStore is enabled)!
+                */
                yield 'Utf8NativeGzip' => [
                        "Wiki est l'\xc3\xa9cole superieur !",
                        'iso-8859-1',
@@ -177,7 +387,7 @@ class RevisionTest extends MediaWikiTestCase {
         */
        public function testGetRevisionWithGzipAndLegacyEncoding( $expected, $encoding, $rowData ) {
                $this->checkPHPExtension( 'zlib' );
-               $GLOBALS['wgLegacyEncoding'] = $encoding;
+               $this->setMwGlobals( 'wgLegacyEncoding', $encoding );
                $this->testGetRevisionText( $expected, $rowData );
        }
 
@@ -218,230 +428,933 @@ class RevisionTest extends MediaWikiTestCase {
                        Revision::getRevisionText( $row ), "getRevisionText" );
        }
 
+       public function provideFetchFromConds() {
+               yield [ 0, [] ];
+               yield [ Revision::READ_LOCKING, [ 'FOR UPDATE' ] ];
+       }
+
        /**
-        * @param string $text
-        * @param string $title
-        * @param string $model
-        * @param string $format
-        *
-        * @return Revision
+        * @dataProvider provideFetchFromConds
+        * @covers Revision::fetchFromConds
         */
-       private function newTestRevision( $text, $title = "Test",
-               $model = CONTENT_MODEL_WIKITEXT, $format = null
-       ) {
-               if ( is_string( $title ) ) {
-                       $title = Title::newFromText( $title );
-               }
+       public function testFetchFromConds( $flags, array $options ) {
+               $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD );
+               $conditions = [ 'conditionsArray' ];
 
-               $content = ContentHandler::makeContent( $text, $title, $model, $format );
+               $db = $this->getMock( IDatabase::class );
+               $db->expects( $this->once() )
+                       ->method( 'selectRow' )
+                       ->with(
+                               $this->equalTo( [ 'revision', 'page', 'user' ] ),
+                               // We don't really care about the fields are they come from the selectField methods
+                               $this->isType( 'array' ),
+                               $this->equalTo( $conditions ),
+                               // Method name
+                               $this->equalTo( 'Revision::fetchFromConds' ),
+                               $this->equalTo( $options ),
+                               // We don't really care about the join conds are they come from the joinCond methods
+                               $this->isType( 'array' )
+                       )
+                       ->willReturn( 'RETURNVALUE' );
 
-               $rev = new Revision(
-                       [
-                               'id' => 42,
-                               'page' => 23,
-                               'title' => $title,
+               $wrapper = TestingAccessWrapper::newFromClass( Revision::class );
+               $result = $wrapper->fetchFromConds( $db, $conditions, $flags );
 
-                               'content' => $content,
-                               'length' => $content->getSize(),
-                               'comment' => "testing",
-                               'minor_edit' => false,
-
-                               'content_format' => $format,
-                       ]
-               );
-
-               return $rev;
+               $this->assertEquals( 'RETURNVALUE', $result );
        }
 
-       public function provideGetContentModel() {
-               // NOTE: we expect the help namespace to always contain wikitext
-               return [
-                       [ 'hello world', 'Help:Hello', null, null, CONTENT_MODEL_WIKITEXT ],
-                       [ 'hello world', 'User:hello/there.css', null, null, CONTENT_MODEL_CSS ],
-                       [ serialize( 'hello world' ), 'Dummy:Hello', null, null, "testing" ],
+       public function provideDecompressRevisionText() {
+               yield '(no legacy encoding), false in false out' => [ false, false, [], false ];
+               yield '(no legacy encoding), empty in empty out' => [ false, '', [], '' ];
+               yield '(no legacy encoding), empty in empty out' => [ false, 'A', [], 'A' ];
+               yield '(no legacy encoding), string in with gzip flag returns string' => [
+                       // gzip string below generated with gzdeflate( 'AAAABBAAA' )
+                       false, "sttttr\002\022\000", [ 'gzip' ], 'AAAABBAAA',
+               ];
+               yield '(no legacy encoding), string in with object flag returns false' => [
+                       // gzip string below generated with serialize( 'JOJO' )
+                       false, "s:4:\"JOJO\";", [ 'object' ], false,
+               ];
+               yield '(no legacy encoding), serialized object in with object flag returns string' => [
+                       false,
+                       // Using a TitleValue object as it has a getText method (which is needed)
+                       serialize( new TitleValue( 0, 'HHJJDDFF' ) ),
+                       [ 'object' ],
+                       'HHJJDDFF',
+               ];
+               yield '(no legacy encoding), serialized object in with object & gzip flag returns string' => [
+                       false,
+                       // Using a TitleValue object as it has a getText method (which is needed)
+                       gzdeflate( serialize( new TitleValue( 0, '8219JJJ840' ) ) ),
+                       [ 'object', 'gzip' ],
+                       '8219JJJ840',
+               ];
+               yield '(ISO-8859-1 encoding), string in string out' => [
+                       'ISO-8859-1',
+                       iconv( 'utf-8', 'ISO-8859-1', "1®Àþ1" ),
+                       [],
+                       '1®Àþ1',
+               ];
+               yield '(ISO-8859-1 encoding), serialized object in with gzip flags returns string' => [
+                       'ISO-8859-1',
+                       gzdeflate( iconv( 'utf-8', 'ISO-8859-1', "4®Àþ4" ) ),
+                       [ 'gzip' ],
+                       '4®Àþ4',
+               ];
+               yield '(ISO-8859-1 encoding), serialized object in with object flags returns string' => [
+                       'ISO-8859-1',
+                       serialize( new TitleValue( 0, iconv( 'utf-8', 'ISO-8859-1', "3®Àþ3" ) ) ),
+                       [ 'object' ],
+                       '3®Àþ3',
+               ];
+               yield '(ISO-8859-1 encoding), serialized object in with object & gzip flags returns string' => [
+                       'ISO-8859-1',
+                       gzdeflate( serialize( new TitleValue( 0, iconv( 'utf-8', 'ISO-8859-1', "2®Àþ2" ) ) ) ),
+                       [ 'gzip', 'object' ],
+                       '2®Àþ2',
                ];
        }
 
        /**
-        * @group Database
-        * @dataProvider provideGetContentModel
-        * @covers Revision::getContentModel
+        * @dataProvider provideDecompressRevisionText
+        * @covers Revision::decompressRevisionText
+        *
+        * @param bool $legacyEncoding
+        * @param mixed $text
+        * @param array $flags
+        * @param mixed $expected
         */
-       public function testGetContentModel( $text, $title, $model, $format, $expectedModel ) {
-               $rev = $this->newTestRevision( $text, $title, $model, $format );
+       public function testDecompressRevisionText( $legacyEncoding, $text, $flags, $expected ) {
+               $this->setMwGlobals( 'wgLegacyEncoding', $legacyEncoding );
+               $this->setMwGlobals( 'wgLanguageCode', 'en' );
+               $this->assertSame(
+                       $expected,
+                       Revision::decompressRevisionText( $text, $flags )
+               );
+       }
 
-               $this->assertEquals( $expectedModel, $rev->getContentModel() );
+       /**
+        * @covers Revision::getRevisionText
+        */
+       public function testGetRevisionText_returnsFalseWhenNoTextField() {
+               $this->assertFalse( Revision::getRevisionText( new stdClass() ) );
        }
 
-       public function provideGetContentFormat() {
-               // NOTE: we expect the help namespace to always contain wikitext
-               return [
-                       [ 'hello world', 'Help:Hello', null, null, CONTENT_FORMAT_WIKITEXT ],
-                       [ 'hello world', 'Help:Hello', CONTENT_MODEL_CSS, null, CONTENT_FORMAT_CSS ],
-                       [ 'hello world', 'User:hello/there.css', null, null, CONTENT_FORMAT_CSS ],
-                       [ serialize( 'hello world' ), 'Dummy:Hello', null, null, "testing" ],
+       public function provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal() {
+               yield 'Just text' => [
+                       (object)[ 'old_text' => 'SomeText' ],
+                       'old_',
+                       'SomeText'
+               ];
+               // gzip string below generated with gzdeflate( 'AAAABBAAA' )
+               yield 'gzip text' => [
+                       (object)[
+                               'old_text' => "sttttr\002\022\000",
+                               'old_flags' => 'gzip'
+                       ],
+                       'old_',
+                       'AAAABBAAA'
+               ];
+               yield 'gzip text and different prefix' => [
+                       (object)[
+                               'jojo_text' => "sttttr\002\022\000",
+                               'jojo_flags' => 'gzip'
+                       ],
+                       'jojo_',
+                       'AAAABBAAA'
                ];
        }
 
        /**
-        * @group Database
-        * @dataProvider provideGetContentFormat
-        * @covers Revision::getContentFormat
+        * @dataProvider provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal
+        * @covers Revision::getRevisionText
         */
-       public function testGetContentFormat( $text, $title, $model, $format, $expectedFormat ) {
-               $rev = $this->newTestRevision( $text, $title, $model, $format );
-
-               $this->assertEquals( $expectedFormat, $rev->getContentFormat() );
+       public function testGetRevisionText_returnsDecompressedTextFieldWhenNotExternal(
+               $row,
+               $prefix,
+               $expected
+       ) {
+               $this->assertSame( $expected, Revision::getRevisionText( $row, $prefix ) );
        }
 
-       public function provideGetContentHandler() {
-               // NOTE: we expect the help namespace to always contain wikitext
-               return [
-                       [ 'hello world', 'Help:Hello', null, null, 'WikitextContentHandler' ],
-                       [ 'hello world', 'User:hello/there.css', null, null, 'CssContentHandler' ],
-                       [ serialize( 'hello world' ), 'Dummy:Hello', null, null, 'DummyContentHandlerForTesting' ],
-               ];
+       public function provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts() {
+               yield 'Just some text' => [ 'someNonUrlText' ];
+               yield 'No second URL part' => [ 'someProtocol://' ];
        }
 
        /**
-        * @group Database
-        * @dataProvider provideGetContentHandler
-        * @covers Revision::getContentHandler
+        * @dataProvider provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts
+        * @covers Revision::getRevisionText
         */
-       public function testGetContentHandler( $text, $title, $model, $format, $expectedClass ) {
-               $rev = $this->newTestRevision( $text, $title, $model, $format );
+       public function testGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts(
+               $text
+       ) {
+               $this->assertFalse(
+                       Revision::getRevisionText(
+                               (object)[
+                                       'old_text' => $text,
+                                       'old_flags' => 'external',
+                               ]
+                       )
+               );
+       }
 
-               $this->assertEquals( $expectedClass, get_class( $rev->getContentHandler() ) );
+       /**
+        * @covers Revision::getRevisionText
+        */
+       public function testGetRevisionText_external_noOldId() {
+               $this->setService(
+                       'ExternalStoreFactory',
+                       new ExternalStoreFactory( [ 'ForTesting' ] )
+               );
+               $this->assertSame(
+                       'AAAABBAAA',
+                       Revision::getRevisionText(
+                               (object)[
+                                       'old_text' => 'ForTesting://cluster1/12345',
+                                       'old_flags' => 'external,gzip',
+                               ]
+                       )
+               );
        }
 
-       public function provideGetContent() {
-               // NOTE: we expect the help namespace to always contain wikitext
-               return [
-                       [ 'hello world', 'Help:Hello', null, null, Revision::FOR_PUBLIC, 'hello world' ],
-                       [
-                               serialize( 'hello world' ),
-                               'Hello',
-                               "testing",
-                               null,
-                               Revision::FOR_PUBLIC,
-                               serialize( 'hello world' )
-                       ],
-                       [
-                               serialize( 'hello world' ),
-                               'Dummy:Hello',
-                               null,
-                               null,
-                               Revision::FOR_PUBLIC,
-                               serialize( 'hello world' )
-                       ],
-               ];
+       /**
+        * @covers Revision::getRevisionText
+        */
+       public function testGetRevisionText_external_oldId() {
+               $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
+               $this->setService( 'MainWANObjectCache', $cache );
+               $this->setService(
+                       'ExternalStoreFactory',
+                       new ExternalStoreFactory( [ 'ForTesting' ] )
+               );
+
+               $cacheKey = $cache->makeKey( 'revisiontext', 'textid', '7777' );
+
+               $this->assertSame(
+                       'AAAABBAAA',
+                       Revision::getRevisionText(
+                               (object)[
+                                       'old_text' => 'ForTesting://cluster1/12345',
+                                       'old_flags' => 'external,gzip',
+                                       'old_id' => '7777',
+                               ]
+                       )
+               );
+               $this->assertSame( 'AAAABBAAA', $cache->get( $cacheKey ) );
        }
 
        /**
-        * @group Database
-        * @dataProvider provideGetContent
-        * @covers Revision::getContent
+        * @covers Revision::userJoinCond
         */
-       public function testGetContent( $text, $title, $model, $format,
-               $audience, $expectedSerialization
-       ) {
-               $rev = $this->newTestRevision( $text, $title, $model, $format );
-               $content = $rev->getContent( $audience );
+       public function testUserJoinCond() {
+               $this->hideDeprecated( 'Revision::userJoinCond' );
+               $this->assertEquals(
+                       [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
+                       Revision::userJoinCond()
+               );
+       }
 
+       /**
+        * @covers Revision::pageJoinCond
+        */
+       public function testPageJoinCond() {
+               $this->hideDeprecated( 'Revision::pageJoinCond' );
                $this->assertEquals(
-                       $expectedSerialization,
-                       is_null( $content ) ? null : $content->serialize( $format )
+                       [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
+                       Revision::pageJoinCond()
                );
        }
 
-       public function provideGetSize() {
-               return [
-                       [ "hello world.", CONTENT_MODEL_WIKITEXT, 12 ],
-                       [ serialize( "hello world." ), "testing", 12 ],
+       public function provideSelectFields() {
+               yield [
+                       true,
+                       [
+                               'rev_id',
+                               'rev_page',
+                               'rev_text_id',
+                               'rev_timestamp',
+                               'rev_user_text',
+                               'rev_user',
+                               'rev_minor_edit',
+                               'rev_deleted',
+                               'rev_len',
+                               'rev_parent_id',
+                               'rev_sha1',
+                               'rev_comment_text' => 'rev_comment',
+                               'rev_comment_data' => 'NULL',
+                               'rev_comment_cid' => 'NULL',
+                               'rev_content_format',
+                               'rev_content_model',
+                       ]
+               ];
+               yield [
+                       false,
+                       [
+                               'rev_id',
+                               'rev_page',
+                               'rev_text_id',
+                               'rev_timestamp',
+                               'rev_user_text',
+                               'rev_user',
+                               'rev_minor_edit',
+                               'rev_deleted',
+                               'rev_len',
+                               'rev_parent_id',
+                               'rev_sha1',
+                               'rev_comment_text' => 'rev_comment',
+                               'rev_comment_data' => 'NULL',
+                               'rev_comment_cid' => 'NULL',
+                       ]
                ];
        }
 
        /**
-        * @covers Revision::getSize
-        * @group Database
-        * @dataProvider provideGetSize
+        * @dataProvider provideSelectFields
+        * @covers Revision::selectFields
+        * @todo a true unit test would mock CommentStore
         */
-       public function testGetSize( $text, $model, $expected_size ) {
-               $rev = $this->newTestRevision( $text, 'RevisionTest_testGetSize', $model );
-               $this->assertEquals( $expected_size, $rev->getSize() );
+       public function testSelectFields( $contentHandlerUseDB, $expected ) {
+               $this->hideDeprecated( 'Revision::selectFields' );
+               $this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB );
+               $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD );
+               $this->assertEquals( $expected, Revision::selectFields() );
        }
 
-       public function provideGetSha1() {
-               return [
-                       [ "hello world.", CONTENT_MODEL_WIKITEXT, Revision::base36Sha1( "hello world." ) ],
+       public function provideSelectArchiveFields() {
+               yield [
+                       true,
                        [
-                               serialize( "hello world." ),
-                               "testing",
-                               Revision::base36Sha1( serialize( "hello world." ) )
-                       ],
+                               'ar_id',
+                               'ar_page_id',
+                               'ar_rev_id',
+                               'ar_text',
+                               'ar_text_id',
+                               'ar_timestamp',
+                               'ar_user_text',
+                               'ar_user',
+                               'ar_minor_edit',
+                               'ar_deleted',
+                               'ar_len',
+                               'ar_parent_id',
+                               'ar_sha1',
+                               'ar_comment_text' => 'ar_comment',
+                               'ar_comment_data' => 'NULL',
+                               'ar_comment_cid' => 'NULL',
+                               'ar_content_format',
+                               'ar_content_model',
+                       ]
+               ];
+               yield [
+                       false,
+                       [
+                               'ar_id',
+                               'ar_page_id',
+                               'ar_rev_id',
+                               'ar_text',
+                               'ar_text_id',
+                               'ar_timestamp',
+                               'ar_user_text',
+                               'ar_user',
+                               'ar_minor_edit',
+                               'ar_deleted',
+                               'ar_len',
+                               'ar_parent_id',
+                               'ar_sha1',
+                               'ar_comment_text' => 'ar_comment',
+                               'ar_comment_data' => 'NULL',
+                               'ar_comment_cid' => 'NULL',
+                       ]
                ];
        }
 
        /**
-        * @covers Revision::getSha1
-        * @group Database
-        * @dataProvider provideGetSha1
+        * @dataProvider provideSelectArchiveFields
+        * @covers Revision::selectArchiveFields
+        * @todo a true unit test would mock CommentStore
         */
-       public function testGetSha1( $text, $model, $expected_hash ) {
-               $rev = $this->newTestRevision( $text, 'RevisionTest_testGetSha1', $model );
-               $this->assertEquals( $expected_hash, $rev->getSha1() );
+       public function testSelectArchiveFields( $contentHandlerUseDB, $expected ) {
+               $this->hideDeprecated( 'Revision::selectArchiveFields' );
+               $this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB );
+               $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD );
+               $this->assertEquals( $expected, Revision::selectArchiveFields() );
        }
 
        /**
-        * Tests whether $rev->getContent() returns a clone when needed.
-        *
-        * @group Database
-        * @covers Revision::getContent
+        * @covers Revision::selectTextFields
         */
-       public function testGetContentClone() {
-               $content = new RevisionTestModifyableContent( "foo" );
+       public function testSelectTextFields() {
+               $this->hideDeprecated( 'Revision::selectTextFields' );
+               $this->assertEquals(
+                       [
+                               'old_text',
+                               'old_flags',
+                       ],
+                       Revision::selectTextFields()
+               );
+       }
 
-               $rev = new Revision(
+       /**
+        * @covers Revision::selectPageFields
+        */
+       public function testSelectPageFields() {
+               $this->hideDeprecated( 'Revision::selectPageFields' );
+               $this->assertEquals(
                        [
-                               'id' => 42,
-                               'page' => 23,
-                               'title' => Title::newFromText( "testGetContentClone_dummy" ),
+                               'page_namespace',
+                               'page_title',
+                               'page_id',
+                               'page_latest',
+                               'page_is_redirect',
+                               'page_len',
+                       ],
+                       Revision::selectPageFields()
+               );
+       }
 
-                               'content' => $content,
-                               'length' => $content->getSize(),
-                               'comment' => "testing",
-                               'minor_edit' => false,
-                       ]
+       /**
+        * @covers Revision::selectUserFields
+        */
+       public function testSelectUserFields() {
+               $this->hideDeprecated( 'Revision::selectUserFields' );
+               $this->assertEquals(
+                       [
+                               'user_name',
+                       ],
+                       Revision::selectUserFields()
                );
+       }
 
-               /** @var RevisionTestModifyableContent $content */
-               $content = $rev->getContent( Revision::RAW );
-               $content->setText( "bar" );
+       public function provideGetArchiveQueryInfo() {
+               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD' => [
+                       [
+                               'wgContentHandlerUseDB' => false,
+                               'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
+                       ],
+                       [
+                               'tables' => [ 'archive' ],
+                               'fields' => [
+                                       'ar_id',
+                                       'ar_page_id',
+                                       'ar_rev_id',
+                                       'ar_text',
+                                       'ar_text_id',
+                                       'ar_timestamp',
+                                       'ar_user_text',
+                                       'ar_user',
+                                       'ar_minor_edit',
+                                       'ar_deleted',
+                                       'ar_len',
+                                       'ar_parent_id',
+                                       'ar_sha1',
+                                       'ar_comment_text' => 'ar_comment',
+                                       'ar_comment_data' => 'NULL',
+                                       'ar_comment_cid' => 'NULL',
+                               ],
+                               'joins' => [],
+                       ]
+               ];
+               yield 'wgContentHandlerUseDB true, wgCommentTableSchemaMigrationStage OLD' => [
+                       [
+                               'wgContentHandlerUseDB' => true,
+                               'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
+                       ],
+                       [
+                               'tables' => [ 'archive' ],
+                               'fields' => [
+                                       'ar_id',
+                                       'ar_page_id',
+                                       'ar_rev_id',
+                                       'ar_text',
+                                       'ar_text_id',
+                                       'ar_timestamp',
+                                       'ar_user_text',
+                                       'ar_user',
+                                       'ar_minor_edit',
+                                       'ar_deleted',
+                                       'ar_len',
+                                       'ar_parent_id',
+                                       'ar_sha1',
+                                       'ar_comment_text' => 'ar_comment',
+                                       'ar_comment_data' => 'NULL',
+                                       'ar_comment_cid' => 'NULL',
+                                       'ar_content_format',
+                                       'ar_content_model',
+                               ],
+                               'joins' => [],
+                       ]
+               ];
+               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_BOTH' => [
+                       [
+                               'wgContentHandlerUseDB' => false,
+                               'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH,
+                       ],
+                       [
+                               'tables' => [
+                                       'archive',
+                                       'comment_ar_comment' => 'comment',
+                               ],
+                               'fields' => [
+                                       'ar_id',
+                                       'ar_page_id',
+                                       'ar_rev_id',
+                                       'ar_text',
+                                       'ar_text_id',
+                                       'ar_timestamp',
+                                       'ar_user_text',
+                                       'ar_user',
+                                       'ar_minor_edit',
+                                       'ar_deleted',
+                                       'ar_len',
+                                       'ar_parent_id',
+                                       'ar_sha1',
+                                       'ar_comment_text' => 'COALESCE( comment_ar_comment.comment_text, ar_comment )',
+                                       'ar_comment_data' => 'comment_ar_comment.comment_data',
+                                       'ar_comment_cid' => 'comment_ar_comment.comment_id',
+                               ],
+                               'joins' => [
+                                       'comment_ar_comment' => [
+                                               'LEFT JOIN',
+                                               'comment_ar_comment.comment_id = ar_comment_id',
+                                       ],
+                               ],
+                       ]
+               ];
+               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_NEW' => [
+                       [
+                               'wgContentHandlerUseDB' => false,
+                               'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW,
+                       ],
+                       [
+                               'tables' => [
+                                       'archive',
+                                       'comment_ar_comment' => 'comment',
+                               ],
+                               'fields' => [
+                                       'ar_id',
+                                       'ar_page_id',
+                                       'ar_rev_id',
+                                       'ar_text',
+                                       'ar_text_id',
+                                       'ar_timestamp',
+                                       'ar_user_text',
+                                       'ar_user',
+                                       'ar_minor_edit',
+                                       'ar_deleted',
+                                       'ar_len',
+                                       'ar_parent_id',
+                                       'ar_sha1',
+                                       'ar_comment_text' => 'COALESCE( comment_ar_comment.comment_text, ar_comment )',
+                                       'ar_comment_data' => 'comment_ar_comment.comment_data',
+                                       'ar_comment_cid' => 'comment_ar_comment.comment_id',
+                               ],
+                               'joins' => [
+                                       'comment_ar_comment' => [
+                                               'LEFT JOIN',
+                                               'comment_ar_comment.comment_id = ar_comment_id',
+                                       ],
+                               ],
+                       ]
+               ];
+               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage NEW' => [
+                       [
+                               'wgContentHandlerUseDB' => false,
+                               'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW,
+                       ],
+                       [
+                               'tables' => [
+                                       'archive',
+                                       'comment_ar_comment' => 'comment',
+                               ],
+                               'fields' => [
+                                       'ar_id',
+                                       'ar_page_id',
+                                       'ar_rev_id',
+                                       'ar_text',
+                                       'ar_text_id',
+                                       'ar_timestamp',
+                                       'ar_user_text',
+                                       'ar_user',
+                                       'ar_minor_edit',
+                                       'ar_deleted',
+                                       'ar_len',
+                                       'ar_parent_id',
+                                       'ar_sha1',
+                                       'ar_comment_text' => 'comment_ar_comment.comment_text',
+                                       'ar_comment_data' => 'comment_ar_comment.comment_data',
+                                       'ar_comment_cid' => 'comment_ar_comment.comment_id',
+                               ],
+                               'joins' => [
+                                       'comment_ar_comment' => [
+                                               'JOIN',
+                                               'comment_ar_comment.comment_id = ar_comment_id',
+                                       ],
+                               ],
+                       ]
+               ];
+       }
 
-               /** @var RevisionTestModifyableContent $content2 */
-               $content2 = $rev->getContent( Revision::RAW );
-               // content is mutable, expect clone
-               $this->assertNotSame( $content, $content2, "expected a clone" );
-               // clone should contain the original text
-               $this->assertEquals( "foo", $content2->getText() );
+       /**
+        * @covers Revision::getArchiveQueryInfo
+        * @dataProvider provideGetArchiveQueryInfo
+        */
+       public function testGetArchiveQueryInfo( $globals, $expected ) {
+               $this->setMwGlobals( $globals );
+               $this->assertEquals(
+                       $expected,
+                       Revision::getArchiveQueryInfo()
+               );
+       }
 
-               $content2->setText( "bla bla" );
-               // clones should be independent
-               $this->assertEquals( "bar", $content->getText() );
+       public function provideGetQueryInfo() {
+               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts none' => [
+                       [
+                               'wgContentHandlerUseDB' => false,
+                               'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
+                       ],
+                       [],
+                       [
+                               'tables' => [ 'revision' ],
+                               'fields' => [
+                                       'rev_id',
+                                       'rev_page',
+                                       'rev_text_id',
+                                       'rev_timestamp',
+                                       'rev_user_text',
+                                       'rev_user',
+                                       'rev_minor_edit',
+                                       'rev_deleted',
+                                       'rev_len',
+                                       'rev_parent_id',
+                                       'rev_sha1',
+                                       'rev_comment_text' => 'rev_comment',
+                                       'rev_comment_data' => 'NULL',
+                                       'rev_comment_cid' => 'NULL',
+                               ],
+                               'joins' => [],
+                       ],
+               ];
+               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts page' => [
+                       [
+                               'wgContentHandlerUseDB' => false,
+                               'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
+                       ],
+                       [ 'page' ],
+                       [
+                               'tables' => [ 'revision', 'page' ],
+                               'fields' => [
+                                       'rev_id',
+                                       'rev_page',
+                                       'rev_text_id',
+                                       'rev_timestamp',
+                                       'rev_user_text',
+                                       'rev_user',
+                                       'rev_minor_edit',
+                                       'rev_deleted',
+                                       'rev_len',
+                                       'rev_parent_id',
+                                       'rev_sha1',
+                                       'rev_comment_text' => 'rev_comment',
+                                       'rev_comment_data' => 'NULL',
+                                       'rev_comment_cid' => 'NULL',
+                                       'page_namespace',
+                                       'page_title',
+                                       'page_id',
+                                       'page_latest',
+                                       'page_is_redirect',
+                                       'page_len',
+                               ],
+                               'joins' => [
+                                       'page' => [
+                                               'INNER JOIN',
+                                               [ 'page_id = rev_page' ],
+                                       ],
+                               ],
+                       ],
+               ];
+               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts user' => [
+                       [
+                               'wgContentHandlerUseDB' => false,
+                               'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
+                       ],
+                       [ 'user' ],
+                       [
+                               'tables' => [ 'revision', 'user' ],
+                               'fields' => [
+                                       'rev_id',
+                                       'rev_page',
+                                       'rev_text_id',
+                                       'rev_timestamp',
+                                       'rev_user_text',
+                                       'rev_user',
+                                       'rev_minor_edit',
+                                       'rev_deleted',
+                                       'rev_len',
+                                       'rev_parent_id',
+                                       'rev_sha1',
+                                       'rev_comment_text' => 'rev_comment',
+                                       'rev_comment_data' => 'NULL',
+                                       'rev_comment_cid' => 'NULL',
+                                       'user_name',
+                               ],
+                               'joins' => [
+                                       'user' => [
+                                               'LEFT JOIN',
+                                               [
+                                                       'rev_user != 0',
+                                                       'user_id = rev_user',
+                                               ],
+                                       ],
+                               ],
+                       ],
+               ];
+               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts text' => [
+                       [
+                               'wgContentHandlerUseDB' => false,
+                               'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
+                       ],
+                       [ 'text' ],
+                       [
+                               'tables' => [ 'revision', 'text' ],
+                               'fields' => [
+                                       'rev_id',
+                                       'rev_page',
+                                       'rev_text_id',
+                                       'rev_timestamp',
+                                       'rev_user_text',
+                                       'rev_user',
+                                       'rev_minor_edit',
+                                       'rev_deleted',
+                                       'rev_len',
+                                       'rev_parent_id',
+                                       'rev_sha1',
+                                       'rev_comment_text' => 'rev_comment',
+                                       'rev_comment_data' => 'NULL',
+                                       'rev_comment_cid' => 'NULL',
+                                       'old_text',
+                                       'old_flags',
+                               ],
+                               'joins' => [
+                                       'text' => [
+                                               'INNER JOIN',
+                                               [ 'rev_text_id=old_id' ],
+                                       ],
+                               ],
+                       ],
+               ];
+               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts 3' => [
+                       [
+                               'wgContentHandlerUseDB' => false,
+                               'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
+                       ],
+                       [ 'text', 'page', 'user' ],
+                       [
+                               'tables' => [ 'revision', 'page', 'user', 'text' ],
+                               'fields' => [
+                                       'rev_id',
+                                       'rev_page',
+                                       'rev_text_id',
+                                       'rev_timestamp',
+                                       'rev_user_text',
+                                       'rev_user',
+                                       'rev_minor_edit',
+                                       'rev_deleted',
+                                       'rev_len',
+                                       'rev_parent_id',
+                                       'rev_sha1',
+                                       'rev_comment_text' => 'rev_comment',
+                                       'rev_comment_data' => 'NULL',
+                                       'rev_comment_cid' => 'NULL',
+                                       'page_namespace',
+                                       'page_title',
+                                       'page_id',
+                                       'page_latest',
+                                       'page_is_redirect',
+                                       'page_len',
+                                       'user_name',
+                                       'old_text',
+                                       'old_flags',
+                               ],
+                               'joins' => [
+                                       'page' => [
+                                               'INNER JOIN',
+                                               [ 'page_id = rev_page' ],
+                                       ],
+                                       'user' => [
+                                               'LEFT JOIN',
+                                               [
+                                                       'rev_user != 0',
+                                                       'user_id = rev_user',
+                                               ],
+                                       ],
+                                       'text' => [
+                                               'INNER JOIN',
+                                               [ 'rev_text_id=old_id' ],
+                                       ],
+                               ],
+                       ],
+               ];
+               yield 'wgContentHandlerUseDB true, wgCommentTableSchemaMigrationStage OLD, opts none' => [
+                       [
+                               'wgContentHandlerUseDB' => true,
+                               'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
+                       ],
+                       [],
+                       [
+                               'tables' => [ 'revision' ],
+                               'fields' => [
+                                       'rev_id',
+                                       'rev_page',
+                                       'rev_text_id',
+                                       'rev_timestamp',
+                                       'rev_user_text',
+                                       'rev_user',
+                                       'rev_minor_edit',
+                                       'rev_deleted',
+                                       'rev_len',
+                                       'rev_parent_id',
+                                       'rev_sha1',
+                                       'rev_comment_text' => 'rev_comment',
+                                       'rev_comment_data' => 'NULL',
+                                       'rev_comment_cid' => 'NULL',
+                                       'rev_content_format',
+                                       'rev_content_model',
+                               ],
+                               'joins' => [],
+                       ],
+               ];
+               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_BOTH, opts none' => [
+                       [
+                               'wgContentHandlerUseDB' => false,
+                               'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH,
+                       ],
+                       [],
+                       [
+                               'tables' => [
+                                       'revision',
+                                       'temp_rev_comment' => 'revision_comment_temp',
+                                       'comment_rev_comment' => 'comment',
+                               ],
+                               'fields' => [
+                                       'rev_id',
+                                       'rev_page',
+                                       'rev_text_id',
+                                       'rev_timestamp',
+                                       'rev_user_text',
+                                       'rev_user',
+                                       'rev_minor_edit',
+                                       'rev_deleted',
+                                       'rev_len',
+                                       'rev_parent_id',
+                                       'rev_sha1',
+                                       'rev_comment_text' => 'COALESCE( comment_rev_comment.comment_text, rev_comment )',
+                                       'rev_comment_data' => 'comment_rev_comment.comment_data',
+                                       'rev_comment_cid' => 'comment_rev_comment.comment_id',
+                               ],
+                               'joins' => [
+                                       'temp_rev_comment' => [
+                                               'LEFT JOIN',
+                                               'temp_rev_comment.revcomment_rev = rev_id',
+                                       ],
+                                       'comment_rev_comment' => [
+                                               'LEFT JOIN',
+                                               'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
+                                       ],
+                               ],
+                       ],
+               ];
+               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_NEW, opts none' => [
+                       [
+                               'wgContentHandlerUseDB' => false,
+                               'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW,
+                       ],
+                       [],
+                       [
+                               'tables' => [
+                                       'revision',
+                                       'temp_rev_comment' => 'revision_comment_temp',
+                                       'comment_rev_comment' => 'comment',
+                               ],
+                               'fields' => [
+                                       'rev_id',
+                                       'rev_page',
+                                       'rev_text_id',
+                                       'rev_timestamp',
+                                       'rev_user_text',
+                                       'rev_user',
+                                       'rev_minor_edit',
+                                       'rev_deleted',
+                                       'rev_len',
+                                       'rev_parent_id',
+                                       'rev_sha1',
+                                       'rev_comment_text' => 'COALESCE( comment_rev_comment.comment_text, rev_comment )',
+                                       'rev_comment_data' => 'comment_rev_comment.comment_data',
+                                       'rev_comment_cid' => 'comment_rev_comment.comment_id',
+                               ],
+                               'joins' => [
+                                       'temp_rev_comment' => [
+                                               'LEFT JOIN',
+                                               'temp_rev_comment.revcomment_rev = rev_id',
+                                       ],
+                                       'comment_rev_comment' => [
+                                               'LEFT JOIN',
+                                               'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
+                                       ],
+                               ],
+                       ],
+               ];
+               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage NEW, opts none' => [
+                       [
+                               'wgContentHandlerUseDB' => false,
+                               'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW,
+                       ],
+                       [],
+                       [
+                               'tables' => [
+                                       'revision',
+                                       'temp_rev_comment' => 'revision_comment_temp',
+                                       'comment_rev_comment' => 'comment',
+                               ],
+                               'fields' => [
+                                       'rev_id',
+                                       'rev_page',
+                                       'rev_text_id',
+                                       'rev_timestamp',
+                                       'rev_user_text',
+                                       'rev_user',
+                                       'rev_minor_edit',
+                                       'rev_deleted',
+                                       'rev_len',
+                                       'rev_parent_id',
+                                       'rev_sha1',
+                                       'rev_comment_text' => 'comment_rev_comment.comment_text',
+                                       'rev_comment_data' => 'comment_rev_comment.comment_data',
+                                       'rev_comment_cid' => 'comment_rev_comment.comment_id',
+                               ],
+                               'joins' => [
+                                       'temp_rev_comment' => [
+                                               'JOIN',
+                                               'temp_rev_comment.revcomment_rev = rev_id',
+                                       ],
+                                       'comment_rev_comment' => [
+                                               'JOIN',
+                                               'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
+                                       ],
+                               ],
+                       ],
+               ];
        }
 
        /**
-        * Tests whether $rev->getContent() returns the same object repeatedly if appropriate.
-        *
-        * @group Database
-        * @covers Revision::getContent
+        * @covers Revision::getQueryInfo
+        * @dataProvider provideGetQueryInfo
         */
-       public function testGetContentUncloned() {
-               $rev = $this->newTestRevision( "hello", "testGetContentUncloned_dummy", CONTENT_MODEL_WIKITEXT );
-               $content = $rev->getContent( Revision::RAW );
-               $content2 = $rev->getContent( Revision::RAW );
-
-               // for immutable content like wikitext, this should be the same object
-               $this->assertSame( $content, $content2 );
+       public function testGetQueryInfo( $globals, $options, $expected ) {
+               $this->setMwGlobals( $globals );
+               $this->assertEquals(
+                       $expected,
+                       Revision::getQueryInfo( $options )
+               );
        }
+
 }