diff options
author | Petr Pchelko <ppchelko@wikimedia.org> | 2021-04-06 18:50:30 -0600 |
---|---|---|
committer | Petr Pchelko <ppchelko@wikimedia.org> | 2021-04-06 19:49:53 -0600 |
commit | 9e0c6afaae432dd92c8ed0f8fa1e11fca5cfc9ad (patch) | |
tree | 588211e05e71a8a031bc3926ae497c0e3b73ff63 /tests/phpunit/integration/includes/user | |
parent | c13e02e9a62dd3415408661c5cf5c871a1ff2b15 (diff) | |
download | mediawikicore-9e0c6afaae432dd92c8ed0f8fa1e11fca5cfc9ad.tar.gz mediawikicore-9e0c6afaae432dd92c8ed0f8fa1e11fca5cfc9ad.zip |
Support User:0 in ActorStore
Surprizingly, PHP treats string "0" as false, so user name "0"
was unconditionally rejected by ActorStore. Even more surprizingly,
we actually have an actor with user name "0" [1], so we need to
explicitly check for nulls instead of just checking for falsy.
[1] https://en.wikipedia.org/wiki/User:0
Change-Id: I535c2aee3e109c3f535e40b747a1c7e4508171cb
Diffstat (limited to 'tests/phpunit/integration/includes/user')
-rw-r--r-- | tests/phpunit/integration/includes/user/ActorStoreTest.php | 34 | ||||
-rw-r--r-- | tests/phpunit/integration/includes/user/ActorStoreTestBase.php | 45 |
2 files changed, 48 insertions, 31 deletions
diff --git a/tests/phpunit/integration/includes/user/ActorStoreTest.php b/tests/phpunit/integration/includes/user/ActorStoreTest.php index 813025207eb0..c51942cc29f5 100644 --- a/tests/phpunit/integration/includes/user/ActorStoreTest.php +++ b/tests/phpunit/integration/includes/user/ActorStoreTest.php @@ -82,6 +82,11 @@ class ActorStoreTest extends ActorStoreTestBase { strtolower( self::IP ), // $argument new UserIdentityValue( 0, self::IP, 43 ), // $expected ]; + yield 'getUserIdentityByName, user name 0' => [ + 'getUserIdentityByName', // $method + '0', // $argument + new UserIdentityValue( 26, '0', 46 ), // $expected + ]; yield 'getUserIdentityByUserId, registered' => [ 'getUserIdentityByUserId', // $method 24, // $argument @@ -228,6 +233,11 @@ class ActorStoreTest extends ActorStoreTestBase { (object)[ 'actor_id' => 42, 'actor_name' => 'TestUser', 'actor_user' => 24 ], // $row new UserIdentityValue( 24, 'TestUser', 42, 'acmewiki' ), // $expected ]; + yield 'user name 0' => [ + UserIdentity::LOCAL, // $wikiId + (object)[ 'actor_id' => '46', 'actor_name' => '0', 'actor_user' => 26 ], // $row + new UserIdentityValue( 26, '0', 46 ), // $expected + ]; } /** @@ -289,6 +299,13 @@ class ActorStoreTest extends ActorStoreTestBase { 0, // $userId new UserIdentityValue( 0, 'TestUser', 42 ), // $expected ]; + yield 'user name 0' => [ + UserIdentity::LOCAL, // $wikiId + 46, // $actorId + '0', // $name + 26, // $userId + new UserIdentityValue( 26, '0', 46 ), // $expected + ]; yield 'cross-wiki' => [ 'acmewiki', // $wikiId 42, // $actorId @@ -358,6 +375,12 @@ class ActorStoreTest extends ActorStoreTestBase { }, // $actorCallback 42, // $expected ]; + yield 'registered, zero user name' => [ + static function () { + return new UserIdentityValue( 26, '0', 0 ); + }, // $actorCallback + 46, // $expected + ]; yield 'anon, non-existent, local' => [ static function () { return new UserIdentityValue( 0, '127.1.2.3', 0 ); @@ -459,6 +482,10 @@ class ActorStoreTest extends ActorStoreTestBase { 'testUser', // $actorCallback 42, // $expected ]; + yield 'registered, 0 user name' => [ + '0', // $actorCallback + 46, // $expected + ]; yield 'external, local' => [ 'acme>TestUser', 45, // $expected @@ -572,6 +599,10 @@ class ActorStoreTest extends ActorStoreTestBase { new UserIdentityValue( 24, 'TestUser', 42 ), // $actor 42, // $expected ]; + yield 'registered, 0 user name' => [ + new UserIdentityValue( 26, '0', 46 ), // $actor + 46, // $expected + ]; } /** @@ -653,6 +684,8 @@ class ActorStoreTest extends ActorStoreTestBase { yield [ 'foo|bar', UserNameUtils::RIGOR_VALID, null ]; yield [ '_', UserNameUtils::RIGOR_NONE, '_' ]; yield [ 'test', UserNameUtils::RIGOR_NONE, 'test' ]; + yield [ '', UserNameUtils::RIGOR_NONE, null ]; + yield [ '0', UserNameUtils::RIGOR_NONE, '0' ]; } /** @@ -674,5 +707,4 @@ class ActorStoreTest extends ActorStoreTestBase { $queryBuilder = $store->newSelectQueryBuilder( $this->db ); $this->assertInstanceOf( UserSelectQueryBuilder::class, $queryBuilder ); } - } diff --git a/tests/phpunit/integration/includes/user/ActorStoreTestBase.php b/tests/phpunit/integration/includes/user/ActorStoreTestBase.php index 8350f0039963..c5a8fb7faa9d 100644 --- a/tests/phpunit/integration/includes/user/ActorStoreTestBase.php +++ b/tests/phpunit/integration/includes/user/ActorStoreTestBase.php @@ -19,37 +19,22 @@ abstract class ActorStoreTestBase extends MediaWikiIntegrationTestCase { public function addDBData() { $this->tablesUsed[] = 'actor'; - // Registered - $this->assertTrue( $this->db->insert( - 'actor', - [ 'actor_id' => '42', 'actor_user' => '24', 'actor_name' => 'TestUser' ], - __METHOD__, - [ 'IGNORE' ] - ) ); + $actors = [ + 'registered' => [ 'actor_id' => '42', 'actor_user' => '24', 'actor_name' => 'TestUser' ], + 'anon' => [ 'actor_id' => '43', 'actor_user' => null, 'actor_name' => self::IP ], + 'another registered' => [ 'actor_id' => '44', 'actor_user' => '25', 'actor_name' => 'TestUser1' ], + 'external' => [ 'actor_id' => '45', 'actor_user' => null, 'actor_name' => 'acme>TestUser' ], + 'user name 0' => [ 'actor_id' => '46', 'actor_user' => '26', 'actor_name' => '0' ], + ]; - // Anon - $this->assertTrue( $this->db->insert( - 'actor', - [ 'actor_id' => '43', 'actor_user' => null, 'actor_name' => self::IP ], - __METHOD__, - [ 'IGNORE' ] - ) ); - - // One more registered - $this->assertTrue( $this->db->insert( - 'actor', - [ 'actor_id' => '44', 'actor_user' => '25', 'actor_name' => 'TestUser1' ], - __METHOD__, - [ 'IGNORE' ] - ) ); - - // External - $this->assertTrue( $this->db->insert( - 'actor', - [ 'actor_id' => '45', 'actor_user' => null, 'actor_name' => 'acme>TestUser' ], - __METHOD__, - [ 'IGNORE' ] - ) ); + foreach ( $actors as $description => $row ) { + $this->assertTrue( $this->db->insert( + 'actor', + $row, + __METHOD__, + [ 'IGNORE' ] + ), "Sanity: must create {$description} actor" ); + } } /** |