mirror of
https://github.com/Karaka-Management/oms-Support.git
synced 2026-01-11 17:18:40 +00:00
cs fixes, bug fixes, code coverage
This commit is contained in:
parent
128bfbd93a
commit
a629fcacdb
|
|
@ -16,13 +16,13 @@ use phpOMS\Uri\UriFactory;
|
|||
|
||||
?>
|
||||
<header>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="<?= UriFactory::build('{/app}'); ?>">Website</a>
|
||||
<li><a href="<?= UriFactory::build('{/app}/components'); ?>">Profile</a>
|
||||
</ul>
|
||||
</nav>
|
||||
<div id="search">
|
||||
<input type="text">
|
||||
</div>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="<?= UriFactory::build('{/app}'); ?>">Website</a>
|
||||
<li><a href="<?= UriFactory::build('{/app}/components'); ?>">Profile</a>
|
||||
</ul>
|
||||
</nav>
|
||||
<div id="search">
|
||||
<input type="text">
|
||||
</div>
|
||||
</header>
|
||||
|
|
@ -40,7 +40,6 @@ use phpOMS\Message\NotificationLevel;
|
|||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
use phpOMS\Model\Message\FormValidation;
|
||||
use phpOMS\Utils\Parser\Markdown\Markdown;
|
||||
|
||||
/**
|
||||
* Api controller for the tickets module.
|
||||
|
|
@ -294,7 +293,7 @@ final class ApiController extends Controller
|
|||
public function apiTicketElementSet(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
$old = clone TicketElementMapper::get((int) $request->getData('id'));
|
||||
$new = $this->updateTicketElementFromRequest($request);
|
||||
$new = $this->updateTicketElementFromRequest($request, $response);
|
||||
$this->updateModel($request->header->account, $old, $new, TicketElementMapper::class, 'ticketelement', $request->getOrigin());
|
||||
|
||||
//$this->updateModel($request->header->account, $ticket, $ticket, TicketMapper::class, 'ticket', $request->getOrigin());
|
||||
|
|
@ -310,31 +309,12 @@ final class ApiController extends Controller
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function updateTicketElementFromRequest(RequestAbstract $request) : TicketElementMapper
|
||||
private function updateTicketElementFromRequest(RequestAbstract $request, ResponseAbstract $response) : TicketElementMapper
|
||||
{
|
||||
$element = TicketElementMapper::get((int) ($request->getData('id')));
|
||||
$element->taskElement->due = new \DateTime((string) ($request->getData('due') ?? $element->getDue()->format('Y-m-d H:i:s')));
|
||||
$element->taskElement->description = Markdown::parse((string) ($request->getData('plain') ?? $element->taskElement->descriptionRaw));
|
||||
$element->taskElement->descriptionRaw = (string) ($request->getData('plain') ?? $element->taskElement->descriptionRaw);
|
||||
$element->taskElement->setStatus((int) ($request->getData('status') ?? $element->taskElement->getStatus()));
|
||||
$element = TicketElementMapper::get((int) ($request->getData('id')));
|
||||
|
||||
$tos = $request->getData('to') ?? $request->header->account;
|
||||
if (!\is_array($tos)) {
|
||||
$tos = [$tos];
|
||||
}
|
||||
|
||||
$ccs = $request->getData('cc') ?? [];
|
||||
if (!\is_array($ccs)) {
|
||||
$ccs = [$ccs];
|
||||
}
|
||||
|
||||
foreach ($tos as $to) {
|
||||
$element->taskElement->addTo($to);
|
||||
}
|
||||
|
||||
foreach ($ccs as $cc) {
|
||||
$element->taskElement->addCC($cc);
|
||||
}
|
||||
$request->setData('id', $element->task, true);
|
||||
$this->app->moduleManager->get('Tasks')->apiTaskElementSet($request, $response);
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
|
@ -517,8 +497,8 @@ final class ApiController extends Controller
|
|||
*/
|
||||
private function createTicketAttributeTypeL11nFromRequest(RequestAbstract $request) : TicketAttributeTypeL11n
|
||||
{
|
||||
$attrL11n = new TicketAttributeTypeL11n();
|
||||
$attrL11n->setType((int) ($request->getData('type') ?? 0));
|
||||
$attrL11n = new TicketAttributeTypeL11n();
|
||||
$attrL11n->type = (int) ($request->getData('type') ?? 0);
|
||||
$attrL11n->setLanguage((string) (
|
||||
$request->getData('language') ?? $request->getLanguage()
|
||||
));
|
||||
|
|
@ -571,7 +551,6 @@ final class ApiController extends Controller
|
|||
}
|
||||
|
||||
$attrType = $this->createTicketAttributeTypeFromRequest($request);
|
||||
$attrType->setL11n($request->getData('title'), $request->getData('language'));
|
||||
$this->createModel($request->header->account, $attrType, TicketAttributeTypeMapper::class, 'attr_type', $request->getOrigin());
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute type', 'Attribute type successfully created', $attrType);
|
||||
|
|
@ -589,9 +568,9 @@ final class ApiController extends Controller
|
|||
private function createTicketAttributeTypeFromRequest(RequestAbstract $request) : TicketAttributeType
|
||||
{
|
||||
$attrType = new TicketAttributeType();
|
||||
$attrType->name = (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;
|
||||
}
|
||||
|
|
@ -608,8 +587,7 @@ final class ApiController extends Controller
|
|||
private function validateTicketAttributeTypeCreate(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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ final class NullTicketAttribute extends TicketAttribute
|
|||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->id = $id;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -208,4 +208,27 @@ class Ticket
|
|||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function toArray() : array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'task' => $this->task,
|
||||
'app' => $this->app,
|
||||
'for' => $this->for,
|
||||
'ticketElements' => $this->ticketElements,
|
||||
'attributes' => $this->attributes,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,6 +58,17 @@ class TicketAttribute implements \JsonSerializable, ArrayableInterface
|
|||
*/
|
||||
public TicketAttributeValue $value;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->type = new TicketAttributeType();
|
||||
$this->value = new TicketAttributeValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
|
|
@ -75,7 +86,12 @@ class TicketAttribute implements \JsonSerializable, ArrayableInterface
|
|||
*/
|
||||
public function toArray() : array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'ticket' => $this->ticket,
|
||||
'type' => $this->type,
|
||||
'value' => $this->value,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class TicketAttributeType 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 TicketAttributeType implements \JsonSerializable, ArrayableInterface
|
|||
* @var bool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected bool $custom = false;
|
||||
public bool $custom = false;
|
||||
|
||||
public string $validationPattern = '';
|
||||
|
||||
|
|
@ -66,9 +66,9 @@ class TicketAttributeType implements \JsonSerializable, ArrayableInterface
|
|||
/**
|
||||
* Localization
|
||||
*
|
||||
* @var TicketAttributeTypeL11n
|
||||
* @var string | TicketAttributeTypeL11n
|
||||
*/
|
||||
protected string|TicketAttributeTypeL11n $l11n;
|
||||
protected string | TicketAttributeTypeL11n $l11n;
|
||||
|
||||
/**
|
||||
* Possible default attribute values
|
||||
|
|
@ -134,40 +134,19 @@ class TicketAttributeType implements \JsonSerializable, ArrayableInterface
|
|||
return $this->l11n instanceof TicketAttributeTypeL11n ? $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 TicketAttributeTypeL11n implements \JsonSerializable, ArrayableInterface
|
|||
* @var int|TicketAttributeType
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected int|TicketAttributeType $type = 0;
|
||||
public int | TicketAttributeType $type = 0;
|
||||
|
||||
/**
|
||||
* Language.
|
||||
|
|
@ -88,29 +88,15 @@ class TicketAttributeTypeL11n implements \JsonSerializable, ArrayableInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Get attribute type
|
||||
* Get language
|
||||
*
|
||||
* @return int|TicketAttributeType
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getType() : int | TicketAttributeType
|
||||
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 TicketAttributeTypeL11n implements \JsonSerializable, ArrayableInterface
|
|||
*/
|
||||
public function toArray() : array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'type' => $this->type,
|
||||
'language' => $this->language,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use phpOMS\Localization\ISO639x1Enum;
|
|||
/**
|
||||
* Ticket attribute value class.
|
||||
*
|
||||
* The relation with the type/ticket is defined in the TicketAttribute class.
|
||||
* The relation with the type/supplier is defined in the TicketAttribute class.
|
||||
*
|
||||
* @package Modules\Support\Models
|
||||
* @license OMS License 1.0
|
||||
|
|
@ -189,6 +189,18 @@ class TicketAttributeValue 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 TicketAttributeValue 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,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -87,7 +87,12 @@ class TicketElement implements \JsonSerializable
|
|||
*/
|
||||
public function toArray() : array
|
||||
{
|
||||
return $this->taskElement->toArray();
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'time' => $this->time,
|
||||
'ticket' => $this->ticket,
|
||||
'taskElement' => $this->taskElement,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ use Modules\Tasks\Models\TaskStatus;
|
|||
use phpOMS\Uri\UriFactory;
|
||||
|
||||
/**
|
||||
* @var \phpOMS\Views\View $this
|
||||
* @var \Modules\Support\Models\Ticket $ticket
|
||||
* @var \Modules\Support\Vies\TicketView $this
|
||||
* @var \Modules\Support\Models\Ticket $ticket
|
||||
*/
|
||||
$ticket = $this->getData('ticket');
|
||||
$task = $ticket->task;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Support\Views;
|
||||
|
||||
use Modules\Media\Models\Media;
|
||||
use Modules\Media\Models\NullMedia;
|
||||
use Modules\Profile\Models\ProfileMapper;
|
||||
use Modules\Tasks\Models\TaskStatus;
|
||||
use phpOMS\Uri\UriFactory;
|
||||
|
|
@ -29,6 +31,24 @@ use phpOMS\Views\View;
|
|||
*/
|
||||
class TicketView extends View
|
||||
{
|
||||
/**
|
||||
* User profile image.
|
||||
*
|
||||
* @var Media
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public Media $defaultProfileImage;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->defaultProfileImage = new NullMedia();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the profile image
|
||||
*
|
||||
|
|
@ -44,11 +64,11 @@ class TicketView extends View
|
|||
{
|
||||
$profile = ProfileMapper::getFor($account, 'account');
|
||||
|
||||
if ($profile === null || $profile->image->getPath() === '') {
|
||||
return UriFactory::build('Web/Backend/img/user_default_' . \mt_rand(1, 6) . '.png');
|
||||
if (($profile instanceof NullProfile) || $profile->image->getPath() === '') {
|
||||
return UriFactory::build('{/prefix}' . $this->defaultProfileImage->getPath());
|
||||
}
|
||||
|
||||
return UriFactory::build($profile->image->getPath());
|
||||
return UriFactory::build('{/prefix}' . $profile->image->getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
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\Support\tests\Controller\Api;
|
||||
|
||||
use Modules\Support\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\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketAttributeTypeCreate() : 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->apiTicketAttributeTypeCreate($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketAttributeTypeL11nCreate() : 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->apiTicketAttributeTypeL11nCreate($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketAttributeValueIntCreate() : 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->apiTicketAttributeValueCreate($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketAttributeValueStrCreate() : 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->apiTicketAttributeValueCreate($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketAttributeValueFloatCreate() : 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->apiTicketAttributeValueCreate($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketAttributeValueDatCreate() : 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->apiTicketAttributeValueCreate($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketAttributeCreate() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('ticket', '1');
|
||||
$request->setData('value', '1');
|
||||
$request->setData('type', '1');
|
||||
|
||||
$this->module->apiTicketAttributeCreate($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketAttributeValueCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiTicketAttributeValueCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketAttributeTypeCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiTicketAttributeTypeCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketAttributeTypeL11nCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiTicketAttributeTypeL11nCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketAttributeCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiTicketAttributeCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
}
|
||||
158
tests/Controller/Api/ApiControllerTicketTrait.php
Normal file
158
tests/Controller/Api/ApiControllerTicketTrait.php
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
<?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\Support\tests\Controller\Api;
|
||||
|
||||
use Modules\Tasks\Models\TaskStatus;
|
||||
use phpOMS\Message\Http\HttpRequest;
|
||||
use phpOMS\Message\Http\HttpResponse;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
use phpOMS\Uri\HttpUri;
|
||||
|
||||
trait ApiControllerTicketTrait
|
||||
{
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiSupportAppCreate() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('name', 'TestSupportApp');
|
||||
|
||||
$this->module->apiSupportAppCreate($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiSupportAppCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiSupportAppCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketCreate() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('title', 'Test Ticket');
|
||||
$request->setData('plain', 'Test **content** here.');
|
||||
$request->setData('forward', '1');
|
||||
$request->setData('for', '1');
|
||||
|
||||
$this->module->apiTicketCreate($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketGet() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('id', '1');
|
||||
|
||||
$this->module->apiTicketGet($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiTicketCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketElementCreate() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('ticket', '1');
|
||||
$request->setData('time', '10');
|
||||
$request->setData('status', TaskStatus::WORKING);
|
||||
$request->setData('due', (new \DateTime('now'))->format('Y-m-d H:i:s'));
|
||||
|
||||
$this->module->apiTicketElementCreate($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketElementGet() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('id', '1');
|
||||
|
||||
$this->module->apiTicketElementGet($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiTicketElementCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiTicketElementCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
}
|
||||
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\Support\tests\Controller;
|
||||
|
||||
use Model\CoreSettings;
|
||||
use Modules\Admin\Models\AccountPermission;
|
||||
use Modules\Support\tests\Controller\Api\ApiControllerAttributeTrait;
|
||||
use Modules\Support\tests\Controller\Api\ApiControllerTicketTrait;
|
||||
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\Support\tests\Controller\ApiControllerTest: Support api controller
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected ApplicationAbstract $app;
|
||||
|
||||
/**
|
||||
* @var \Modules\Support\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('Support');
|
||||
|
||||
TestUtils::setMember($this->module, 'app', $this->app);
|
||||
}
|
||||
|
||||
use ApiControllerTicketTrait;
|
||||
use ApiControllerAttributeTrait;
|
||||
}
|
||||
62
tests/Models/SupportAppTest.php
Normal file
62
tests/Models/SupportAppTest.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?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\Support\tests\Models;
|
||||
|
||||
use Modules\Support\Models\SupportApp;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class SupportAppTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private SupportApp $app;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->app = new SupportApp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\SupportApp
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertEquals(0, $this->app->getId());
|
||||
self::assertEquals('', $this->app->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\SupportApp
|
||||
* @group module
|
||||
*/
|
||||
public function testSerialize() : void
|
||||
{
|
||||
$this->app->name = 'Test Title';
|
||||
|
||||
$serialized = $this->app->jsonSerialize();
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
'id' => 0,
|
||||
'name' => 'Test Title',
|
||||
],
|
||||
$serialized
|
||||
);
|
||||
}
|
||||
}
|
||||
63
tests/Models/TicketAttributeTest.php
Normal file
63
tests/Models/TicketAttributeTest.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\Support\tests\Models;
|
||||
|
||||
use Modules\Support\Models\TicketAttribute;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class TicketAttributeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private TicketAttribute $attribute;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->attribute = new TicketAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketAttribute
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertEquals(0, $this->attribute->getId());
|
||||
self::assertInstanceOf('\Modules\Support\Models\TicketAttributeType', $this->attribute->type);
|
||||
self::assertInstanceOf('\Modules\Support\Models\TicketAttributeValue', $this->attribute->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketAttribute
|
||||
* @group module
|
||||
*/
|
||||
public function testSerialize() : void
|
||||
{
|
||||
$serialized = $this->attribute->jsonSerialize();
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
'id',
|
||||
'ticket',
|
||||
'type',
|
||||
'value',
|
||||
],
|
||||
\array_keys($serialized)
|
||||
);
|
||||
}
|
||||
}
|
||||
87
tests/Models/TicketAttributeTypeL11nTest.php
Normal file
87
tests/Models/TicketAttributeTypeL11nTest.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\Support\tests\Models;
|
||||
|
||||
use Modules\Support\Models\TicketAttributeTypeL11n;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class TicketAttributeTypeL11nTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private TicketAttributeTypeL11n $l11n;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->l11n = new TicketAttributeTypeL11n();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketAttributeTypeL11n
|
||||
* @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\Support\Models\TicketAttributeTypeL11n
|
||||
* @group module
|
||||
*/
|
||||
public function testNameInputOutput() : void
|
||||
{
|
||||
$this->l11n->title = 'TestName';
|
||||
self::assertEquals('TestName', $this->l11n->title);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketAttributeTypeL11n
|
||||
* @group module
|
||||
*/
|
||||
public function testLanguageInputOutput() : void
|
||||
{
|
||||
$this->l11n->setLanguage(ISO639x1Enum::_DE);
|
||||
self::assertEquals(ISO639x1Enum::_DE, $this->l11n->getLanguage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketAttributeTypeL11n
|
||||
* @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/TicketAttributeTypeTest.php
Normal file
82
tests/Models/TicketAttributeTypeTest.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\Support\tests\Models;
|
||||
|
||||
use Modules\Support\Models\TicketAttributeType;
|
||||
use Modules\Support\Models\TicketAttributeTypeL11n;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class TicketAttributeTypeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private TicketAttributeType $type;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->type = new TicketAttributeType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketAttributeType
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertEquals(0, $this->type->getId());
|
||||
self::assertEquals('', $this->type->getL11n());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketAttributeType
|
||||
* @group module
|
||||
*/
|
||||
public function testL11nInputOutput() : void
|
||||
{
|
||||
$this->type->setL11n('Test');
|
||||
self::assertEquals('Test', $this->type->getL11n());
|
||||
|
||||
$this->type->setL11n(new TicketAttributeTypeL11n(0, 'NewTest'));
|
||||
self::assertEquals('NewTest', $this->type->getL11n());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketAttributeType
|
||||
* @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/TicketAttributeValueTest.php
Normal file
133
tests/Models/TicketAttributeValueTest.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\Support\tests\Models;
|
||||
|
||||
use Modules\Support\Models\TicketAttributeValue;
|
||||
use phpOMS\Localization\ISO3166TwoEnum;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class TicketAttributeValueTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private TicketAttributeValue $value;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->value = new TicketAttributeValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketAttributeValue
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertEquals(0, $this->value->getId());
|
||||
self::assertNull($this->value->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketAttributeValue
|
||||
* @group module
|
||||
*/
|
||||
public function testLanguageInputOutput() : void
|
||||
{
|
||||
$this->value->setLanguage(ISO639x1Enum::_DE);
|
||||
self::assertEquals(ISO639x1Enum::_DE, $this->value->getLanguage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketAttributeValue
|
||||
* @group module
|
||||
*/
|
||||
public function testCountryInputOutput() : void
|
||||
{
|
||||
$this->value->setCountry(ISO3166TwoEnum::_DEU);
|
||||
self::assertEquals(ISO3166TwoEnum::_DEU, $this->value->getCountry());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketAttributeValue
|
||||
* @group module
|
||||
*/
|
||||
public function testValueIntInputOutput() : void
|
||||
{
|
||||
$this->value->setValue(1);
|
||||
self::assertEquals(1, $this->value->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketAttributeValue
|
||||
* @group module
|
||||
*/
|
||||
public function testValueFloatInputOutput() : void
|
||||
{
|
||||
$this->value->setValue(1.1);
|
||||
self::assertEquals(1.1, $this->value->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketAttributeValue
|
||||
* @group module
|
||||
*/
|
||||
public function testValueStringInputOutput() : void
|
||||
{
|
||||
$this->value->setValue('test');
|
||||
self::assertEquals('test', $this->value->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketAttributeValue
|
||||
* @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\Support\Models\TicketAttributeValue
|
||||
* @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()
|
||||
);
|
||||
}
|
||||
}
|
||||
66
tests/Models/TicketElementTest.php
Normal file
66
tests/Models/TicketElementTest.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?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\Support\tests\Models;
|
||||
|
||||
use Modules\Support\Models\TicketElement;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class TicketElementTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private TicketElement $element;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->element = new TicketElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketElement
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertEquals(0, $this->element->getId());
|
||||
self::assertEquals(0, $this->element->time);
|
||||
self::assertEquals(0, $this->element->ticket);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\TicketElement
|
||||
* @group module
|
||||
*/
|
||||
public function testSerialize() : void
|
||||
{
|
||||
$this->element->time = 10;
|
||||
$this->element->ticket = 2;
|
||||
|
||||
$serialized = $this->element->jsonSerialize();
|
||||
unset($serialized['taskElement']);
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
'id' => 0,
|
||||
'time' => 10,
|
||||
'ticket' => 2,
|
||||
],
|
||||
$serialized
|
||||
);
|
||||
}
|
||||
}
|
||||
118
tests/Models/TicketTest.php
Normal file
118
tests/Models/TicketTest.php
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
<?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\Support\tests\Models;
|
||||
|
||||
use Modules\Support\Models\Ticket;
|
||||
use Modules\Support\Models\TicketAttribute;
|
||||
use Modules\Support\Models\TicketElement;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class TicketTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private Ticket $ticket;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->ticket = new Ticket();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\Ticket
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertEquals(0, $this->ticket->getId());
|
||||
self::assertNull($this->ticket->for);
|
||||
self::assertEquals([], $this->ticket->getTicketElements());
|
||||
self::assertEquals([], $this->ticket->getAttributes());
|
||||
self::assertInstanceOf('\Modules\Tasks\Models\Task', $this->ticket->task);
|
||||
self::assertInstanceOf('\Modules\Support\Models\TicketElement', $this->ticket->getTicketElement(999));
|
||||
self::assertInstanceOf('\Modules\Support\Models\SupportApp', $this->ticket->app);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\Ticket
|
||||
* @group module
|
||||
*/
|
||||
public function testElementInputOutput() : void
|
||||
{
|
||||
$element1 = new TicketElement();
|
||||
$element1->description = '1';
|
||||
|
||||
$element2 = new TicketElement();
|
||||
$element2->description = '2';
|
||||
|
||||
self::assertEquals(0, $this->ticket->addElement($element1));
|
||||
self::assertEquals(1, $this->ticket->addElement($element2));
|
||||
self::assertCount(2, $this->ticket->getTicketElements());
|
||||
self::assertEquals($element1, $this->ticket->getTicketElement(0));
|
||||
self::assertEquals([$element2, $element1], $this->ticket->invertTicketElements());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\Ticket
|
||||
* @group module
|
||||
*/
|
||||
public function testElementRemove() : void
|
||||
{
|
||||
$element1 = new TicketElement();
|
||||
$element1->description = '1';
|
||||
|
||||
$this->ticket->addElement($element1);
|
||||
self::assertCount(1, $this->ticket->getTicketElements());
|
||||
self::assertTrue($this->ticket->removeElement(0));
|
||||
self::assertCount(0, $this->ticket->getTicketElements());
|
||||
self::assertFalse($this->ticket->removeElement(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\Ticket
|
||||
* @group module
|
||||
*/
|
||||
public function testAttributeInputOutput() : void
|
||||
{
|
||||
$attr = new TicketAttribute();
|
||||
$this->ticket->addAttribute($attr);
|
||||
|
||||
self::assertCount(1, $this->ticket->getAttributes());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Models\Ticket
|
||||
* @group module
|
||||
*/
|
||||
public function testSerialize() : void
|
||||
{
|
||||
$serialized = $this->ticket->jsonSerialize();
|
||||
unset($serialized['task']);
|
||||
unset($serialized['app']);
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
'id' => 0,
|
||||
'for' => null,
|
||||
'ticketElements' => [],
|
||||
'attributes' => [],
|
||||
],
|
||||
$serialized
|
||||
);
|
||||
}
|
||||
}
|
||||
45
tests/Views/TicketViewTest.php
Normal file
45
tests/Views/TicketViewTest.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?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\Support\tests\Views;
|
||||
|
||||
use Modules\Support\Views\TicketView;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class TicketViewTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\Support\Views\TicketView
|
||||
* @group framework
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$view = new TicketView();
|
||||
|
||||
self::assertStringContainsString('', $view->getAccountImage(999));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\Support\Views\TicketView
|
||||
* @group framework
|
||||
*/
|
||||
public function testAccountImageUrl() : void
|
||||
{
|
||||
$view = new TicketView();
|
||||
|
||||
self::assertEquals('Web/Backend/img/default-user.jpg', $view->getAccountImage(1));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user