From 486dd41c9c95564ba70687ddc5584ef54d17607a Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 26 Jan 2024 22:54:00 +0000 Subject: [PATCH] auto fixes + some impl. --- Admin/Routes/Web/Backend.php | 10 +- Controller/ApiController.php | 36 ++--- Controller/BackendController.php | 2 +- Models/SurveyAnswer.php | 21 --- Models/SurveyTemplate.php | 124 +----------------- Models/SurveyTemplateElement.php | 26 +--- Models/SurveyTemplateElementL11n.php | 12 +- Models/SurveyTemplateElementL11nMapper.php | 12 +- Models/SurveyTemplateElementMapper.php | 30 ++--- Models/SurveyTemplateL11n.php | 12 +- Models/SurveyTemplateL11nMapper.php | 16 +-- Models/SurveyTemplateLabelL11n.php | 10 +- Models/SurveyTemplateLabelL11nMapper.php | 10 +- Models/SurveyTemplateMapper.php | 40 +++--- Theme/Backend/Lang/de.lang.php | 8 +- Theme/Backend/Lang/en.lang.php | 8 +- Theme/Backend/surveys-create.tpl.php | 20 +-- Theme/Backend/surveys-list.tpl.php | 2 +- tests/Autoloader.php | 4 +- tests/Bootstrap.php | 71 +++++----- tests/Controller/ApiControllerTest.php | 27 ++-- .../Models/SurveyTemplateElementL11nTest.php | 24 +--- tests/Models/SurveyTemplateElementTest.php | 20 +-- tests/Models/SurveyTemplateL11nTest.php | 24 +--- tests/Models/SurveyTemplateLabelL11nTest.php | 28 ++-- tests/Models/SurveyTemplateTest.php | 66 +--------- 26 files changed, 210 insertions(+), 453 deletions(-) diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php index 50fff94..0336374 100755 --- a/Admin/Routes/Web/Backend.php +++ b/Admin/Routes/Web/Backend.php @@ -18,7 +18,7 @@ use phpOMS\Account\PermissionType; use phpOMS\Router\RouteVerb; return [ - '^.*/survey.*$' => [ + '^.*/survey(\?.*$|$)' => [ [ 'dest' => '\Modules\Surveys\Controller\BackendController:setUpBackend', 'verb' => RouteVerb::GET, @@ -29,7 +29,7 @@ return [ ], ], ], - '^.*/survey/list.*$' => [ + '^.*/survey/list(\?.*$|$)' => [ [ 'dest' => '\Modules\Surveys\Controller\BackendController:viewSurveysList', 'verb' => RouteVerb::GET, @@ -40,7 +40,7 @@ return [ ], ], ], - '^.*/survey/create.*$' => [ + '^.*/survey/create(\?.*$|$)' => [ [ 'dest' => '\Modules\Surveys\Controller\BackendController:viewSurveysCreate', 'verb' => RouteVerb::GET, @@ -51,7 +51,7 @@ return [ ], ], ], - '^.*/survey/edit.*$' => [ + '^.*/survey/edit(\?.*$|$)' => [ [ 'dest' => '\Modules\Surveys\Controller\BackendController:viewSurveysEdit', 'verb' => RouteVerb::GET, @@ -62,7 +62,7 @@ return [ ], ], ], - '^.*/survey(\?.*|$)$' => [ + '^.*/survey(\?.*$|$)' => [ [ 'dest' => '\Modules\Surveys\Controller\BackendController:viewSurveysSurvey', 'verb' => RouteVerb::GET, diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 3a92c57..33baf82 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -26,9 +26,7 @@ use Modules\Surveys\Models\SurveyTemplateElementMapper; use Modules\Surveys\Models\SurveyTemplateL11n; use Modules\Surveys\Models\SurveyTemplateLabelL11n; use Modules\Surveys\Models\SurveyTemplateMapper; -use Modules\Tag\Models\NullTag; use phpOMS\Localization\ISO639x1Enum; -use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; @@ -105,38 +103,20 @@ final class ApiController extends Controller $template = new SurveyTemplate(); $template->start = $request->getDataDateTime('start'); $template->end = $request->getDataDateTime('end'); - $template->status = $request->getDataInt('status') ?? SurveyStatus::ACTIVE; + $template->status = SurveyStatus::tryFromValue($request->getDataInt('status')) ?? SurveyStatus::ACTIVE; $template->createdBy = new NullAccount($request->header->account); $l11n = new SurveyTemplateL11n( $request->getDataString('title') ?? '', Markdown::parse($request->getDataString('description') ?? ''), $request->getDataString('description') ?? '', - $request->getDataString('language') ?? ISO639x1Enum::_EN + ISO639x1Enum::tryFromValue($request->getDataString('language')) ?? ISO639x1Enum::_EN ); $template->setL11n($l11n); - if (!empty($tags = $request->getDataJson('tags'))) { - foreach ($tags as $tag) { - if (!isset($tag['id'])) { - $request->setData('title', $tag['title'], true); - $request->setData('color', $tag['color'], true); - $request->setData('icon', $tag['icon'] ?? null, true); - $request->setData('language', $tag['language'], true); - - $internalResponse = new HttpResponse(); - $this->app->moduleManager->get('Tag')->apiTagCreate($request, $internalResponse); - - if (!\is_array($data = $internalResponse->getDataArray($request->uri->__toString()))) { - continue; - } - - $template->addTag($data['response']); - } else { - $template->addTag(new NullTag((int) $tag['id'])); - } - } + if ($request->hasData('tags')) { + $template->tags = $this->app->moduleManager->get('Tag', 'Api')->createTagsFromRequest($request); } if (!empty($uploadedFiles = $request->files)) { @@ -150,13 +130,13 @@ final class ApiController extends Controller ); foreach ($uploaded as $media) { - $template->addMedia($media); + $template->files[] = $media; } } if (!empty($mediaFiles = $request->getDataJson('media'))) { foreach ($mediaFiles as $media) { - $template->addMedia(new NullMedia($media)); + $template->files[] = new NullMedia($media); } } @@ -235,7 +215,7 @@ final class ApiController extends Controller $request->getDataString('text') ?? '', Markdown::parse($request->getDataString('description') ?? ''), $request->getDataString('description') ?? '', - $request->getDataString('language') ?? ISO639x1Enum::_EN + ISO639x1Enum::tryFromValue($request->getDataString('language')) ?? ISO639x1Enum::_EN ); $element->setL11n($l11n); @@ -244,7 +224,7 @@ final class ApiController extends Controller foreach ($labels as $text) { $label = new SurveyTemplateLabelL11n( $text, - $request->getDataString('language') ?? ISO639x1Enum::_EN + ISO639x1Enum::tryFromValue($request->getDataString('language')) ?? ISO639x1Enum::_EN ); $element->addLabel($label); diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 6f63c2c..f2903eb 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -131,7 +131,7 @@ final class BackendController extends Controller ->with('elements') ->with('elements/l11n') ->with('elements/labels') - ->with('media') + ->with('files') ->with('l11n') ->with('tags') ->with('tags/title') diff --git a/Models/SurveyAnswer.php b/Models/SurveyAnswer.php index 412763c..72ca7b5 100755 --- a/Models/SurveyAnswer.php +++ b/Models/SurveyAnswer.php @@ -31,25 +31,4 @@ final class SurveyAnswer * @since 1.0.0 */ public int $id = 0; - - /** - * Constructor - * - * @since 1.0.0 - */ - public function __construct() - { - } - - /** - * Get id. - * - * @return int - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } } diff --git a/Models/SurveyTemplate.php b/Models/SurveyTemplate.php index 48d0f88..4e3ea94 100755 --- a/Models/SurveyTemplate.php +++ b/Models/SurveyTemplate.php @@ -15,8 +15,6 @@ declare(strict_types=1); namespace Modules\Surveys\Models; use Modules\Admin\Models\Account; -use Modules\Media\Models\Media; -use Modules\Tag\Models\NullTag; use Modules\Tag\Models\Tag; use phpOMS\Localization\ISO639x1Enum; @@ -120,14 +118,6 @@ class SurveyTemplate */ public array $elements = []; - /** - * Media files - * - * @var Media[] - * @since 1.0.0 - */ - public array $media = []; - /** * Constructor. * @@ -138,18 +128,6 @@ class SurveyTemplate $this->createdAt = new \DateTimeImmutable('now'); } - /** - * Get id. - * - * @return int - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } - /** * @return SurveyTemplateL11n * @@ -175,104 +153,6 @@ class SurveyTemplate $this->l11n = $l11n; } - /** - * Get tags - * - * @return array - * - * @since 1.0.0 - */ - public function getTags() : array - { - return $this->tags; - } - - /** - * Get tag. - * - * @param int $id Element id - * - * @return Tag - * - * @since 1.0.0 - */ - public function getTag(int $id) : Tag - { - return $this->tags[$id] ?? new NullTag(); - } - - /** - * Add tag - * - * @param Tag $tag Tag - * - * @return void - * - * @since 1.0.0 - */ - public function addTag(Tag $tag) : void - { - $this->tags[] = $tag; - } - - /** - * Remove Tag from list. - * - * @param int $id Tag - * - * @return bool - * - * @since 1.0.0 - */ - public function removeTag($id) : bool - { - if (isset($this->tags[$id])) { - unset($this->tags[$id]); - - return true; - } - - return false; - } - - /** - * Get all media - * - * @return Media[] - * - * @since 1.0.0 - */ - public function getMedia() : array - { - return $this->media; - } - - /** - * Add media - * - * @param Media $media Media to add - * - * @return void - * - * @since 1.0.0 - */ - public function addMedia(Media $media) : void - { - $this->media[] = $media; - } - - /** - * Get elements - * - * @return array - * - * @since 1.0.0 - */ - public function getElements() : array - { - return $this->elements; - } - /** * Add element * @@ -302,7 +182,7 @@ class SurveyTemplate 'virtualPath' => $this->virtualPath, 'tags' => $this->tags, 'elements' => $this->elements, - 'media' => $this->media, + 'media' => $this->files, ]; } @@ -313,4 +193,6 @@ class SurveyTemplate { return $this->toArray(); } + + use \Modules\Media\Models\MediaListTrait; } diff --git a/Models/SurveyTemplateElement.php b/Models/SurveyTemplateElement.php index 8fe95da..ac92eae 100755 --- a/Models/SurveyTemplateElement.php +++ b/Models/SurveyTemplateElement.php @@ -90,18 +90,6 @@ class SurveyTemplateElement */ public array $values = []; - /** - * Get id. - * - * @return int - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } - /** * @return SurveyTemplateElementL11n * @@ -177,13 +165,13 @@ class SurveyTemplateElement public function toArray() : array { return [ - 'id' => $this->id, - 'type' => $this->type, - 'isOptional' => $this->isOptional, - 'order' => $this->order, - 'template' => $this->template, - 'labels' => $this->labels, - 'values' => $this->values, + 'id' => $this->id, + 'type' => $this->type, + 'isOptional' => $this->isOptional, + 'order' => $this->order, + 'template' => $this->template, + 'labels' => $this->labels, + 'values' => $this->values, ]; } diff --git a/Models/SurveyTemplateElementL11n.php b/Models/SurveyTemplateElementL11n.php index d15241f..47d57f7 100755 --- a/Models/SurveyTemplateElementL11n.php +++ b/Models/SurveyTemplateElementL11n.php @@ -124,12 +124,12 @@ class SurveyTemplateElementL11n implements \JsonSerializable public function toArray() : array { return [ - 'id' => $this->id, - 'text' => $this->text, - 'description' => $this->description, - 'descriptionPlain' => $this->descriptionPlain, - 'element' => $this->element, - 'language' => $this->language, + 'id' => $this->id, + 'text' => $this->text, + 'description' => $this->description, + 'descriptionPlain' => $this->descriptionPlain, + 'element' => $this->element, + 'language' => $this->language, ]; } diff --git a/Models/SurveyTemplateElementL11nMapper.php b/Models/SurveyTemplateElementL11nMapper.php index 8aebd85..d2d6fb3 100755 --- a/Models/SurveyTemplateElementL11nMapper.php +++ b/Models/SurveyTemplateElementL11nMapper.php @@ -33,12 +33,12 @@ final class SurveyTemplateElementL11nMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'survey_template_element_l11n_id' => ['name' => 'survey_template_element_l11n_id', 'type' => 'int', 'internal' => 'id'], - 'survey_template_element_l11n_text' => ['name' => 'survey_template_element_l11n_text', 'type' => 'string', 'internal' => 'text', 'autocomplete' => true], - 'survey_template_element_l11n_description' => ['name' => 'survey_template_element_l11n_description', 'type' => 'string', 'internal' => 'description'], - 'survey_template_element_l11n_description_plain' => ['name' => 'survey_template_element_l11n_description_plain', 'type' => 'string', 'internal' => 'descriptionPlain'], - 'survey_template_element_l11n_element' => ['name' => 'survey_template_element_l11n_element', 'type' => 'int', 'internal' => 'element'], - 'survey_template_element_l11n_language' => ['name' => 'survey_template_element_l11n_language', 'type' => 'string', 'internal' => 'language'], + 'survey_template_element_l11n_id' => ['name' => 'survey_template_element_l11n_id', 'type' => 'int', 'internal' => 'id'], + 'survey_template_element_l11n_text' => ['name' => 'survey_template_element_l11n_text', 'type' => 'string', 'internal' => 'text', 'autocomplete' => true], + 'survey_template_element_l11n_description' => ['name' => 'survey_template_element_l11n_description', 'type' => 'string', 'internal' => 'description'], + 'survey_template_element_l11n_description_plain' => ['name' => 'survey_template_element_l11n_description_plain', 'type' => 'string', 'internal' => 'descriptionPlain'], + 'survey_template_element_l11n_element' => ['name' => 'survey_template_element_l11n_element', 'type' => 'int', 'internal' => 'element'], + 'survey_template_element_l11n_language' => ['name' => 'survey_template_element_l11n_language', 'type' => 'string', 'internal' => 'language'], ]; /** diff --git a/Models/SurveyTemplateElementMapper.php b/Models/SurveyTemplateElementMapper.php index 44c8407..dd51e6a 100755 --- a/Models/SurveyTemplateElementMapper.php +++ b/Models/SurveyTemplateElementMapper.php @@ -36,12 +36,12 @@ final class SurveyTemplateElementMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'survey_template_element_id' => ['name' => 'survey_template_element_id', 'type' => 'int', 'internal' => 'id'], - 'survey_template_element_type' => ['name' => 'survey_template_element_type', 'type' => 'int', 'internal' => 'type'], - 'survey_template_element_order' => ['name' => 'survey_template_element_order', 'type' => 'int', 'internal' => 'order'], - 'survey_template_element_optional' => ['name' => 'survey_template_element_optional', 'type' => 'bool', 'internal' => 'isOptional'], - 'survey_template_element_values' => ['name' => 'survey_template_element_values', 'type' => 'Json', 'internal' => 'values'], - 'survey_template_element_template' => ['name' => 'survey_template_element_template', 'type' => 'int', 'internal' => 'template'], + 'survey_template_element_id' => ['name' => 'survey_template_element_id', 'type' => 'int', 'internal' => 'id'], + 'survey_template_element_type' => ['name' => 'survey_template_element_type', 'type' => 'int', 'internal' => 'type'], + 'survey_template_element_order' => ['name' => 'survey_template_element_order', 'type' => 'int', 'internal' => 'order'], + 'survey_template_element_optional' => ['name' => 'survey_template_element_optional', 'type' => 'bool', 'internal' => 'isOptional'], + 'survey_template_element_values' => ['name' => 'survey_template_element_values', 'type' => 'Json', 'internal' => 'values'], + 'survey_template_element_template' => ['name' => 'survey_template_element_template', 'type' => 'int', 'internal' => 'template'], ]; /** @@ -52,17 +52,17 @@ final class SurveyTemplateElementMapper extends DataMapperFactory */ public const HAS_MANY = [ 'l11n' => [ - 'mapper' => SurveyTemplateElementL11nMapper::class, - 'table' => 'survey_template_element_l11n', - 'self' => 'survey_template_element_l11n_element', - 'conditional' => true, - 'external' => null, + 'mapper' => SurveyTemplateElementL11nMapper::class, + 'table' => 'survey_template_element_l11n', + 'self' => 'survey_template_element_l11n_element', + 'conditional' => true, + 'external' => null, ], 'labels' => [ - 'mapper' => SurveyTemplateLabelL11nMapper::class, - 'table' => 'survey_template_element_label_l11n', - 'self' => 'survey_template_element_label_l11n_element', - 'external' => null, + 'mapper' => SurveyTemplateLabelL11nMapper::class, + 'table' => 'survey_template_element_label_l11n', + 'self' => 'survey_template_element_label_l11n_element', + 'external' => null, ], ]; diff --git a/Models/SurveyTemplateL11n.php b/Models/SurveyTemplateL11n.php index 25924c0..4eb7221 100755 --- a/Models/SurveyTemplateL11n.php +++ b/Models/SurveyTemplateL11n.php @@ -140,12 +140,12 @@ class SurveyTemplateL11n implements \JsonSerializable public function toArray() : array { return [ - 'id' => $this->id, - 'title' => $this->title, - 'description' => $this->description, - 'descriptionPlain' => $this->descriptionPlain, - 'template' => $this->template, - 'language' => $this->language, + 'id' => $this->id, + 'title' => $this->title, + 'description' => $this->description, + 'descriptionPlain' => $this->descriptionPlain, + 'template' => $this->template, + 'language' => $this->language, ]; } diff --git a/Models/SurveyTemplateL11nMapper.php b/Models/SurveyTemplateL11nMapper.php index 1e16ed7..8a662bb 100755 --- a/Models/SurveyTemplateL11nMapper.php +++ b/Models/SurveyTemplateL11nMapper.php @@ -36,14 +36,14 @@ final class SurveyTemplateL11nMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'survey_template_l11n_id' => ['name' => 'survey_template_l11n_id', 'type' => 'int', 'internal' => 'id'], - 'survey_template_l11n_title' => ['name' => 'survey_template_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], - 'survey_template_l11n_description' => ['name' => 'survey_template_l11n_description', 'type' => 'string', 'internal' => 'description'], - 'survey_template_l11n_description_plain' => ['name' => 'survey_template_l11n_description_plain', 'type' => 'string', 'internal' => 'descriptionPlain'], - 'survey_template_l11n_footer' => ['name' => 'survey_template_l11n_footer', 'type' => 'string', 'internal' => 'footer'], - 'survey_template_l11n_footer_plain' => ['name' => 'survey_template_l11n_footer_plain', 'type' => 'string', 'internal' => 'footerPlain'], - 'survey_template_l11n_template' => ['name' => 'survey_template_l11n_template', 'type' => 'int', 'internal' => 'template'], - 'survey_template_l11n_language' => ['name' => 'survey_template_l11n_language', 'type' => 'string', 'internal' => 'language'], + 'survey_template_l11n_id' => ['name' => 'survey_template_l11n_id', 'type' => 'int', 'internal' => 'id'], + 'survey_template_l11n_title' => ['name' => 'survey_template_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], + 'survey_template_l11n_description' => ['name' => 'survey_template_l11n_description', 'type' => 'string', 'internal' => 'description'], + 'survey_template_l11n_description_plain' => ['name' => 'survey_template_l11n_description_plain', 'type' => 'string', 'internal' => 'descriptionPlain'], + 'survey_template_l11n_footer' => ['name' => 'survey_template_l11n_footer', 'type' => 'string', 'internal' => 'footer'], + 'survey_template_l11n_footer_plain' => ['name' => 'survey_template_l11n_footer_plain', 'type' => 'string', 'internal' => 'footerPlain'], + 'survey_template_l11n_template' => ['name' => 'survey_template_l11n_template', 'type' => 'int', 'internal' => 'template'], + 'survey_template_l11n_language' => ['name' => 'survey_template_l11n_language', 'type' => 'string', 'internal' => 'language'], ]; /** diff --git a/Models/SurveyTemplateLabelL11n.php b/Models/SurveyTemplateLabelL11n.php index ea2757f..ed8b424 100755 --- a/Models/SurveyTemplateLabelL11n.php +++ b/Models/SurveyTemplateLabelL11n.php @@ -112,11 +112,11 @@ class SurveyTemplateLabelL11n implements \JsonSerializable public function toArray() : array { return [ - 'id' => $this->id, - 'title' => $this->title, - 'element' => $this->element, - 'order' => $this->order, - 'language' => $this->language, + 'id' => $this->id, + 'title' => $this->title, + 'element' => $this->element, + 'order' => $this->order, + 'language' => $this->language, ]; } diff --git a/Models/SurveyTemplateLabelL11nMapper.php b/Models/SurveyTemplateLabelL11nMapper.php index cf5652f..96995d6 100755 --- a/Models/SurveyTemplateLabelL11nMapper.php +++ b/Models/SurveyTemplateLabelL11nMapper.php @@ -36,11 +36,11 @@ final class SurveyTemplateLabelL11nMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'survey_template_element_label_l11n_id' => ['name' => 'survey_template_element_label_l11n_id', 'type' => 'int', 'internal' => 'id'], - 'survey_template_element_label_l11n_title' => ['name' => 'survey_template_element_label_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], - 'survey_template_element_label_l11n_element' => ['name' => 'survey_template_element_label_l11n_element', 'type' => 'int', 'internal' => 'element'], - 'survey_template_element_label_l11n_order' => ['name' => 'survey_template_element_label_l11n_order', 'type' => 'int', 'internal' => 'order'], - 'survey_template_element_label_l11n_language' => ['name' => 'survey_template_element_label_l11n_language', 'type' => 'string', 'internal' => 'language'], + 'survey_template_element_label_l11n_id' => ['name' => 'survey_template_element_label_l11n_id', 'type' => 'int', 'internal' => 'id'], + 'survey_template_element_label_l11n_title' => ['name' => 'survey_template_element_label_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], + 'survey_template_element_label_l11n_element' => ['name' => 'survey_template_element_label_l11n_element', 'type' => 'int', 'internal' => 'element'], + 'survey_template_element_label_l11n_order' => ['name' => 'survey_template_element_label_l11n_order', 'type' => 'int', 'internal' => 'order'], + 'survey_template_element_label_l11n_language' => ['name' => 'survey_template_element_label_l11n_language', 'type' => 'string', 'internal' => 'language'], ]; /** diff --git a/Models/SurveyTemplateMapper.php b/Models/SurveyTemplateMapper.php index 7318df6..f8671f9 100755 --- a/Models/SurveyTemplateMapper.php +++ b/Models/SurveyTemplateMapper.php @@ -40,14 +40,14 @@ final class SurveyTemplateMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'survey_template_id' => ['name' => 'survey_template_id', 'type' => 'int', 'internal' => 'id'], - 'survey_template_status' => ['name' => 'survey_template_status', 'type' => 'int', 'internal' => 'status'], - 'survey_template_public_result' => ['name' => 'survey_template_public_result', 'type' => 'bool', 'internal' => 'hasPublicResult'], - 'survey_template_start' => ['name' => 'survey_template_start', 'type' => 'DateTime', 'internal' => 'start'], - 'survey_template_end' => ['name' => 'survey_template_end', 'type' => 'DateTime', 'internal' => 'end'], - 'survey_template_virtual' => ['name' => 'survey_template_virtual', 'type' => 'string', 'internal' => 'virtualPath'], - 'survey_template_created_by' => ['name' => 'survey_template_created_by', 'type' => 'int', 'internal' => 'createdBy'], - 'survey_template_created_at' => ['name' => 'survey_template_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt'], + 'survey_template_id' => ['name' => 'survey_template_id', 'type' => 'int', 'internal' => 'id'], + 'survey_template_status' => ['name' => 'survey_template_status', 'type' => 'int', 'internal' => 'status'], + 'survey_template_public_result' => ['name' => 'survey_template_public_result', 'type' => 'bool', 'internal' => 'hasPublicResult'], + 'survey_template_start' => ['name' => 'survey_template_start', 'type' => 'DateTime', 'internal' => 'start'], + 'survey_template_end' => ['name' => 'survey_template_end', 'type' => 'DateTime', 'internal' => 'end'], + 'survey_template_virtual' => ['name' => 'survey_template_virtual', 'type' => 'string', 'internal' => 'virtualPath'], + 'survey_template_created_by' => ['name' => 'survey_template_created_by', 'type' => 'int', 'internal' => 'createdBy'], + 'survey_template_created_at' => ['name' => 'survey_template_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt'], ]; /** @@ -58,17 +58,17 @@ final class SurveyTemplateMapper extends DataMapperFactory */ public const HAS_MANY = [ 'elements' => [ - 'mapper' => SurveyTemplateElementMapper::class, - 'table' => 'survey_template_element', - 'self' => 'survey_template_element_template', - 'external' => null, + 'mapper' => SurveyTemplateElementMapper::class, + 'table' => 'survey_template_element', + 'self' => 'survey_template_element_template', + 'external' => null, ], 'l11n' => [ - 'mapper' => SurveyTemplateL11nMapper::class, - 'table' => 'survey_template_l11n', - 'self' => 'survey_template_l11n_template', - 'conditional' => true, - 'external' => null, + 'mapper' => SurveyTemplateL11nMapper::class, + 'table' => 'survey_template_l11n', + 'self' => 'survey_template_l11n_template', + 'conditional' => true, + 'external' => null, ], 'tags' => [ 'mapper' => TagMapper::class, @@ -76,7 +76,7 @@ final class SurveyTemplateMapper extends DataMapperFactory 'self' => 'survey_template_tag_dst', 'external' => 'survey_template_tag_src', ], - 'media' => [ + 'files' => [ 'mapper' => MediaMapper::class, 'table' => 'survey_template_media', 'external' => 'survey_template_media_dst', @@ -92,8 +92,8 @@ final class SurveyTemplateMapper extends DataMapperFactory */ public const BELONGS_TO = [ 'createdBy' => [ - 'mapper' => AccountMapper::class, - 'external' => 'survey_template_created_by', + 'mapper' => AccountMapper::class, + 'external' => 'survey_template_created_by', ], ]; diff --git a/Theme/Backend/Lang/de.lang.php b/Theme/Backend/Lang/de.lang.php index 15190ea..1cba012 100755 --- a/Theme/Backend/Lang/de.lang.php +++ b/Theme/Backend/Lang/de.lang.php @@ -49,8 +49,8 @@ return ['Surveys' => [ 'Type' => 'Typ', 'User' => 'Nutzer', 'UserGroup' => 'Benutzergruppe', - 'Headline' => 'Headline', - 'Textfield' => 'Textfeld', - 'Textarea' => 'Textblock', - 'Numeric' => 'Zahl', + 'Headline' => 'Headline', + 'Textfield' => 'Textfeld', + 'Textarea' => 'Textblock', + 'Numeric' => 'Zahl', ]]; diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index 68b0602..f5e75db 100755 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -49,8 +49,8 @@ return ['Surveys' => [ 'Type' => 'Type', 'User' => 'User', 'UserGroup' => 'User/Group', - 'Headline' => 'Headline', - 'Textfield' => 'Textfield', - 'Textarea' => 'Textarea', - 'Numeric' => 'Numeric', + 'Headline' => 'Headline', + 'Textfield' => 'Textfield', + 'Textarea' => 'Textarea', + 'Numeric' => 'Numeric', ]]; diff --git a/Theme/Backend/surveys-create.tpl.php b/Theme/Backend/surveys-create.tpl.php index 00aca1f..3a4e28a 100755 --- a/Theme/Backend/surveys-create.tpl.php +++ b/Theme/Backend/surveys-create.tpl.php @@ -106,14 +106,14 @@ echo $this->data['nav']->render(); ?>
@@ -136,8 +136,8 @@ echo $this->data['nav']->render(); ?> getL11n()->description)) : ?>
getL11n()->description; ?>
- getElements(); - foreach ($elements as $element) { + elements as $element) { if ($element->type === SurveyElementType::HEADLINE) { echo '

' . $this->printHtml($element->getL11n()->text) . '

'; diff --git a/Theme/Backend/surveys-list.tpl.php b/Theme/Backend/surveys-list.tpl.php index 746716c..5d4771a 100755 --- a/Theme/Backend/surveys-list.tpl.php +++ b/Theme/Backend/surveys-list.tpl.php @@ -109,7 +109,7 @@ echo $this->data['nav']->render(); ?> getL11n()->title; ?> - printHtml($this->renderUserName('%3$s %2$s %1$s', [$value->createdBy->name1, $value->createdBy->name2, $value->createdBy->name3, $value->createdBy->login ?? ''])); ?> + printHtml($this->renderUserName('%3$s %2$s %1$s', [$value->createdBy->name1, $value->createdBy->name2, $value->createdBy->name3, $value->createdBy->login ?? ''])); ?> createdAt->format('Y-m-d'); ?> diff --git a/tests/Autoloader.php b/tests/Autoloader.php index 7a2c794..b70cd29 100644 --- a/tests/Autoloader.php +++ b/tests/Autoloader.php @@ -75,8 +75,8 @@ final class Autoloader */ public static function defaultAutoloader(string $class) : void { - $class = \ltrim($class, '\\'); - $class = \strtr($class, '_\\', '//'); + $class = \ltrim($class, '\\'); + $class = \strtr($class, '_\\', '//'); if (\stripos($class, 'Web/Backend') !== false || \stripos($class, 'Web/Api') !== false) { $class = \is_dir(__DIR__ . '/Web') ? $class : \str_replace('Web/', 'MainRepository/Web/', $class); diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index ddc049d..bf2c01e 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -1,4 +1,15 @@ [ + 'db' => [ 'core' => [ 'masters' => [ - 'admin' => [ + 'admin' => [ 'db' => 'mysql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '3306', /* db host port */ @@ -80,7 +91,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'insert' => [ + 'insert' => [ 'db' => 'mysql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '3306', /* db host port */ @@ -90,7 +101,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'select' => [ + 'select' => [ 'db' => 'mysql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '3306', /* db host port */ @@ -100,7 +111,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'update' => [ + 'update' => [ 'db' => 'mysql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '3306', /* db host port */ @@ -110,7 +121,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'delete' => [ + 'delete' => [ 'db' => 'mysql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '3306', /* db host port */ @@ -120,7 +131,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'schema' => [ + 'schema' => [ 'db' => 'mysql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '3306', /* db host port */ @@ -132,7 +143,7 @@ $CONFIG = [ ], ], 'postgresql' => [ - 'admin' => [ + 'admin' => [ 'db' => 'pgsql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '5432', /* db host port */ @@ -142,7 +153,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'insert' => [ + 'insert' => [ 'db' => 'pgsql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '5432', /* db host port */ @@ -152,7 +163,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'select' => [ + 'select' => [ 'db' => 'pgsql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '5432', /* db host port */ @@ -162,7 +173,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'update' => [ + 'update' => [ 'db' => 'pgsql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '5432', /* db host port */ @@ -172,7 +183,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'delete' => [ + 'delete' => [ 'db' => 'pgsql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '5432', /* db host port */ @@ -182,7 +193,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'schema' => [ + 'schema' => [ 'db' => 'pgsql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '5432', /* db host port */ @@ -194,37 +205,37 @@ $CONFIG = [ ], ], 'sqlite' => [ - 'admin' => [ + 'admin' => [ 'db' => 'sqlite', /* db type */ 'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'insert' => [ + 'insert' => [ 'db' => 'sqlite', /* db type */ 'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'select' => [ + 'select' => [ 'db' => 'sqlite', /* db type */ 'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'update' => [ + 'update' => [ 'db' => 'sqlite', /* db type */ 'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'delete' => [ + 'delete' => [ 'db' => 'sqlite', /* db type */ 'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'schema' => [ + 'schema' => [ 'db' => 'sqlite', /* db type */ 'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */ 'weight' => 1000, /* db table prefix */ @@ -232,7 +243,7 @@ $CONFIG = [ ], ], 'mssql' => [ - 'admin' => [ + 'admin' => [ 'db' => 'mssql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '1433', /* db host port */ @@ -242,7 +253,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'insert' => [ + 'insert' => [ 'db' => 'mssql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '1433', /* db host port */ @@ -252,7 +263,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'select' => [ + 'select' => [ 'db' => 'mssql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '1433', /* db host port */ @@ -262,7 +273,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'update' => [ + 'update' => [ 'db' => 'mssql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '1433', /* db host port */ @@ -272,7 +283,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'delete' => [ + 'delete' => [ 'db' => 'mssql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '1433', /* db host port */ @@ -282,7 +293,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'schema' => [ + 'schema' => [ 'db' => 'mssql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '1433', /* db host port */ @@ -322,16 +333,16 @@ $CONFIG = [ 'password' => '123456', ], ], - 'log' => [ + 'log' => [ 'file' => [ 'path' => __DIR__ . '/Logs', ], ], - 'page' => [ + 'page' => [ 'root' => '/', 'https' => false, ], - 'app' => [ + 'app' => [ 'path' => __DIR__, 'default' => [ 'app' => 'Backend', @@ -350,7 +361,7 @@ $CONFIG = [ ], ], ], - 'socket' => [ + 'socket' => [ 'master' => [ 'host' => '127.0.0.1', 'limit' => 300, @@ -360,7 +371,7 @@ $CONFIG = [ 'language' => [ 'en', ], - 'apis' => [ + 'apis' => [ ], ]; diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index be9d558..abb3d05 100755 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -32,7 +32,6 @@ use phpOMS\Module\ModuleAbstract; use phpOMS\Module\ModuleManager; use phpOMS\Router\WebRouter; use phpOMS\System\MimeType; -use phpOMS\Uri\HttpUri; use phpOMS\Utils\TestUtils; /** @@ -59,13 +58,13 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase protected string $appName = 'Api'; }; - $this->app->dbPool = $GLOBALS['dbpool']; - $this->app->unitId = 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->dbPool = $GLOBALS['dbpool']; + $this->app->unitId = 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); $this->app->l11nManager = new L11nManager(); @@ -101,7 +100,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase public function testApiSurveyTemplateCreate() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('title', 'TestSurvey'); @@ -136,7 +135,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase public function testApiSurveyTemplateCreateInvalidData() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('invalid', '1'); @@ -152,7 +151,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase public function testApiSurveyTemplateElementCreate() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('survey', '1'); @@ -177,7 +176,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase public function testApiSurveyTemplateElementCreateInvalidData() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('invalid', '1'); @@ -193,7 +192,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase public function testApiSurveyAnswerCreate() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('survey', '1'); @@ -211,7 +210,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase public function testApiSurveyAnswerCreateInvalidData() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('invalid', '1'); diff --git a/tests/Models/SurveyTemplateElementL11nTest.php b/tests/Models/SurveyTemplateElementL11nTest.php index d12601c..2497f22 100755 --- a/tests/Models/SurveyTemplateElementL11nTest.php +++ b/tests/Models/SurveyTemplateElementL11nTest.php @@ -65,16 +65,6 @@ final class SurveyTemplateElementL11nTest extends \PHPUnit\Framework\TestCase self::assertEquals('TestContent', $this->l11n->description); } - /** - * @covers Modules\Surveys\Models\SurveyTemplateElementL11n - * @group module - */ - public function testLanguageInputOutput() : void - { - $this->l11n->setLanguage(ISO639x1Enum::_DE); - self::assertEquals(ISO639x1Enum::_DE, $this->l11n->language); - } - /** * @covers Modules\Surveys\Models\SurveyTemplateElementL11n * @group module @@ -85,16 +75,16 @@ final class SurveyTemplateElementL11nTest extends \PHPUnit\Framework\TestCase $this->l11n->description = 'Content'; $this->l11n->descriptionPlain = 'ContentPlain'; $this->l11n->element = 2; - $this->l11n->setLanguage(ISO639x1Enum::_DE); + $this->l11n->language = ISO639x1Enum::_DE; self::assertEquals( [ - 'id' => 0, - 'text' => 'Title', - 'description' => 'Content', - 'descriptionPlain' => 'ContentPlain', - 'element' => 2, - 'language' => ISO639x1Enum::_DE, + 'id' => 0, + 'text' => 'Title', + 'description' => 'Content', + 'descriptionPlain' => 'ContentPlain', + 'element' => 2, + 'language' => ISO639x1Enum::_DE, ], $this->l11n->jsonSerialize() ); diff --git a/tests/Models/SurveyTemplateElementTest.php b/tests/Models/SurveyTemplateElementTest.php index e4243d2..8da24c0 100755 --- a/tests/Models/SurveyTemplateElementTest.php +++ b/tests/Models/SurveyTemplateElementTest.php @@ -84,21 +84,21 @@ final class SurveyTemplateElementTest extends \PHPUnit\Framework\TestCase */ public function testSerialize() : void { - $this->element->isOptional = true; - $this->element->order = 3; - $this->element->template = 2; + $this->element->isOptional = true; + $this->element->order = 3; + $this->element->template = 2; $serialized = $this->element->jsonSerialize(); self::assertEquals( [ - 'id' => 0, - 'type' => SurveyElementType::CHECKBOX, - 'isOptional' => true, - 'order' => 3, - 'template' => 2, - 'labels' => [], - 'values' => [], + 'id' => 0, + 'type' => SurveyElementType::CHECKBOX, + 'isOptional' => true, + 'order' => 3, + 'template' => 2, + 'labels' => [], + 'values' => [], ], $serialized ); diff --git a/tests/Models/SurveyTemplateL11nTest.php b/tests/Models/SurveyTemplateL11nTest.php index 39cc6ce..ca21ba2 100755 --- a/tests/Models/SurveyTemplateL11nTest.php +++ b/tests/Models/SurveyTemplateL11nTest.php @@ -65,16 +65,6 @@ final class SurveyTemplateL11nTest extends \PHPUnit\Framework\TestCase self::assertEquals('TestContent', $this->l11n->description); } - /** - * @covers Modules\Surveys\Models\SurveyTemplateL11n - * @group module - */ - public function testLanguageInputOutput() : void - { - $this->l11n->setLanguage(ISO639x1Enum::_DE); - self::assertEquals(ISO639x1Enum::_DE, $this->l11n->language); - } - /** * @covers Modules\Surveys\Models\SurveyTemplateL11n * @group module @@ -85,16 +75,16 @@ final class SurveyTemplateL11nTest extends \PHPUnit\Framework\TestCase $this->l11n->description = 'Content'; $this->l11n->descriptionPlain = 'ContentPlain'; $this->l11n->template = 2; - $this->l11n->setLanguage(ISO639x1Enum::_DE); + $this->l11n->language = ISO639x1Enum::_DE; self::assertEquals( [ - 'id' => 0, - 'title' => 'Title', - 'description' => 'Content', - 'descriptionPlain' => 'ContentPlain', - 'template' => 2, - 'language' => ISO639x1Enum::_DE, + 'id' => 0, + 'title' => 'Title', + 'description' => 'Content', + 'descriptionPlain' => 'ContentPlain', + 'template' => 2, + 'language' => ISO639x1Enum::_DE, ], $this->l11n->jsonSerialize() ); diff --git a/tests/Models/SurveyTemplateLabelL11nTest.php b/tests/Models/SurveyTemplateLabelL11nTest.php index d240ff0..25ff0de 100755 --- a/tests/Models/SurveyTemplateLabelL11nTest.php +++ b/tests/Models/SurveyTemplateLabelL11nTest.php @@ -53,34 +53,24 @@ final class SurveyTemplateLabelL11nTest extends \PHPUnit\Framework\TestCase self::assertEquals('TestName', $this->l11n->title); } - /** - * @covers Modules\Surveys\Models\SurveyTemplateLabelL11n - * @group module - */ - public function testLanguageInputOutput() : void - { - $this->l11n->setLanguage(ISO639x1Enum::_DE); - self::assertEquals(ISO639x1Enum::_DE, $this->l11n->language); - } - /** * @covers Modules\Surveys\Models\SurveyTemplateLabelL11n * @group module */ public function testSerialize() : void { - $this->l11n->title = 'Title'; - $this->l11n->element = 2; - $this->l11n->order = 3; - $this->l11n->setLanguage(ISO639x1Enum::_DE); + $this->l11n->title = 'Title'; + $this->l11n->element = 2; + $this->l11n->order = 3; + $this->l11n->language = ISO639x1Enum::_DE; self::assertEquals( [ - 'id' => 0, - 'title' => 'Title', - 'element' => 2, - 'order' => 3, - 'language' => ISO639x1Enum::_DE, + 'id' => 0, + 'title' => 'Title', + 'element' => 2, + 'order' => 3, + 'language' => ISO639x1Enum::_DE, ], $this->l11n->jsonSerialize() ); diff --git a/tests/Models/SurveyTemplateTest.php b/tests/Models/SurveyTemplateTest.php index a19bce5..17761ea 100755 --- a/tests/Models/SurveyTemplateTest.php +++ b/tests/Models/SurveyTemplateTest.php @@ -14,12 +14,9 @@ declare(strict_types=1); namespace Modules\Surveys\tests\Models; -use Modules\Media\Models\Media; use Modules\Surveys\Models\SurveyStatus; use Modules\Surveys\Models\SurveyTemplate; -use Modules\Surveys\Models\SurveyTemplateElement; use Modules\Surveys\Models\SurveyTemplateL11n; -use Modules\Tag\Models\Tag; /** * @internal @@ -45,58 +42,9 @@ final class SurveyTemplateTest extends \PHPUnit\Framework\TestCase self::assertEquals(0, $this->survey->id); $date = new \DateTime('now'); - self::assertEquals([], $this->survey->getElements()); - self::assertEquals([], $this->survey->getTags()); - self::assertEquals([], $this->survey->getMedia()); - } - - /** - * @covers Modules\Surveys\Models\SurveyTemplate - * @group module - */ - public function testTagInputOutput() : void - { - $tag = new Tag(); - $tag->setL11n('Tag'); - - $this->survey->addTag($tag); - self::assertEquals($tag, $this->survey->getTag(0)); - self::assertCount(1, $this->survey->getTags()); - } - - /** - * @covers Modules\Surveys\Models\SurveyTemplate - * @group module - */ - public function testTagRemove() : void - { - $tag = new Tag(); - $tag->setL11n('Tag'); - - $this->survey->addTag($tag); - self::assertTrue($this->survey->removeTag(0)); - self::assertCount(0, $this->survey->getTags()); - self::assertFalse($this->survey->removeTag(0)); - } - - /** - * @covers Modules\Surveys\Models\SurveyTemplate - * @group module - */ - public function testMediaInputOutput() : void - { - $this->survey->addMedia(new Media()); - self::assertCount(1, $this->survey->getMedia()); - } - - /** - * @covers Modules\Surveys\Models\SurveyTemplate - * @group module - */ - public function testElementInputOutput() : void - { - $this->survey->addElement(new SurveyTemplateElement()); - self::assertCount(1, $this->survey->getElements()); + self::assertEquals([], $this->survey->elements); + self::assertEquals([], $this->survey->tags); + self::assertEquals([], $this->survey->files); } /** @@ -115,10 +63,10 @@ final class SurveyTemplateTest extends \PHPUnit\Framework\TestCase */ public function testSerialize() : void { - $this->survey->hasPublicResult = false; - $this->survey->start = new \DateTime('now'); - $this->survey->end = new \DateTime('now'); - $this->survey->virtualPath = 'test/path'; + $this->survey->hasPublicResult = false; + $this->survey->start = new \DateTime('now'); + $this->survey->end = new \DateTime('now'); + $this->survey->virtualPath = 'test/path'; $serialized = $this->survey->jsonSerialize(); unset($serialized['createdAt']);