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

namespace frontend\tests\unit\models;

use frontend\tests\unit\DbTestCase;
use common\tests\fixtures\UserFixture;

Mark committed
8
class SignupFormTest extends DbTestCase
9 10 11 12 13 14
{

	use \Codeception\Specify;

	public function testCorrectSignup()
	{
AlexGx committed
15
		$model = $this->getMock('frontend\models\SignupForm', ['validate']);
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
		$model->expects($this->once())->method('validate')->will($this->returnValue(true));

		$model->username = 'some_username';
		$model->email = 'some_email@example.com';
		$model->password = 'some_password';

		$user = $model->signup();
		$this->assertInstanceOf('common\models\User', $user);
		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()
	{
AlexGx committed
31
		$model = $this->getMock('frontend\models\SignupForm', ['validate']);
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
		$model->expects($this->once())->method('validate')->will($this->returnValue(false));

		expect('user should not be created', $model->signup())->null();
	}

	public function fixtures()
	{
		return [
			'user' => [
				'class' => UserFixture::className(),
				'dataFile' => false, //do not load test data, only table cleanup
			],
		];
	}
}