mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Инициализировано Yii2 приложение, выпилены лишние части, накинуты чуточку нужных
This commit is contained in:
4
tests/codeception/api/.gitignore
vendored
Normal file
4
tests/codeception/api/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
# these files are auto generated by codeception build
|
||||
/unit/UnitTester.php
|
||||
/functional/FunctionalTester.php
|
||||
/acceptance/AcceptanceTester.php
|
23
tests/codeception/api/_bootstrap.php
Normal file
23
tests/codeception/api/_bootstrap.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', true);
|
||||
defined('YII_ENV') or define('YII_ENV', 'test');
|
||||
|
||||
defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', dirname(dirname(dirname(__DIR__))));
|
||||
|
||||
defined('API_ENTRY_URL') or define('API_ENTRY_URL', parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_PATH));
|
||||
defined('API_ENTRY_FILE') or define('API_ENTRY_FILE', YII_APP_BASE_PATH . '/api/web/index-test.php');
|
||||
|
||||
require_once(YII_APP_BASE_PATH . '/vendor/autoload.php');
|
||||
require_once(YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/Yii.php');
|
||||
require_once(YII_APP_BASE_PATH . '/common/config/bootstrap.php');
|
||||
require_once(YII_APP_BASE_PATH . '/api/config/bootstrap.php');
|
||||
|
||||
// set correct script paths
|
||||
|
||||
// the entry script file path for functional and acceptance 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);
|
||||
$_SERVER['SERVER_PORT'] = parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_PORT) ?: '80';
|
||||
|
||||
Yii::setAlias('@tests', dirname(dirname(__DIR__)));
|
2
tests/codeception/api/_output/.gitignore
vendored
Normal file
2
tests/codeception/api/_output/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
14
tests/codeception/api/_pages/AboutPage.php
Normal file
14
tests/codeception/api/_pages/AboutPage.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?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';
|
||||
}
|
26
tests/codeception/api/_pages/ContactPage.php
Normal file
26
tests/codeception/api/_pages/ContactPage.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\_pages;
|
||||
|
||||
use yii\codeception\BasePage;
|
||||
|
||||
/**
|
||||
* Represents contact page
|
||||
* @property \codeception_api\AcceptanceTester|\codeception_api\FunctionalTester $actor
|
||||
*/
|
||||
class ContactPage extends BasePage
|
||||
{
|
||||
public $route = 'site/contact';
|
||||
|
||||
/**
|
||||
* @param 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');
|
||||
}
|
||||
}
|
27
tests/codeception/api/_pages/SignupPage.php
Normal file
27
tests/codeception/api/_pages/SignupPage.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
28
tests/codeception/api/acceptance.suite.yml
Normal file
28
tests/codeception/api/acceptance.suite.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
# 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
|
10
tests/codeception/api/acceptance/AboutCept.php
Normal file
10
tests/codeception/api/acceptance/AboutCept.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?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');
|
56
tests/codeception/api/acceptance/ContactCept.php
Normal file
56
tests/codeception/api/acceptance/ContactCept.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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.');
|
12
tests/codeception/api/acceptance/HomeCept.php
Normal file
12
tests/codeception/api/acceptance/HomeCept.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?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.');
|
34
tests/codeception/api/acceptance/LoginCept.php
Normal file
34
tests/codeception/api/acceptance/LoginCept.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
use tests\codeception\api\AcceptanceTester;
|
||||
use tests\codeception\common\_pages\LoginPage;
|
||||
|
||||
/* @var $scenario Codeception\Scenario */
|
||||
|
||||
$I = new AcceptanceTester($scenario);
|
||||
$I->wantTo('ensure login page works');
|
||||
|
||||
$loginPage = LoginPage::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');
|
||||
*/
|
82
tests/codeception/api/acceptance/SignupCest.php
Normal file
82
tests/codeception/api/acceptance/SignupCest.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\acceptance;
|
||||
|
||||
use tests\codeception\api\_pages\SignupPage;
|
||||
use common\models\User;
|
||||
|
||||
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)
|
||||
{
|
||||
User::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)');
|
||||
}
|
||||
}
|
2
tests/codeception/api/acceptance/_bootstrap.php
Normal file
2
tests/codeception/api/acceptance/_bootstrap.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
new yii\web\Application(require(dirname(dirname(__DIR__)) . '/config/api/acceptance.php'));
|
17
tests/codeception/api/codeception.yml
Normal file
17
tests/codeception/api/codeception.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace: tests\codeception\api
|
||||
actor: Tester
|
||||
paths:
|
||||
tests: .
|
||||
log: _output
|
||||
data: _data
|
||||
helpers: _support
|
||||
settings:
|
||||
bootstrap: _bootstrap.php
|
||||
suite_class: \PHPUnit_Framework_TestSuite
|
||||
colors: true
|
||||
memory_limit: 1024M
|
||||
log: true
|
||||
config:
|
||||
# the entry script URL (with host info) for functional and acceptance tests
|
||||
# PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL
|
||||
test_entry_url: http://localhost:8080/api/web/index-test.php
|
17
tests/codeception/api/functional.suite.yml
Normal file
17
tests/codeception/api/functional.suite.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
# Codeception Test Suite Configuration
|
||||
|
||||
# suite for functional (integration) tests.
|
||||
# emulate web requests and make application process them.
|
||||
# (tip: better to use with frameworks).
|
||||
|
||||
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
|
||||
#basic/web/index.php
|
||||
class_name: FunctionalTester
|
||||
modules:
|
||||
enabled:
|
||||
- Filesystem
|
||||
- Yii2
|
||||
- tests\codeception\common\_support\FixtureHelper
|
||||
config:
|
||||
Yii2:
|
||||
configFile: '../config/api/functional.php'
|
10
tests/codeception/api/functional/AboutCept.php
Normal file
10
tests/codeception/api/functional/AboutCept.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?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');
|
47
tests/codeception/api/functional/ContactCept.php
Normal file
47
tests/codeception/api/functional/ContactCept.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
use tests\codeception\api\FunctionalTester;
|
||||
use tests\codeception\api\_pages\ContactPage;
|
||||
|
||||
/* @var $scenario Codeception\Scenario */
|
||||
|
||||
$I = new FunctionalTester($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([]);
|
||||
$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',
|
||||
]);
|
||||
$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',
|
||||
]);
|
||||
$I->see('Thank you for contacting us. We will respond to you as soon as possible.');
|
12
tests/codeception/api/functional/HomeCept.php
Normal file
12
tests/codeception/api/functional/HomeCept.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?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.');
|
29
tests/codeception/api/functional/LoginCept.php
Normal file
29
tests/codeception/api/functional/LoginCept.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
use tests\codeception\api\FunctionalTester;
|
||||
use tests\codeception\common\_pages\LoginPage;
|
||||
|
||||
/* @var $scenario Codeception\Scenario */
|
||||
|
||||
$I = new FunctionalTester($scenario);
|
||||
$I->wantTo('ensure login page works');
|
||||
|
||||
$loginPage = LoginPage::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');
|
90
tests/codeception/api/functional/SignupCest.php
Normal file
90
tests/codeception/api/functional/SignupCest.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\functional;
|
||||
|
||||
use tests\codeception\api\_pages\SignupPage;
|
||||
use common\models\User;
|
||||
|
||||
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)
|
||||
{
|
||||
User::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)');
|
||||
}
|
||||
}
|
3
tests/codeception/api/functional/_bootstrap.php
Normal file
3
tests/codeception/api/functional/_bootstrap.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
new yii\web\Application(require(dirname(dirname(__DIR__)) . '/config/api/functional.php'));
|
6
tests/codeception/api/unit.suite.yml
Normal file
6
tests/codeception/api/unit.suite.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
# Codeception Test Suite Configuration
|
||||
|
||||
# suite for unit (internal) tests.
|
||||
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
|
||||
|
||||
class_name: UnitTester
|
11
tests/codeception/api/unit/DbTestCase.php
Normal file
11
tests/codeception/api/unit/DbTestCase.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\unit;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
class DbTestCase extends \yii\codeception\DbTestCase
|
||||
{
|
||||
public $appConfig = '@tests/codeception/config/api/unit.php';
|
||||
}
|
11
tests/codeception/api/unit/TestCase.php
Normal file
11
tests/codeception/api/unit/TestCase.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\unit;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
class TestCase extends \yii\codeception\TestCase
|
||||
{
|
||||
public $appConfig = '@tests/codeception/config/api/unit.php';
|
||||
}
|
2
tests/codeception/api/unit/_bootstrap.php
Normal file
2
tests/codeception/api/unit/_bootstrap.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
// Here you can initialize variables that will for your tests
|
23
tests/codeception/api/unit/fixtures/data/models/user.php
Normal file
23
tests/codeception/api/unit/fixtures/data/models/user.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
'username' => 'okirlin',
|
||||
'auth_key' => 'iwTNae9t34OmnK6l4vT4IeaTk-YWI2Rv',
|
||||
'password_hash' => '$2y$13$CXT0Rkle1EMJ/c1l5bylL.EylfmQ39O5JlHJVFpNn618OUS1HwaIi',
|
||||
'password_reset_token' => 't5GU9NwpuGYSfb7FEZMAxqtuz2PkEvv_' . time(),
|
||||
'created_at' => '1391885313',
|
||||
'updated_at' => '1391885313',
|
||||
'email' => 'brady.renner@rutherford.com',
|
||||
],
|
||||
[
|
||||
'username' => 'troy.becker',
|
||||
'auth_key' => 'EdKfXrx88weFMV0vIxuTMWKgfK2tS3Lp',
|
||||
'password_hash' => '$2y$13$g5nv41Px7VBqhS3hVsVN2.MKfgT3jFdkXEsMC4rQJLfaMa7VaJqL2',
|
||||
'password_reset_token' => '4BSNyiZNAuxjs5Mty990c47sVrgllIi_' . time(),
|
||||
'created_at' => '1391885313',
|
||||
'updated_at' => '1391885313',
|
||||
'email' => 'nicolas.dianna@hotmail.com',
|
||||
'status' => '0',
|
||||
],
|
||||
];
|
59
tests/codeception/api/unit/models/ContactFormTest.php
Normal file
59
tests/codeception/api/unit/models/ContactFormTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\unit\models;
|
||||
|
||||
use Yii;
|
||||
use tests\codeception\api\unit\TestCase;
|
||||
use api\models\ContactForm;
|
||||
|
||||
class ContactFormTest extends TestCase
|
||||
{
|
||||
|
||||
use \Codeception\Specify;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Yii::$app->mailer->fileTransportCallback = function ($mailer, $message) {
|
||||
return 'testing_message.eml';
|
||||
};
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
unlink($this->getMessageFile());
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testContact()
|
||||
{
|
||||
$model = new ContactForm();
|
||||
|
||||
$model->attributes = [
|
||||
'name' => 'Tester',
|
||||
'email' => 'tester@example.com',
|
||||
'subject' => 'very important letter subject',
|
||||
'body' => 'body of current message',
|
||||
];
|
||||
|
||||
$model->sendEmail('admin@example.com');
|
||||
|
||||
$this->specify('email should be send', function () {
|
||||
expect('email file should exist', file_exists($this->getMessageFile()))->true();
|
||||
});
|
||||
|
||||
$this->specify('message should contain correct data', function () use ($model) {
|
||||
$emailMessage = file_get_contents($this->getMessageFile());
|
||||
|
||||
expect('email should contain user name', $emailMessage)->contains($model->name);
|
||||
expect('email should contain sender email', $emailMessage)->contains($model->email);
|
||||
expect('email should contain subject', $emailMessage)->contains($model->subject);
|
||||
expect('email should contain body', $emailMessage)->contains($model->body);
|
||||
});
|
||||
}
|
||||
|
||||
private function getMessageFile()
|
||||
{
|
||||
return Yii::getAlias(Yii::$app->mailer->fileTransportPath) . '/testing_message.eml';
|
||||
}
|
||||
}
|
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\models;
|
||||
|
||||
use Yii;
|
||||
use tests\codeception\api\unit\DbTestCase;
|
||||
use api\models\PasswordResetRequestForm;
|
||||
use tests\codeception\common\fixtures\UserFixture;
|
||||
use common\models\User;
|
||||
use Codeception\Specify;
|
||||
|
||||
class PasswordResetRequestFormTest extends DbTestCase
|
||||
{
|
||||
use Specify;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Yii::$app->mailer->fileTransportCallback = function ($mailer, $message) {
|
||||
return 'testing_message.eml';
|
||||
};
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
@unlink($this->getMessageFile());
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testSendEmailWrongUser()
|
||||
{
|
||||
$this->specify('no user with such email, message should not be sent', function () {
|
||||
|
||||
$model = new PasswordResetRequestForm();
|
||||
$model->email = 'not-existing-email@example.com';
|
||||
|
||||
expect('email not sent', $model->sendEmail())->false();
|
||||
|
||||
});
|
||||
|
||||
$this->specify('user is not active, message should not be sent', function () {
|
||||
|
||||
$model = new PasswordResetRequestForm();
|
||||
$model->email = $this->user[1]['email'];
|
||||
|
||||
expect('email not sent', $model->sendEmail())->false();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public function testSendEmailCorrectUser()
|
||||
{
|
||||
$model = new PasswordResetRequestForm();
|
||||
$model->email = $this->user[0]['email'];
|
||||
$user = User::findOne(['password_reset_token' => $this->user[0]['password_reset_token']]);
|
||||
|
||||
expect('email sent', $model->sendEmail())->true();
|
||||
expect('user has valid token', $user->password_reset_token)->notNull();
|
||||
|
||||
$this->specify('message has correct format', function () use ($model) {
|
||||
|
||||
expect('message file exists', file_exists($this->getMessageFile()))->true();
|
||||
|
||||
$message = file_get_contents($this->getMessageFile());
|
||||
expect('message "from" is correct', $message)->contains(Yii::$app->params['supportEmail']);
|
||||
expect('message "to" is correct', $message)->contains($model->email);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public function fixtures()
|
||||
{
|
||||
return [
|
||||
'user' => [
|
||||
'class' => UserFixture::className(),
|
||||
'dataFile' => '@tests/codeception/api/unit/fixtures/data/models/user.php'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private function getMessageFile()
|
||||
{
|
||||
return Yii::getAlias(Yii::$app->mailer->fileTransportPath) . '/testing_message.eml';
|
||||
}
|
||||
}
|
43
tests/codeception/api/unit/models/ResetPasswordFormTest.php
Normal file
43
tests/codeception/api/unit/models/ResetPasswordFormTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\api\unit\models;
|
||||
|
||||
use tests\codeception\api\unit\DbTestCase;
|
||||
use tests\codeception\common\fixtures\UserFixture;
|
||||
use api\models\ResetPasswordForm;
|
||||
|
||||
class ResetPasswordFormTest extends DbTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @expectedException \yii\base\InvalidParamException
|
||||
*/
|
||||
public function testResetWrongToken()
|
||||
{
|
||||
new ResetPasswordForm('notexistingtoken_1391882543');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \yii\base\InvalidParamException
|
||||
*/
|
||||
public function testResetEmptyToken()
|
||||
{
|
||||
new ResetPasswordForm('');
|
||||
}
|
||||
|
||||
public function testResetCorrectToken()
|
||||
{
|
||||
$form = new ResetPasswordForm($this->user[0]['password_reset_token']);
|
||||
expect('password should be resetted', $form->resetPassword())->true();
|
||||
}
|
||||
|
||||
public function fixtures()
|
||||
{
|
||||
return [
|
||||
'user' => [
|
||||
'class' => UserFixture::className(),
|
||||
'dataFile' => '@tests/codeception/api/unit/fixtures/data/models/user.php'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
52
tests/codeception/api/unit/models/SignupFormTest.php
Normal file
52
tests/codeception/api/unit/models/SignupFormTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?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('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()
|
||||
{
|
||||
$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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user