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