mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Отрефакторены тесты
Удалено тестовое окружение acceptance Удалена часть потенциально ненужных тестов Добавлена логика для формы регистрации Добавлена таблица для хранения ключей активации по E-mail Добавлены тесты для формы регистрации Реорганизован роутинг Добавлен компонент для ReCaptcha2
This commit is contained in:
1
tests/codeception/api/.gitignore
vendored
1
tests/codeception/api/.gitignore
vendored
@@ -1,4 +1,3 @@
|
||||
# these files are auto generated by codeception build
|
||||
/unit/UnitTester.php
|
||||
/functional/FunctionalTester.php
|
||||
/acceptance/AcceptanceTester.php
|
||||
|
@@ -14,7 +14,7 @@ require_once(YII_APP_BASE_PATH . '/api/config/bootstrap.php');
|
||||
|
||||
// set correct script paths
|
||||
|
||||
// the entry script file path for functional and acceptance tests
|
||||
// the entry script file path for functional tests
|
||||
$_SERVER['SCRIPT_FILENAME'] = API_ENTRY_FILE;
|
||||
$_SERVER['SCRIPT_NAME'] = API_ENTRY_URL;
|
||||
$_SERVER['SERVER_NAME'] = parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_HOST);
|
||||
|
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\_pages;
|
||||
|
||||
use yii\codeception\BasePage;
|
||||
|
||||
/**
|
||||
* Represents about page
|
||||
* @property \codeception_api\AcceptanceTester|\codeception_api\FunctionalTester $actor
|
||||
*/
|
||||
class AboutPage extends BasePage
|
||||
{
|
||||
public $route = 'site/about';
|
||||
}
|
@@ -6,21 +6,21 @@ use yii\codeception\BasePage;
|
||||
|
||||
/**
|
||||
* Represents contact page
|
||||
* @property \codeception_api\AcceptanceTester|\codeception_api\FunctionalTester $actor
|
||||
* @property \tests\codeception\api\FunctionalTester $actor
|
||||
*/
|
||||
class ContactPage extends BasePage
|
||||
{
|
||||
class ContactPage extends BasePage {
|
||||
|
||||
public $route = 'site/contact';
|
||||
|
||||
/**
|
||||
* @param array $contactData
|
||||
*/
|
||||
public function submit(array $contactData)
|
||||
{
|
||||
public function submit(array $contactData) {
|
||||
foreach ($contactData as $field => $value) {
|
||||
$inputType = $field === 'body' ? 'textarea' : 'input';
|
||||
$this->actor->fillField($inputType . '[name="ContactForm[' . $field . ']"]', $value);
|
||||
}
|
||||
$this->actor->click('contact-button');
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,16 +4,15 @@ namespace tests\codeception\api\_pages;
|
||||
use yii\codeception\BasePage;
|
||||
|
||||
/**
|
||||
* Represents loging page
|
||||
* @property \tests\codeception\api\FunctionalTester $actor
|
||||
*/
|
||||
class LoginRoute extends BasePage {
|
||||
|
||||
public $route = 'login/authentication/login-info';
|
||||
public $route = ['authentication/login'];
|
||||
|
||||
public function login($email, $password) {
|
||||
public function login($login = '', $password = '') {
|
||||
$this->actor->sendPOST($this->getUrl(), [
|
||||
'email' => $email,
|
||||
'login' => $login,
|
||||
'password' => $password,
|
||||
]);
|
||||
}
|
||||
|
17
tests/codeception/api/_pages/RegisterRoute.php
Normal file
17
tests/codeception/api/_pages/RegisterRoute.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\_pages;
|
||||
|
||||
use yii\codeception\BasePage;
|
||||
|
||||
/**
|
||||
* @property \tests\codeception\api\FunctionalTester $actor
|
||||
*/
|
||||
class RegisterRoute extends BasePage {
|
||||
|
||||
public $route = ['signup/register'];
|
||||
|
||||
public function send(array $registrationData) {
|
||||
$this->actor->sendPOST($this->getUrl(), $registrationData);
|
||||
}
|
||||
|
||||
}
|
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\_pages;
|
||||
|
||||
use \yii\codeception\BasePage;
|
||||
|
||||
/**
|
||||
* Represents signup page
|
||||
* @property \codeception_api\AcceptanceTester|\codeception_api\FunctionalTester $actor
|
||||
*/
|
||||
class SignupPage extends BasePage
|
||||
{
|
||||
|
||||
public $route = 'site/signup';
|
||||
|
||||
/**
|
||||
* @param array $signupData
|
||||
*/
|
||||
public function submit(array $signupData)
|
||||
{
|
||||
foreach ($signupData as $field => $value) {
|
||||
$inputType = $field === 'body' ? 'textarea' : 'input';
|
||||
$this->actor->fillField($inputType . '[name="SignupForm[' . $field . ']"]', $value);
|
||||
}
|
||||
$this->actor->click('signup-button');
|
||||
}
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
# Codeception Test Suite Configuration
|
||||
|
||||
# suite for acceptance tests.
|
||||
# perform tests in browser using the Selenium-like tools.
|
||||
# powered by Mink (http://mink.behat.org).
|
||||
# (tip: that's what your customer will see).
|
||||
# (tip: test your ajax and javascript by one of Mink drivers).
|
||||
|
||||
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
|
||||
|
||||
class_name: AcceptanceTester
|
||||
modules:
|
||||
enabled:
|
||||
- PhpBrowser
|
||||
- tests\codeception\common\_support\FixtureHelper
|
||||
# you can use WebDriver instead of PhpBrowser to test javascript and ajax.
|
||||
# This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium
|
||||
# "restart" option is used by the WebDriver to start each time per test-file new session and cookies,
|
||||
# it is useful if you want to login in your app in each test.
|
||||
# - WebDriver
|
||||
config:
|
||||
PhpBrowser:
|
||||
# PLEASE ADJUST IT TO THE ACTUAL ENTRY POINT WITHOUT PATH INFO
|
||||
url: http://localhost:8080
|
||||
# WebDriver:
|
||||
# url: http://localhost:8080
|
||||
# browser: firefox
|
||||
# restart: true
|
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
use tests\codeception\api\AcceptanceTester;
|
||||
use tests\codeception\api\_pages\AboutPage;
|
||||
|
||||
/* @var $scenario Codeception\Scenario */
|
||||
|
||||
$I = new AcceptanceTester($scenario);
|
||||
$I->wantTo('ensure that about works');
|
||||
AboutPage::openBy($I);
|
||||
$I->see('About', 'h1');
|
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
use tests\codeception\api\AcceptanceTester;
|
||||
use tests\codeception\api\_pages\ContactPage;
|
||||
|
||||
/* @var $scenario Codeception\Scenario */
|
||||
|
||||
$I = new AcceptanceTester($scenario);
|
||||
$I->wantTo('ensure that contact works');
|
||||
|
||||
$contactPage = ContactPage::openBy($I);
|
||||
|
||||
$I->see('Contact', 'h1');
|
||||
|
||||
$I->amGoingTo('submit contact form with no data');
|
||||
$contactPage->submit([]);
|
||||
if (method_exists($I, 'wait')) {
|
||||
$I->wait(3); // only for selenium
|
||||
}
|
||||
$I->expectTo('see validations errors');
|
||||
$I->see('Contact', 'h1');
|
||||
$I->see('Name cannot be blank', '.help-block');
|
||||
$I->see('Email cannot be blank', '.help-block');
|
||||
$I->see('Subject cannot be blank', '.help-block');
|
||||
$I->see('Body cannot be blank', '.help-block');
|
||||
$I->see('The verification code is incorrect', '.help-block');
|
||||
|
||||
$I->amGoingTo('submit contact form with not correct email');
|
||||
$contactPage->submit([
|
||||
'name' => 'tester',
|
||||
'email' => 'tester.email',
|
||||
'subject' => 'test subject',
|
||||
'body' => 'test content',
|
||||
'verifyCode' => 'testme',
|
||||
]);
|
||||
if (method_exists($I, 'wait')) {
|
||||
$I->wait(3); // only for selenium
|
||||
}
|
||||
$I->expectTo('see that email adress is wrong');
|
||||
$I->dontSee('Name cannot be blank', '.help-block');
|
||||
$I->see('Email is not a valid email address.', '.help-block');
|
||||
$I->dontSee('Subject cannot be blank', '.help-block');
|
||||
$I->dontSee('Body cannot be blank', '.help-block');
|
||||
$I->dontSee('The verification code is incorrect', '.help-block');
|
||||
|
||||
$I->amGoingTo('submit contact form with correct data');
|
||||
$contactPage->submit([
|
||||
'name' => 'tester',
|
||||
'email' => 'tester@example.com',
|
||||
'subject' => 'test subject',
|
||||
'body' => 'test content',
|
||||
'verifyCode' => 'testme',
|
||||
]);
|
||||
if (method_exists($I, 'wait')) {
|
||||
$I->wait(3); // only for selenium
|
||||
}
|
||||
$I->see('Thank you for contacting us. We will respond to you as soon as possible.');
|
@@ -1,12 +0,0 @@
|
||||
<?php
|
||||
use tests\codeception\api\AcceptanceTester;
|
||||
|
||||
/* @var $scenario Codeception\Scenario */
|
||||
|
||||
$I = new AcceptanceTester($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.');
|
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
use tests\codeception\api\_pages\LoginRoute;
|
||||
use tests\codeception\api\AcceptanceTester;
|
||||
|
||||
/* @var $scenario Codeception\Scenario */
|
||||
|
||||
$I = new AcceptanceTester($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->see('Username cannot be blank.', '.help-block');
|
||||
$I->see('Password cannot be blank.', '.help-block');
|
||||
|
||||
$I->amGoingTo('try to login with wrong credentials');
|
||||
$I->expectTo('see validations errors');
|
||||
$loginPage->login('admin', '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');
|
||||
/** Uncomment if using WebDriver
|
||||
* $I->click('Logout (erau)');
|
||||
* $I->dontSeeLink('Logout (erau)');
|
||||
* $I->seeLink('Login');
|
||||
*/
|
@@ -1,82 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\acceptance;
|
||||
|
||||
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\AcceptanceTester $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 logged in');
|
||||
$I->seeLink('Logout (tester)');
|
||||
}
|
||||
}
|
@@ -1,2 +0,0 @@
|
||||
<?php
|
||||
new yii\web\Application(require(dirname(dirname(__DIR__)) . '/config/api/acceptance.php'));
|
@@ -12,6 +12,6 @@ settings:
|
||||
memory_limit: 1024M
|
||||
log: true
|
||||
config:
|
||||
# the entry script URL (with host info) for functional and acceptance tests
|
||||
# the entry script URL (with host info) for functional tests
|
||||
# PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL
|
||||
test_entry_url: http://localhost:8080/api/web/index-test.php
|
||||
|
@@ -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');
|
@@ -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.');
|
@@ -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');
|
||||
*/
|
137
tests/codeception/api/functional/LoginCest.php
Normal file
137
tests/codeception/api/functional/LoginCest.php
Normal 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');
|
||||
}
|
||||
|
||||
}
|
224
tests/codeception/api/functional/RegisterCest.php
Normal file
224
tests/codeception/api/functional/RegisterCest.php
Normal 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');
|
||||
}
|
||||
|
||||
}
|
@@ -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)');
|
||||
}
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
return [
|
||||
[
|
||||
'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,
|
||||
],
|
||||
];
|
61
tests/codeception/api/unit/models/LoginFormTest.php
Normal file
61
tests/codeception/api/unit/models/LoginFormTest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\models;
|
||||
|
||||
use api\models\LoginForm;
|
||||
use Codeception\Specify;
|
||||
use tests\codeception\api\unit\DbTestCase;
|
||||
use tests\codeception\common\fixtures\AccountFixture;
|
||||
use Yii;
|
||||
|
||||
class LoginFormTest extends DbTestCase {
|
||||
use Specify;
|
||||
|
||||
protected function tearDown() {
|
||||
Yii::$app->user->logout();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function fixtures() {
|
||||
return [
|
||||
'account' => [
|
||||
'class' => AccountFixture::className(),
|
||||
'dataFile' => '@tests/codeception/common/fixtures/data/accounts.php',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function createModel($login = '', $password = '') {
|
||||
return new LoginForm([
|
||||
'login' => $login,
|
||||
'password' => $password,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testIncorrectLogin() {
|
||||
$model = $this->createModel('not-esist-login', 'fully-invalid-password');
|
||||
$this->specify('get errors and don\'t log in into account with wrong credentials', function () use ($model) {
|
||||
expect('model should not login user', $model->login())->false();
|
||||
expect('error messages should be set', $model->errors)->notEmpty();
|
||||
expect('user should not be logged in', Yii::$app->user->isGuest)->true();
|
||||
});
|
||||
}
|
||||
|
||||
public function testLoginByUsernameCorrect() {
|
||||
$model = $this->createModel('Admin', 'password_0');
|
||||
$this->specify('user should be able to login with correct username and password', function () use ($model) {
|
||||
expect('model should login user', $model->login())->true();
|
||||
expect('error message should not be set', $model->errors)->isEmpty();
|
||||
expect('user should be logged in', Yii::$app->user->isGuest)->false();
|
||||
});
|
||||
}
|
||||
|
||||
public function testLoginByEmailCorrect() {
|
||||
$model = $this->createModel('admin@ely.by', 'password_0');
|
||||
$this->specify('user should be able to login with correct email and password', function () use ($model) {
|
||||
expect('model should login user', $model->login())->true();
|
||||
expect('error message should not be set', $model->errors)->isEmpty();
|
||||
expect('user should be logged in', Yii::$app->user->isGuest)->false();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
111
tests/codeception/api/unit/models/RegistrationFormTest.php
Normal file
111
tests/codeception/api/unit/models/RegistrationFormTest.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\models;
|
||||
|
||||
use api\models\RegistrationForm;
|
||||
use Codeception\Specify;
|
||||
use common\models\Account;
|
||||
use common\models\EmailActivation;
|
||||
use tests\codeception\api\unit\DbTestCase;
|
||||
use tests\codeception\common\fixtures\AccountFixture;
|
||||
use Yii;
|
||||
|
||||
class RegistrationFormTest extends DbTestCase {
|
||||
use Specify;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
/** @var \yii\swiftmailer\Mailer $mailer */
|
||||
$mailer = Yii::$app->mailer;
|
||||
$mailer->fileTransportCallback = function () {
|
||||
return 'testing_message.eml';
|
||||
};
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
if (file_exists($this->getMessageFile())) {
|
||||
unlink($this->getMessageFile());
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function fixtures() {
|
||||
return [
|
||||
'account' => [
|
||||
'class' => AccountFixture::className(),
|
||||
'dataFile' => '@tests/codeception/common/fixtures/data/accounts.php',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testNotCorrectRegistration() {
|
||||
$model = new RegistrationForm([
|
||||
'username' => 'valid_nickname',
|
||||
'email' => 'correct-email@ely.by',
|
||||
'password' => 'enough-length',
|
||||
'rePassword' => 'password',
|
||||
'rulesAgreement' => true,
|
||||
]);
|
||||
$this->specify('username and email in use, passwords not math - model is not created', function() use ($model) {
|
||||
expect($model->signup())->null();
|
||||
expect($model->getErrors())->notEmpty();
|
||||
expect_file($this->getMessageFile())->notExists();
|
||||
});
|
||||
}
|
||||
|
||||
public function testUsernameValidators() {
|
||||
$shouldBeValid = [
|
||||
'русский_ник', 'русский_ник_на_грани!', 'numbers1132', '*__*-Stars-*__*', '1-_.!?#$%^&*()[]', '[ESP]Эрик',
|
||||
'Свят_помидор;', 'зроблена_ў_беларусі:)',
|
||||
];
|
||||
$shouldBeInvalid = [
|
||||
'nick@name', 'spaced nick', ' ', 'sh', ' sh ',
|
||||
];
|
||||
|
||||
foreach($shouldBeValid as $nickname) {
|
||||
$model = new RegistrationForm([
|
||||
'username' => $nickname,
|
||||
]);
|
||||
expect($nickname . ' passed validation', $model->validate(['username']))->true();
|
||||
}
|
||||
|
||||
foreach($shouldBeInvalid as $nickname) {
|
||||
$model = new RegistrationForm([
|
||||
'username' => $nickname,
|
||||
]);
|
||||
expect($nickname . ' fail validation', $model->validate('username'))->false();
|
||||
}
|
||||
}
|
||||
|
||||
public function testCorrectSignup() {
|
||||
$model = new RegistrationForm([
|
||||
'username' => 'some_username',
|
||||
'email' => 'some_email@example.com',
|
||||
'password' => 'some_password',
|
||||
'rePassword' => 'some_password',
|
||||
'rulesAgreement' => true,
|
||||
]);
|
||||
|
||||
$user = $model->signup();
|
||||
|
||||
expect('user should be valid', $user)->isInstanceOf(Account::class);
|
||||
expect('password should be correct', $user->validatePassword('some_password'))->true();
|
||||
expect('user model exists in database', Account::find()->andWhere([
|
||||
'username' => 'some_username',
|
||||
'email' => 'some_email@example.com',
|
||||
])->exists())->true();
|
||||
expect('email activation code exists in database', EmailActivation::find()->andWhere([
|
||||
'account_id' => $user->id,
|
||||
'type' => EmailActivation::TYPE_REGISTRATION_EMAIL_CONFIRMATION,
|
||||
])->exists())->true();
|
||||
expect_file('message file exists', $this->getMessageFile())->exists();
|
||||
}
|
||||
|
||||
private function getMessageFile() {
|
||||
/** @var \yii\swiftmailer\Mailer $mailer */
|
||||
$mailer = Yii::$app->mailer;
|
||||
|
||||
return Yii::getAlias($mailer->fileTransportPath) . '/testing_message.eml';
|
||||
}
|
||||
|
||||
}
|
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\unit\models;
|
||||
|
||||
use tests\codeception\api\unit\DbTestCase;
|
||||
use tests\codeception\common\fixtures\UserFixture;
|
||||
use Codeception\Specify;
|
||||
use api\models\SignupForm;
|
||||
|
||||
class SignupFormTest extends DbTestCase
|
||||
{
|
||||
|
||||
use Specify;
|
||||
|
||||
public function testCorrectSignup()
|
||||
{
|
||||
$model = new SignupForm([
|
||||
'username' => 'some_username',
|
||||
'email' => 'some_email@example.com',
|
||||
'password' => 'some_password',
|
||||
]);
|
||||
|
||||
$user = $model->signup();
|
||||
|
||||
$this->assertInstanceOf('common\models\User', $user, 'user should be valid');
|
||||
|
||||
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()
|
||||
{
|
||||
$model = new SignupForm([
|
||||
'username' => 'troy.becker',
|
||||
'email' => 'nicolas.dianna@hotmail.com',
|
||||
'password' => 'some_password',
|
||||
]);
|
||||
|
||||
expect('username and email are in use, user should not be created', $model->signup())->null();
|
||||
}
|
||||
|
||||
public function fixtures()
|
||||
{
|
||||
return [
|
||||
'user' => [
|
||||
'class' => UserFixture::className(),
|
||||
'dataFile' => '@tests/codeception/api/unit/fixtures/data/models/user.php',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
@@ -1,127 +0,0 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\modules\login\models;
|
||||
|
||||
use api\modules\login\models\AuthenticationForm;
|
||||
use Codeception\Specify;
|
||||
use tests\codeception\api\unit\DbTestCase;
|
||||
use tests\codeception\common\fixtures\AccountFixture;
|
||||
use Yii;
|
||||
|
||||
class AuthenticationFormTest extends DbTestCase {
|
||||
|
||||
use Specify;
|
||||
|
||||
protected function tearDown() {
|
||||
Yii::$app->user->logout();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function fixtures() {
|
||||
return [
|
||||
'account' => [
|
||||
'class' => AccountFixture::className(),
|
||||
'dataFile' => '@tests/codeception/api/unit/fixtures/data/models/accounts.php'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function createModel($login = '', $password = '') {
|
||||
return new AuthenticationForm([
|
||||
'login' => $login,
|
||||
'password' => $password,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testLoginEmailOrUsername() {
|
||||
$model = $this->createModel();
|
||||
$this->specify('error.login_required expected if login is not set', function() use ($model) {
|
||||
expect($model->login())->false();
|
||||
expect($model->getErrors('login'))->equals(['error.login_required']);
|
||||
expect(Yii::$app->user->isGuest)->true();
|
||||
});
|
||||
|
||||
$model = $this->createModel('non-exist-username');
|
||||
$this->specify('error.login_not_exist expected if username not exists in database', function() use ($model) {
|
||||
expect($model->login())->false();
|
||||
expect(Yii::$app->user->isGuest)->true();
|
||||
expect($model->getErrors('login'))->equals(['error.login_not_exist']);
|
||||
});
|
||||
|
||||
$model = $this->createModel('not-exist@user.com');
|
||||
$this->specify('error.login_not_exist expected if email not exists in database', function() use ($model) {
|
||||
expect($model->login())->false();
|
||||
expect(Yii::$app->user->isGuest)->true();
|
||||
expect($model->getErrors('login'))->equals(['error.login_not_exist']);
|
||||
});
|
||||
|
||||
$model = $this->createModel('Admin');
|
||||
$this->specify('no errors on login field if username is correct and exists in database', function() use ($model) {
|
||||
expect($model->login())->false();
|
||||
expect(Yii::$app->user->isGuest)->true();
|
||||
expect($model->getErrors('login'))->isEmpty();
|
||||
});
|
||||
|
||||
$model = $this->createModel('admin@ely.by');
|
||||
$this->specify('no errors on login field if email is correct and exists in database', function() use ($model) {
|
||||
expect($model->login())->false();
|
||||
expect(Yii::$app->user->isGuest)->true();
|
||||
expect($model->getErrors('login'))->isEmpty();
|
||||
});
|
||||
}
|
||||
|
||||
public function testLoginPassword() {
|
||||
$model = $this->createModel();
|
||||
$this->specify('password don\'t has errors if email or username not set', function() use ($model) {
|
||||
expect($model->login())->false();
|
||||
expect(Yii::$app->user->isGuest)->true();
|
||||
expect($model->getErrors('password'))->isEmpty();
|
||||
});
|
||||
|
||||
$model = $this->createModel('non-exist-username', 'random-password');
|
||||
$this->specify('password don\'t has errors if username not exists in database', function() use ($model) {
|
||||
expect($model->login())->false();
|
||||
expect(Yii::$app->user->isGuest)->true();
|
||||
expect($model->getErrors('password'))->isEmpty();
|
||||
});
|
||||
|
||||
$model = $this->createModel('not-exist@user.com', 'random-password');
|
||||
$this->specify('password don\'t has errors if email not exists in database', function() use ($model) {
|
||||
expect($model->login())->false();
|
||||
expect(Yii::$app->user->isGuest)->true();
|
||||
expect($model->getErrors('password'))->isEmpty();
|
||||
});
|
||||
|
||||
$model = $this->createModel('admin@ely.by', 'wrong-password');
|
||||
$this->specify('error.password_incorrect expected if email correct, but password wrong', function() use ($model) {
|
||||
expect($model->login())->false();
|
||||
expect(Yii::$app->user->isGuest)->true();
|
||||
expect($model->getErrors('password'))->equals(['error.password_incorrect']);
|
||||
});
|
||||
|
||||
$model = $this->createModel('Admin', 'wrong-password');
|
||||
$this->specify('error.password_incorrect expected if username correct, but password wrong', function() use ($model) {
|
||||
expect($model->login())->false();
|
||||
expect(Yii::$app->user->isGuest)->true();
|
||||
expect($model->getErrors('password'))->equals(['error.password_incorrect']);
|
||||
});
|
||||
}
|
||||
|
||||
public function testLoginByUsernameCorrect() {
|
||||
$model = $this->createModel('Admin', 'password_0');
|
||||
$this->specify('user should be able to login with correct username and password', function () use ($model) {
|
||||
expect('model should login user', $model->login())->true();
|
||||
expect('error message should not be set', $model->errors)->isEmpty();
|
||||
expect('user should be logged in', Yii::$app->user->isGuest)->false();
|
||||
});
|
||||
}
|
||||
|
||||
public function testLoginByEmailCorrect() {
|
||||
$model = $this->createModel('admin@ely.by', 'password_0');
|
||||
$this->specify('user should be able to login with correct email and password', function () use ($model) {
|
||||
expect('model should login user', $model->login())->true();
|
||||
expect('error message should not be set', $model->errors)->isEmpty();
|
||||
expect('user should be logged in', Yii::$app->user->isGuest)->false();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
42
tests/codeception/api/unit/traits/ApiNormalizerTest.php
Normal file
42
tests/codeception/api/unit/traits/ApiNormalizerTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\traits;
|
||||
|
||||
use api\traits\ApiNormalize;
|
||||
use Codeception\Specify;
|
||||
use Codeception\TestCase\Test;
|
||||
|
||||
class ApiNormalizeTestClass {
|
||||
use ApiNormalize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @property \tests\codeception\api\UnitTester $actor
|
||||
*/
|
||||
class ApiNormalizerTest extends Test {
|
||||
use Specify;
|
||||
|
||||
public function testNormalizeModelErrors() {
|
||||
$object = new ApiNormalizeTestClass();
|
||||
$this->specify('', function() use ($object) {
|
||||
$normalized = $object->normalizeModelErrors([
|
||||
'rulesAgreement' => [
|
||||
'error.you_must_accept_rules',
|
||||
],
|
||||
'email' => [
|
||||
'error.email_required',
|
||||
],
|
||||
'username' => [
|
||||
'error.username_too_short',
|
||||
'error.username_not_unique',
|
||||
],
|
||||
]);
|
||||
|
||||
expect($normalized)->equals([
|
||||
'rulesAgreement' => 'error.you_must_accept_rules',
|
||||
'email' => 'error.email_required',
|
||||
'username' => 'error.username_too_short',
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
1
tests/codeception/common/.gitignore
vendored
1
tests/codeception/common/.gitignore
vendored
@@ -1,4 +1,3 @@
|
||||
# these files are auto generated by codeception build
|
||||
/unit/UnitTester.php
|
||||
/functional/FunctionalTester.php
|
||||
/acceptance/AcceptanceTester.php
|
||||
|
@@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
29
tests/codeception/common/fixtures/data/accounts.php
Normal file
29
tests/codeception/common/fixtures/data/accounts.php
Normal 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,
|
||||
],
|
||||
];
|
@@ -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'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Application configuration shared by all applications acceptance tests
|
||||
*/
|
||||
return [
|
||||
|
||||
];
|
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', dirname(dirname(dirname(dirname(__DIR__)))));
|
||||
|
||||
/**
|
||||
* Application configuration for api acceptance tests
|
||||
*/
|
||||
return yii\helpers\ArrayHelper::merge(
|
||||
require(YII_APP_BASE_PATH . '/common/config/main.php'),
|
||||
require(YII_APP_BASE_PATH . '/common/config/main-local.php'), require(YII_APP_BASE_PATH . '/api/config/main.php'),
|
||||
require(YII_APP_BASE_PATH . '/api/config/main-local.php'),
|
||||
require(dirname(__DIR__) . '/config.php'),
|
||||
require(dirname(__DIR__) . '/acceptance.php'),
|
||||
require(__DIR__ . '/config.php'),
|
||||
[
|
||||
]
|
||||
);
|
Reference in New Issue
Block a user