Код модели подтверждения через email теперь является первичным ключом тамблицы

Реализована форма подтверждения email, обмазана тестами
Слегка отрефакторена форма регистрации и авторизации в пользу выноса части логики в общего родителя
Проект зачищен от стандартных тестовых параметров
Пофикшены методы доступа к API
This commit is contained in:
ErickSkrauch
2016-01-21 00:14:29 +03:00
parent 44aaea2c08
commit 7e90f1838e
30 changed files with 430 additions and 107 deletions

View File

@ -0,0 +1,31 @@
<?php
namespace tests\codeception\api\models;
use api\models\BaseApiForm;
use Codeception\Specify;
use tests\codeception\api\unit\TestCase;
class BaseApiFormTest extends TestCase {
use Specify;
public function testLoad() {
$model = new DummyTestModel();
$this->specify('model should load data without ModelName array scope', function() use ($model) {
expect('model successful load data without prefix', $model->load(['field' => 'test-data']))->true();
expect('field is set as passed data', $model->field)->equals('test-data');
});
}
}
class DummyTestModel extends BaseApiForm {
public $field;
public function rules() {
return [
['field', 'safe'],
];
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace tests\codeception\api\models;
use api\models\BaseKeyConfirmationForm;
use Codeception\Specify;
use tests\codeception\api\unit\DbTestCase;
use tests\codeception\common\fixtures\EmailActivationFixture;
use Yii;
/**
* @property array $emailActivations
*/
class BaseKeyConfirmationFormTest extends DbTestCase {
use Specify;
public function fixtures() {
return [
'emailActivations' => [
'class' => EmailActivationFixture::class,
'dataFile' => '@tests/codeception/common/fixtures/data/email-activations.php',
],
];
}
protected function createModel($key = null) {
return new BaseKeyConfirmationForm([
'key' => $key,
]);
}
public function testEmptyKey() {
$model = $this->createModel();
$this->specify('get error.key_is_required with validating empty key field', function () use ($model) {
expect('model should don\'t pass validation', $model->validate())->false();
expect('error messages should be set', $model->errors)->equals([
'key' => [
'error.key_is_required',
],
]);
});
}
public function testIncorrectKey() {
$model = $this->createModel('not-exists-key');
$this->specify('get error.key_not_exists with validation wrong key', function () use ($model) {
expect('model should don\'t pass validation', $model->validate())->false();
expect('error messages should be set', $model->errors)->equals([
'key' => [
'error.key_not_exists',
],
]);
});
}
public function testCorrectKey() {
$model = $this->createModel($this->emailActivations[0]['key']);
$this->specify('no errors if key exists', function () use ($model) {
expect('model should pass validation', $model->validate())->true();
});
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace tests\codeception\api\models;
use api\models\ConfirmEmailForm;
use Codeception\Specify;
use common\models\Account;
use common\models\EmailActivation;
use tests\codeception\api\unit\DbTestCase;
use tests\codeception\common\fixtures\EmailActivationFixture;
use Yii;
/**
* @property array $emailActivations
*/
class ConfirmEmailFormTest extends DbTestCase {
use Specify;
public function fixtures() {
return [
'emailActivations' => [
'class' => EmailActivationFixture::class,
'dataFile' => '@tests/codeception/common/fixtures/data/email-activations.php',
],
];
}
protected function createModel($key) {
return new ConfirmEmailForm([
'key' => $key,
]);
}
public function testValidInput() {
$fixture = $this->emailActivations[0];
$model = $this->createModel($fixture['key']);
$this->specify('expect true result', function() use ($model, $fixture) {
expect('model return successful result', $model->confirm())->true();
expect('email activation key is not exist', EmailActivation::find()->andWhere(['key' => $fixture['key']])->exists())->false();
/** @var Account $user */
$user = Account::findOne($fixture['account_id']);
expect('user status changed to active', $user->status)->equals(Account::STATUS_ACTIVE);
});
}
}

View File

@ -7,6 +7,9 @@ use tests\codeception\api\unit\DbTestCase;
use tests\codeception\common\fixtures\AccountFixture;
use Yii;
/**
* @property array $accounts
*/
class LoginFormTest extends DbTestCase {
use Specify;
@ -17,8 +20,8 @@ class LoginFormTest extends DbTestCase {
public function fixtures() {
return [
'account' => [
'class' => AccountFixture::className(),
'accounts' => [
'class' => AccountFixture::class,
'dataFile' => '@tests/codeception/common/fixtures/data/accounts.php',
],
];

View File

@ -9,6 +9,9 @@ use tests\codeception\api\unit\DbTestCase;
use tests\codeception\common\fixtures\AccountFixture;
use Yii;
/**
* @property array $accounts
*/
class RegistrationFormTest extends DbTestCase {
use Specify;
@ -31,8 +34,8 @@ class RegistrationFormTest extends DbTestCase {
public function fixtures() {
return [
'account' => [
'class' => AccountFixture::className(),
'accounts' => [
'class' => AccountFixture::class,
'dataFile' => '@tests/codeception/common/fixtures/data/accounts.php',
],
];