13 private static $username =
'john';
15 public static function setUpBeforeClass()
17 $_POST[
'ajax'] =
'registration-form';
21 public static function tearDownAfterClass()
26 public function testCreateUsernameUnique()
28 Yii::app()->getModule(
'user')->usernameUnique =
true;
29 Yii::app()->getModule(
'user')->usernameRequired =
true;
31 $username = self::$username;
33 $form->attributes = array(
34 'username' => $username,
35 'email' =>
"$username@$username.com",
36 'password' => $username,
37 'verifyPassword' => $username
39 $this->assertTrue($form->validate());
40 $form->attributes = array(
44 $this->assertTrue($form->save());
47 $form->attributes = array(
48 'username' => $username,
49 'email' =>
"$username@$username.com",
50 'password' => $username,
51 'verifyPassword' => $username
53 $this->assertFalse($form->validate());
55 $this->assertNotEmpty($form->getError(
'username'));
56 $this->assertNotEmpty($form->getError(
'email'));
64 Yii::app()->getModule(
'user')->usernameUnique =
false;
65 Yii::app()->getModule(
'user')->usernameRequired =
true;
67 $username = self::$username;
69 $form->attributes = array(
70 'username' => $username,
71 'email' =>
"$username@$username.com",
72 'password' => $username,
73 'verifyPassword' => $username
75 $this->assertFalse($form->validate());
78 public function testCreateUsernameNotRequired()
80 Yii::app()->getModule(
'user')->usernameUnique =
true;
81 Yii::app()->getModule(
'user')->usernameRequired =
false;
83 $username = self::$username . rand();
85 $form->attributes = array(
86 'username' => $username,
87 'email' =>
"$username@$username.com",
88 'password' => $username,
89 'verifyPassword' => $username
91 $this->assertTrue($form->validate());