From 56010f1f3d023917d7f78ee2125695b50adaba97 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 25 Oct 2021 20:06:48 +0200 Subject: [PATCH] test fixes --- Interfaces/GSD/Importer.php | 2 + Interfaces/GSD/Model/GSDAddress.php | 2 + Interfaces/GSD/Model/GSDArticle.php | 2 + Interfaces/GSD/Model/GSDCostCenter.php | 2 + Interfaces/GSD/Model/GSDCostObject.php | 2 + Interfaces/GSD/Model/GSDCustomer.php | 2 + Interfaces/GSD/Model/GSDSupplier.php | 2 + Interfaces/Intrexx/Importer.php | 2 + Interfaces/OMS/Exporter.php | 6 +- Models/ExchangeLog.php | 34 ++----- Models/InterfaceManager.php | 12 +-- tests/Interfaces/OMS/ExporterTest.php | 55 +++++++++++ tests/Interfaces/OMS/ImporterTest.php | 70 ++++++++++++++ tests/Interfaces/OMS/test.csv | 3 + tests/Models/ExchangeLogTest.php | 95 +++++++++++++++++++ tests/Models/ExporterAbstractTest.php | 53 +++++++++++ tests/Models/ImporterAbstractTest.php | 56 ++++++++++++ tests/Models/InterfaceManagerTest.php | 121 +++++++++++++++++++++++++ tests/Models/testInterface.json | 8 ++ 19 files changed, 495 insertions(+), 34 deletions(-) create mode 100644 tests/Interfaces/OMS/ExporterTest.php create mode 100644 tests/Interfaces/OMS/ImporterTest.php create mode 100644 tests/Interfaces/OMS/test.csv create mode 100644 tests/Models/ExchangeLogTest.php create mode 100644 tests/Models/ExporterAbstractTest.php create mode 100644 tests/Models/ImporterAbstractTest.php create mode 100644 tests/Models/InterfaceManagerTest.php create mode 100644 tests/Models/testInterface.json diff --git a/Interfaces/GSD/Importer.php b/Interfaces/GSD/Importer.php index 7995f6f..7b71be8 100755 --- a/Interfaces/GSD/Importer.php +++ b/Interfaces/GSD/Importer.php @@ -70,6 +70,8 @@ use phpOMS\Utils\IO\Zip\Zip; * @license OMS License 1.0 * @link https://orange-management.org * @since 1.0.0 + * + * @codeCoverageIgnore */ final class Importer extends ImporterAbstract { diff --git a/Interfaces/GSD/Model/GSDAddress.php b/Interfaces/GSD/Model/GSDAddress.php index cbd047f..3af66ec 100755 --- a/Interfaces/GSD/Model/GSDAddress.php +++ b/Interfaces/GSD/Model/GSDAddress.php @@ -21,6 +21,8 @@ namespace Modules\Exchange\Interfaces\GSD\Model; * @license OMS License 1.0 * @link https://orange-management.org * @since 1.0.0 + * + * @codeCoverageIgnore */ class GSDAddress { diff --git a/Interfaces/GSD/Model/GSDArticle.php b/Interfaces/GSD/Model/GSDArticle.php index 5479a53..0bd23ed 100755 --- a/Interfaces/GSD/Model/GSDArticle.php +++ b/Interfaces/GSD/Model/GSDArticle.php @@ -21,6 +21,8 @@ namespace Modules\Exchange\Interfaces\GSD\Model; * @license OMS License 1.0 * @link https://orange-management.org * @since 1.0.0 + * + * @codeCoverageIgnore */ class GSDArticle { diff --git a/Interfaces/GSD/Model/GSDCostCenter.php b/Interfaces/GSD/Model/GSDCostCenter.php index 8920986..60e4bac 100755 --- a/Interfaces/GSD/Model/GSDCostCenter.php +++ b/Interfaces/GSD/Model/GSDCostCenter.php @@ -21,6 +21,8 @@ namespace Modules\Exchange\Interfaces\GSD\Model; * @license OMS License 1.0 * @link https://orange-management.org * @since 1.0.0 + * + * @codeCoverageIgnore */ class GSDCostCenter implements \JsonSerializable { diff --git a/Interfaces/GSD/Model/GSDCostObject.php b/Interfaces/GSD/Model/GSDCostObject.php index d275138..42a3b62 100755 --- a/Interfaces/GSD/Model/GSDCostObject.php +++ b/Interfaces/GSD/Model/GSDCostObject.php @@ -21,6 +21,8 @@ namespace Modules\Exchange\Interfaces\GSD\Model; * @license OMS License 1.0 * @link https://orange-management.org * @since 1.0.0 + * + * @codeCoverageIgnore */ class GSDCostObject implements \JsonSerializable { diff --git a/Interfaces/GSD/Model/GSDCustomer.php b/Interfaces/GSD/Model/GSDCustomer.php index 5a8f794..8b751ca 100755 --- a/Interfaces/GSD/Model/GSDCustomer.php +++ b/Interfaces/GSD/Model/GSDCustomer.php @@ -21,6 +21,8 @@ namespace Modules\Exchange\Interfaces\GSD\Model; * @license OMS License 1.0 * @link https://orange-management.org * @since 1.0.0 + * + * @codeCoverageIgnore */ class GSDCustomer { diff --git a/Interfaces/GSD/Model/GSDSupplier.php b/Interfaces/GSD/Model/GSDSupplier.php index 03de9b2..ad4aad4 100755 --- a/Interfaces/GSD/Model/GSDSupplier.php +++ b/Interfaces/GSD/Model/GSDSupplier.php @@ -21,6 +21,8 @@ namespace Modules\Exchange\Interfaces\GSD\Model; * @license OMS License 1.0 * @link https://orange-management.org * @since 1.0.0 + * + * @codeCoverageIgnore */ class GSDSupplier { diff --git a/Interfaces/Intrexx/Importer.php b/Interfaces/Intrexx/Importer.php index 1bdfece..23e16af 100755 --- a/Interfaces/Intrexx/Importer.php +++ b/Interfaces/Intrexx/Importer.php @@ -24,6 +24,8 @@ use phpOMS\Message\RequestAbstract; * @license OMS License 1.0 * @link https://orange-management.org * @since 1.0.0 + * + * @codeCoverageIgnore */ final class Importer extends ImporterAbstract { diff --git a/Interfaces/OMS/Exporter.php b/Interfaces/OMS/Exporter.php index a752649..4255b8d 100755 --- a/Interfaces/OMS/Exporter.php +++ b/Interfaces/OMS/Exporter.php @@ -55,13 +55,13 @@ final class Exporter extends ExporterAbstract * @param \DateTime $start Start time (inclusive) * @param \DateTime $end End time (inclusive) * - * @return void + * @return array * * @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(); } /** diff --git a/Models/ExchangeLog.php b/Models/ExchangeLog.php index 0379ac0..5d3cf4b 100755 --- a/Models/ExchangeLog.php +++ b/Models/ExchangeLog.php @@ -46,6 +46,8 @@ class ExchangeLog implements \JsonSerializable, ArrayableInterface /** * Fields. * + * What where the values used in the exchange form to reproduce this output (exchange specific)? + * * @var array * @since 1.0.0 */ @@ -59,6 +61,12 @@ class ExchangeLog implements \JsonSerializable, ArrayableInterface */ private int $type = ExchangeType::IMPORT; + /** + * Exchange specific subtype. + * + * @var string + * @since 1.0.0 + */ public string $subtype = ''; /** @@ -133,30 +141,6 @@ class ExchangeLog implements \JsonSerializable, ArrayableInterface 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. * @@ -193,7 +177,7 @@ class ExchangeLog implements \JsonSerializable, ArrayableInterface 'message' => $this->message, 'type' => $this->type, 'fields' => $this->fields, - 'datetime' => $this->createdAt, + 'createdAt' => $this->createdAt, ]; } diff --git a/Models/InterfaceManager.php b/Models/InterfaceManager.php index c5a40ac..61b39b9 100755 --- a/Models/InterfaceManager.php +++ b/Models/InterfaceManager.php @@ -98,7 +98,7 @@ class InterfaceManager */ public function getInterfacePath() : string { - return $this->info['path']; + return $this->info['path'] ?? ''; } /** @@ -110,7 +110,7 @@ class InterfaceManager */ public function getName() : string { - return $this->info['name']; + return $this->info['name'] ?? ''; } /** @@ -122,7 +122,7 @@ class InterfaceManager */ public function hasImport() : bool { - return $this->info['import']; + return $this->info['import'] ?? false; } /** @@ -134,7 +134,7 @@ class InterfaceManager */ public function hasExport() : bool { - return $this->info['export']; + return $this->info['export'] ?? false; } /** @@ -187,13 +187,13 @@ class InterfaceManager * * @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)) { 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); } /** diff --git a/tests/Interfaces/OMS/ExporterTest.php b/tests/Interfaces/OMS/ExporterTest.php new file mode 100644 index 0000000..c087da1 --- /dev/null +++ b/tests/Interfaces/OMS/ExporterTest.php @@ -0,0 +1,55 @@ +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']); + } +} diff --git a/tests/Interfaces/OMS/ImporterTest.php b/tests/Interfaces/OMS/ImporterTest.php new file mode 100644 index 0000000..48a1ad6 --- /dev/null +++ b/tests/Interfaces/OMS/ImporterTest.php @@ -0,0 +1,70 @@ +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')) + ); + } +} diff --git a/tests/Interfaces/OMS/test.csv b/tests/Interfaces/OMS/test.csv new file mode 100644 index 0000000..4778853 --- /dev/null +++ b/tests/Interfaces/OMS/test.csv @@ -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" \ No newline at end of file diff --git a/tests/Models/ExchangeLogTest.php b/tests/Models/ExchangeLogTest.php new file mode 100644 index 0000000..7c4aa46 --- /dev/null +++ b/tests/Models/ExchangeLogTest.php @@ -0,0 +1,95 @@ +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 + ); + } +} diff --git a/tests/Models/ExporterAbstractTest.php b/tests/Models/ExporterAbstractTest.php new file mode 100644 index 0000000..4ab13c5 --- /dev/null +++ b/tests/Models/ExporterAbstractTest.php @@ -0,0 +1,53 @@ +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]); + } +} diff --git a/tests/Models/ImporterAbstractTest.php b/tests/Models/ImporterAbstractTest.php new file mode 100644 index 0000000..5365020 --- /dev/null +++ b/tests/Models/ImporterAbstractTest.php @@ -0,0 +1,56 @@ +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]); + } +} diff --git a/tests/Models/InterfaceManagerTest.php b/tests/Models/InterfaceManagerTest.php new file mode 100644 index 0000000..d918009 --- /dev/null +++ b/tests/Models/InterfaceManagerTest.php @@ -0,0 +1,121 @@ +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()); + } +} diff --git a/tests/Models/testInterface.json b/tests/Models/testInterface.json new file mode 100644 index 0000000..8916412 --- /dev/null +++ b/tests/Models/testInterface.json @@ -0,0 +1,8 @@ +{ + "name": "OMS", + "version": "1.0.0", + "website": "", + "path": "OMS", + "export": true, + "import": true +} \ No newline at end of file