mirror of
https://github.com/Karaka-Management/oms-Exchange.git
synced 2026-02-16 01:38:40 +00:00
test fixes
This commit is contained in:
parent
3267ae6b24
commit
56010f1f3d
|
|
@ -70,6 +70,8 @@ use phpOMS\Utils\IO\Zip\Zip;
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
final class Importer extends ImporterAbstract
|
final class Importer extends ImporterAbstract
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ namespace Modules\Exchange\Interfaces\GSD\Model;
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
class GSDAddress
|
class GSDAddress
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ namespace Modules\Exchange\Interfaces\GSD\Model;
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
class GSDArticle
|
class GSDArticle
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ namespace Modules\Exchange\Interfaces\GSD\Model;
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
class GSDCostCenter implements \JsonSerializable
|
class GSDCostCenter implements \JsonSerializable
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ namespace Modules\Exchange\Interfaces\GSD\Model;
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
class GSDCostObject implements \JsonSerializable
|
class GSDCostObject implements \JsonSerializable
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ namespace Modules\Exchange\Interfaces\GSD\Model;
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
class GSDCustomer
|
class GSDCustomer
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ namespace Modules\Exchange\Interfaces\GSD\Model;
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
class GSDSupplier
|
class GSDSupplier
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ use phpOMS\Message\RequestAbstract;
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
final class Importer extends ImporterAbstract
|
final class Importer extends ImporterAbstract
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -55,13 +55,13 @@ final class Exporter extends ExporterAbstract
|
||||||
* @param \DateTime $start Start time (inclusive)
|
* @param \DateTime $start Start time (inclusive)
|
||||||
* @param \DateTime $end End time (inclusive)
|
* @param \DateTime $end End time (inclusive)
|
||||||
*
|
*
|
||||||
* @return void
|
* @return array
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function export(\DateTime $start, \DateTime $end) : void
|
public function export(\DateTime $start, \DateTime $end) : array
|
||||||
{
|
{
|
||||||
$this->exportLanguage();
|
return $this->exportLanguage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@ class ExchangeLog implements \JsonSerializable, ArrayableInterface
|
||||||
/**
|
/**
|
||||||
* Fields.
|
* Fields.
|
||||||
*
|
*
|
||||||
|
* What where the values used in the exchange form to reproduce this output (exchange specific)?
|
||||||
|
*
|
||||||
* @var array
|
* @var array
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
@ -59,6 +61,12 @@ class ExchangeLog implements \JsonSerializable, ArrayableInterface
|
||||||
*/
|
*/
|
||||||
private int $type = ExchangeType::IMPORT;
|
private int $type = ExchangeType::IMPORT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exchange specific subtype.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public string $subtype = '';
|
public string $subtype = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -133,30 +141,6 @@ class ExchangeLog implements \JsonSerializable, ArrayableInterface
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getMessage() : string
|
|
||||||
{
|
|
||||||
return $this->message;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set message
|
|
||||||
*
|
|
||||||
* @param string $message Log message
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setMessage(string $message) : void
|
|
||||||
{
|
|
||||||
$this->message = $message;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get fields.
|
* Get fields.
|
||||||
*
|
*
|
||||||
|
|
@ -193,7 +177,7 @@ class ExchangeLog implements \JsonSerializable, ArrayableInterface
|
||||||
'message' => $this->message,
|
'message' => $this->message,
|
||||||
'type' => $this->type,
|
'type' => $this->type,
|
||||||
'fields' => $this->fields,
|
'fields' => $this->fields,
|
||||||
'datetime' => $this->createdAt,
|
'createdAt' => $this->createdAt,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ class InterfaceManager
|
||||||
*/
|
*/
|
||||||
public function getInterfacePath() : string
|
public function getInterfacePath() : string
|
||||||
{
|
{
|
||||||
return $this->info['path'];
|
return $this->info['path'] ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -110,7 +110,7 @@ class InterfaceManager
|
||||||
*/
|
*/
|
||||||
public function getName() : string
|
public function getName() : string
|
||||||
{
|
{
|
||||||
return $this->info['name'];
|
return $this->info['name'] ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -122,7 +122,7 @@ class InterfaceManager
|
||||||
*/
|
*/
|
||||||
public function hasImport() : bool
|
public function hasImport() : bool
|
||||||
{
|
{
|
||||||
return $this->info['import'];
|
return $this->info['import'] ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -134,7 +134,7 @@ class InterfaceManager
|
||||||
*/
|
*/
|
||||||
public function hasExport() : bool
|
public function hasExport() : bool
|
||||||
{
|
{
|
||||||
return $this->info['export'];
|
return $this->info['export'] ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -187,13 +187,13 @@ class InterfaceManager
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function set(string $path, $data, string $delim = '/') : void
|
public function set(string $path, mixed $data, string $delim = '/') : void
|
||||||
{
|
{
|
||||||
if (!\is_scalar($data) && !\is_array($data) && !($data instanceof \JsonSerializable)) {
|
if (!\is_scalar($data) && !\is_array($data) && !($data instanceof \JsonSerializable)) {
|
||||||
throw new \InvalidArgumentException('Type of $data "' . \gettype($data) . '" is not supported.');
|
throw new \InvalidArgumentException('Type of $data "' . \gettype($data) . '" is not supported.');
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayUtils::setArray($path, $this->info, $data, $delim, true);
|
$this->info = ArrayUtils::setArray($path, $this->info, $data, $delim, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
55
tests/Interfaces/OMS/ExporterTest.php
Normal file
55
tests/Interfaces/OMS/ExporterTest.php
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 8.0
|
||||||
|
*
|
||||||
|
* @package tests
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\Exchange\tests\Interfacs\OMS;
|
||||||
|
|
||||||
|
use Modules\Exchange\Interfaces\OMS\Exporter;
|
||||||
|
use phpOMS\Localization\L11nManager;
|
||||||
|
use phpOMS\DataStorage\Database\Connection\NullConnection;
|
||||||
|
use phpOMS\Uri\HttpUri;
|
||||||
|
use phpOMS\Message\Http\HttpRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class ExporterTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
private Exporter $exporter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() : void
|
||||||
|
{
|
||||||
|
$this->exporter = new Exporter(new NullConnection(), new L11nManager('Api'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Exchange\Interfaces\OMS\Exporter
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testLanguageExport() : void
|
||||||
|
{
|
||||||
|
$request = new HttpRequest(new HttpUri(''));
|
||||||
|
|
||||||
|
$request->header->account = 1;
|
||||||
|
$request->setData('id', '123');
|
||||||
|
$request->setData('type', 'language');
|
||||||
|
|
||||||
|
$export = $this->exporter->exportFromRequest($request);
|
||||||
|
self::assertCount(4, $export);
|
||||||
|
self::assertGreaterThan(100, \strlen($export['content']));
|
||||||
|
self::assertEquals($export['content'], $this->exporter->export(new \DateTime('now'), new \DateTime('now'))['content']);
|
||||||
|
}
|
||||||
|
}
|
||||||
70
tests/Interfaces/OMS/ImporterTest.php
Normal file
70
tests/Interfaces/OMS/ImporterTest.php
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 8.0
|
||||||
|
*
|
||||||
|
* @package tests
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\Exchange\tests\Interfacs\OMS;
|
||||||
|
|
||||||
|
use Modules\Exchange\Interfaces\OMS\Importer;
|
||||||
|
use phpOMS\Localization\L11nManager;
|
||||||
|
use phpOMS\DataStorage\Database\Connection\NullConnection;
|
||||||
|
use phpOMS\Uri\HttpUri;
|
||||||
|
use phpOMS\Message\Http\HttpRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class ImporterTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
private Importer $importer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() : void
|
||||||
|
{
|
||||||
|
$this->importer = new Importer(new NullConnection(), new NullConnection(), new L11nManager('Api'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Exchange\Interfaces\OMS\Importer
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testLanguageImport() : void
|
||||||
|
{
|
||||||
|
$request = new HttpRequest(new HttpUri(''));
|
||||||
|
|
||||||
|
$request->header->account = 1;
|
||||||
|
$request->setData('id', '123');
|
||||||
|
$request->setData('type', 'language');
|
||||||
|
|
||||||
|
if (!\is_file()) {
|
||||||
|
\copy(__DIR__ . '/test.csv', __DIR__ . '/test_tmp.csv');
|
||||||
|
}
|
||||||
|
|
||||||
|
TestUtils::setMember($request, 'files', [
|
||||||
|
'file0' => [
|
||||||
|
'name' => 'test.csv',
|
||||||
|
'type' => 'csv',
|
||||||
|
'tmp_name' => __DIR__ . '/test_tmp.csv',
|
||||||
|
'error' => \UPLOAD_ERR_OK,
|
||||||
|
'size' => \filesize(__DIR__ . '/test_tmp.csv'),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$export = $this->importer->importFromRequest($request);
|
||||||
|
self::assertEquals(
|
||||||
|
\date('Y-m-d'),
|
||||||
|
\date('Y-m-d', \filemtime(__DIR__ . '/../../../../TestModule/Theme/Backend/Lang/en.lang.php'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
3
tests/Interfaces/OMS/test.csv
Normal file
3
tests/Interfaces/OMS/test.csv
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
"Module";"Theme";"File";"ID";"en";"ar";"cs";"da";"de";"el";"es";"fi";"fr";"hu";"it";"ja";"ko";"no";"pl";"pt";"ru";"sv";"th";"tr";"uk";"zh"
|
||||||
|
"TestModule";"Backend";"";"Test1";"Test1";"TEST1";"test1";"test1";"";"test1";"test1";"test1";"test1";"test1";"test1";"Test1を";"TEST1";"test1";"test1";"Test1";"Test1";"test1";"test1";"Test1";"Test1";"测试1"
|
||||||
|
"TestModule";"Backend";"";"Test2";"Test2";"TEST2";"test2";"test2";"";"test2";"test2";"test2";"test2";"test2";"test2";"Test2を";"TEST2";"test2";"test2";"test2";"Test2";"test2";"Test2";"Test2";"Test2";"TEST2"
|
||||||
|
95
tests/Models/ExchangeLogTest.php
Normal file
95
tests/Models/ExchangeLogTest.php
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 8.0
|
||||||
|
*
|
||||||
|
* @package tests
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\Exchange\tests\Models;
|
||||||
|
|
||||||
|
use Modules\Exchange\Models\ExchangeLog;
|
||||||
|
use Modules\Exchange\Models\ExchangeType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class ExchangeLogTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
private ExchangeLog $log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() : void
|
||||||
|
{
|
||||||
|
$this->log = new ExchangeLog();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Exchange\Models\ExchangeLog
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testDefault() : void
|
||||||
|
{
|
||||||
|
self::assertEquals(0, $this->log->getId());
|
||||||
|
self::assertEquals('', $this->log->message);
|
||||||
|
self::assertEquals('', $this->log->subtype);
|
||||||
|
self::assertEquals(0, $this->log->exchange);
|
||||||
|
self::assertEquals(0, $this->log->createdBy);
|
||||||
|
self::assertEquals(ExchangeType::IMPORT, $this->log->getType());
|
||||||
|
self::assertInstanceOf('\DateTimeImmutable', $this->log->createdAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Exchange\Models\ExchangeLog
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testTypeInputOutput() : void
|
||||||
|
{
|
||||||
|
$this->log->setType(ExchangeType::EXPORT);
|
||||||
|
self::assertEquals(ExchangeType::EXPORT, $this->log->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Exchange\Models\ExchangeLog
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testFieldsInputOutput() : void
|
||||||
|
{
|
||||||
|
$this->log->setFields($fields = [
|
||||||
|
'name' => 'test',
|
||||||
|
'start' => 'now',
|
||||||
|
]);
|
||||||
|
self::assertEquals($fields, $this->log->getFields());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Exchange\Models\ExchangeLog
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testSerialize() : void
|
||||||
|
{
|
||||||
|
$this->log->message = '123456';
|
||||||
|
$this->log->setType(ExchangeType::EXPORT);
|
||||||
|
|
||||||
|
$serialized = $this->log->jsonSerialize();
|
||||||
|
unset($serialized['createdAt']);
|
||||||
|
|
||||||
|
self::assertEquals(
|
||||||
|
[
|
||||||
|
'id' => 0,
|
||||||
|
'message' => '123456',
|
||||||
|
'type' => ExchangeType::EXPORT,
|
||||||
|
'fields' => [],
|
||||||
|
],
|
||||||
|
$serialized
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
53
tests/Models/ExporterAbstractTest.php
Normal file
53
tests/Models/ExporterAbstractTest.php
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 8.0
|
||||||
|
*
|
||||||
|
* @package tests
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\Exchange\tests\Models;
|
||||||
|
|
||||||
|
use Modules\Exchange\Models\ExporterAbstract;
|
||||||
|
use phpOMS\Message\RequestAbstract;
|
||||||
|
use phpOMS\Message\Http\HttpRequest;
|
||||||
|
use phpOMS\DataStorage\Database\Connection\SQLiteConnection;
|
||||||
|
use phpOMS\Uri\HttpUri;
|
||||||
|
use phpOMS\Localization\L11nManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class ExporterAbstractTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
private ExporterAbstract $class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() : void
|
||||||
|
{
|
||||||
|
$this->class = new class(
|
||||||
|
new SQLiteConnection($GLOBALS['CONFIG']['db']['core']['sqlite']['admin']),
|
||||||
|
new L11nManager('placeholder')
|
||||||
|
) extends ExporterAbstract {
|
||||||
|
public function exportFromRequest(RequestAbstract $request) : array
|
||||||
|
{
|
||||||
|
return [$this->local, $this->l11n];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMembers() : void
|
||||||
|
{
|
||||||
|
$result = $this->class->exportFromRequest(new HttpRequest(new HttpUri('')));
|
||||||
|
self::assertInstanceOf('\phpOMS\DataStorage\Database\Connection\ConnectionAbstract', $result[0]);
|
||||||
|
self::assertInstanceOf(L11nManager::class, $result[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
56
tests/Models/ImporterAbstractTest.php
Normal file
56
tests/Models/ImporterAbstractTest.php
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 8.0
|
||||||
|
*
|
||||||
|
* @package tests
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\Exchange\tests\Models;
|
||||||
|
|
||||||
|
use Modules\Exchange\Models\ImporterAbstract;
|
||||||
|
use phpOMS\Message\RequestAbstract;
|
||||||
|
use phpOMS\Message\Http\HttpRequest;
|
||||||
|
use phpOMS\DataStorage\Database\Connection\SQLiteConnection;
|
||||||
|
use phpOMS\DataStorage\Database\Connection\NullConnection;
|
||||||
|
use phpOMS\Uri\HttpUri;
|
||||||
|
use phpOMS\Localization\L11nManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class ImporterAbstractTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
private ImporterAbstract $class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() : void
|
||||||
|
{
|
||||||
|
$this->class = new class(
|
||||||
|
new SQLiteConnection($GLOBALS['CONFIG']['db']['core']['sqlite']['admin']),
|
||||||
|
new NullConnection(),
|
||||||
|
new L11nManager('placeholder')
|
||||||
|
) extends ImporterAbstract {
|
||||||
|
public function importFromRequest(RequestAbstract $request) : array
|
||||||
|
{
|
||||||
|
return [$this->local, $this->remote, $this->l11n];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMembers() : void
|
||||||
|
{
|
||||||
|
$result = $this->class->importFromRequest(new HttpRequest(new HttpUri('')));
|
||||||
|
self::assertInstanceOf('\phpOMS\DataStorage\Database\Connection\ConnectionAbstract', $result[0]);
|
||||||
|
self::assertInstanceOf('\phpOMS\DataStorage\Database\Connection\ConnectionAbstract', $result[1]);
|
||||||
|
self::assertInstanceOf(L11nManager::class, $result[2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
121
tests/Models/InterfaceManagerTest.php
Normal file
121
tests/Models/InterfaceManagerTest.php
Normal file
|
|
@ -0,0 +1,121 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 8.0
|
||||||
|
*
|
||||||
|
* @package tests
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\Exchange\tests\Models;
|
||||||
|
|
||||||
|
use Modules\Exchange\Models\InterfaceManager;
|
||||||
|
use Modules\Exchange\Models\ExchangeType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class InterfaceManagerTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
private InterfaceManager $interface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() : void
|
||||||
|
{
|
||||||
|
$this->interface = new InterfaceManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Exchange\Models\InterfaceManager
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testDefault() : void
|
||||||
|
{
|
||||||
|
self::assertEquals(0, $this->interface->getId());
|
||||||
|
self::assertEquals('', $this->interface->getPath());
|
||||||
|
self::assertEquals('', $this->interface->getName());
|
||||||
|
self::assertEquals('', $this->interface->getInterfacePath());
|
||||||
|
self::assertFalse($this->interface->hasImport());
|
||||||
|
self::assertFalse($this->interface->hasExport());
|
||||||
|
self::assertEquals([], $this->interface->get());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Exchange\Models\InterfaceManager
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testLoadInputOutput() : void
|
||||||
|
{
|
||||||
|
$this->interface = new InterfaceManager(__DIR__ . '/testInterface.json');
|
||||||
|
$this->interface->load();
|
||||||
|
|
||||||
|
self::assertEquals(
|
||||||
|
\json_decode(\file_get_contents(__DIR__ . '/testInterface.json'), true),
|
||||||
|
$this->interface->get()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Exchange\Models\InterfaceManager
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testSetInputOutput() : void
|
||||||
|
{
|
||||||
|
$this->interface = new InterfaceManager(__DIR__ . '/testInterface.json');
|
||||||
|
$this->interface->load();
|
||||||
|
|
||||||
|
$this->interface->set('website', 'https://orange-management.org');
|
||||||
|
self::assertEquals('https://orange-management.org', $this->interface->get()['website']);
|
||||||
|
|
||||||
|
self::assertNotEquals(
|
||||||
|
\json_decode(\file_get_contents(__DIR__ . '/testInterface.json'), true),
|
||||||
|
$this->interface->get()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->interface->update();
|
||||||
|
self::assertEquals(
|
||||||
|
\json_decode(\file_get_contents(__DIR__ . '/testInterface.json'), true),
|
||||||
|
$this->interface->get()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->interface->set('website', '');
|
||||||
|
$this->interface->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Exchange\Models\InterfaceManager
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testInvalidPathLoad() : void
|
||||||
|
{
|
||||||
|
$this->expectException(\phpOMS\System\File\PathException::class);
|
||||||
|
$this->interface->load();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Exchange\Models\InterfaceManager
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testInvalidPathUpdate() : void
|
||||||
|
{
|
||||||
|
$this->expectException(\phpOMS\System\File\PathException::class);
|
||||||
|
$this->interface->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Modules\Exchange\Models\InterfaceManager
|
||||||
|
* @group module
|
||||||
|
*/
|
||||||
|
public function testInvalidDataSet() : void
|
||||||
|
{
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
$this->interface->set('test/path', new InterfaceManager());
|
||||||
|
}
|
||||||
|
}
|
||||||
8
tests/Models/testInterface.json
Normal file
8
tests/Models/testInterface.json
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"name": "OMS",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"website": "",
|
||||||
|
"path": "OMS",
|
||||||
|
"export": true,
|
||||||
|
"import": true
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user