Initial commit
This commit is contained in:
9
common/tests/_bootstrap.php
Normal file
9
common/tests/_bootstrap.php
Normal 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';
|
||||
23
common/tests/_data/user.php
Normal file
23
common/tests/_data/user.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
'auth_key' => 'HP187Mvq7Mmm3CTU80dLkGmni_FUH_lR',
|
||||
//password_0
|
||||
'password_hash' => '$2y$13$.NVUBcghbQPiEcBh4LmI7.ctT3FDofwpgrKIAfwWvsr.wBM0l6Y7u',
|
||||
'password_reset_token' => 'ExzkCOaYc1L8IOBs4wdTGGbgNiG3Wz1I_1402312317',
|
||||
'created_at' => '1402312317',
|
||||
'updated_at' => '1402312317',
|
||||
'email' => 'nicole.paucek@schultz.info',
|
||||
],
|
||||
[
|
||||
//password
|
||||
'password_hash' => '$2y$13$k2hQ8aV/z6V0Y7pRbq1ufOUSaJI7EhNvvTUIoj2s/rxAmgyY95KPa',
|
||||
'email' => 'admin@example.com',
|
||||
'auth_key' => '1',
|
||||
'status' => '1',
|
||||
'sales_agent_id' => '0',
|
||||
'created_at' => '1402312317',
|
||||
'updated_at' => '1402312317',
|
||||
],
|
||||
];
|
||||
2
common/tests/_output/.gitignore
vendored
Normal file
2
common/tests/_output/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
1
common/tests/_support/.gitignore
vendored
Normal file
1
common/tests/_support/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
_generated
|
||||
26
common/tests/_support/UnitTester.php
Normal file
26
common/tests/_support/UnitTester.php
Normal 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
Normal file
7
common/tests/unit.suite.yml
Normal 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
Normal file
67
common/tests/unit/models/LoginFormTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace 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([
|
||||
'email' => 'not_existing_username',
|
||||
'password' => 'not_existing_password',
|
||||
]);
|
||||
|
||||
verify($model->login())->false();
|
||||
verify(Yii::$app->user->isGuest)->true();
|
||||
}
|
||||
|
||||
public function testLoginWrongPassword()
|
||||
{
|
||||
$model = new LoginForm([
|
||||
'email' => 'nicole.paucek@schultz.info',
|
||||
'password' => 'wrong_password',
|
||||
]);
|
||||
|
||||
verify($model->login())->false();
|
||||
verify( $model->errors)->arrayHasKey('password');
|
||||
verify(Yii::$app->user->isGuest)->true();
|
||||
}
|
||||
|
||||
public function testLoginCorrect()
|
||||
{
|
||||
$model = new LoginForm([
|
||||
'email' => 'admin@example.com',
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
verify($model->login())->true();
|
||||
verify($model->errors)->arrayHasNotKey('password');
|
||||
verify(Yii::$app->user->isGuest)->false();
|
||||
}
|
||||
}
|
||||
45
common/tests/unit/traits/FormattedDollarTraitTest.php
Normal file
45
common/tests/unit/traits/FormattedDollarTraitTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace unit\traits;
|
||||
|
||||
use common\traits\FormattedDollarTrait;
|
||||
use Yii;
|
||||
|
||||
use function PHPUnit\Framework\assertEquals;
|
||||
|
||||
/**
|
||||
* Formatted dollar trait test
|
||||
*/
|
||||
class FormattedDollarTraitTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @dataProvider floatDataProvider
|
||||
* @return void
|
||||
*/
|
||||
public function testConvertToCents($test, $expected)
|
||||
{
|
||||
$mock = $this->getMockForTrait(FormattedDollarTrait::class);
|
||||
|
||||
$this->assertEquals($expected, $mock->convertToCents($test));
|
||||
}
|
||||
|
||||
public function floatDataProvider()
|
||||
{
|
||||
return [
|
||||
[12.445, 1244],
|
||||
[-13.678901234, -1367],
|
||||
["-10.4", -1040],
|
||||
["-10", -1000],
|
||||
["11.445", 1144],
|
||||
["533.3.3533.11,445", 533335331144],
|
||||
["1,40032,0030.445", 140032003044],
|
||||
[124.99, 12499],
|
||||
[-1.4, -140],
|
||||
[14, 1400],
|
||||
[.99, 99],
|
||||
[2.3, 230],
|
||||
[-30, -3000],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user