Merge "Fix sessionfailure i18n message during authentication"
[lhc/web/wiklou.git] / tests / phpunit / includes / RevisionTest.php
index 6286e70..57c0531 100644 (file)
@@ -1,6 +1,12 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\BlobStoreFactory;
+use MediaWiki\Storage\MutableRevisionRecord;
+use MediaWiki\Storage\RevisionAccessException;
+use MediaWiki\Storage\RevisionRecord;
 use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\SlotRecord;
 use MediaWiki\Storage\SqlBlobStore;
 use Wikimedia\Rdbms\IDatabase;
 use Wikimedia\Rdbms\LoadBalancer;
@@ -42,7 +48,7 @@ class RevisionTest extends MediaWikiTestCase {
                        ->method( 'getPrefixedText' )
                        ->will( $this->returnValue( 'RevisionTest' ) );
                $mock->expects( $this->any() )
-                       ->method( 'getDBKey' )
+                       ->method( 'getDBkey' )
                        ->will( $this->returnValue( 'RevisionTest' ) );
                $mock->expects( $this->any() )
                        ->method( 'getArticleID' )
@@ -57,7 +63,7 @@ class RevisionTest extends MediaWikiTestCase {
        /**
         * @dataProvider provideConstructFromArray
         * @covers Revision::__construct
-        * @covers RevisionStore::newMutableRevisionFromArray
+        * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
         */
        public function testConstructFromArray( $rowArray ) {
                $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
@@ -68,13 +74,24 @@ class RevisionTest extends MediaWikiTestCase {
 
        /**
         * @covers Revision::__construct
-        * @covers RevisionStore::newMutableRevisionFromArray
+        * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
         */
        public function testConstructFromEmptyArray() {
                $rev = new Revision( [], 0, $this->getMockTitle() );
                $this->assertNull( $rev->getContent(), 'no content object should be available' );
        }
 
+       /**
+        * @covers Revision::__construct
+        * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
+        */
+       public function testConstructFromArrayWithBadPageId() {
+               MediaWiki\suppressWarnings();
+               $rev = new Revision( [ 'page' => 77777777 ] );
+               $this->assertSame( 77777777, $rev->getPage() );
+               MediaWiki\restoreWarnings();
+       }
+
        public function provideConstructFromArray_userSetAsExpected() {
                yield 'no user defaults to wgUser' => [
                        [
@@ -106,7 +123,7 @@ class RevisionTest extends MediaWikiTestCase {
        /**
         * @dataProvider provideConstructFromArray_userSetAsExpected
         * @covers Revision::__construct
-        * @covers RevisionStore::newMutableRevisionFromArray
+        * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
         *
         * @param array $rowArray
         * @param mixed $expectedUserId null to expect the current wgUser ID
@@ -289,13 +306,26 @@ class RevisionTest extends MediaWikiTestCase {
                        ) );
 
                // Note override internal service, so RevisionStore uses it as well.
-               $this->setService( '_SqlBlobStore', $blobStore );
+               $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
 
                $row = (object)$arrayData;
                $rev = new Revision( $row, 0, $this->getMockTitle() );
                $assertions( $this, $rev );
        }
 
+       /**
+        * @covers Revision::__construct
+        * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
+        */
+       public function testConstructFromRowWithBadPageId() {
+               $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD );
+               $this->overrideMwServices();
+               MediaWiki\suppressWarnings();
+               $rev = new Revision( (object)[ 'rev_page' => 77777777 ] );
+               $this->assertSame( 77777777, $rev->getPage() );
+               MediaWiki\restoreWarnings();
+       }
+
        public function provideGetRevisionText() {
                yield 'Generic test' => [
                        'This is a goat of revision text.',
@@ -435,6 +465,20 @@ class RevisionTest extends MediaWikiTestCase {
                return $blobStore;
        }
 
+       private function mockBlobStoreFactory( $blobStore ) {
+               /** @var LoadBalancer $lb */
+               $factory = $this->getMockBuilder( BlobStoreFactory::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $factory->expects( $this->any() )
+                       ->method( 'newBlobStore' )
+                       ->willReturn( $blobStore );
+               $factory->expects( $this->any() )
+                       ->method( 'newSqlBlobStore' )
+                       ->willReturn( $blobStore );
+               return $factory;
+       }
+
        /**
         * @return RevisionStore
         */
@@ -446,7 +490,12 @@ class RevisionTest extends MediaWikiTestCase {
 
                $cache = $this->getWANObjectCache();
 
-               $blobStore = new RevisionStore( $lb, $this->getBlobStore(), $cache );
+               $blobStore = new RevisionStore(
+                       $lb,
+                       $this->getBlobStore(),
+                       $cache,
+                       MediaWikiServices::getInstance()->getCommentStore()
+               );
                return $blobStore;
        }
 
@@ -478,7 +527,7 @@ class RevisionTest extends MediaWikiTestCase {
        public function testGetRevisionWithLegacyEncoding( $expected, $lang, $encoding, $rowData ) {
                $blobStore = $this->getBlobStore();
                $blobStore->setLegacyEncoding( $encoding, Language::factory( $lang ) );
-               $this->setService( 'BlobStore', $blobStore );
+               $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
 
                $this->testGetRevisionText( $expected, $rowData );
        }
@@ -518,7 +567,7 @@ class RevisionTest extends MediaWikiTestCase {
 
                $blobStore = $this->getBlobStore();
                $blobStore->setLegacyEncoding( $encoding, Language::factory( $lang ) );
-               $this->setService( 'BlobStore', $blobStore );
+               $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
 
                $this->testGetRevisionText( $expected, $rowData );
        }
@@ -548,7 +597,7 @@ class RevisionTest extends MediaWikiTestCase {
 
                $blobStore = $this->getBlobStore();
                $blobStore->setCompressBlobs( true );
-               $this->setService( 'BlobStore', $blobStore );
+               $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
 
                $row = new stdClass;
                $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
@@ -567,6 +616,8 @@ class RevisionTest extends MediaWikiTestCase {
         * @covers Revision::loadFromTitle
         */
        public function testLoadFromTitle() {
+               $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD );
+               $this->overrideMwServices();
                $title = $this->getMockTitle();
 
                $conditions = [
@@ -693,7 +744,7 @@ class RevisionTest extends MediaWikiTestCase {
                        $blobStore->setLegacyEncoding( $legacyEncoding, Language::factory( 'en' ) );
                }
 
-               $this->setService( 'BlobStore', $blobStore );
+               $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
                $this->assertSame(
                        $expected,
                        Revision::decompressRevisionText( $text, $flags )
@@ -802,7 +853,7 @@ class RevisionTest extends MediaWikiTestCase {
                        ->getMock();
 
                $blobStore = new SqlBlobStore( $lb, $cache );
-               $this->setService( 'BlobStore', $blobStore );
+               $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
 
                $this->assertSame(
                        'AAAABBAAA',
@@ -841,6 +892,24 @@ class RevisionTest extends MediaWikiTestCase {
                );
        }
 
+       private function overrideCommentStore() {
+               $mockStore = $this->getMockBuilder( CommentStore::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $mockStore->expects( $this->any() )
+                       ->method( 'getFields' )
+                       ->willReturn( [ 'commentstore' => 'fields' ] );
+               $mockStore->expects( $this->any() )
+                       ->method( 'getJoin' )
+                       ->willReturn( [
+                               'tables' => [ 'commentstore' => 'table' ],
+                               'fields' => [ 'commentstore' => 'field' ],
+                               'joins' => [ 'commentstore' => 'join' ],
+                       ] );
+
+               $this->setService( 'CommentStore', $mockStore );
+       }
+
        public function provideSelectFields() {
                yield [
                        true,
@@ -856,9 +925,7 @@ class RevisionTest extends MediaWikiTestCase {
                                'rev_len',
                                'rev_parent_id',
                                'rev_sha1',
-                               'rev_comment_text' => 'rev_comment',
-                               'rev_comment_data' => 'NULL',
-                               'rev_comment_cid' => 'NULL',
+                               'commentstore' => 'fields',
                                'rev_content_format',
                                'rev_content_model',
                        ]
@@ -877,9 +944,7 @@ class RevisionTest extends MediaWikiTestCase {
                                'rev_len',
                                'rev_parent_id',
                                'rev_sha1',
-                               'rev_comment_text' => 'rev_comment',
-                               'rev_comment_data' => 'NULL',
-                               'rev_comment_cid' => 'NULL',
+                               'commentstore' => 'fields',
                        ]
                ];
        }
@@ -887,12 +952,11 @@ class RevisionTest extends MediaWikiTestCase {
        /**
         * @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->overrideCommentStore();
                $this->assertEquals( $expected, Revision::selectFields() );
        }
 
@@ -913,9 +977,7 @@ class RevisionTest extends MediaWikiTestCase {
                                'ar_len',
                                'ar_parent_id',
                                'ar_sha1',
-                               'ar_comment_text' => 'ar_comment',
-                               'ar_comment_data' => 'NULL',
-                               'ar_comment_cid' => 'NULL',
+                               'commentstore' => 'fields',
                                'ar_content_format',
                                'ar_content_model',
                        ]
@@ -936,9 +998,7 @@ class RevisionTest extends MediaWikiTestCase {
                                'ar_len',
                                'ar_parent_id',
                                'ar_sha1',
-                               'ar_comment_text' => 'ar_comment',
-                               'ar_comment_data' => 'NULL',
-                               'ar_comment_cid' => 'NULL',
+                               'commentstore' => 'fields',
                        ]
                ];
        }
@@ -946,12 +1006,11 @@ class RevisionTest extends MediaWikiTestCase {
        /**
         * @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->overrideCommentStore();
                $this->assertEquals( $expected, Revision::selectArchiveFields() );
        }
 
@@ -1001,115 +1060,14 @@ class RevisionTest extends MediaWikiTestCase {
        }
 
        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' => [
+               yield 'wgContentHandlerUseDB false' => [
                        [
                                'wgContentHandlerUseDB' => false,
-                               'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW,
                        ],
                        [
                                'tables' => [
                                        'archive',
-                                       'comment_ar_comment' => 'comment',
+                                       'commentstore' => 'table',
                                ],
                                'fields' => [
                                        'ar_id',
@@ -1127,27 +1085,19 @@ class RevisionTest extends MediaWikiTestCase {
                                        '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',
-                                       ],
+                                       'commentstore' => 'field'
                                ],
+                               'joins' => [ 'commentstore' => 'join' ],
                        ]
                ];
-               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage NEW' => [
+               yield 'wgContentHandlerUseDB true' => [
                        [
-                               'wgContentHandlerUseDB' => false,
-                               'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW,
+                               'wgContentHandlerUseDB' => true,
                        ],
                        [
                                'tables' => [
                                        'archive',
-                                       'comment_ar_comment' => 'comment',
+                                       'commentstore' => 'table',
                                ],
                                'fields' => [
                                        'ar_id',
@@ -1165,16 +1115,11 @@ class RevisionTest extends MediaWikiTestCase {
                                        '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',
-                                       ],
+                                       'commentstore' => 'field',
+                                       'ar_content_format',
+                                       'ar_content_model',
                                ],
+                               'joins' => [ 'commentstore' => 'join' ],
                        ]
                ];
        }
@@ -1185,11 +1130,11 @@ class RevisionTest extends MediaWikiTestCase {
         */
        public function testGetArchiveQueryInfo( $globals, $expected ) {
                $this->setMwGlobals( $globals );
+               $this->overrideCommentStore();
 
                $revisionStore = $this->getRevisionStore();
                $revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] );
                $this->setService( 'RevisionStore', $revisionStore );
-
                $this->assertEquals(
                        $expected,
                        Revision::getArchiveQueryInfo()
@@ -1197,14 +1142,13 @@ class RevisionTest extends MediaWikiTestCase {
        }
 
        public function provideGetQueryInfo() {
-               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts none' => [
+               yield 'wgContentHandlerUseDB false, opts none' => [
                        [
                                'wgContentHandlerUseDB' => false,
-                               'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
                        ],
                        [],
                        [
-                               'tables' => [ 'revision' ],
+                               'tables' => [ 'revision', 'commentstore' => 'table' ],
                                'fields' => [
                                        'rev_id',
                                        'rev_page',
@@ -1217,21 +1161,18 @@ class RevisionTest extends MediaWikiTestCase {
                                        'rev_len',
                                        'rev_parent_id',
                                        'rev_sha1',
-                                       'rev_comment_text' => 'rev_comment',
-                                       'rev_comment_data' => 'NULL',
-                                       'rev_comment_cid' => 'NULL',
+                                       'commentstore' => 'field',
                                ],
-                               'joins' => [],
+                               'joins' => [ 'commentstore' => 'join' ],
                        ],
                ];
-               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts page' => [
+               yield 'wgContentHandlerUseDB false, opts page' => [
                        [
                                'wgContentHandlerUseDB' => false,
-                               'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
                        ],
                        [ 'page' ],
                        [
-                               'tables' => [ 'revision', 'page' ],
+                               'tables' => [ 'revision', 'commentstore' => 'table', 'page' ],
                                'fields' => [
                                        'rev_id',
                                        'rev_page',
@@ -1244,9 +1185,7 @@ class RevisionTest extends MediaWikiTestCase {
                                        'rev_len',
                                        'rev_parent_id',
                                        'rev_sha1',
-                                       'rev_comment_text' => 'rev_comment',
-                                       'rev_comment_data' => 'NULL',
-                                       'rev_comment_cid' => 'NULL',
+                                       'commentstore' => 'field',
                                        'page_namespace',
                                        'page_title',
                                        'page_id',
@@ -1259,17 +1198,17 @@ class RevisionTest extends MediaWikiTestCase {
                                                'INNER JOIN',
                                                [ 'page_id = rev_page' ],
                                        ],
+                                       'commentstore' => 'join',
                                ],
                        ],
                ];
-               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts user' => [
+               yield 'wgContentHandlerUseDB false, opts user' => [
                        [
                                'wgContentHandlerUseDB' => false,
-                               'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
                        ],
                        [ 'user' ],
                        [
-                               'tables' => [ 'revision', 'user' ],
+                               'tables' => [ 'revision', 'commentstore' => 'table', 'user' ],
                                'fields' => [
                                        'rev_id',
                                        'rev_page',
@@ -1282,9 +1221,7 @@ class RevisionTest extends MediaWikiTestCase {
                                        'rev_len',
                                        'rev_parent_id',
                                        'rev_sha1',
-                                       'rev_comment_text' => 'rev_comment',
-                                       'rev_comment_data' => 'NULL',
-                                       'rev_comment_cid' => 'NULL',
+                                       'commentstore' => 'field',
                                        'user_name',
                                ],
                                'joins' => [
@@ -1295,17 +1232,17 @@ class RevisionTest extends MediaWikiTestCase {
                                                        'user_id = rev_user',
                                                ],
                                        ],
+                                       'commentstore' => 'join',
                                ],
                        ],
                ];
-               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts text' => [
+               yield 'wgContentHandlerUseDB false, opts text' => [
                        [
                                'wgContentHandlerUseDB' => false,
-                               'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
                        ],
                        [ 'text' ],
                        [
-                               'tables' => [ 'revision', 'text' ],
+                               'tables' => [ 'revision', 'commentstore' => 'table', 'text' ],
                                'fields' => [
                                        'rev_id',
                                        'rev_page',
@@ -1318,9 +1255,7 @@ class RevisionTest extends MediaWikiTestCase {
                                        'rev_len',
                                        'rev_parent_id',
                                        'rev_sha1',
-                                       'rev_comment_text' => 'rev_comment',
-                                       'rev_comment_data' => 'NULL',
-                                       'rev_comment_cid' => 'NULL',
+                                       'commentstore' => 'field',
                                        'old_text',
                                        'old_flags',
                                ],
@@ -1329,17 +1264,17 @@ class RevisionTest extends MediaWikiTestCase {
                                                'INNER JOIN',
                                                [ 'rev_text_id=old_id' ],
                                        ],
+                                       'commentstore' => 'join',
                                ],
                        ],
                ];
-               yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts 3' => [
+               yield 'wgContentHandlerUseDB false, opts 3' => [
                        [
                                'wgContentHandlerUseDB' => false,
-                               'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
                        ],
                        [ 'text', 'page', 'user' ],
                        [
-                               'tables' => [ 'revision', 'page', 'user', 'text' ],
+                               'tables' => [ 'revision', 'commentstore' => 'table', 'page', 'user', 'text' ],
                                'fields' => [
                                        'rev_id',
                                        'rev_page',
@@ -1352,9 +1287,7 @@ class RevisionTest extends MediaWikiTestCase {
                                        'rev_len',
                                        'rev_parent_id',
                                        'rev_sha1',
-                                       'rev_comment_text' => 'rev_comment',
-                                       'rev_comment_data' => 'NULL',
-                                       'rev_comment_cid' => 'NULL',
+                                       'commentstore' => 'field',
                                        'page_namespace',
                                        'page_title',
                                        'page_id',
@@ -1381,17 +1314,17 @@ class RevisionTest extends MediaWikiTestCase {
                                                'INNER JOIN',
                                                [ 'rev_text_id=old_id' ],
                                        ],
+                                       'commentstore' => 'join',
                                ],
                        ],
                ];
-               yield 'wgContentHandlerUseDB true, wgCommentTableSchemaMigrationStage OLD, opts none' => [
+               yield 'wgContentHandlerUseDB true, opts none' => [
                        [
                                'wgContentHandlerUseDB' => true,
-                               'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
                        ],
                        [],
                        [
-                               'tables' => [ 'revision' ],
+                               'tables' => [ 'revision', 'commentstore' => 'table' ],
                                'fields' => [
                                        'rev_id',
                                        'rev_page',
@@ -1404,133 +1337,11 @@ class RevisionTest extends MediaWikiTestCase {
                                        'rev_len',
                                        'rev_parent_id',
                                        'rev_sha1',
-                                       'rev_comment_text' => 'rev_comment',
-                                       'rev_comment_data' => 'NULL',
-                                       'rev_comment_cid' => 'NULL',
+                                       'commentstore' => 'field',
                                        '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',
-                                       ],
-                               ],
+                               'joins' => [ 'commentstore' => 'join' ],
                        ],
                ];
        }
@@ -1541,6 +1352,7 @@ class RevisionTest extends MediaWikiTestCase {
         */
        public function testGetQueryInfo( $globals, $options, $expected ) {
                $this->setMwGlobals( $globals );
+               $this->overrideCommentStore();
 
                $revisionStore = $this->getRevisionStore();
                $revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] );
@@ -1552,4 +1364,102 @@ class RevisionTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Revision::getSize
+        */
+       public function testGetSize() {
+               $title = $this->getMockTitle();
+
+               $rec = new MutableRevisionRecord( $title );
+               $rev = new Revision( $rec, 0, $title );
+
+               $this->assertSame( 0, $rev->getSize(), 'Size of no slots is 0' );
+
+               $rec->setSize( 13 );
+               $this->assertSame( 13, $rev->getSize() );
+       }
+
+       /**
+        * @covers Revision::getSize
+        */
+       public function testGetSize_failure() {
+               $title = $this->getMockTitle();
+
+               $rec = $this->getMockBuilder( RevisionRecord::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $rec->method( 'getSize' )
+                       ->willThrowException( new RevisionAccessException( 'Oops!' ) );
+
+               $rev = new Revision( $rec, 0, $title );
+               $this->assertNull( $rev->getSize() );
+       }
+
+       /**
+        * @covers Revision::getSha1
+        */
+       public function testGetSha1() {
+               $title = $this->getMockTitle();
+
+               $rec = new MutableRevisionRecord( $title );
+               $rev = new Revision( $rec, 0, $title );
+
+               $emptyHash = SlotRecord::base36Sha1( '' );
+               $this->assertSame( $emptyHash, $rev->getSha1(), 'Sha1 of no slots is hash of empty string' );
+
+               $rec->setSha1( 'deadbeef' );
+               $this->assertSame( 'deadbeef', $rev->getSha1() );
+       }
+
+       /**
+        * @covers Revision::getSha1
+        */
+       public function testGetSha1_failure() {
+               $title = $this->getMockTitle();
+
+               $rec = $this->getMockBuilder( RevisionRecord::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $rec->method( 'getSha1' )
+                       ->willThrowException( new RevisionAccessException( 'Oops!' ) );
+
+               $rev = new Revision( $rec, 0, $title );
+               $this->assertNull( $rev->getSha1() );
+       }
+
+       /**
+        * @covers Revision::getContent
+        */
+       public function testGetContent() {
+               $title = $this->getMockTitle();
+
+               $rec = new MutableRevisionRecord( $title );
+               $rev = new Revision( $rec, 0, $title );
+
+               $this->assertNull( $rev->getContent(), 'Content of no slots is null' );
+
+               $content = new TextContent( 'Hello Kittens!' );
+               $rec->setContent( 'main', $content );
+               $this->assertSame( $content, $rev->getContent() );
+       }
+
+       /**
+        * @covers Revision::getContent
+        */
+       public function testGetContent_failure() {
+               $title = $this->getMockTitle();
+
+               $rec = $this->getMockBuilder( RevisionRecord::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $rec->method( 'getContent' )
+                       ->willThrowException( new RevisionAccessException( 'Oops!' ) );
+
+               $rev = new Revision( $rec, 0, $title );
+               $this->assertNull( $rev->getContent() );
+       }
+
 }