* @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' ) );
// 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
$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() );
+ }
}