diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 4bd91e0..e7b4ed4 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -32,6 +32,7 @@ use Modules\SupplierManagement\Models\SupplierAttributeTypeMapper; use Modules\SupplierManagement\Models\SupplierAttributeValue; use Modules\SupplierManagement\Models\SupplierAttributeValueMapper; use Modules\SupplierManagement\Models\SupplierMapper; +use phpOMS\Localization\ISO639x1Enum; use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\NotificationLevel; use phpOMS\Message\RequestAbstract; @@ -269,8 +270,8 @@ final class ApiController extends Controller */ private function createSupplierAttributeTypeL11nFromRequest(RequestAbstract $request) : SupplierAttributeTypeL11n { - $attrL11n = new SupplierAttributeTypeL11n(); - $attrL11n->setType((int) ($request->getData('type') ?? 0)); + $attrL11n = new SupplierAttributeTypeL11n(); + $attrL11n->type = (int) ($request->getData('type') ?? 0); $attrL11n->setLanguage((string) ( $request->getData('language') ?? $request->getLanguage() )); @@ -323,7 +324,6 @@ final class ApiController extends Controller } $attrType = $this->createSupplierAttributeTypeFromRequest($request); - $attrType->setL11n($request->getData('title'), $request->getData('language')); $this->createModel($request->header->account, $attrType, SupplierAttributeTypeMapper::class, 'attr_type', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute type', 'Attribute type successfully created', $attrType); @@ -341,9 +341,9 @@ final class ApiController extends Controller private function createSupplierAttributeTypeFromRequest(RequestAbstract $request) : SupplierAttributeType { $attrType = new SupplierAttributeType(); - $attrType->setL11n((string) ($request->getData('name') ?? '')); - $attrType->setFields((int) ($request->getData('fields') ?? 0)); - $attrType->setCustom((bool) ($request->getData('custom') ?? false)); + $attrType->setL11n((string) ($request->getData('title') ?? ''), $request->getData('language') ?? ISO639x1Enum::_EN); + $attrType->fields = (int) ($request->getData('fields') ?? 0); + $attrType->custom = (bool) ($request->getData('custom') ?? false); return $attrType; } @@ -360,8 +360,7 @@ final class ApiController extends Controller private function validateSupplierAttributeTypeCreate(RequestAbstract $request) : array { $val = []; - if (($val['name'] = empty($request->getData('name'))) - || ($val['title'] = empty($request->getData('title'))) + if (($val['title'] = empty($request->getData('title'))) ) { return $val; } @@ -490,7 +489,8 @@ final class ApiController extends Controller } $uploaded = $this->app->moduleManager->get('Media')->uploadFiles( - [$request->getData('name') ?? ''], + $request->getDataList('names') ?? [], + $request->getDataList('filenames') ?? [], $uploadedFiles, $request->header->account, __DIR__ . '/../../../Modules/Media/Files/Modules/SupplierManagement/' . ($request->getData('supplier') ?? '0'), diff --git a/Controller/BackendController.php b/Controller/BackendController.php index e3e1b47..4c26e6f 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -16,7 +16,6 @@ namespace Modules\SupplierManagement\Controller; use Modules\Billing\Models\BillTypeL11n; use Modules\Billing\Models\PurchaseBillMapper; -use Modules\Media\Models\Media; use Modules\SupplierManagement\Models\SupplierMapper; use phpOMS\Asset\AssetType; use phpOMS\Contract\RenderableInterface; diff --git a/Models/NullSupplierAttribute.php b/Models/NullSupplierAttribute.php index 8e18513..de5af51 100755 --- a/Models/NullSupplierAttribute.php +++ b/Models/NullSupplierAttribute.php @@ -33,6 +33,7 @@ final class NullSupplierAttribute extends SupplierAttribute */ public function __construct(int $id = 0) { + parent::__construct(); $this->id = $id; } } diff --git a/Models/Supplier.php b/Models/Supplier.php index 91f8072..44e7e65 100755 --- a/Models/Supplier.php +++ b/Models/Supplier.php @@ -18,7 +18,6 @@ use Modules\Admin\Models\Address; use Modules\Admin\Models\NullAddress; use Modules\Editor\Models\EditorDoc; use Modules\Media\Models\Media; -use Modules\Media\Models\NullMedia; use Modules\Profile\Models\ContactElement; use Modules\Profile\Models\NullContactElement; use Modules\Profile\Models\Profile; @@ -43,15 +42,15 @@ class Supplier public string $number = ''; - private string $numberReverse = ''; + public string $numberReverse = ''; - private int $status = 0; + private int $status = SupplierStatus::ACTIVE; private int $type = 0; public string $info = ''; - private \DateTimeImmutable $createdAt; + public \DateTimeImmutable $createdAt; public Profile $profile; @@ -79,6 +78,8 @@ class Supplier public Address $mainAddress; + private array $partners = []; + /** * Constructor. * @@ -103,36 +104,6 @@ class Supplier return $this->id; } - /** - * Get reverse number. - * - * @return string - * - * @since 1.0.0 - */ - public function getReverseNumber() : string - { - return $this->numberReverse; - } - - /** - * Set revers number. - * - * @param string $numberReverse Reverse number - * - * @return void - * - * @since 1.0.0 - */ - public function setReverseNumber(string $numberReverse) : void - { - if (!\is_scalar($numberReverse)) { - throw new \Exception(); - } - - $this->numberReverse = $numberReverse; - } - /** * Get status. * @@ -185,32 +156,6 @@ class Supplier $this->type = $type; } - /** - * Get info. - * - * @return string - * - * @since 1.0.0 - */ - public function getInfo() : string - { - return $this->info; - } - - /** - * Set info. - * - * @param string $info Info - * - * @return void - * - * @since 1.0.0 - */ - public function setInfo(string $info) : void - { - $this->info = $info; - } - /** * Add doc to item * @@ -299,7 +244,7 @@ class Supplier */ private function orderContactElements(ContactElement $a, ContactElement $b) : int { - return $a->getOrder() <=> $b->getOrder(); + return $a->order <=> $b->order; } /** @@ -338,36 +283,16 @@ class Supplier $this->contactElements[] = $element; } - /** - * Get media file by type - * - * @param string $type Media type - * - * @return Media - * - * @since 1.0.0 - */ - public function getFileByType(string $type) : Media - { - foreach ($this->files as $file) { - if ($file->type === $type) { - return $file; - } - } - - return new NullMedia(); - } - /** * Get all media files by type * - * @param string $type Media type + * @param null|int $type Media type * * @return Media[] * * @since 1.0.0 */ - public function getFilesByType(string $type) : array + public function getFilesByType(int $type = null) : array { $files = []; foreach ($this->files as $file) { @@ -378,4 +303,27 @@ class Supplier return $files; } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'number' => $this->number, + 'numberReverse' => $this->numberReverse, + 'status' => $this->status, + 'type' => $this->type, + 'info' => $this->info, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } } diff --git a/Models/SupplierAttribute.php b/Models/SupplierAttribute.php index 8455a5c..b4e7e4f 100755 --- a/Models/SupplierAttribute.php +++ b/Models/SupplierAttribute.php @@ -58,6 +58,17 @@ class SupplierAttribute implements \JsonSerializable, ArrayableInterface */ public SupplierAttributeValue $value; + /** + * Constructor. + * + * @since 1.0.0 + */ + public function __construct() + { + $this->type = new SupplierAttributeType(); + $this->value = new SupplierAttributeValue(); + } + /** * Get id * @@ -75,7 +86,12 @@ class SupplierAttribute implements \JsonSerializable, ArrayableInterface */ public function toArray() : array { - return []; + return [ + 'id' => $this->id, + 'supplier' => $this->supplier, + 'type' => $this->type, + 'value' => $this->value, + ]; } /** diff --git a/Models/SupplierAttributeType.php b/Models/SupplierAttributeType.php index 95091a5..fe80c14 100755 --- a/Models/SupplierAttributeType.php +++ b/Models/SupplierAttributeType.php @@ -41,7 +41,7 @@ class SupplierAttributeType implements \JsonSerializable, ArrayableInterface * @var string * @since 1.0.0 */ - protected string $name = ''; // @todo: currently not filled, should be used as identifier or if not required removed (at the moment it seems like it is useless?!) + public string $name = ''; // @todo: currently not filled, should be used as identifier or if not required removed (at the moment it seems like it is useless?!) /** * Which field data type is required (string, int, ...) in the value @@ -49,7 +49,7 @@ class SupplierAttributeType implements \JsonSerializable, ArrayableInterface * @var int * @since 1.0.0 */ - protected int $fields = 0; + public int $fields = 0; /** * Is a custom value allowed (e.g. custom string) @@ -57,7 +57,7 @@ class SupplierAttributeType implements \JsonSerializable, ArrayableInterface * @var bool * @since 1.0.0 */ - protected bool $custom = false; + public bool $custom = false; public string $validationPattern = ''; @@ -134,40 +134,19 @@ class SupplierAttributeType implements \JsonSerializable, ArrayableInterface return $this->l11n instanceof SupplierAttributeTypeL11n ? $this->l11n->title : $this->l11n; } - /** - * Set fields - * - * @param int $fields Fields - * - * @return void - * - * @since 1.0.0 - */ - public function setFields(int $fields) : void - { - $this->fields = $fields; - } - - /** - * Set custom - * - * @param bool $custom FieldsCustom - * - * @return void - * - * @since 1.0.0 - */ - public function setCustom(bool $custom) : void - { - $this->custom = $custom; - } - /** * {@inheritdoc} */ public function toArray() : array { - return []; + return [ + 'id' => $this->id, + 'name' => $this->name, + 'fields' => $this->fields, + 'custom' => $this->custom, + 'validationPattern' => $this->validationPattern, + 'isRequired' => $this->isRequired, + ]; } /** diff --git a/Models/SupplierAttributeTypeL11n.php b/Models/SupplierAttributeTypeL11n.php index 40e8e5f..1c58b1f 100755 --- a/Models/SupplierAttributeTypeL11n.php +++ b/Models/SupplierAttributeTypeL11n.php @@ -41,7 +41,7 @@ class SupplierAttributeTypeL11n implements \JsonSerializable, ArrayableInterface * @var int|SupplierAttributeType * @since 1.0.0 */ - protected int | SupplierAttributeType $type = 0; + public int | SupplierAttributeType $type = 0; /** * Language. @@ -88,29 +88,15 @@ class SupplierAttributeTypeL11n implements \JsonSerializable, ArrayableInterface } /** - * Get attribute type + * Get language * - * @return int|SupplierAttributeType + * @return string * * @since 1.0.0 */ - public function getType() + public function getLanguage() : string { - return $this->type; - } - - /** - * Set type. - * - * @param int $type Type id - * - * @return void - * - * @since 1.0.0 - */ - public function setType(int $type) : void - { - $this->type = $type; + return $this->language; } /** @@ -132,7 +118,12 @@ class SupplierAttributeTypeL11n implements \JsonSerializable, ArrayableInterface */ public function toArray() : array { - return []; + return [ + 'id' => $this->id, + 'title' => $this->title, + 'type' => $this->type, + 'language' => $this->language, + ]; } /** diff --git a/Models/SupplierAttributeValue.php b/Models/SupplierAttributeValue.php index a43332a..ee134bb 100755 --- a/Models/SupplierAttributeValue.php +++ b/Models/SupplierAttributeValue.php @@ -189,6 +189,18 @@ class SupplierAttributeValue implements \JsonSerializable, ArrayableInterface $this->language = $language; } + /** + * Get language + * + * @return string + * + * @since 1.0.0 + */ + public function getLanguage() : string + { + return $this->language; + } + /** * Set country * @@ -203,12 +215,34 @@ class SupplierAttributeValue implements \JsonSerializable, ArrayableInterface $this->country = $country; } + /** + * Get country + * + * @return string + * + * @since 1.0.0 + */ + public function getCountry() : string + { + return $this->country; + } + /** * {@inheritdoc} */ public function toArray() : array { - return []; + return [ + 'id' => $this->id, + 'type' => $this->type, + 'valueInt' => $this->valueInt, + 'valueStr' => $this->valueStr, + 'valueDec' => $this->valueDec, + 'valueDat' => $this->valueDat, + 'isDefault' => $this->isDefault, + 'language' => $this->language, + 'country' => $this->country, + ]; } /** diff --git a/Models/SupplierStatus.php b/Models/SupplierStatus.php new file mode 100644 index 0000000..dd20f57 --- /dev/null +++ b/Models/SupplierStatus.php @@ -0,0 +1,34 @@ +getData('nav')->render();
- +
diff --git a/tests/Controller/Api/ApiControllerAttributeTrait.php b/tests/Controller/Api/ApiControllerAttributeTrait.php new file mode 100644 index 0000000..299dbdb --- /dev/null +++ b/tests/Controller/Api/ApiControllerAttributeTrait.php @@ -0,0 +1,221 @@ +header->account = 1; + $request->setData('title', 'EN:1'); + $request->setData('language', ISO639x1Enum::_EN); + + $this->module->apiSupplierAttributeTypeCreate($request, $response); + self::assertGreaterThan(0, $response->get('')['response']->getId()); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierAttributeTypeL11nCreate() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('title', 'DE:2'); + $request->setData('type', '1'); + $request->setData('language', ISO639x1Enum::_DE); + + $this->module->apiSupplierAttributeTypeL11nCreate($request, $response); + self::assertGreaterThan(0, $response->get('')['response']->getId()); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierAttributeValueIntCreate() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('default', '1'); + $request->setData('attributetype', '1'); + $request->setData('type', AttributeValueType::_INT); + $request->setData('value', '1'); + $request->setData('language', ISO639x1Enum::_DE); + $request->setData('country', ISO3166TwoEnum::_DEU); + + $this->module->apiSupplierAttributeValueCreate($request, $response); + self::assertGreaterThan(0, $response->get('')['response']->getId()); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierAttributeValueStrCreate() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('type', AttributeValueType::_STRING); + $request->setData('value', '1'); + $request->setData('language', ISO639x1Enum::_DE); + $request->setData('country', ISO3166TwoEnum::_DEU); + + $this->module->apiSupplierAttributeValueCreate($request, $response); + self::assertGreaterThan(0, $response->get('')['response']->getId()); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierAttributeValueFloatCreate() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('type', AttributeValueType::_FLOAT); + $request->setData('value', '1.1'); + $request->setData('language', ISO639x1Enum::_DE); + $request->setData('country', ISO3166TwoEnum::_DEU); + + $this->module->apiSupplierAttributeValueCreate($request, $response); + self::assertGreaterThan(0, $response->get('')['response']->getId()); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierAttributeValueDatCreate() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('type', AttributeValueType::_DATETIME); + $request->setData('value', '2020-08-02'); + $request->setData('language', ISO639x1Enum::_DE); + $request->setData('country', ISO3166TwoEnum::_DEU); + + $this->module->apiSupplierAttributeValueCreate($request, $response); + self::assertGreaterThan(0, $response->get('')['response']->getId()); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierAttributeCreate() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('supplier', '1'); + $request->setData('value', '1'); + $request->setData('type', '1'); + + $this->module->apiSupplierAttributeCreate($request, $response); + self::assertGreaterThan(0, $response->get('')['response']->getId()); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierAttributeValueCreateInvalidData() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('invalid', '1'); + + $this->module->apiSupplierAttributeValueCreate($request, $response); + self::assertEquals(RequestStatusCode::R_400, $response->header->status); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierAttributeTypeCreateInvalidData() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('invalid', '1'); + + $this->module->apiSupplierAttributeTypeCreate($request, $response); + self::assertEquals(RequestStatusCode::R_400, $response->header->status); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierAttributeTypeL11nCreateInvalidData() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('invalid', '1'); + + $this->module->apiSupplierAttributeTypeL11nCreate($request, $response); + self::assertEquals(RequestStatusCode::R_400, $response->header->status); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierAttributeCreateInvalidData() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('invalid', '1'); + + $this->module->apiSupplierAttributeCreate($request, $response); + self::assertEquals(RequestStatusCode::R_400, $response->header->status); + } +} diff --git a/tests/Controller/Api/ApiControllerSupplierTrait.php b/tests/Controller/Api/ApiControllerSupplierTrait.php new file mode 100644 index 0000000..82608de --- /dev/null +++ b/tests/Controller/Api/ApiControllerSupplierTrait.php @@ -0,0 +1,210 @@ +header->account = 1; + $request->setData('number', '123456'); + $request->setData('name1', 'Name1'); + $request->setData('name2', 'Name2'); + $request->setData('info', 'Info text'); + $request->setData('address', 'Address'); + $request->setData('postal', 'Postal'); + $request->setData('city', 'City'); + $request->setData('country', ISO3166TwoEnum::_USA); + + $this->module->apiSupplierCreate($request, $response); + self::assertGreaterThan(0, $response->get('')['response']->getId()); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierContactElementCreate() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('account', '1'); // supplier id in this case + $request->setData('type', ContactType::EMAIL); + $request->setData('content', 'email@email.com'); + + $this->module->apiContactElementCreate($request, $response); + + self::assertGreaterThan(0, $response->get('')['response']->getId()); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierContactElementCreateInvalidData() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('invalid', '1'); + + $this->module->apiContactElementCreate($request, $response); + self::assertEquals(RequestStatusCode::R_400, $response->header->status); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierCreateInvalidData() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('invalid', '1'); + + $this->module->apiSupplierCreate($request, $response); + self::assertEquals(RequestStatusCode::R_400, $response->header->status); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierProfileImageCreate() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + \copy(__DIR__ . '/m_icon.png', __DIR__ . '/m_icon_tmp.png'); + + $request->header->account = 1; + $request->setData('name', '123456 backend'); + $request->setData('supplier', 1); + $request->setData('type', 'backend_image'); + + TestUtils::setMember($request, 'files', [ + 'file1' => [ + 'name' => '123456.png', + 'type' => MimeType::M_PNG, + 'tmp_name' => __DIR__ . '/m_icon_tmp.png', + 'error' => \UPLOAD_ERR_OK, + 'size' => \filesize(__DIR__ . '/m_icon_tmp.png'), + ], + ]); + + $this->module->apiFileCreate($request, $response); + $file = $response->get('')['response']; + self::assertGreaterThan(0, \reset($file)->getId()); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierFileCreate() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + \copy(__DIR__ . '/Test file.txt', __DIR__ . '/Test file_tmp.txt'); + + $request->header->account = 1; + $request->setData('name', 'test file backend'); + $request->setData('supplier', 1); + + TestUtils::setMember($request, 'files', [ + 'file1' => [ + 'name' => 'Test file.txt', + 'type' => MimeType::M_TXT, + 'tmp_name' => __DIR__ . '/Test file_tmp.txt', + 'error' => \UPLOAD_ERR_OK, + 'size' => \filesize(__DIR__ . '/Test file_tmp.txt'), + ], + ]); + + $this->module->apiFileCreate($request, $response); + $file = $response->get('')['response']; + self::assertGreaterThan(0, \reset($file)->getId()); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiSupplierNoteCreate() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + + $MARKDOWN = "# Test Title\n\nThis is **some** text."; + + $request->setData('id', 1); + $request->setData('title', \trim(\strtok($MARKDOWN, "\n"), ' #')); + $request->setData('plain', \preg_replace('/^.+\n/', '', $MARKDOWN)); + + $this->module->apiNoteCreate($request, $response); + self::assertGreaterThan(0, $response->get('')['response']->getId()); + } + + /** + * @covers Modules\SupplierManagement\Controller\ApiController + * @group module + */ + public function testApiFileCreateInvalidData() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('invalid', '1'); + + $this->module->apiFileCreate($request, $response); + self::assertEquals(RequestStatusCode::R_400, $response->header->status); + } +} diff --git a/tests/Controller/Api/Test file.txt b/tests/Controller/Api/Test file.txt new file mode 100644 index 0000000..bdf08de --- /dev/null +++ b/tests/Controller/Api/Test file.txt @@ -0,0 +1 @@ +test file \ No newline at end of file diff --git a/tests/Controller/Api/m_icon.png b/tests/Controller/Api/m_icon.png new file mode 100644 index 0000000..587d4f9 Binary files /dev/null and b/tests/Controller/Api/m_icon.png differ diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php new file mode 100644 index 0000000..c2e9b49 --- /dev/null +++ b/tests/Controller/ApiControllerTest.php @@ -0,0 +1,93 @@ +app = new class() extends ApplicationAbstract + { + protected string $appName = 'Api'; + }; + + $this->app->dbPool = $GLOBALS['dbpool']; + $this->app->orgId = 1; + $this->app->accountManager = new AccountManager($GLOBALS['session']); + $this->app->appSettings = new CoreSettings(); + $this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules/'); + $this->app->dispatcher = new Dispatcher($this->app); + $this->app->eventManager = new EventManager($this->app->dispatcher); + $this->app->eventManager->importFromFile(__DIR__ . '/../../../../Web/Api/Hooks.php'); + $this->app->sessionManager = new HttpSession(36000); + + $account = new Account(); + TestUtils::setMember($account, 'id', 1); + + $permission = new AccountPermission(); + $permission->setUnit(1); + $permission->setApp('backend'); + $permission->setPermission( + PermissionType::READ + | PermissionType::CREATE + | PermissionType::MODIFY + | PermissionType::DELETE + | PermissionType::PERMISSION + ); + + $account->addPermission($permission); + + $this->app->accountManager->add($account); + $this->app->router = new WebRouter(); + + $this->module = $this->app->moduleManager->get('SupplierManagement'); + + TestUtils::setMember($this->module, 'app', $this->app); + } + + use ApiControllerSupplierTrait; + use ApiControllerAttributeTrait; +} diff --git a/tests/Models/NullSupplierAttributeTest.php b/tests/Models/NullSupplierAttributeTest.php new file mode 100644 index 0000000..d01c97b --- /dev/null +++ b/tests/Models/NullSupplierAttributeTest.php @@ -0,0 +1,42 @@ +getId()); + } +} diff --git a/tests/Models/NullSupplierAttributeTypeL11nTest.php b/tests/Models/NullSupplierAttributeTypeL11nTest.php new file mode 100644 index 0000000..566d51d --- /dev/null +++ b/tests/Models/NullSupplierAttributeTypeL11nTest.php @@ -0,0 +1,42 @@ +getId()); + } +} diff --git a/tests/Models/NullSupplierAttributeTypeTest.php b/tests/Models/NullSupplierAttributeTypeTest.php new file mode 100644 index 0000000..bca6b8f --- /dev/null +++ b/tests/Models/NullSupplierAttributeTypeTest.php @@ -0,0 +1,42 @@ +getId()); + } +} diff --git a/tests/Models/NullSupplierAttributeValueTest.php b/tests/Models/NullSupplierAttributeValueTest.php new file mode 100644 index 0000000..c64ccd2 --- /dev/null +++ b/tests/Models/NullSupplierAttributeValueTest.php @@ -0,0 +1,42 @@ +getId()); + } +} diff --git a/tests/Models/SupplierAttributeTest.php b/tests/Models/SupplierAttributeTest.php new file mode 100644 index 0000000..bdd84ff --- /dev/null +++ b/tests/Models/SupplierAttributeTest.php @@ -0,0 +1,63 @@ +attribute = new SupplierAttribute(); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttribute + * @group module + */ + public function testDefault() : void + { + self::assertEquals(0, $this->attribute->getId()); + self::assertInstanceOf('\Modules\SupplierManagement\Models\SupplierAttributeType', $this->attribute->type); + self::assertInstanceOf('\Modules\SupplierManagement\Models\SupplierAttributeValue', $this->attribute->value); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttribute + * @group module + */ + public function testSerialize() : void + { + $serialized = $this->attribute->jsonSerialize(); + + self::assertEquals( + [ + 'id', + 'supplier', + 'type', + 'value', + ], + \array_keys($serialized) + ); + } +} diff --git a/tests/Models/SupplierAttributeTypeL11nTest.php b/tests/Models/SupplierAttributeTypeL11nTest.php new file mode 100644 index 0000000..771d557 --- /dev/null +++ b/tests/Models/SupplierAttributeTypeL11nTest.php @@ -0,0 +1,87 @@ +l11n = new SupplierAttributeTypeL11n(); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttributeTypeL11n + * @group module + */ + public function testDefault() : void + { + self::assertEquals(0, $this->l11n->getId()); + self::assertEquals('', $this->l11n->title); + self::assertEquals(0, $this->l11n->type); + self::assertEquals(ISO639x1Enum::_EN, $this->l11n->getLanguage()); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttributeTypeL11n + * @group module + */ + public function testNameInputOutput() : void + { + $this->l11n->title = 'TestName'; + self::assertEquals('TestName', $this->l11n->title); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttributeTypeL11n + * @group module + */ + public function testLanguageInputOutput() : void + { + $this->l11n->setLanguage(ISO639x1Enum::_DE); + self::assertEquals(ISO639x1Enum::_DE, $this->l11n->getLanguage()); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttributeTypeL11n + * @group module + */ + public function testSerialize() : void + { + $this->l11n->title = 'Title'; + $this->l11n->type = 2; + $this->l11n->setLanguage(ISO639x1Enum::_DE); + + self::assertEquals( + [ + 'id' => 0, + 'title' => 'Title', + 'type' => 2, + 'language' => ISO639x1Enum::_DE, + ], + $this->l11n->jsonSerialize() + ); + } +} diff --git a/tests/Models/SupplierAttributeTypeTest.php b/tests/Models/SupplierAttributeTypeTest.php new file mode 100644 index 0000000..bf44fb7 --- /dev/null +++ b/tests/Models/SupplierAttributeTypeTest.php @@ -0,0 +1,82 @@ +type = new SupplierAttributeType(); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttributeType + * @group module + */ + public function testDefault() : void + { + self::assertEquals(0, $this->type->getId()); + self::assertEquals('', $this->type->getL11n()); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttributeType + * @group module + */ + public function testL11nInputOutput() : void + { + $this->type->setL11n('Test'); + self::assertEquals('Test', $this->type->getL11n()); + + $this->type->setL11n(new SupplierAttributeTypeL11n(0, 'NewTest')); + self::assertEquals('NewTest', $this->type->getL11n()); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttributeType + * @group module + */ + public function testSerialize() : void + { + $this->type->name = 'Title'; + $this->type->fields = 2; + $this->type->custom = true; + $this->type->validationPattern = '\d*'; + $this->type->isRequired = true; + + self::assertEquals( + [ + 'id' => 0, + 'name' => 'Title', + 'fields' => 2, + 'custom' => true, + 'validationPattern' => '\d*', + 'isRequired' => true, + ], + $this->type->jsonSerialize() + ); + } +} diff --git a/tests/Models/SupplierAttributeValueTest.php b/tests/Models/SupplierAttributeValueTest.php new file mode 100644 index 0000000..488f5da --- /dev/null +++ b/tests/Models/SupplierAttributeValueTest.php @@ -0,0 +1,133 @@ +value = new SupplierAttributeValue(); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttributeValue + * @group module + */ + public function testDefault() : void + { + self::assertEquals(0, $this->value->getId()); + self::assertNull($this->value->getValue()); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttributeValue + * @group module + */ + public function testLanguageInputOutput() : void + { + $this->value->setLanguage(ISO639x1Enum::_DE); + self::assertEquals(ISO639x1Enum::_DE, $this->value->getLanguage()); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttributeValue + * @group module + */ + public function testCountryInputOutput() : void + { + $this->value->setCountry(ISO3166TwoEnum::_DEU); + self::assertEquals(ISO3166TwoEnum::_DEU, $this->value->getCountry()); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttributeValue + * @group module + */ + public function testValueIntInputOutput() : void + { + $this->value->setValue(1); + self::assertEquals(1, $this->value->getValue()); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttributeValue + * @group module + */ + public function testValueFloatInputOutput() : void + { + $this->value->setValue(1.1); + self::assertEquals(1.1, $this->value->getValue()); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttributeValue + * @group module + */ + public function testValueStringInputOutput() : void + { + $this->value->setValue('test'); + self::assertEquals('test', $this->value->getValue()); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttributeValue + * @group module + */ + public function testValueDateInputOutput() : void + { + $this->value->setValue($dat = new \DateTime('now')); + self::assertEquals($dat->format('Y-m-d'), $this->value->getValue()->format('Y-m-d')); + } + + /** + * @covers Modules\SupplierManagement\Models\SupplierAttributeValue + * @group module + */ + public function testSerialize() : void + { + $this->value->type = 1; + $this->value->setValue('test'); + $this->value->isDefault = true; + $this->value->setLanguage(ISO639x1Enum::_DE); + $this->value->setCountry(ISO3166TwoEnum::_DEU); + + self::assertEquals( + [ + 'id' => 0, + 'type' => 1, + 'valueInt' => null, + 'valueStr' => 'test', + 'valueDec' => null, + 'valueDat' => null, + 'isDefault' => true, + 'language' => ISO639x1Enum::_DE, + 'country' => ISO3166TwoEnum::_DEU, + ], + $this->value->jsonSerialize() + ); + } +} diff --git a/tests/Models/SupplierTest.php b/tests/Models/SupplierTest.php new file mode 100644 index 0000000..51000bc --- /dev/null +++ b/tests/Models/SupplierTest.php @@ -0,0 +1,137 @@ +supplier = new Supplier(); + } + + /** + * @covers Modules\SupplierManagement\Models\Supplier + * @group module + */ + public function testDefault() : void + { + self::assertEquals(0, $this->supplier->getId()); + self::assertEquals('', $this->supplier->number); + self::assertEquals('', $this->supplier->numberReverse); + self::assertEquals('', $this->supplier->info); + self::assertEquals(SupplierStatus::ACTIVE, $this->supplier->getStatus()); + self::assertEquals(0, $this->supplier->getType()); + self::assertEquals([], $this->supplier->getNotes()); + self::assertEquals([], $this->supplier->getFiles()); + self::assertEquals([], $this->supplier->getAddresses()); + self::assertEquals([], $this->supplier->getContactElements()); + self::assertEquals([], $this->supplier->getFilesByType(0)); + self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $this->supplier->createdAt->format('Y-m-d')); + self::assertInstanceOf('\Modules\Profile\Models\Profile', $this->supplier->profile); + self::assertInstanceOf('\Modules\Admin\Models\Address', $this->supplier->mainAddress); + self::assertInstanceOf('\Modules\Profile\Models\NullContactElement', $this->supplier->getMainContactElement(0)); + } + + /** + * @covers Modules\SupplierManagement\Models\Supplier + * @group module + */ + public function testStatusInputOutput() : void + { + $this->supplier->setStatus(SupplierStatus::INACTIVE); + self::assertEquals(SupplierStatus::INACTIVE, $this->supplier->getStatus()); + } + + /** + * @covers Modules\SupplierManagement\Models\Supplier + * @group module + */ + public function testTypeInputOutput() : void + { + $this->supplier->setType(2); + self::assertEquals(2, $this->supplier->getType()); + } + + /** + * @covers Modules\SupplierManagement\Models\Supplier + * @group module + */ + public function testFileInputOutput() : void + { + $this->supplier->addFile($temp = new Media()); + self::assertCount(1, $this->supplier->getFiles()); + self::assertEquals([$temp], $this->supplier->getFilesByType()); + } + + /** + * @covers Modules\SupplierManagement\Models\Supplier + * @group module + */ + public function testContactElementInputOutput() : void + { + $this->supplier->addContactElement($temp = new ContactElement()); + self::assertCount(1, $this->supplier->getContactElements()); + self::assertEquals($temp, $this->supplier->getMainContactElement(0)); + } + + /** + * @covers Modules\SupplierManagement\Models\Supplier + * @group module + */ + public function testNoteInputOutput() : void + { + $this->supplier->addNote(new EditorDoc()); + self::assertCount(1, $this->supplier->getNotes()); + } + + /** + * @covers Modules\SupplierManagement\Models\Supplier + * @group module + */ + public function testSerialize() : void + { + $this->supplier->number = '123456'; + $this->supplier->numberReverse = '654321'; + $this->supplier->setStatus(SupplierStatus::INACTIVE); + $this->supplier->setType(2); + $this->supplier->info = 'Test info'; + + self::assertEquals( + [ + 'id' => 0, + 'number' => '123456', + 'numberReverse' => '654321', + 'status' => SupplierStatus::INACTIVE, + 'type' => 2, + 'info' => 'Test info', + ], + $this->supplier->jsonSerialize() + ); + } +}