Merge "Gracefully handle redirects in SpecialMyLanguage"
[lhc/web/wiklou.git] / tests / phpunit / includes / UserTest.php
index 8cc2a8e..860529e 100644 (file)
@@ -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 ) );
+       }
 }