SignupFormTest.php 1.43 KB
Newer Older
1 2 3 4 5 6
<?php

namespace frontend\tests\unit\models;

use frontend\tests\unit\DbTestCase;
use common\tests\fixtures\UserFixture;
7 8
use Codeception\Specify;
use frontend\models\SignupForm;
9

Mark committed
10
class SignupFormTest extends DbTestCase
11 12
{

13
    use Specify;
14 15 16

    public function testCorrectSignup()
    {
17 18 19 20 21
        $model = new SignupForm([
            'username' => 'some_username',
            'email' => 'some_email@example.com',
            'password' => 'some_password',
        ]);
22 23

        $user = $model->signup();
24 25 26

        $this->assertInstanceOf('common\models\User', $user, 'user should be valid');

27 28 29 30 31 32 33
        expect('username should be correct', $user->username)->equals('some_username');
        expect('email should be correct', $user->email)->equals('some_email@example.com');
        expect('password should be correct', $user->validatePassword('some_password'))->true();
    }

    public function testNotCorrectSignup()
    {
34 35 36 37 38
        $model = new SignupForm([
            'username' => 'troy.becker',
            'email' => 'nicolas.dianna@hotmail.com',
            'password' => 'some_password',
        ]);
39

40
        expect('username and email are in use, user should not be created', $model->signup())->null();
41 42 43 44 45 46 47
    }

    public function fixtures()
    {
        return [
            'user' => [
                'class' => UserFixture::className(),
48
                'dataFile' => '@frontend/tests/unit/fixtures/data/models/user.php',
49 50 51
            ],
        ];
    }
52

53
}