diff --git a/CHANGELOG.md b/CHANGELOG.md index dcedef755..f3c59eeda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,44 @@ + +## [2.13.7](https://github.com/pluginsGLPI/formcreator/compare/2.13.6..2.13.7) (2023-07-19) + + +### Bug Fixes + +* Adding READ right for display reservations menu tab ([03e6281e](https://github.com/pluginsGLPI/formcreator/commit/03e6281e)) +* bad lcoale in en_US ([db9986f1](https://github.com/pluginsGLPI/formcreator/commit/db9986f1)) +* resize dashboard to match GLPI's core (#3306) ([9272cda3](https://github.com/pluginsGLPI/formcreator/commit/9272cda3)) +* show FAQ without tabs for self-service ([c5499ad4](https://github.com/pluginsGLPI/formcreator/commit/c5499ad4)) +* **TargetChange:** use RichText instead of plaintext ([8845b888](https://github.com/pluginsGLPI/formcreator/commit/8845b888)) +* **checkboxesfield,radiosfield,selectfield:** add missing error messages ([66585193](https://github.com/pluginsGLPI/formcreator/commit/66585193)) +* **datefield, datetimefield:** comparison against empty string ([be4831c7](https://github.com/pluginsGLPI/formcreator/commit/be4831c7)) +* **dropdownfield:** SQL error for GLPI objects / tickets and some specific rights ([2539e366](https://github.com/pluginsGLPI/formcreator/commit/2539e366)) +* **dropdownfield:** handle specific case with Entity itemtype ([bd25e7d1](https://github.com/pluginsGLPI/formcreator/commit/bd25e7d1)) +* **dropdownfield:** missing entity restriction setting ([54543cb3](https://github.com/pluginsGLPI/formcreator/commit/54543cb3)) +* **dropdownfield:** prevent language switching and log error ([49f8fc07](https://github.com/pluginsGLPI/formcreator/commit/49f8fc07)) +* **fieldsfield:** restore mandatory field as read only ([52a9fc2b](https://github.com/pluginsGLPI/formcreator/commit/52a9fc2b)) +* **form,category:** obey show count on tabs parameter ([f4ebf9e5](https://github.com/pluginsGLPI/formcreator/commit/f4ebf9e5)) +* **form_language:** obey show counter in tab setting ([9dfc3b8d](https://github.com/pluginsGLPI/formcreator/commit/9dfc3b8d)) +* **formanswer:** php warning ([ce078990](https://github.com/pluginsGLPI/formcreator/commit/ce078990)) +* **formanswer:** prevent silent rejection of answers ([d630302d](https://github.com/pluginsGLPI/formcreator/commit/d630302d)) +* **formanswer:** redirect to login if session expired ([eb0acb65](https://github.com/pluginsGLPI/formcreator/commit/eb0acb65)) +* **glpiselectfield:** fix namespace (#3287) ([613e0fad](https://github.com/pluginsGLPI/formcreator/commit/613e0fad)) +* **install:** missing row in sql query, causing PHP warning ([0c47776a](https://github.com/pluginsGLPI/formcreator/commit/0c47776a)) +* **issue:** php warnings when anonymisation enabled ([f6f01d7d](https://github.com/pluginsGLPI/formcreator/commit/f6f01d7d)) +* **issue:** prevent fatal error in tooltip ([3419affc](https://github.com/pluginsGLPI/formcreator/commit/3419affc)) +* **question,section:** duplicate a question or section must duplicate inner conditions ([22597832](https://github.com/pluginsGLPI/formcreator/commit/22597832)) +* **section:** cannot rename section twice ([7bbb9b81](https://github.com/pluginsGLPI/formcreator/commit/7bbb9b81)) +* **section:** condition rule loss after duplicate / import ([883a1227](https://github.com/pluginsGLPI/formcreator/commit/883a1227)) +* **section:** duplicate form may lead to bad question id in condition ([a6f9c41c](https://github.com/pluginsGLPI/formcreator/commit/a6f9c41c)) +* **section:** rename section impacts display of inner questions ([c4277d8c](https://github.com/pluginsGLPI/formcreator/commit/c4277d8c)) +* **selectfield,multiselectfield:** fix possible encoding problem ([8aaec8ac](https://github.com/pluginsGLPI/formcreator/commit/8aaec8ac)) +* **tag:** tag was always deleted ([6201d61d](https://github.com/pluginsGLPI/formcreator/commit/6201d61d)) +* **targetchange,targetproblem:** folow method call signature for fields plugin ([016696ab](https://github.com/pluginsGLPI/formcreator/commit/016696ab)) +* **textfield:** Unescaped HTML when displaying a form answer ([6ce71f95](https://github.com/pluginsGLPI/formcreator/commit/6ce71f95)) +* **textfield:** exception while displaying counters ([0a857d7f](https://github.com/pluginsGLPI/formcreator/commit/0a857d7f)) +* **textfield:** target ticket title need html encoding ([1b71d652](https://github.com/pluginsGLPI/formcreator/commit/1b71d652)) + + + ## [2.13.6](https://github.com/pluginsGLPI/formcreator/compare/2.13.5..2.13.6) (2023-05-26) diff --git a/RoboFile.php b/RoboFile.php index 14e57285a..59397ae58 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -203,10 +203,25 @@ public function archiveBuild($release = 'release') { } // Add composer dependencies - $this->_exec("composer install --no-dev --working-dir='$archiveWorkdir/$pluginName'"); + $success = $this->taskExec('composer') + ->arg('install') + ->arg('--no-dev') + ->arg("--working-dir='$archiveWorkdir/$pluginName'") + ->run(); + if ($success->getExitCode() != 0) { + throw new RuntimeException("failed to generate PHP resources"); + } // Add JS dependencies - $this->_exec("yarn --cwd '$archiveWorkdir/$pluginName' install --prod"); + $success = $this->taskExec('yarn') + ->arg('--cwd') + ->arg("$archiveWorkdir/$pluginName") + ->arg('install') + ->arg('--prod') + ->run(); + if ($success->getExitCode() != 0) { + throw new RuntimeException("failed to generate JS resources"); + } // Create the final archive $this->taskPack($archiveFile) diff --git a/inc/abstractfield.class.php b/inc/abstractfield.class.php index 998d11c55..b67220373 100644 --- a/inc/abstractfield.class.php +++ b/inc/abstractfield.class.php @@ -202,10 +202,13 @@ public function getLabel() { /** * Gets the available values for the field + * @param array $values values to parse. If null, the values are ised from the instance of the question * @return array available values */ - public function getAvailableValues() { - $values = json_decode($this->question->fields['values']); + public function getAvailableValues(array $values = null): array { + if ($values === null) { + $values = json_decode($this->question->fields['values']); + } $tab_values = []; foreach ($values as $value) { $trimmedValue = trim($value); @@ -221,13 +224,11 @@ public function isRequired(): bool { } /** - * trim values separated by \r\n + * trim and explode values separated by \r\n * @param string $value a value or default value - * @return string + * @return array */ - protected function trimValue($value) { - global $DB; - + protected function trimValue($value): array { $value = explode('\r\n', $value); // input has escpaed single quotes $value = Toolbox::stripslashes_deep($value); @@ -241,6 +242,7 @@ function ($value) { $value ); + return $value; return $DB->escape(json_encode($value, JSON_UNESCAPED_UNICODE)); } diff --git a/inc/field/checkboxesfield.class.php b/inc/field/checkboxesfield.class.php index fc35e939f..a53eaee17 100644 --- a/inc/field/checkboxesfield.class.php +++ b/inc/field/checkboxesfield.class.php @@ -250,24 +250,33 @@ public function isValidValue($value): bool { } public function prepareQuestionInputForSave($input) { - if (isset($input['values'])) { - if (strlen($input['values']) === 0) { + global $DB; + + if (strlen($input['values'] ?? '') == 0) { + Session::addMessageAfterRedirect( + __('The field value is required.', 'formcreator'), + false, + ERROR + ); + return []; + } + + $values = $this->trimValue($input['values']); + $defaultValues = $this->trimValue($input['default_values'] ?? ''); + if (count($defaultValues) > 0) { + // trim values + $validDefaultValues = array_intersect($this->getAvailableValues($values), $defaultValues); + if (count($validDefaultValues) != (count($defaultValues))) { Session::addMessageAfterRedirect( - __('The field value is required:', 'formcreator') . ' ' . $input['name'], + __('The default values are not in the list of available values.', 'formcreator'), false, ERROR ); return []; } - - // trim values - $input['values'] = $this->trimValue($input['values']); - } - - if (isset($input['default_values'])) { - // trim values - $input['default_values'] = $this->trimValue($input['default_values']); + $input['default_values'] = $DB->escape(json_encode($defaultValues, JSON_UNESCAPED_UNICODE)); } + $input['values'] = $DB->escape(json_encode($values, JSON_UNESCAPED_UNICODE)); return $input; } diff --git a/inc/field/glpiselectfield.class.php b/inc/field/glpiselectfield.class.php index b843413c2..5b520d35c 100644 --- a/inc/field/glpiselectfield.class.php +++ b/inc/field/glpiselectfield.class.php @@ -72,6 +72,7 @@ public function showForm(array $options): void { } $this->question->fields['default_values'] = Html::entities_deep($this->question->fields['default_values']); $this->deserializeValue($this->question->fields['default_values']); + $this->question->fields['_default_values'] = $this->value; $parameters = $this->getParameters(); TemplateRenderer::getInstance()->display($template, [ @@ -106,7 +107,9 @@ public function isValidValue($value): bool { } public function prepareQuestionInputForSave($input) { - if (isset($input['itemtype']) && empty($input['itemtype'])) { + global $DB; + + if (!isset($input['itemtype']) || strlen($input['itemtype']) === 0) { Session::addMessageAfterRedirect( __('The field value is required:', 'formcreator') . ' ' . $input['name'], false, @@ -134,7 +137,7 @@ public function prepareQuestionInputForSave($input) { unset($input['show_tree_depth']); unset($input['selectable_tree_root']); - $input['values'] = json_encode($input['values']); + $input['values'] = $DB->escape(json_encode($input['values'], JSON_UNESCAPED_UNICODE)); return $input; } @@ -143,7 +146,7 @@ public static function canRequire(): bool { return true; } - public function getAvailableValues(): array { + public function getAvailableValues(array $values = null): array { return []; } diff --git a/inc/field/radiosfield.class.php b/inc/field/radiosfield.class.php index c92342963..39f6c3beb 100644 --- a/inc/field/radiosfield.class.php +++ b/inc/field/radiosfield.class.php @@ -49,7 +49,7 @@ public function isPrerequisites(): bool { public function showForm(array $options): void { $template = '@formcreator/field/' . $this->question->fields['fieldtype'] . 'field.html.twig'; - $this->question->fields['values'] = json_decode($this->question->fields['values']); + $this->question->fields['values'] = json_decode($this->question->fields['values']); $this->question->fields['values'] = is_array($this->question->fields['values']) ? $this->question->fields['values'] : []; $this->question->fields['values'] = implode("\r\n", $this->question->fields['values']); $this->deserializeValue($this->question->fields['default_values']); @@ -110,24 +110,41 @@ public static function getName(): string { } public function prepareQuestionInputForSave($input) { - if (isset($input['values'])) { - if (strlen($input['values']) === 0) { + global $DB; + + if (strlen($input['values'] ?? '') === 0) { + Session::addMessageAfterRedirect( + __('The field value is required.', 'formcreator'), + false, + ERROR + ); + return []; + } + + // trim values (actually there is only one value then no \r\n expected) + $defaultValues = $this->trimValue($input['default_values'] ?? ''); + if (count($defaultValues) > 1) { + Session::addMessageAfterRedirect( + __('Only one default value is allowed.', 'formcreator'), + false, + ERROR + ); + return []; + } + $values = $this->trimValue($input['values']); + if (count($defaultValues) > 0) { + $validDefaultValues = array_intersect($this->getAvailableValues($values), $defaultValues); + if (count($validDefaultValues) != count($defaultValues)) { Session::addMessageAfterRedirect( - __('The field value is required:', 'formcreator') . ' ' . $input['name'], + __('The default value is not in the list of available values.', 'formcreator'), false, ERROR ); return []; } - - // trim values - $input['values'] = $this->trimValue($input['values']); - } - - if (isset($input['default_values'])) { - // trim values - $input['default_values'] = trim($input['default_values']); } + $input['values'] = $DB->escape(json_encode($values, JSON_UNESCAPED_UNICODE)); + $input['default_values'] = array_pop($defaultValues); return $input; } diff --git a/inc/field/requesttypefield.class.php b/inc/field/requesttypefield.class.php index dfbd5090d..95ba35c6b 100644 --- a/inc/field/requesttypefield.class.php +++ b/inc/field/requesttypefield.class.php @@ -112,7 +112,7 @@ public static function canRequire(): bool { return true; } - public function getAvailableValues() { + public function getAvailableValues(array $values = null): array { return Ticket::getTypes(); } diff --git a/inc/field/selectfield.class.php b/inc/field/selectfield.class.php index fcb79a8ba..dc652b189 100644 --- a/inc/field/selectfield.class.php +++ b/inc/field/selectfield.class.php @@ -74,7 +74,7 @@ public function getRenderedHtml($domain, $canEdit = true): string { foreach ($values as $value) { if ((trim($value) != '')) { $unsanitized = Sanitizer::unsanitize(__($value, $domain)); - $translatedValues[$unsanitized] = $unsanitized; + $translatedValues[$value] = $unsanitized; } } diff --git a/inc/field/urgencyfield.class.php b/inc/field/urgencyfield.class.php index 6c9f3876c..9125ab588 100644 --- a/inc/field/urgencyfield.class.php +++ b/inc/field/urgencyfield.class.php @@ -115,7 +115,7 @@ public static function canRequire(): bool { return true; } - public function getAvailableValues() { + public function getAvailableValues(array $values = null): array { return [ 5 => _x('urgency', 'Very high'), 4 => _x('urgency', 'High'), diff --git a/inc/formanswer.class.php b/inc/formanswer.class.php index baeafbc6f..6c610de7a 100644 --- a/inc/formanswer.class.php +++ b/inc/formanswer.class.php @@ -1452,6 +1452,8 @@ public function parseTags(string $content, PluginFormcreatorTargetInterface $tar $content = Sanitizer::sanitize($content); } + $content = $this->parseExtraTags($content, $target, $richText); + $hook_data = Plugin::doHookFunction('formcreator_parse_extra_tags', [ 'formanswer' => $this, 'content' => $content, @@ -1462,6 +1464,12 @@ public function parseTags(string $content, PluginFormcreatorTargetInterface $tar return $hook_data['content']; } + protected function parseExtraTags(string $content, PluginFormcreatorTargetInterface $target = null, $richText = false): string { + $content = str_replace('##answer_id##', $this->getField('id'), $content); + + return $content; + } + /** * Validates answers of a form * @@ -1699,7 +1707,7 @@ public function createIssue() { 'items_id' => $ticketId, 'itemtype' => Ticket::class, 'name' => $issueName, - 'status' => $ticket->fields['status'], + 'status' => PluginFormcreatorCommon::getTicketStatusForIssue($ticket), 'date_creation' => $ticket->fields['date'], 'date_mod' => $ticket->fields['date_mod'], 'entities_id' => $ticket->fields['entities_id'], diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index bb658f611..5ac0c2556 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -699,8 +699,6 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM { return null; } - $this->saveTags($formanswer, $changeID); - // Add link between Change and FormAnswer $itemlink = $this->getItem_Item(); $itemlink->add([ @@ -709,6 +707,8 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM { 'changes_id' => $changeID, ]); + $this->saveTags($formanswer, $changeID); + return $change; } diff --git a/inc/targetproblem.class.php b/inc/targetproblem.class.php index ab4d77451..6bed0bd81 100644 --- a/inc/targetproblem.class.php +++ b/inc/targetproblem.class.php @@ -219,8 +219,6 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM { return null; } - $this->saveTags($formanswer, $problemID); - // Add link between Problem and FormAnswer $itemlink = $this->getItem_Item(); $itemlink->add([ @@ -229,6 +227,8 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM { 'problems_id' => $problemID, ]); + $this->saveTags($formanswer, $problemID); + return $problem; } diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index f29deeecd..4a4a1809d 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -907,8 +907,6 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM { } } - $this->saveTags($formanswer, $ticketID); - // Add link between Ticket and FormAnswer $itemlink = $this->getItem_Item(); $itemlink->add([ @@ -917,6 +915,8 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM { 'tickets_id' => $ticketID, ]); + $this->saveTags($formanswer, $ticketID); + // Attach validation message as first ticket followup if validation is required and // if is set in ticket target configuration if ($form->validationRequired() && $this->fields['validation_followup']) { diff --git a/plugin.xml b/plugin.xml index 54f0c5822..dc7eeaa09 100644 --- a/plugin.xml +++ b/plugin.xml @@ -58,6 +58,11 @@ Features Teclib' + + 2.13.7 + ~10.0 + https://github.com/pluginsGLPI/formcreator/releases/download/2.13.7/glpi-formcreator-2.13.7.tar.bz2 + 2.13.6 ~10.0 diff --git a/setup.php b/setup.php index 974babfbd..dfd52a772 100644 --- a/setup.php +++ b/setup.php @@ -37,7 +37,7 @@ // Schema version of this version (major.minor only) define('PLUGIN_FORMCREATOR_SCHEMA_VERSION', '2.14'); // is or is not an official release of the plugin -define('PLUGIN_FORMCREATOR_IS_OFFICIAL_RELEASE', false); +define('PLUGIN_FORMCREATOR_IS_OFFICIAL_RELEASE', true); // Minimal GLPI version, inclusive define ('PLUGIN_FORMCREATOR_GLPI_MIN_VERSION', '10.0.5'); diff --git a/templates/field/glpiselectfield.html.twig b/templates/field/glpiselectfield.html.twig index 0e812c432..9a996ed02 100644 --- a/templates/field/glpiselectfield.html.twig +++ b/templates/field/glpiselectfield.html.twig @@ -72,7 +72,7 @@ {{ fields.dropdownField( item.fields['itemtype'], 'default_values', - default_values, + item.fields['_default_values'], __('Default values'), { label_class: 'col-xxl-4', input_class: 'col-xxl-8', diff --git a/tests/3-unit/GlpiPlugin/Formcreator/Field/CheckboxesField.php b/tests/3-unit/GlpiPlugin/Formcreator/Field/CheckboxesField.php index 247ea52eb..cd1080797 100644 --- a/tests/3-unit/GlpiPlugin/Formcreator/Field/CheckboxesField.php +++ b/tests/3-unit/GlpiPlugin/Formcreator/Field/CheckboxesField.php @@ -234,32 +234,161 @@ public function testDeserializeValue($value, $expected) { $this->string($output)->isEqualTo(implode(', ', $expected)); } - public function testPrepareQuestionInputForSave() { + public function providerPrepareQuestionInputForSave() { + global $DB; + $question = $this->getQuestion([ 'fieldtype' => 'checkboxes', 'name' => 'question', 'required' => '0', - 'default_values' => json_encode(['1', '2', '3', '5', '6']), - 'values' => json_encode(['1', '2', '3', '4', '5', '6']), + 'values' => '1\r\n2\r\n3\r\n4\r\n5\r\n6', + 'default_values' => '1\r\n2\r\n3\r\n5\r\n6', 'order' => '1', 'show_rule' => \PluginFormcreatorCondition::SHOW_RULE_ALWAYS, 'range_min' => 3, 'range_max' => 4, ]); + + yield [ + 'field' => $this->newTestedInstance($question), + 'input' => [ + 'values' => "", + 'name' => 'foo', + ], + 'expected' => [], + 'message' => 'The field value is required.', + ]; + + yield [ + 'field' => $this->newTestedInstance($question), + 'input' => [ + 'values' => 'éè\r\nsomething else', + 'default_values' => 'éè', + ], + 'expected' => [ + 'values' => '[\"éè\",\"something else\"]', + 'default_values' => '[\"éè\"]', + ], + 'message' => '', + ]; + + yield [ + 'field' => $this->newTestedInstance($question), + 'input' => [ + 'values' => ' something \r\n something else ', + 'default_values' => ' something ', + ], + 'expected' => [ + 'values' => '[\"something\",\"something else\"]', + 'default_values' => '[\"something\"]', + ], + 'message' => '', + ]; + + yield 'no default value' => [ + 'field' => $this->newTestedInstance($question), + 'input' => [ + 'values' => 'a\r\nb\r\nc', + 'name' => 'foo', + 'default_values' => '' + ], + 'expected' => [ + 'values' => $DB->escape('["a","b","c"]'), + 'name' => 'foo', + 'default_values' => '', + ], + 'message' => '', + ]; + + yield 'several default values' => [ + 'field' => $this->newTestedInstance($question), + 'input' => [ + 'values' => 'a\r\nb\r\nc', + 'name' => 'foo', + 'default_values' => 'a\r\n\b' + ], + 'expected' => [ + 'values' => $DB->escape('["a","b","c"]'), + 'name' => 'foo', + 'default_values' => $DB->escape('["a","b"]'), + ], + 'message' => '', + ]; + + yield 'one default value' => [ + 'field' => $this->newTestedInstance($question), + 'input' => [ + 'values' => 'a\r\nb\r\nc', + 'name' => 'foo', + 'default_values' => 'b' + ], + 'expected' => [ + 'values' => $DB->escape('["a","b","c"]'), + 'name' => 'foo', + 'default_values' => $DB->escape('["b"]'), + ], + 'message' => '', + ]; + + yield 'invalid default value' => [ + 'field' => $this->newTestedInstance($question), + 'input' => [ + 'values' => 'a\r\nb\r\nc', + 'name' => 'foo', + 'default_values' => 'z' + ], + 'expected' => [], + 'message' => 'The default values are not in the list of available values.', + ]; + } + + /** + * @dataProvider providerPrepareQuestionInputForSave + * + * @return void + */ + public function testPrepareQuestionInputForSave($field, $input, $expected, $message) { + + // Clean error messages + $_SESSION['MESSAGE_AFTER_REDIRECT'] = []; + + $output = $field->prepareQuestionInputForSave($input); + if ($expected === false || is_array($expected) && count($expected) == 0) { + $this->array($output)->hasSize(0); + $this->sessionHasMessage($message, ERROR); + //End of test on expected failure + return; + } + + $this->array($output)->isEqualTo($expected); + + return; + + $question = $this->getQuestion([ + 'fieldtype' => 'checkboxes', + 'name' => 'question', + 'required' => '0', + 'default_values' => json_encode(['1', '2', '3', '5', '6']), + 'values' => json_encode(['1', '2', '3', '4', '5', '6']), + 'order' => '1', + 'show_rule' => \PluginFormcreatorCondition::SHOW_RULE_ALWAYS, + 'range_min' => 3, + 'range_max' => 4, + ]); $fieldInstance = $this->newTestedInstance($question); // Test a value is mandatory $input = [ - 'values' => "", - 'name' => 'foo', + 'values' => "", + 'name' => 'foo', ]; $out = $fieldInstance->prepareQuestionInputForSave($input); $this->integer(count($out))->isEqualTo(0); // Test accented chars are kept $input = [ - 'values' => 'éè\r\nsomething else', - 'default_values' => 'éè', + 'values' => 'éè\r\nsomething else', + 'default_values' => 'éè', ]; $out = $fieldInstance->prepareQuestionInputForSave($input); $this->string($out['values'])->isEqualTo('[\"éè\",\"something else\"]'); @@ -267,8 +396,8 @@ public function testPrepareQuestionInputForSave() { // Test values are trimmed $input = [ - 'values' => ' something \r\n something else ', - 'default_values' => ' something ', + 'values' => ' something \r\n something else ', + 'default_values' => ' something ', ]; $out = $fieldInstance->prepareQuestionInputForSave($input); $this->string($out['values'])->isEqualTo('[\"something\",\"something else\"]'); diff --git a/tests/3-unit/GlpiPlugin/Formcreator/Field/MultiselectField.php b/tests/3-unit/GlpiPlugin/Formcreator/Field/MultiselectField.php index 1495ec25e..abfd1c5b9 100644 --- a/tests/3-unit/GlpiPlugin/Formcreator/Field/MultiselectField.php +++ b/tests/3-unit/GlpiPlugin/Formcreator/Field/MultiselectField.php @@ -41,8 +41,8 @@ public function provider() { 'name' => 'question', 'required' => '0', 'show_empty' => '0', - 'default_values' => '[]', - 'values' => json_encode(['1', '2', '3', '4', '5', '6']), + 'default_values' => '', + 'values' => '1\r\n2\r\n3\r\n4\r\n5\r\n6', 'order' => '1', 'show_rule' => \PluginFormcreatorCondition::SHOW_RULE_ALWAYS, '_parameters' => [ @@ -63,8 +63,8 @@ public function provider() { 'name' => 'question', 'required' => '0', 'show_empty' => '0', - 'default_values' => '["3"]', - 'values' => json_encode(['1', '2', '3', '4', '5', '6']), + 'default_values' => '3', + 'values' => '1\r\n2\r\n3\r\n4\r\n5\r\n6', 'order' => '1', 'show_rule' => \PluginFormcreatorCondition::SHOW_RULE_ALWAYS, '_parameters' => [ @@ -85,8 +85,8 @@ public function provider() { 'name' => 'question', 'required' => '0', 'show_empty' => '0', - 'default_values' => '[3]', - 'values' => json_encode(['1', '2', '3', '4', '5', '6']), + 'default_values' => '3', + 'values' => '1\r\n2\r\n3\r\n4\r\n5\r\n6', 'order' => '1', 'show_rule' => \PluginFormcreatorCondition::SHOW_RULE_ALWAYS, '_parameters' => [ @@ -107,8 +107,8 @@ public function provider() { 'name' => 'question', 'required' => '0', 'show_empty' => '0', - 'default_values' => json_encode(['3', '4']), - 'values' => json_encode(['1', '2', '3', '4', '5', '6']), + 'default_values' => '3\r\n4', + 'values' => '1\r\n2\r\n3\r\n4\r\n5\r\n6', 'order' => '1', 'show_rule' => \PluginFormcreatorCondition::SHOW_RULE_ALWAYS, '_parameters' => [ @@ -129,8 +129,8 @@ public function provider() { 'name' => 'question', 'required' => '0', 'show_empty' => '0', - 'default_values' => json_encode(['3', '4', '2', '1', '6']), - 'values' => json_encode(['1', '2', '3', '4', '5', '6']), + 'default_values' => '3\r\n4\r\n2\r\n1\r\n6', + 'values' => '1\r\n2\r\n3\r\n4\r\n5\r\n6', 'order' => '1', 'show_rule' => \PluginFormcreatorCondition::SHOW_RULE_ALWAYS, '_parameters' => [ @@ -158,7 +158,7 @@ public function testGetAvailableValues($fields, $expectedValue, $expectedValidit $fieldInstance = $this->newTestedInstance($question); $availableValues = $fieldInstance->getAvailableValues(); - $expectedAvaliableValues = explode("\r\n", $fields['values']); + $expectedAvaliableValues = explode('\r\n', $fields['values']); $this->integer(count($availableValues))->isEqualTo(count($expectedAvaliableValues)); foreach ($expectedAvaliableValues as $expectedValue) { diff --git a/tests/3-unit/GlpiPlugin/Formcreator/Field/RadiosField.php b/tests/3-unit/GlpiPlugin/Formcreator/Field/RadiosField.php index 172ac3343..2977a99ea 100644 --- a/tests/3-unit/GlpiPlugin/Formcreator/Field/RadiosField.php +++ b/tests/3-unit/GlpiPlugin/Formcreator/Field/RadiosField.php @@ -32,47 +32,132 @@ namespace GlpiPlugin\Formcreator\Field\tests\units; use GlpiPlugin\Formcreator\Tests\CommonAbstractFieldTestCase; use PluginFormcreatorFormAnswer; +use PluginFormcreatorCondition; class RadiosField extends CommonAbstractFieldTestCase { - public function testPrepareQuestionInputForSave() { + + public function providerPrepareQuestionInputForSave() { + global $DB; + $question = $this->getQuestion([ 'fieldtype' => 'radios', 'name' => 'question', 'required' => '0', - 'default_values' => '1\r\n2\r\n3\r\n4\r\n5\r\n6', - 'values' => '1\r\n2\r\n3\r\n4\r\n5\r\n6', + 'default_values' => '1', + 'values' => '1', 'order' => '1', - 'show_rule' => \PluginFormcreatorCondition::SHOW_RULE_ALWAYS, + 'show_rule' => PluginFormcreatorCondition::SHOW_RULE_ALWAYS, 'range_min' => 3, 'range_max' => 4, ]); - $fieldInstance = $this->newTestedInstance($question); - // Test a value is mandatory - $input = [ - 'values' => "", - 'name' => 'foo', + yield [ + 'field' => $this->newTestedInstance($question), + 'input' => [ + 'values' => "", + 'name' => 'foo', + ], + 'expected' => [], + 'message' => 'The field value is required.', ]; - $out = $fieldInstance->prepareQuestionInputForSave($input); - $this->integer(count($out))->isEqualTo(0); - // Test accented chars are kept - $input = [ - 'values' => 'éè\r\nsomething else', - 'default_values' => 'éè', + yield [ + 'field' => $this->newTestedInstance($question), + 'input' => [ + 'values' => 'éè\r\nsomething else', + 'default_values' => 'éè', + ], + 'expected' => [ + 'values' => '[\"éè\",\"something else\"]', + 'default_values' => 'éè', + ], + 'message' => '', ]; - $out = $fieldInstance->prepareQuestionInputForSave($input); - $this->string($out['values'])->isEqualTo('[\"éè\",\"something else\"]'); - $this->string($out['default_values'])->isEqualTo("éè"); - - // Test values are trimmed - $input = [ - 'values' => ' something \r\n something else ', - 'default_values' => ' something ', + + yield [ + 'field' => $this->newTestedInstance($question), + 'input' => [ + 'values' => ' something \r\n something else ', + 'default_values' => ' something ', + ], + 'expected' => [ + 'values' => '[\"something\",\"something else\"]', + 'default_values' => 'something', + ], + 'message' => '', + ]; + + yield 'no default value' => [ + 'field' => $this->newTestedInstance($question), + 'input' => [ + 'values' => 'a\r\nb\r\nc', + 'name' => 'foo', + 'default_values' => '' + ], + 'expected' => [ + 'values' => $DB->escape('["a","b","c"]'), + 'name' => 'foo', + 'default_values' => null, + ], + 'message' => '', ]; - $out = $fieldInstance->prepareQuestionInputForSave($input); - $this->string($out['values'])->isEqualTo('[\"something\",\"something else\"]'); - $this->string($out['default_values'])->isEqualTo("something"); + + yield 'several default values not allowed' => [ + 'field' => $this->newTestedInstance($question), + 'input' => [ + 'values' => 'a\r\nb\r\nc', + 'name' => 'foo', + 'default_values' => 'a\r\n\b' + ], + 'expected' => [], + 'message' => 'Only one default value is allowed.', + ]; + + yield 'one default value' => [ + 'field' => $this->newTestedInstance($question), + 'input' => [ + 'values' => 'a\r\nb\r\nc', + 'name' => 'foo', + 'default_values' => 'b' + ], + 'expected' => [ + 'values' => $DB->escape('["a","b","c"]'), + 'name' => 'foo', + 'default_values' => 'b' + ], + 'message' => '', + ]; + + yield 'invalid default value' => [ + 'field' => $this->newTestedInstance($question), + 'input' => [ + 'values' => 'a\r\nb\r\nc', + 'name' => 'foo', + 'default_values' => 'z' + ], + 'expected' => [], + 'message' => 'The default value is not in the list of available values.', + ]; + } + + /** + * @dataProvider providerPrepareQuestionInputForSave + * + * @return void + */ + public function testPrepareQuestionInputForSave($field, $input, $expected, $message) { + // Clean error messages + $_SESSION['MESSAGE_AFTER_REDIRECT'] = []; + + $output = $field->prepareQuestionInputForSave($input); + if ($expected === false || is_array($expected) && count($expected) == 0) { + $this->array($output)->hasSize(0); + $this->sessionHasMessage($message, ERROR); + //End of test on expected failure + return; + } + + $this->array($output)->isEqualTo($expected); } public function testGetName() { diff --git a/tests/3-unit/PluginFormcreatorIssue.php b/tests/3-unit/PluginFormcreatorIssue.php index b3554c487..ec0319d9b 100644 --- a/tests/3-unit/PluginFormcreatorIssue.php +++ b/tests/3-unit/PluginFormcreatorIssue.php @@ -43,6 +43,7 @@ use Search; use CommonITILObject; use ValidatorSubstitute; +use TicketValidation; class PluginFormcreatorIssue extends CommonTestCase { public function beforeTestMethod($method) { @@ -60,11 +61,11 @@ public function providerGetsyncIssuesRequest_simpleTicket() { $ticket = $this->getGlpiCoreItem(Ticket::class, [ 'name' => 'simple ticket', 'content' => 'foo', - 'status' => \Ticket::INCOMING, + 'status' => Ticket::INCOMING, '_actors' => [ 'requester' => [ - 0 => ['itemtype' => \User::class, - 'items_id' => 2, // glpi + 0 => ['itemtype' => User::class, + 'items_id' => User::getIdByName('glpi'), // glpi 'use_notification' => 1, 'alternative_email' => '', ] @@ -77,11 +78,11 @@ public function providerGetsyncIssuesRequest_simpleTicket() { $ticket2 = $this->getGlpiCoreItem(Ticket::class, [ 'name' => '', 'content' => 'foo', - 'status' => \Ticket::INCOMING, + 'status' => Ticket::INCOMING, '_actors' => [ 'requester' => [ - 0 => ['itemtype' => \User::class, - 'items_id' => 2, // glpi + 0 => ['itemtype' => User::class, + 'items_id' => User::getIdByName('glpi'), // glpi 'use_notification' => 1, 'alternative_email' => '', ] @@ -99,7 +100,7 @@ public function providerGetsyncIssuesRequest_simpleTicket() { 'simpleTicket' => [ 'item' => $ticket, 'expected' => [ - 'itemtype' => \Ticket::getType(), + 'itemtype' => Ticket::getType(), 'items_id' => $ticket->getID(), 'display_id' => 't_' . $ticket->getID(), 'name' => $ticket->fields['name'], @@ -112,7 +113,7 @@ public function providerGetsyncIssuesRequest_simpleTicket() { 'simpleTicket_without_name' => [ 'item' => $ticket2, 'expected' => [ - 'itemtype' => \Ticket::getType(), + 'itemtype' => Ticket::getType(), 'items_id' => $ticket2->getID(), 'display_id' => 't_' . $ticket2->getID(), 'name' => '(' . $ticket2->getID() . ')', @@ -129,7 +130,7 @@ public function providerGetsyncIssuesRequest_simpleFormanswers() { $form = $this->getForm([ 'formanswer_name' => $this->getUniqueString(), ]); - $formAnswer = new \PluginFormcreatorFormAnswer(); + $formAnswer = new PluginFormcreatorFormAnswer(); $formAnswer->add([ 'plugin_formcreator_forms_id' => $form->getID(), ]); @@ -140,7 +141,7 @@ public function providerGetsyncIssuesRequest_simpleFormanswers() { 'simpleFormanswers' => [ 'item' => $formAnswer, 'expected' => [ - 'itemtype' => \PluginFormcreatorFormAnswer::getType(), + 'itemtype' => PluginFormcreatorFormAnswer::getType(), 'items_id' => $formAnswer->getID(), 'display_id' => 'f_' . $formAnswer->getID(), 'name' => $formAnswer->fields['name'], @@ -163,14 +164,14 @@ public function providerGetSyncIssuesRequest_formAnswerWithOneTicket() { ]); $this->boolean($targetTicket1->isNewItem())->isFalse(); - $formAnswer = new \PluginFormcreatorFormAnswer(); + $formAnswer = new PluginFormcreatorFormAnswer(); $formAnswer->add([ 'plugin_formcreator_forms_id' => $form->getID(), ]); $this->boolean($formAnswer->isNewItem())->isFalse(); $formAnswer->getFromDB($formAnswer->getID()); $ticket = array_shift($formAnswer->targetList); - $this->object($ticket)->isInstanceOf(\Ticket::getType()); + $this->object($ticket)->isInstanceOf(Ticket::getType()); // case 2 // Add business rules to add 2 validators @@ -199,7 +200,7 @@ public function providerGetSyncIssuesRequest_formAnswerWithOneTicket() { 'field' => 'users_id_validate', 'value' => User::getIdByName('normal'), ]); - $formAnswer = new \PluginFormcreatorFormAnswer(); + $formAnswer = new PluginFormcreatorFormAnswer(); $formAnswer->add([ 'plugin_formcreator_forms_id' => $form->getID(), ]); @@ -210,13 +211,13 @@ public function providerGetSyncIssuesRequest_formAnswerWithOneTicket() { $this->boolean($formAnswer->isNewItem())->isFalse(); $formAnswer->getFromDB($formAnswer->getID()); $ticket2 = array_shift($formAnswer->targetList); - $this->object($ticket)->isInstanceOf(\Ticket::getType()); + $this->object($ticket)->isInstanceOf(Ticket::getType()); return [ 'formAnswerWithOneTicket' => [ 'item' => $ticket, 'expected' => [ - 'itemtype' => \Ticket::getType(), + 'itemtype' => Ticket::getType(), 'items_id' => $ticket->getID(), 'display_id' => 't_' . $ticket->getID(), 'name' => $ticket->fields['name'], @@ -229,7 +230,7 @@ public function providerGetSyncIssuesRequest_formAnswerWithOneTicket() { 'formAnswer With One Ticket Having several validators' => [ 'item' => $ticket2, 'expected' => [ - 'itemtype' => \Ticket::getType(), + 'itemtype' => Ticket::getType(), 'items_id' => $ticket2->getID(), 'display_id' => 't_' . $ticket2->getID(), 'name' => $ticket2->fields['name'], @@ -257,7 +258,7 @@ public function providerGetSyncIssuesRequest_formAnswerWithSeveralTickets() { ]); $this->boolean($targetTicket2->isNewItem())->isFalse(); - $formAnswer = new \PluginFormcreatorFormAnswer(); + $formAnswer = new PluginFormcreatorFormAnswer(); $formAnswer->add([ 'plugin_formcreator_forms_id' => $form->getID(), ]); @@ -267,7 +268,7 @@ public function providerGetSyncIssuesRequest_formAnswerWithSeveralTickets() { 'formAnswerWithSeveralTickets' => [ 'item' => $formAnswer, 'expected' => [ - 'itemtype' => \PluginFormcreatorFormAnswer::getType(), + 'itemtype' => PluginFormcreatorFormAnswer::getType(), 'items_id' => $formAnswer->getID(), 'display_id' => 'f_' . $formAnswer->getID(), 'name' => $formAnswer->fields['name'], @@ -289,21 +290,21 @@ public function providerGetSyncIssuesRequest_formAnswerWithOneTickets() { ]); $this->boolean($targetTicket1->isNewItem())->isFalse(); - $formAnswer = new \PluginFormcreatorFormAnswer(); + $formAnswer = new PluginFormcreatorFormAnswer(); $formAnswer->add([ 'plugin_formcreator_forms_id' => $form->getID(), ]); $this->boolean($formAnswer->isNewItem())->isFalse(); $formAnswer->getFromDB($formAnswer->getID()); - /** @var \Ticket */ + /** @var Ticket */ $ticket = array_pop($formAnswer->targetList); - $this->object($ticket)->isInstanceOf(\Ticket::class); + $this->object($ticket)->isInstanceOf(Ticket::class); return [ 'formAnswerWithOneTickets' => [ 'item' => $formAnswer, 'expected' => [ - 'itemtype' => \PluginFormcreatorFormAnswer::getType(), + 'itemtype' => PluginFormcreatorFormAnswer::getType(), 'items_id' => $ticket->getID(), 'display_id' => 't_' . $ticket->getID(), 'name' => $formAnswer->fields['name'], @@ -326,10 +327,10 @@ public function providerGetSyncIssuesRequest_formanswerUnderValidation() { ]); $this->boolean($formValidator->isNewItem())->isFalse(); - $formAnswer = new \PluginFormcreatorFormAnswer(); + $formAnswer = new PluginFormcreatorFormAnswer(); $formAnswer->add([ 'plugin_formcreator_forms_id' => $form->getID(), - 'formcreator_validator' => 4 // Tech + 'formcreator_validator' => User::getIdByName('tech') // Tech ]); $this->boolean($formAnswer->isNewItem())->isFalse(); $formAnswer->getFromDB($formAnswer->getID()); @@ -338,7 +339,7 @@ public function providerGetSyncIssuesRequest_formanswerUnderValidation() { 'formanswerUnderValidation' => [ 'item' => $formAnswer, 'expected' => [ - 'itemtype' => \PluginFormcreatorFormAnswer::getType(), + 'itemtype' => PluginFormcreatorFormAnswer::getType(), 'items_id' => $formAnswer->getID(), 'display_id' => 'f_' . $formAnswer->getID(), 'name' => $formAnswer->fields['name'], @@ -355,14 +356,14 @@ public function providerGetsyncIssuesRequest_ticketUnderValidation() { $ticket = $this->getGlpiCoreItem(Ticket::class, [ 'name' => 'a ticket', 'content' => 'foo', - 'status' => \Ticket::INCOMING, + 'status' => Ticket::INCOMING, '_add_validation' => '0', 'validatortype' => User::class, - 'users_id_validate' => [4], // Tech + 'users_id_validate' => [User::getIdByName('tech')], // Tech '_actors' => [ 'requester' => [ - 0 => ['itemtype' => \User::class, - 'items_id' => 2, // glpi + 0 => ['itemtype' => User::class, + 'items_id' => User::getIdByName('glpi'), // glpi 'use_notification' => 1, 'alternative_email' => '', ] @@ -376,11 +377,11 @@ public function providerGetsyncIssuesRequest_ticketUnderValidation() { 'ticketUnderValidation' => [ 'item' => $ticket, 'expected' => [ - 'itemtype' => \Ticket::getType(), + 'itemtype' => Ticket::getType(), 'items_id' => $ticket->getID(), 'display_id' => 't_' . $ticket->getID(), 'name' => $ticket->fields['name'], - 'status' => \PluginFormcreatorFormAnswer::STATUS_WAITING, + 'status' => PluginFormcreatorFormAnswer::STATUS_WAITING, 'requester_id' => $ticket->fields['users_id_recipient'], 'date_creation' => $ticket->fields['date'], 'date_mod' => $ticket->fields['date_mod'], @@ -393,14 +394,14 @@ public function providerGetsyncIssuesRequest_validatedTicket() { $ticket = $this->getGlpiCoreItem(Ticket::class, [ 'name' => 'a ticket', 'content' => 'foo', - 'status' => \Ticket::INCOMING, + 'status' => Ticket::INCOMING, '_add_validation' => '0', 'validatortype' => User::class, 'users_id_validate' => [4], // Tech '_actors' => [ 'requester' => [ - 0 => ['itemtype' => \User::class, - 'items_id' => 2, // glpi + 0 => ['itemtype' => User::class, + 'items_id' => User::getIdByName('glpi'), // glpi 'use_notification' => 1, 'alternative_email' => '', ] @@ -411,26 +412,26 @@ public function providerGetsyncIssuesRequest_validatedTicket() { $ticket->getFromDB($ticket->getID()); // Validate the ticket - $ticketValidation = new \TicketValidation(); + $ticketValidation = new TicketValidation(); $ticketValidation->getFromDBByCrit([ 'tickets_id' => $ticket->getID(), ]); $this->boolean($ticketValidation->isNewItem())->isFalse(); $ticketValidation->update([ 'id' => $ticketValidation->getID(), - 'status' => \TicketValidation::ACCEPTED + 'status' => TicketValidation::ACCEPTED ]); $ticket2 = $this->getGlpiCoreItem(Ticket::class, [ 'name' => 'a ticket', 'content' => 'foo', - 'status' => \Ticket::INCOMING, + 'status' => Ticket::INCOMING, '_add_validation' => '0', 'validatortype' => User::class, 'users_id_validate' => [User::getIdByName('tech'), User::getIdByName('normal')], // Tech '_actors' => [ 'requester' => [ - 0 => ['itemtype' => \User::class, + 0 => ['itemtype' => User::class, 'items_id' => User::getIdByName('glpi'), // glpi 'use_notification' => 1, 'alternative_email' => '', @@ -445,11 +446,11 @@ public function providerGetsyncIssuesRequest_validatedTicket() { 'validatedTicket' => [ 'item' => $ticket, 'expected' => [ - 'itemtype' => \Ticket::getType(), + 'itemtype' => Ticket::getType(), 'items_id' => $ticket->getID(), 'display_id' => 't_' . $ticket->getID(), 'name' => $ticket->fields['name'], - 'status' => \Ticket::INCOMING, + 'status' => Ticket::INCOMING, 'requester_id' => $ticket->fields['users_id_recipient'], 'date_creation' => $ticket->fields['date'], 'date_mod' => $ticket->fields['date_mod'], @@ -458,7 +459,7 @@ public function providerGetsyncIssuesRequest_validatedTicket() { 'ticket with multiple validators' => [ 'item' => $ticket2, 'expected' => [ - 'itemtype' => \Ticket::getType(), + 'itemtype' => Ticket::getType(), 'items_id' => $ticket2->getID(), 'display_id' => 't_' . $ticket2->getID(), 'name' => $ticket2->fields['name'], @@ -501,7 +502,7 @@ public function providerGetSyncIssuesRequest_FormAnswerWithSeveralRequesters() { ]); $this->boolean($actor2->isNewItem())->isFalse(); - $formAnswer = new \PluginFormcreatorFormAnswer(); + $formAnswer = new PluginFormcreatorFormAnswer(); $formAnswer->add([ 'plugin_formcreator_forms_id' => $form->getID(), ]); @@ -509,12 +510,12 @@ public function providerGetSyncIssuesRequest_FormAnswerWithSeveralRequesters() { $formAnswer->getFromDB($formAnswer->getID()); $ticket = array_shift($formAnswer->targetList); - $this->object($ticket)->isInstanceOf(\Ticket::getType()); + $this->object($ticket)->isInstanceOf(Ticket::getType()); return [ 'formAnswerWithSeveralRequesters' => [ 'item' => $ticket, 'expected' => [ - 'itemtype' => \Ticket::getType(), + 'itemtype' => Ticket::getType(), 'items_id' => $ticket->getID(), 'display_id' => 't_' . $ticket->getID(), 'name' => $ticket->fields['name'], @@ -568,18 +569,18 @@ public function testGetSyncIssuesRequest($item, $expected) { } // Test there are no other rows matching the form answer or ticket - if ($item->getType() == \Ticket::class) { + if ($item->getType() == Ticket::class) { $unwantedItems = $DB->request([ 'SELECT' => ['items_id'], 'FROM' => \Item_Ticket::getTable(), 'WHERE' => [ - 'itemtype' => \PluginFormcreatorFormAnswer::getType(), + 'itemtype' => PluginFormcreatorFormAnswer::getType(), 'tickets_id' => $item->getID(), ], ]); if (count($unwantedItems) > 0) { $unwantedWhere = [ - 'itemtype' => \PluginFormcreatorFormAnswer::getType(), + 'itemtype' => PluginFormcreatorFormAnswer::getType(), ]; foreach ($unwantedItems as $row) { $unwantedWhere['items_id'][] = $row['items_id']; @@ -592,18 +593,18 @@ public function testGetSyncIssuesRequest($item, $expected) { $this->integer(count($result))->isEqualTo(0); } } - if ($item->getType() == \PluginFormcreatorFormAnswer::class) { + if ($item->getType() == PluginFormcreatorFormAnswer::class) { $unwantedItems = $DB->request([ 'SELECT' => ['tickets_id'], 'FROM' => \Item_Ticket::getTable(), 'WHERE' => [ - 'itemtype' => \PluginFormcreatorFormAnswer::getType(), + 'itemtype' => PluginFormcreatorFormAnswer::getType(), 'items_id' => $item->getID(), ], ]); if (count($unwantedItems) > 0) { $unwantedWhere = [ - 'itemtype' => \Ticket::getType(), + 'itemtype' => Ticket::getType(), ]; foreach ($unwantedItems as $row) { $unwantedWhere['items_id'][] = $row['tickets_id']; @@ -628,7 +629,7 @@ public function testUpdateDateModOnNewFollowup() { $issue = new \PluginFormcreatorISsue(); $issue->getFromDBByCrit([ - 'itemtype' => \Ticket::getType(), + 'itemtype' => Ticket::getType(), 'items_id' => $ticket->getID(), ]); $this->boolean($issue->isNewItem())->isFalse(); @@ -639,12 +640,12 @@ public function testUpdateDateModOnNewFollowup() { $this->login('glpi', 'glpi'); // Needed to update the current datetime in session $followup = new \ITILFollowup(); $followup->add([ - 'itemtype' => \Ticket::getType(), + 'itemtype' => Ticket::getType(), 'items_id' => $ticket->getID(), 'content' => 'bar' ]); $this->boolean($followup->isNewItem())->isFalse(); - $ticket = new \Ticket(); + $ticket = new Ticket(); $ticket->getFromDB($issue->fields['items_id']); $this->boolean($ticket->isNewItem())->isFalse(); $this->string($ticket->fields['date_mod'])->isNotEqualTo($creationDate); @@ -652,7 +653,7 @@ public function testUpdateDateModOnNewFollowup() { $issue = new \PluginFormcreatorISsue(); $issue->getFromDBByCrit([ - 'itemtype' => \Ticket::getType(), + 'itemtype' => Ticket::getType(), 'items_id' => $ticket->getID(), ]); $this->string($issue->fields['date_creation'])->isEqualTo($creationDate);