1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace tests\codeception\frontend\unit\models; |
4
|
|
|
|
5
|
|
|
use tests\codeception\frontend\unit\DbTestCase; |
6
|
|
|
use tests\codeception\common\fixtures\UserFixture; |
7
|
|
|
use Codeception\Specify; |
8
|
|
|
use frontend\models\SignupForm; |
9
|
|
|
|
10
|
|
|
class SignupFormTest extends DbTestCase |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
use Specify; |
14
|
|
|
|
15
|
|
|
public function testCorrectSignup() |
16
|
|
|
{ |
17
|
|
|
$model = new SignupForm([ |
18
|
|
|
'username' => 'some_username', |
19
|
|
|
'email' => '[email protected]', |
20
|
|
|
'password' => 'some_password', |
21
|
|
|
]); |
22
|
|
|
|
23
|
|
|
$user = $model->signup(); |
24
|
|
|
|
25
|
|
|
$this->assertInstanceOf('common\models\User', $user, 'user should be valid'); |
26
|
|
|
|
27
|
|
|
expect('username should be correct', $user->username)->equals('some_username'); |
28
|
|
|
expect('email should be correct', $user->email)->equals('[email protected]'); |
29
|
|
|
expect('password should be correct', $user->validatePassword('some_password'))->true(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testNotCorrectSignup() |
33
|
|
|
{ |
34
|
|
|
$model = new SignupForm([ |
35
|
|
|
'username' => 'troy.becker', |
36
|
|
|
'email' => '[email protected]', |
37
|
|
|
'password' => 'some_password', |
38
|
|
|
]); |
39
|
|
|
|
40
|
|
|
expect('username and email are in use, user should not be created', $model->signup())->null(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function fixtures() |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
'user' => [ |
47
|
|
|
'class' => UserFixture::className(), |
48
|
|
|
'dataFile' => '@tests/codeception/frontend/unit/fixtures/data/models/user.php', |
49
|
|
|
], |
50
|
|
|
]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
} |
54
|
|
|
|