Merge "SlotRecord:compute sha1 if empty."
[lhc/web/wiklou.git] / tests / phpunit / includes / ActorMigrationTest.php
index 15c70bc..40c45dc 100644 (file)
@@ -18,15 +18,6 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
                'actor',
        ];
 
-       /**
-        * Create an ActorMigration for a particular stage
-        * @param int $stage
-        * @return ActorMigration
-        */
-       protected function makeMigration( $stage ) {
-               return new ActorMigration( $stage );
-       }
-
        /**
         * @dataProvider provideConstructor
         * @param int $stage
@@ -81,7 +72,7 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
         * @param array $expect
         */
        public function testGetJoin( $stage, $key, $expect ) {
-               $m = $this->makeMigration( $stage );
+               $m = new ActorMigration( $stage );
                $result = $m->getJoin( $key );
                $this->assertEquals( $expect, $result );
        }
@@ -260,7 +251,7 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
                        $users = reset( $users );
                }
 
-               $m = $this->makeMigration( $stage );
+               $m = new ActorMigration( $stage );
                $result = $m->getWhere( $this->db, $key, $users, $useId );
                $this->assertEquals( $expect, $result );
        }
@@ -510,7 +501,7 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
                                $extraFields['ipb_address'] = __CLASS__ . "#{$stageNames[$writeStage]}";
                        }
 
-                       $w = $this->makeMigration( $writeStage );
+                       $w = new ActorMigration( $writeStage );
                        $usesTemp = $key === 'rev_user';
 
                        if ( $usesTemp ) {
@@ -543,7 +534,7 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
                        }
 
                        foreach ( $possibleReadStages as $readStage ) {
-                               $r = $this->makeMigration( $readStage );
+                               $r = new ActorMigration( $readStage );
 
                                $queryInfo = $r->getJoin( $key );
                                $row = $this->db->selectRow(
@@ -593,7 +584,6 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
                        ] ],
                        'revision' => [ 'revision', 'rev_user', 'rev_id', [
                                'rev_page' => 42,
-                               'rev_text_id' => 42,
                                'rev_len' => 0,
                                'rev_timestamp' => $db->timestamp(),
                        ] ],
@@ -616,7 +606,7 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
         * @expectedExceptionMessage Must use getInsertValuesWithTempTable() for rev_user
         */
        public function testInsertWrong( $stage ) {
-               $m = $this->makeMigration( $stage );
+               $m = new ActorMigration( $stage );
                $m->getInsertValues( $this->db, 'rev_user', $this->getTestUser()->getUser() );
        }
 
@@ -627,7 +617,7 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
         * @expectedExceptionMessage Must use getInsertValues() for rc_user
         */
        public function testInsertWithTempTableWrong( $stage ) {
-               $m = $this->makeMigration( $stage );
+               $m = new ActorMigration( $stage );
                $m->getInsertValuesWithTempTable( $this->db, 'rc_user', $this->getTestUser()->getUser() );
        }
 
@@ -640,7 +630,7 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
                $wrap->formerTempTables += [ 'rc_user' => '1.30' ];
 
                $this->hideDeprecated( 'ActorMigration::getInsertValuesWithTempTable for rc_user' );
-               $m = $this->makeMigration( $stage );
+               $m = new ActorMigration( $stage );
                list( $fields, $callback )
                        = $m->getInsertValuesWithTempTable( $this->db, 'rc_user', $this->getTestUser()->getUser() );
                $this->assertTrue( is_callable( $callback ) );
@@ -653,20 +643,24 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
         * @expectedExceptionMessage $extra[rev_timestamp] is not provided
         */
        public function testInsertWithTempTableCallbackMissingFields( $stage ) {
-               $m = $this->makeMigration( $stage );
+               $m = new ActorMigration( $stage );
                list( $fields, $callback )
                        = $m->getInsertValuesWithTempTable( $this->db, 'rev_user', $this->getTestUser()->getUser() );
                $callback( 1, [] );
        }
 
-       public function testInsertUserIdentity() {
+       /**
+        * @dataProvider provideStages
+        * @param int $stage
+        */
+       public function testInsertUserIdentity( $stage ) {
                $this->setMwGlobals( [
                        // for User::getActorId()
-                       'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
+                       'wgActorTableSchemaMigrationStage' => $stage
                ] );
                $this->overrideMwServices();
 
-               $user = $this->getTestUser()->getUser();
+               $user = $this->getMutableTestUser()->getUser();
                $userIdentity = $this->getMock( UserIdentity::class );
                $userIdentity->method( 'getId' )->willReturn( $user->getId() );
                $userIdentity->method( 'getName' )->willReturn( $user->getName() );
@@ -674,12 +668,11 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
 
                list( $cFields, $cCallback ) = MediaWikiServices::getInstance()->getCommentStore()
                        ->insertWithTempTable( $this->db, 'rev_comment', '' );
-               $m = $this->makeMigration( SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW );
+               $m = new ActorMigration( $stage );
                list( $fields, $callback ) =
                        $m->getInsertValuesWithTempTable( $this->db, 'rev_user', $userIdentity );
                $extraFields = [
                        'rev_page' => 42,
-                       'rev_text_id' => 42,
                        'rev_len' => 0,
                        'rev_timestamp' => $this->db->timestamp(),
                ] + $cFields;
@@ -694,13 +687,25 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
                );
                $this->assertSame( $user->getId(), (int)$row->rev_user );
                $this->assertSame( $user->getName(), $row->rev_user_text );
-               $this->assertSame( $user->getActorId(), (int)$row->rev_actor );
+               $this->assertSame(
+                       ( $stage & SCHEMA_COMPAT_READ_NEW ) ? $user->getActorId() : 0,
+                       (int)$row->rev_actor
+               );
 
-               $m = $this->makeMigration( SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW );
+               $m = new ActorMigration( $stage );
                $fields = $m->getInsertValues( $this->db, 'dummy_user', $userIdentity );
-               $this->assertSame( $user->getId(), $fields['dummy_user'] );
-               $this->assertSame( $user->getName(), $fields['dummy_user_text'] );
-               $this->assertSame( $user->getActorId(), $fields['dummy_actor'] );
+               if ( $stage & SCHEMA_COMPAT_WRITE_OLD ) {
+                       $this->assertSame( $user->getId(), $fields['dummy_user'] );
+                       $this->assertSame( $user->getName(), $fields['dummy_user_text'] );
+               } else {
+                       $this->assertArrayNotHasKey( 'dummy_user', $fields );
+                       $this->assertArrayNotHasKey( 'dummy_user_text', $fields );
+               }
+               if ( $stage & SCHEMA_COMPAT_WRITE_NEW ) {
+                       $this->assertSame( $user->getActorId(), $fields['dummy_actor'] );
+               } else {
+                       $this->assertArrayNotHasKey( 'dummy_actor', $fields );
+               }
        }
 
        public function testNewMigration() {
@@ -716,7 +721,7 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
         * @param string $isNotAnon
         */
        public function testIsAnon( $stage, $isAnon, $isNotAnon ) {
-               $m = $this->makeMigration( $stage );
+               $m = new ActorMigration( $stage );
                $this->assertSame( $isAnon, $m->isAnon( 'foo' ) );
                $this->assertSame( $isNotAnon, $m->isNotAnon( 'foo' ) );
        }