X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FUserTest.php;h=860529e152c413cc645140e0783877c904a00f6f;hb=db00239568969a41148cfdec0a77436f73fe802d;hp=8cc2a8e29e2d431b22279294f6f9287810deafbf;hpb=7746e1458bc052f7458d4c705df6cb327a15293c;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/UserTest.php b/tests/phpunit/includes/UserTest.php index 8cc2a8e29e..860529e152 100644 --- a/tests/phpunit/includes/UserTest.php +++ b/tests/phpunit/includes/UserTest.php @@ -332,8 +332,8 @@ class UserTest extends MediaWikiTestCase { public function testGetCanonicalName( $name, $expectedArray, $msg ) { foreach ( $expectedArray as $validate => $expected ) { $this->assertEquals( - User::getCanonicalName( $name, $validate === 'false' ? false : $validate ), $expected, + User::getCanonicalName( $name, $validate === 'false' ? false : $validate ), $msg . ' (' . $validate . ')' ); } @@ -341,7 +341,7 @@ class UserTest extends MediaWikiTestCase { public static function provideGetCanonicalName() { return array( - array( ' trailing space ', array( 'creatable' => 'Trailing space' ), 'Trailing spaces' ), + array( ' Trailing space ', array( 'creatable' => 'Trailing space' ), 'Trailing spaces' ), // @todo FIXME: Maybe the creatable name should be 'Talk:Username' or false to reject? array( 'Talk:Username', array( 'creatable' => 'Username', 'usable' => 'Username', 'valid' => 'Username', 'false' => 'Talk:Username' ), 'Namespace prefix' ), @@ -355,4 +355,34 @@ class UserTest extends MediaWikiTestCase { 'false' => 'With / slash' ), 'With slash' ), ); } + + /** + * @covers User::equals + */ + public function testEquals() { + $first = User::newFromName( 'EqualUser' ); + $second = User::newFromName( 'EqualUser' ); + + $this->assertTrue( $first->equals( $first ) ); + $this->assertTrue( $first->equals( $second ) ); + $this->assertTrue( $second->equals( $first ) ); + + $third = User::newFromName( '0' ); + $fourth = User::newFromName( '000' ); + + $this->assertFalse( $third->equals( $fourth ) ); + $this->assertFalse( $fourth->equals( $third ) ); + + // Test users loaded from db with id + $user = User::newFromName( 'EqualUnitTestUser' ); + if ( !$user->getId() ) { + $user->addToDatabase(); + } + + $id = $user->getId(); + + $fifth = User::newFromId( $id ); + $sixth = User::newFromName( 'EqualUnitTestUser' ); + $this->assertTrue( $fifth->equals( $sixth ) ); + } }