yii composer install
This commit is contained in:
4
tests/codeception/.gitignore
vendored
Normal file
4
tests/codeception/.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
|
||||
16
tests/codeception/_bootstrap.php
Normal file
16
tests/codeception/_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_TEST_ENTRY_URL') or define('YII_TEST_ENTRY_URL', parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_PATH));
|
||||
defined('YII_TEST_ENTRY_FILE') or define('YII_TEST_ENTRY_FILE', dirname(dirname(__DIR__)) . '/web/index-test.php');
|
||||
|
||||
require_once(__DIR__ . '/../../vendor/autoload.php');
|
||||
require_once(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
|
||||
|
||||
$_SERVER['SCRIPT_FILENAME'] = YII_TEST_ENTRY_FILE;
|
||||
$_SERVER['SCRIPT_NAME'] = YII_TEST_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(__DIR__));
|
||||
2
tests/codeception/_output/.gitignore
vendored
Normal file
2
tests/codeception/_output/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
14
tests/codeception/_pages/AboutPage.php
Normal file
14
tests/codeception/_pages/AboutPage.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\_pages;
|
||||
|
||||
use yii\codeception\BasePage;
|
||||
|
||||
/**
|
||||
* Represents about page
|
||||
* @property \AcceptanceTester|\FunctionalTester $actor
|
||||
*/
|
||||
class AboutPage extends BasePage
|
||||
{
|
||||
public $route = 'site/about';
|
||||
}
|
||||
26
tests/codeception/_pages/ContactPage.php
Normal file
26
tests/codeception/_pages/ContactPage.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\_pages;
|
||||
|
||||
use yii\codeception\BasePage;
|
||||
|
||||
/**
|
||||
* Represents contact page
|
||||
* @property \AcceptanceTester|\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');
|
||||
}
|
||||
}
|
||||
25
tests/codeception/_pages/LoginPage.php
Normal file
25
tests/codeception/_pages/LoginPage.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\_pages;
|
||||
|
||||
use yii\codeception\BasePage;
|
||||
|
||||
/**
|
||||
* Represents login page
|
||||
* @property \AcceptanceTester|\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');
|
||||
}
|
||||
}
|
||||
27
tests/codeception/acceptance.suite.yml
Normal file
27
tests/codeception/acceptance.suite.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
# 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
|
||||
# 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/acceptance/AboutCept.php
Normal file
10
tests/codeception/acceptance/AboutCept.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
use tests\codeception\_pages\AboutPage;
|
||||
|
||||
/* @var $scenario Codeception\Scenario */
|
||||
|
||||
$I = new AcceptanceTester($scenario);
|
||||
$I->wantTo('ensure that about works');
|
||||
AboutPage::openBy($I);
|
||||
$I->see('About', 'h1');
|
||||
57
tests/codeception/acceptance/ContactCept.php
Normal file
57
tests/codeception/acceptance/ContactCept.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use tests\codeception\_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');
|
||||
$I->see('Email cannot be blank');
|
||||
$I->see('Subject cannot be blank');
|
||||
$I->see('Body cannot be blank');
|
||||
$I->see('The verification code is incorrect');
|
||||
|
||||
$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 address is wrong');
|
||||
$I->dontSee('Name cannot be blank', '.help-inline');
|
||||
$I->see('Email is not a valid email address.');
|
||||
$I->dontSee('Subject cannot be blank', '.help-inline');
|
||||
$I->dontSee('Body cannot be blank', '.help-inline');
|
||||
$I->dontSee('The verification code is incorrect', '.help-inline');
|
||||
|
||||
$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->dontSeeElement('#contact-form');
|
||||
$I->see('Thank you for contacting us. We will respond to you as soon as possible.');
|
||||
11
tests/codeception/acceptance/HomeCept.php
Normal file
11
tests/codeception/acceptance/HomeCept.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
/* @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.');
|
||||
37
tests/codeception/acceptance/LoginCept.php
Normal file
37
tests/codeception/acceptance/LoginCept.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use tests\codeception\_pages\LoginPage;
|
||||
|
||||
/* @var $scenario Codeception\Scenario */
|
||||
|
||||
$I = new AcceptanceTester($scenario);
|
||||
$I->wantTo('ensure that login works');
|
||||
|
||||
$loginPage = LoginPage::openBy($I);
|
||||
|
||||
$I->see('Login', 'h1');
|
||||
|
||||
$I->amGoingTo('try to login with empty credentials');
|
||||
$loginPage->login('', '');
|
||||
if (method_exists($I, 'wait')) {
|
||||
$I->wait(3); // only for selenium
|
||||
}
|
||||
$I->expectTo('see validations errors');
|
||||
$I->see('Username cannot be blank.');
|
||||
$I->see('Password cannot be blank.');
|
||||
|
||||
$I->amGoingTo('try to login with wrong credentials');
|
||||
$loginPage->login('admin', 'wrong');
|
||||
if (method_exists($I, 'wait')) {
|
||||
$I->wait(3); // only for selenium
|
||||
}
|
||||
$I->expectTo('see validations errors');
|
||||
$I->see('Incorrect username or password.');
|
||||
|
||||
$I->amGoingTo('try to login with correct credentials');
|
||||
$loginPage->login('admin', 'admin');
|
||||
if (method_exists($I, 'wait')) {
|
||||
$I->wait(3); // only for selenium
|
||||
}
|
||||
$I->expectTo('see user info');
|
||||
$I->see('Logout (admin)');
|
||||
2
tests/codeception/acceptance/_bootstrap.php
Normal file
2
tests/codeception/acceptance/_bootstrap.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
new yii\web\Application(require(dirname(__DIR__) . '/config/acceptance.php'));
|
||||
10
tests/codeception/bin/_bootstrap.php
Normal file
10
tests/codeception/bin/_bootstrap.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?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(YII_APP_BASE_PATH . '/vendor/autoload.php');
|
||||
require(YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/Yii.php');
|
||||
|
||||
Yii::setAlias('@tests', dirname(dirname(__DIR__)));
|
||||
20
tests/codeception/bin/yii
Normal file
20
tests/codeception/bin/yii
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/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 . '/config/console.php'),
|
||||
require(__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
|
||||
11
tests/codeception/config/acceptance.php
Normal file
11
tests/codeception/config/acceptance.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Application configuration for acceptance tests
|
||||
*/
|
||||
return yii\helpers\ArrayHelper::merge(
|
||||
require(__DIR__ . '/../../../config/web.php'),
|
||||
require(__DIR__ . '/config.php'),
|
||||
[
|
||||
|
||||
]
|
||||
);
|
||||
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 test types
|
||||
*/
|
||||
return [
|
||||
'language' => 'en-US',
|
||||
'controllerMap' => [
|
||||
'fixture' => [
|
||||
'class' => 'yii\faker\FixtureController',
|
||||
'fixtureDataPath' => '@tests/codeception/fixtures',
|
||||
'templatePath' => '@tests/codeception/templates',
|
||||
'namespace' => 'tests\codeception\fixtures',
|
||||
],
|
||||
],
|
||||
'components' => [
|
||||
'db' => [
|
||||
'dsn' => 'mysql:host=localhost;dbname=yii2_basic_tests',
|
||||
],
|
||||
'mailer' => [
|
||||
'useFileTransport' => true,
|
||||
],
|
||||
'urlManager' => [
|
||||
'showScriptName' => true,
|
||||
],
|
||||
],
|
||||
];
|
||||
25
tests/codeception/config/functional.php
Normal file
25
tests/codeception/config/functional.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
$_SERVER['SCRIPT_FILENAME'] = YII_TEST_ENTRY_FILE;
|
||||
$_SERVER['SCRIPT_NAME'] = YII_TEST_ENTRY_URL;
|
||||
|
||||
/**
|
||||
* Application configuration for functional tests
|
||||
*/
|
||||
return yii\helpers\ArrayHelper::merge(
|
||||
require(__DIR__ . '/../../../config/web.php'),
|
||||
require(__DIR__ . '/config.php'),
|
||||
[
|
||||
'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',
|
||||
],
|
||||
*/
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
11
tests/codeception/config/unit.php
Normal file
11
tests/codeception/config/unit.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Application configuration for unit tests
|
||||
*/
|
||||
return yii\helpers\ArrayHelper::merge(
|
||||
require(__DIR__ . '/../../../config/web.php'),
|
||||
require(__DIR__ . '/config.php'),
|
||||
[
|
||||
|
||||
]
|
||||
);
|
||||
2
tests/codeception/fixtures/.gitignore
vendored
Normal file
2
tests/codeception/fixtures/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
16
tests/codeception/functional.suite.yml
Normal file
16
tests/codeception/functional.suite.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
# 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
|
||||
config:
|
||||
Yii2:
|
||||
configFile: 'codeception/config/functional.php'
|
||||
10
tests/codeception/functional/AboutCept.php
Normal file
10
tests/codeception/functional/AboutCept.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
use tests\codeception\_pages\AboutPage;
|
||||
|
||||
/* @var $scenario Codeception\Scenario */
|
||||
|
||||
$I = new FunctionalTester($scenario);
|
||||
$I->wantTo('ensure that about works');
|
||||
AboutPage::openBy($I);
|
||||
$I->see('About', 'h1');
|
||||
48
tests/codeception/functional/ContactCept.php
Normal file
48
tests/codeception/functional/ContactCept.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use tests\codeception\_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');
|
||||
$I->see('Email cannot be blank');
|
||||
$I->see('Subject cannot be blank');
|
||||
$I->see('Body cannot be blank');
|
||||
$I->see('The verification code is incorrect');
|
||||
|
||||
$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 address is wrong');
|
||||
$I->dontSee('Name cannot be blank', '.help-inline');
|
||||
$I->see('Email is not a valid email address.');
|
||||
$I->dontSee('Subject cannot be blank', '.help-inline');
|
||||
$I->dontSee('Body cannot be blank', '.help-inline');
|
||||
$I->dontSee('The verification code is incorrect', '.help-inline');
|
||||
|
||||
$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->dontSeeElement('#contact-form');
|
||||
$I->see('Thank you for contacting us. We will respond to you as soon as possible.');
|
||||
11
tests/codeception/functional/HomeCept.php
Normal file
11
tests/codeception/functional/HomeCept.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
/* @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.');
|
||||
28
tests/codeception/functional/LoginCept.php
Normal file
28
tests/codeception/functional/LoginCept.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use tests\codeception\_pages\LoginPage;
|
||||
|
||||
/* @var $scenario Codeception\Scenario */
|
||||
|
||||
$I = new FunctionalTester($scenario);
|
||||
$I->wantTo('ensure that login works');
|
||||
|
||||
$loginPage = LoginPage::openBy($I);
|
||||
|
||||
$I->see('Login', 'h1');
|
||||
|
||||
$I->amGoingTo('try to login with empty credentials');
|
||||
$loginPage->login('', '');
|
||||
$I->expectTo('see validations errors');
|
||||
$I->see('Username cannot be blank.');
|
||||
$I->see('Password cannot be blank.');
|
||||
|
||||
$I->amGoingTo('try to login with wrong credentials');
|
||||
$loginPage->login('admin', 'wrong');
|
||||
$I->expectTo('see validations errors');
|
||||
$I->see('Incorrect username or password.');
|
||||
|
||||
$I->amGoingTo('try to login with correct credentials');
|
||||
$loginPage->login('admin', 'admin');
|
||||
$I->expectTo('see user info');
|
||||
$I->see('Logout (admin)');
|
||||
2
tests/codeception/functional/_bootstrap.php
Normal file
2
tests/codeception/functional/_bootstrap.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
new yii\web\Application(require(dirname(__DIR__) . '/config/functional.php'));
|
||||
2
tests/codeception/templates/.gitignore
vendored
Normal file
2
tests/codeception/templates/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
6
tests/codeception/unit.suite.yml
Normal file
6
tests/codeception/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
|
||||
3
tests/codeception/unit/_bootstrap.php
Normal file
3
tests/codeception/unit/_bootstrap.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
// add unit testing specific bootstrap code here
|
||||
0
tests/codeception/unit/fixtures/.gitkeep
Normal file
0
tests/codeception/unit/fixtures/.gitkeep
Normal file
0
tests/codeception/unit/fixtures/data/.gitkeep
Normal file
0
tests/codeception/unit/fixtures/data/.gitkeep
Normal file
60
tests/codeception/unit/models/ContactFormTest.php
Normal file
60
tests/codeception/unit/models/ContactFormTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\unit\models;
|
||||
|
||||
use Yii;
|
||||
use yii\codeception\TestCase;
|
||||
use Codeception\Specify;
|
||||
|
||||
class ContactFormTest extends TestCase
|
||||
{
|
||||
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 testContact()
|
||||
{
|
||||
$model = $this->getMock('app\models\ContactForm', ['validate']);
|
||||
$model->expects($this->once())->method('validate')->will($this->returnValue(true));
|
||||
|
||||
$model->attributes = [
|
||||
'name' => 'Tester',
|
||||
'email' => 'tester@example.com',
|
||||
'subject' => 'very important letter subject',
|
||||
'body' => 'body of current message',
|
||||
];
|
||||
|
||||
$model->contact('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';
|
||||
}
|
||||
|
||||
}
|
||||
61
tests/codeception/unit/models/LoginFormTest.php
Normal file
61
tests/codeception/unit/models/LoginFormTest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\unit\models;
|
||||
|
||||
use Yii;
|
||||
use yii\codeception\TestCase;
|
||||
use app\models\LoginForm;
|
||||
use Codeception\Specify;
|
||||
|
||||
class LoginFormTest extends TestCase
|
||||
{
|
||||
use Specify;
|
||||
|
||||
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' => 'demo',
|
||||
'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' => 'demo',
|
||||
'password' => 'demo',
|
||||
]);
|
||||
|
||||
$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();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
17
tests/codeception/unit/models/UserTest.php
Normal file
17
tests/codeception/unit/models/UserTest.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\unit\models;
|
||||
|
||||
use yii\codeception\TestCase;
|
||||
|
||||
class UserTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
// uncomment the following to load fixtures for user table
|
||||
//$this->loadFixtures(['user']);
|
||||
}
|
||||
|
||||
// TODO add test methods here
|
||||
}
|
||||
0
tests/codeception/unit/templates/fixtures/.gitkeep
Normal file
0
tests/codeception/unit/templates/fixtures/.gitkeep
Normal file
Reference in New Issue
Block a user