Отрефакторены тесты

Удалено тестовое окружение acceptance
Удалена часть потенциально ненужных тестов
Добавлена логика для формы регистрации
Добавлена таблица для хранения ключей активации по E-mail
Добавлены тесты для формы регистрации
Реорганизован роутинг
Добавлен компонент для ReCaptcha2
This commit is contained in:
ErickSkrauch
2016-01-15 12:21:27 +03:00
parent 45c31dfbbe
commit 44aaea2c08
56 changed files with 1075 additions and 972 deletions

View File

@@ -1,4 +1,3 @@
# these files are auto generated by codeception build
/unit/UnitTester.php
/functional/FunctionalTester.php
/acceptance/AcceptanceTester.php

View File

@@ -2,19 +2,16 @@
namespace tests\codeception\common\_support;
use tests\codeception\common\fixtures\UserFixture;
use Codeception\Module;
use tests\codeception\common\fixtures\AccountFixture;
use yii\test\FixtureTrait;
use yii\test\InitDbFixture;
/**
* This helper is used to populate the database with needed fixtures before any tests are run.
* In this example, the database is populated with the demo login user, which is used in acceptance
* and functional tests. All fixtures will be loaded before the suite is started and unloaded after it
* completes.
* All fixtures will be loaded before the suite is started and unloaded after it completes.
*/
class FixtureHelper extends Module
{
class FixtureHelper extends Module {
/**
* Redeclare visibility because codeception includes all public methods that do not start with "_"
@@ -31,27 +28,25 @@ class FixtureHelper extends Module
/**
* Method called before any suite tests run. Loads User fixture login user
* to use in acceptance and functional tests.
* to use in functional tests.
*
* @param array $settings
*/
public function _beforeSuite($settings = [])
{
public function _beforeSuite($settings = []) {
$this->loadFixtures();
}
/**
* Method is called after all suite tests run
*/
public function _afterSuite()
{
public function _afterSuite() {
$this->unloadFixtures();
}
/**
* @inheritdoc
*/
public function globalFixtures()
{
public function globalFixtures() {
return [
InitDbFixture::className(),
];
@@ -60,13 +55,12 @@ class FixtureHelper extends Module
/**
* @inheritdoc
*/
public function fixtures()
{
public function fixtures() {
return [
//'user' => [
// 'class' => UserFixture::className(),
// 'dataFile' => '@tests/codeception/common/fixtures/data/init_login.php',
//],
'accounts' => [
'class' => AccountFixture::class,
'dataFile' => '@tests/codeception/common/fixtures/data/accounts.php',
],
];
}
}

View File

@@ -0,0 +1,29 @@
<?php
return [
'admin' => [
'id' => 1,
'uuid' => 'df936908-b2e1-544d-96f8-2977ec213022',
'username' => 'Admin',
'email' => 'admin@ely.by',
'password_hash' => '$2y$13$CXT0Rkle1EMJ/c1l5bylL.EylfmQ39O5JlHJVFpNn618OUS1HwaIi', # password_0
'password_hash_strategy' => 1,
'password_reset_token' => NULL,
'auth_key' => 'iwTNae9t34OmnK6l4vT4IeaTk-YWI2Rv',
'status' => 10,
'created_at' => 1451775316,
'updated_at' => 1451775316,
],
'user-with-old-password-type' => [
'id' => 2,
'uuid' => 'bdc239f0-8a22-518d-8b93-f02d4827c3eb',
'username' => 'AccWithOldPassword',
'email' => 'erickskrauch123@yandex.ru',
'password_hash' => '133c00c463cbd3e491c28cb653ce4718', # 12345678
'password_hash_strategy' => 0,
'password_reset_token' => NULL,
'auth_key' => 'ltTNae9t34OmnK6l4vT4IeaTk-YWI2Rv',
'status' => 10,
'created_at' => 1385225069,
'updated_at' => 1385225069,
],
];

View File

@@ -1,93 +0,0 @@
<?php
namespace tests\codeception\common\unit\models;
use api\models\LoginForm;
use Codeception\Specify;
use tests\codeception\common\fixtures\UserFixture;
use tests\codeception\common\unit\DbTestCase;
use Yii;
/**
* Login form test
*/
class LoginFormTest extends DbTestCase
{
use Specify;
public function setUp()
{
parent::setUp();
Yii::configure(Yii::$app, [
'components' => [
'user' => [
'class' => 'yii\web\User',
'identityClass' => 'common\models\User',
],
],
]);
}
protected function tearDown()
{
Yii::$app->user->logout();
parent::tearDown();
}
public function testLoginNoUser()
{
$model = new LoginForm([
'username' => 'not_existing_username',
'password' => 'not_existing_password',
]);
$this->specify('user should not be able to login, when there is no identity', function () use ($model) {
expect('model should not login user', $model->login())->false();
expect('user should not be logged in', Yii::$app->user->isGuest)->true();
});
}
public function testLoginWrongPassword()
{
$model = new LoginForm([
'username' => 'bayer.hudson',
'password' => 'wrong_password',
]);
$this->specify('user should not be able to login with wrong password', function () use ($model) {
expect('model should not login user', $model->login())->false();
expect('error message should be set', $model->errors)->hasKey('password');
expect('user should not be logged in', Yii::$app->user->isGuest)->true();
});
}
public function testLoginCorrect()
{
$model = new LoginForm([
'username' => 'bayer.hudson',
'password' => 'password_0',
]);
$this->specify('user should be able to login with correct credentials', function () use ($model) {
expect('model should login user', $model->login())->true();
expect('error message should not be set', $model->errors)->hasntKey('password');
expect('user should be logged in', Yii::$app->user->isGuest)->false();
});
}
/**
* @inheritdoc
*/
public function fixtures()
{
return [
'user' => [
'class' => UserFixture::className(),
'dataFile' => '@tests/codeception/common/unit/fixtures/data/models/user.php'
],
];
}
}