Skip to content

Commit

Permalink
add test file
Browse files Browse the repository at this point in the history
  • Loading branch information
shi-yang committed Jan 7, 2018
1 parent 3621c29 commit fddd2e8
Show file tree
Hide file tree
Showing 39 changed files with 792 additions and 0 deletions.
9 changes: 9 additions & 0 deletions backend/config/test-local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../common/config/test-local.php'),
require(__DIR__ . '/main.php'),
require(__DIR__ . '/main-local.php'),
require(__DIR__ . '/test.php'),
[
]
);
9 changes: 9 additions & 0 deletions backend/tests/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?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', __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 __DIR__ . '/../config/bootstrap.php';
Empty file added backend/tests/_data/.gitignore
Empty file.
13 changes: 13 additions & 0 deletions backend/tests/_data/login_data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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' => '[email protected]',
],
];
2 changes: 2 additions & 0 deletions backend/tests/_output/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
1 change: 1 addition & 0 deletions backend/tests/_support/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_generated
25 changes: 25 additions & 0 deletions backend/tests/_support/FunctionalTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace backend\tests;

/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class FunctionalTester extends \Codeception\Actor
{
use _generated\FunctionalTesterActions;
/**
* Define custom actions here
*/
}
25 changes: 25 additions & 0 deletions backend/tests/_support/UnitTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace backend\tests;

/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}
4 changes: 4 additions & 0 deletions backend/tests/functional.suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class_name: FunctionalTester
modules:
enabled:
- Yii2
45 changes: 45 additions & 0 deletions backend/tests/functional/LoginCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace backend\tests\functional;

use backend\tests\FunctionalTester;
use common\fixtures\UserFixture;

/**
* Class LoginCest
*/
class LoginCest
{

/**
* Load fixtures before db transaction begin
* Called in _before()
* @see \Codeception\Module\Yii2::_before()
* @see \Codeception\Module\Yii2::loadFixtures()
* @return array
*/
public function _fixtures()
{
return [
'user' => [
'class' => UserFixture::className(),
'dataFile' => codecept_data_dir() . 'login_data.php'
]
];
}

/**
* @param FunctionalTester $I
*/
public function loginUser(FunctionalTester $I)
{
$I->amOnPage('/site/login');
$I->fillField('Username', 'erau');
$I->fillField('Password', 'password_0');
$I->click('login-button');

$I->see('Logout (erau)', 'form button[type=submit]');
$I->dontSeeLink('Login');
$I->dontSeeLink('Signup');
}
}
16 changes: 16 additions & 0 deletions backend/tests/functional/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Here you can initialize variables via \Codeception\Util\Fixtures class
* to store data in global array and use it in Cests.
*
* ```php
* // Here _bootstrap.php
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
* ```
*
* In Cests
*
* ```php
* \Codeception\Util\Fixtures::get('user1');
* ```
*/
1 change: 1 addition & 0 deletions backend/tests/unit.suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class_name: UnitTester
16 changes: 16 additions & 0 deletions backend/tests/unit/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Here you can initialize variables via \Codeception\Util\Fixtures class
* to store data in global array and use it in Tests.
*
* ```php
* // Here _bootstrap.php
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
* ```
*
* In Tests
*
* ```php
* \Codeception\Util\Fixtures::get('user1');
* ```
*/
13 changes: 13 additions & 0 deletions common/config/test-local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/main.php'),
require(__DIR__ . '/main-local.php'),
require(__DIR__ . '/test.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2advanced_test',
]
],
]
);
11 changes: 11 additions & 0 deletions common/config/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
return [
'id' => 'app-common-tests',
'basePath' => dirname(__DIR__),
'components' => [
'user' => [
'class' => 'yii\web\User',
'identityClass' => 'common\models\User',
],
],
];
9 changes: 9 additions & 0 deletions frontend/config/test-local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../common/config/test-local.php'),
require(__DIR__ . '/main.php'),
require(__DIR__ . '/main-local.php'),
require(__DIR__ . '/test.php'),
[
]
);
9 changes: 9 additions & 0 deletions frontend/tests/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?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', __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 __DIR__ . '/../config/bootstrap.php';
13 changes: 13 additions & 0 deletions frontend/tests/_data/login_data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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' => '[email protected]',
],
];
23 changes: 23 additions & 0 deletions frontend/tests/_data/user.php
Original file line number Diff line number Diff line change
@@ -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' => '[email protected]',
],
[
'username' => 'troy.becker',
'auth_key' => 'EdKfXrx88weFMV0vIxuTMWKgfK2tS3Lp',
'password_hash' => '$2y$13$g5nv41Px7VBqhS3hVsVN2.MKfgT3jFdkXEsMC4rQJLfaMa7VaJqL2',
'password_reset_token' => '4BSNyiZNAuxjs5Mty990c47sVrgllIi_' . time(),
'created_at' => '1391885313',
'updated_at' => '1391885313',
'email' => '[email protected]',
'status' => '0',
],
];
2 changes: 2 additions & 0 deletions frontend/tests/_output/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
1 change: 1 addition & 0 deletions frontend/tests/_support/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_generated
33 changes: 33 additions & 0 deletions frontend/tests/_support/FunctionalTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace frontend\tests;

/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class FunctionalTester extends \Codeception\Actor
{
use _generated\FunctionalTesterActions;


public function seeValidationError($message)
{
$this->see($message, '.help-block');
}

public function dontSeeValidationError($message)
{
$this->dontSee($message, '.help-block');
}
}
25 changes: 25 additions & 0 deletions frontend/tests/_support/UnitTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace frontend\tests;

/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}
8 changes: 8 additions & 0 deletions frontend/tests/acceptance.suite.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://localhost:8080
browser: firefox
- Yii2:
part: init
20 changes: 20 additions & 0 deletions frontend/tests/acceptance/HomeCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace frontend\tests\acceptance;

use frontend\tests\AcceptanceTester;
use yii\helpers\Url;

class HomeCest
{
public function checkHome(AcceptanceTester $I)
{
$I->amOnPage(Url::toRoute('/site/index'));
$I->see('My Application');

$I->seeLink('About');
$I->click('About');
$I->wait(2); // wait for page to be opened

$I->see('This is the About page.');
}
}
16 changes: 16 additions & 0 deletions frontend/tests/acceptance/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Here you can initialize variables via \Codeception\Util\Fixtures class
* to store data in global array and use it in Cepts.
*
* ```php
* // Here _bootstrap.php
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
* ```
*
* In Cept
*
* ```php
* \Codeception\Util\Fixtures::get('user1');
* ```
*/
5 changes: 5 additions & 0 deletions frontend/tests/functional.suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class_name: FunctionalTester
modules:
enabled:
- Filesystem
- Yii2
13 changes: 13 additions & 0 deletions frontend/tests/functional/AboutCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
namespace frontend\tests\functional;

use frontend\tests\FunctionalTester;

class AboutCest
{
public function checkAbout(FunctionalTester $I)
{
$I->amOnRoute('site/about');
$I->see('About', 'h1');
}
}
Loading

0 comments on commit fddd2e8

Please sign in to comment.