Initial commit

This commit is contained in:
Chris Smith
2025-02-19 14:51:16 +01:00
commit d82a6cad96
198 changed files with 13819 additions and 0 deletions

View 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';

View 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
View File

@@ -0,0 +1,2 @@
*
!.gitignore

1
common/tests/_support/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
_generated

View 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
*/
}

View File

@@ -0,0 +1,7 @@
suite_namespace: common\tests\unit
actor: UnitTester
bootstrap: false
modules:
enabled:
- Yii2:
part: fixtures

View 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();
}
}

View 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],
];
}
}