mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Инициализировано Yii2 приложение, выпилены лишние части, накинуты чуточку нужных
This commit is contained in:
4
tests/codeception/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'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user