mirror of
https://github.com/Karaka-Management/oms-SupplierManagement.git
synced 2026-01-11 01:18:40 +00:00
cs fixes, bug fixes, code coverage
This commit is contained in:
parent
d558fcd5e4
commit
9a7fe5a5e8
|
|
@ -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'),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ final class NullSupplierAttribute extends SupplierAttribute
|
|||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->id = $id;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
34
Models/SupplierStatus.php
Normal file
34
Models/SupplierStatus.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package Modules\SupplierManagement\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\SupplierManagement\Models;
|
||||
|
||||
use phpOMS\Stdlib\Base\Enum;
|
||||
|
||||
/**
|
||||
* Supplier status enum.
|
||||
*
|
||||
* @package Modules\SupplierManagement\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class SupplierStatus extends Enum
|
||||
{
|
||||
public const ACTIVE = 1;
|
||||
|
||||
public const INACTIVE = 2;
|
||||
|
||||
public const BANNED = 4;
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Modules\Media\Models\NullMedia;
|
||||
use phpOMS\Uri\UriFactory;
|
||||
|
||||
/** @var \phpOMS\Views\View $this */
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ echo $this->getData('nav')->render();
|
|||
|
||||
<section class="portlet highlight-4">
|
||||
<div class="portlet-body">
|
||||
<textarea class="undecorated"><?= $this->printHtml($supplier->getInfo()); ?></textarea>
|
||||
<textarea class="undecorated"><?= $this->printHtml($supplier->info); ?></textarea>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
|
|
|||
221
tests/Controller/Api/ApiControllerAttributeTrait.php
Normal file
221
tests/Controller/Api/ApiControllerAttributeTrait.php
Normal file
|
|
@ -0,0 +1,221 @@
|
|||
<?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\SupplierManagement\tests\Controller\Api;
|
||||
|
||||
use Modules\SupplierManagement\Models\AttributeValueType;
|
||||
use phpOMS\Localization\ISO3166TwoEnum;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
use phpOMS\Message\Http\HttpRequest;
|
||||
use phpOMS\Message\Http\HttpResponse;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
use phpOMS\Uri\HttpUri;
|
||||
|
||||
trait ApiControllerAttributeTrait
|
||||
{
|
||||
/**
|
||||
* @covers Modules\SupplierManagement\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiSupplierAttributeTypeCreate() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->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);
|
||||
}
|
||||
}
|
||||
210
tests/Controller/Api/ApiControllerSupplierTrait.php
Normal file
210
tests/Controller/Api/ApiControllerSupplierTrait.php
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
<?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\SupplierManagement\tests\Controller\Api;
|
||||
|
||||
use Modules\Profile\Models\ContactType;
|
||||
use phpOMS\Localization\ISO3166TwoEnum;
|
||||
use phpOMS\Message\Http\HttpRequest;
|
||||
use phpOMS\Message\Http\HttpResponse;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
use phpOMS\System\MimeType;
|
||||
use phpOMS\Uri\HttpUri;
|
||||
use phpOMS\Utils\TestUtils;
|
||||
|
||||
trait ApiControllerSupplierTrait
|
||||
{
|
||||
public static function tearDownAfterClass() : void
|
||||
{
|
||||
if (\is_file(__DIR__ . '/m_icon_tmp.png')) {
|
||||
\unlink(__DIR__ . '/m_icon_tmp.png');
|
||||
}
|
||||
|
||||
if (\is_file(__DIR__ . '/Test file_tmp.txt')) {
|
||||
\unlink(__DIR__ . '/Test file_tmp.txt');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\SupplierManagement\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiSupplierCreate() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->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);
|
||||
}
|
||||
}
|
||||
1
tests/Controller/Api/Test file.txt
Normal file
1
tests/Controller/Api/Test file.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
test file
|
||||
BIN
tests/Controller/Api/m_icon.png
Normal file
BIN
tests/Controller/Api/m_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 92 KiB |
93
tests/Controller/ApiControllerTest.php
Normal file
93
tests/Controller/ApiControllerTest.php
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?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\SupplierManagement\tests\Controller;
|
||||
|
||||
use Model\CoreSettings;
|
||||
use Modules\Admin\Models\AccountPermission;
|
||||
use Modules\SupplierManagement\tests\Controller\Api\ApiControllerAttributeTrait;
|
||||
use Modules\SupplierManagement\tests\Controller\Api\ApiControllerSupplierTrait;
|
||||
use phpOMS\Account\Account;
|
||||
use phpOMS\Account\AccountManager;
|
||||
use phpOMS\Account\PermissionType;
|
||||
use phpOMS\Application\ApplicationAbstract;
|
||||
use phpOMS\DataStorage\Session\HttpSession;
|
||||
use phpOMS\Dispatcher\Dispatcher;
|
||||
use phpOMS\Event\EventManager;
|
||||
use phpOMS\Module\ModuleAbstract;
|
||||
use phpOMS\Module\ModuleManager;
|
||||
use phpOMS\Router\WebRouter;
|
||||
use phpOMS\Utils\TestUtils;
|
||||
|
||||
/**
|
||||
* @testdox Modules\SupplierManagement\tests\Controller\ApiControllerTest: SupplierManagement api controller
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected ApplicationAbstract $app;
|
||||
|
||||
/**
|
||||
* @var \Modules\SupplierManagement\Controller\ApiController
|
||||
*/
|
||||
protected ModuleAbstract $module;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
42
tests/Models/NullSupplierAttributeTest.php
Normal file
42
tests/Models/NullSupplierAttributeTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?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\SupplierManagement\tests\Models;
|
||||
|
||||
use Modules\SupplierManagement\Models\NullSupplierAttribute;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class NullSupplierAttributeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\SupplierManagement\Models\NullSupplierAttribute
|
||||
* @group framework
|
||||
*/
|
||||
public function testNull() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\SupplierManagement\Models\SupplierAttribute', new NullSupplierAttribute());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\SupplierManagement\Models\NullSupplierAttribute
|
||||
* @group framework
|
||||
*/
|
||||
public function testId() : void
|
||||
{
|
||||
$null = new NullSupplierAttribute(2);
|
||||
self::assertEquals(2, $null->getId());
|
||||
}
|
||||
}
|
||||
42
tests/Models/NullSupplierAttributeTypeL11nTest.php
Normal file
42
tests/Models/NullSupplierAttributeTypeL11nTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?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\SupplierManagement\tests\Models;
|
||||
|
||||
use Modules\SupplierManagement\Models\NullSupplierAttributeTypeL11n;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class NullSupplierAttributeTypeL11nTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\SupplierManagement\Models\NullSupplierAttributeTypeL11n
|
||||
* @group framework
|
||||
*/
|
||||
public function testNull() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\SupplierManagement\Models\SupplierAttributeTypeL11n', new NullSupplierAttributeTypeL11n());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\SupplierManagement\Models\NullSupplierAttributeTypeL11n
|
||||
* @group framework
|
||||
*/
|
||||
public function testId() : void
|
||||
{
|
||||
$null = new NullSupplierAttributeTypeL11n(2);
|
||||
self::assertEquals(2, $null->getId());
|
||||
}
|
||||
}
|
||||
42
tests/Models/NullSupplierAttributeTypeTest.php
Normal file
42
tests/Models/NullSupplierAttributeTypeTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?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\SupplierManagement\tests\Models;
|
||||
|
||||
use Modules\SupplierManagement\Models\NullSupplierAttributeType;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class NullSupplierAttributeTypeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\SupplierManagement\Models\NullSupplierAttributeType
|
||||
* @group framework
|
||||
*/
|
||||
public function testNull() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\SupplierManagement\Models\SupplierAttributeType', new NullSupplierAttributeType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\SupplierManagement\Models\NullSupplierAttributeType
|
||||
* @group framework
|
||||
*/
|
||||
public function testId() : void
|
||||
{
|
||||
$null = new NullSupplierAttributeType(2);
|
||||
self::assertEquals(2, $null->getId());
|
||||
}
|
||||
}
|
||||
42
tests/Models/NullSupplierAttributeValueTest.php
Normal file
42
tests/Models/NullSupplierAttributeValueTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?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\SupplierManagement\tests\Models;
|
||||
|
||||
use Modules\SupplierManagement\Models\NullSupplierAttributeValue;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class NullSupplierAttributeValueTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\SupplierManagement\Models\NullSupplierAttributeValue
|
||||
* @group framework
|
||||
*/
|
||||
public function testNull() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\SupplierManagement\Models\SupplierAttributeValue', new NullSupplierAttributeValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\SupplierManagement\Models\NullSupplierAttributeValue
|
||||
* @group framework
|
||||
*/
|
||||
public function testId() : void
|
||||
{
|
||||
$null = new NullSupplierAttributeValue(2);
|
||||
self::assertEquals(2, $null->getId());
|
||||
}
|
||||
}
|
||||
63
tests/Models/SupplierAttributeTest.php
Normal file
63
tests/Models/SupplierAttributeTest.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?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\SupplierManagement\tests\Models;
|
||||
|
||||
use Modules\SupplierManagement\Models\SupplierAttribute;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class SupplierAttributeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private SupplierAttribute $attribute;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->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)
|
||||
);
|
||||
}
|
||||
}
|
||||
87
tests/Models/SupplierAttributeTypeL11nTest.php
Normal file
87
tests/Models/SupplierAttributeTypeL11nTest.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?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\SupplierManagement\tests\Models;
|
||||
|
||||
use Modules\SupplierManagement\Models\SupplierAttributeTypeL11n;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class SupplierAttributeTypeL11nTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private SupplierAttributeTypeL11n $l11n;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->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()
|
||||
);
|
||||
}
|
||||
}
|
||||
82
tests/Models/SupplierAttributeTypeTest.php
Normal file
82
tests/Models/SupplierAttributeTypeTest.php
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
<?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\SupplierManagement\tests\Models;
|
||||
|
||||
use Modules\SupplierManagement\Models\SupplierAttributeType;
|
||||
use Modules\SupplierManagement\Models\SupplierAttributeTypeL11n;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class SupplierAttributeTypeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private SupplierAttributeType $type;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->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()
|
||||
);
|
||||
}
|
||||
}
|
||||
133
tests/Models/SupplierAttributeValueTest.php
Normal file
133
tests/Models/SupplierAttributeValueTest.php
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
<?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\SupplierManagement\tests\Models;
|
||||
|
||||
use Modules\SupplierManagement\Models\SupplierAttributeValue;
|
||||
use phpOMS\Localization\ISO3166TwoEnum;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class SupplierAttributeValueTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private SupplierAttributeValue $value;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->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()
|
||||
);
|
||||
}
|
||||
}
|
||||
137
tests/Models/SupplierTest.php
Normal file
137
tests/Models/SupplierTest.php
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
<?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\SupplierManagement\tests\Models;
|
||||
|
||||
use Modules\Editor\Models\EditorDoc;
|
||||
use Modules\Media\Models\Media;
|
||||
use Modules\Profile\Models\ContactElement;
|
||||
use Modules\SupplierManagement\Models\Supplier;
|
||||
use Modules\SupplierManagement\Models\SupplierStatus;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class SupplierTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private Supplier $supplier;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->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()
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user