mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Инициализировано Yii2 приложение, выпилены лишние части, накинуты чуточку нужных
This commit is contained in:
58
tests/README.md
Normal file
58
tests/README.md
Normal file
@@ -0,0 +1,58 @@
|
||||
This directory contains various tests for the advanced applications.
|
||||
|
||||
Tests in `codeception` directory are developed with [Codeception PHP Testing Framework](http://codeception.com/).
|
||||
|
||||
After creating and setting up the advanced application, follow these steps to prepare for the tests:
|
||||
|
||||
1. Install Codeception if it's not yet installed:
|
||||
|
||||
```
|
||||
composer global require "codeception/codeception=2.0.*" "codeception/specify=*" "codeception/verify=*"
|
||||
```
|
||||
|
||||
If you've never used Composer for global packages run `composer global status`. It should output:
|
||||
|
||||
```
|
||||
Changed current directory to <directory>
|
||||
```
|
||||
|
||||
Then add `<directory>/vendor/bin` to you `PATH` environment variable. Now you're able to use `codecept` from command
|
||||
line globally.
|
||||
|
||||
2. Install faker extension by running the following from template root directory where `composer.json` is:
|
||||
|
||||
```
|
||||
composer require --dev yiisoft/yii2-faker:*
|
||||
```
|
||||
|
||||
3. Create `yii2_advanced_tests` database then update it by applying migrations:
|
||||
|
||||
```
|
||||
codeception/bin/yii migrate
|
||||
```
|
||||
|
||||
4. In order to be able to run acceptance tests you need to start a webserver. The simplest way is to use PHP built in
|
||||
webserver. In the root directory where `common`, `frontend` etc. are execute the following:
|
||||
|
||||
```
|
||||
php -S localhost:8080
|
||||
```
|
||||
|
||||
5. Now you can run the tests with the following commands, assuming you are in the `tests/codeception` directory:
|
||||
|
||||
```
|
||||
# frontend tests
|
||||
cd frontend
|
||||
codecept build
|
||||
codecept run
|
||||
|
||||
# backend tests
|
||||
|
||||
cd backend
|
||||
codecept build
|
||||
codecept run
|
||||
|
||||
# etc.
|
||||
```
|
||||
|
||||
If you already have run `codecept build` for each application, you can skip that step and run all tests by a single `codecept run`.
|
10
tests/codeception.yml
Normal file
10
tests/codeception.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
include:
|
||||
- codeception/common
|
||||
- codeception/console
|
||||
- codeception/api
|
||||
|
||||
paths:
|
||||
log: codeception/_output
|
||||
|
||||
settings:
|
||||
colors: true
|
2
tests/codeception/_output/.gitignore
vendored
Normal file
2
tests/codeception/_output/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
19
tests/codeception/bin/_bootstrap.php
Normal file
19
tests/codeception/bin/_bootstrap.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Yii console bootstrap file.
|
||||
*
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
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__))));
|
||||
|
||||
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');
|
||||
|
||||
Yii::setAlias('@tests', dirname(dirname(__DIR__)));
|
23
tests/codeception/bin/yii
Normal file
23
tests/codeception/bin/yii
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* Yii console bootstrap file.
|
||||
*
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
$config = 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 . '/console/config/main.php'),
|
||||
require(YII_APP_BASE_PATH . '/console/config/main-local.php'),
|
||||
require(dirname(__DIR__) . '/config/config.php')
|
||||
);
|
||||
|
||||
$application = new yii\console\Application($config);
|
||||
$exitCode = $application->run();
|
||||
exit($exitCode);
|
20
tests/codeception/bin/yii.bat
Normal file
20
tests/codeception/bin/yii.bat
Normal file
@@ -0,0 +1,20 @@
|
||||
@echo off
|
||||
|
||||
rem -------------------------------------------------------------
|
||||
rem Yii command line bootstrap script for Windows.
|
||||
rem
|
||||
rem @author Qiang Xue <qiang.xue@gmail.com>
|
||||
rem @link http://www.yiiframework.com/
|
||||
rem @copyright Copyright (c) 2008 Yii Software LLC
|
||||
rem @license http://www.yiiframework.com/license/
|
||||
rem -------------------------------------------------------------
|
||||
|
||||
@setlocal
|
||||
|
||||
set YII_PATH=%~dp0
|
||||
|
||||
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
|
||||
|
||||
"%PHP_COMMAND%" "%YII_PATH%yii" %*
|
||||
|
||||
@endlocal
|
4
tests/codeception/common/.gitignore
vendored
Normal file
4
tests/codeception/common/.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
|
15
tests/codeception/common/_bootstrap.php
Normal file
15
tests/codeception/common/_bootstrap.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?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__))));
|
||||
|
||||
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');
|
||||
|
||||
// set correct script paths
|
||||
$_SERVER['SERVER_NAME'] = 'localhost';
|
||||
$_SERVER['SERVER_PORT'] = '80';
|
||||
|
||||
Yii::setAlias('@tests', dirname(dirname(__DIR__)));
|
2
tests/codeception/common/_output/.gitignore
vendored
Normal file
2
tests/codeception/common/_output/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
25
tests/codeception/common/_pages/LoginPage.php
Normal file
25
tests/codeception/common/_pages/LoginPage.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\common\_pages;
|
||||
|
||||
use yii\codeception\BasePage;
|
||||
|
||||
/**
|
||||
* Represents loging page
|
||||
* @property \codeception_api\AcceptanceTester|\codeception_api\FunctionalTester $actor
|
||||
*/
|
||||
class LoginPage extends BasePage
|
||||
{
|
||||
public $route = 'site/login';
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
*/
|
||||
public function login($username, $password)
|
||||
{
|
||||
$this->actor->fillField('input[name="LoginForm[username]"]', $username);
|
||||
$this->actor->fillField('input[name="LoginForm[password]"]', $password);
|
||||
$this->actor->click('login-button');
|
||||
}
|
||||
}
|
72
tests/codeception/common/_support/FixtureHelper.php
Normal file
72
tests/codeception/common/_support/FixtureHelper.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\common\_support;
|
||||
|
||||
use tests\codeception\common\fixtures\UserFixture;
|
||||
use Codeception\Module;
|
||||
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.
|
||||
*/
|
||||
class FixtureHelper extends Module
|
||||
{
|
||||
|
||||
/**
|
||||
* Redeclare visibility because codeception includes all public methods that do not start with "_"
|
||||
* and are not excluded by module settings, in actor class.
|
||||
*/
|
||||
use FixtureTrait {
|
||||
loadFixtures as protected;
|
||||
fixtures as protected;
|
||||
globalFixtures as protected;
|
||||
unloadFixtures as protected;
|
||||
getFixtures as protected;
|
||||
getFixture as protected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called before any suite tests run. Loads User fixture login user
|
||||
* to use in acceptance and functional tests.
|
||||
* @param array $settings
|
||||
*/
|
||||
public function _beforeSuite($settings = [])
|
||||
{
|
||||
$this->loadFixtures();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method is called after all suite tests run
|
||||
*/
|
||||
public function _afterSuite()
|
||||
{
|
||||
$this->unloadFixtures();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function globalFixtures()
|
||||
{
|
||||
return [
|
||||
InitDbFixture::className(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function fixtures()
|
||||
{
|
||||
return [
|
||||
'user' => [
|
||||
'class' => UserFixture::className(),
|
||||
'dataFile' => '@tests/codeception/common/fixtures/data/init_login.php',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
13
tests/codeception/common/codeception.yml
Normal file
13
tests/codeception/common/codeception.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace: tests\codeception\common
|
||||
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
|
13
tests/codeception/common/fixtures/UserFixture.php
Normal file
13
tests/codeception/common/fixtures/UserFixture.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\common\fixtures;
|
||||
|
||||
use yii\test\ActiveFixture;
|
||||
|
||||
/**
|
||||
* User fixture
|
||||
*/
|
||||
class UserFixture extends ActiveFixture
|
||||
{
|
||||
public $modelClass = 'common\models\User';
|
||||
}
|
14
tests/codeception/common/fixtures/data/init_login.php
Normal file
14
tests/codeception/common/fixtures/data/init_login.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
'username' => 'erau',
|
||||
'auth_key' => 'tUu1qHcde0diwUol3xeI-18MuHkkprQI',
|
||||
// password_0
|
||||
'password_hash' => '$2y$13$nJ1WDlBaGcbCdbNC5.5l4.sgy.OMEKCqtDQOdQ2OWpgiKRWYyzzne',
|
||||
'password_reset_token' => 'RkD_Jw0_8HEedzLk7MM-ZKEFfYR7VbMr_1392559490',
|
||||
'created_at' => '1392559490',
|
||||
'updated_at' => '1392559490',
|
||||
'email' => 'sfriesen@jenkins.info',
|
||||
],
|
||||
];
|
17
tests/codeception/common/templates/fixtures/user.php
Normal file
17
tests/codeception/common/templates/fixtures/user.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* @var $faker \Faker\Generator
|
||||
* @var $index integer
|
||||
*/
|
||||
|
||||
$security = Yii::$app->getSecurity();
|
||||
|
||||
return [
|
||||
'username' => $faker->userName,
|
||||
'email' => $faker->email,
|
||||
'auth_key' => $security->generateRandomString(),
|
||||
'password_hash' => $security->generatePasswordHash('password_' . $index),
|
||||
'password_reset_token' => $security->generateRandomString() . '_' . time(),
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
];
|
6
tests/codeception/common/unit.suite.yml
Normal file
6
tests/codeception/common/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/common/unit/DbTestCase.php
Normal file
11
tests/codeception/common/unit/DbTestCase.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\common\unit;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
class DbTestCase extends \yii\codeception\DbTestCase
|
||||
{
|
||||
public $appConfig = '@tests/codeception/config/common/unit.php';
|
||||
}
|
11
tests/codeception/common/unit/TestCase.php
Normal file
11
tests/codeception/common/unit/TestCase.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\common\unit;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
class TestCase extends \yii\codeception\TestCase
|
||||
{
|
||||
public $appConfig = '@tests/codeception/config/common/unit.php';
|
||||
}
|
2
tests/codeception/common/unit/_bootstrap.php
Normal file
2
tests/codeception/common/unit/_bootstrap.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
// Here you can initialize variables that will for your tests
|
14
tests/codeception/common/unit/fixtures/data/models/user.php
Normal file
14
tests/codeception/common/unit/fixtures/data/models/user.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
'username' => 'bayer.hudson',
|
||||
'auth_key' => 'HP187Mvq7Mmm3CTU80dLkGmni_FUH_lR',
|
||||
//password_0
|
||||
'password_hash' => '$2y$13$EjaPFBnZOQsHdGuHI.xvhuDp1fHpo8hKRSk6yshqa9c5EG8s3C3lO',
|
||||
'password_reset_token' => 'ExzkCOaYc1L8IOBs4wdTGGbgNiG3Wz1I_1402312317',
|
||||
'created_at' => '1402312317',
|
||||
'updated_at' => '1402312317',
|
||||
'email' => 'nicole.paucek@schultz.info',
|
||||
],
|
||||
];
|
93
tests/codeception/common/unit/models/LoginFormTest.php
Normal file
93
tests/codeception/common/unit/models/LoginFormTest.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\common\unit\models;
|
||||
|
||||
use Yii;
|
||||
use tests\codeception\common\unit\DbTestCase;
|
||||
use Codeception\Specify;
|
||||
use common\models\LoginForm;
|
||||
use tests\codeception\common\fixtures\UserFixture;
|
||||
|
||||
/**
|
||||
* 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'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
7
tests/codeception/config/acceptance.php
Normal file
7
tests/codeception/config/acceptance.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Application configuration shared by all applications acceptance tests
|
||||
*/
|
||||
return [
|
||||
|
||||
];
|
16
tests/codeception/config/api/acceptance.php
Normal file
16
tests/codeception/config/api/acceptance.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?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'),
|
||||
[
|
||||
]
|
||||
);
|
5
tests/codeception/config/api/config.php
Normal file
5
tests/codeception/config/api/config.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
/**
|
||||
* Application configuration for all api test types
|
||||
*/
|
||||
return [];
|
17
tests/codeception/config/api/functional.php
Normal file
17
tests/codeception/config/api/functional.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
$_SERVER['SCRIPT_FILENAME'] = API_ENTRY_FILE;
|
||||
$_SERVER['SCRIPT_NAME'] = API_ENTRY_URL;
|
||||
|
||||
/**
|
||||
* Application configuration for api functional 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__) . '/functional.php'),
|
||||
require(__DIR__ . '/config.php'),
|
||||
[
|
||||
]
|
||||
);
|
15
tests/codeception/config/api/unit.php
Normal file
15
tests/codeception/config/api/unit.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Application configuration for api unit 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__) . '/unit.php'),
|
||||
require(__DIR__ . '/config.php'),
|
||||
[
|
||||
]
|
||||
);
|
14
tests/codeception/config/common/unit.php
Normal file
14
tests/codeception/config/common/unit.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Application config for common unit 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(dirname(__DIR__) . '/config.php'),
|
||||
require(dirname(__DIR__) . '/unit.php'),
|
||||
[
|
||||
'id' => 'app-common',
|
||||
'basePath' => dirname(__DIR__),
|
||||
]
|
||||
);
|
26
tests/codeception/config/config.php
Normal file
26
tests/codeception/config/config.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Application configuration shared by all applications and test types
|
||||
*/
|
||||
return [
|
||||
'language' => 'en-US',
|
||||
'controllerMap' => [
|
||||
'fixture' => [
|
||||
'class' => 'yii\faker\FixtureController',
|
||||
'fixtureDataPath' => '@tests/codeception/common/fixtures/data',
|
||||
'templatePath' => '@tests/codeception/common/templates/fixtures',
|
||||
'namespace' => 'tests\codeception\common\fixtures',
|
||||
],
|
||||
],
|
||||
'components' => [
|
||||
'db' => [
|
||||
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_tests',
|
||||
],
|
||||
'mailer' => [
|
||||
'useFileTransport' => true,
|
||||
],
|
||||
'urlManager' => [
|
||||
'showScriptName' => true,
|
||||
],
|
||||
],
|
||||
];
|
14
tests/codeception/config/console/unit.php
Normal file
14
tests/codeception/config/console/unit.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Application configuration for console unit 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 . '/console/config/main.php'),
|
||||
require(YII_APP_BASE_PATH . '/console/config/main-local.php'),
|
||||
require(dirname(__DIR__) . '/config.php'),
|
||||
require(dirname(__DIR__) . '/unit.php'),
|
||||
[
|
||||
]
|
||||
);
|
18
tests/codeception/config/functional.php
Normal file
18
tests/codeception/config/functional.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Application configuration shared by all applications functional tests
|
||||
*/
|
||||
return [
|
||||
'components' => [
|
||||
'request' => [
|
||||
// it's not recommended to run functional tests with CSRF validation enabled
|
||||
'enableCsrfValidation' => false,
|
||||
// but if you absolutely need it set cookie domain to localhost
|
||||
/*
|
||||
'csrfCookie' => [
|
||||
'domain' => 'localhost',
|
||||
],
|
||||
*/
|
||||
],
|
||||
],
|
||||
];
|
7
tests/codeception/config/unit.php
Normal file
7
tests/codeception/config/unit.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Application configuration shared by all applications unit tests
|
||||
*/
|
||||
return [
|
||||
|
||||
];
|
2
tests/codeception/console/.gitignore
vendored
Normal file
2
tests/codeception/console/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# these files are auto generated by codeception build
|
||||
/unit/UnitTester.php
|
16
tests/codeception/console/_bootstrap.php
Normal file
16
tests/codeception/console/_bootstrap.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?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__))));
|
||||
|
||||
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 . '/console/config/bootstrap.php');
|
||||
|
||||
// set correct script paths
|
||||
$_SERVER['SERVER_NAME'] = 'localhost';
|
||||
$_SERVER['SERVER_PORT'] = '80';
|
||||
|
||||
Yii::setAlias('@tests', dirname(dirname(__DIR__)));
|
2
tests/codeception/console/_output/.gitignore
vendored
Normal file
2
tests/codeception/console/_output/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
13
tests/codeception/console/codeception.yml
Normal file
13
tests/codeception/console/codeception.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace: tests\codeception\console
|
||||
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
|
6
tests/codeception/console/unit.suite.yml
Normal file
6
tests/codeception/console/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/console/unit/DbTestCase.php
Normal file
11
tests/codeception/console/unit/DbTestCase.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\console\unit;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
class DbTestCase extends \yii\codeception\DbTestCase
|
||||
{
|
||||
public $appConfig = '@tests/codeception/config/console/config.php';
|
||||
}
|
11
tests/codeception/console/unit/TestCase.php
Normal file
11
tests/codeception/console/unit/TestCase.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\console\unit;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
class TestCase extends \yii\codeception\TestCase
|
||||
{
|
||||
public $appConfig = '@tests/codeception/config/console/config.php';
|
||||
}
|
2
tests/codeception/console/unit/_bootstrap.php
Normal file
2
tests/codeception/console/unit/_bootstrap.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
// Here you can initialize variables that will for your tests
|
Reference in New Issue
Block a user