1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace yii2mod\user\tests\forms; |
4
|
|
|
|
5
|
|
|
use yii2mod\user\models\SignupForm; |
6
|
|
|
use yii2mod\user\models\UserModel; |
7
|
|
|
use yii2mod\user\tests\TestCase; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class SignupFormTest |
11
|
|
|
* |
12
|
|
|
* @package yii2mod\user\tests\forms |
13
|
|
|
*/ |
14
|
|
|
class SignupFormTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
public function testSignupWithoutCredentials() |
17
|
|
|
{ |
18
|
|
|
$model = new SignupForm(); |
19
|
|
|
|
20
|
|
|
$this->assertNull($model->signup()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testSignupWithAlreadyExistUsername() |
24
|
|
|
{ |
25
|
|
|
$model = new SignupForm(); |
26
|
|
|
$model->email = '[email protected]'; |
27
|
|
|
$model->password = 'password'; |
28
|
|
|
$model->username = 'demo'; |
29
|
|
|
|
30
|
|
|
$this->assertNull($model->signup()); |
31
|
|
|
$this->assertArrayHasKey('username', $model->errors); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testSignupWithAlreadyExistEmail() |
35
|
|
|
{ |
36
|
|
|
$model = new SignupForm(); |
37
|
|
|
$model->email = '[email protected]'; |
38
|
|
|
$model->password = 'password'; |
39
|
|
|
$model->username = 'demo'; |
40
|
|
|
|
41
|
|
|
$this->assertNull($model->signup()); |
42
|
|
|
$this->assertNull($model->getUser()); |
43
|
|
|
$this->assertArrayHasKey('email', $model->errors); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testSignupCorrect() |
47
|
|
|
{ |
48
|
|
|
$model = new SignupForm(); |
49
|
|
|
$model->email = '[email protected]'; |
50
|
|
|
$model->password = 'password'; |
51
|
|
|
$model->username = 'demo2'; |
52
|
|
|
|
53
|
|
|
$this->assertInstanceOf(UserModel::class, $model->signup()); |
54
|
|
|
$this->assertInstanceOf(UserModel::class, $model->getUser()); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|