Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
UserIdentityTest.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  *
10  */
12 {
13  public $fixtures = array(
14  'users' => 'User',
15  );
16 
17  public function testAuthenticationUsername()
18  {
19  Yii::app()->getModule('user')->authField = 'username';
20  $user = $this->users['sample1'];
21  $userIdentity = new UserIdentity($user['username'], $user['password_not_hashed']);
22  $this->assertTrue($userIdentity->authenticate());
23  }
24 
25  public function testAuthenticationEmail()
26  {
27  Yii::app()->getModule('user')->authField = 'email';
28  $user = $this->users['sample1'];
29  $userIdentity = new UserIdentity($user['email'], $user['password_not_hashed']);
30  $this->assertTrue($userIdentity->authenticate());
31  }
32 
33  public function testAuthenticationFailure()
34  {
35  Yii::app()->getModule('user')->authField = 'email';
36  $user = $this->users['sample1'];
37  $userIdentity = new UserIdentity($user['email'] . 'ssss', $user['password_not_hashed']);
38  $userIdentity->authenticate();
39  $this->assertEquals(UserIdentity::ERROR_AUTH_FIELD_INVALID, $userIdentity->errorCode);
40 
41  $userIdentity = new UserIdentity($user['email'], $user['password_not_hashed'] . 'ssss');
42  $userIdentity->authenticate();
43  $this->assertEquals(UserIdentity::ERROR_PASSWORD_INVALID, $userIdentity->errorCode);
44 
45  $user = $this->users['sample3'];
46  $userIdentity = new UserIdentity($user['email'], $user['password_not_hashed']);
47  $userIdentity->authenticate();
48  $this->assertEquals(UserIdentity::ERROR_STATUS_BAN, $userIdentity->errorCode);
49  }
50 }