mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
add tests
This commit is contained in:
parent
0ff97e74ff
commit
01837d3755
|
|
@ -2051,7 +2051,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
$objects = $mapper::getBy($values, static::$hasMany[$member]['by'], RelationType::ALL, null, $depth);
|
||||
}
|
||||
|
||||
$refProp->setValue($obj, !\is_array($objects) ? [$objects->getId() => $objects] : $objects);
|
||||
$refProp->setValue($obj, !\is_array($objects) ? [$mapper::getObjectId($objects) => $objects] : $objects);
|
||||
|
||||
if (!$accessible) {
|
||||
$refProp->setAccessible(false);
|
||||
|
|
|
|||
|
|
@ -207,12 +207,12 @@ class Localization implements \JsonSerializable
|
|||
{
|
||||
$l11n = new self();
|
||||
$l11n->setCountry($json['country']);
|
||||
$l11n->setTimezone($json['timezone']);
|
||||
$l11n->setTimezone($json['timezone'] ?? 'America/New_York');
|
||||
$l11n->setLanguage($json['language']);
|
||||
$l11n->setCurrency($json['currency']);
|
||||
$l11n->setCurrencyFormat($json['currencyformat']);
|
||||
$l11n->setCurrency(\is_string($json['currency']) ? $json['currency'] : ($json['currency']['code'] ?? ISO4217Enum::_USD));
|
||||
$l11n->setCurrencyFormat(isset($json['currencyformat']) && \is_string($json['currencyformat']) ? $json['currencyformat'] : ($json['currency']['format'] ?? '1'));
|
||||
$l11n->setDecimal($json['decimal']);
|
||||
$l11n->setThousands($json['thousands']);
|
||||
$l11n->setThousands($json['thousand']);
|
||||
$l11n->setAngle($json['angle']);
|
||||
$l11n->setTemperature($json['temperature']);
|
||||
$l11n->setDatetime($json['datetime']);
|
||||
|
|
@ -772,7 +772,7 @@ class Localization implements \JsonSerializable
|
|||
'currency' => $this->currency,
|
||||
'currencyformat' => $this->currencyFormat,
|
||||
'decimal' => $this->decimal,
|
||||
'thousands' => $this->thousands,
|
||||
'thousand' => $this->thousands,
|
||||
'angle' => $this->angle,
|
||||
'temperature' => $this->temperature,
|
||||
'datetime' => $this->datetime,
|
||||
|
|
|
|||
|
|
@ -39,6 +39,10 @@ final class FormElementGenerator
|
|||
*/
|
||||
public static function generate(array $json, $value = null, array $lang = []) : string
|
||||
{
|
||||
if (!isset($json['type'])) {
|
||||
return 'INVALID';
|
||||
}
|
||||
|
||||
if ($json['type'] === 'select') {
|
||||
return self::generateSelect($json, $value, $lang);
|
||||
} elseif ($json['type'] === 'input') {
|
||||
|
|
@ -132,7 +136,7 @@ final class FormElementGenerator
|
|||
$value ??= $json['default']['value'];
|
||||
|
||||
$element .= '>';
|
||||
$element .= isset($json['default']) ? ' value="' . $value . '"' : '';
|
||||
$element .= isset($json['default']) ? $value : '';
|
||||
$element .= '</textarea>';
|
||||
|
||||
return $element;
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ abstract class ModuleAbstract
|
|||
/**
|
||||
* Update a model
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param int $account Account id
|
||||
* @param mixed $old Response object old
|
||||
* @param mixed $new Response object new
|
||||
* @param \Closure|string $mapper Object mapper
|
||||
|
|
@ -307,7 +307,7 @@ abstract class ModuleAbstract
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function updateModel(RequestAbstract $request, $old, $new, $mapper, string $trigger) : void
|
||||
protected function updateModel(int $account, $old, $new, $mapper, string $trigger) : void
|
||||
{
|
||||
$this->app->eventManager->trigger('PRE:Module:' . static::MODULE_NAME . '-' . $trigger . '-update', '', $old);
|
||||
if (\is_string($mapper)) {
|
||||
|
|
@ -316,7 +316,7 @@ abstract class ModuleAbstract
|
|||
$mapper();
|
||||
}
|
||||
$this->app->eventManager->trigger('POST:Module:' . static::MODULE_NAME . '-' . $trigger . '-update', '', [
|
||||
$request->getHeader()->getAccount(),
|
||||
$account,
|
||||
$old, $new,
|
||||
0, 0,
|
||||
static::MODULE_NAME,
|
||||
|
|
@ -326,21 +326,21 @@ abstract class ModuleAbstract
|
|||
/**
|
||||
* Delete a model
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param mixed $obj Response object
|
||||
* @param string $mapper Object mapper
|
||||
* @param string $trigger Trigger for the event manager
|
||||
* @param int $account Account id
|
||||
* @param mixed $obj Response object
|
||||
* @param string $mapper Object mapper
|
||||
* @param string $trigger Trigger for the event manager
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function deleteModel(RequestAbstract $request, $obj, string $mapper, string $trigger) : void
|
||||
protected function deleteModel(int $account, $obj, string $mapper, string $trigger) : void
|
||||
{
|
||||
$this->app->eventManager->trigger('PRE:Module:' . static::MODULE_NAME . '-' . $trigger . '-delete', '', $obj);
|
||||
$mapper::delete($obj);
|
||||
$this->app->eventManager->trigger('POST:Module:' . static::MODULE_NAME . '-' . $trigger . '-delete', '', [
|
||||
$request->getHeader()->getAccount(),
|
||||
$account,
|
||||
$obj, null,
|
||||
0, 0,
|
||||
static::MODULE_NAME,
|
||||
|
|
@ -350,23 +350,23 @@ abstract class ModuleAbstract
|
|||
/**
|
||||
* Create a model relation
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param mixed $rel1 Response object relation1
|
||||
* @param mixed $rel2 Response object relation2
|
||||
* @param string $mapper Object mapper
|
||||
* @param string $field Relation field
|
||||
* @param string $trigger Trigger for the event manager
|
||||
* @param int $account Account id
|
||||
* @param mixed $rel1 Object relation1
|
||||
* @param mixed $rel2 Object relation2
|
||||
* @param string $mapper Object mapper
|
||||
* @param string $field Relation field
|
||||
* @param string $trigger Trigger for the event manager
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function createModelRelation(RequestAbstract $request, $rel1, $rel2, string $mapper, string $field, string $trigger) : void
|
||||
protected function createModelRelation(int $account, $rel1, $rel2, string $mapper, string $field, string $trigger) : void
|
||||
{
|
||||
$this->app->eventManager->trigger('PRE:Module:' . static::MODULE_NAME . '-' . $trigger . '-relation', '', $rel1);
|
||||
$mapper::createRelation($field, $rel1, $rel2);
|
||||
$this->app->eventManager->trigger('POST:Module:' . static::MODULE_NAME . '-' . $trigger . '-relation', '', [
|
||||
$request->getHeader()->getAccount(),
|
||||
$account,
|
||||
$rel1, $rel2,
|
||||
0, 0,
|
||||
static::MODULE_NAME,
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class Heap
|
|||
}
|
||||
}
|
||||
|
||||
$this->nodes = \array_splice($this->nodes, $lo, 0, $x);
|
||||
\array_splice($this->nodes, $lo, 0, [$x]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -224,12 +224,7 @@ class Heap
|
|||
{
|
||||
$pos = null;
|
||||
foreach ($this->nodes as $key => $node) {
|
||||
if (\is_scalar($item)) {
|
||||
if ($node === $item) {
|
||||
$pos = $key;
|
||||
break;
|
||||
}
|
||||
} elseif ($item->isEqual($node)) {
|
||||
if ($item->isEqual($node)) {
|
||||
$pos = $key;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -329,7 +329,7 @@ final class Argument implements UriInterface
|
|||
*/
|
||||
public function getPathOffset() : int
|
||||
{
|
||||
return \substr_count($this->rootPath, '/') - 1;
|
||||
return $this->pathOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -246,10 +246,13 @@ final class ArrayUtils
|
|||
throw new \Exception(); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
\fputcsv($outstream, $data, $delimiter, $enclosure, $escape);
|
||||
foreach ($data as $line) {
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
\fputcsv($outstream, $line, $delimiter, $enclosure, $escape);
|
||||
}
|
||||
|
||||
\rewind($outstream);
|
||||
$csv = \fgets($outstream);
|
||||
$csv = \stream_get_contents($outstream);
|
||||
\fclose($outstream);
|
||||
|
||||
return $csv === false ? '' : $csv;
|
||||
|
|
|
|||
|
|
@ -187,10 +187,6 @@ class View extends ViewAbstract
|
|||
*/
|
||||
public function getText($translation, string $module = null, string $theme = null) : string
|
||||
{
|
||||
if ($this->l11nManager === null) {
|
||||
return 'ERROR';
|
||||
}
|
||||
|
||||
if ($module === null && $this->module === null) {
|
||||
$this->setModuleDynamically();
|
||||
}
|
||||
|
|
@ -226,8 +222,13 @@ class View extends ViewAbstract
|
|||
throw new InvalidModuleException($this->template);
|
||||
}
|
||||
|
||||
$start = $start + \strlen($match);
|
||||
$end = \strpos($this->template, '/', $start);
|
||||
$start = $start + \strlen($match);
|
||||
$end = \strpos($this->template, '/', $start);
|
||||
|
||||
if ($end === false) {
|
||||
throw new InvalidModuleException($this->template);
|
||||
}
|
||||
|
||||
$this->module = \substr($this->template, $start, $end - $start);
|
||||
|
||||
if ($this->module === false) {
|
||||
|
|
|
|||
|
|
@ -198,11 +198,11 @@ class AccountTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @testdox Account permissions can be added and checked for existence
|
||||
* @testdox Account permissions can be added
|
||||
* @covers phpOMS\Account\Account<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testPermissionHandling() : void
|
||||
public function testPermissionAdd() : void
|
||||
{
|
||||
$account = new Account();
|
||||
$account->generatePassword('abcd');
|
||||
|
|
@ -221,17 +221,45 @@ class AccountTest extends \PHPUnit\Framework\TestCase
|
|||
new class() extends PermissionAbstract {},
|
||||
]);
|
||||
self::assertCount(4, $account->getPermissions());
|
||||
}
|
||||
|
||||
$account->addPermissions([[
|
||||
new class() extends PermissionAbstract {},
|
||||
new class() extends PermissionAbstract {},
|
||||
]]);
|
||||
self::assertCount(6, $account->getPermissions());
|
||||
/**
|
||||
* @testdox Account permissions can be checked for existence
|
||||
* @covers phpOMS\Account\Account<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testPermissionExists() : void
|
||||
{
|
||||
$account = new Account();
|
||||
$account->generatePassword('abcd');
|
||||
|
||||
$account->addPermission(new class() extends PermissionAbstract {});
|
||||
self::assertCount(1, $account->getPermissions());
|
||||
|
||||
self::assertFalse($account->hasPermission(PermissionType::READ, 1, 'a', 'a', 1, 1, 1));
|
||||
self::assertTrue($account->hasPermission(PermissionType::NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Account permissions can be removed
|
||||
* @covers phpOMS\Account\Account<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testPermissionRemove() : void
|
||||
{
|
||||
$account = new Account();
|
||||
$account->generatePassword('abcd');
|
||||
|
||||
$perm = new class() extends PermissionAbstract {};
|
||||
$perm->setPermission(PermissionType::READ);
|
||||
|
||||
$account->addPermission($perm);
|
||||
self::assertCount(1, $account->getPermissions());
|
||||
|
||||
$account->removePermission($perm);
|
||||
self::assertCount(0, $account->getPermissions());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An account can have it's own localization
|
||||
* @covers phpOMS\Account\Account<extended>
|
||||
|
|
|
|||
|
|
@ -94,36 +94,63 @@ class GroupTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @testdox Group permissions can be added and checked for existence
|
||||
* @testdox Group permissions can be added
|
||||
* @covers phpOMS\Account\Group<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testPermissionHandling() : void
|
||||
public function testPermissionAdd() : void
|
||||
{
|
||||
$group = new Group();
|
||||
$group->addPermission(new class() extends PermissionAbstract {});
|
||||
self::assertCount(1, $group->getPermissions());
|
||||
$account = new Group();
|
||||
|
||||
$group->setPermissions([
|
||||
$account->addPermission(new class() extends PermissionAbstract {});
|
||||
self::assertCount(1, $account->getPermissions());
|
||||
|
||||
$account->setPermissions([
|
||||
new class() extends PermissionAbstract {},
|
||||
new class() extends PermissionAbstract {},
|
||||
]);
|
||||
self::assertCount(2, $group->getPermissions());
|
||||
self::assertCount(2, $account->getPermissions());
|
||||
|
||||
$group->addPermissions([
|
||||
$account->addPermissions([
|
||||
new class() extends PermissionAbstract {},
|
||||
new class() extends PermissionAbstract {},
|
||||
]);
|
||||
self::assertCount(4, $group->getPermissions());
|
||||
self::assertCount(4, $account->getPermissions());
|
||||
}
|
||||
|
||||
$group->addPermissions([[
|
||||
new class() extends PermissionAbstract {},
|
||||
new class() extends PermissionAbstract {},
|
||||
]]);
|
||||
self::assertCount(6, $group->getPermissions());
|
||||
/**
|
||||
* @testdox Group permissions can be checked for existence
|
||||
* @covers phpOMS\Account\Group<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testPermissionExists() : void
|
||||
{
|
||||
$account = new Group();
|
||||
|
||||
self::assertFalse($group->hasPermission(PermissionType::READ, 1, 'a', 'a', 1, 1, 1));
|
||||
self::assertTrue($group->hasPermission(PermissionType::NONE));
|
||||
$account->addPermission(new class() extends PermissionAbstract {});
|
||||
self::assertCount(1, $account->getPermissions());
|
||||
|
||||
self::assertFalse($account->hasPermission(PermissionType::READ, 1, 'a', 'a', 1, 1, 1));
|
||||
self::assertTrue($account->hasPermission(PermissionType::NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Group permissions can be removed
|
||||
* @covers phpOMS\Account\Group<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testPermissionRemove() : void
|
||||
{
|
||||
$account = new Group();
|
||||
|
||||
$perm = new class() extends PermissionAbstract {};
|
||||
$perm->setPermission(PermissionType::READ);
|
||||
|
||||
$account->addPermission($perm);
|
||||
self::assertCount(1, $account->getPermissions());
|
||||
|
||||
$account->removePermission($perm);
|
||||
self::assertCount(0, $account->getPermissions());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -169,6 +169,26 @@ class PermissionAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals(PermissionType::READ, $perm->getPermission());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Two permissions can be checked for equality
|
||||
* @covers phpOMS\Account\PermissionAbstract
|
||||
* @group framework
|
||||
*/
|
||||
public function testEqualPermissions() : void
|
||||
{
|
||||
$perm1 = new class() extends PermissionAbstract {};
|
||||
$perm1->setUnit(1);
|
||||
$perm1->setPermission(PermissionType::READ);
|
||||
|
||||
self::assertTrue($perm1->isEqual($perm1));
|
||||
|
||||
$perm2 = new class() extends PermissionAbstract {};
|
||||
$perm2->setUnit(1);
|
||||
$perm2->setPermission(PermissionType::CREATE);
|
||||
|
||||
self::assertFalse($perm1->isEqual($perm2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Correct permissions are validated
|
||||
* @covers phpOMS\Account\PermissionAbstract
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ class CountryTest extends \PHPUnit\Framework\TestCase
|
|||
public function testDefaults() : void
|
||||
{
|
||||
$obj = new Country();
|
||||
self::assertEquals(0, $obj->getId());
|
||||
self::assertEquals('', $obj->getName());
|
||||
self::assertEquals('', $obj->getCode2());
|
||||
self::assertEquals('', $obj->getCode3());
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ class LanguageTest extends \PHPUnit\Framework\TestCase
|
|||
public function testDefaults() : void
|
||||
{
|
||||
$obj = new Language();
|
||||
self::assertEquals(0, $obj->getId());
|
||||
self::assertEquals('', $obj->getName());
|
||||
self::assertEquals('', $obj->getNative());
|
||||
self::assertEquals('', $obj->getCode2());
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ declare(strict_types=1);
|
|||
namespace phpOMS\tests\Localization;
|
||||
|
||||
use phpOMS\Localization\L11nManager;
|
||||
use phpOMS\Localization\Localization;
|
||||
|
||||
require_once __DIR__ . '/../Autoloader.php';
|
||||
|
||||
|
|
@ -56,26 +57,6 @@ class L11nManagerTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals('ERROR', $this->l11nManager->getText('en', 'Admin', 'Backend', 'Test2'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Loading language for an invalid module throws Exception
|
||||
* @covers phpOMS\Localization\L11nManager
|
||||
* @group framework
|
||||
*/
|
||||
public function testInvalidModule() : void
|
||||
{
|
||||
self::expectException(\Exception::class);
|
||||
|
||||
$expected = [
|
||||
'en' => [
|
||||
'Admin' => [
|
||||
'Test' => 'Test string',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->l11nManager->loadLanguage('en', 'doesNotExist', $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Language data can be loaded and output as plain text or html
|
||||
* @covers phpOMS\Localization\L11nManager
|
||||
|
|
@ -121,4 +102,79 @@ class L11nManagerTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals(['Test' => ['key' => 'value']], $this->l11nManager2->getModuleLanguage('en'));
|
||||
self::assertEquals(['key' => 'value'], $this->l11nManager2->getModuleLanguage('en', 'Test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The numeric value can be printed based on the localization
|
||||
* @covers phpOMS\Localization\L11nManager
|
||||
* @group framework
|
||||
*/
|
||||
public function testGetNumeric() : void
|
||||
{
|
||||
$l11n = Localization::fromLanguage('en');
|
||||
self::assertEquals('1.23', $this->l11nManager->getNumeric($l11n, 1.2345, 'medium'));
|
||||
self::assertEquals('1.235', $this->l11nManager->getNumeric($l11n, 1.2345, 'long'));
|
||||
self::assertEquals('1,234.235', $this->l11nManager->getNumeric($l11n, 1234.2345, 'long'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The percentage value can be printed based on the localization
|
||||
* @covers phpOMS\Localization\L11nManager
|
||||
* @group framework
|
||||
*/
|
||||
public function testGetPercentage() : void
|
||||
{
|
||||
$l11n = Localization::fromLanguage('en');
|
||||
self::assertEquals('1.23%', $this->l11nManager->getPercentage($l11n, 1.2345, 'medium'));
|
||||
self::assertEquals('1.235%', $this->l11nManager->getPercentage($l11n, 1.2345, 'long'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The currency value can be printed based on the localization
|
||||
* @covers phpOMS\Localization\L11nManager
|
||||
* @group framework
|
||||
*/
|
||||
public function testGetCurrency() : void
|
||||
{
|
||||
$l11n = Localization::fromLanguage('en');
|
||||
self::assertEquals('USD 1.23', $this->l11nManager->getCurrency($l11n, 1.2345, 'medium'));
|
||||
self::assertEquals('USD 1.235', $this->l11nManager->getCurrency($l11n, 1.2345, 'long'));
|
||||
|
||||
$this->l11nManager->loadLanguage('en', '0', ['0' => ['CurrencyK' => 'K']]);
|
||||
self::assertEquals('K$ 12.345', $this->l11nManager->getCurrency($l11n, 12345.0, 'long', '$', 1000));
|
||||
self::assertEquals('KUSD 12.345', $this->l11nManager->getCurrency($l11n, 12345.0, 'long', null, 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The datetime value can be printed based on the localization
|
||||
* @covers phpOMS\Localization\L11nManager
|
||||
* @group framework
|
||||
*/
|
||||
public function testGetDateTime() : void
|
||||
{
|
||||
$l11n = Localization::fromLanguage('en');
|
||||
|
||||
$date = new \DateTime('2020-01-01 13:45:22');
|
||||
self::assertEquals('2020.01.01', $this->l11nManager->getDateTime($l11n, $date, 'medium'));
|
||||
self::assertEquals('2020.01.01 01:45', $this->l11nManager->getDateTime($l11n, $date, 'long'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Loading language for an invalid module throws Exception
|
||||
* @covers phpOMS\Localization\L11nManager
|
||||
* @group framework
|
||||
*/
|
||||
public function testInvalidModule() : void
|
||||
{
|
||||
self::expectException(\Exception::class);
|
||||
|
||||
$expected = [
|
||||
'en' => [
|
||||
'Admin' => [
|
||||
'Test' => 'Test string',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->l11nManager->loadLanguage('en', 'doesNotExist', $expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,14 +61,17 @@ class LocalizationTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertEquals(0, $this->localization->getId());
|
||||
self::assertTrue(ISO3166TwoEnum::isValidValue($this->localization->getCountry()));
|
||||
self::assertTrue(TimeZoneEnumArray::isValidValue($this->localization->getTimezone()));
|
||||
self::assertTrue(ISO639x1Enum::isValidValue($this->localization->getLanguage()));
|
||||
self::assertTrue(ISO4217CharEnum::isValidValue($this->localization->getCurrency()));
|
||||
self::assertEquals('0', $this->localization->getCurrencyFormat());
|
||||
self::assertEquals('.', $this->localization->getDecimal());
|
||||
self::assertEquals(',', $this->localization->getThousands());
|
||||
self::assertEquals([], $this->localization->getDatetime());
|
||||
|
||||
self::assertEquals([], $this->localization->getPrecision());
|
||||
self::assertEquals([], $this->localization->getSpeed());
|
||||
self::assertEquals([], $this->localization->getWeight());
|
||||
self::assertEquals([], $this->localization->getLength());
|
||||
|
|
@ -258,6 +261,28 @@ class LocalizationTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals([1], $this->localization->getWeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The currency format can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
* @group framework
|
||||
*/
|
||||
public function testCurrencyFormatInputOutput() : void
|
||||
{
|
||||
$this->localization->setCurrencyFormat('1');
|
||||
self::assertEquals('1', $this->localization->getCurrencyFormat());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The precision can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
* @group framework
|
||||
*/
|
||||
public function testPrecisionInputOutput() : void
|
||||
{
|
||||
$this->localization->setPrecision([1]);
|
||||
self::assertEquals([1], $this->localization->getPrecision());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The length can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
|
|
@ -313,6 +338,22 @@ class LocalizationTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals(ISO4217CharEnum::_USD, $this->localization->getCurrency());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Localization data can be serialized and unserialized
|
||||
* @covers phpOMS\Localization\Localization
|
||||
* @group framework
|
||||
*/
|
||||
public function testLocalizationSerialize() : void
|
||||
{
|
||||
$this->localization->loadFromLanguage(ISO639x1Enum::_EN);
|
||||
$l11n1 = $this->localization->jsonSerialize();
|
||||
|
||||
$l11nObj = Localization::fromJson($l11n1);
|
||||
$l11n2 = $l11nObj->jsonSerialize();
|
||||
|
||||
self::assertEquals($l11n1, $l11n2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox If no locale file for a specified country exists or a wild card country is used the first match of a locale file based on the defined language is loaded
|
||||
* @covers phpOMS\Localization\Localization
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class IntegrationTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
/**
|
||||
* @testdox Integration by summing up rectangle areas from the left side
|
||||
* @covers phpOMS\tests\Math\Numerics\IntegrationTest
|
||||
* @covers phpOMS\Math\Numerics\Integration
|
||||
* @group framework
|
||||
*/
|
||||
public function testLRect(): void
|
||||
|
|
@ -42,7 +42,7 @@ class IntegrationTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
/**
|
||||
* @testdox Integration by summing up rectangle areas from the right side
|
||||
* @covers phpOMS\tests\Math\Numerics\IntegrationTest
|
||||
* @covers phpOMS\Math\Numerics\Integration
|
||||
* @group framework
|
||||
*/
|
||||
public function testRRect(): void
|
||||
|
|
@ -55,7 +55,7 @@ class IntegrationTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
/**
|
||||
* @testdox Integration by summing up rectangle areas from the middle
|
||||
* @covers phpOMS\tests\Math\Numerics\IntegrationTest
|
||||
* @covers phpOMS\Math\Numerics\Integration
|
||||
* @group framework
|
||||
*/
|
||||
public function testMRect(): void
|
||||
|
|
@ -68,7 +68,7 @@ class IntegrationTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
/**
|
||||
* @testdox Integration by summing up trapezoid areas
|
||||
* @covers phpOMS\tests\Math\Numerics\IntegrationTest
|
||||
* @covers phpOMS\Math\Numerics\Integration
|
||||
* @group framework
|
||||
*/
|
||||
public function testTrapeze(): void
|
||||
|
|
@ -81,7 +81,7 @@ class IntegrationTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
/**
|
||||
* @testdox Integration by using the simpson formula
|
||||
* @covers phpOMS\tests\Math\Numerics\IntegrationTest
|
||||
* @covers phpOMS\Math\Numerics\Integration
|
||||
* @group framework
|
||||
*/
|
||||
public function testSimpson(): void
|
||||
|
|
|
|||
|
|
@ -34,8 +34,6 @@ class ConsoleRequestTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals(OSType::LINUX, $request->getOS());
|
||||
self::assertEquals('127.0.0.1', $request->getOrigin());
|
||||
self::assertEmpty($request->getBody());
|
||||
self::assertEquals(RouteVerb::GET, $request->getRouteVerb());
|
||||
self::assertEquals(RequestMethod::GET, $request->getMethod());
|
||||
self::assertInstanceOf('\phpOMS\Message\Console\ConsoleHeader', $request->getHeader());
|
||||
self::assertEquals('', $request->__toString());
|
||||
self::assertFalse($request->hasData('key'));
|
||||
|
|
@ -50,16 +48,10 @@ class ConsoleRequestTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals(OSType::WINDOWS_XP, $request->getOS());
|
||||
|
||||
$request->setMethod(RequestMethod::PUT);
|
||||
self::assertEquals(RequestMethod::PUT, $request->getMethod());
|
||||
self::assertEquals(RouteVerb::PUT, $request->getRouteVerb());
|
||||
|
||||
$request->setMethod(RequestMethod::DELETE);
|
||||
self::assertEquals(RequestMethod::DELETE, $request->getMethod());
|
||||
self::assertEquals(RouteVerb::DELETE, $request->getRouteVerb());
|
||||
|
||||
$request->setMethod(RequestMethod::POST);
|
||||
self::assertEquals(RequestMethod::POST, $request->getMethod());
|
||||
self::assertEquals(RouteVerb::SET, $request->getRouteVerb());
|
||||
|
||||
self::assertEquals('get:some/test/path', $request->getUri()->__toString());
|
||||
|
||||
|
|
@ -84,13 +76,4 @@ class ConsoleRequestTest extends \PHPUnit\Framework\TestCase
|
|||
$request = new ConsoleRequest(new Argument('get:some/test/path?test=var'));
|
||||
self::assertEquals('get:some/test/path?test=var', $request->__toString());
|
||||
}
|
||||
|
||||
public function testInvalidRouteVerb() : void
|
||||
{
|
||||
self::expectException(\Exception::class);
|
||||
|
||||
$request = new ConsoleRequest(new Argument('get:some/test/path'));
|
||||
$request->setMethod('failure');
|
||||
$request->getRouteVerb();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
386
tests/Model/Html/FormElementGeneratorTest.php
Normal file
386
tests/Model/Html/FormElementGeneratorTest.php
Normal file
|
|
@ -0,0 +1,386 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\tests\Model\Html;
|
||||
|
||||
use phpOMS\Model\Html\FormElementGenerator;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Model\Html\FormElementGeneratorTest: Form element generator
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class FormElementGeneratorTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox A text input element can be generated
|
||||
* @covers phpOMS\Model\Html\FormElementGenerator
|
||||
* @group framework
|
||||
*/
|
||||
public function testGenerateTextInput() : void
|
||||
{
|
||||
$element = [
|
||||
'type' => 'input',
|
||||
'subtype' => 'text',
|
||||
'attributes' => [
|
||||
'id' => 'testId',
|
||||
'name' => 'testName',
|
||||
'type' => 'text',
|
||||
],
|
||||
'default' => [
|
||||
'value' => 'testValue',
|
||||
],
|
||||
];
|
||||
|
||||
self::assertEquals(
|
||||
'<input id="testId" name="testName" type="text" value="testValue">',
|
||||
FormElementGenerator::generate($element)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A text input element can be generated with a custom value
|
||||
* @covers phpOMS\Model\Html\FormElementGenerator
|
||||
* @group framework
|
||||
*/
|
||||
public function testGenerateTextInputWithValue() : void
|
||||
{
|
||||
$element = [
|
||||
'type' => 'input',
|
||||
'subtype' => 'text',
|
||||
'attributes' => [
|
||||
'id' => 'testId',
|
||||
'name' => 'testName',
|
||||
'type' => 'text',
|
||||
],
|
||||
'default' => [
|
||||
'value' => 'testValue',
|
||||
],
|
||||
];
|
||||
|
||||
self::assertEquals(
|
||||
'<input id="testId" name="testName" type="text" value="manualValue">',
|
||||
FormElementGenerator::generate($element, 'manualValue')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A datetime input element can be generated with custom formatting
|
||||
* @covers phpOMS\Model\Html\FormElementGenerator
|
||||
* @group framework
|
||||
*/
|
||||
public function testGenerateDateTimeInput() : void
|
||||
{
|
||||
$element = [
|
||||
'type' => 'input',
|
||||
'subtype' => 'datetime',
|
||||
'attributes' => [
|
||||
'id' => 'testId',
|
||||
'name' => 'testName',
|
||||
'type' => 'datetime',
|
||||
],
|
||||
'default' => [
|
||||
"value" => "2019-02-03 01:23",
|
||||
"format" => "Y-m-d"
|
||||
],
|
||||
];
|
||||
|
||||
self::assertEquals(
|
||||
'<input id="testId" name="testName" type="datetime" value="2019-02-03">',
|
||||
FormElementGenerator::generate($element)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A checkbox element can be generated
|
||||
* @covers phpOMS\Model\Html\FormElementGenerator
|
||||
* @group framework
|
||||
*/
|
||||
public function testGenerateCheckboxInput() : void
|
||||
{
|
||||
$element = [
|
||||
'type' => 'input',
|
||||
'subtype' => 'checkbox',
|
||||
'attributes' => [
|
||||
'id' => 'testId',
|
||||
'name' => 'testName',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
'default' => [
|
||||
'value' => 'testValue',
|
||||
'checked' => true,
|
||||
'content' => 'testContent'
|
||||
],
|
||||
];
|
||||
|
||||
self::assertEquals(
|
||||
'<input id="testId" name="testName" type="checkbox" value="testValue" checked><label for="testId">testContent</label>',
|
||||
FormElementGenerator::generate($element)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A checkbox element can be generated with a localized label element
|
||||
* @covers phpOMS\Model\Html\FormElementGenerator
|
||||
* @group framework
|
||||
*/
|
||||
public function testGenerateCheckboxWithLanguageInput() : void
|
||||
{
|
||||
$element = [
|
||||
'type' => 'input',
|
||||
'subtype' => 'checkbox',
|
||||
'attributes' => [
|
||||
'id' => 'testId',
|
||||
'name' => 'testName',
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
'default' => [
|
||||
'value' => 'testValue',
|
||||
'checked' => false,
|
||||
'content' => 'testContent'
|
||||
],
|
||||
];
|
||||
|
||||
self::assertEquals(
|
||||
'<input id="testId" name="testName" type="checkbox" value="testValue"><label for="testId">langContent</label>',
|
||||
FormElementGenerator::generate($element, null, ['testContent' => 'langContent'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A radio element can be generated
|
||||
* @covers phpOMS\Model\Html\FormElementGenerator
|
||||
* @group framework
|
||||
*/
|
||||
public function testGenerateRadioInput() : void
|
||||
{
|
||||
$element = [
|
||||
'type' => 'input',
|
||||
'subtype' => 'radio',
|
||||
'attributes' => [
|
||||
'id' => 'testId',
|
||||
'name' => 'testName',
|
||||
'type' => 'radio',
|
||||
],
|
||||
'default' => [
|
||||
'value' => 'testValue',
|
||||
'checked' => true,
|
||||
'content' => 'testContent'
|
||||
],
|
||||
];
|
||||
|
||||
self::assertEquals(
|
||||
'<input id="testId" name="testName" type="radio" value="testValue" checked><label for="testId">testContent</label>',
|
||||
FormElementGenerator::generate($element)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A radio element can be generated with a localized label element
|
||||
* @covers phpOMS\Model\Html\FormElementGenerator
|
||||
* @group framework
|
||||
*/
|
||||
public function testGenerateRadioWithLanguageInput() : void
|
||||
{
|
||||
$element = [
|
||||
'type' => 'input',
|
||||
'subtype' => 'radio',
|
||||
'attributes' => [
|
||||
'id' => 'testId',
|
||||
'name' => 'testName',
|
||||
'type' => 'radio',
|
||||
],
|
||||
'default' => [
|
||||
'value' => 'testValue',
|
||||
'checked' => false,
|
||||
'content' => 'testContent'
|
||||
],
|
||||
];
|
||||
|
||||
self::assertEquals(
|
||||
'<input id="testId" name="testName" type="radio" value="testValue"><label for="testId">langContent</label>',
|
||||
FormElementGenerator::generate($element, null, ['testContent' => 'langContent'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A label element can be generated
|
||||
* @covers phpOMS\Model\Html\FormElementGenerator
|
||||
* @group framework
|
||||
*/
|
||||
public function testGenerateLabel() : void
|
||||
{
|
||||
$element = [
|
||||
'type' => 'label',
|
||||
'attributes' => [
|
||||
'for' => 'testId',
|
||||
],
|
||||
'default' => [
|
||||
'value' => 'testValue',
|
||||
],
|
||||
];
|
||||
|
||||
self::assertEquals(
|
||||
'<label for="testId">testValue</label>',
|
||||
FormElementGenerator::generate($element)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A localized label element can be generated
|
||||
* @covers phpOMS\Model\Html\FormElementGenerator
|
||||
* @group framework
|
||||
*/
|
||||
public function testGenerateWithLanguageLabel() : void
|
||||
{
|
||||
$element = [
|
||||
'type' => 'label',
|
||||
'attributes' => [
|
||||
'for' => 'testId',
|
||||
],
|
||||
'default' => [
|
||||
'value' => 'testValue',
|
||||
],
|
||||
];
|
||||
|
||||
self::assertEquals(
|
||||
'<label for="testId">langValue</label>',
|
||||
FormElementGenerator::generate($element, null, ['testValue' => 'langValue'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A textarea element can be generated
|
||||
* @covers phpOMS\Model\Html\FormElementGenerator
|
||||
* @group framework
|
||||
*/
|
||||
public function testGenerateTextarea() : void
|
||||
{
|
||||
$element = [
|
||||
'type' => 'textarea',
|
||||
'attributes' => [
|
||||
'id' => 'testId',
|
||||
'name' => 'testName',
|
||||
],
|
||||
'default' => [
|
||||
'value' => 'testValue',
|
||||
],
|
||||
];
|
||||
|
||||
self::assertEquals(
|
||||
'<textarea id="testId" name="testName">testValue</textarea>',
|
||||
FormElementGenerator::generate($element)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A textarea element can be generated with a custom value
|
||||
* @covers phpOMS\Model\Html\FormElementGenerator
|
||||
* @group framework
|
||||
*/
|
||||
public function testGenerateWithValueTextarea() : void
|
||||
{
|
||||
$element = [
|
||||
'type' => 'textarea',
|
||||
'attributes' => [
|
||||
'id' => 'testId',
|
||||
'name' => 'testName',
|
||||
],
|
||||
'default' => [
|
||||
'value' => 'testValue',
|
||||
],
|
||||
];
|
||||
|
||||
self::assertEquals(
|
||||
'<textarea id="testId" name="testName">manualValue</textarea>',
|
||||
FormElementGenerator::generate($element, 'manualValue')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A select element can be generated
|
||||
* @covers phpOMS\Model\Html\FormElementGenerator
|
||||
* @group framework
|
||||
*/
|
||||
public function testGenerateSelect() : void
|
||||
{
|
||||
$element = [
|
||||
'type' => 'select',
|
||||
'attributes' => [
|
||||
'id' => 'testId',
|
||||
'name' => 'testName',
|
||||
],
|
||||
'options' => [
|
||||
'option1' => 'value1',
|
||||
'option2' => 'value2',
|
||||
'option3' => 'value3',
|
||||
],
|
||||
'default' => [
|
||||
'value' => 'option2',
|
||||
],
|
||||
];
|
||||
|
||||
self::assertEquals(
|
||||
'<select id="testId" name="testName"><option value="option1">value1</option><option value="option2" selected>value2</option><option value="option3">value3</option></select>',
|
||||
FormElementGenerator::generate($element)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A localized select element can be generated
|
||||
* @covers phpOMS\Model\Html\FormElementGenerator
|
||||
* @group framework
|
||||
*/
|
||||
public function testGenerateWithLanguageSelect() : void
|
||||
{
|
||||
$element = [
|
||||
'type' => 'select',
|
||||
'attributes' => [
|
||||
'id' => 'testId',
|
||||
'name' => 'testName',
|
||||
],
|
||||
'options' => [
|
||||
'option1' => 'value1',
|
||||
'option2' => 'value2',
|
||||
'option3' => 'value3',
|
||||
],
|
||||
'default' => [
|
||||
'value' => 'option2',
|
||||
],
|
||||
];
|
||||
|
||||
self::assertEquals(
|
||||
'<select id="testId" name="testName"><option value="option1">value1</option><option value="option2" selected>lang2</option><option value="option3">value3</option></select>',
|
||||
FormElementGenerator::generate($element, null, ['value2' => 'lang2'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing or invalid element type generates a INVALID output
|
||||
* @covers phpOMS\Model\Html\FormElementGenerator
|
||||
* @group framework
|
||||
*/
|
||||
public function testInvalidElementType() : void
|
||||
{
|
||||
self::assertEquals(
|
||||
'INVALID',
|
||||
FormElementGenerator::generate([])
|
||||
);
|
||||
|
||||
self::assertEquals(
|
||||
'INVALID',
|
||||
FormElementGenerator::generate(['type' => 'somethingInvalid'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -16,10 +16,16 @@ namespace phpOMS\tests\Module;
|
|||
|
||||
require_once __DIR__ . '/../Autoloader.php';
|
||||
|
||||
use phpOMS\ApplicationAbstract;
|
||||
use phpOMS\Event\EventManager;
|
||||
use phpOMS\Message\Http\HttpRequest;
|
||||
use phpOMS\Message\Http\HttpResponse;
|
||||
use phpOMS\Module\ModuleAbstract;
|
||||
use phpOMS\Uri\HttpUri;
|
||||
use phpOMS\tests\DataStorage\Database\TestModel\BaseModel;
|
||||
use phpOMS\tests\DataStorage\Database\TestModel\BaseModelMapper;
|
||||
use phpOMS\tests\DataStorage\Database\TestModel\ManyToManyRelModelMapper;
|
||||
use phpOMS\tests\DataStorage\Database\TestModel\ManyToManyRelModel;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Module\ModuleAbstractTest: Abstract module
|
||||
|
|
@ -32,12 +38,18 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->module = new class(null) extends ModuleAbstract {
|
||||
$this->module = new class() extends ModuleAbstract {
|
||||
const MODULE_VERSION = '1.2.3';
|
||||
const MODULE_NAME = 'Test';
|
||||
const MODULE_ID = 2;
|
||||
protected static array $dependencies = [1, 2];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->app = new class() extends ApplicationAbstract {};
|
||||
$this->app->eventManager = new EventManager();
|
||||
}
|
||||
|
||||
public function fillJson(HttpRequest $request, HttpResponse $response, string $status, string $title, string $message, array $data) : void
|
||||
{
|
||||
$this->fillJsonResponse($request, $response, $status, $title, $message, $data);
|
||||
|
|
@ -47,6 +59,51 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
$this->fillJsonRawResponse($request, $response, $data);
|
||||
}
|
||||
|
||||
public function create() : void
|
||||
{
|
||||
$model = new BaseModel();
|
||||
$model->hasManyRelations = [];
|
||||
$this->createModel(1, $model, BaseModelMapper::class, '');
|
||||
}
|
||||
|
||||
public function createRelationModel() : void
|
||||
{
|
||||
$model = new ManyToManyRelModel();
|
||||
ManyToManyRelModelMapper::create($model);
|
||||
}
|
||||
|
||||
public function createRelationDB() : void
|
||||
{
|
||||
$model1 = BaseModelMapper::get(1);
|
||||
$model2 = ManyToManyRelModelMapper::get(1);
|
||||
|
||||
$this->createModelRelation(1, $model1->id, $model2->id, BaseModelMapper::class, 'hasManyRelations', '');
|
||||
}
|
||||
|
||||
public function creates() : void
|
||||
{
|
||||
$model1 = new BaseModel();
|
||||
$model2 = new BaseModel();
|
||||
$this->createModel(1, [$model1, $model2], BaseModelMapper::class, '');
|
||||
}
|
||||
|
||||
public function update() : void
|
||||
{
|
||||
$old = new BaseModel();
|
||||
BaseModelMapper::create($old);
|
||||
|
||||
$new = clone $old;
|
||||
$new->string = 'Updated';
|
||||
|
||||
$this->updateModel(1, $old, $new, BaseModelMapper::class, '');
|
||||
}
|
||||
|
||||
public function delete() : void
|
||||
{
|
||||
$model = BaseModelMapper::get(1);
|
||||
$this->deleteModel(1, $model, BaseModelMapper::class, '');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -152,4 +209,161 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
$response->get('')
|
||||
);
|
||||
}
|
||||
|
||||
private function dbSetup() : void
|
||||
{
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_base` (
|
||||
`test_base_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_base_string` varchar(254) NOT NULL,
|
||||
`test_base_int` int(11) NOT NULL,
|
||||
`test_base_bool` tinyint(1) DEFAULT NULL,
|
||||
`test_base_null` int(11) DEFAULT NULL,
|
||||
`test_base_float` decimal(5, 4) DEFAULT NULL,
|
||||
`test_base_belongs_to_one` int(11) DEFAULT NULL,
|
||||
`test_base_owns_one_self` int(11) DEFAULT NULL,
|
||||
`test_base_json` varchar(254) DEFAULT NULL,
|
||||
`test_base_json_serializable` varchar(254) DEFAULT NULL,
|
||||
`test_base_datetime` datetime DEFAULT NULL,
|
||||
`test_base_datetime_null` datetime DEFAULT NULL, /* There was a bug where it returned the current date because new \DateTime(null) === current date which is wrong, we want null as value! */
|
||||
PRIMARY KEY (`test_base_id`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
|
||||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_belongs_to_one` (
|
||||
`test_belongs_to_one_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_belongs_to_one_string` varchar(254) NOT NULL,
|
||||
PRIMARY KEY (`test_belongs_to_one_id`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
|
||||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_owns_one` (
|
||||
`test_owns_one_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_owns_one_string` varchar(254) NOT NULL,
|
||||
PRIMARY KEY (`test_owns_one_id`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
|
||||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_has_many_direct` (
|
||||
`test_has_many_direct_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_has_many_direct_string` varchar(254) NOT NULL,
|
||||
`test_has_many_direct_to` int(11) NOT NULL,
|
||||
PRIMARY KEY (`test_has_many_direct_id`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
|
||||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_has_many_rel` (
|
||||
`test_has_many_rel_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_has_many_rel_string` varchar(254) NOT NULL,
|
||||
PRIMARY KEY (`test_has_many_rel_id`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
|
||||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_has_many_rel_relations` (
|
||||
`test_has_many_rel_relations_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_has_many_rel_relations_src` int(11) NOT NULL,
|
||||
`test_has_many_rel_relations_dest` int(11) NOT NULL,
|
||||
PRIMARY KEY (`test_has_many_rel_relations_id`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
|
||||
)->execute();
|
||||
}
|
||||
|
||||
private function dbTeardown() : void
|
||||
{
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_base')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_belongs_to_one')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_owns_one')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_has_many_direct')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_has_many_rel')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_has_many_rel_relations')->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A model can be created
|
||||
* @covers phpOMS\Module\ModuleAbstract<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testModelCreate() : void
|
||||
{
|
||||
$this->dbSetup();
|
||||
|
||||
$this->module->create();
|
||||
self::assertCount(1, BaseModelMapper::getAll());
|
||||
|
||||
$this->dbTeardown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Multiple models can be generated
|
||||
* @covers phpOMS\Module\ModuleAbstract<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testModelsCreate() : void
|
||||
{
|
||||
$this->dbSetup();
|
||||
|
||||
$this->module->create();
|
||||
$this->module->create();
|
||||
self::assertCount(2, BaseModelMapper::getAll());
|
||||
|
||||
$this->dbTeardown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A model can be updated
|
||||
* @covers phpOMS\Module\ModuleAbstract<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testModelUpdate() : void
|
||||
{
|
||||
$this->dbSetup();
|
||||
|
||||
$this->module->update();
|
||||
$updated = BaseModelMapper::get(1);
|
||||
|
||||
self::assertEquals('Updated', $updated->string);
|
||||
|
||||
$this->dbTeardown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A model can be deleted
|
||||
* @covers phpOMS\Module\ModuleAbstract<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testModelDelete() : void
|
||||
{
|
||||
$this->dbSetup();
|
||||
|
||||
$this->module->create();
|
||||
self::assertCount(1, BaseModelMapper::getAll());
|
||||
$this->module->delete();
|
||||
self::assertCount(0, BaseModelMapper::getAll());
|
||||
|
||||
$this->dbTeardown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A model relation can be created
|
||||
* @covers phpOMS\Module\ModuleAbstract<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testModelRelation() : void
|
||||
{
|
||||
$this->dbSetup();
|
||||
|
||||
$this->module->create();
|
||||
$this->module->createRelationModel();
|
||||
$this->module->createRelationDB();
|
||||
|
||||
$model = BaseModelMapper::get(1);
|
||||
self::assertCount(1, $model->hasManyRelations);
|
||||
|
||||
$this->dbTeardown();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
45
tests/Stdlib/Base/HeapItem.php
Normal file
45
tests/Stdlib/Base/HeapItem.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\tests\Stdlib\Base;
|
||||
|
||||
final class HeapItem
|
||||
{
|
||||
private int $value = 0;
|
||||
|
||||
public static function compare(self $a, self $b) : int
|
||||
{
|
||||
return $a <=> $b;
|
||||
}
|
||||
|
||||
public function __construct(int $value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function setValue(int $value) : void
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function getValue() : int
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function isEqual(self $item) : bool
|
||||
{
|
||||
return $this->value === $item->getValue();
|
||||
}
|
||||
}
|
||||
|
|
@ -56,6 +56,25 @@ class HeapTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals(5, $heap->size());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A element can be added to a heap at the correct position
|
||||
* @covers phpOMS\Stdlib\Base\Heap
|
||||
* @group framework
|
||||
*/
|
||||
public function testInsort() : void
|
||||
{
|
||||
$heap = new Heap();
|
||||
$heap->heapify([3, 6, 1, 5, 4]);
|
||||
$heap->insort(2);
|
||||
|
||||
self::assertEquals(1, $heap->pop());
|
||||
self::assertEquals(2, $heap->pop());
|
||||
self::assertEquals(3, $heap->pop());
|
||||
self::assertEquals(4, $heap->pop());
|
||||
self::assertEquals(5, $heap->pop());
|
||||
self::assertEquals(6, $heap->pop());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Heap elements get returned in the correct order
|
||||
* @covers phpOMS\Stdlib\Base\Heap
|
||||
|
|
@ -173,6 +192,56 @@ class HeapTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertFalse($heap->contains(6));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The heap can be checked if it contains certain custom elements
|
||||
* @covers phpOMS\Stdlib\Base\Heap
|
||||
* @group framework
|
||||
*/
|
||||
public function testContainsItem(): void
|
||||
{
|
||||
$heap = new Heap();
|
||||
for ($i = 1; $i < 6; ++$i) {
|
||||
$heap->push(new HeapItem($i));
|
||||
}
|
||||
|
||||
self::assertTrue($heap->contains(new HeapItem(1)));
|
||||
self::assertTrue($heap->contains(new HeapItem(2)));
|
||||
self::assertTrue($heap->contains(new HeapItem(3)));
|
||||
self::assertTrue($heap->contains(new HeapItem(4)));
|
||||
self::assertTrue($heap->contains(new HeapItem(5)));
|
||||
self::assertFalse($heap->contains(new HeapItem(0)));
|
||||
self::assertFalse($heap->contains(new HeapItem(6)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A heap item can be updated if it exists while maintaining the correct order
|
||||
* @covers phpOMS\Stdlib\Base\Heap
|
||||
* @group framework
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
$heap = new Heap();
|
||||
$items = [];
|
||||
|
||||
for ($i = 1; $i < 7; ++$i) {
|
||||
$items[$i] = new HeapItem($i);
|
||||
}
|
||||
|
||||
$heap->heapify([$items[3], $items[2], $items[6], $items[1], $items[5], $items[4]]);
|
||||
|
||||
$items[4]->setValue(8);
|
||||
self::assertTrue($heap->update($items[4]));
|
||||
|
||||
self::assertEquals(1, $heap->pop()->getValue());
|
||||
self::assertEquals(2, $heap->pop()->getValue());
|
||||
self::assertEquals(3, $heap->pop()->getValue());
|
||||
self::assertEquals(5, $heap->pop()->getValue());
|
||||
self::assertEquals(6, $heap->pop()->getValue());
|
||||
self::assertEquals(8, $heap->pop()->getValue());
|
||||
|
||||
self::assertFalse($heap->update(new HeapItem(999)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The first heap element can be returned without removing it
|
||||
* @covers phpOMS\Stdlib\Base\Heap
|
||||
|
|
|
|||
|
|
@ -71,6 +71,23 @@ class ArgumentTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
self::assertEquals('modules/admin/test/path', $obj->getPath());
|
||||
self::assertEquals('modules', $obj->getPathElement(0));
|
||||
self::assertEquals(
|
||||
['modules', 'admin', 'test', 'path'],
|
||||
$obj->getPathElements()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The path offset can be set and returned
|
||||
* @covers phpOMS\Uri\Argument
|
||||
* @group framework
|
||||
*/
|
||||
public function testPathOffsetInputOutput() : void
|
||||
{
|
||||
$obj = new Argument();
|
||||
$obj->setPathOffset(2);
|
||||
|
||||
self::assertEquals(2, $obj->getPathOffset());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -168,6 +168,26 @@ class ArrayUtilsTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertFalse(ArrayUtils::anyInArray($numArr, [10, 22]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An array can be turned into a csv string
|
||||
* @covers phpOMS\Utils\ArrayUtils
|
||||
* @group framework
|
||||
*/
|
||||
public function testArrayToCsv() : void
|
||||
{
|
||||
$csvArr = [
|
||||
['Title1', 'Title2', 'Title3', 'Title4'],
|
||||
[1, 1.2, true, 'test'],
|
||||
[2, 3.2, false, 'test2'],
|
||||
];
|
||||
|
||||
self::assertEquals(
|
||||
"Title1;Title2;Title3;Title4\n"
|
||||
. "1;1.2;1;test\n"
|
||||
. "2;3.2;;test2\n",
|
||||
ArrayUtils::arrayToCsv($csvArr));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An array can be checked if it has an element and returns its index
|
||||
* @covers phpOMS\Utils\ArrayUtils
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class DateTimeTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
/**
|
||||
* @testdox A random date time can be generated
|
||||
* @covers phpOMS\Utils\RnG\ArrayRandomize
|
||||
* @covers phpOMS\Utils\RnG\DateTime
|
||||
* @group framework
|
||||
*/
|
||||
public function testRnG() : void
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ use phpOMS\Message\Http\HttpResponse;
|
|||
use phpOMS\Uri\HttpUri;
|
||||
use phpOMS\Views\View;
|
||||
use phpOMS\Views\ViewAbstract;
|
||||
use phpOMS\Localization\Money;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Views\ViewTest: View for response rendering
|
||||
|
|
@ -59,7 +60,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, new HttpRequest(new HttpUri('')), new HttpResponse(new Localization()));
|
||||
$view = new View($this->app->l11nManager);
|
||||
|
||||
self::assertEmpty($view->getTemplate());
|
||||
self::assertEmpty($view->getViews());
|
||||
|
|
@ -78,7 +79,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testGetText() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, $request = new HttpRequest(new HttpUri('')), $response = new HttpResponse());
|
||||
$view = new View($this->app->l11nManager);
|
||||
$view->setTemplate('/Modules/Admin/Theme/Backend/accounts-list');
|
||||
|
||||
$expected = [
|
||||
|
|
@ -102,7 +103,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testGetHtml() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, $request = new HttpRequest(new HttpUri('')), $response = new HttpResponse());
|
||||
$view = new View($this->app->l11nManager);
|
||||
$view->setTemplate('/Modules/Admin/Theme/Backend/accounts-list');
|
||||
|
||||
$expected = [
|
||||
|
|
@ -119,6 +120,61 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals('<a href="test">Test</a>', $view->getHtml('Test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The numeric value can be printed based on the localization
|
||||
* @covers phpOMS\Views\View<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testGetNumeric() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, null, new HttpResponse(Localization::fromLanguage('en')));
|
||||
self::assertEquals('1.23', $view->getNumeric(1.2345, 'medium'));
|
||||
self::assertEquals('1.235', $view->getNumeric(1.2345, 'long'));
|
||||
self::assertEquals('1,234.235', $view->getNumeric(1234.2345, 'long'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The percentage value can be printed based on the localization
|
||||
* @covers phpOMS\Views\View<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testGetPercentage() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, null, new HttpResponse(Localization::fromLanguage('en')));
|
||||
self::assertEquals('1.23%', $view->getPercentage(1.2345, 'medium'));
|
||||
self::assertEquals('1.235%', $view->getPercentage(1.2345, 'long'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The currency value can be printed based on the localization
|
||||
* @covers phpOMS\Views\View<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testGetCurrency() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, null, new HttpResponse(Localization::fromLanguage('en')));
|
||||
self::assertEquals('USD 1.23', $view->getCurrency(1.2345, 'medium'));
|
||||
self::assertEquals('USD 1.235', $view->getCurrency(1.2345, 'long'));
|
||||
|
||||
$this->app->l11nManager->loadLanguage('en', '0', ['0' => ['CurrencyK' => 'K']]);
|
||||
self::assertEquals('K$ 12.345', $view->getCurrency(12345.0, 'long', '$', 1000));
|
||||
self::assertEquals('KUSD 12.345', $view->getCurrency(12345.0, 'long', null, 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The datetime value can be printed based on the localization
|
||||
* @covers phpOMS\Views\View<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testGetDateTime() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, null, new HttpResponse(Localization::fromLanguage('en')));
|
||||
|
||||
$date = new \DateTime('2020-01-01 13:45:22');
|
||||
self::assertEquals('2020.01.01', $view->getDateTime($date, 'medium'));
|
||||
self::assertEquals('2020.01.01 01:45', $view->getDateTime($date, 'long'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox View data can be set and returned
|
||||
* @covers phpOMS\Views\View<extended>
|
||||
|
|
@ -126,7 +182,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testDataInputOutput() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, $request = new HttpRequest(new HttpUri('')), $response = new HttpResponse());
|
||||
$view = new View($this->app->l11nManager);
|
||||
|
||||
$view->setData('key', 'value');
|
||||
self::assertEquals('value', $view->getData('key'));
|
||||
|
|
@ -139,7 +195,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testDataAdd() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, $request = new HttpRequest(new HttpUri('')), $response = new HttpResponse());
|
||||
$view = new View($this->app->l11nManager);
|
||||
|
||||
self::assertTrue($view->addData('key2', 'valu2'));
|
||||
self::assertEquals('valu2', $view->getData('key2'));
|
||||
|
|
@ -152,7 +208,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testInvalidDataOverwrite() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, $request = new HttpRequest(new HttpUri('')), $response = new HttpResponse());
|
||||
$view = new View($this->app->l11nManager);
|
||||
|
||||
$view->addData('key2', 'valu2');
|
||||
self::assertFalse($view->addData('key2', 'valu3'));
|
||||
|
|
@ -166,7 +222,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testRemove() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, $request = new HttpRequest(new HttpUri('')), $response = new HttpResponse());
|
||||
$view = new View($this->app->l11nManager);
|
||||
|
||||
$view->addData('key2', 'valu2');
|
||||
self::assertTrue($view->removeData('key2'));
|
||||
|
|
@ -179,7 +235,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testInvalidDataRemove() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, $request = new HttpRequest(new HttpUri('')), $response = new HttpResponse());
|
||||
$view = new View($this->app->l11nManager);
|
||||
|
||||
self::assertFalse($view->removeData('key3'));
|
||||
}
|
||||
|
|
@ -204,7 +260,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testGetResponse() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, $request = new HttpRequest(new HttpUri('')), $response = new HttpResponse());
|
||||
$view = new View($this->app->l11nManager, new HttpRequest(new HttpUri('')), $response = new HttpResponse());
|
||||
|
||||
self::assertEquals($response, $view->getResponse());
|
||||
}
|
||||
|
|
@ -229,9 +285,9 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testViewInputOutput() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, $request = new HttpRequest(new HttpUri('')), $response = new HttpResponse());
|
||||
$view = new View($this->app->l11nManager);
|
||||
|
||||
$tView = new View($this->app->l11nManager, $request, $response);
|
||||
$tView = new View($this->app->l11nManager);
|
||||
self::assertTrue($view->addView('test', $tView));
|
||||
self::assertEquals($tView, $view->getView('test'));
|
||||
self::assertCount(1, $view->getViews());
|
||||
|
|
@ -244,7 +300,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testInvalidViewGet() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, $request = new HttpRequest(new HttpUri('')), $response = new HttpResponse());
|
||||
$view = new View($this->app->l11nManager);
|
||||
|
||||
self::assertFalse($view->getView('test'));
|
||||
}
|
||||
|
|
@ -256,9 +312,9 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testViewRemove() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, $request = new HttpRequest(new HttpUri('')), $response = new HttpResponse());
|
||||
$view = new View($this->app->l11nManager);
|
||||
|
||||
$tView = new View($this->app->l11nManager, $request, $response);
|
||||
$tView = new View($this->app->l11nManager);
|
||||
$view->addView('test', $tView);
|
||||
self::assertTrue($view->removeView('test'));
|
||||
}
|
||||
|
|
@ -270,7 +326,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testInvalidViewRemove() : void
|
||||
{
|
||||
$view = new View($this->app->l11nManager, $request = new HttpRequest(new HttpUri('')), $response = new HttpResponse());
|
||||
$view = new View($this->app->l11nManager);
|
||||
|
||||
self::assertFalse($view->removeView('test'));
|
||||
}
|
||||
|
|
@ -383,4 +439,44 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$view->serialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Getting the text without defining a module throws a InvalidModuleException exception
|
||||
* @covers phpOMS\Views\View<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testTextWithoutModuleAndTemplate() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Module\Exception\InvalidModuleException::class);
|
||||
|
||||
$view = new View($this->app->l11nManager);
|
||||
$view->getText('InvalidText');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Getting the text with an invalid template path throws a InvalidModuleException exception
|
||||
* @covers phpOMS\Views\View<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testTextFromInvalidTemplatePath() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Module\Exception\InvalidModuleException::class);
|
||||
|
||||
$view = new View($this->app->l11nManager);
|
||||
$view->setTemplate('/Modules/ABC');
|
||||
$view->getText('InvalidText');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Getting the text without defining a template throws a InvalidThemeException exception
|
||||
* @covers phpOMS\Views\View<extended>
|
||||
* @group framework
|
||||
*/
|
||||
public function testTextInvalidTemplate() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Module\Exception\InvalidThemeException::class);
|
||||
|
||||
$view = new View($this->app->l11nManager);
|
||||
$view->getText('InvalidText', 'Admin');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user