RevisionTest: Make @covers tags absolute (re-apply)
[lhc/web/wiklou.git] / tests / phpunit / includes / RevisionTest.php
index ca8ed2b..6286e70 100644 (file)
@@ -1,6 +1,9 @@
 <?php
 
-use Wikimedia\TestingAccessWrapper;
+use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\SqlBlobStore;
+use Wikimedia\Rdbms\IDatabase;
+use Wikimedia\Rdbms\LoadBalancer;
 
 /**
  * Test cases in RevisionTest should not interact with the Database.
@@ -20,47 +23,150 @@ class RevisionTest extends MediaWikiTestCase {
                                'content' => new JavaScriptContent( 'hellow world.' )
                        ],
                ];
+               // FIXME: test with and without user ID, and with a user object.
+               // We can't prepare that here though, since we don't yet have a dummy DB
+       }
+
+       /**
+        * @param string $model
+        * @return Title
+        */
+       public function getMockTitle( $model = CONTENT_MODEL_WIKITEXT ) {
+               $mock = $this->getMockBuilder( Title::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $mock->expects( $this->any() )
+                       ->method( 'getNamespace' )
+                       ->will( $this->returnValue( $this->getDefaultWikitextNS() ) );
+               $mock->expects( $this->any() )
+                       ->method( 'getPrefixedText' )
+                       ->will( $this->returnValue( 'RevisionTest' ) );
+               $mock->expects( $this->any() )
+                       ->method( 'getDBKey' )
+                       ->will( $this->returnValue( 'RevisionTest' ) );
+               $mock->expects( $this->any() )
+                       ->method( 'getArticleID' )
+                       ->will( $this->returnValue( 23 ) );
+               $mock->expects( $this->any() )
+                       ->method( 'getModel' )
+                       ->will( $this->returnValue( $model ) );
+
+               return $mock;
        }
 
        /**
         * @dataProvider provideConstructFromArray
         * @covers Revision::__construct
-        * @covers Revision::constructFromRowArray
+        * @covers RevisionStore::newMutableRevisionFromArray
         */
-       public function testConstructFromArray( array $rowArray ) {
-               $rev = new Revision( $rowArray );
+       public function testConstructFromArray( $rowArray ) {
+               $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
                $this->assertNotNull( $rev->getContent(), 'no content object available' );
                $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContent()->getModel() );
                $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() );
        }
 
+       /**
+        * @covers Revision::__construct
+        * @covers RevisionStore::newMutableRevisionFromArray
+        */
+       public function testConstructFromEmptyArray() {
+               $rev = new Revision( [], 0, $this->getMockTitle() );
+               $this->assertNull( $rev->getContent(), 'no content object should be available' );
+       }
+
+       public function provideConstructFromArray_userSetAsExpected() {
+               yield 'no user defaults to wgUser' => [
+                       [
+                               'content' => new JavaScriptContent( 'hello world.' ),
+                       ],
+                       null,
+                       null,
+               ];
+               yield 'user text and id' => [
+                       [
+                               'content' => new JavaScriptContent( 'hello world.' ),
+                               'user_text' => 'SomeTextUserName',
+                               'user' => 99,
+
+                       ],
+                       99,
+                       'SomeTextUserName',
+               ];
+               yield 'user text only' => [
+                       [
+                               'content' => new JavaScriptContent( 'hello world.' ),
+                               'user_text' => '111.111.111.111',
+                       ],
+                       0,
+                       '111.111.111.111',
+               ];
+       }
+
+       /**
+        * @dataProvider provideConstructFromArray_userSetAsExpected
+        * @covers Revision::__construct
+        * @covers RevisionStore::newMutableRevisionFromArray
+        *
+        * @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, 0, $this->getMockTitle() );
+               $this->assertEquals( $expectedUserId, $rev->getUser() );
+               $this->assertEquals( $expectedUserName, $rev->getUserText() );
+       }
+
        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 'unknown user id and no user name' => [
+                       [
+                               'content' => new JavaScriptContent( 'hello world.' ),
+                               'user' => 9989,
+                       ],
+                       new MWException( 'user_text not given, and unknown user ID 9989' )
+               ];
                yield 'with bad content object (class)' => [
                        [ 'content' => new stdClass() ],
-                       new MWException( '`content` field must contain a Content object.' )
+                       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.' )
+                       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.' )
+                       new InvalidArgumentException(
+                               '$row must be a row object, an associative array, or a RevisionRecord'
+                       )
                ];
        }
 
        /**
         * @dataProvider provideConstructFromArrayThrowsExceptions
         * @covers Revision::__construct
-        * @covers Revision::constructFromRowArray
+        * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
         */
        public function testConstructFromArrayThrowsExceptions( $rowArray, Exception $expectedException ) {
                $this->setExpectedException(
@@ -68,14 +174,25 @@ class RevisionTest extends MediaWikiTestCase {
                        $expectedException->getMessage(),
                        $expectedException->getCode()
                );
-               new Revision( $rowArray );
+               new Revision( $rowArray, 0, $this->getMockTitle() );
+       }
+
+       /**
+        * @covers Revision::__construct
+        * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
+        */
+       public function testConstructFromNothing() {
+               $this->setExpectedException(
+                       InvalidArgumentException::class
+               );
+               new Revision( [] );
        }
 
        public function provideConstructFromRow() {
                yield 'Full construction' => [
                        [
-                               'rev_id' => '2',
-                               'rev_page' => '1',
+                               'rev_id' => '42',
+                               'rev_page' => '23',
                                'rev_text_id' => '2',
                                'rev_timestamp' => '20171017114835',
                                'rev_user_text' => '127.0.0.1',
@@ -92,8 +209,8 @@ class RevisionTest extends MediaWikiTestCase {
                                'rev_content_model' => 'GOATMODEL',
                        ],
                        function ( RevisionTest $testCase, Revision $rev ) {
-                               $testCase->assertSame( 2, $rev->getId() );
-                               $testCase->assertSame( 1, $rev->getPage() );
+                               $testCase->assertSame( 42, $rev->getId() );
+                               $testCase->assertSame( 23, $rev->getPage() );
                                $testCase->assertSame( 2, $rev->getTextId() );
                                $testCase->assertSame( '20171017114835', $rev->getTimestamp() );
                                $testCase->assertSame( '127.0.0.1', $rev->getUserText() );
@@ -108,10 +225,10 @@ class RevisionTest extends MediaWikiTestCase {
                                $testCase->assertSame( 'GOATMODEL', $rev->getContentModel() );
                        }
                ];
-               yield 'null fields' => [
+               yield 'default field values' => [
                        [
-                               'rev_id' => '2',
-                               'rev_page' => '1',
+                               'rev_id' => '42',
+                               'rev_page' => '23',
                                'rev_text_id' => '2',
                                'rev_timestamp' => '20171017114835',
                                'rev_user_text' => '127.0.0.1',
@@ -123,11 +240,24 @@ class RevisionTest extends MediaWikiTestCase {
                                '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() );
+                               // parent ID may be null
+                               $testCase->assertSame( null, $rev->getParentId(), 'revision id' );
+
+                               // given fields
+                               $testCase->assertSame( $rev->getTimestamp(), '20171017114835', 'timestamp' );
+                               $testCase->assertSame( $rev->getUserText(), '127.0.0.1', 'user name' );
+                               $testCase->assertSame( $rev->getUser(), 0, 'user id' );
+                               $testCase->assertSame( $rev->getComment(), 'Goat Comment!' );
+                               $testCase->assertSame( false, $rev->isMinor(), 'minor edit' );
+                               $testCase->assertSame( 0, $rev->getVisibility(), 'visibility flags' );
+
+                               // computed fields
+                               $testCase->assertNotNull( $rev->getSize(), 'size' );
+                               $testCase->assertNotNull( $rev->getSha1(), 'hash' );
+
+                               // NOTE: model and format will be detected based on the namespace of the (mock) title
+                               $testCase->assertSame( 'text/x-wiki', $rev->getContentFormat(), 'format' );
+                               $testCase->assertSame( 'wikitext', $rev->getContentModel(), 'model' );
                        }
                ];
        }
@@ -135,11 +265,34 @@ class RevisionTest extends MediaWikiTestCase {
        /**
         * @dataProvider provideConstructFromRow
         * @covers Revision::__construct
-        * @covers Revision::constructFromDbRowObject
+        * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
         */
        public function testConstructFromRow( array $arrayData, $assertions ) {
+               $data = 'Hello goat.'; // needs to match model and format
+
+               $blobStore = $this->getMockBuilder( SqlBlobStore::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $blobStore->method( 'getBlob' )
+                       ->will( $this->returnValue( $data ) );
+
+               $blobStore->method( 'getTextIdFromAddress' )
+                       ->will( $this->returnCallback(
+                               function ( $address ) {
+                                       // Turn "tt:1234" into 12345.
+                                       // Note that this must be functional so we can test getTextId().
+                                       // Ideally, we'd un-mock getTextIdFromAddress and use its actual implementation.
+                                       $parts = explode( ':', $address );
+                                       return (int)array_pop( $parts );
+                               }
+                       ) );
+
+               // Note override internal service, so RevisionStore uses it as well.
+               $this->setService( '_SqlBlobStore', $blobStore );
+
                $row = (object)$arrayData;
-               $rev = new Revision( $row );
+               $rev = new Revision( $row, 0, $this->getMockTitle() );
                $assertions( $this, $rev );
        }
 
@@ -169,7 +322,7 @@ class RevisionTest extends MediaWikiTestCase {
         * @covers Revision::getId
         */
        public function testGetId( $rowArray, $expectedId ) {
-               $rev = new Revision( $rowArray );
+               $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
                $this->assertEquals( $expectedId, $rev->getId() );
        }
 
@@ -183,7 +336,7 @@ class RevisionTest extends MediaWikiTestCase {
         * @covers Revision::setId
         */
        public function testSetId( $input, $expected ) {
-               $rev = new Revision( [] );
+               $rev = new Revision( [], 0, $this->getMockTitle() );
                $rev->setId( $input );
                $this->assertSame( $expected, $rev->getId() );
        }
@@ -198,7 +351,7 @@ class RevisionTest extends MediaWikiTestCase {
         * @covers Revision::setUserIdAndName
         */
        public function testSetUserIdAndName( $inputId, $expectedId, $name ) {
-               $rev = new Revision( [] );
+               $rev = new Revision( [], 0, $this->getMockTitle() );
                $rev->setUserIdAndName( $inputId, $name );
                $this->assertSame( $expectedId, $rev->getUser( Revision::RAW ) );
                $this->assertEquals( $name, $rev->getUserText( Revision::RAW ) );
@@ -215,7 +368,7 @@ class RevisionTest extends MediaWikiTestCase {
         * @covers Revision::getTextId()
         */
        public function testGetTextId( $rowArray, $expected ) {
-               $rev = new Revision( $rowArray );
+               $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
                $this->assertSame( $expected, $rev->getTextId() );
        }
 
@@ -230,7 +383,7 @@ class RevisionTest extends MediaWikiTestCase {
         * @covers Revision::getParentId()
         */
        public function testGetParentId( $rowArray, $expected ) {
-               $rev = new Revision( $rowArray );
+               $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
                $this->assertSame( $expected, $rev->getParentId() );
        }
 
@@ -263,9 +416,44 @@ class RevisionTest extends MediaWikiTestCase {
                $this->testGetRevisionText( $expected, $rowData );
        }
 
+       private function getWANObjectCache() {
+               return new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
+       }
+
+       /**
+        * @return SqlBlobStore
+        */
+       private function getBlobStore() {
+               /** @var LoadBalancer $lb */
+               $lb = $this->getMockBuilder( LoadBalancer::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $cache = $this->getWANObjectCache();
+
+               $blobStore = new SqlBlobStore( $lb, $cache );
+               return $blobStore;
+       }
+
+       /**
+        * @return RevisionStore
+        */
+       private function getRevisionStore() {
+               /** @var LoadBalancer $lb */
+               $lb = $this->getMockBuilder( LoadBalancer::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $cache = $this->getWANObjectCache();
+
+               $blobStore = new RevisionStore( $lb, $this->getBlobStore(), $cache );
+               return $blobStore;
+       }
+
        public function provideGetRevisionTextWithLegacyEncoding() {
                yield 'Utf8Native' => [
                        "Wiki est l'\xc3\xa9cole superieur !",
+                       'fr',
                        'iso-8859-1',
                        [
                                'old_flags' => 'utf-8',
@@ -274,6 +462,7 @@ class RevisionTest extends MediaWikiTestCase {
                ];
                yield 'Utf8Legacy' => [
                        "Wiki est l'\xc3\xa9cole superieur !",
+                       'fr',
                        'iso-8859-1',
                        [
                                'old_flags' => '',
@@ -286,8 +475,11 @@ class RevisionTest extends MediaWikiTestCase {
         * @covers Revision::getRevisionText
         * @dataProvider provideGetRevisionTextWithLegacyEncoding
         */
-       public function testGetRevisionWithLegacyEncoding( $expected, $encoding, $rowData ) {
-               $this->setMwGlobals( 'wgLegacyEncoding', $encoding );
+       public function testGetRevisionWithLegacyEncoding( $expected, $lang, $encoding, $rowData ) {
+               $blobStore = $this->getBlobStore();
+               $blobStore->setLegacyEncoding( $encoding, Language::factory( $lang ) );
+               $this->setService( 'BlobStore', $blobStore );
+
                $this->testGetRevisionText( $expected, $rowData );
        }
 
@@ -299,6 +491,7 @@ class RevisionTest extends MediaWikiTestCase {
                 */
                yield 'Utf8NativeGzip' => [
                        "Wiki est l'\xc3\xa9cole superieur !",
+                       'fr',
                        'iso-8859-1',
                        [
                                'old_flags' => 'gzip,utf-8',
@@ -307,6 +500,7 @@ class RevisionTest extends MediaWikiTestCase {
                ];
                yield 'Utf8LegacyGzip' => [
                        "Wiki est l'\xc3\xa9cole superieur !",
+                       'fr',
                        'iso-8859-1',
                        [
                                'old_flags' => 'gzip',
@@ -319,9 +513,13 @@ class RevisionTest extends MediaWikiTestCase {
         * @covers Revision::getRevisionText
         * @dataProvider provideGetRevisionTextWithGzipAndLegacyEncoding
         */
-       public function testGetRevisionWithGzipAndLegacyEncoding( $expected, $encoding, $rowData ) {
+       public function testGetRevisionWithGzipAndLegacyEncoding( $expected, $lang, $encoding, $rowData ) {
                $this->checkPHPExtension( 'zlib' );
-               $this->setMwGlobals( 'wgLegacyEncoding', $encoding );
+
+               $blobStore = $this->getBlobStore();
+               $blobStore->setLegacyEncoding( $encoding, Language::factory( $lang ) );
+               $this->setService( 'BlobStore', $blobStore );
+
                $this->testGetRevisionText( $expected, $rowData );
        }
 
@@ -347,7 +545,10 @@ class RevisionTest extends MediaWikiTestCase {
         */
        public function testCompressRevisionTextUtf8Gzip() {
                $this->checkPHPExtension( 'zlib' );
-               $this->setMwGlobals( 'wgCompressRevisions', true );
+
+               $blobStore = $this->getBlobStore();
+               $blobStore->setCompressBlobs( true );
+               $this->setService( 'BlobStore', $blobStore );
 
                $row = new stdClass;
                $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
@@ -362,19 +563,41 @@ class RevisionTest extends MediaWikiTestCase {
                        Revision::getRevisionText( $row ), "getRevisionText" );
        }
 
-       public function provideFetchFromConds() {
-               yield [ 0, [] ];
-               yield [ Revision::READ_LOCKING, [ 'FOR UPDATE' ] ];
-       }
-
        /**
-        * @dataProvider provideFetchFromConds
-        * @covers Revision::fetchFromConds
+        * @covers Revision::loadFromTitle
         */
-       public function testFetchFromConds( $flags, array $options ) {
-               $conditions = [ 'conditionsArray' ];
+       public function testLoadFromTitle() {
+               $title = $this->getMockTitle();
+
+               $conditions = [
+                       'rev_id=page_latest',
+                       'page_namespace' => $title->getNamespace(),
+                       'page_title' => $title->getDBkey()
+               ];
+
+               $row = (object)[
+                       'rev_id' => '42',
+                       'rev_page' => $title->getArticleID(),
+                       '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',
+               ];
 
                $db = $this->getMock( IDatabase::class );
+               $db->expects( $this->any() )
+                       ->method( 'getDomainId' )
+                       ->will( $this->returnValue( wfWikiID() ) );
                $db->expects( $this->once() )
                        ->method( 'selectRow' )
                        ->with(
@@ -383,17 +606,24 @@ class RevisionTest extends MediaWikiTestCase {
                                $this->isType( 'array' ),
                                $this->equalTo( $conditions ),
                                // Method name
-                               $this->equalTo( 'Revision::fetchFromConds' ),
-                               $this->equalTo( $options ),
+                               $this->stringContains( 'fetchRevisionRowFromConds' ),
+                               // We don't really care about the options here
+                               $this->isType( 'array' ),
                                // We don't really care about the join conds are they come from the joinCond methods
                                $this->isType( 'array' )
                        )
-                       ->willReturn( 'RETURNVALUE' );
+                       ->willReturn( $row );
 
-               $wrapper = TestingAccessWrapper::newFromClass( Revision::class );
-               $result = $wrapper->fetchFromConds( $db, $conditions, $flags );
+               $revision = Revision::loadFromTitle( $db, $title );
 
-               $this->assertEquals( 'RETURNVALUE', $result );
+               $this->assertEquals( $title->getArticleID(), $revision->getTitle()->getArticleID() );
+               $this->assertEquals( $row->rev_id, $revision->getId() );
+               $this->assertEquals( $row->rev_len, $revision->getSize() );
+               $this->assertEquals( $row->rev_sha1, $revision->getSha1() );
+               $this->assertEquals( $row->rev_parent_id, $revision->getParentId() );
+               $this->assertEquals( $row->rev_timestamp, $revision->getTimestamp() );
+               $this->assertEquals( $row->rev_comment_text, $revision->getComment() );
+               $this->assertEquals( $row->rev_user_text, $revision->getUserText() );
        }
 
        public function provideDecompressRevisionText() {
@@ -424,25 +654,25 @@ class RevisionTest extends MediaWikiTestCase {
                ];
                yield '(ISO-8859-1 encoding), string in string out' => [
                        'ISO-8859-1',
-                       iconv( 'utf8', 'ISO-8859-1', "1®Àþ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( 'utf8', 'ISO-8859-1', "4®Àþ4" ) ),
+                       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( 'utf8', 'ISO-8859-1', "3®Àþ3" ) ) ),
+                       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( 'utf8', 'ISO-8859-1', "2®Àþ2" ) ) ) ),
+                       gzdeflate( serialize( new TitleValue( 0, iconv( 'utf-8', 'ISO-8859-1', "2®Àþ2" ) ) ) ),
                        [ 'gzip', 'object' ],
                        '2®Àþ2',
                ];
@@ -458,8 +688,12 @@ class RevisionTest extends MediaWikiTestCase {
         * @param mixed $expected
         */
        public function testDecompressRevisionText( $legacyEncoding, $text, $flags, $expected ) {
-               $this->setMwGlobals( 'wgLegacyEncoding', $legacyEncoding );
-               $this->setMwGlobals( 'wgLanguageCode', 'en' );
+               $blobStore = $this->getBlobStore();
+               if ( $legacyEncoding ) {
+                       $blobStore->setLegacyEncoding( $legacyEncoding, Language::factory( 'en' ) );
+               }
+
+               $this->setService( 'BlobStore', $blobStore );
                $this->assertSame(
                        $expected,
                        Revision::decompressRevisionText( $text, $flags )
@@ -532,4 +766,790 @@ class RevisionTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @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',
+                               ]
+                       )
+               );
+       }
+
+       /**
+        * @covers Revision::getRevisionText
+        */
+       public function testGetRevisionText_external_oldId() {
+               $cache = $this->getWANObjectCache();
+               $this->setService( 'MainWANObjectCache', $cache );
+
+               $this->setService(
+                       'ExternalStoreFactory',
+                       new ExternalStoreFactory( [ 'ForTesting' ] )
+               );
+
+               $lb = $this->getMockBuilder( LoadBalancer::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $blobStore = new SqlBlobStore( $lb, $cache );
+               $this->setService( 'BlobStore', $blobStore );
+
+               $this->assertSame(
+                       'AAAABBAAA',
+                       Revision::getRevisionText(
+                               (object)[
+                                       'old_text' => 'ForTesting://cluster1/12345',
+                                       'old_flags' => 'external,gzip',
+                                       'old_id' => '7777',
+                               ]
+                       )
+               );
+
+               $cacheKey = $cache->makeKey( 'revisiontext', 'textid', 'tt:7777' );
+               $this->assertSame( 'AAAABBAAA', $cache->get( $cacheKey ) );
+       }
+
+       /**
+        * @covers Revision::userJoinCond
+        */
+       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(
+                       [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
+                       Revision::pageJoinCond()
+               );
+       }
+
+       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',
+                       ]
+               ];
+       }
+
+       /**
+        * @dataProvider provideSelectFields
+        * @covers Revision::selectFields
+        * @todo a true unit test would mock CommentStore
+        */
+       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 provideSelectArchiveFields() {
+               yield [
+                       true,
+                       [
+                               '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',
+                       ]
+               ];
+       }
+
+       /**
+        * @dataProvider provideSelectArchiveFields
+        * @covers Revision::selectArchiveFields
+        * @todo a true unit test would mock CommentStore
+        */
+       public function testSelectArchiveFields( $contentHandlerUseDB, $expected ) {
+               $this->hideDeprecated( 'Revision::selectArchiveFields' );
+               $this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB );
+               $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD );
+               $this->assertEquals( $expected, Revision::selectArchiveFields() );
+       }
+
+       /**
+        * @covers Revision::selectTextFields
+        */
+       public function testSelectTextFields() {
+               $this->hideDeprecated( 'Revision::selectTextFields' );
+               $this->assertEquals(
+                       [
+                               'old_text',
+                               'old_flags',
+                       ],
+                       Revision::selectTextFields()
+               );
+       }
+
+       /**
+        * @covers Revision::selectPageFields
+        */
+       public function testSelectPageFields() {
+               $this->hideDeprecated( 'Revision::selectPageFields' );
+               $this->assertEquals(
+                       [
+                               'page_namespace',
+                               'page_title',
+                               'page_id',
+                               'page_latest',
+                               'page_is_redirect',
+                               'page_len',
+                       ],
+                       Revision::selectPageFields()
+               );
+       }
+
+       /**
+        * @covers Revision::selectUserFields
+        */
+       public function testSelectUserFields() {
+               $this->hideDeprecated( 'Revision::selectUserFields' );
+               $this->assertEquals(
+                       [
+                               'user_name',
+                       ],
+                       Revision::selectUserFields()
+               );
+       }
+
+       public function provideGetArchiveQueryInfo() {
+               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD' => [
+                       [
+                               'wgContentHandlerUseDB' => false,
+                               'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
+                       ],
+                       [
+                               'tables' => [ 'archive' ],
+                               'fields' => [
+                                       'ar_id',
+                                       'ar_page_id',
+                                       'ar_namespace',
+                                       'ar_title',
+                                       '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_namespace',
+                                       'ar_title',
+                                       '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_namespace',
+                                       'ar_title',
+                                       '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_namespace',
+                                       'ar_title',
+                                       '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_namespace',
+                                       'ar_title',
+                                       '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',
+                                       ],
+                               ],
+                       ]
+               ];
+       }
+
+       /**
+        * @covers Revision::getArchiveQueryInfo
+        * @dataProvider provideGetArchiveQueryInfo
+        */
+       public function testGetArchiveQueryInfo( $globals, $expected ) {
+               $this->setMwGlobals( $globals );
+
+               $revisionStore = $this->getRevisionStore();
+               $revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] );
+               $this->setService( 'RevisionStore', $revisionStore );
+
+               $this->assertEquals(
+                       $expected,
+                       Revision::getArchiveQueryInfo()
+               );
+       }
+
+       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',
+                                       ],
+                               ],
+                       ],
+               ];
+       }
+
+       /**
+        * @covers Revision::getQueryInfo
+        * @dataProvider provideGetQueryInfo
+        */
+       public function testGetQueryInfo( $globals, $options, $expected ) {
+               $this->setMwGlobals( $globals );
+
+               $revisionStore = $this->getRevisionStore();
+               $revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] );
+               $this->setService( 'RevisionStore', $revisionStore );
+
+               $this->assertEquals(
+                       $expected,
+                       Revision::getQueryInfo( $options )
+               );
+       }
+
 }