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

Удалено тестовое окружение 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,10 +0,0 @@
<?php
use tests\codeception\api\FunctionalTester;
use tests\codeception\api\_pages\AboutPage;
/* @var $scenario Codeception\Scenario */
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that about works');
AboutPage::openBy($I);
$I->see('About', 'h1');

View File

@ -1,12 +0,0 @@
<?php
use tests\codeception\api\FunctionalTester;
/* @var $scenario Codeception\Scenario */
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that home page works');
$I->amOnPage(Yii::$app->homeUrl);
$I->see('My Company');
$I->seeLink('About');
$I->click('About');
$I->see('This is the About page.');

View File

@ -1,40 +0,0 @@
<?php
use tests\codeception\api\_pages\LoginRoute;
use tests\codeception\api\FunctionalTester;
/* @var $scenario Codeception\Scenario */
$I = new FunctionalTester($scenario);
$I->wantTo('ensure login page works');
$loginPage = LoginRoute::openBy($I);
$I->amGoingTo('submit login form with no data');
$loginPage->login('', '');
$I->expectTo('see validations errors');
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'email' => [
'error.email_required',
],
'password' => [
'error.password_required',
],
],
]);
/*
$I->amGoingTo('try to login with wrong credentials');
$I->expectTo('see validations errors');
$loginPage->login('', 'wrong');
$I->expectTo('see validations errors');
$I->see('Incorrect username or password.', '.help-block');
$I->amGoingTo('try to login with correct credentials');
$loginPage->login('erau', 'password_0');
$I->expectTo('see that user is logged');
$I->seeLink('Logout (erau)');
$I->dontSeeLink('Login');
$I->dontSeeLink('Signup');
*/

View File

@ -0,0 +1,137 @@
<?php
namespace tests\codeception\api;
use tests\codeception\api\_pages\LoginRoute;
class LoginCest {
public function _before(FunctionalTester $I) {
}
public function _after(FunctionalTester $I) {
}
public function testLoginEmailOrUsername(FunctionalTester $I) {
$route = new LoginRoute($I);
$I->wantTo('see error.login_required expected if login is not set');
$route->login();
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'login' => 'error.login_required',
],
]);
$I->wantTo('see error.login_not_exist expected if username not exists in database');
$route->login('non-exist-username');
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'login' => 'error.login_not_exist',
],
]);
$I->wantTo('see error.login_not_exist expected if email not exists in database');
$route->login('not-exist@user.com');
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'login' => 'error.login_not_exist',
],
]);
$I->wantTo('don\'t see errors on login field if username is correct and exists in database');
$route->login('Admin');
$I->canSeeResponseContainsJson([
'success' => false,
]);
$I->cantSeeResponseJsonMatchesJsonPath('$.errors.login');
$I->wantTo('don\'t see errors on login field if email is correct and exists in database');
$route->login('admin@ely.by');
$I->canSeeResponseContainsJson([
'success' => false,
]);
$I->cantSeeResponseJsonMatchesJsonPath('$.errors.login');
}
public function testLoginPassword(FunctionalTester $I) {
$route = new LoginRoute($I);
$I->wantTo('see password doesn\'t have errors if email or username not set');
$route->login();
$I->canSeeResponseContainsJson([
'success' => false,
]);
$I->cantSeeResponseJsonMatchesJsonPath('$.errors.password');
$I->wantTo('see password doesn\'t have errors if username not exists in database');
$route->login('non-exist-username', 'random-password');
$I->canSeeResponseContainsJson([
'success' => false,
]);
$I->cantSeeResponseJsonMatchesJsonPath('$.errors.password');
$I->wantTo('see password doesn\'t has errors if email not exists in database');
$route->login('not-exist@user.com', 'random-password');
$I->canSeeResponseContainsJson([
'success' => false,
]);
$I->cantSeeResponseJsonMatchesJsonPath('$.errors.password');
$I->wantTo('see error.password_incorrect if email correct, but password wrong');
$route->login('admin@ely.by', 'wrong-password');
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'password' => 'error.password_incorrect',
],
]);
$I->wantTo('see error.password_incorrect if username correct, but password wrong');
$route->login('Admin', 'wrong-password');
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'password' => 'error.password_incorrect',
],
]);
}
public function testLoginByUsernameCorrect(FunctionalTester $I) {
$route = new LoginRoute($I);
$I->wantTo('login into account using correct username and password');
$route->login('Admin', 'password_0');
$I->canSeeResponseContainsJson([
'success' => true,
]);
$I->cantSeeResponseJsonMatchesJsonPath('$.errors');
}
public function testLoginByEmailCorrect(FunctionalTester $I) {
$route = new LoginRoute($I);
$I->wantTo('login into account using correct email and password');
$route->login('admin@ely.by', 'password_0');
$I->canSeeResponseContainsJson([
'success' => true,
]);
$I->cantSeeResponseJsonMatchesJsonPath('$.errors');
}
public function testLoginInAccWithPasswordMethod(FunctionalTester $I) {
$route = new LoginRoute($I);
$I->wantTo('login into account with old password hash function using correct username and password');
$route->login('AccWithOldPassword', '12345678');
$I->canSeeResponseContainsJson([
'success' => true,
]);
$I->cantSeeResponseJsonMatchesJsonPath('$.errors');
}
}

View File

@ -0,0 +1,224 @@
<?php
namespace tests\codeception\api\functional;
use Codeception\Specify;
use common\models\Account;
use tests\codeception\api\_pages\RegisterRoute;
use tests\codeception\api\FunctionalTester;
class RegisterCest {
public function _after() {
Account::deleteAll([
'email' => 'erickskrauch@ely.by',
'username' => 'ErickSkrauch',
]);
}
public function testIncorrectRegistration(FunctionalTester $I) {
$route = new RegisterRoute($I);
$I->wantTo('get error.you_must_accept_rules if we don\'t accept rules');
$route->send([
'username' => 'ErickSkrauch',
'email' => 'erickskrauch@ely.by',
'password' => 'some_password',
'rePassword' => 'some_password',
]);
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'rulesAgreement' => 'error.you_must_accept_rules',
],
]);
$I->wantTo('don\'t see error.you_must_accept_rules if we accept rules');
$route->send([
'rulesAgreement' => true,
]);
$I->cantSeeResponseContainsJson([
'errors' => [
'rulesAgreement' => 'error.you_must_accept_rules',
],
]);
$I->wantTo('see error.username_required if username is not set');
$route->send([
'username' => '',
'email' => '',
'password' => '',
'rePassword' => '',
'rulesAgreement' => true,
]);
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'username' => 'error.username_required',
],
]);
$I->wantTo('don\'t see error.username_required if username is not set');
$route->send([
'username' => 'valid_nickname',
'email' => '',
'password' => '',
'rePassword' => '',
'rulesAgreement' => true,
]);
$I->cantSeeResponseContainsJson([
'errors' => [
'username' => 'error.username_required',
],
]);
$I->wantTo('see error.email_required if email is not set');
$route->send([
'username' => 'valid_nickname',
'email' => '',
'password' => '',
'rePassword' => '',
'rulesAgreement' => true,
]);
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'email' => 'error.email_required',
],
]);
$I->wantTo('see error.email_invalid if email is set, but invalid');
$route->send([
'username' => 'valid_nickname',
'email' => 'invalid@email',
'password' => '',
'rePassword' => '',
'rulesAgreement' => true,
]);
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'email' => 'error.email_invalid',
],
]);
$I->wantTo('see error.email_invalid if email is set, valid, but domain doesn\'t exist or don\'t have mx record');
$route->send([
'username' => 'valid_nickname',
'email' => 'invalid@govnomail.com',
'password' => '',
'rePassword' => '',
'rulesAgreement' => true,
]);
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'email' => 'error.email_invalid',
],
]);
$I->wantTo('see error.email_not_available if email is set, fully valid, but not available for registration');
$route->send([
'username' => 'valid_nickname',
'email' => 'admin@ely.by',
'password' => '',
'rePassword' => '',
'rulesAgreement' => true,
]);
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'email' => 'error.email_not_available',
],
]);
$I->wantTo('don\'t see errors on email if all valid');
$route->send([
'username' => 'valid_nickname',
'email' => 'erickskrauch@ely.by',
'password' => '',
'rePassword' => '',
'rulesAgreement' => true,
]);
$I->cantSeeResponseJsonMatchesJsonPath('$.errors.email');
$I->wantTo('see error.password_required if password is not set');
$route->send([
'username' => 'valid_nickname',
'email' => 'erickskrauch@ely.by',
'password' => '',
'rePassword' => '',
'rulesAgreement' => true,
]);
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'password' => 'error.password_required',
],
]);
$I->wantTo('see error.password_too_short before it will be compared with rePassword');
$route->send([
'username' => 'valid_nickname',
'email' => 'correct-email@ely.by',
'password' => 'short',
'rePassword' => 'password',
'rulesAgreement' => true,
]);
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'password' => 'error.password_too_short',
],
]);
$I->cantSeeResponseJsonMatchesJsonPath('$.errors.rePassword');
$I->wantTo('see error.rePassword_required if password valid and rePassword not set');
$route->send([
'username' => 'valid_nickname',
'email' => 'correct-email@ely.by',
'password' => 'valid-password',
'rePassword' => '',
'rulesAgreement' => true,
]);
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'rePassword' => 'error.rePassword_required',
],
]);
$I->wantTo('see error.rePassword_does_not_match if password valid and rePassword donen\'t match it');
$route->send([
'username' => 'valid_nickname',
'email' => 'correct-email@ely.by',
'password' => 'valid-password',
'rePassword' => 'password',
'rulesAgreement' => true,
]);
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
'rePassword' => 'error.rePassword_does_not_match',
],
]);
$I->cantSeeResponseJsonMatchesJsonPath('$.errors.password');
}
public function testUserCorrectRegistration(FunctionalTester $I) {
$route = new RegisterRoute($I);
$I->wantTo('ensure that signup works');
$route->send([
'username' => 'some_username',
'email' => 'some_email@example.com',
'password' => 'some_password',
'rePassword' => 'some_password',
'rulesAgreement' => true,
]);
$I->canSeeResponseCodeIs(200);
$I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson(['success' => true]);
$I->cantSeeResponseJsonMatchesJsonPath('$.errors');
}
}

View File

@ -1,90 +0,0 @@
<?php
namespace tests\codeception\api\functional;
use tests\codeception\api\_pages\SignupPage;
use common\models\Account;
class SignupCest
{
/**
* This method is called before each cest class test method
* @param \Codeception\Event\TestEvent $event
*/
public function _before($event)
{
}
/**
* This method is called after each cest class test method, even if test failed.
* @param \Codeception\Event\TestEvent $event
*/
public function _after($event)
{
Account::deleteAll([
'email' => 'tester.email@example.com',
'username' => 'tester',
]);
}
/**
* This method is called when test fails.
* @param \Codeception\Event\FailEvent $event
*/
public function _fail($event)
{
}
/**
*
* @param \codeception_api\FunctionalTester $I
* @param \Codeception\Scenario $scenario
*/
public function testUserSignup($I, $scenario)
{
$I->wantTo('ensure that signup works');
$signupPage = SignupPage::openBy($I);
$I->see('Signup', 'h1');
$I->see('Please fill out the following fields to signup:');
$I->amGoingTo('submit signup form with no data');
$signupPage->submit([]);
$I->expectTo('see validation errors');
$I->see('Username cannot be blank.', '.help-block');
$I->see('Email cannot be blank.', '.help-block');
$I->see('Password cannot be blank.', '.help-block');
$I->amGoingTo('submit signup form with not correct email');
$signupPage->submit([
'username' => 'tester',
'email' => 'tester.email',
'password' => 'tester_password',
]);
$I->expectTo('see that email address is wrong');
$I->dontSee('Username cannot be blank.', '.help-block');
$I->dontSee('Password cannot be blank.', '.help-block');
$I->see('Email is not a valid email address.', '.help-block');
$I->amGoingTo('submit signup form with correct email');
$signupPage->submit([
'username' => 'tester',
'email' => 'tester.email@example.com',
'password' => 'tester_password',
]);
$I->expectTo('see that user is created');
$I->seeRecord('common\models\User', [
'username' => 'tester',
'email' => 'tester.email@example.com',
]);
$I->expectTo('see that user logged in');
$I->seeLink('Logout (tester)');
}
}