first commit
This commit is contained in:
9
common/tests/_bootstrap.php
Executable file
9
common/tests/_bootstrap.php
Executable file
@ -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 __DIR__ . '/../../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
|
||||
require __DIR__ . '/../config/bootstrap.php';
|
14
common/tests/_data/user.php
Executable file
14
common/tests/_data/user.php
Executable 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',
|
||||
],
|
||||
];
|
2
common/tests/_output/.gitignore
vendored
Executable file
2
common/tests/_output/.gitignore
vendored
Executable file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
1
common/tests/_support/.gitignore
vendored
Executable file
1
common/tests/_support/.gitignore
vendored
Executable file
@ -0,0 +1 @@
|
||||
_generated
|
26
common/tests/_support/UnitTester.php
Executable file
26
common/tests/_support/UnitTester.php
Executable file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace common\tests;
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void verify($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
|
||||
*/
|
||||
}
|
7
common/tests/unit.suite.yml
Executable file
7
common/tests/unit.suite.yml
Executable file
@ -0,0 +1,7 @@
|
||||
suite_namespace: common\tests\unit
|
||||
actor: UnitTester
|
||||
bootstrap: false
|
||||
modules:
|
||||
enabled:
|
||||
- Yii2:
|
||||
part: fixtures
|
67
common/tests/unit/models/LoginFormTest.php
Executable file
67
common/tests/unit/models/LoginFormTest.php
Executable file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace common\tests\unit\models;
|
||||
|
||||
use Yii;
|
||||
use common\models\LoginForm;
|
||||
use common\fixtures\UserFixture;
|
||||
|
||||
/**
|
||||
* Login form test
|
||||
*/
|
||||
class LoginFormTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var \common\tests\UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function _fixtures()
|
||||
{
|
||||
return [
|
||||
'user' => [
|
||||
'class' => UserFixture::class,
|
||||
'dataFile' => codecept_data_dir() . 'user.php'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function testLoginNoUser()
|
||||
{
|
||||
$model = new LoginForm([
|
||||
'username' => 'not_existing_username',
|
||||
'password' => 'not_existing_password',
|
||||
]);
|
||||
|
||||
verify($model->login())->false();
|
||||
verify(Yii::$app->user->isGuest)->true();
|
||||
}
|
||||
|
||||
public function testLoginWrongPassword()
|
||||
{
|
||||
$model = new LoginForm([
|
||||
'username' => 'bayer.hudson',
|
||||
'password' => 'wrong_password',
|
||||
]);
|
||||
|
||||
verify($model->login())->false();
|
||||
verify( $model->errors)->arrayHasKey('password');
|
||||
verify(Yii::$app->user->isGuest)->true();
|
||||
}
|
||||
|
||||
public function testLoginCorrect()
|
||||
{
|
||||
$model = new LoginForm([
|
||||
'username' => 'bayer.hudson',
|
||||
'password' => 'password_0',
|
||||
]);
|
||||
|
||||
verify($model->login())->true();
|
||||
verify($model->errors)->arrayHasNotKey('password');
|
||||
verify(Yii::$app->user->isGuest)->false();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user