Merge "Make the spelling and pluralization of "Active filters" consistent"
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / RevisionStoreTest.php
index 727697c..aac94b8 100644 (file)
@@ -17,9 +17,16 @@ use WANObjectCache;
 use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\LoadBalancer;
 use Wikimedia\TestingAccessWrapper;
+use WikitextContent;
 
 class RevisionStoreTest extends MediaWikiTestCase {
 
+       private function useTextId() {
+               global $wgMultiContentRevisionSchemaMigrationStage;
+
+               return (bool)( $wgMultiContentRevisionSchemaMigrationStage & SCHEMA_COMPAT_READ_OLD );
+       }
+
        /**
         * @param LoadBalancer $loadBalancer
         * @param SqlBlobStore $blobStore
@@ -86,13 +93,17 @@ class RevisionStoreTest extends MediaWikiTestCase {
 
        public function provideSetContentHandlerUseDB() {
                return [
-                       // ContentHandlerUseDB can be true of false pre migration
-                       [ false, MIGRATION_OLD, false ],
-                       [ true, MIGRATION_OLD, false ],
-                       // During migration it can not be false
-                       [ false, MIGRATION_WRITE_BOTH, true ],
-                       // But it can be true
-                       [ true, MIGRATION_WRITE_BOTH, false ],
+                       // ContentHandlerUseDB can be true of false pre migration.
+                       [ false, SCHEMA_COMPAT_OLD, false ],
+                       [ true, SCHEMA_COMPAT_OLD, false ],
+                       // During and after migration it can not be false...
+                       [ false, SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, true ],
+                       [ false, SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, true ],
+                       [ false, SCHEMA_COMPAT_NEW, true ],
+                       // ...but it can be true.
+                       [ true, SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, false ],
+                       [ true, SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, false ],
+                       [ true, SCHEMA_COMPAT_NEW, false ],
                ];
        }
 
@@ -106,13 +117,15 @@ class RevisionStoreTest extends MediaWikiTestCase {
                        $this->setExpectedException( MWException::class );
                }
 
+               $nameTables = MediaWikiServices::getInstance()->getNameTableStoreFactory();
+
                $store = new RevisionStore(
                        $this->getMockLoadBalancer(),
                        $this->getMockSqlBlobStore(),
                        $this->getHashWANObjectCache(),
                        $this->getMockCommentStore(),
-                       MediaWikiServices::getInstance()->getContentModelStore(),
-                       MediaWikiServices::getInstance()->getSlotRoleStore(),
+                       $nameTables->getContentModels(),
+                       $nameTables->getSlotRoles(),
                        $migrationMode,
                        MediaWikiServices::getInstance()->getActorMigration()
                );
@@ -405,6 +418,10 @@ class RevisionStoreTest extends MediaWikiTestCase {
         * @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow
         */
        public function testNewRevisionFromRow_legacyEncoding_applied( $encoding, $locale, $row, $text ) {
+               if ( !$this->useTextId() ) {
+                       $this->markTestSkipped( 'No longer applicable with MCR schema' );
+               }
+
                $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
                $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
 
@@ -426,6 +443,10 @@ class RevisionStoreTest extends MediaWikiTestCase {
         * @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow
         */
        public function testNewRevisionFromRow_legacyEncoding_ignored() {
+               if ( !$this->useTextId() ) {
+                       $this->markTestSkipped( 'No longer applicable with MCR schema' );
+               }
+
                $row = [
                        'old_flags' => 'utf-8',
                        'old_text' => 'Söme Content',
@@ -451,7 +472,6 @@ class RevisionStoreTest extends MediaWikiTestCase {
                $row = $array + [
                                'rev_id' => 7,
                                'rev_page' => 5,
-                               'rev_text_id' => 11,
                                'rev_timestamp' => '20110101000000',
                                'rev_user_text' => 'Tester',
                                'rev_user' => 17,
@@ -463,8 +483,6 @@ class RevisionStoreTest extends MediaWikiTestCase {
                                'rev_comment_text' => 'Testing',
                                'rev_comment_data' => '{}',
                                'rev_comment_cid' => 111,
-                               'rev_content_format' => CONTENT_FORMAT_TEXT,
-                               'rev_content_model' => CONTENT_MODEL_TEXT,
                                'page_namespace' => 0,
                                'page_title' => 'TEST',
                                'page_id' => 5,
@@ -472,18 +490,37 @@ class RevisionStoreTest extends MediaWikiTestCase {
                                'page_is_redirect' => 0,
                                'page_len' => 100,
                                'user_name' => 'Tester',
-                               'old_is' => 13,
+                       ];
+
+               if ( $this->useTextId() ) {
+                       $row += [
+                               'rev_content_format' => CONTENT_FORMAT_TEXT,
+                               'rev_content_model' => CONTENT_MODEL_TEXT,
+                               'rev_text_id' => 11,
+                               'old_id' => 11,
                                'old_text' => 'Hello World',
                                'old_flags' => 'utf-8',
                        ];
+               } else {
+                       if ( !isset( $row['content'] ) && isset( $array['old_text'] ) ) {
+                               $row['content'] = [
+                                       'main' => new WikitextContent( $array['old_text'] ),
+                               ];
+                       }
+               }
 
                return (object)$row;
        }
 
        public function provideMigrationConstruction() {
                return [
-                       [ MIGRATION_OLD, false ],
-                       [ MIGRATION_WRITE_BOTH, false ],
+                       [ SCHEMA_COMPAT_OLD, false ],
+                       [ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, false ],
+                       [ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, false ],
+                       [ SCHEMA_COMPAT_NEW, false ],
+                       [ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_BOTH, true ],
+                       [ SCHEMA_COMPAT_WRITE_OLD | SCHEMA_COMPAT_READ_BOTH, true ],
+                       [ SCHEMA_COMPAT_WRITE_NEW | SCHEMA_COMPAT_READ_BOTH, true ],
                ];
        }
 
@@ -499,17 +536,19 @@ class RevisionStoreTest extends MediaWikiTestCase {
                $blobStore = $this->getMockSqlBlobStore();
                $cache = $this->getHashWANObjectCache();
                $commentStore = $this->getMockCommentStore();
-               $contentModelStore = MediaWikiServices::getInstance()->getContentModelStore();
-               $slotRoleStore = MediaWikiServices::getInstance()->getSlotRoleStore();
+               $services = MediaWikiServices::getInstance();
+               $nameTables = $services->getNameTableStoreFactory();
+               $contentModelStore = $nameTables->getContentModels();
+               $slotRoleStore = $nameTables->getSlotRoles();
                $store = new RevisionStore(
                        $loadBalancer,
                        $blobStore,
                        $cache,
                        $commentStore,
-                       MediaWikiServices::getInstance()->getContentModelStore(),
-                       MediaWikiServices::getInstance()->getSlotRoleStore(),
+                       $nameTables->getContentModels(),
+                       $nameTables->getSlotRoles(),
                        $migration,
-                       MediaWikiServices::getInstance()->getActorMigration()
+                       $services->getActorMigration()
                );
                if ( !$expectException ) {
                        $store = TestingAccessWrapper::newFromObject( $store );