Add User::equals
[lhc/web/wiklou.git] / tests / phpunit / includes / UserTest.php
index a0c20bb..f5cd1fc 100644 (file)
@@ -281,9 +281,7 @@ class UserTest extends MediaWikiTestCase {
         * @covers User::getPasswordExpired()
         */
        public function testPasswordExpire() {
-               global $wgPasswordExpireGrace;
-               $wgTemp = $wgPasswordExpireGrace;
-               $wgPasswordExpireGrace = 3600 * 24 * 7; // 7 days
+               $this->setMwGlobals( 'wgPasswordExpireGrace', 3600 * 24 * 7 ); // 7 days
 
                $user = User::newFromName( 'UnitTestUser' );
                $user->loadDefaults( 'UnitTestUser' );
@@ -296,8 +294,6 @@ class UserTest extends MediaWikiTestCase {
                $ts = time() - ( 3600 * 24 * 10 ); // 10 days ago
                $user->expirePassword( $ts );
                $this->assertEquals( 'hard', $user->getPasswordExpired() );
-
-               $wgPasswordExpireGrace = $wgTemp;
        }
 
        /**
@@ -346,7 +342,7 @@ class UserTest extends MediaWikiTestCase {
        public static function provideGetCanonicalName() {
                return array(
                        array( ' trailing space ', array( 'creatable' => 'Trailing space' ), 'Trailing spaces' ),
-                       // @todo FIXME: Maybe the createable name should be 'Talk:Username' or false to reject?
+                       // @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' ),
                        array( ' name with # hash', array( 'creatable' => false, 'usable' => false ), 'With hash' ),
@@ -359,4 +355,31 @@ class UserTest extends MediaWikiTestCase {
                                'false' => 'With / slash' ), 'With slash' ),
                );
        }
+
+       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 ) );
+       }
 }