Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
RegistrationFormTest.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  */
11 class RegistrationFormTest extends CDbTestCase
12 {
13  private static $username = 'john';
14 
15  public static function setUpBeforeClass()
16  {
17  $_POST['ajax'] = 'registration-form';
18  User::model()->deleteAll();
19  }
20 
21  public static function tearDownAfterClass()
22  {
23  User::model()->deleteAll();
24  }
25 
26  public function testCreateUsernameUnique()
27  {
28  Yii::app()->getModule('user')->usernameUnique = true;
29  Yii::app()->getModule('user')->usernameRequired = true;
30 
31  $username = self::$username;
32  $form = new RegistrationForm();
33  $form->attributes = array(
34  'username' => $username,
35  'email' => "$username@$username.com",
36  'password' => $username,
37  'verifyPassword' => $username
38  );
39  $this->assertTrue($form->validate());
40  $form->attributes = array(
41  'password' => UserModule::encrypting($username),
42  'verifyPassword' => UserModule::encrypting($username)
43  );
44  $this->assertTrue($form->save());
45 
46  $form = new RegistrationForm();
47  $form->attributes = array(
48  'username' => $username,
49  'email' => "$username@$username.com",
50  'password' => $username,
51  'verifyPassword' => $username
52  );
53  $this->assertFalse($form->validate());
54 
55  $this->assertNotEmpty($form->getError('username'));
56  $this->assertNotEmpty($form->getError('email'));
57  }
58 
59  /**
60  * @depends testCreateUsernameUnique
61  */
62  public function testCreateUsernameNotUnique()
63  {
64  Yii::app()->getModule('user')->usernameUnique = false;
65  Yii::app()->getModule('user')->usernameRequired = true;
66 
67  $username = self::$username;
68  $form = new RegistrationForm();
69  $form->attributes = array(
70  'username' => $username,
71  'email' => "$username@$username.com",
72  'password' => $username,
73  'verifyPassword' => $username
74  );
75  $this->assertFalse($form->validate());
76  }
77 
78  public function testCreateUsernameNotRequired()
79  {
80  Yii::app()->getModule('user')->usernameUnique = true;
81  Yii::app()->getModule('user')->usernameRequired = false;
82 
83  $username = self::$username . rand();
84  $form = new RegistrationForm();
85  $form->attributes = array(
86  'username' => $username,
87  'email' => "$username@$username.com",
88  'password' => $username,
89  'verifyPassword' => $username
90  );
91  $this->assertTrue($form->validate());
92  }
93 
94 }