Merge "Displaying protection expiry date and time in action=info"
[lhc/web/wiklou.git] / tests / phpunit / includes / UserTest.php
index c3cb193..b74a7ea 100644 (file)
@@ -306,7 +306,10 @@ class UserTest extends MediaWikiTestCase {
         * @covers User::isValidPassword()
         */
        public function testCheckPasswordValidity() {
-               $this->setMwGlobals( 'wgMinimalPasswordLength', 6 );
+               $this->setMwGlobals( array(
+                       'wgMinimalPasswordLength' => 6,
+                       'wgMaximalPasswordLength' => 30,
+               ) );
                $user = User::newFromName( 'Useruser' );
                // Sanity
                $this->assertTrue( $user->isValidPassword( 'Password1234' ) );
@@ -314,10 +317,19 @@ class UserTest extends MediaWikiTestCase {
                // Minimum length
                $this->assertFalse( $user->isValidPassword( 'a' ) );
                $this->assertFalse( $user->checkPasswordValidity( 'a' )->isGood() );
+               $this->assertTrue( $user->checkPasswordValidity( 'a' )->isOK() );
                $this->assertEquals( 'passwordtooshort', $user->getPasswordValidity( 'a' ) );
 
+               // Maximum length
+               $longPass = str_repeat( 'a', 31 );
+               $this->assertFalse( $user->isValidPassword( $longPass ) );
+               $this->assertFalse( $user->checkPasswordValidity( $longPass )->isGood() );
+               $this->assertFalse( $user->checkPasswordValidity( $longPass )->isOK() );
+               $this->assertEquals( 'passwordtoolong', $user->getPasswordValidity( $longPass ) );
+
                // Matches username
                $this->assertFalse( $user->checkPasswordValidity( 'Useruser' )->isGood() );
+               $this->assertTrue( $user->checkPasswordValidity( 'Useruser' )->isOK() );
                $this->assertEquals( 'password-name-match', $user->getPasswordValidity( 'Useruser' ) );
 
                // On the forbidden list
@@ -332,8 +344,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 +353,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' ),
@@ -385,4 +397,32 @@ class UserTest extends MediaWikiTestCase {
                $sixth = User::newFromName( 'EqualUnitTestUser' );
                $this->assertTrue( $fifth->equals( $sixth ) );
        }
+
+       /**
+        * @covers User::getId
+        */
+       public function testGetId() {
+               $user = User::newFromName( 'UTSysop' );
+               $this->assertTrue( $user->getId() > 0 );
+
+       }
+
+       /**
+        * @covers User::isLoggedIn
+        * @covers User::isAnon
+        */
+       public function testLoggedIn() {
+               $user = User::newFromName( 'UTSysop' );
+               $this->assertTrue( $user->isLoggedIn() );
+               $this->assertFalse( $user->isAnon() );
+
+               // Non-existent users are perceived as anonymous
+               $user = User::newFromName( 'UTNonexistent' );
+               $this->assertFalse( $user->isLoggedIn() );
+               $this->assertTrue( $user->isAnon() );
+
+               $user = new User;
+               $this->assertFalse( $user->isLoggedIn() );
+               $this->assertTrue( $user->isAnon() );
+       }
 }