From 970c0aa485c530b2209567dbb332d339c62f5408 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 14 Aug 2018 18:00:50 +0200 Subject: [PATCH 001/192] chore: make the branch unofficial release Signed-off-by: btry --- setup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.php b/setup.php index 71a07f15b..277e7895f 100644 --- a/setup.php +++ b/setup.php @@ -37,7 +37,7 @@ // Schema version of this version define('PLUGIN_FORMCREATOR_SCHEMA_VERSION', '2.6'); // is or is not an official release of the plugin -define('PLUGIN_FORMCREATOR_IS_OFFICIAL_RELEASE', true); +define('PLUGIN_FORMCREATOR_IS_OFFICIAL_RELEASE', false); // Minimal GLPI version, inclusive From 2c0f4bc73e552f336ab6512a7d09e871417def65 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 31 Oct 2017 09:27:47 +0100 Subject: [PATCH 002/192] refactor(question): full redesign of question parameters schema --- front/form_answer.form.php | 2 +- front/question.form.php | 2 + inc/answer.class.php | 4 +- inc/category.class.php | 1 - inc/common.class.php | 2 +- inc/entityconfig.class.php | 2 +- inc/exportableinterface.class.php | 5 + inc/field.class.php | 69 ++- inc/fieldinterface.class.php | 46 +- inc/fields.class.php | 37 +- inc/fields/checkboxesfield.class.php | 57 ++- inc/fields/floatfield.class.php | 104 ++++- inc/fields/integerfield.class.php | 104 ++++- inc/fields/multiselectfield.class.php | 45 +- inc/fields/textfield.class.php | 87 +++- inc/form.class.php | 135 +++++- inc/form_answer.class.php | 15 +- inc/importlinker.class.php | 54 +++ inc/issue.class.php | 2 - inc/question.class.php | 419 ++++++++++++------ inc/question_condition.class.php | 42 +- inc/questiondependency.class.php | 140 ++++++ inc/questionparameter.class.php | 139 ++++++ inc/questionparameterinterface.class.php | 30 ++ inc/questionrange.class.php | 83 ++++ inc/questionregex.class.php | 79 ++++ inc/section.class.php | 72 ++- inc/target.class.php | 4 +- inc/target_actor.class.php | 2 +- inc/targetbase.class.php | 18 +- inc/targetchange.class.php | 4 +- inc/targetticket.class.php | 6 +- install/install.php | 7 + install/mysql/plugin_formcreator_empty.sql | 34 +- install/update_2.6.2_2.6.3.php | 4 - install/update_2.6_2.7.php | 90 ++++ setup.php | 1 - tests/0000_Install/PluginInstallTest.php | 5 +- tests/0005_Unit/CheckboxesFieldTest.php | 221 +++++---- tests/0005_Unit/FloatFieldTest.php | 23 +- tests/0005_Unit/IntegerFieldTest.php | 248 +++++++---- tests/0005_Unit/MultiselectFieldTest.php | 209 +++++---- tests/0005_Unit/QuestionTest.php | 82 ++++ tests/0005_Unit/Question_ConditionTest.php | 53 ++- tests/0005_Unit/TextFieldTest.php | 169 +++++++ tests/0010_Integration/CloneTest.php | 33 +- tests/0010_Integration/ExportImportTest.php | 47 +- .../0010_Integration/FormDuplicationTest.php | 134 ++++-- .../QuestionConditionTest.php | 2 +- tests/0010_Integration/QuestionTest.php | 94 ---- 50 files changed, 2580 insertions(+), 687 deletions(-) create mode 100644 inc/exportableinterface.class.php create mode 100644 inc/importlinker.class.php create mode 100644 inc/questiondependency.class.php create mode 100644 inc/questionparameter.class.php create mode 100644 inc/questionparameterinterface.class.php create mode 100644 inc/questionrange.class.php create mode 100644 inc/questionregex.class.php create mode 100644 install/update_2.6_2.7.php create mode 100644 tests/0005_Unit/QuestionTest.php create mode 100644 tests/0005_Unit/TextFieldTest.php delete mode 100644 tests/0010_Integration/QuestionTest.php diff --git a/front/form_answer.form.php b/front/form_answer.form.php index ba6edbea9..83413f539 100644 --- a/front/form_answer.form.php +++ b/front/form_answer.form.php @@ -62,7 +62,7 @@ } else if (isset($_POST['save_formanswer'])) { $_POST['plugin_formcreator_forms_id'] = intval($_POST['formcreator_form']); - $_POST['status'] = 'waiting'; + $_POST['status'] = 'waiting'; $formanswer->saveAnswers($_POST); if (plugin_formcreator_replaceHelpdesk()) { $issue = new PluginFormcreatorIssue(); diff --git a/front/question.form.php b/front/question.form.php index 94288c4ab..bd0b02e75 100644 --- a/front/question.form.php +++ b/front/question.form.php @@ -50,6 +50,7 @@ Session::addMessageAfterRedirect(__('The question has been successfully saved!', 'formcreator'), true, INFO); $_POST['id'] = $newid; $question->updateConditions($_POST); + $question->updateParameters($_POST); } Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']); @@ -59,6 +60,7 @@ if ($question->update($_POST)) { Session::addMessageAfterRedirect(__('The question has been successfully updated!', 'formcreator'), true, INFO); $question->updateConditions($_POST); + $question->updateParameters($_POST); } Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']); diff --git a/inc/answer.class.php b/inc/answer.class.php index 067648c89..8f8367168 100644 --- a/inc/answer.class.php +++ b/inc/answer.class.php @@ -75,7 +75,7 @@ public static function getTypeName($nb = 0) { * @param array $input data used to add the item * * @return array the modified $input array - **/ + */ public function prepareInputForAdd($input) { global $DB; @@ -107,7 +107,7 @@ public function prepareInputForAdd($input) { * @param array $input data used to add the item * * @return array the modified $input array - **/ + */ public function prepareInputForUpdate($input) { return $this->prepareInputForAdd($input); } diff --git a/inc/category.class.php b/inc/category.class.php index 6c8205f1e..bce7b1ebf 100644 --- a/inc/category.class.php +++ b/inc/category.class.php @@ -58,7 +58,6 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ } /** - * {@inheritDoc} * @see CommonTreeDropdown::getAdditionalFields() */ public function getAdditionalFields() { diff --git a/inc/common.class.php b/inc/common.class.php index b098e8508..1a3052fea 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -77,7 +77,7 @@ public static function getGlpiVersion() { * @param boolean $inverted Whether to invert label * * @return string - **/ + */ public static function getLinkName($value, $inverted = false) { $tmp = []; diff --git a/inc/entityconfig.class.php b/inc/entityconfig.class.php index d47851730..708858f58 100644 --- a/inc/entityconfig.class.php +++ b/inc/entityconfig.class.php @@ -140,7 +140,7 @@ public function showFormForEntity(Entity $entity) { * @param $entities_id * @param $fieldval string name of the field that we want value (default '') * @param $default_value integer value to return (default -2) - **/ + */ static function getUsedConfig($fieldref, $entities_id, $fieldval='', $default_value=-2) { // for calendar diff --git a/inc/exportableinterface.class.php b/inc/exportableinterface.class.php new file mode 100644 index 000000000..bc1fc1da9 --- /dev/null +++ b/inc/exportableinterface.class.php @@ -0,0 +1,5 @@ +fields = $fields; @@ -128,14 +130,15 @@ public function displayField($canEdit = true) { } } + /** + * Gets the label of the field + * + * @return string + */ public function getLabel() { return $this->fields['name']; } - public function getField() { - - } - public function getValue() { if (isset($this->fields['answer'])) { if (!is_array($this->fields['answer']) && is_array(json_decode($this->fields['answer']))) { @@ -208,4 +211,58 @@ protected function trimValue($value) { return implode('\\r\\n', $value); } + public function getFieldTypeName() { + $classname = get_called_class(); + $matches = null; + preg_match("#^PluginFormcreator(.+)Field$#", $classname, $matches); + return strtolower($matches[1]); + } + + public function getUsedParameters() { + return []; + } + + public final function addParameters(PluginFormcreatorQuestion $question, array $input) { + $fieldTypeName = $this->getFieldTypeName(); + if (!isset($input['_parameters'][$fieldTypeName])) { + return; + } + + foreach ($this->getUsedParameters() as $fieldName => $parameter) { + $input['_parameters'][$fieldTypeName][$fieldName]['plugin_formcreator_questions_id'] = $question->getID(); + $parameter->add($input['_parameters'][$fieldTypeName][$fieldName]); + } + } + + public final function updateParameters(PluginFormcreatorQuestion $question, array $input) { + $fieldTypeName = $this->getFieldTypeName(); + if (!isset($input['_parameters'][$fieldTypeName])) { + return; + } + + foreach ($this->getUsedParameters() as $fieldName => $parameter) { + $parameter->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $question->getID(), + 'fieldname' => $fieldName, + ]); + $input['_parameters'][$fieldTypeName][$fieldName]['plugin_formcreator_questions_id'] = $question->getID(); + if ($parameter->isNewItem()) { + // In case of the parameter vanished in DB, just recreate it + $parameter->add($input['_parameters'][$fieldTypeName][$fieldName]); + } else { + $input['_parameters'][$fieldTypeName][$fieldName]['id'] = $parameter->getID(); + $parameter->update($input['_parameters'][$fieldTypeName][$fieldName]); + } + } + } + + public final function deleteParameters(PluginFormcreatorQuestion $question) { + foreach ($this->getUsedParameters() as $parameter) { + if (!$parameter->deleteByCriteria(['plugin_formcreator_questions_id' => $question->getID()])) { + // Don't make this error fatal, but log it anyway + Toolbox::logInFile('php-errors', 'failed to delete parameter for question ' . $question->getID() . PHP_EOL); + } + } + return true; + } } diff --git a/inc/fieldinterface.class.php b/inc/fieldinterface.class.php index 20a1eb0c5..41abbf129 100644 --- a/inc/fieldinterface.class.php +++ b/inc/fieldinterface.class.php @@ -35,10 +35,21 @@ die("Sorry. You can't access this file directly"); } -interface PluginFormcreatorFieldInterface { +interface PluginFormcreatorFieldInterface +{ + /** + * gets the localized name of the field + * @return string + */ public static function getName(); public static function getPrefs(); public static function getJSFields(); + + /** + * Transform input to properly save it in the database + * @param array $input data to transform before save + * @return array|false input data to save or false if data is rejected + */ public function prepareQuestionInputForSave($input); public function prepareQuestionInputForTarget($input); @@ -49,4 +60,37 @@ public function prepareQuestionInputForTarget($input); * @return string */ public function prepareQuestionValuesForEdit($input); + + /** + * Gets the parameters of the field + * @return PluginFormcreatorQuestionParameter[] + */ + public function getUsedParameters(); + + /** + * Gets the name of the field type + * @return string + */ + public function getFieldTypeName(); + + /** + * Adds parameters of the field into the database + * @param PluginFormcreatorQuestion $question question of the field + * @param array $input data of parameters + */ + public function addParameters(PluginFormcreatorQuestion $question, array $input); + + /** + * Updates parameters of the field into the database + * @param PluginFormcreatorQuestion $question question of the field + * @param array $input data of parameters + */ + public function updateParameters(PluginFormcreatorQuestion $question, array $input); + + /** + * Deletes all parameters of the field applied to the question + * @param PluginFormcreatorQuestion $question + * @return boolean true if success, false otherwise + */ + public function deleteParameters(PluginFormcreatorQuestion $question); } diff --git a/inc/fields.class.php b/inc/fields.class.php index 175e30657..433d99c3c 100644 --- a/inc/fields.class.php +++ b/inc/fields.class.php @@ -37,9 +37,12 @@ class PluginFormcreatorFields { + + private $types = null; /** - * Retrieve all field types and file path - * @return Array field_type => File_path + * Retrive all field types and file path + * + * @return array field_type => File_path */ public static function getTypes() { $tab_field_types = []; @@ -56,13 +59,31 @@ public static function getTypes() { return $tab_field_types; } + /** + * Gets classe names of all known field types + * + * @return array field_type => classname + */ + public static function getClasses() { + $classes = []; + foreach (glob(dirname(__FILE__).'/fields/*field.class.php') as $class_file) { + $matches = null; + preg_match("#fields/(.+)field\.class.php$#", $class_file, $matches); + $classname = 'PluginFormcreator' . ucfirst($matches[1]) . 'Field'; + if (class_exists($classname)) { + $classes[strtolower($matches[1])] = $classname; + } + } + + return $classes; + } + /** * Get type and name of all field types * @return Array field_type => Name */ public static function getNames() { // Get field types and file path - $tab_field_types = self::getTypes(); $plugin = new Plugin(); // Initialize array @@ -70,9 +91,8 @@ public static function getNames() { $tab_field_types_name[''] = '---'; // Get localized names of field types - foreach (array_keys($tab_field_types) as $field_type) { + foreach (PluginFormcreatorFields::getClasses() as $field_type => $classname) { $classname = 'PluginFormcreator' . ucfirst($field_type) . 'Field'; - if ($classname == 'PluginFormcreatorTagField' && !$plugin->isActivated('tag')) { continue; } @@ -102,9 +122,10 @@ public static function printAllTabFieldsForJS() { } /** - * @param unknown $field - * @param unknown $data - * @param string $edit + * + * @param array $field fields of a PluginFormcreatorQuestion instance + * @param mixed|null $data + * @param boolean $edit */ public static function showField($field, $data = null, $edit = true) { // Get field types and file path diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index 3cb018a7f..e5f1df9b2 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -108,23 +108,42 @@ public function isValid($value) { false, ERROR); return false; + } - // Min range not set or number of selected item lower than min - } else if (!empty($this->fields['range_min']) && (count($value) < $this->fields['range_min'])) { - $message = sprintf(__('The following question needs of at least %d answers', 'formcreator'), $this->fields['range_min']); - Session::addMessageAfterRedirect($message . ' ' . $this->getLabel(), false, ERROR); + if (!$this->isValidValue($value)) { return false; + } - // Max range not set or number of selected item greater than max - } else if (!empty($this->fields['range_max']) && (count($value) > $this->fields['range_max'])) { - $message = sprintf(__('The following question does not accept more than %d answers', 'formcreator'), $this->fields['range_max']); - Session::addMessageAfterRedirect($message . ' ' . $this->getLabel(), false, ERROR); - return false; + return true; + } - // All is OK - } else { - return true; + private function isValidValue($value) { + $parameters = $this->getUsedParameters(); + foreach ($parameters as $fieldname => $parameter) { + $parameter->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $this->fields['id'], + 'fieldname' => $fieldname, + ]); } + + // Check the field matches the format regex + if (!$parameters['range']->isNewItem()) { + $rangeMin = $parameters['range']->getField('range_min'); + $rangeMax = $parameters['range']->getField('range_max'); + if (strlen($rangeMin) > 0 && count($value) < $rangeMin) { + $message = sprintf(__('The following question needs of at least %d answers', 'formcreator'), $rangeMin); + Session::addMessageAfterRedirect($message . ' ' . $this->getLabel(), false, ERROR); + return false; + } + + if (strlen($rangeMax) > 0 && count($value) > $rangeMax) { + $message = sprintf(__('The following question does not accept more than %d answers', 'formcreator'), $rangeMax); + Session::addMessageAfterRedirect($message . ' ' . $this->getLabel(), false, ERROR); + return false; + } + } + + return true; } public static function getName() { @@ -211,4 +230,18 @@ public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['checkboxes'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + public function getUsedParameters() { + return [ + 'range' => new PluginFormcreatorQuestionRange( + $this, + [ + 'fieldName' => 'range', + 'label' => __('Range', 'formcreator'), + 'fieldType' => ['text'], + ] + ), + ]; + } + } diff --git a/inc/fields/floatfield.class.php b/inc/fields/floatfield.class.php index 720175156..dd07ad3c6 100644 --- a/inc/fields/floatfield.class.php +++ b/inc/fields/floatfield.class.php @@ -38,32 +38,56 @@ public function isValid($value) { return false; } - // Not a number + if (!$this->isValidValue($value)) { + return false; + } + + return true; + } + + private function isValidValue($value) { if (!empty($value) && !is_numeric($value)) { Session::addMessageAfterRedirect(__('This is not a number:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); return false; + } - // Min range not set or text length longer than min length - } else if (!empty($this->fields['range_min']) && ($value < $this->fields['range_min'])) { - $message = sprintf(__('The following number must be greater than %d:', 'formcreator'), $this->fields['range_min']); - Session::addMessageAfterRedirect($message . ' ' . $this->fields['name'], false, ERROR); - return false; + $parameters = $this->getUsedParameters(); + foreach ($parameters as $fieldname => $parameter) { + $parameter->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $this->fields['id'], + 'fieldname' => $fieldname, + ]); + } - // Max range not set or text length shorter than max length - } else if (!empty($this->fields['range_max']) && ($value > $this->fields['range_max'])) { - $message = sprintf(__('The following number must be lower than %d:', 'formcreator'), $this->fields['range_max']); - Session::addMessageAfterRedirect($message . ' ' . $this->fields['name'], false, ERROR); - return false; + // Check the field matches the format regex + if (!$parameters['regex']->isNewItem()) { + $regex = $parameters['regex']->getField('regex'); + if ($regex !== null && strlen($regex) > 0) { + if (!preg_match($regex, $value)) { + Session::addMessageAfterRedirect(__('Specific format does not match:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); + return false; + } + } + } - // Specific format not set or well match - } else if (!empty($this->fields['regex']) && !preg_match($this->fields['regex'], $value)) { - Session::addMessageAfterRedirect(__('Specific format does not match:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); - return false; + // Check the field is in the range + if (!$parameters['range']->isNewItem()) { + $rangeMin = $parameters['range']->getField('range_min'); + $rangeMax = $parameters['range']->getField('range_max'); + if (strlen($rangeMin) > 0 && $value < $rangeMin) { + $message = sprintf(__('The following number must be greater than %d:', 'formcreator'), $rangeMin); + Session::addMessageAfterRedirect($message . ' ' . $this->fields['name'], false, ERROR); + return false; + } - // All is OK - } else { - return true; + if (strlen($rangeMax) > 0 && $value > $rangeMax) { + $message = sprintf(__('The following number must be lower than %d:', 'formcreator'), $rangeMax); + Session::addMessageAfterRedirect($message . ' ' . $this->fields['name'], false, ERROR); + return false; + } } + + return true; } public static function getName() { @@ -71,6 +95,24 @@ public static function getName() { } public function prepareQuestionInputForSave($input) { + $success = true; + $fieldType = $this->getFieldTypeName(); + // Add leading and trailing regex marker automaticaly + if (isset($input['_parameters'][$fieldType]['regex']['regex']) && !empty($input['_parameters'][$fieldType]['regex']['regex'])) { + // Avoid php notice when validating the regular expression + set_error_handler(function($errno, $errstr, $errfile, $errline, $errcontext) {}); + $isValid = !(preg_match($input['_parameters'][$fieldType]['regex']['regex'], null) === false); + restore_error_handler(); + + if (!$isValid) { + Session::addMessageAfterRedirect(__('The regular expression is invalid', 'formcreator'), false, ERROR); + $success = false; + } + } + if (!$success) { + return false; + } + if (isset($input['range_min']) && isset($input['range_max']) && isset($input['default_values'])) { @@ -106,4 +148,30 @@ public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['float'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + public function getUsedParameters() { + $regexDoc = ''; + $regexDoc.= ''; + $regexDoc.= '('.__('Regular expression', 'formcreator').')'; + $regexDoc.= ''; + return [ + 'regex' => new PluginFormcreatorQuestionRegex( + $this, + [ + 'fieldName' => 'regex', + 'label' => __('Additional validation', 'formcreator') . $regexDoc, + 'fieldType' => ['text'], + ] + ), + 'range' => new PluginFormcreatorQuestionRange( + $this, + [ + 'fieldName' => 'range', + 'label' => __('Range', 'formcreator'), + 'fieldType' => ['text'], + ] + ), + ]; + } + } diff --git a/inc/fields/integerfield.class.php b/inc/fields/integerfield.class.php index fb129e59c..f1fe4a107 100644 --- a/inc/fields/integerfield.class.php +++ b/inc/fields/integerfield.class.php @@ -38,32 +38,56 @@ public function isValid($value) { return false; } - // Not a number + if (!$this->isValidValue($value)) { + return false; + } + + return true; + } + + private function isValidValue($value) { if (!empty($value) && !ctype_digit($value)) { Session::addMessageAfterRedirect(__('This is not an integer:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); return false; + } - // Min range not set or text length longer than min length - } else if (!empty($this->fields['range_min']) && ($value < $this->fields['range_min'])) { - $message = sprintf(__('The following number must be greater than %d:', 'formcreator'), $this->fields['range_min']); - Session::addMessageAfterRedirect($message . ' ' . $this->fields['name'], false, ERROR); - return false; + $parameters = $this->getUsedParameters(); + foreach ($parameters as $fieldname => $parameter) { + $parameter->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $this->fields['id'], + 'fieldname' => $fieldname, + ]); + } - // Max range not set or text length shorter than max length - } else if (!empty($this->fields['range_max']) && ($value > $this->fields['range_max'])) { - $message = sprintf(__('The following number must be lower than %d:', 'formcreator'), $this->fields['range_max']); - Session::addMessageAfterRedirect($message . ' ' . $this->fields['name'], false, ERROR); - return false; + // Check the field matches the format regex + if (!$parameters['regex']->isNewItem()) { + $regex = $parameters['regex']->getField('regex'); + if ($regex !== null && strlen($regex) > 0) { + if (!preg_match($regex, $value)) { + Session::addMessageAfterRedirect(__('Specific format does not match:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); + return false; + } + } + } - // Specific format not set or well match - } else if (!empty($this->fields['regex']) && !preg_match($this->fields['regex'], $value)) { - Session::addMessageAfterRedirect(__('Specific format does not match:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); - return false; + // Check the field is in the range + if (!$parameters['range']->isNewItem()) { + $rangeMin = $parameters['range']->getField('range_min'); + $rangeMax = $parameters['range']->getField('range_max'); + if (strlen($rangeMin) > 0 && $value < $rangeMin) { + $message = sprintf(__('The following number must be greater than %d:', 'formcreator'), $rangeMin); + Session::addMessageAfterRedirect($message . ' ' . $this->fields['name'], false, ERROR); + return false; + } - // All is OK - } else { - return true; + if (strlen($rangeMax) > 0 && $value > $rangeMax) { + $message = sprintf(__('The following number must be lower than %d:', 'formcreator'), $rangeMax); + Session::addMessageAfterRedirect($message . ' ' . $this->fields['name'], false, ERROR); + return false; + } } + + return true; } public static function getName() { @@ -71,6 +95,24 @@ public static function getName() { } public function prepareQuestionInputForSave($input) { + $success = true; + $fieldType = $this->getFieldTypeName(); + // Add leading and trailing regex marker automaticaly + if (isset($input['_parameters'][$fieldType]['regex']['regex']) && !empty($input['_parameters'][$fieldType]['regex']['regex'])) { + // Avoid php notice when validating the regular expression + set_error_handler(function($errno, $errstr, $errfile, $errline, $errcontext) {}); + $isValid = !(preg_match($input['_parameters'][$fieldType]['regex']['regex'], null) === false); + restore_error_handler(); + + if (!$isValid) { + Session::addMessageAfterRedirect(__('The regular expression is invalid', 'formcreator'), false, ERROR); + $success = false; + } + } + if (!$success) { + return false; + } + if (isset($input['range_min']) && isset($input['range_max']) && isset($input['default_values'])) { @@ -106,4 +148,30 @@ public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['integer'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + public function getUsedParameters() { + $regexDoc = ''; + $regexDoc.= ''; + $regexDoc.= '('.__('Regular expression', 'formcreator').')'; + $regexDoc.= ''; + return [ + 'regex' => new PluginFormcreatorQuestionRegex( + $this, + [ + 'fieldName' => 'regex', + 'label' => __('Additional validation', 'formcreator') . $regexDoc, + 'fieldType' => ['text'], + ] + ), + 'range' => new PluginFormcreatorQuestionRange( + $this, + [ + 'fieldName' => 'range', + 'label' => __('Range', 'formcreator'), + 'fieldType' => ['text'], + ] + ), + ]; + } + } diff --git a/inc/fields/multiselectfield.class.php b/inc/fields/multiselectfield.class.php index b1c5f047d..2a92f9eae 100644 --- a/inc/fields/multiselectfield.class.php +++ b/inc/fields/multiselectfield.class.php @@ -46,20 +46,38 @@ public function isValid($value) { Session::addMessageAfterRedirect(__('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(), false, ERROR); return false; - // Min range not set or number of selected item lower than min - } else if (!empty($this->fields['range_min']) && (count($value) < $this->fields['range_min'])) { - $message = sprintf(__('The following question needs of at least %d answers', 'formcreator'), $this->fields['range_min']); + } + if (!$this->isValidValue($value)) { + return false; + } + + return true; + } + + private function isValidValue($value) { + $parameters = $this->getUsedParameters(); + foreach ($parameters as $fieldname => $parameter) { + $parameter->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $this->fields['id'], + 'fieldname' => $fieldname, + ]); + } + + // Check the field matches the format regex + $rangeMin = $parameters['range']->getField('range_min'); + $rangeMax = $parameters['range']->getField('range_max'); + if (strlen($rangeMin) > 0 && count($value) < $rangeMin) { + $message = sprintf(__('The following question needs of at least %d answers', 'formcreator'), $rangeMin); Session::addMessageAfterRedirect($message . ' ' . $this->getLabel(), false, ERROR); return false; + } - // Max range not set or number of selected item greater than max - } else if (!empty($this->fields['range_max']) && (count($value) > $this->fields['range_max'])) { - $message = sprintf(__('The following question does not accept more than %d answers', 'formcreator'), $this->fields['range_max']); + if (strlen($rangeMax) > 0 && count($value) > $rangeMax) { + $message = sprintf(__('The following question does not accept more than %d answers', 'formcreator'), $rangeMax); Session::addMessageAfterRedirect($message . ' ' . $this->getLabel(), false, ERROR); return false; } - // All is OK return true; } @@ -151,4 +169,17 @@ public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['multiselect'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + public function getUsedParameters() { + return [ + 'range' => new PluginFormcreatorQuestionRange( + $this, + [ + 'fieldName' => 'range', + 'label' => __('Range', 'formcreator'), + 'fieldType' => ['text'], + ] + ), + ]; + } } diff --git a/inc/fields/textfield.class.php b/inc/fields/textfield.class.php index 26dcac6a0..4bba99b71 100644 --- a/inc/fields/textfield.class.php +++ b/inc/fields/textfield.class.php @@ -40,23 +40,45 @@ public function isValid($value) { $value = utf8_decode(stripcslashes($value)); - // Min range not set or text length longer than min length - if (!empty($this->fields['range_min']) && strlen($value) < $this->fields['range_min']) { - Session::addMessageAfterRedirect(sprintf(__('The text is too short (minimum %d characters):', 'formcreator'), $this->fields['range_min']) . ' ' . $this->fields['name'], false, ERROR); + if (!$this->isValidValue($value)) { return false; + } + + // All is OK + return true; + } - // Max range not set or text length shorter than max length - } else if (!empty($this->fields['range_max']) && strlen($value) > $this->fields['range_max']) { - Session::addMessageAfterRedirect(sprintf(__('The text is too long (maximum %d characters):', 'formcreator'), $this->fields['range_max']) . ' ' . $this->fields['name'], false, ERROR); + private function isValidValue($value) { + $parameters = $this->getUsedParameters(); + foreach ($parameters as $fieldname => $parameter) { + $parameter->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $this->fields['id'], + 'fieldname' => $fieldname, + ]); + } + + // Check the field matches the format regex + $regex = $parameters['regex']->getField('regex'); + if ($regex !== null && strlen($regex) > 0) { + if (!preg_match($regex, $value)) { + Session::addMessageAfterRedirect(__('Specific format does not match:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); + return false; + } + } + + // Check the field is in the range + $rangeMin = $parameters['range']->getField('range_min'); + $rangeMax = $parameters['range']->getField('range_max'); + if (strlen($rangeMin) > 0 && strlen($value) < $rangeMin) { + Session::addMessageAfterRedirect(sprintf(__('The text is too short (minimum %d characters):', 'formcreator'), $rangeMin) . ' ' . $this->fields['name'], false, ERROR); return false; + } - // Specific format not set or well match - } else if (!empty($this->fields['regex']) && !preg_match($this->fields['regex'], $value)) { - Session::addMessageAfterRedirect(__('Specific format does not match:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); - return false; + if (strlen($rangeMax) > 0 && strlen($value) > $rangeMax) { + Session::addMessageAfterRedirect(sprintf(__('The text is too short (minimum %d characters):', 'formcreator'), $rangeMax) . ' ' . $this->fields['name'], false, ERROR); + return false; } - // All is OK return true; } @@ -65,6 +87,24 @@ public static function getName() { } public function prepareQuestionInputForSave($input) { + $success = true; + $fieldType = $this->getFieldTypeName(); + // Add leading and trailing regex marker automaticaly + if (isset($input['_parameters'][$fieldType]['regex']['regex']) && !empty($input['_parameters'][$fieldType]['regex']['regex'])) { + // Avoid php notice when validating the regular expression + set_error_handler(function($errno, $errstr, $errfile, $errline, $errcontext) {}); + $isValid = !(preg_match($input['_parameters'][$fieldType]['regex']['regex'], null) === false); + restore_error_handler(); + + if (!$isValid) { + Session::addMessageAfterRedirect(__('The regular expression is invalid', 'formcreator'), false, ERROR); + $success = false; + } + } + if (!$success) { + return false; + } + if (isset($input['default_values'])) { $input['default_values'] = addslashes($input['default_values']); } @@ -90,4 +130,29 @@ public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['text'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + public function getUsedParameters() { + $regexDoc = ''; + $regexDoc.= ''; + $regexDoc.= '('.__('Regular expression', 'formcreator').')'; + $regexDoc.= ''; + return [ + 'regex' => new PluginFormcreatorQuestionRegex( + $this, + [ + 'fieldName' => 'regex', + 'label' => __('Additional validation', 'formcreator') . $regexDoc, + 'fieldType' => ['text'], + ] + ), + 'range' => new PluginFormcreatorQuestionRange( + $this, + [ + 'fieldName' => 'range', + 'label' => __('Range', 'formcreator'), + 'fieldType' => ['text'], + ] + ), + ]; + } } diff --git a/inc/form.class.php b/inc/form.class.php index a85867169..02cd18e64 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -35,7 +35,7 @@ die("Sorry. You can't access this file directly"); } -class PluginFormcreatorForm extends CommonDBTM +class PluginFormcreatorForm extends CommonDBTM implements PluginFormcreatorExportableInterface { static $rightname = 'entity'; @@ -245,7 +245,7 @@ public function rawSearchOptions() { * @param Array $options Options (optional) * * @return String Html string to be displayed for the form field - **/ + */ public static function getSpecificValueToSelect($field, $name='', $values='', array $options=[]) { if (!is_array($values)) { @@ -1063,7 +1063,7 @@ public function prepareInputForAdd($input) { * Actions done after the ADD of the item in the database * * @return void - **/ + */ public function post_addItem() { $this->updateValidators(); return true; @@ -1075,7 +1075,7 @@ public function post_addItem() { * @param array $input data used to add the item * * @return array the modified $input array - **/ + */ public function prepareInputForUpdate($input) { if (isset($input['access_rights']) || isset($_POST['massiveaction']) @@ -1091,7 +1091,7 @@ public function prepareInputForUpdate($input) { * Actions done after the PURGE of the item in the database * * @return void - **/ + */ public function post_purgeItem() { $target = new PluginFormcreatorTarget(); $target->deleteByCriteria(['plugin_formcreator_forms_id' => $this->getID()]); @@ -1231,6 +1231,11 @@ public function increaseUsageCount() { ]); } + /** + * gets a form from database from a question + * + * @param integer $questionId + */ public function getByQuestionId($questionId) { $table_sections = PluginFormcreatorSection::getTable(); $table_questions = PluginFormcreatorQuestion::getTable(); @@ -1322,7 +1327,7 @@ public function duplicate() { } // Form sections - $sectionRows = $form_section->find("`plugin_formcreator_forms_id` = '$old_form_id'"); + $sectionRows = $form_section->find("`plugin_formcreator_forms_id` = '$old_form_id'", "`order` ASC"); foreach ($sectionRows as $sections_id => $sectionRow) { unset($sectionRow['id'], $sectionRow['uuid']); @@ -1332,11 +1337,12 @@ public function duplicate() { } // Form questions - $questionRows = $section_question->find("`plugin_formcreator_sections_id` = '$sections_id'"); + $questionRows = $section_question->find("`plugin_formcreator_sections_id` = '$sections_id'", "`order` ASC"); foreach ($questionRows as $questions_id => $questionRow) { unset($questionRow['id'], $questionRow['uuid']); $questionRow['plugin_formcreator_sections_id'] = $new_sections_id; + $questionRow['_skip_checks'] = true; if (!$new_questions_id = $section_question->add($questionRow)) { return false; } @@ -1346,6 +1352,25 @@ public function duplicate() { } } + // Form questions parameters + foreach ($tab_questions as $questions_id => $new_questions_id) { + $oldQuestion = new PluginFormcreatorQuestion(); + $oldQuestion->getFromDB($questions_id); + $fieldType = 'PluginFormcreator' . ucfirst($oldQuestion->fields['fieldtype']) . 'Field'; + $this->field = new $fieldType($oldQuestion->fields); + $parameters = $this->field->getUsedParameters(); + foreach ($parameters as $fieldName => $parameter) { + $parameter->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $questions_id, + 'fieldname' => $fieldName, + ]); + $newQuestion = new PluginFormcreatorQuestion(); + $newQuestion->getFromDB($new_questions_id); + $parameter = $parameter->duplicate($newQuestion, $tab_questions); + $parameter->add($parameter->fields); + } + } + // Form questions conditions $questionIds = implode("', '", array_keys($tab_questions)); $rows = $question_condition->find("`plugin_formcreator_questions_id` IN ('$questionIds')"); @@ -1550,7 +1575,7 @@ public function transfer($entity) { * @since version 0.85 * * @see CommonDBTM::showMassiveActionsSubForm() - **/ + */ public static function showMassiveActionsSubForm(MassiveAction $ma) { switch ($ma->getAction()) { case 'Transfert': @@ -1569,7 +1594,7 @@ public static function showMassiveActionsSubForm(MassiveAction $ma) { * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() - **/ + */ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'Duplicate' : @@ -1825,12 +1850,18 @@ public function importJson($params = []) { continue; } + $importLinker = new PluginFormcreatorImportLinker(); foreach ($forms_toimport['forms'] as $form) { - self::import($form); + //self::import($form); + self::import($importLinker, $form); + } + if (!$importLinker->importPostponed()) { + Session::addMessageAfterRedirect(sprintf(__("Forms successfully imported from %s", "formcreator"), + $filename)); + } else { + Session::addMessageAfterRedirect(sprintf(__("Failed to import forms from %s", "formcreator"), + $filename)); } - - Session::addMessageAfterRedirect(sprintf(__("Forms successfully imported from %s", "formcreator"), - $filename)); } } @@ -1841,6 +1872,7 @@ public function importJson($params = []) { * @param array $form the form data (match the form table) * @return integer the form's id */ + /* public static function import($form = []) { $form_obj = new self; $entity = new Entity; @@ -1922,6 +1954,78 @@ public static function import($form = []) { return $forms_id; } + */ + + public static function import(PluginFormcreatorImportLinker $importLinker, $form = []) { + $form_obj = new self; + $entity = new Entity; + $form_cat = new PluginFormcreatorCategory; + + // retrieve foreign keys + if (!isset($form['_entity']) + || !$form['entities_id'] + = plugin_formcreator_getFromDBByField($entity, + 'completename', + $form['_entity'])) { + $form['entities_id'] = $_SESSION['glpiactive_entity']; + } + if (!isset($form['_plugin_formcreator_categories_id']) + || !$form['_plugin_formcreator_categories_id'] + = plugin_formcreator_getFromDBByField($form_cat, + 'completename', + $form['_plugin_formcreator_category'])) { + $form['plugin_formcreator_categories_id'] = 0; + } + + // retrieve form by its uuid + if ($forms_id = plugin_formcreator_getFromDBByField($form_obj, + 'uuid', + $form['uuid'])) { + // add id key + $form['id'] = $forms_id; + + // update existing form + $form_obj->update($form); + } else { + // create new form + $forms_id = $form_obj->add($form); + } + + // import restrictions + if ($forms_id) { + // Delete all previous restrictions + $FormProfile = new PluginFormcreatorForm_Profile(); + $FormProfile->deleteByCriteria([ + 'plugin_formcreator_forms_id' => $forms_id, + ]); + + // Import updates + if (isset($form['_profiles'])) { + foreach ($form['_profiles'] as $formProfile) { + PluginFormcreatorForm_Profile::import($forms_id, $formProfile); + } + } + } + + // import form's sections + if ($forms_id + && isset($form['_sections'])) { + // sort questions by order + usort($form['_sections'], function ($a, $b) { + if ($a['order'] == $b['order']) { + return 0; + } + return ($a['order'] < $b['order']) ? -1 : 1; + }); + + $importLinker->addImportedObject($form['uuid'], $form_obj); + foreach ($form['_sections'] as $section) { + PluginFormcreatorSection::import($importLinker, $forms_id, $section); + } + } + + return $forms_id; + } public function createDocumentType() { $documentType = new DocumentType(); @@ -2120,6 +2224,11 @@ static function header() { } } + /** + * Gets the footer HTML + * + * @return string HTML to show a footer + */ static function footer() { switch (self::getInterface()) { case "servicecatalog"; diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index 3a09d9568..da47c9863 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -291,7 +291,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options * @param Array $options Options (optional) * * @return String Html string to be displayed for the form field - **/ + */ public static function getSpecificValueToSelect($field, $name='', $values='', array $options = []) { if (!is_array($values)) { $values = [$field => $values]; @@ -582,7 +582,7 @@ function checkComment(field) { * @param array $input data used to add the item * * @return array the modified $input array - **/ + */ public function prepareInputForAdd($input) { $form = new PluginFormcreatorForm(); $form->getFromDB($input['plugin_formcreator_forms_id']); @@ -598,7 +598,7 @@ public function prepareInputForAdd($input) { * @param array $input data used to add the item * * @return array the modified $input array - **/ + */ public function prepareInputForUpdate($input) { return $input; } @@ -620,6 +620,11 @@ public function pre_deleteItem() { } + /** + * Create or update answers of a gorm + * @param array $data answers + * @return boolean + */ public function saveAnswers($data) { $form = new PluginFormcreatorForm(); $answer = new PluginFormcreatorAnswer(); @@ -627,8 +632,8 @@ public function saveAnswers($data) { $form->getFromDB($data['formcreator_form']); $formanswers_id = isset($data['id']) - ?intval($data['id']) - :-1; + ? intval($data['id']) + : -1; $question = new PluginFormcreatorQuestion(); $questions = $question->getQuestionsFromForm($data['formcreator_form']); diff --git a/inc/importlinker.class.php b/inc/importlinker.class.php new file mode 100644 index 000000000..fab683dbc --- /dev/null +++ b/inc/importlinker.class.php @@ -0,0 +1,54 @@ +imported[$object->getType()])) { + $this->imported[$object->getType()] = []; + } + $this->imported[$object->getType()][$uuid] = $object; + } + + /** + * + * @param string $uuid + * @param string $itemtype + * @param array $object + */ + public function postponeImport($uuid, $itemtype, array $object, $relationId) { + if (!isset($this->postponed[$itemtype])) { + $this->postponed[$itemtype] = []; + } + $this->postponed[$itemtype][$uuid] = ['object' => $object, 'relationId' => $relationId]; + } + + public function importPostponed() { + do { + $postponedCount = 0; + $postponedAgainCount = 0; + foreach ($this->postponed as $itemtype => $postponedItemtypeList) { + $postponedCount += count($postponedItemtypeList); + $newList = $postponedItemtypeList; + foreach ($postponedItemtypeList as $uuid => $postponedItem) { + if ($itemtype::import($this, $postponedItem['relationId'], $postponedItem['object']) === false) { + $newList[$uuid] = $postponedItem; + $postponedAgainCount++; + } + } + } + + // If no item was successfully imported, then the import is in a deadlock and fails + if ($postponedAgainCount > 0 && $postponedCount == $postponedAgainCount) { + return false; + } + } while ($postponedCount > 0); + } +} \ No newline at end of file diff --git a/inc/issue.class.php b/inc/issue.class.php index d3a20c9d5..d7c8064b2 100644 --- a/inc/issue.class.php +++ b/inc/issue.class.php @@ -143,7 +143,6 @@ public static function hook_update_ticket(CommonDBTM $item) { } /** - * {@inheritDoc} * @see CommonGLPI::display() */ public function display($options = []) { @@ -184,7 +183,6 @@ public function displayExtended($options = []) { } /** - * {@inheritDoc} * @see CommonGLPI::display() */ public function displaySimplified($options = []) { diff --git a/inc/question.class.php b/inc/question.class.php index b1556949f..1c72012fc 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -35,10 +35,12 @@ die("Sorry. You can't access this file directly"); } -class PluginFormcreatorQuestion extends CommonDBChild -{ - static public $itemtype = "PluginFormcreatorSection"; - static public $items_id = "plugin_formcreator_sections_id"; +class PluginFormcreatorQuestion extends CommonDBChild implements PluginFormcreatorExportableInterface { + static public $itemtype = PluginFormcreatorSection::class; + static public $items_id = 'plugin_formcreator_sections_id'; + + /** @var PluginFormcreatorFieldInterface|null $field a field describing the question denpending on its field type */ + private $field = null; /** * Check if current user have the right to create and modify requests @@ -82,9 +84,9 @@ function addMessageOnPurgeAction() {} * * @return String Name to be displayed */ - public function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { switch ($item->getType()) { - case "PluginFormcreatorForm": + case PluginFormcreatorForm::class: $number = 0; $section = new PluginFormcreatorSection(); $found = $section->find('plugin_formcreator_forms_id = ' . $item->getID()); @@ -114,9 +116,10 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { * * @return null Nothing, just display the list */ - public static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { global $CFG_GLPI; + // TODO: move the content of this method into a new showForForm() method echo ''; // Get sections @@ -270,6 +273,7 @@ private function checkBeforeSave($input) { Session::addMessageAfterRedirect(__('The title is required', 'formcreator'), false, ERROR); return []; } + $input['name'] = addslashes($input['name']); } // - field type is required @@ -303,21 +307,29 @@ private function checkBeforeSave($input) { if (!isset($input['fieldtype'])) { $input['fieldtype'] = $this->fields['fieldtype']; } - $fieldObject = PluginFormcreatorFields::getFieldInstance($input['fieldtype'], $this); - $input = $fieldObject->prepareQuestionInputForSave($input); - - // Add leading and trailing regex marker automaticaly - if (isset($input['regex']) && !empty($input['regex'])) { - // Avoid php notice when validating the regular expression - set_error_handler(function($errno, $errstr, $errfile, $errline, $errcontext) {}); - $regex = Toolbox::stripslashes_deep($input['regex']); - $isValid = !(preg_match($regex, null) === false); - restore_error_handler(); - - if (!$isValid) { - Session::addMessageAfterRedirect(__('The regular expression is invalid', 'formcreator'), false, ERROR); + $this->field = PluginFormcreatorFields::getFieldInstance($input['fieldtype'], $this); + + // Check the parameters are provided + $parameters = $this->field->getUsedParameters(); + if (count($parameters) > 0) { + if (!isset($input['_parameters'][$input['fieldtype']])) { + // This should not happen + Session::addMessageAfterRedirect(__('This type of question requires parameters', 'formcreator')); return []; } + foreach ($parameters as $parameter) { + if (!isset($input['_parameters'][$input['fieldtype']][$parameter->getFieldName()])) { + // This should not happen + Session::addMessageAfterRedirect(__('A parameter is missing for this question type', 'formcreator')); + return []; + } + } + } + + $input = $this->field->prepareQuestionInputForSave($input); + if ($input === false || !is_array($input)) { + // Invalid data + return []; } return $input; @@ -330,11 +342,14 @@ private function checkBeforeSave($input) { * @param array $input data used to add the item * * @return array the modified $input array - **/ + */ public function prepareInputForAdd($input) { global $DB; - $input = $this->checkBeforeSave($input); + if (!isset($input['_skip_checks']) + || !$input['_skip_checks']) { + $input = $this->checkBeforeSave($input); + } if (count($input) == 0) { return []; } @@ -377,7 +392,7 @@ public function prepareInputForAdd($input) { * @param array $input data used to add the item * * @array return the modified $input array - **/ + */ public function prepareInputForUpdate($input) { global $DB; @@ -472,6 +487,9 @@ protected function deserializeDefaultValue($input) { return $input; } + /** + * Moves the question up in the ordered list of questions in the section + */ public function moveUp() { $order = $this->fields['order']; $sectionId = $this->fields['plugin_formcreator_sections_id']; @@ -504,6 +522,9 @@ public function moveUp() { } } + /** + * Moves the question down in the ordered list of questions in the section + */ public function moveDown() { $order = $this->fields['order']; $sectionId = $this->fields['plugin_formcreator_sections_id']; @@ -536,6 +557,10 @@ public function moveDown() { } } + /** + * Updates the conditions of the question + * @param array $input + */ public function updateConditions($input) { // Delete all existing conditions for the question $question_condition = new PluginFormcreatorQuestion_Condition(); @@ -574,12 +599,63 @@ public function updateConditions($input) { } } + /** + * Adds or updates parameters of the question + * @param array $input parameters + */ + public function updateParameters($input) { + if (!isset($this->fields['fieldtype'])) { + return; + } + + $fieldType = 'PluginFormcreator' . ucfirst($input['fieldtype']) . 'Field'; + $this->field = new $fieldType($this->fields); + $parameters = $this->field->getUsedParameters(); + if (isset($input['_parameters'][$this->fields['fieldtype']])) { + foreach ($input['_parameters'][$this->fields['fieldtype']] as $fieldName => $parameterInput) { + $parameters[$fieldName]->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $this->getID(), + 'fieldname' => $fieldName, + ]); + $parameterInput['plugin_formcreator_questions_id'] = $this->getID(); + if ($parameters[$fieldName]->isNewItem()) { + $parameters[$fieldName]->add($parameterInput); + } else { + $parameterInput['id'] = $parameters[$fieldName]->getID(); + $parameters[$fieldName]->update($parameterInput); + } + } + } + } + + public function pre_deleteItem() { + $fieldType = 'PluginFormcreator' . ucfirst($this->fields['fieldtype']) . 'Field'; + $this->field = new $fieldType($this->fields); + return $this->field->deleteParameters($this); + } + + public function post_updateItem($history = 1) { + if (!in_array('fieldtype', $this->updates)) { + // update question parameters into the database + $this->field->updateParameters($this, $this->input); + } else { + // Field type changed + // Drop old parameters + $fieldType = 'PluginFormcreator' . ucfirst($this->oldvalues['fieldtype']) . 'Field'; + $oldField = new $fieldType($this->oldvalues); + $oldField->deleteParameters($this); + + // add new ones + $this->field->addParameters($this, $this->input); + } + } + /** * Actions done after the PURGE of the item in the database * Reorder other questions * * @return void - **/ + */ public function post_purgeItem() { global $DB; @@ -608,10 +684,14 @@ public function post_purgeItem() { } public function showForm($ID, $options = []) { - global $DB, $CFG_GLPI; + global $CFG_GLPI; $rootDoc = $CFG_GLPI['root_doc']; + $form_id = (int) $_REQUEST['form_id']; + $form = new PluginFormcreatorForm(); + $form->getFromDB($form_id); + $rand = mt_rand(); $action = Toolbox::getItemTypeFormURL('PluginFormcreatorQuestion'); echo ''; @@ -646,7 +726,7 @@ public function showForm($ID, $options = []) { $fieldtypes = PluginFormcreatorFields::getNames(); Dropdown::showFromArray('fieldtype', $fieldtypes, [ 'value' => $this->fields['fieldtype'], - 'on_change' => 'changeQuestionType();', + 'on_change' => 'plugin_formcreator_changeQuestionType();', 'rand' => $rand, ]); echo ''; @@ -664,13 +744,8 @@ public function showForm($ID, $options = []) { $dbUtil = new DbUtils(); $table = $dbUtil->getTableForItemtype('PluginFormcreatorSection'); $sections = []; - $sql = "SELECT `id`, `name` - FROM $table - WHERE `plugin_formcreator_forms_id` = $form_id - ORDER BY `order`"; - $result = $DB->query($sql); - while ($section = $DB->fetch_array($result)) { - $sections[$section['id']] = $section['name']; + foreach ((new PluginFormcreatorSection())->getSectionsFromForm($form_id) as $section) { + $sections[$section->getID()] = $section->getField('name'); } Dropdown::showFromArray('plugin_formcreator_sections_id', $sections, [ 'value' => ($this->fields['plugin_formcreator_sections_id']) ?:intval($_REQUEST['section_id']), @@ -755,6 +830,80 @@ public function showForm($ID, $options = []) { echo ''; echo ''; + // DOM selectors of all possible parameters + $allParameterSelectors = []; + + // generate JS to show / hide parameters depending on field type + $showHideForFieldTypeJs = " + function plugin_formcreator_changeQuestionType() { + var value = document.getElementById('dropdown_fieldtype$rand').value + plugin_formcreator_hideAllParameters()" . "\n"; + + // build JS code to show parameters for the current question type + // also colelcts all selectors of the parameters to hide all parameters + $showHideForFieldTypeJs.= "switch(value) {" . "\n"; + $evenRow = 0; + foreach (PluginFormcreatorFields::getClasses() as $fieldType => $classname) { + $evenRow++; + $showHideForFieldTypeJs.= "case '$fieldType':" . "\n"; + $field = new $classname([]); + $evenColumnGroup = 0; + foreach ($field->getUsedParameters() as $parameter) { + $evenColumnGroup++; + if ($parameter->getParameterFormSize() > 0) { + // The parameter needs a 4 columns to show its form + // Force a hew table row prior showing the parameter form + if (($evenColumnGroup % 2) === 0) { + $evenColumnGroup++; + } + } + if (($evenColumnGroup % 2) === 1) { + echo ''; + } + $jsSelector = $parameter->getJsShowHideSelector(); + // Output the table row for the parameter + echo $parameter->getParameterForm($form, $this); + + // If the parameter form needs 4 columns, count it twice + if ($parameter->getParameterFormSize() > 0) { + $evenColumnGroup++; + } + + // generate JS code to show the parameter depending on the selected field type + $showHideForFieldTypeJs.= "$('$jsSelector').show()" . "\n"; + $showHideForFieldTypeJs.= "$('$jsSelector + td').show()" . "\n"; + + // save the selector to build JS code to hide all parameters + $allParameterSelectors[] = $jsSelector; + if (($evenColumnGroup % 2) === 0) { + echo ''; + } + } + if ($evenColumnGroup > 0 && ($evenColumnGroup % 2) === 1) { + // If the question has an odd quantity of parameters + // the last row is incomplete + // Fill it with an empty dumy cell + // show or hide it with the last parameter + echo ''; + $showHideForFieldTypeJs.= "$('$jsSelector + td + td').show()" . "\n"; + $allParameterSelectors[] = "$jsSelector + td + td"; + echo ''; + } + $showHideForFieldTypeJs.= "break" . "\n"; + } + $showHideForFieldTypeJs.= "} + changeQuestionType() + } + + function plugin_formcreator_hideAllParameters() { + showFields(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)" . "\n"; + + foreach ($allParameterSelectors as $jsSelector) { + $showHideForFieldTypeJs.= "$('$jsSelector').hide()" . "\n"; + $showHideForFieldTypeJs.= "$('$jsSelector + td').hide()" . "\n"; + } + $showHideForFieldTypeJs.= "}" . "\n"; + echo ''; echo ''; echo ''; @@ -907,28 +1056,6 @@ public function showForm($ID, $options = []) { echo ''; echo ''; - echo ''; - echo ''; - - echo ''; - - echo ''; - echo ''; - echo ''; echo ''; echo ''; - echo ''; - echo ''; - - echo ''; - echo ''; - echo ''; echo ''; $rootDoc = $CFG_GLPI['root_doc']; $allTabFields = PluginFormcreatorFields::printAllTabFieldsForJS(); - echo << + + echo Html::scriptBlock("$showHideForFieldTypeJs + function changeQuestionType() { var value = document.getElementById('dropdown_fieldtype$rand').value; - if(value != "") { + if(value != '') { var tab_fields_fields = []; $allTabFields @@ -1023,7 +1131,7 @@ function changeQuestionType() { showFields(0, 0, 0, 0, 0, 0, 0, 0, 0, 0); } } - changeQuestionType(); + plugin_formcreator_changeQuestionType(); function showFields(required, default_values, values, range, show_empty, regex, show_type, dropdown_value, glpi_object, ldap_values) { if(required) { document.getElementById('dropdown_required$rand').style.display = 'inline'; @@ -1082,21 +1190,6 @@ function showFields(required, default_values, values, range, show_empty, regex, document.getElementById('dropdown_default_value_field').style.display = 'none'; document.getElementById('label_dropdown_default_value').style.display = 'none'; } - if(range) { - document.getElementById('range_min').style.display = 'inline'; - document.getElementById('range_max').style.display = 'inline'; - document.getElementById('label_range_min').style.display = 'inline'; - document.getElementById('label_range_max').style.display = 'inline'; - document.getElementById('label_range').style.display = 'inline'; - document.getElementById('range_tr').style.display = 'table-row'; - } else { - document.getElementById('range_min').style.display = 'none'; - document.getElementById('range_max').style.display = 'none'; - document.getElementById('label_range_min').style.display = 'none'; - document.getElementById('label_range_max').style.display = 'none'; - document.getElementById('label_range').style.display = 'none'; - document.getElementById('range_tr').style.display = 'none'; - } if(show_empty) { document.getElementById('show_empty').style.display = 'inline'; document.getElementById('label_show_empty').style.display = 'inline'; @@ -1104,15 +1197,6 @@ function showFields(required, default_values, values, range, show_empty, regex, document.getElementById('show_empty').style.display = 'none'; document.getElementById('label_show_empty').style.display = 'none'; } - if(regex) { - document.getElementById('regex').style.display = 'inline'; - document.getElementById('label_regex').style.display = 'inline'; - document.getElementById('regex_tr').style.display = 'table-row'; - } else { - document.getElementById('regex').style.display = 'none'; - document.getElementById('label_regex').style.display = 'none'; - document.getElementById('regex_tr').style.display = 'none'; - } if(values || default_values || dropdown_value || glpi_object) { document.getElementById('values_tr').style.display = 'table-row'; } else { @@ -1135,13 +1219,13 @@ function showFields(required, default_values, values, range, show_empty, regex, } function toggleCondition(field) { - if (field.value == "always") { - $(".plugin_formcreator_logicRow").hide(); + if (field.value == 'always') { + $('.plugin_formcreator_logicRow').hide(); } else { - if ($(".plugin_formcreator_logicRow").length < 1) { + if ($('.plugin_formcreator_logicRow').length < 1) { addEmptyCondition(field); } - $(".plugin_formcreator_logicRow").show(); + $('.plugin_formcreator_logicRow').show(); } } @@ -1163,27 +1247,27 @@ function addEmptyCondition(target) { } }).done(function (data) { $(target).parents('tr').after(data); - $(".plugin_formcreator_logicRow .div_show_condition_logic").first().hide(); + $('.plugin_formcreator_logicRow .div_show_condition_logic').first().hide(); }); } function removeNextCondition(target) { $(target).parents('tr').remove(); - $(".plugin_formcreator_logicRow .div_show_condition_logic").first().hide(); + $('.plugin_formcreator_logicRow .div_show_condition_logic').first().hide(); } function change_dropdown() { dropdown_type = document.getElementById('dropdown_dropdown_values$rand').value; jQuery.ajax({ - url: "$rootDoc/plugins/formcreator/ajax/dropdown_values.php", - type: "GET", + url: '$rootDoc/plugins/formcreator/ajax/dropdown_values.php', + type: 'GET', data: { dropdown_itemtype: dropdown_type, - rand: "$rand" + rand: '$rand' }, }).done(function(response){ - jQuery("#dropdown_default_value_field").html(response); + jQuery('#dropdown_default_value_field').html(response); }); } @@ -1191,14 +1275,14 @@ function change_glpi_objects() { glpi_object = document.getElementById('dropdown_glpi_objects$rand').value; jQuery.ajax({ - url: "$rootDoc/plugins/formcreator/ajax/dropdown_values.php", - type: "GET", + url: '$rootDoc/plugins/formcreator/ajax/dropdown_values.php', + type: 'GET', data: { dropdown_itemtype: glpi_object, - rand: "$rand" + rand: '$rand' }, }).done(function(response){ - jQuery("#dropdown_default_value_field").html(response); + jQuery('#dropdown_default_value_field').html(response); }); } @@ -1206,18 +1290,17 @@ function change_LDAP(ldap) { var ldap_directory = ldap.value; jQuery.ajax({ - url: "$rootDoc/plugins/formcreator/ajax/ldap_filter.php", - type: "POST", + url: '$rootDoc/plugins/formcreator/ajax/ldap_filter.php', + type: 'POST', data: { value: ldap_directory, - _glpi_csrf_token: "" + _glpi_csrf_token: '" . Session::getNewCSRFToken() . "' }, }).done(function(response){ document.getElementById('ldap_filter').value = response; }); } - -JS; + "); echo '
'; echo ''; - echo ' 
'; - echo ''.__('Range', 'formcreator').''; - echo ''; - echo ''; - echo ''; - echo ' '; - echo ''; - echo ''; - echo ' 
'; echo '
'; - echo ''; - echo ''; - echo ''; - echo ''; - echo __('Specify the additional validation conditions in the description of the question to help users.', 'formcreator'); - echo ''; - echo '
'; echo '
'; Html::closeForm(); } @@ -1235,10 +1318,26 @@ public function duplicate() { $row = $this->fields; unset($row['id'], $row['uuid']); + $row['_skip_checks'] = true; if (!$newQuestion->add($row)) { return false; } + // Form questions parameters + $fieldType = 'PluginFormcreator' . ucfirst($this->fields['fieldtype']) . 'Field'; + $this->field = new $fieldType($this->fields); + $parameters = $this->field->getUsedParameters(); + foreach ($parameters as $fieldName => $parameter) { + $parameter->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $oldQuestionId, + 'fieldname' => $fieldName, + ]); + $row = $parameter->fields; + $row[PluginFormcreatorQuestion::getForeignKeyField()] = $newQuestion->getID(); + unset($row['id']); + $parameter->add($row); + } + // Form questions conditions $rows = $question_condition->find("`plugin_formcreator_questions_id` IN ('$oldQuestionId')"); foreach ($rows as $row) { @@ -1249,10 +1348,8 @@ public function duplicate() { return false; } } - } - /** * Import a section's question into the db * @see PluginFormcreatorSection::import @@ -1261,6 +1358,7 @@ public function duplicate() { * @param array $question the question data (match the question table) * @return integer the question's id */ + /* public static function import($sections_id = 0, $question = []) { $item = new self; @@ -1287,6 +1385,50 @@ public static function import($sections_id = 0, $question = []) { return $questions_id; } + */ + + public static function import(PluginFormcreatorImportLinker $importLinker, $sections_id = 0, $question = []) { + $item = new self; + + $question['plugin_formcreator_sections_id'] = $sections_id; + $question['_skip_checks'] = true; + + if ($questions_id = plugin_formcreator_getFromDBByField($item, 'uuid', $question['uuid'])) { + // add id key + $question['id'] = $questions_id; + $fieldType = 'PluginFormcreator' . ucfirst($question['fieldtype']) . 'Field'; + $item->field = new $fieldType($item->fields); + + // update question + $item->update($question); + } else { + //create question + + $questions_id = $item->add($question); + } + + if ($questions_id + && isset($question['_conditions'])) { + $importLinker->addImportedObject($question['uuid'], $item); + + foreach ($question['_conditions'] as $condition) { + PluginFormcreatorQuestion_Condition::import($importLinker, $questions_id, $condition); + } + + $fieldType = 'PluginFormcreator' . ucfirst($question['fieldtype']) . 'Field'; + $field = new $fieldType($item->fields); + $parameters = $field->getUsedParameters(); + foreach ($parameters as $fieldName => $parameter) { + $parameter->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $item->fields['id'], + 'fieldname' => $fieldName, + ]); + $parameter::import($importLinker, $questions_id, $fieldName, $question['_parameters'][$question['fieldtype']][$fieldName]); + } + } + + return $questions_id; + } /** * Export in an array all the data of the current instanciated question @@ -1315,6 +1457,19 @@ public function export($remove_uuid = false) { } } + // get question parameters + $question['_parameters'] = []; + $fieldType = 'PluginFormcreator' . ucfirst($this->fields['fieldtype']) . 'Field'; + $this->field = new $fieldType($this->fields); + $parameters = $this->field->getUsedParameters(); + foreach ($parameters as $fieldname => $parameter) { + $parameter->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $this->fields['id'], + 'fieldname' => $fieldname, + ]); + $question['_parameters'][$this->fields['fieldtype']][$fieldname] = $parameter->export(); + } + if ($remove_uuid) { $question['uuid'] = ''; } @@ -1362,17 +1517,20 @@ public function getForm() { * @param integer $formId * @return PluginFormcreatorQuestion[] */ - public function getQuestionsFromForm($formId) { + public function getQuestionsFromForm($formId, $crit = '') { global $DB; $questions = []; + if ($crit === '') { + $crit = '1'; + } $dbUtil = new DbUtils(); $table_question = $dbUtil->getTableForItemtype('PluginFormcreatorQuestion'); $table_section = $dbUtil->getTableForItemtype('PluginFormcreatorSection'); $result = $DB->query("SELECT `q`.* FROM $table_question `q` LEFT JOIN $table_section `s` ON `q`.`plugin_formcreator_sections_id` = `s`.`id` - WHERE `s`.`plugin_formcreator_forms_id` = '$formId' + WHERE `s`.`plugin_formcreator_forms_id` = '$formId' AND $crit ORDER BY `s`.`order`, `q`.`order`" ); while ($row = $DB->fetch_assoc($result)) { @@ -1384,6 +1542,13 @@ public function getQuestionsFromForm($formId) { return $questions; } + /** + * Gets questions belonging to a section + * + * @param integer $sectionId + * + * @return PluginFormcreatorQuestion[] + */ public function getQuestionsFromSection($sectionId) { $questions = []; $rows = $this->find("`plugin_formcreator_sections_id` = '$sectionId'", "`order` ASC"); diff --git a/inc/question_condition.class.php b/inc/question_condition.class.php index 79691c3e9..19d0d105f 100644 --- a/inc/question_condition.class.php +++ b/inc/question_condition.class.php @@ -35,10 +35,10 @@ die("Sorry. You can't access this file directly"); } -class PluginFormcreatorQuestion_Condition extends CommonDBChild +class PluginFormcreatorQuestion_Condition extends CommonDBChild implements PluginFormcreatorExportableInterface { - static public $itemtype = "PluginFormcreatorQuestion"; - static public $items_id = "plugin_formcreator_questions_id"; + static public $itemtype = PluginFormcreatorQuestion::class; + static public $items_id = 'plugin_formcreator_questions_id'; public function prepareInputForAdd($input) { // generate a unique id @@ -61,12 +61,13 @@ public static function getEnumShowLogic() { * Import a question's condition into the db * @see PluginFormcreatorQuestion::import * - * @param integer $questions_id id of the parent question - * @param array $condition the condition data (match the condition table) - * @param boolean storeOnly + * @param integer $questions_id id of the parent question + * @param array $condition the condition data (match the condition table) + * @param boolean $storeOnly * * @return integer the condition's id */ + /* public static function import($questions_id = 0, $condition = [], $storeOnly = true) { static $conditionsToImport = []; @@ -100,6 +101,35 @@ public static function import($questions_id = 0, $condition = [], $storeOnly = t $conditionsToImport = []; } } + */ + + public static function import(PluginFormcreatorImportLinker $importLinker, $questions_id = 0, $condition = []) { + $item = new static(); + + if ($showField + = plugin_formcreator_getFromDBByField(new PluginFormcreatorQuestion(), + 'uuid', + $condition['show_field'])) { + $importLinker->postponeImport($condition['uuid'], $item->getType(), $condition, $questions_id); + return false; + } + + $condition['show_field'] = $showField; + $condition['plugin_formcreator_questions_id'] = $questions_id; + + if ($conditions_id = plugin_formcreator_getFromDBByField($item, 'uuid', $condition['uuid'])) { + // add id key + $condition['id'] = $conditions_id; + + // prepare update condition + $item->update($condition); + } else { + // prepare create condition + $item->add($condition); + } + $importLinker->addImportedObject($condition['uuid'], $item); + return $conditions_id; + } /** * Export in an array all the data of the current instanciated condition diff --git a/inc/questiondependency.class.php b/inc/questiondependency.class.php new file mode 100644 index 000000000..c63dfa9d5 --- /dev/null +++ b/inc/questiondependency.class.php @@ -0,0 +1,140 @@ +fieldtype = isset($options['fieldType']) ? $options['fieldType'] : []; + } + + public function getParameterFormSize() { + return 0; + } + + public function getParameterForm(PluginFormcreatorForm $form, PluginFormcreatorQuestion $question) { + // get questions of type text in the form + $eligibleQuestions = []; + $criteria = "`fieldtype` IN ('" . implode("', '", $this->fieldtype) . "')"; + foreach ($question->getQuestionsFromForm($form->getID(), $criteria) as $item) { + $eligibleQuestions[$item->getID()] = $item->getField('name'); + } + + // get the name of the HTML input field + $name = '_parameters[' . $this->field->getFieldTypeName() . '][' . $this->fieldName . ']'; + + // get the selected value in the dropdown + $selected = 0; + if (!$question->isNewItem()) { + $this->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $question->getID(), + 'fieldname' => $this->fieldName, + ]); + if (!$this->isNewItem()) { + $selected = $this->fields['plugin_formcreator_questions_id_2']; + } + } + + // get the HTML for the dropdown + $questionsDropdown = Dropdown::showFromArray( + $name . '[plugin_formcreator_questions_id_2]', + $eligibleQuestions, + [ + 'display' => false, + 'display_emptychoice' => true, + 'value' => $selected, + 'used' => [$question->getID() => ''], + ]); + + // build HTML code + $selector = $this->domId; + $out = ''; + $out.= '' . $this->label . ''; + $out.= '' . $questionsDropdown . ''; + + return $out; + } + + public function getJsShowHideSelector() { + return "#" . $this->domId; + } + + public function prepareInputForAdd($input) { + $input = parent::prepareInputForAdd($input); + $input['fieldname'] = $this->fieldName; + + return $input; + } + + public function getFieldName() { + return $this->fieldName; + } + + public function export($remove_uuid = false) { + if (!$this->getID()) { + return false; + } + + $parameter = $this->fields; + $this->convertIds($parameter); + unset($parameter['id'], + $parameter[PluginFormcreatorQuestion::getForeignKeyField()]); + + if ($remove_uuid) { + $parameter['uuid'] = ''; + } + + return $parameter; + } + + public function duplicate(PluginFormcreatorQuestion $newQuestion, array $tab_questions) { + $parameter = parent::duplicate($newQuestion, $tab_questions); + + // update the question ID the parameter depends on + if (isset($tab_questions[$parameter->fields['plugin_formcreator_questions_id_2']])) { + $parameter->fields['plugin_formcreator_questions_id_2'] = $tab_questions[$parameter->fields['plugin_formcreator_questions_id_2']]; + } + + return $parameter; + } + + protected function convertIds(&$parameter) { + $question = new PluginFormcreatorQuestion(); + $question->getFromDB($this->fields['plugin_formcreator_questions_id_2']); + $parameter['plugin_formcreator_questions_id_2'] = $question->getField('uuid'); + } + + + protected function convertUuids(&$parameter) { + if ($questionId2 + = plugin_formcreator_getFromDBByField(new PluginFormcreatorQuestion(), + 'uuid', + $parameter['plugin_formcreator_questions_id_2'])) { + $parameter['plugin_formcreator_questions_id_2'] = $questionId2; + return true; + } + return false; + } +} \ No newline at end of file diff --git a/inc/questionparameter.class.php b/inc/questionparameter.class.php new file mode 100644 index 000000000..bfb01d92d --- /dev/null +++ b/inc/questionparameter.class.php @@ -0,0 +1,139 @@ +getFieldTypeName(); + $fieldName = $options['fieldName']; + $this->domId = $this->domId . "_{$fieldType}_{$fieldName}"; + $this->field = $field; + $this->label = $options['label']; + $this->fieldName = $options['fieldName']; + } + + public function prepareInputforAdd($input) { + $input = parent::prepareInputForAdd($input); + // generate a uniq id + if (!isset($input['uuid']) + || empty($input['uuid'])) { + $input['uuid'] = plugin_formcreator_getUuid(); + } + + return $input; + } + + /** + * Export in an array all the data of the current instanciated condition + * @param boolean $remove_uuid remove the uuid key + * + * @return array the array with all data (with sub tables) + */ + public function export($remove_uuid = false) { + if (!$this->getID()) { + return false; + } + + $parameter = $this->fields; + unset($parameter['id'], + $parameter[PluginFormcreatorQuestion::getForeignKeyField()]); + + if ($remove_uuid) { + $parameter['uuid'] = ''; + } + + return $parameter; + } + + public static function import(PluginFormcreatorImportLinker $importLinker, $questions_id = 0, $fieldName = '', $parameter = []) { + $parameter['plugin_formcreator_questions_id'] = $questions_id; + + // get a built instance of the parameter + $question = new PluginFormcreatorquestion(); + $question->getFromDB($questions_id); + $fieldType = 'PluginFormcreator' . ucfirst($question->fields['fieldtype']) . 'Field'; + $field = new $fieldType($question->fields); + $parameters = $field->getUsedParameters(); + $item = $parameters[$fieldName]; + $found = $item->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $questions_id, + 'fieldname' => $fieldName, + ]); + if (!$item->convertUuids($parameter)) { + $importLinker->postponeImport($parameter['uuid'], $item->getType(), $parameter, $questions_id); + return false; + } + + if ($found) { + $parameter['id'] = $item->getID(); + $item->update($parameter); + } else { + $item->add($parameter); + } + $importLinker->addImportedObject($item->fields['uuid'], $item); + } + + /** + * Covnerts IDs of related objects into their UUID + * @param array $parameter + */ + protected function convertIds(&$parameter) {} + + /** + * Converts uuids of linked objects into ID + * @param array $parameter + * @return boolean true if success, or false otherwise + */ + protected function convertUuids(&$parameter) { + return true; + } + + /** + * Duplicates a parameter + * @param PluginFormcreatorQuestion $newQuestion question which will contain the new parameter + * @param array $tab_questions map old question ID => new question ID + * @return PluginFormcreatorQuestionParameter new isntance (not saved in DB) + */ + public function duplicate(PluginFormcreatorQuestion $newQuestion, array $tab_questions) { + $parameter = new static($this->field, ['fieldName' => $this->fieldName, 'label' => $this->label]); + $row = $this->fields; + unset($row['id']); + + // Update the question ID linked to the parameter with the old/new question ID map + $questionKey = PluginFormcreatorQuestion::getForeignKeyField(); + $row[$questionKey] = $tab_questions[$this->fields[$questionKey]]; + + // return the new instance, not saved yet in DB + $parameter->fields = $row; + return $parameter; + } +} \ No newline at end of file diff --git a/inc/questionparameterinterface.class.php b/inc/questionparameterinterface.class.php new file mode 100644 index 000000000..1ac7e9622 --- /dev/null +++ b/inc/questionparameterinterface.class.php @@ -0,0 +1,30 @@ +field->getFieldTypeName() . '][' . $this->fieldName . ']'; + + // get the selected value in the dropdown + $rangeMin = ''; + $rangeMax = ''; + $this->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $question->getID(), + 'fieldname' => $this->fieldName, + ]); + if (!$this->isNewItem()) { + $rangeMin = $this->fields['range_min']; + $rangeMax = $this->fields['range_max']; + } + + // build HTML code + $selector = $this->domId; + $out = ''; + $out.= '' . $this->label . ''; + $out.= ''; + $out.= ' '; + $out.= ''; + $out.= '  '; + $out.= ''; + $out.= ''; + + return $out; + } + + public function getJsShowHideSelector() { + return "#" . $this->domId; + } + + public function prepareInputForAdd($input) { + $input = parent::prepareInputForAdd($input); + $input['fieldname'] = $this->fieldName; + + return $input; + } + + public function getFieldName() { + return $this->fieldName; + } + + public function export($remove_uuid = false) { + if (!$this->getID()) { + return false; + } + + $parameter = $this->fields; + $this->convertIds($parameter); + unset($parameter['id'], + $parameter[PluginFormcreatorQuestion::getForeignKeyField()]); + + if ($remove_uuid) { + $parameter['uuid'] = ''; + } + + return $parameter; + } +} \ No newline at end of file diff --git a/inc/questionregex.class.php b/inc/questionregex.class.php new file mode 100644 index 000000000..dd009867d --- /dev/null +++ b/inc/questionregex.class.php @@ -0,0 +1,79 @@ +field->getFieldTypeName() . '][' . $this->fieldName . ']'; + + // get the selected value in the dropdown + $selected = ''; + $this->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $question->getID(), + 'fieldname' => $this->fieldName, + ]); + if (!$this->isNewItem()) { + $selected = $this->fields['regex']; + } + + // build HTML code + $selector = $this->domId; + $out = ''; + $out.= '' . $this->label . ''; + $out.= ''; + $out.= ''; + $out.= __('Specify the additional validation conditions in the description of the question to help users.', 'formcreator'); + $out.= ''; + + return $out; + } + + public function getJsShowHideSelector() { + return "#" . $this->domId; + } + + public function prepareInputForAdd($input) { + $input = parent::prepareInputForAdd($input); + $input['fieldname'] = $this->fieldName; + + return $input; + } + + public function getFieldName() { + return $this->fieldName; + } + + public function export($remove_uuid = false) { + if (!$this->getID()) { + return false; + } + + $parameter = $this->fields; + $this->convertIds($parameter); + unset($parameter['id'], + $parameter[PluginFormcreatorQuestion::getForeignKeyField()]); + + if ($remove_uuid) { + $parameter['uuid'] = ''; + } + + return $parameter; + } +} \ No newline at end of file diff --git a/inc/section.class.php b/inc/section.class.php index 599c20c7c..a4ed27d54 100644 --- a/inc/section.class.php +++ b/inc/section.class.php @@ -35,7 +35,7 @@ die("Sorry. You can't access this file directly"); } -class PluginFormcreatorSection extends CommonDBChild +class PluginFormcreatorSection extends CommonDBChild implements PluginFormcreatorExportableInterface { static public $itemtype = "PluginFormcreatorForm"; static public $items_id = "plugin_formcreator_forms_id"; @@ -136,7 +136,7 @@ public function prepareInputForUpdate($input) { * Reorder other sections * * @return void - **/ + */ public function post_purgeItem() { global $DB; @@ -177,6 +177,7 @@ public function duplicate() { unset($row['id'], $row['uuid']); $row['plugin_formcreator_sections_id'] = $newSection->getID(); + $row['_skip_checks'] = true; if (!$new_questions_id = $section_question->add($row)) { return false; } @@ -184,6 +185,28 @@ public function duplicate() { $tab_questions[$questions_id] = $new_questions_id; } + // Form questions parameters + foreach ($tab_questions as $questions_id => $new_questions_id) { + $oldQuestion = new PluginFormcreatorQuestion(); + $oldQuestion->getFromDB($questions_id); + $fieldType = 'PluginFormcreator' . ucfirst($oldQuestion->fields['fieldtype']) . 'Field'; + $this->field = new $fieldType($oldQuestion->fields); + $parameters = $this->field->getUsedParameters(); + foreach ($parameters as $fieldName => $parameter) { + $parameter->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $questions_id, + 'fieldname' => $fieldName, + ]); + if (!$parameter->isNewItem()) { + // Should always happen + $newQuestion = new PluginFormcreatorQuestion(); + $newQuestion->getFromDB($new_questions_id); + $parameter = $parameter->duplicate($newQuestion, $tab_questions); + $parameter->add($parameter->fields); + } + } + } + // Form questions conditions $questionIds = implode("', '", array_keys($tab_questions)); $rows = $question_condition->find("`plugin_formcreator_questions_id` IN ('$questionIds')"); @@ -276,6 +299,7 @@ public function moveDown() { * @param array $section the section data (match the section table) * @return integer the section's id */ + /* public static function import($forms_id = 0, $section = []) { $item = new self; @@ -300,7 +324,7 @@ public static function import($forms_id = 0, $section = []) { if ($a['order'] == $b['order']) { return 0; } - return ($a['order'] < $b['order']) ? -1 : 1; + return ($a['order'] < $b['order']) ? -1 : 1; } ); @@ -311,6 +335,44 @@ public static function import($forms_id = 0, $section = []) { return $sections_id; } + */ + + public static function import(PluginFormcreatorImportLinker $importLinker, $forms_id = 0, $section = []) { + $item = new self; + + $section['plugin_formcreator_forms_id'] = $forms_id; + $section['_skip_checks'] = true; + + if ($sections_id = plugin_formcreator_getFromDBByField($item, 'uuid', $section['uuid'])) { + // add id key + $section['id'] = $sections_id; + + // update section + $item->update($section); + } else { + //create section + $sections_id = $item->add($section); + } + + if ($sections_id + && isset($section['_questions'])) { + $importLinker->addImportedObject($section['uuid'], $item); + // sort questions by order + usort($section['_questions'], function ($a, $b) { + if ($a['order'] == $b['order']) { + return 0; + } + return ($a['order'] < $b['order']) ? -1 : 1; + } + ); + + foreach ($section['_questions'] as $question) { + PluginFormcreatorQuestion::import($importLinker, $sections_id, $question); + } + } + + return $sections_id; + } /** * Export in an array all the data of the current instanciated section @@ -347,7 +409,9 @@ public function export($remove_uuid = false) { } /** - * get all sections in a form + * gets all sections in a form + * @param integer $formId ID of a form + * @return array sections in a form */ public function getSectionsFromForm($formId) { $sections = []; diff --git a/inc/target.class.php b/inc/target.class.php index 4bfe5e7ad..66e086656 100644 --- a/inc/target.class.php +++ b/inc/target.class.php @@ -132,7 +132,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ * @param array $input data used to add the item * * @return array the modified $input array - **/ + */ public function prepareInputForAdd($input) { // Control fields values : // - name is required @@ -219,7 +219,7 @@ public function prepareInputForAdd($input) { * @param array $input data used to add the item * * @return array the modified $input array - **/ + */ public function prepareInputForUpdate($input) { // generate a uniq id if (!isset($input['uuid']) diff --git a/inc/target_actor.class.php b/inc/target_actor.class.php index 61f5ec16f..f07271e96 100644 --- a/inc/target_actor.class.php +++ b/inc/target_actor.class.php @@ -35,7 +35,7 @@ die("Sorry. You can't access this file directly"); } -abstract class PluginFormcreatorTarget_Actor extends CommonDBTM +abstract class PluginFormcreatorTarget_Actor extends CommonDBTM implements PluginFormcreatorExportableInterface { abstract protected function getTargetItem(); diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index bc65674c3..d5a39045b 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -35,7 +35,7 @@ die("Sorry. You can't access this file directly"); } -abstract class PluginFormcreatorTargetBase extends CommonDBTM +abstract class PluginFormcreatorTargetBase extends CommonDBTM implements PluginFormcreatorExportableInterface { protected $requesters; @@ -54,7 +54,7 @@ abstract class PluginFormcreatorTargetBase extends CommonDBTM protected $attachedDocuments = []; - abstract public function export(); + abstract public function export($remove_uuid = false); abstract public function save(PluginFormcreatorForm_Answer $formanswer); @@ -782,8 +782,8 @@ protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer, // retrieve answers $answers_values = $formanswer->getAnswers($formanswer->getID()); - $section = new PluginFormcreatorSection(); - $sections = $section->getSectionsFromForm($formanswer->fields['plugin_formcreator_forms_id']); + $section = new PluginFormcreatorSection(); + $sections = $section->getSectionsFromForm($formanswer->fields['plugin_formcreator_forms_id']); $sectionsIdString = implode(', ', array_keys($sections)); if (count($sections) > 0) { @@ -801,7 +801,7 @@ protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer, $fieldObject = new $classname($question_line, $question_line['answer']); } - $id = $question_line['id']; + $id = $question_line['id']; if (!PluginFormcreatorFields::isVisible($question_line['id'], $answers_values)) { $name = ''; $value = ''; @@ -809,6 +809,14 @@ protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer, $name = $question_line['name']; $value = $fieldObject->prepareQuestionInputForTarget($fieldObject->getValue()); } + if (is_array($value)) { + if ($CFG_GLPI['use_rich_text']) { + $value = '
' . implode('
', $value); + } else { + $value = "\r\n" . implode("\r\n", $value); + } + } + if ($question_line['fieldtype'] !== 'file') { $content = str_replace('##question_' . $id . '##', addslashes($name), $content); $content = str_replace('##answer_' . $id . '##', $value, $content); diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index 72dd23497..aeaac8f6f 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -89,7 +89,7 @@ protected function getCategoryFilter() { * Export in an array all the data of the current instanciated target ticket * @return array the array with all data (with sub tables) */ - public function export() { + public function export($remove_uuid = false) { if (!$this->getID()) { return false; } @@ -839,7 +839,7 @@ public function showForm($options=[]) { * @param array $input data used to add the item * * @return array the modified $input array - **/ + */ public function prepareInputForUpdate($input) { global $CFG_GLPI; diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index aca00c914..dedab6b56 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -831,7 +831,7 @@ public function prepareInputForAdd($input) { * @param array $input datas used to add the item * * @return array the modified $input array - **/ + */ public function prepareInputForUpdate($input) { global $CFG_GLPI; @@ -1259,7 +1259,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { // Create the target ticket if (!$ticketID = $ticket->add($data)) { - return false; + return null; } // Add tag if presents @@ -1527,7 +1527,7 @@ public static function import($targetitems_id = 0, $target_data = []) { * Export in an array all the data of the current instanciated targetticket * @return array the array with all data (with sub tables) */ - public function export() { + public function export($remove_uuid = false) { if (!$this->getID()) { return false; } diff --git a/install/install.php b/install/install.php index 3fae859a7..92713ff6a 100644 --- a/install/install.php +++ b/install/install.php @@ -88,6 +88,13 @@ public function upgrade(Migration $migration) { require_once(__DIR__ . '/update_2.6.2_2.6.3.php'); plugin_formcreator_update_2_6_3($this->migration); + + case 2.7: + case PLUGIN_FORMCREATOR_SCHEMA_VERSION: + //Any schema version below or equal to 2.7 + require_once(__DIR__ . '/update_2.6_2.7.php'); + plugin_formcreator_update_2_7($this->migration); + default: // Must be the last case if ($this->endsWith(PLUGIN_FORMCREATOR_VERSION, "-dev")) { diff --git a/install/mysql/plugin_formcreator_empty.sql b/install/mysql/plugin_formcreator_empty.sql index 38d26467e..9a5191514 100644 --- a/install/mysql/plugin_formcreator_empty.sql +++ b/install/mysql/plugin_formcreator_empty.sql @@ -109,7 +109,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questions` ( `range_min` varchar(10) DEFAULT NULL, `range_max` varchar(10) DEFAULT NULL, `description` text NOT NULL, - `regex` varchar(255) DEFAULT NULL, + `regex` text, `order` int(11) NOT NULL DEFAULT '0', `show_rule` enum('always','hidden','shown') NOT NULL DEFAULT 'always', `uuid` varchar(255) DEFAULT NULL, @@ -262,3 +262,35 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_items_targettickets` ( INDEX `plugin_formcreator_targettickets_id` (`plugin_formcreator_targettickets_id`), INDEX `item` (`itemtype`,`items_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questiondependencies` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plugin_formcreator_questions_id` int(11) NOT NULL, + `plugin_formcreator_questions_id_2` int(11) NOT NULL, + `fieldname` varchar(255) DEFAULT NULL, + `uuid` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + INDEX `plugin_formcreator_questions_id` (`plugin_formcreator_questions_id`), + INDEX `plugin_formcreator_questions_id_2` (`plugin_formcreator_questions_id_2`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questionregexes` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plugin_formcreator_questions_id` int(11) NOT NULL, + `regex` text DEFAULT NULL, + `fieldname` varchar(255) DEFAULT NULL, + `uuid` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + INDEX `plugin_formcreator_questions_id` (`plugin_formcreator_questions_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questionranges` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plugin_formcreator_questions_id` int(11) NOT NULL, + `range_min` varchar(255) DEFAULT NULL, + `range_max` varchar(255) DEFAULT NULL, + `fieldname` varchar(255) DEFAULT NULL, + `uuid` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + INDEX `plugin_formcreator_questions_id` (`plugin_formcreator_questions_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/install/update_2.6.2_2.6.3.php b/install/update_2.6.2_2.6.3.php index e333679fb..f5ecc5305 100644 --- a/install/update_2.6.2_2.6.3.php +++ b/install/update_2.6.2_2.6.3.php @@ -45,7 +45,6 @@ function plugin_formcreator_update_2_6_3() { 'FROM' => $table, ]; foreach ($DB->request($request) as $row) { - $id = $row['id']; $name = Toolbox::addslashes_deep(html_entity_decode($row['name'], ENT_QUOTES|ENT_HTML5)); $id = $row['id']; $DB->query("UPDATE `$table` SET `name`='$name' WHERE `id` = '$id'"); @@ -57,7 +56,6 @@ function plugin_formcreator_update_2_6_3() { 'FROM' => $table, ]; foreach ($DB->request($request) as $row) { - $id = $row['id']; $name = Toolbox::addslashes_deep(html_entity_decode($row['name'], ENT_QUOTES|ENT_HTML5)); $id = $row['id']; $DB->query("UPDATE `$table` SET `name`='$name' WHERE `id` = '$id'"); @@ -69,7 +67,6 @@ function plugin_formcreator_update_2_6_3() { 'FROM' => $table, ]; foreach ($DB->request($request) as $row) { - $id = $row['id']; $name = Toolbox::addslashes_deep(html_entity_decode($row['name'], ENT_QUOTES|ENT_HTML5)); $id = $row['id']; $DB->query("UPDATE `$table` SET `name`='$name' WHERE `id` = '$id'"); @@ -81,7 +78,6 @@ function plugin_formcreator_update_2_6_3() { 'FROM' => $table, ]; foreach ($DB->request($request) as $row) { - $id = $row['id']; $name = Toolbox::addslashes_deep(html_entity_decode($row['name'], ENT_QUOTES|ENT_HTML5)); $id = $row['id']; $DB->query("UPDATE `$table` SET `name`='$name' WHERE `id` = '$id'"); diff --git a/install/update_2.6_2.7.php b/install/update_2.6_2.7.php new file mode 100644 index 000000000..cea60c215 --- /dev/null +++ b/install/update_2.6_2.7.php @@ -0,0 +1,90 @@ +fieldExists($table, 'regex')) { + $request = [ + 'FROM' => $table, + 'WHERE' => ['fieldtype' => ['float', 'integer', 'text', 'textarea']] + ]; + foreach ($DB->request($request) as $row) { + $id = $row['id']; + $regex = $DB->escape($row['regex']); + $uuid = plugin_formcreator_getUuid(); + $DB->query("INSERT INTO `glpi_plugin_formcreator_questionregexes` + SET `plugin_formcreator_questions_id`='$id', `fieldname`='regex', `regex`='$regex', `uuid`='$uuid'" + ) or plugin_formcreator_upgrade_error($migration); + } + $migration->dropField($table, 'regex'); + } + + // Migrate range question parameters + $table = 'glpi_plugin_formcreator_questions'; + if ($DB->fieldExists($table, 'range_min')) { + $request = [ + 'FROM' => $table, + 'WHERE' => ['fieldtype' => ['float', 'integer', 'checkboxes', 'multiselect', 'text']] + ]; + foreach ($DB->request($request) as $row) { + $id = $row['id']; + $rangeMin = $DB->escape($row['range_min']); + $rangeMax = $DB->escape($row['range_max']); + $uuid = plugin_formcreator_getUuid(); + $DB->query("INSERT INTO `glpi_plugin_formcreator_questionranges` + SET `plugin_formcreator_questions_id`='$id', `fieldname`='range', `range_min`='$rangeMin', `range_max`='$rangeMax', `uuid`='$uuid'" + ) or plugin_formcreator_upgrade_error($migration); + } + $migration->dropField($table, 'range_min'); + $migration->dropField($table, 'range_max'); + + // decode html entities in answers + $request = [ + 'SELECT' => [ + 'glpi_plugin_formcreator_answers.*' + ], + 'FROM' => 'glpi_plugin_formcreator_answers', + 'INNER JOIN' => [ + 'glpi_plugin_formcreator_questions' => [ + 'FKEY' => [ + 'glpi_plugin_formcreator_answers' => 'plugin_formcreator_questions_id', + 'glpi_plugin_formcreator_questions' => 'id' + ] + ] + ], + 'WHERE' => ['fieldtype' => 'textarea'] + ]; + foreach ($DB->request($request) as $row) { + $answer = Toolbox::addslashes_deep(html_entity_decode($row['answer'])); + $id = $row['id']; + $DB->query("UPDATE `glpi_plugin_formcreator_answers` SET `answer`='$answer' WHERE `id` = '$id'"); + } + } + + // decode html entities in question definitions + $request = [ + 'FROM' => 'glpi_plugin_formcreator_questions', + 'WHERE' => [ + 'fieldtype' => ['select', 'multiselect', 'checkboxes', 'radios'] + ] + ]; + foreach ($DB->request($request) as $row) { + $values = html_entity_decode($row['values']); + $defaultValues = html_entity_decode($row['default_values']); + $DB->query("UDATE `glpi_plugin_formcreator_questions` SET `values` = '$values', `default_values` = '$defaultValues'"); + } + + // decode html entities in name of questions + foreach ($DB->request(['FROM' => 'glpi_plugin_formcreator_questions']) as $row) { + $name = html_entity_decode($row['name']); + $DB->query("UPDATE `glpi_plugin_formcreator_questions` SET `name`='$name'"); + } + +} \ No newline at end of file diff --git a/setup.php b/setup.php index 277e7895f..818086b5e 100644 --- a/setup.php +++ b/setup.php @@ -39,7 +39,6 @@ // is or is not an official release of the plugin define('PLUGIN_FORMCREATOR_IS_OFFICIAL_RELEASE', false); - // Minimal GLPI version, inclusive define ('PLUGIN_FORMCREATOR_GLPI_MIN_VERSION', '9.2.1'); // Maximum GLPI version, exclusive diff --git a/tests/0000_Install/PluginInstallTest.php b/tests/0000_Install/PluginInstallTest.php index dd7df8e27..313103d7f 100644 --- a/tests/0000_Install/PluginInstallTest.php +++ b/tests/0000_Install/PluginInstallTest.php @@ -71,7 +71,6 @@ public function testInstallPlugin() { $query = 'SHOW TABLES'; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { - if (strstr($data[0], 'glpi_plugin_formcreator') !== false) { $DB->query('DROP TABLE '.$data[0]); } @@ -87,7 +86,9 @@ public function testInstallPlugin() { ob_end_clean(); $PluginDBTest = new PluginDB(); - $PluginDBTest->checkInstall('formcreator', 'install'); + // Checking the installed shcma is useless fir fresh install + // TODO: use the GLPI upgraded schema test + //$PluginDBTest->checkInstall('formcreator', 'install'); // Check the version of the schema is saved $config = Config::getConfigurationValues('formcreator'); diff --git a/tests/0005_Unit/CheckboxesFieldTest.php b/tests/0005_Unit/CheckboxesFieldTest.php index 1f84ce5b5..afe29cc26 100644 --- a/tests/0005_Unit/CheckboxesFieldTest.php +++ b/tests/0005_Unit/CheckboxesFieldTest.php @@ -37,94 +37,136 @@ public function provider() { $dataset = array( array( - 'fields' => array( - 'fieldtype' => 'checkboxes', - 'name' => 'question', - 'required' => '0', - 'default_values' => '', - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => array(''), - 'expectedIsValid' => true + 'fields' => array( + 'fieldtype' => 'checkboxes', + 'name' => 'question', + 'required' => '0', + 'default_values' => '', + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ), + 'data' => null, + 'expectedValue' => array(''), + 'expectedIsValid' => true ), array( - 'fields' => array( - 'fieldtype' => 'checkboxes', - 'name' => 'question', - 'required' => '0', - 'default_values' => '2', - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => array('2'), - 'expectedIsValid' => true + 'fields' => array( + 'fieldtype' => 'checkboxes', + 'name' => 'question', + 'required' => '0', + 'default_values' => '2', + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ), + 'data' => null, + 'expectedValue' => array('2'), + 'expectedIsValid' => true ), array( - 'fields' => array( - 'fieldtype' => 'checkboxes', - 'name' => 'question', - 'required' => '0', - 'default_values' => "3\r\n5", - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => array('3', '5'), - 'expectedIsValid' => true + 'fields' => array( + 'fieldtype' => 'checkboxes', + 'name' => 'question', + 'required' => '0', + 'default_values' => "3\r\n5", + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ), + 'data' => null, + 'expectedValue' => array('3', '5'), + 'expectedIsValid' => true ), array( - 'fields' => array( - 'fieldtype' => 'checkboxes', - 'name' => 'question', - 'required' => '0', - 'default_values' => "3\r\n5", - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always', - 'range_min' => 3, - 'range_max' => 4, - ), - 'data' => null, - 'expectedValue' => array('3', '5'), - 'expectedIsValid' => false + 'fields' => array( + 'fieldtype' => 'checkboxes', + 'name' => 'question', + 'required' => '0', + 'default_values' => "3\r\n5", + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '3', + 'range_max' => '4', + ] + ] + ], + ), + 'data' => null, + 'expectedValue' => array('3', '5'), + 'expectedIsValid' => false ), array( - 'fields' => array( - 'fieldtype' => 'checkboxes', - 'name' => 'question', - 'required' => '0', - 'default_values' => "3\r\n5\r\n6", - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always', - 'range_min' => 3, - 'range_max' => 4, - ), - 'data' => null, - 'expectedValue' => array('3', '5', '6'), - 'expectedIsValid' => true + 'fields' => array( + 'fieldtype' => 'checkboxes', + 'name' => 'question', + 'required' => '0', + 'default_values' => "3\r\n5\r\n6", + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '3', + 'range_max' => '4', + ] + ] + ], + ), + 'data' => null, + 'expectedValue' => array('3', '5', '6'), + 'expectedIsValid' => true ), array( - 'fields' => array( - 'fieldtype' => 'checkboxes', - 'name' => 'question', - 'required' => '0', - 'default_values' => "1\r\n2\r\n3\r\n5\r\n6", - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always', - 'range_min' => 3, - 'range_max' => 4, - ), - 'data' => null, - 'expectedValue' => array('1', '2', '3', '5', '6'), - 'expectedIsValid' => false + 'fields' => array( + 'fieldtype' => 'checkboxes', + 'name' => 'question', + 'required' => '0', + 'default_values' => "1\r\n2\r\n3\r\n5\r\n6", + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '3', + 'range_max' => '4', + ] + ] + ], + ), + 'data' => null, + 'expectedValue' => array('1', '2', '3', '5', '6'), + 'expectedIsValid' => false ), ); @@ -135,6 +177,8 @@ public function provider() { * @dataProvider provider */ public function testFieldAvailableValue($fields, $data, $expectedValue, $expectedValidity) { + $section = $this->getSection(); + $fields[$section::getForeignKeyField()] = $section->getID(); $fieldInstance = new PluginFormcreatorCheckboxesField($fields, $data); $availableValues = $fieldInstance->getAvailableValues(); @@ -164,8 +208,14 @@ public function testFieldValue($fields, $data, $expectedValue, $expectedValidity * @dataProvider provider */ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidity) { - $fieldInstance = new PluginFormcreatorCheckboxesField($fields, $data); + $section = $this->getSection(); + $fields[$section::getForeignKeyField()] = $section->getID(); + + $question = new PluginFormcreatorQuestion(); + $question->add($fields); + $question->updateParameters($fields); + $fieldInstance = new PluginFormcreatorCheckboxesField($question->fields, $data); $values = json_encode(explode("\r\n", $fields['default_values']), JSON_OBJECT_AS_ARRAY); $isValid = $fieldInstance->isValid($values); $this->assertEquals($expectedValidity, $isValid); @@ -211,4 +261,17 @@ public function testPrepareInputForSave() { $this->assertEquals('something\r\nsomething else', $out['values']); $this->assertEquals("something", $out['default_values']); } + + private function getSection() { + $form = new PluginFormcreatorForm(); + $form->add([ + 'name' => 'form' + ]); + $section = new PluginFormcreatorSection(); + $section->add([ + $form::getForeignKeyField() => $form->getID(), + 'name' => 'section', + ]); + return $section; + } } \ No newline at end of file diff --git a/tests/0005_Unit/FloatFieldTest.php b/tests/0005_Unit/FloatFieldTest.php index 098c5689d..d802427be 100644 --- a/tests/0005_Unit/FloatFieldTest.php +++ b/tests/0005_Unit/FloatFieldTest.php @@ -134,10 +134,29 @@ public function testFieldValue($fields, $data, $expectedValue, $expectedValidity * @dataProvider provider */ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidity) { - $fieldInstance = new PluginFormcreatorFloatField($fields, $data); + $section = $this->getSection(); + $fields[$section::getForeignKeyField()] = $section->getID(); + + $question = new PluginFormcreatorQuestion(); + $question->add($fields); + $this->assertFalse($question->isNewItem(), json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); + $question->updateParameters($fields); + $fieldInstance = new PluginFormcreatorFloatField($question->fields, $data); $isValid = $fieldInstance->isValid($fields['default_values']); $this->assertEquals($expectedValidity, $isValid); } -} \ No newline at end of file + private function getSection() { + $form = new PluginFormcreatorForm(); + $form->add([ + 'name' => 'form' + ]); + $section = new PluginFormcreatorSection(); + $section->add([ + $form::getForeignKeyField() => $form->getID(), + 'name' => 'section', + ]); + return $section; + } +} diff --git a/tests/0005_Unit/IntegerFieldTest.php b/tests/0005_Unit/IntegerFieldTest.php index 1f153e9b6..a9b3e3c07 100644 --- a/tests/0005_Unit/IntegerFieldTest.php +++ b/tests/0005_Unit/IntegerFieldTest.php @@ -35,103 +35,149 @@ class IntegerFieldTest extends SuperAdminTestCase { public function provider() { $dataset = array( - array( - 'fields' => array( - 'fieldtype' => 'integer', - 'name' => 'question', - 'required' => '0', - 'default_values' => '', - 'order' => '1', - 'show_rule' => 'always', - 'show_empty' => '0', - 'values' => '' - ), - 'data' => null, - 'expectedValue' => '', - 'expectedIsValid' => true + array( + 'fields' => array( + 'fieldtype' => 'integer', + 'name' => 'question', + 'required' => '0', + 'default_values' => '', + 'order' => '1', + 'show_rule' => 'always', + 'show_empty' => '0', + 'values' => '', + '_parameters' => [ + 'integer' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => '', + ] + ], ), - array( - 'fields' => array( - 'fieldtype' => 'integer', - 'name' => 'question', - 'required' => '0', - 'default_values' => '2', - 'order' => '1', - 'show_rule' => 'always', - 'show_empty' => '0', - 'values' => '' - ), - 'data' => null, - 'expectedValue' => '2', - 'expectedIsValid' => true + 'data' => null, + 'expectedValue' => '', + 'expectedIsValid' => true + ), + array( + 'fields' => array( + 'fieldtype' => 'integer', + 'name' => 'question', + 'required' => '0', + 'default_values' => '2', + 'order' => '1', + 'show_rule' => 'always', + 'show_empty' => '0', + 'values' => '', + '_parameters' => [ + 'integer' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => '', + ] + ], ), - array( - 'fields' => array( - 'fieldtype' => 'integer', - 'name' => 'question', - 'required' => '0', - 'default_values' => "2", - 'order' => '1', - 'show_rule' => 'always', - 'show_empty' => '0', - 'range_min' => 3, - 'range_max' => 4, - ), - 'data' => null, - 'expectedValue' => '2', - 'expectedIsValid' => false + 'data' => null, + 'expectedValue' => '2', + 'expectedIsValid' => true + ), + array( + 'fields' => array( + 'fieldtype' => 'integer', + 'name' => 'question', + 'required' => '0', + 'default_values' => "2", + 'order' => '1', + 'show_rule' => 'always', + 'show_empty' => '0', + '_parameters' => [ + 'integer' => [ + 'range' => [ + 'range_min' => 3, + 'range_max' => 4, + ], + 'regex' => '', + ] + ], ), - array( - 'fields' => array( - 'fieldtype' => 'integer', - 'name' => 'question', - 'required' => '0', - 'default_values' => "5", - 'order' => '1', - 'show_rule' => 'always', - 'show_empty' => '0', - 'values' => '', - 'range_min' => 3, - 'range_max' => 4, - ), - 'data' => null, - 'expectedValue' => '5', - 'expectedIsValid' => false + 'data' => null, + 'expectedValue' => '2', + 'expectedIsValid' => false + ), + array( + 'fields' => array( + 'fieldtype' => 'integer', + 'name' => 'question', + 'required' => '0', + 'default_values' => "5", + 'order' => '1', + 'show_rule' => 'always', + 'show_empty' => '0', + 'values' => '', + '_parameters' => [ + 'integer' => [ + 'range' => [ + 'range_min' => 3, + 'range_max' => 4, + ], + 'regex' => '', + ] + ], ), - array( - 'fields' => array( - 'fieldtype' => 'integer', - 'name' => 'question', - 'required' => '0', - 'default_values' => "3.4", - 'order' => '1', - 'show_rule' => 'always', - 'show_empty' => '0', - 'values' => '', - 'range_min' => 3, - 'range_max' => 4, - ), - 'data' => null, - 'expectedValue' => '3.4', - 'expectedIsValid' => false + 'data' => null, + 'expectedValue' => '5', + 'expectedIsValid' => false + ), + array( + 'fields' => array( + 'fieldtype' => 'integer', + 'name' => 'question', + 'required' => '0', + 'default_values' => "3.4", + 'order' => '1', + 'show_rule' => 'always', + 'show_empty' => '0', + 'values' => '', + '_parameters' => [ + 'integer' => [ + 'range' => [ + 'range_min' => 3, + 'range_max' => 4, + ], + 'regex' => '', + ] + ], ), - array( - 'fields' => array( - 'fieldtype' => 'integer', - 'name' => 'question', - 'required' => '0', - 'default_values' => "4", - 'order' => '1', - 'show_rule' => 'always', - 'show_empty' => '0', - 'values' => '', - 'range_min' => 3, - 'range_max' => 4, - ), - 'data' => null, - 'expectedValue' => '4', - 'expectedIsValid' => true + 'data' => null, + 'expectedValue' => '3.4', + 'expectedIsValid' => false + ), + array( + 'fields' => array( + 'fieldtype' => 'integer', + 'name' => 'question', + 'required' => '0', + 'default_values' => "4", + 'order' => '1', + 'show_rule' => 'always', + 'show_empty' => '0', + 'values' => '', + '_parameters' => [ + 'integer' => [ + 'range' => [ + 'range_min' => 3, + 'range_max' => 4, + ], + 'regex' => '', + ] + ], ), + 'data' => null, + 'expectedValue' => '4', + 'expectedIsValid' => true + ), ); return $dataset; @@ -151,10 +197,28 @@ public function testFieldValue($fields, $data, $expectedValue, $expectedValidity * @dataProvider provider */ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidity) { - $fieldInstance = new PluginFormcreatorIntegerField($fields, $data); + $section = $this->getSection(); + $fields[$section::getForeignKeyField()] = $section->getID(); + + $question = new PluginFormcreatorQuestion(); + $question->add($fields); + $question->updateParameters($fields); + $fieldInstance = new PluginFormcreatorIntegerField($question->fields, $data); $isValid = $fieldInstance->isValid($fields['default_values']); $this->assertEquals($expectedValidity, $isValid); } + private function getSection() { + $form = new PluginFormcreatorForm(); + $form->add([ + 'name' => 'form' + ]); + $section = new PluginFormcreatorSection(); + $section->add([ + $form::getForeignKeyField() => $form->getID(), + 'name' => 'section', + ]); + return $section; + } } \ No newline at end of file diff --git a/tests/0005_Unit/MultiselectFieldTest.php b/tests/0005_Unit/MultiselectFieldTest.php index 78500f9ac..c4d87e95d 100644 --- a/tests/0005_Unit/MultiselectFieldTest.php +++ b/tests/0005_Unit/MultiselectFieldTest.php @@ -36,87 +36,121 @@ class MultielectFieldTest extends SuperAdminTestCase { public function provider() { $dataset = array( - array( - 'fields' => array( - 'fieldtype' => 'select', - 'name' => 'question', - 'required' => '0', - 'show_empty' => '0', - 'default_values' => '', - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => array(''), - 'expectedIsValid' => true + array( + 'fields' => array( + 'fieldtype' => 'multiselect', + 'name' => 'question', + 'required' => '0', + 'show_empty' => '0', + 'default_values' => '', + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'multiselect' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], ), - array( - 'fields' => array( - 'fieldtype' => 'select', - 'name' => 'question', - 'required' => '0', - 'show_empty' => '0', - 'default_values' => '3', - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => array('3'), - 'expectedIsValid' => true + 'data' => null, + 'expectedValue' => array(''), + 'expectedIsValid' => true + ), + array( + 'fields' => array( + 'fieldtype' => 'multiselect', + 'name' => 'question', + 'required' => '0', + 'show_empty' => '0', + 'default_values' => '3', + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'multiselect' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], ), - array( - 'fields' => array( - 'fieldtype' => 'select', - 'name' => 'question', - 'required' => '0', - 'show_empty' => '0', - 'default_values' => '3', - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always', - 'range_min' => 2, - 'range_max' => 4, - ), - 'data' => null, - 'expectedValue' => array('3'), - 'expectedIsValid' => false + 'data' => null, + 'expectedValue' => array('3'), + 'expectedIsValid' => true + ), + array( + 'fields' => array( + 'fieldtype' => 'multiselect', + 'name' => 'question', + 'required' => '0', + 'show_empty' => '0', + 'default_values' => '3', + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'multiselect' => [ + 'range' => [ + 'range_min' => '2', + 'range_max' => '4', + ] + ] + ], ), - array( - 'fields' => array( - 'fieldtype' => 'select', - 'name' => 'question', - 'required' => '0', - 'show_empty' => '0', - 'default_values' => "3\r\n4", - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always', - 'range_min' => 2, - 'range_max' => 4, - ), - 'data' => null, - 'expectedValue' => array('3', '4'), - 'expectedIsValid' => true + 'data' => null, + 'expectedValue' => array('3'), + 'expectedIsValid' => false + ), + array( + 'fields' => array( + 'fieldtype' => 'multiselect', + 'name' => 'question', + 'required' => '0', + 'show_empty' => '0', + 'default_values' => "3\r\n4", + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'multiselect' => [ + 'range' => [ + 'range_min' => '2', + 'range_max' => '4', + ] + ] + ], ), - array( - 'fields' => array( - 'fieldtype' => 'select', - 'name' => 'question', - 'required' => '0', - 'show_empty' => '0', - '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' => 'always', - 'range_min' => 2, - 'range_max' => 4, - ), - 'data' => null, - 'expectedValue' => array('3', '4', '2', '1', '6'), - 'expectedIsValid' => false + 'data' => null, + 'expectedValue' => array('3', '4'), + 'expectedIsValid' => true + ), + array( + 'fields' => array( + 'fieldtype' => 'multiselect', + 'name' => 'question', + 'required' => '0', + 'show_empty' => '0', + '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' => 'always', + '_parameters' => [ + 'multiselect' => [ + 'range' => [ + 'range_min' => '2', + 'range_max' => '4', + ] + ] + ], ), + 'data' => null, + 'expectedValue' => array('3', '4', '2', '1', '6'), + 'expectedIsValid' => false + ), ); return $dataset; @@ -126,6 +160,8 @@ public function provider() { * @dataProvider provider */ public function testFieldAvailableValue($fields, $data, $expectedValue, $expectedValidity) { + $section = $this->getSection(); + $fields[$section::getForeignKeyField()] = $section->getID(); $fieldInstance = new PluginFormcreatorMultiSelectField($fields, $data); $availableValues = $fieldInstance->getAvailableValues(); @@ -155,8 +191,14 @@ public function testFieldValue($fields, $data, $expectedValue, $expectedValidity * @dataProvider provider */ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidity) { - $fieldInstance = new PluginFormcreatorMultiSelectField($fields, $data); + $section = $this->getSection(); + $fields[$section::getForeignKeyField()] = $section->getID(); + + $question = new PluginFormcreatorQuestion(); + $question->add($fields); + $question->updateParameters($fields); + $fieldInstance = new PluginFormcreatorMultiSelectField($question->fields, $data); $values = json_encode(explode("\r\n", $fields['default_values']), JSON_OBJECT_AS_ARRAY); $isValid = $fieldInstance->isValid($values); $this->assertEquals($expectedValidity, $isValid); @@ -202,4 +244,17 @@ public function testPrepareInputForSave() { $this->assertEquals('something\r\nsomething else', $out['values']); $this->assertEquals("something", $out['default_values']); } + + private function getSection() { + $form = new PluginFormcreatorForm(); + $form->add([ + 'name' => 'form' + ]); + $section = new PluginFormcreatorSection(); + $section->add([ + $form::getForeignKeyField() => $form->getID(), + 'name' => 'section', + ]); + return $section; + } } \ No newline at end of file diff --git a/tests/0005_Unit/QuestionTest.php b/tests/0005_Unit/QuestionTest.php new file mode 100644 index 000000000..41be91043 --- /dev/null +++ b/tests/0005_Unit/QuestionTest.php @@ -0,0 +1,82 @@ + [ + 'input' => [ + 'fieldtype' => 'text', + 'name' => "here is a single quote (')", + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ], + 'expected' => [ + 'fieldtype' => 'text', + 'name' => "here is a single quote (\')", + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ] + ], + ]; + } + + /** + * @dataProvider inputProvider + * @param array $input + * @param array $expected + */ + public function testPrepareInputForAdd($input, $expected) { + $section = $this->getSection(); + $input[$section::getForeignKeyField()] = $section->getID(); + + $question = new PluginFormcreatorQuestion(); + $output = $question->prepareInputForAdd($input); + $this->assertEquals($expected['name'], $output['name'], json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); + $this->assertArrayHasKey('uuid', $output); + } + + /** + * @dataProvider inputProvider + * @param array $input + * @param array $expected + */ + public function testPrepareInputForUpdate($input, $expected) { + $section = $this->getSection(); + $input[$section::getForeignKeyField()] = $section->getID(); + + $question = new PluginFormcreatorQuestion(); + $output = $question->prepareInputForAdd($input); + $this->assertEquals($expected['name'], $output['name']); + } + + private function getSection() { + $form = new PluginFormcreatorForm(); + $form->add([ + 'name' => 'form' + ]); + $section = new PluginFormcreatorSection(); + $section->add([ + $form::getForeignKeyField() => $form->getID(), + 'name' => 'section', + ]); + return $section; + } +} \ No newline at end of file diff --git a/tests/0005_Unit/Question_ConditionTest.php b/tests/0005_Unit/Question_ConditionTest.php index e9ba057be..55fd83dfa 100644 --- a/tests/0005_Unit/Question_ConditionTest.php +++ b/tests/0005_Unit/Question_ConditionTest.php @@ -62,19 +62,41 @@ public static function setUpBeforeClass() { // Create a question self::$question = new PluginFormcreatorQuestion(); - self::$question->add(array( - 'name' => 'text question', - 'fieldtype' => 'text', - 'plugin_formcreator_sections_id' => $section->getID(), - )); + self::$question->add([ + 'name' => 'text question', + 'fieldtype' => 'text', + 'plugin_formcreator_sections_id' => $section->getID(), + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ]); for ($i = 0; $i < 4; $i++) { $item = new PluginFormcreatorQuestion(); - $item->add(array( - 'fieldtype' => 'text', - 'name' => "question $i", - 'plugin_formcreator_sections_id' => $section->getID(), - )); + $item->add([ + 'fieldtype' => 'text', + 'name' => "question $i", + 'plugin_formcreator_sections_id' => $section->getID(), + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ]); self::$questionPool[$i] = $item->getID(); } } @@ -296,6 +318,17 @@ public function testConditionsEvaluation($show_rule, $conditions, $answers, $exp 'id' => self::$question->getID(), 'fieldtype' => 'text', 'show_rule' => $show_rule, + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], ); self::$question->update($input); self::$question->updateConditions($input); diff --git a/tests/0005_Unit/TextFieldTest.php b/tests/0005_Unit/TextFieldTest.php new file mode 100644 index 000000000..1f4128269 --- /dev/null +++ b/tests/0005_Unit/TextFieldTest.php @@ -0,0 +1,169 @@ + [ + 'fieldtype' => 'text', + 'name' => 'question', + 'required' => '0', + 'show_empty' => '0', + 'default_values' => '', + 'values' => "", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => '1', + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'text', + 'name' => 'question', + 'required' => '0', + 'show_empty' => '0', + 'default_values' => 'a', + 'values' => "", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '5', + 'range_max' => '8', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => '1', + 'expectedIsValid' => false + ], + [ + 'fields' => [ + 'fieldtype' => 'text', + 'name' => 'question', + 'required' => '0', + 'show_empty' => '0', + 'default_values' => 'short', + 'values' => "", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '6', + 'range_max' => '8', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => '1', + 'expectedIsValid' => false + ], + [ + 'fields' => [ + 'fieldtype' => 'text', + 'name' => 'question', + 'required' => '0', + 'show_empty' => '0', + 'default_values' => 'very long', + 'values' => "", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '6', + 'range_max' => '8', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => '1', + 'expectedIsValid' => false + ], + [ + 'fields' => [ + 'fieldtype' => 'text', + 'name' => 'question', + 'required' => '0', + 'show_empty' => '0', + 'default_values' => 'very long', + 'values' => "", + 'order' => '1', + 'show_rule' => 'good', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '3', + 'range_max' => '8', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => '1', + 'expectedIsValid' => false + ], + ]; + return $dataset; + } + + /** + * @dataProvider provider + */ + public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidity) { + $section = $this->getSection(); + $fields[$section::getForeignKeyField()] = $section->getID(); + + $question = new PluginFormcreatorQuestion(); + $question->add($fields); + $question->updateParameters($fields); + + $fieldInstance = new PluginFormcreatorTextField($question->fields, $data); + + $isValid = $fieldInstance->isValid($fields['default_values']); + $this->assertEquals($expectedValidity, $isValid, $_SESSION['MESSAGE_AFTER_REDIRECT']); + } + + private function getSection() { + $form = new PluginFormcreatorForm(); + $form->add([ + 'name' => 'form' + ]); + $section = new PluginFormcreatorSection(); + $section->add([ + $form::getForeignKeyField() => $form->getID(), + 'name' => 'section', + ]); + return $section; + } +} \ No newline at end of file diff --git a/tests/0010_Integration/CloneTest.php b/tests/0010_Integration/CloneTest.php index 51e7125cd..4d2296449 100644 --- a/tests/0010_Integration/CloneTest.php +++ b/tests/0010_Integration/CloneTest.php @@ -47,19 +47,26 @@ public static function setUpBeforeClass() { $form_profile = new PluginFormcreatorForm_Profile; // create objects - $forms_id = $form->add(array('name' => "test clone form", - 'is_active' => true, - 'validation_required' => PluginFormcreatorForm_Validator::VALIDATION_USER)); - - $sections_id = $form_section->add(array('name' => "test clone section", - 'plugin_formcreator_forms_id' => $forms_id)); - - $questions_id_1 = $form_question->add(array('name' => "test clone question 1", - 'fieldtype' => 'text', - 'plugin_formcreator_sections_id' => $sections_id)); - $questions_id_2 = $form_question->add(array('name' => "test clone question 2", - 'fieldtype' => 'textarea', - 'plugin_formcreator_sections_id' => $sections_id)); + $forms_id = $form->add(['name' => "test clone form", + 'is_active' => true, + 'validation_required' => PluginFormcreatorForm_Validator::VALIDATION_USER]); + + $sections_id = $form_section->add(['name' => "test clone section", + 'plugin_formcreator_forms_id' => $forms_id]); + + $questions_id_1 = $form_question->add(['name' => "test clone question 1", + 'fieldtype' => 'text', + 'plugin_formcreator_sections_id' => $sections_id, + '_parameters' => [ + 'text' => [ + 'regex' => '', + 'range' => ['min' => '', 'max' => ''], + ] + ], + ]); + $questions_id_2 = $form_question->add(['name' => "test clone question 2", + 'fieldtype' => 'textarea', + 'plugin_formcreator_sections_id' => $sections_id]); } /** diff --git a/tests/0010_Integration/ExportImportTest.php b/tests/0010_Integration/ExportImportTest.php index 56ae8244e..b13df8dee 100644 --- a/tests/0010_Integration/ExportImportTest.php +++ b/tests/0010_Integration/ExportImportTest.php @@ -56,12 +56,38 @@ public static function setUpBeforeClass() { $sections_id = $form_section->add(['name' => "test export section", 'plugin_formcreator_forms_id' => $forms_id]); - $questions_id_1 = $form_question->add(['name' => "test export question 1", - 'fieldtype' => 'text', - 'plugin_formcreator_sections_id' => $sections_id]); - $questions_id_2 = $form_question->add(['name' => "test export question 2", - 'fieldtype' => 'textarea', - 'plugin_formcreator_sections_id' => $sections_id]); + $questions_id_1 = $form_question->add([ + 'name' => "test export question 1", + 'fieldtype' => 'text', + 'plugin_formcreator_sections_id' => $sections_id, + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ]); + $questions_id_2 = $form_question->add([ + 'name' => "test export question 2", + 'fieldtype' => 'textarea', + 'plugin_formcreator_sections_id' => $sections_id, + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ]); $form_condition->add(['plugin_formcreator_questions_id' => $questions_id_1, 'show_field' => $questions_id_2, @@ -189,7 +215,8 @@ public function testExportTarget() { * @depends testExportForm */ public function testImportForm($export = []) { - $forms_id = PluginFormcreatorForm::import($export); + $importLinker = new PluginFormcreatorImportLinker(); + $forms_id = PluginFormcreatorForm::import($importLinker, $export); $this->assertNotFalse($forms_id); @@ -202,7 +229,8 @@ public function testImportForm($export = []) { * @depends testExportSection */ public function testImportSection($forms_id, $export = []) { - $sections_id = PluginFormcreatorSection::import($forms_id, $export); + $importLinker = new PluginFormcreatorImportLinker(); + $sections_id = PluginFormcreatorSection::import($importLinker, $forms_id, $export); $this->assertNotFalse($sections_id); @@ -215,7 +243,8 @@ public function testImportSection($forms_id, $export = []) { * @depends testExportQuestion */ public function testImportQuestion($sections_id, $export = []) { - $questions_id = PluginFormcreatorQuestion::import($sections_id, $export); + $importLinker = new PluginFormcreatorImportLinker(); + $questions_id = PluginFormcreatorQuestion::import($importLinker, $sections_id, $export); $this->assertNotFalse($questions_id); diff --git a/tests/0010_Integration/FormDuplicationTest.php b/tests/0010_Integration/FormDuplicationTest.php index 2d7666325..0836967c9 100644 --- a/tests/0010_Integration/FormDuplicationTest.php +++ b/tests/0010_Integration/FormDuplicationTest.php @@ -51,47 +51,91 @@ public function setUp() { ); $this->sectionData = array( - array( - 'name' => 'a section', - 'questions' => array ( - array( - 'name' => 'text question', - 'fieldtype' => 'text' - ), - array( - 'name' => 'other text question', - 'fieldtype' => 'text' - ), - ), + array( + 'name' => 'a section', + 'questions' => array ( + array( + 'name' => 'text question', + 'fieldtype' => 'text', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ), + array( + 'name' => 'other text question', + 'fieldtype' => 'text', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ), ), - array( - 'name' => 'an other section', - 'questions' => array ( - array( - 'name' => 'text question', - 'fieldtype' => 'text' - ), - array( - 'name' => 'other text question', - 'fieldtype' => 'text', - 'show_rule' => 'hidden', - 'show_field' => 'text question', - 'show_condition' => '==', - 'show_value' => 'azerty', - ), - ), + ), + array( + 'name' => 'an other section', + 'questions' => array ( + array( + 'name' => 'text question', + 'fieldtype' => 'text', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ), + array( + 'name' => 'other text question', + 'fieldtype' => 'text', + 'show_rule' => 'hidden', + 'show_field' => 'text question', + 'show_condition' => '==', + 'show_value' => 'azerty', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ), ), + ), ); $this->targetData = array( - array( - 'name' => 'target ticket 1', - 'itemtype' => 'PluginFormcreatorTargetTicket', - ), - array( - 'name' => 'target ticket 2', - 'itemtype' => 'PluginFormcreatorTargetTicket', - ) + array( + 'name' => 'target ticket 1', + 'itemtype' => 'PluginFormcreatorTargetTicket', + ), + array( + 'name' => 'target ticket 2', + 'itemtype' => 'PluginFormcreatorTargetTicket', + ) ); } @@ -102,7 +146,7 @@ public function testInitCreateForm() { foreach ($this->sectionData as $sectionData) { // Keep questions data set apart from sections data - $questionsData = $sectionData['questions']; + $questionData = $sectionData['questions']; unset($sectionData['questions']); // Create section @@ -111,16 +155,16 @@ public function testInitCreateForm() { $section->add($sectionData); $this->assertFalse($section->isNewItem()); $sectionId = $section->getID(); - foreach ($questionsData as $questionData) { + foreach ($questionData as $oneQuestionData) { // Create question - $questionData ['plugin_formcreator_sections_id'] = $section->getID(); + $oneQuestionData ['plugin_formcreator_sections_id'] = $section->getID(); $question = new PluginFormcreatorQuestion(); - $question->add($questionData); - $this->assertFalse($question->isNewItem(), $_SESSION['MESSAGE_AFTER_REDIRECT']); + $question->add($oneQuestionData); + $this->assertFalse($question->isNewItem(), json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); $questionData['id'] = $question->getID(); if (isset($questionData['show_rule']) && $questionData['show_rule'] != 'always') { - $showFieldName = $questionData['show_field']; + $showFieldName = $oneQuestionData['show_field']; $showfield = new PluginFormcreatorQuestion(); $showfield->getFromDBByCrit([ 'AND' => [ @@ -128,8 +172,8 @@ public function testInitCreateForm() { 'name' => $showFieldName ] ]); - $questionData['show_field'] = $showfield->getID(); - $question->updateConditions($questionData); + $oneQuestionData['show_field'] = $showfield->getID(); + $question->updateConditions($oneQuestionData); } } foreach ($this->targetData as $targetData) { @@ -188,4 +232,4 @@ public function testDuplicateForm(PluginFormcreatorForm $form) { } } -} \ No newline at end of file +} diff --git a/tests/0010_Integration/QuestionConditionTest.php b/tests/0010_Integration/QuestionConditionTest.php index 76224a84e..e628621c0 100644 --- a/tests/0010_Integration/QuestionConditionTest.php +++ b/tests/0010_Integration/QuestionConditionTest.php @@ -344,4 +344,4 @@ public function testConditionForManyQuestions() { $this->assertEquals(false, $visibility["formcreator_field_$secondQuestionId"]); $this->assertEquals(true, $visibility["formcreator_field_$thirdQuestionId"]); } -} \ No newline at end of file +} diff --git a/tests/0010_Integration/QuestionTest.php b/tests/0010_Integration/QuestionTest.php deleted file mode 100644 index 48da5a395..000000000 --- a/tests/0010_Integration/QuestionTest.php +++ /dev/null @@ -1,94 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class QuestionTest extends SuperAdminTestCase { - - public function setUp() { - parent::setUp(); - - $this->formData = array( - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'a form', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 0 - ); - - $this->sectionData = array( - 'name' => 'a section', - ); - - $this->questionTextData = array( - 'name' => 'text question', - 'fieldtype' => 'text' - ); - } - - public function testInitCreateForm() { - $form = new PluginFormcreatorForm(); - $form->add($this->formData); - $this->assertFalse($form->isNewItem()); - - return $form; - } - - /** - * @depends testInitCreateForm - * @param PluginFormcreatorForm $form - */ - public function testInitCreateSection(PluginFormcreatorForm $form) { - $section = new PluginFormcreatorSection(); - $this->sectionData = $this->sectionData + array( - 'plugin_formcreator_forms_id' => $form->getID() - ); - $section->add($this->sectionData); - $this->assertFalse($section->isNewItem()); - - return $section; - } - - /** - * @depends testInitCreateSection - * @param PluginFormcreatorSection $section - */ - public function testCreateQuestionText(PluginFormcreatorSection $section) { - $question = new PluginFormcreatorQuestion(); - $this->questionTextData = $this->questionTextData + array('plugin_formcreator_sections_id' => $section->getID()); - $question->add($this->questionTextData); - $this->assertFalse($question->isNewItem()); - - return $question; - } - -} \ No newline at end of file From b39c899d36526d8be8d76e4e2e043b6468aca8f0 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 29 Jan 2018 16:29:34 +0100 Subject: [PATCH 003/192] test: update tests --- inc/question.class.php | 1 + tests/0005_Unit/FloatFieldTest.php | 55 ++++++++++-- tests/0005_Unit/IntegerFieldTest.php | 12 +-- .../0010_Integration/FormDuplicationTest.php | 1 + .../QuestionConditionTest.php | 86 +++++++++++++++++-- tests/0010_Integration/UrgencyTest.php | 76 +++++++++------- 6 files changed, 178 insertions(+), 53 deletions(-) diff --git a/inc/question.class.php b/inc/question.class.php index 1c72012fc..013f4b1f1 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -613,6 +613,7 @@ public function updateParameters($input) { $parameters = $this->field->getUsedParameters(); if (isset($input['_parameters'][$this->fields['fieldtype']])) { foreach ($input['_parameters'][$this->fields['fieldtype']] as $fieldName => $parameterInput) { + // echo var_dump($parameterInput); $parameters[$fieldName]->getFromDBByCrit([ 'plugin_formcreator_questions_id' => $this->getID(), 'fieldname' => $fieldName, diff --git a/tests/0005_Unit/FloatFieldTest.php b/tests/0005_Unit/FloatFieldTest.php index d802427be..1f0fb9266 100644 --- a/tests/0005_Unit/FloatFieldTest.php +++ b/tests/0005_Unit/FloatFieldTest.php @@ -44,7 +44,16 @@ public function provider() { 'order' => '1', 'show_rule' => 'always', 'show_empty' => '0', - 'values' => '' + 'values' => '', + '_parameters' => [ + 'float' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => ['regex' => ''], + ] + ] ], 'data' => null, 'expectedValue' => '', @@ -59,7 +68,16 @@ public function provider() { 'order' => '1', 'show_rule' => 'always', 'show_empty' => '0', - 'values' => '' + 'values' => '', + '_parameters' => [ + 'float' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => ['regex' => ''], + ] + ] ], 'data' => null, 'expectedValue' => '2', @@ -74,8 +92,15 @@ public function provider() { 'order' => '1', 'show_rule' => 'always', 'show_empty' => '0', - 'range_min' => 3, - 'range_max' => 4, + '_parameters' => [ + 'float' => [ + 'range' => [ + 'range_min' => 3, + 'range_max' => 4, + ], + 'regex' => ['regex' => ''], + ] + ] ], 'data' => null, 'expectedValue' => '2', @@ -91,8 +116,15 @@ public function provider() { 'show_rule' => 'always', 'show_empty' => '0', 'values' => '', - 'range_min' => 3, - 'range_max' => 4, + '_parameters' => [ + 'float' => [ + 'range' => [ + 'range_min' => 3, + 'range_max' => 4, + ], + 'regex' => ['regex' => ''], + ] + ] ], 'data' => null, 'expectedValue' => '5', @@ -108,8 +140,15 @@ public function provider() { 'show_rule' => 'always', 'show_empty' => '0', 'values' => '', - 'range_min' => 3, - 'range_max' => 4, + '_parameters' => [ + 'float' => [ + 'range' => [ + 'range_min' => 3, + 'range_max' => 4, + ], + 'regex' => ['regex' => ''], + ] + ] ], 'data' => null, 'expectedValue' => '3.141592', diff --git a/tests/0005_Unit/IntegerFieldTest.php b/tests/0005_Unit/IntegerFieldTest.php index a9b3e3c07..366aba2e5 100644 --- a/tests/0005_Unit/IntegerFieldTest.php +++ b/tests/0005_Unit/IntegerFieldTest.php @@ -51,7 +51,7 @@ public function provider() { 'range_min' => '', 'range_max' => '', ], - 'regex' => '', + 'regex' => ['regex' => ''], ] ], ), @@ -75,7 +75,7 @@ public function provider() { 'range_min' => '', 'range_max' => '', ], - 'regex' => '', + 'regex' => ['regex' => ''], ] ], ), @@ -98,7 +98,7 @@ public function provider() { 'range_min' => 3, 'range_max' => 4, ], - 'regex' => '', + 'regex' => ['regex' => ''], ] ], ), @@ -122,7 +122,7 @@ public function provider() { 'range_min' => 3, 'range_max' => 4, ], - 'regex' => '', + 'regex' => ['regex' => ''], ] ], ), @@ -146,7 +146,7 @@ public function provider() { 'range_min' => 3, 'range_max' => 4, ], - 'regex' => '', + 'regex' => ['regex' => ''], ] ], ), @@ -170,7 +170,7 @@ public function provider() { 'range_min' => 3, 'range_max' => 4, ], - 'regex' => '', + 'regex' => ['regex' => ''], ] ], ), diff --git a/tests/0010_Integration/FormDuplicationTest.php b/tests/0010_Integration/FormDuplicationTest.php index 0836967c9..440fa4a80 100644 --- a/tests/0010_Integration/FormDuplicationTest.php +++ b/tests/0010_Integration/FormDuplicationTest.php @@ -175,6 +175,7 @@ public function testInitCreateForm() { $oneQuestionData['show_field'] = $showfield->getID(); $question->updateConditions($oneQuestionData); } + $question->updateParameters($oneQuestionData); } foreach ($this->targetData as $targetData) { $target = new PluginFormcreatorTarget(); diff --git a/tests/0010_Integration/QuestionConditionTest.php b/tests/0010_Integration/QuestionConditionTest.php index e628621c0..636159242 100644 --- a/tests/0010_Integration/QuestionConditionTest.php +++ b/tests/0010_Integration/QuestionConditionTest.php @@ -54,19 +54,52 @@ public static function setUpBeforeClass() { self::$sectionData = [ [ - 'name' => 'a section', - 'questions' => [ + 'name' => 'a section', + 'questions' => [ [ - 'name' => 'text question', - 'fieldtype' => 'text', + 'name' => 'text question', + 'fieldtype' => 'text', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ] ], [ - 'name' => 'other text question', - 'fieldtype' => 'text', + 'name' => 'other text question', + 'fieldtype' => 'text', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ] ], [ 'name' => 'third text question', 'fieldtype' => 'text', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ] ], ], ], @@ -109,6 +142,7 @@ public static function setUpBeforeClass() { $questionData['show_field'] = $showfield->getID(); $question->updateConditions($questionData); } + $question->updateParameters($questionData); } foreach (self::$targetData as $targetData) { $target = new PluginFormcreatorTarget(); @@ -168,7 +202,7 @@ public function testConditionForSingleValue($condition) { $secondQuestionId = $question->getID(); $condition['show_field'] = [self::$questions[0]->getID()]; $condition['id'] = $secondQuestionId; - $question->update($condition + $question->fields); + $question->update($condition + self::$sectionData[0]['questions'][1]); $question->updateConditions($condition); //Run the condition @@ -265,19 +299,57 @@ public function testConditionForManyQuestions() { 'name' => 'text question 0', 'fieldtype' => 'text', 'plugin_formcreator_sections_id' => $sectionId, + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ] ]); + $this->assertFalse($questions[0]->isNewItem(), json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); + $secondQuestionId = $questions[1]->add([ 'name' => 'text question 1', 'fieldtype' => 'text', 'plugin_formcreator_sections_id' => $sectionId, 'show_rule' => 'hidden', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ] ]); + $this->assertFalse($questions[1]->isNewItem(), json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); + $thirdQuestionId = $questions[2]->add([ 'name' => 'text question 2', 'fieldtype' => 'text', 'plugin_formcreator_sections_id' => $sectionId, 'show_rule' => 'hidden', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ] ]); + $this->assertFalse($questions[2]->isNewItem(), json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); // create conditions $condition = new PluginFormcreatorQuestion_Condition(); diff --git a/tests/0010_Integration/UrgencyTest.php b/tests/0010_Integration/UrgencyTest.php index 4951040e1..b13fda4be 100644 --- a/tests/0010_Integration/UrgencyTest.php +++ b/tests/0010_Integration/UrgencyTest.php @@ -50,38 +50,49 @@ public function setUp() { 'validation_required' => 0 ); - $this->sectionData = array( - array( - 'name' => 'a section', - 'questions' => array ( - array( - 'name' => 'text question', - 'fieldtype' => 'text' - ), - array( - 'name' => 'custom urgency', - 'fieldtype' => 'urgency' - ), - ), - ), - ); - - $this->targetTicketData = array( - array( - 'name' => 'target 1', - 'itemtype' => 'PluginFormcreatorTargetTicket', - 'urgency_rule' => 'answer', - 'urgency_question' => 'custom urgency', - 'expected' => 5 - ), - array( - 'name' => 'target 2', - 'itemtype' => 'PluginFormcreatorTargetTicket', - 'urgency_rule' => 'none', - 'urgency_question' => '', - 'expected' => 3 - ) - ); + $this->sectionData = [ + [ + 'name' => 'a section', + 'questions' => [ + [ + 'name' => 'text question', + 'fieldtype' => 'text', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ], + [ + 'name' => 'custom urgency', + 'fieldtype' => 'urgency', + ], + ], + ], + ]; + + $this->targetTicketData = [ + [ + 'name' => 'target 1', + 'itemtype' => 'PluginFormcreatorTargetTicket', + 'urgency_rule' => 'answer', + 'urgency_question' => 'custom urgency', + 'expected' => 5 + ], + [ + 'name' => 'target 2', + 'itemtype' => 'PluginFormcreatorTargetTicket', + 'urgency_rule' => 'none', + 'urgency_question' => '', + 'expected' => 3 + ] + ]; } public function testInitCreateForm() { @@ -119,6 +130,7 @@ public function testInitCreateForm() { ]); $question->updateConditions($questionData); } + $question->updateParameters($questionData); } } From 0741de1fe469c89474212d8f86d2877ca7d7a02f Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 17 Apr 2018 09:38:03 +0200 Subject: [PATCH 004/192] fix(install): delete tables when the plugin is being uninstalled --- install/install.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/install/install.php b/install/install.php index 92713ff6a..bb3133f43 100644 --- a/install/install.php +++ b/install/install.php @@ -88,7 +88,7 @@ public function upgrade(Migration $migration) { require_once(__DIR__ . '/update_2.6.2_2.6.3.php'); plugin_formcreator_update_2_6_3($this->migration); - + case 2.7: case PLUGIN_FORMCREATOR_SCHEMA_VERSION: //Any schema version below or equal to 2.7 @@ -452,6 +452,9 @@ protected function deleteTables() { 'PluginFormcreatorTargetTicket', 'PluginFormcreatorItem_TargetTicket', 'PluginFormcreatorIssue', + 'PluginFormcreatorQuestionDependency', + 'PluginFormcreatorQuestionRange', + 'PluginFormcreatorQuestionRegex', ]; foreach ($itemtypes as $itemtype) { From 0feeffa90539575a8bffe4cf22ca6065c95d06f0 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 10 Oct 2017 16:09:23 +0200 Subject: [PATCH 005/192] test: migrate to atoum Signed-off-by: btry --- .travis.yml | 7 +- composer.json | 8 +- composer.lock | 841 +++++++++++++----- inc/form.class.php | 6 +- inc/form_answer.class.php | 8 +- inc/question.class.php | 14 +- inc/section.class.php | 9 +- setup.php | 2 +- tests/0000_Install/PluginInstallTest.php | 108 --- tests/0000_Install/SaveInstallTest.php | 57 -- tests/0005_Unit/ActorFieldTest.php | 184 ---- tests/0005_Unit/CheckboxesFieldTest.php | 277 ------ tests/0005_Unit/CommonTest.php | 41 - tests/0005_Unit/FormTest.php | 123 --- tests/0005_Unit/RadiosFieldTest.php | 75 -- tests/0005_Unit/SelectFieldTest.php | 195 ---- tests/0005_Unit/TargetTest.php | 91 -- tests/0005_Unit/TargetTicketTest.php | 107 --- tests/0010_Integration/CloneTest.php | 137 --- .../FormAnswerValidationTest.php | 178 ---- tests/0010_Integration/Form_AnswerTest.php | 84 -- tests/0010_Integration/Form_ValidatorTest.php | 111 --- tests/0010_Integration/IssueTest.php | 440 --------- .../Item_TargetTicketTest.php | 130 --- tests/0010_Integration/SectionTest.php | 95 -- tests/0010_Integration/TargetChangeTest.php | 124 --- tests/0010_Integration/TargetTicketTest.php | 124 --- tests/9000_Uninstall/PluginUninstallTest.php | 76 -- tests/bootstrap.php | 77 +- tests/functional/.empty | 0 tests/functional/testCentralHasTab.js | 46 + tests/functionalTest.dist.js | 16 + tests/functionalTest.json | 4 + tests/inc/CommonDBTestCase.php | 206 ----- tests/inc/CommonTestCase.php | 74 -- tests/inc/GLPIlogs.php | 68 -- tests/inc/PluginDB.php | 157 ---- tests/inc/SuperAdminTestCase.php | 48 - tests/logs/.empty | 0 tests/src/CommonDBTestCase.php | 248 ++++++ tests/src/CommonTestCase.php | 157 ++++ tests/suite-install/Config.php | 121 +++ .../PluginFormcreatorForm.php | 477 ++++++++++ .../PluginFormcreatorForm_Answer.php | 169 ++++ .../PluginFormcreatorForm_Validator.php | 65 ++ .../PluginFormcreatorQuestion.php | 102 +++ .../PluginFormcreatorSection.php | 135 +++ .../PluginFormcreatorTargetChange.php | 68 ++ .../PluginFormcreatorTargetTicket.php | 258 ++++++ tests/suite-uninstall/Config.php | 88 ++ .../PluginFormcreatorActorField.php | 153 ++++ .../PluginFormcreatorCheckboxesField.php | 245 +++++ tests/suite-unit/PluginFormcreatorCommon.php | 12 + tests/suite-unit/PluginFormcreatorFields.php | 263 ++++++ .../PluginFormcreatorFloatField.php} | 15 +- tests/suite-unit/PluginFormcreatorForm.php | 133 +++ .../PluginFormcreatorIntegerField.php} | 68 +- .../PluginFormcreatorMultiSelectField.php} | 152 ++-- .../suite-unit/PluginFormcreatorQuestion.php | 147 +++ .../PluginFormcreatorQuestion_Condition.php} | 132 +-- .../PluginFormcreatorRadiosField.php | 46 + tests/suite-unit/PluginFormcreatorSection.php | 76 ++ .../PluginFormcreatorSelectField.php | 125 +++ tests/suite-unit/PluginFormcreatorTarget.php | 62 ++ .../PluginFormcreatorTargetTicket.php | 84 ++ .../QuestionTest.php | 0 .../TextFieldTest.php | 0 tests/testall.sh | 32 + tests/testinstall.sh | 17 + tests/testone.sh | 19 + 70 files changed, 4225 insertions(+), 3792 deletions(-) delete mode 100644 tests/0000_Install/PluginInstallTest.php delete mode 100644 tests/0000_Install/SaveInstallTest.php delete mode 100644 tests/0005_Unit/ActorFieldTest.php delete mode 100644 tests/0005_Unit/CheckboxesFieldTest.php delete mode 100644 tests/0005_Unit/CommonTest.php delete mode 100644 tests/0005_Unit/FormTest.php delete mode 100644 tests/0005_Unit/RadiosFieldTest.php delete mode 100644 tests/0005_Unit/SelectFieldTest.php delete mode 100644 tests/0005_Unit/TargetTest.php delete mode 100644 tests/0005_Unit/TargetTicketTest.php delete mode 100644 tests/0010_Integration/CloneTest.php delete mode 100644 tests/0010_Integration/FormAnswerValidationTest.php delete mode 100644 tests/0010_Integration/Form_AnswerTest.php delete mode 100644 tests/0010_Integration/Form_ValidatorTest.php delete mode 100644 tests/0010_Integration/IssueTest.php delete mode 100644 tests/0010_Integration/Item_TargetTicketTest.php delete mode 100644 tests/0010_Integration/SectionTest.php delete mode 100644 tests/0010_Integration/TargetChangeTest.php delete mode 100644 tests/0010_Integration/TargetTicketTest.php delete mode 100644 tests/9000_Uninstall/PluginUninstallTest.php create mode 100644 tests/functional/.empty create mode 100644 tests/functional/testCentralHasTab.js create mode 100644 tests/functionalTest.dist.js create mode 100644 tests/functionalTest.json delete mode 100644 tests/inc/CommonDBTestCase.php delete mode 100644 tests/inc/CommonTestCase.php delete mode 100644 tests/inc/GLPIlogs.php delete mode 100644 tests/inc/PluginDB.php delete mode 100644 tests/inc/SuperAdminTestCase.php create mode 100644 tests/logs/.empty create mode 100644 tests/src/CommonDBTestCase.php create mode 100644 tests/src/CommonTestCase.php create mode 100644 tests/suite-install/Config.php create mode 100644 tests/suite-integration/PluginFormcreatorForm.php create mode 100644 tests/suite-integration/PluginFormcreatorForm_Answer.php create mode 100644 tests/suite-integration/PluginFormcreatorForm_Validator.php create mode 100644 tests/suite-integration/PluginFormcreatorQuestion.php create mode 100644 tests/suite-integration/PluginFormcreatorSection.php create mode 100644 tests/suite-integration/PluginFormcreatorTargetChange.php create mode 100644 tests/suite-integration/PluginFormcreatorTargetTicket.php create mode 100644 tests/suite-uninstall/Config.php create mode 100644 tests/suite-unit/PluginFormcreatorActorField.php create mode 100644 tests/suite-unit/PluginFormcreatorCheckboxesField.php create mode 100644 tests/suite-unit/PluginFormcreatorCommon.php create mode 100644 tests/suite-unit/PluginFormcreatorFields.php rename tests/{0005_Unit/FloatFieldTest.php => suite-unit/PluginFormcreatorFloatField.php} (92%) create mode 100644 tests/suite-unit/PluginFormcreatorForm.php rename tests/{0005_Unit/IntegerFieldTest.php => suite-unit/PluginFormcreatorIntegerField.php} (87%) rename tests/{0005_Unit/MultiselectFieldTest.php => suite-unit/PluginFormcreatorMultiSelectField.php} (63%) create mode 100644 tests/suite-unit/PluginFormcreatorQuestion.php rename tests/{0005_Unit/Question_ConditionTest.php => suite-unit/PluginFormcreatorQuestion_Condition.php} (91%) create mode 100644 tests/suite-unit/PluginFormcreatorRadiosField.php create mode 100644 tests/suite-unit/PluginFormcreatorSection.php create mode 100644 tests/suite-unit/PluginFormcreatorSelectField.php create mode 100644 tests/suite-unit/PluginFormcreatorTarget.php create mode 100644 tests/suite-unit/PluginFormcreatorTargetTicket.php rename tests/{0005_Unit => suite-unit}/QuestionTest.php (100%) rename tests/{0005_Unit => suite-unit}/TextFieldTest.php (100%) create mode 100755 tests/testall.sh create mode 100755 tests/testinstall.sh create mode 100755 tests/testone.sh diff --git a/.travis.yml b/.travis.yml index e05d793a8..84be8a82f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,8 +34,11 @@ before_script: - composer install script: - - vendor/bin/phpunit $PHPUNIT_ARGS - - if [ ${TRAVIS_PHP_VERSION:0:3} == "$CS" ] && [ "$GLPI_BRANCH" = "$AFTER_SUCCESS_BRANCH" ]; then vendor/bin/robo --no-interaction code:cs; fi + - vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-install -ncc + - vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-unit --ncc + - vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-integration --ncc + - vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-uninstall -ncc + - if [[ ${TRAVIS_PHP_VERSION:0:3} == "$CS" ]] ; then vendor/bin/robo --no-interaction code:cs; fi cache: directories: diff --git a/composer.json b/composer.json index 3c3fe6692..a640c00be 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,14 @@ "require-dev": { "ext-bz2": "*", "pear/archive_tar": "^1.4", - "phpunit/phpunit": "^4.8 || ^5.7 || ^6.0", + "atoum/atoum": "^3.3", + "atoum/stubs": "^2.5" "glpi-project/tools": "^0.1.0", "glpi-project/coding-standard": "0.5.0" + }, + "autoload-dev": { + "psr-4": { + "GlpiPlugin\\Formcreator\\Tests\\": "tests/src/" + } } } diff --git a/composer.lock b/composer.lock index 4f974f3fb..42418b790 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,11 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], +<<<<<<< HEAD "content-hash": "c61213958ef3f4c2b3bdbc0aa90a9d9e", +======= + "content-hash": "120b50e50e3e04e6aae2ad36fd20dd40", +>>>>>>> 0612117... test: migrate to atoum "packages": [ { "name": "docopt/docopt", @@ -54,6 +58,136 @@ } ], "packages-dev": [ + { + "name": "atoum/atoum", + "version": "3.3.0", + "source": { + "type": "git", + "url": "https://github.com/atoum/atoum.git", + "reference": "c5279d0ecd4e2d53af6b38815db2cafee8fc46b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/atoum/atoum/zipball/c5279d0ecd4e2d53af6b38815db2cafee8fc46b6", + "reference": "c5279d0ecd4e2d53af6b38815db2cafee8fc46b6", + "shasum": "" + }, + "require": { + "ext-hash": "*", + "ext-json": "*", + "ext-tokenizer": "*", + "ext-xml": "*", + "php": "^5.6.0 || ^7.0.0 <7.4.0" + }, + "replace": { + "mageekguy/atoum": "*" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2" + }, + "suggest": { + "atoum/stubs": "Provides IDE support (like autocompletion) for atoum", + "ext-mbstring": "Provides support for UTF-8 strings", + "ext-xdebug": "Provides code coverage report (>= 2.3)" + }, + "bin": [ + "bin/atoum" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "autoload": { + "classmap": [ + "classes/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Frédéric Hardy", + "email": "frederic.hardy@atoum.org", + "homepage": "http://blog.mageekbox.net" + }, + { + "name": "François Dussert", + "email": "francois.dussert@atoum.org" + }, + { + "name": "Gérald Croes", + "email": "gerald.croes@atoum.org" + }, + { + "name": "Julien Bianchi", + "email": "julien.bianchi@atoum.org" + }, + { + "name": "Ludovic Fleury", + "email": "ludovic.fleury@atoum.org" + } + ], + "description": "Simple modern and intuitive unit testing framework for PHP 5.3+", + "homepage": "http://www.atoum.org", + "keywords": [ + "TDD", + "atoum", + "test", + "unit testing" + ], + "time": "2018-03-15T22:46:39+00:00" + }, + { + "name": "atoum/stubs", + "version": "2.6.0", + "source": { + "type": "git", + "url": "https://github.com/atoum/stubs.git", + "reference": "df8b73b0358de7283ecba91d8f4a9683f583993d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/atoum/stubs/zipball/df8b73b0358de7283ecba91d8f4a9683f583993d", + "reference": "df8b73b0358de7283ecba91d8f4a9683f583993d", + "shasum": "" + }, + "suggest": { + "atoum/atoum": "Include atoum in your projet dependencies" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Julien Bianchi", + "email": "julien.bianchi@atoum.org" + }, + { + "name": "Ludovic Fleury", + "email": "ludovic.fleury@atoum.org" + } + ], + "description": "Stubs for atoum, the simple modern and intuitive unit testing framework for PHP 5.3+", + "homepage": "http://www.atoum.org", + "keywords": [ + "TDD", + "atoum", + "test", + "unit testing" + ], + "time": "2018-01-29T22:41:37+00:00" + }, { "name": "consolidation/annotated-command", "version": "2.8.4", @@ -108,6 +242,7 @@ }, { "name": "consolidation/config", +<<<<<<< HEAD "version": "1.1.0", "source": { "type": "git", @@ -118,6 +253,18 @@ "type": "zip", "url": "https://api.github.com/repos/consolidation/config/zipball/c9fc25e9088a708637e18a256321addc0670e578", "reference": "c9fc25e9088a708637e18a256321addc0670e578", +======= + "version": "1.0.11", + "source": { + "type": "git", + "url": "https://github.com/consolidation/config.git", + "reference": "ede41d946078e97e7a9513aadc3352f1c26817af" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/consolidation/config/zipball/ede41d946078e97e7a9513aadc3352f1c26817af", + "reference": "ede41d946078e97e7a9513aadc3352f1c26817af", +>>>>>>> 0612117... test: migrate to atoum "shasum": "" }, "require": { @@ -127,7 +274,11 @@ }, "require-dev": { "g1a/composer-test-scenarios": "^1", +<<<<<<< HEAD "phpunit/phpunit": "^5", +======= + "phpunit/phpunit": "^4", +>>>>>>> 0612117... test: migrate to atoum "satooshi/php-coveralls": "^1.0", "squizlabs/php_codesniffer": "2.*", "symfony/console": "^2.5|^3|^4", @@ -158,7 +309,11 @@ } ], "description": "Provide configuration services for a commandline tool.", +<<<<<<< HEAD "time": "2018-08-07T22:57:00+00:00" +======= + "time": "2018-05-27T01:17:02+00:00" +>>>>>>> 0612117... test: migrate to atoum }, { "name": "consolidation/log", @@ -270,12 +425,21 @@ "source": { "type": "git", "url": "https://github.com/consolidation/Robo.git", +<<<<<<< HEAD "reference": "967b88fad6f554e990407047f44a794ce9c773af" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/consolidation/Robo/zipball/967b88fad6f554e990407047f44a794ce9c773af", "reference": "967b88fad6f554e990407047f44a794ce9c773af", +======= + "reference": "48e7e55b2b739cb4e0a1246c3ec22e566dfc06ca" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/consolidation/Robo/zipball/48e7e55b2b739cb4e0a1246c3ec22e566dfc06ca", + "reference": "48e7e55b2b739cb4e0a1246c3ec22e566dfc06ca", +>>>>>>> 0612117... test: migrate to atoum "shasum": "" }, "require": { @@ -283,7 +447,10 @@ "consolidation/config": "^1.0.10", "consolidation/log": "~1", "consolidation/output-formatters": "^3.1.13", +<<<<<<< HEAD "g1a/composer-test-scenarios": "^2", +======= +>>>>>>> 0612117... test: migrate to atoum "grasmash/yaml-expander": "^1.3", "league/container": "^2.2", "php": ">=5.5.0", @@ -300,6 +467,10 @@ "codeception/aspect-mock": "^1|^2.1.1", "codeception/base": "^2.3.7", "codeception/verify": "^0.3.2", +<<<<<<< HEAD +======= + "g1a/composer-test-scenarios": "^2", +>>>>>>> 0612117... test: migrate to atoum "goaop/framework": "~2.1.2", "goaop/parser-reflection": "^1.1.0", "natxet/cssmin": "3.0.4", @@ -342,7 +513,11 @@ } ], "description": "Modern task runner", +<<<<<<< HEAD "time": "2018-08-12 00:17:46" +======= + "time": "2018-06-28 14:57:16" +>>>>>>> 0612117... test: migrate to atoum }, { "name": "container-interop/container-interop", @@ -378,6 +553,7 @@ { "name": "dflydev/dot-access-data", "version": "v1.1.0", +<<<<<<< HEAD "source": { "type": "git", "url": "https://github.com/dflydev/dflydev-dot-access-data.git", @@ -437,36 +613,31 @@ { "name": "doctrine/instantiator", "version": "1.0.5", +======= +>>>>>>> 0612117... test: migrate to atoum "source": { "type": "git", - "url": "https://github.com/doctrine/instantiator.git", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + "url": "https://github.com/dflydev/dflydev-dot-access-data.git", + "reference": "3fbd874921ab2c041e899d044585a2ab9795df8a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "url": "https://api.github.com/repos/dflydev/dflydev-dot-access-data/zipball/3fbd874921ab2c041e899d044585a2ab9795df8a", + "reference": "3fbd874921ab2c041e899d044585a2ab9795df8a", "shasum": "" }, "require": { - "php": ">=5.3,<8.0-DEV" - }, - "require-dev": { - "athletic/athletic": "~0.1.8", - "ext-pdo": "*", - "ext-phar": "*", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "~2.0" + "php": ">=5.3.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.0-dev" } }, "autoload": { - "psr-4": { - "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + "psr-0": { + "Dflydev\\DotAccessData": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -475,18 +646,30 @@ ], "authors": [ { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com", - "homepage": "http://ocramius.github.com/" + "name": "Dragonfly Development Inc.", + "email": "info@dflydev.com", + "homepage": "http://dflydev.com" + }, + { + "name": "Beau Simensen", + "email": "beau@dflydev.com", + "homepage": "http://beausimensen.com" + }, + { + "name": "Carlos Frutos", + "email": "carlos@kiwing.it", + "homepage": "https://github.com/cfrutos" } ], - "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://github.com/doctrine/instantiator", + "description": "Given a deep data structure, access data by dot notation.", + "homepage": "https://github.com/dflydev/dflydev-dot-access-data", "keywords": [ - "constructor", - "instantiate" + "access", + "data", + "dot", + "notation" ], - "time": "2015-06-14T21:17:01+00:00" + "time": "2017-01-20T21:14:22+00:00" }, { "name": "g1a/composer-test-scenarios", @@ -607,6 +790,7 @@ "tools" ], "time": "2018-01-02T10:48:41+00:00" +<<<<<<< HEAD }, { "name": "grasmash/expander", @@ -715,45 +899,39 @@ "type": "zip", "url": "https://api.github.com/repos/thephpleague/container/zipball/43f35abd03a12977a60ffd7095efd6a7808488c0", "reference": "43f35abd03a12977a60ffd7095efd6a7808488c0", +======= + }, + { + "name": "grasmash/expander", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/grasmash/expander.git", + "reference": "95d6037344a4be1dd5f8e0b0b2571a28c397578f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/grasmash/expander/zipball/95d6037344a4be1dd5f8e0b0b2571a28c397578f", + "reference": "95d6037344a4be1dd5f8e0b0b2571a28c397578f", +>>>>>>> 0612117... test: migrate to atoum "shasum": "" }, "require": { - "container-interop/container-interop": "^1.2", - "php": "^5.4.0 || ^7.0" - }, - "provide": { - "container-interop/container-interop-implementation": "^1.2", - "psr/container-implementation": "^1.0" - }, - "replace": { - "orno/di": "~2.0" + "dflydev/dot-access-data": "^1.1.0", + "php": ">=5.4" }, "require-dev": { - "phpunit/phpunit": "4.*" + "greg-1-anderson/composer-test-scenarios": "^1", + "phpunit/phpunit": "^4|^5.5.4", + "satooshi/php-coveralls": "^1.0.2|dev-master", + "squizlabs/php_codesniffer": "^2.7" }, "type": "library", "extra": { "branch-alias": { - "dev-2.x": "2.x-dev", - "dev-1.x": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "League\\Container\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Phil Bennett", - "email": "philipobenito@gmail.com", - "homepage": "http://www.philipobenito.com", - "role": "Developer" + "dev-master": "1.x-dev" } +<<<<<<< HEAD ], "description": "A fast and intuitive dependency injection container.", "homepage": "https://github.com/thephpleague/container", @@ -789,10 +967,12 @@ "doctrine/collections": "^1.0", "doctrine/common": "^2.6", "phpunit/phpunit": "^4.1" +======= +>>>>>>> 0612117... test: migrate to atoum }, - "type": "library", "autoload": { "psr-4": { +<<<<<<< HEAD "DeepCopy\\": "src/DeepCopy/" }, "files": [ @@ -2000,169 +2180,157 @@ "classmap": [ "src/" ] +======= + "Grasmash\\Expander\\": "src/" + } +>>>>>>> 0612117... test: migrate to atoum }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" + "MIT" ], "authors": [ { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" + "name": "Matthew Grasmick" } ], - "description": "Provides functionality to handle HHVM/PHP environments", - "homepage": "http://www.github.com/sebastianbergmann/environment", - "keywords": [ - "Xdebug", - "environment", - "hhvm" - ], - "time": "2016-11-26T07:53:53+00:00" + "description": "Expands internal property references in PHP arrays file.", + "time": "2017-12-21T22:14:55+00:00" }, { - "name": "sebastian/exporter", - "version": "2.0.0", + "name": "grasmash/yaml-expander", + "version": "1.4.0", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4" + "url": "https://github.com/grasmash/yaml-expander.git", + "reference": "3f0f6001ae707a24f4d9733958d77d92bf9693b1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", - "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "url": "https://api.github.com/repos/grasmash/yaml-expander/zipball/3f0f6001ae707a24f4d9733958d77d92bf9693b1", + "reference": "3f0f6001ae707a24f4d9733958d77d92bf9693b1", "shasum": "" }, "require": { - "php": ">=5.3.3", - "sebastian/recursion-context": "~2.0" + "dflydev/dot-access-data": "^1.1.0", + "php": ">=5.4", + "symfony/yaml": "^2.8.11|^3|^4" }, "require-dev": { - "ext-mbstring": "*", - "phpunit/phpunit": "~4.4" + "greg-1-anderson/composer-test-scenarios": "^1", + "phpunit/phpunit": "^4.8|^5.5.4", + "satooshi/php-coveralls": "^1.0.2|dev-master", + "squizlabs/php_codesniffer": "^2.7" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "1.x-dev" } }, "autoload": { - "classmap": [ - "src/" - ] + "psr-4": { + "Grasmash\\YamlExpander\\": "src/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" + "MIT" ], "authors": [ { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" + "name": "Matthew Grasmick" } ], - "description": "Provides the functionality to export PHP variables for visualization", - "homepage": "http://www.github.com/sebastianbergmann/exporter", - "keywords": [ - "export", - "exporter" - ], - "time": "2016-11-19T08:54:04+00:00" + "description": "Expands internal property references in a yaml file.", + "time": "2017-12-16T16:06:03+00:00" }, { - "name": "sebastian/global-state", - "version": "1.1.1", + "name": "league/container", + "version": "2.4.1", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" + "url": "https://github.com/thephpleague/container.git", + "reference": "43f35abd03a12977a60ffd7095efd6a7808488c0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", - "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", + "url": "https://api.github.com/repos/thephpleague/container/zipball/43f35abd03a12977a60ffd7095efd6a7808488c0", + "reference": "43f35abd03a12977a60ffd7095efd6a7808488c0", "shasum": "" }, "require": { - "php": ">=5.3.3" + "container-interop/container-interop": "^1.2", + "php": "^5.4.0 || ^7.0" }, - "require-dev": { - "phpunit/phpunit": "~4.2" + "provide": { + "container-interop/container-interop-implementation": "^1.2", + "psr/container-implementation": "^1.0" }, - "suggest": { - "ext-uopz": "*" + "replace": { + "orno/di": "~2.0" + }, + "require-dev": { + "phpunit/phpunit": "4.*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-2.x": "2.x-dev", + "dev-1.x": "1.x-dev" } }, "autoload": { - "classmap": [ - "src/" - ] + "psr-4": { + "League\\Container\\": "src" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" + "MIT" ], "authors": [ { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" + "name": "Phil Bennett", + "email": "philipobenito@gmail.com", + "homepage": "http://www.philipobenito.com", + "role": "Developer" } ], - "description": "Snapshotting of global state", - "homepage": "http://www.github.com/sebastianbergmann/global-state", + "description": "A fast and intuitive dependency injection container.", + "homepage": "https://github.com/thephpleague/container", "keywords": [ - "global state" + "container", + "dependency", + "di", + "injection", + "league", + "provider", + "service" ], - "time": "2015-10-12T03:26:01+00:00" + "time": "2017-05-10T09:20:27+00:00" }, { - "name": "sebastian/object-enumerator", - "version": "2.0.1", + "name": "natxet/CssMin", + "version": "v3.0.6", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7" + "url": "https://github.com/natxet/CssMin.git", + "reference": "d5d9f4c3e5cedb1ae96a95a21731f8790e38f1dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/1311872ac850040a79c3c058bea3e22d0f09cbb7", - "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7", + "url": "https://api.github.com/repos/natxet/CssMin/zipball/d5d9f4c3e5cedb1ae96a95a21731f8790e38f1dd", + "reference": "d5d9f4c3e5cedb1ae96a95a21731f8790e38f1dd", "shasum": "" }, "require": { - "php": ">=5.6", - "sebastian/recursion-context": "~2.0" - }, - "require-dev": { - "phpunit/phpunit": "~5" + "php": ">=5.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -2172,87 +2340,81 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" + "MIT" ], "authors": [ { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" + "name": "Joe Scylla", + "email": "joe.scylla@gmail.com", + "homepage": "https://profiles.google.com/joe.scylla" } ], - "description": "Traverses array structures and object graphs to enumerate all referenced objects", - "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2017-02-18T15:18:39+00:00" + "description": "Minifying CSS", + "homepage": "http://code.google.com/p/cssmin/", + "keywords": [ + "css", + "minify" + ], + "time": "2018-01-09T11:15:01+00:00" }, { - "name": "sebastian/recursion-context", - "version": "2.0.0", + "name": "patchwork/jsqueeze", + "version": "v1.0.7", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a" + "url": "https://github.com/tchwork/jsqueeze.git", + "reference": "f90a933213534b93e4ff3c2c3026ff7458f7721b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/2c3ba150cbec723aa057506e73a8d33bdb286c9a", - "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "url": "https://api.github.com/repos/tchwork/jsqueeze/zipball/f90a933213534b93e4ff3c2c3026ff7458f7721b", + "reference": "f90a933213534b93e4ff3c2c3026ff7458f7721b", "shasum": "" }, "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" + "php": ">=5.1.4" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, "autoload": { - "classmap": [ - "src/" - ] + "psr-0": { + "JSqueeze": "class/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" + "(Apache-2.0 or GPL-2.0)" ], "authors": [ { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" + "name": "Nicolas Grekas", + "email": "p@tchwork.com" } ], - "description": "Provides functionality to recursively process PHP variables", - "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2016-11-19T07:33:16+00:00" + "description": "Efficient JavaScript minification in PHP", + "homepage": "https://github.com/tchwork/jsqueeze", + "keywords": [ + "compression", + "javascript", + "minification" + ], + "time": "2015-03-25T10:11:08+00:00" }, { - "name": "sebastian/resource-operations", + "name": "psr/container", "version": "1.0.0", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + "url": "https://github.com/php-fig/container.git", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", - "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", "shasum": "" }, "require": { - "php": ">=5.6.0" + "php": ">=5.3.0" }, "type": "library", "extra": { @@ -2261,66 +2423,77 @@ } }, "autoload": { - "classmap": [ - "src/" - ] + "psr-4": { + "Psr\\Container\\": "src/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" + "MIT" ], "authors": [ { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" } ], - "description": "Provides a list of PHP built-in functions that operate on resources", - "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2015-07-28T20:34:47+00:00" + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "time": "2017-02-14T16:28:37+00:00" }, { - "name": "sebastian/version", - "version": "2.0.1", + "name": "psr/log", + "version": "1.0.2", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/version.git", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", "shasum": "" }, "require": { - "php": ">=5.6" + "php": ">=5.3.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "1.0.x-dev" } }, "autoload": { - "classmap": [ - "src/" - ] + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" + "MIT" ], "authors": [ { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" } ], - "description": "Library that helps with managing the version number of Git-hosted PHP projects", - "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-10-03T07:35:21+00:00" + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10T12:19:37+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -2402,6 +2575,7 @@ }, { "name": "symfony/console", +<<<<<<< HEAD "version": "v3.4.14", "source": { "type": "git", @@ -2417,6 +2591,22 @@ "require": { "php": "^5.5.9|>=7.0.8", "symfony/debug": "~2.8|~3.0|~4.0", +======= + "version": "v4.1.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "70591cda56b4b47c55776ac78e157c4bb6c8b43f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/70591cda56b4b47c55776ac78e157c4bb6c8b43f", + "reference": "70591cda56b4b47c55776ac78e157c4bb6c8b43f", + "shasum": "" + }, + "require": { + "php": "^7.1.3", +>>>>>>> 0612117... test: migrate to atoum "symfony/polyfill-mbstring": "~1.0" }, "conflict": { @@ -2425,11 +2615,19 @@ }, "require-dev": { "psr/log": "~1.0", +<<<<<<< HEAD "symfony/config": "~3.3|~4.0", "symfony/dependency-injection": "~3.4|~4.0", "symfony/event-dispatcher": "~2.8|~3.0|~4.0", "symfony/lock": "~3.4|~4.0", "symfony/process": "~3.3|~4.0" +======= + "symfony/config": "~3.4|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/event-dispatcher": "~3.4|~4.0", + "symfony/lock": "~3.4|~4.0", + "symfony/process": "~3.4|~4.0" +>>>>>>> 0612117... test: migrate to atoum }, "suggest": { "psr/log-implementation": "For using the console logger", @@ -2440,7 +2638,11 @@ "type": "library", "extra": { "branch-alias": { +<<<<<<< HEAD "dev-master": "3.4-dev" +======= + "dev-master": "4.1-dev" +>>>>>>> 0612117... test: migrate to atoum } }, "autoload": { @@ -2467,6 +2669,7 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", +<<<<<<< HEAD "time": "2018-07-26T11:19:56+00:00" }, { @@ -2486,22 +2689,58 @@ "require": { "php": "^5.5.9|>=7.0.8", "psr/log": "~1.0" +======= + "time": "2018-05-31T10:17:53+00:00" + }, + { + "name": "symfony/event-dispatcher", + "version": "v4.1.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "2391ed210a239868e7256eb6921b1bd83f3087b5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/2391ed210a239868e7256eb6921b1bd83f3087b5", + "reference": "2391ed210a239868e7256eb6921b1bd83f3087b5", + "shasum": "" + }, + "require": { + "php": "^7.1.3" +>>>>>>> 0612117... test: migrate to atoum }, "conflict": { - "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2" + "symfony/dependency-injection": "<3.4" }, "require-dev": { +<<<<<<< HEAD "symfony/http-kernel": "~2.8|~3.0|~4.0" +======= + "psr/log": "~1.0", + "symfony/config": "~3.4|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/expression-language": "~3.4|~4.0", + "symfony/stopwatch": "~3.4|~4.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" +>>>>>>> 0612117... test: migrate to atoum }, "type": "library", "extra": { "branch-alias": { +<<<<<<< HEAD "dev-master": "3.4-dev" +======= + "dev-master": "4.1-dev" +>>>>>>> 0612117... test: migrate to atoum } }, "autoload": { "psr-4": { - "Symfony\\Component\\Debug\\": "" + "Symfony\\Component\\EventDispatcher\\": "" }, "exclude-from-classmap": [ "/Tests/" @@ -2521,8 +2760,9 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony Debug Component", + "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", +<<<<<<< HEAD "time": "2018-07-26T11:19:56+00:00" }, { @@ -2555,16 +2795,41 @@ "suggest": { "symfony/dependency-injection": "", "symfony/http-kernel": "" +======= + "time": "2018-04-06T07:35:57+00:00" + }, + { + "name": "symfony/filesystem", + "version": "v4.1.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "562bf7005b55fd80d26b582d28e3e10f2dd5ae9c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/562bf7005b55fd80d26b582d28e3e10f2dd5ae9c", + "reference": "562bf7005b55fd80d26b582d28e3e10f2dd5ae9c", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/polyfill-ctype": "~1.8" +>>>>>>> 0612117... test: migrate to atoum }, "type": "library", "extra": { "branch-alias": { +<<<<<<< HEAD "dev-master": "3.4-dev" +======= + "dev-master": "4.1-dev" +>>>>>>> 0612117... test: migrate to atoum } }, "autoload": { "psr-4": { - "Symfony\\Component\\EventDispatcher\\": "" + "Symfony\\Component\\Filesystem\\": "" }, "exclude-from-classmap": [ "/Tests/" @@ -2584,8 +2849,9 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony EventDispatcher Component", + "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", +<<<<<<< HEAD "time": "2018-07-26T09:06:28+00:00" }, { @@ -2605,16 +2871,40 @@ "require": { "php": "^5.5.9|>=7.0.8", "symfony/polyfill-ctype": "~1.8" +======= + "time": "2018-05-30T07:26:09+00:00" + }, + { + "name": "symfony/finder", + "version": "v4.1.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/finder.git", + "reference": "84714b8417d19e4ba02ea78a41a975b3efaafddb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/finder/zipball/84714b8417d19e4ba02ea78a41a975b3efaafddb", + "reference": "84714b8417d19e4ba02ea78a41a975b3efaafddb", + "shasum": "" + }, + "require": { + "php": "^7.1.3" +>>>>>>> 0612117... test: migrate to atoum }, "type": "library", "extra": { "branch-alias": { +<<<<<<< HEAD "dev-master": "3.4-dev" +======= + "dev-master": "4.1-dev" +>>>>>>> 0612117... test: migrate to atoum } }, "autoload": { "psr-4": { - "Symfony\\Component\\Filesystem\\": "" + "Symfony\\Component\\Finder\\": "" }, "exclude-from-classmap": [ "/Tests/" @@ -2634,8 +2924,9 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony Filesystem Component", + "description": "Symfony Finder Component", "homepage": "https://symfony.com", +<<<<<<< HEAD "time": "2018-07-26T11:19:56+00:00" }, { @@ -2654,19 +2945,43 @@ }, "require": { "php": "^5.5.9|>=7.0.8" +======= + "time": "2018-06-19T21:38:16+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.8.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" +>>>>>>> 0612117... test: migrate to atoum }, "type": "library", "extra": { "branch-alias": { +<<<<<<< HEAD "dev-master": "3.4-dev" +======= + "dev-master": "1.8-dev" +>>>>>>> 0612117... test: migrate to atoum } }, "autoload": { "psr-4": { - "Symfony\\Component\\Finder\\": "" + "Symfony\\Polyfill\\Ctype\\": "" }, - "exclude-from-classmap": [ - "/Tests/" + "files": [ + "bootstrap.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -2674,17 +2989,18 @@ "MIT" ], "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" + }, + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" } ], - "description": "Symfony Finder Component", + "description": "Symfony polyfill for ctype functions", "homepage": "https://symfony.com", +<<<<<<< HEAD "time": "2018-07-26T11:19:56+00:00" }, { @@ -2737,12 +3053,15 @@ ], "description": "Symfony polyfill for ctype functions", "homepage": "https://symfony.com", +======= +>>>>>>> 0612117... test: migrate to atoum "keywords": [ "compatibility", "ctype", "polyfill", "portable" ], +<<<<<<< HEAD "time": "2018-08-06T14:22:27+00:00" }, { @@ -2757,6 +3076,22 @@ "type": "zip", "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8", "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8", +======= + "time": "2018-04-30T19:57:29+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.8.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "3296adf6a6454a050679cde90f95350ad604b171" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171", + "reference": "3296adf6a6454a050679cde90f95350ad604b171", +>>>>>>> 0612117... test: migrate to atoum "shasum": "" }, "require": { @@ -2768,7 +3103,11 @@ "type": "library", "extra": { "branch-alias": { +<<<<<<< HEAD "dev-master": "1.9-dev" +======= + "dev-master": "1.8-dev" +>>>>>>> 0612117... test: migrate to atoum } }, "autoload": { @@ -2802,6 +3141,7 @@ "portable", "shim" ], +<<<<<<< HEAD "time": "2018-08-06T14:22:27+00:00" }, { @@ -2820,11 +3160,35 @@ }, "require": { "php": "^5.5.9|>=7.0.8" +======= + "time": "2018-04-26T10:06:28+00:00" + }, + { + "name": "symfony/process", + "version": "v4.1.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "1d1677391ecf00d1c5b9482d6050c0c27aa3ac3a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/1d1677391ecf00d1c5b9482d6050c0c27aa3ac3a", + "reference": "1d1677391ecf00d1c5b9482d6050c0c27aa3ac3a", + "shasum": "" + }, + "require": { + "php": "^7.1.3" +>>>>>>> 0612117... test: migrate to atoum }, "type": "library", "extra": { "branch-alias": { +<<<<<<< HEAD "dev-master": "3.4-dev" +======= + "dev-master": "4.1-dev" +>>>>>>> 0612117... test: migrate to atoum } }, "autoload": { @@ -2851,6 +3215,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", +<<<<<<< HEAD "time": "2018-07-26T11:19:56+00:00" }, { @@ -2869,6 +3234,26 @@ }, "require": { "php": "^5.5.9|>=7.0.8", +======= + "time": "2018-05-31T10:17:53+00:00" + }, + { + "name": "symfony/yaml", + "version": "v4.1.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "80e4bfa9685fc4a09acc4a857ec16974a9cd944e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/80e4bfa9685fc4a09acc4a857ec16974a9cd944e", + "reference": "80e4bfa9685fc4a09acc4a857ec16974a9cd944e", + "shasum": "" + }, + "require": { + "php": "^7.1.3", +>>>>>>> 0612117... test: migrate to atoum "symfony/polyfill-ctype": "~1.8" }, "conflict": { @@ -2883,7 +3268,11 @@ "type": "library", "extra": { "branch-alias": { +<<<<<<< HEAD "dev-master": "3.4-dev" +======= + "dev-master": "4.1-dev" +>>>>>>> 0612117... test: migrate to atoum } }, "autoload": { @@ -2910,6 +3299,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", +<<<<<<< HEAD "time": "2018-07-26T11:19:56+00:00" }, { @@ -2961,6 +3351,9 @@ "validate" ], "time": "2018-01-29T19:49:41+00:00" +======= + "time": "2018-05-30T07:26:09+00:00" +>>>>>>> 0612117... test: migrate to atoum } ], "aliases": [], diff --git a/inc/form.class.php b/inc/form.class.php index 02cd18e64..dd9bceb6a 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1557,9 +1557,9 @@ public function duplicate() { } /** - * Transfer a form to another entity. Execute transfer action for massive action. + * Transfer a form to another entity. Execute transfert action for massive action. * - * @return Boolean true if success, false otherwise. + * @return Boolean true if success, false otherwize. */ public function transfer($entity) { global $DB; @@ -1599,7 +1599,7 @@ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBT switch ($ma->getAction()) { case 'Duplicate' : foreach ($ids as $id) { - if ($item->getFromDB($id) && $item->duplicate()) { + if ($item->getFromDB($id) && $item->duplicate() !== false) { Session::addMessageAfterRedirect(sprintf(__('Form duplicated: %s', 'formcreator'), $item->getName())); $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index da47c9863..405da2481 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -619,7 +619,6 @@ public function pre_deleteItem() { return true; } - /** * Create or update answers of a gorm * @param array $data answers @@ -872,6 +871,13 @@ public function saveAnswers($data) { } Session::addMessageAfterRedirect(__('The form has been successfully saved!', 'formcreator'), true, INFO); + + // TODO: This reveals a real refactor need in this method ! + if ($is_newFormAnswer) { + return $id; + } else { + return $formAnswerId; + } } /** diff --git a/inc/question.class.php b/inc/question.class.php index 013f4b1f1..a224a6504 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -84,7 +84,7 @@ function addMessageOnPurgeAction() {} * * @return String Name to be displayed */ - public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { + public function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { switch ($item->getType()) { case PluginFormcreatorForm::class: $number = 0; @@ -116,7 +116,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { * * @return null Nothing, just display the list */ - public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { + public static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { global $CFG_GLPI; // TODO: move the content of this method into a new showForForm() method @@ -1309,7 +1309,7 @@ function change_LDAP(ldap) { /** * Duplicate a question * - * @return boolean + * @return integer|boolean ID of the new question, false otherwise */ public function duplicate() { $oldQuestionId = $this->getID(); @@ -1319,8 +1319,8 @@ public function duplicate() { $row = $this->fields; unset($row['id'], $row['uuid']); - $row['_skip_checks'] = true; - if (!$newQuestion->add($row)) { + $newQuestion_id = $newQuestion->add($row); + if ($newQuestion_id === false) { return false; } @@ -1344,11 +1344,13 @@ public function duplicate() { foreach ($rows as $row) { unset($row['id'], $row['uuid']); - $row['plugin_formcreator_questions_id'] = $newQuestion->getID(); + $row['plugin_formcreator_questions_id'] = $newQuestion_id; if (!$question_condition->add($row)) { return false; } } + + return $newQuestion_id; } /** diff --git a/inc/section.class.php b/inc/section.class.php index a4ed27d54..638610f8d 100644 --- a/inc/section.class.php +++ b/inc/section.class.php @@ -154,7 +154,7 @@ public function post_purgeItem() { /** * Duplicate a section * - * @return boolean + * @return integer|boolean ID of the new section, false otherwise */ public function duplicate() { $oldSectionId = $this->getID(); @@ -167,7 +167,8 @@ public function duplicate() { $row = $this->fields; unset($row['id'], $row['uuid']); - if (!$newSection->add($row)) { + $newSection_id = $newSection->add($row); + if ($newSection_id === false) { return false; } @@ -176,7 +177,7 @@ public function duplicate() { foreach ($rows as $questions_id => $row) { unset($row['id'], $row['uuid']); - $row['plugin_formcreator_sections_id'] = $newSection->getID(); + $row['plugin_formcreator_sections_id'] = $newSection_id; $row['_skip_checks'] = true; if (!$new_questions_id = $section_question->add($row)) { return false; @@ -223,7 +224,7 @@ public function duplicate() { } } - return true; + return $newSection_id; } diff --git a/setup.php b/setup.php index 818086b5e..8502f811b 100644 --- a/setup.php +++ b/setup.php @@ -205,7 +205,7 @@ function plugin_init_formcreator() { } if (strpos($_SERVER['REQUEST_URI'], "plugins/formcreator/front/targetticket.form.php") !== false) { - if ($CFG_GLPI['use_rich_text']) { + if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { Html::requireJs('tinymce'); } } diff --git a/tests/0000_Install/PluginInstallTest.php b/tests/0000_Install/PluginInstallTest.php deleted file mode 100644 index 313103d7f..000000000 --- a/tests/0000_Install/PluginInstallTest.php +++ /dev/null @@ -1,108 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class PluginInstallTest extends CommonTestCase -{ - - public function setUp() { - parent::setUp(); - self::setupGLPIFramework(); - self::login('glpi', 'glpi', true); - } - - protected function setupGLPI() { - global $CFG_GLPI; - - $settings = [ - 'use_notifications' => '1', - ]; - Config::setConfigurationValues('core', $settings); - - $CFG_GLPI = $settings + $CFG_GLPI; - } - - /** - * @engine inline - */ - public function testInstallPlugin() { - global $DB; - - $this->setupGLPI(); - - $this->assertTrue($DB->connected, 'Problem connecting to the Database'); - - $this->login('glpi', 'glpi'); - - //Drop plugin configuration if exists - $config = new Config(); - $config->deleteByCriteria(array('context' => 'formcreator')); - - // Drop tables of the plugin if they exist - $query = 'SHOW TABLES'; - $result = $DB->query($query); - while ($data = $DB->fetch_array($result)) { - if (strstr($data[0], 'glpi_plugin_formcreator') !== false) { - $DB->query('DROP TABLE '.$data[0]); - } - } - - self::resetGLPILogs(); - - $plugin = new Plugin(); - $plugin->getFromDBbyDir("formcreator"); - - ob_start(function($in) { return ''; }); - $plugin->install($plugin->fields['id']); - ob_end_clean(); - - $PluginDBTest = new PluginDB(); - // Checking the installed shcma is useless fir fresh install - // TODO: use the GLPI upgraded schema test - //$PluginDBTest->checkInstall('formcreator', 'install'); - - // Check the version of the schema is saved - $config = Config::getConfigurationValues('formcreator'); - $this->assertArrayHasKey('schema_version', $config); - $this->assertEquals(PLUGIN_FORMCREATOR_SCHEMA_VERSION, $config['schema_version']); - - // Check the cron task is created - $cronTask = new CronTask(); - $cronTask->getFromDBbyName(PluginFormcreatorIssue::class, 'SyncIssues'); - $this->assertFalse($cronTask->isNewItem()); - - // Enable the plugin - $plugin->activate($plugin->fields['id']); - $this->assertTrue($plugin->isActivated('formcreator'), 'Cannot enable the plugin'); - - } -} diff --git a/tests/0000_Install/SaveInstallTest.php b/tests/0000_Install/SaveInstallTest.php deleted file mode 100644 index 24f464f97..000000000 --- a/tests/0000_Install/SaveInstallTest.php +++ /dev/null @@ -1,57 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class SaveInstallTest extends CommonDBTestCase -{ - - public function should_restore_install() { - return false; - } - - public function testPluginIsActive() { - $plugin = new Plugin(); - $this->assertTrue($plugin->isActivated('formcreator'), "The plugin is not activated"); - } - - public function testSaveInstallation() { - global $DB; - $DB = new DB(); - - $this->mysql_dump($DB->dbuser, $DB->dbhost, $DB->dbpassword, $DB->dbdefault, './save.sql'); - - $this->assertFileExists("./save.sql"); - $filestats = stat("./save.sql"); - $length = $filestats[7]; - $this->assertGreaterThan(0, $length); - } -} \ No newline at end of file diff --git a/tests/0005_Unit/ActorFieldTest.php b/tests/0005_Unit/ActorFieldTest.php deleted file mode 100644 index 867c5fc3f..000000000 --- a/tests/0005_Unit/ActorFieldTest.php +++ /dev/null @@ -1,184 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class ActorFieldTest extends SuperAdminTestCase { - - public function provider() { - - $user = new User(); - $user->getFromDBbyName('glpi'); - $userId = $user->getID(); - $dataset = array( - array( - 'fields' => array( - 'fieldtype' => 'actor', - 'name' => 'question', - 'required' => '0', - 'default_values' => '', - 'values' => '', - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => array(''), - 'expectedIsValid' => true - ), - array( - 'fields' => array( - 'fieldtype' => 'actor', - 'name' => 'question', - 'required' => '0', - 'default_values' => '', - 'values' => 'glpi', - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => array(''), - 'expectedIsValid' => true - ), - array( - 'fields' => array( - 'fieldtype' => 'actor', - 'name' => 'question', - 'required' => '0', - 'default_values' => 'nonexistent', - 'values' => '', - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => array(''), - 'expectedIsValid' => false - ), - array( - 'fields' => array( - 'fieldtype' => 'actor', - 'name' => 'question', - 'required' => '0', - 'default_values' => 'email@incomplete', - 'values' => '', - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => array(''), - 'expectedIsValid' => false - ), - array( - 'fields' => array( - 'fieldtype' => 'actor', - 'name' => 'question', - 'required' => '0', - 'default_values' => 'email@something.com', - 'values' => '', - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => array('email@something.com'), - 'expectedIsValid' => true - ), - array( - 'fields' => array( - 'fieldtype' => 'actor', - 'name' => 'question', - 'required' => '0', - 'default_values' => $userId . ',email@something.com', - 'values' => '', - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => array('glpi', 'email@something.com'), - 'expectedIsValid' => true - ), - array( - 'fields' => array( - 'fieldtype' => 'actor', - 'name' => 'question', - 'required' => '0', - 'default_values' => $userId . ',email@something.com,nonexistent', - 'values' => '', - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => array('glpi', 'email@something.com'), - 'expectedIsValid' => false - ), - array( - 'fields' => array( - 'fieldtype' => 'actor', - 'name' => 'question', - 'required' => '0', - 'default_values' => $userId . ',email@something.com,email@incomplete', - 'values' => '', - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => array('glpi', 'email@something.com'), - 'expectedIsValid' => false - ), - ); - - return $dataset; - } - - /** - * @dataProvider provider - */ - public function testFieldValue($fields, $data, $expectedValue, $expectedValidity) { - $fieldInstance = new PluginFormcreatorActorField($fields, $data); - - $value = $fieldInstance->getValue(); - $this->assertEquals(count($expectedValue), count(explode(',', $value))); - foreach ($expectedValue as $expectedSubValue) { - if (!empty($expectedSubValue)) { - $this->assertTrue(in_array($expectedSubValue, explode(',', $value))); - } - } - } - - /** - * @dataProvider provider - */ - public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidity) { - $fieldInstance = new PluginFormcreatorActorField($fields, $data); - - $values = $fields['default_values']; - $isValid = $fieldInstance->isValid($values); - $this->assertEquals($expectedValidity, $isValid); - } -} diff --git a/tests/0005_Unit/CheckboxesFieldTest.php b/tests/0005_Unit/CheckboxesFieldTest.php deleted file mode 100644 index afe29cc26..000000000 --- a/tests/0005_Unit/CheckboxesFieldTest.php +++ /dev/null @@ -1,277 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class CheckboxesFieldTest extends SuperAdminTestCase { - - public function provider() { - - $dataset = array( - array( - 'fields' => array( - 'fieldtype' => 'checkboxes', - 'name' => 'question', - 'required' => '0', - 'default_values' => '', - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always', - '_parameters' => [ - 'checkboxes' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ] - ] - ], - ), - 'data' => null, - 'expectedValue' => array(''), - 'expectedIsValid' => true - ), - array( - 'fields' => array( - 'fieldtype' => 'checkboxes', - 'name' => 'question', - 'required' => '0', - 'default_values' => '2', - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always', - '_parameters' => [ - 'checkboxes' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ] - ] - ], - ), - 'data' => null, - 'expectedValue' => array('2'), - 'expectedIsValid' => true - ), - array( - 'fields' => array( - 'fieldtype' => 'checkboxes', - 'name' => 'question', - 'required' => '0', - 'default_values' => "3\r\n5", - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always', - '_parameters' => [ - 'checkboxes' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ] - ] - ], - ), - 'data' => null, - 'expectedValue' => array('3', '5'), - 'expectedIsValid' => true - ), - array( - 'fields' => array( - 'fieldtype' => 'checkboxes', - 'name' => 'question', - 'required' => '0', - 'default_values' => "3\r\n5", - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always', - '_parameters' => [ - 'checkboxes' => [ - 'range' => [ - 'range_min' => '3', - 'range_max' => '4', - ] - ] - ], - ), - 'data' => null, - 'expectedValue' => array('3', '5'), - 'expectedIsValid' => false - ), - array( - 'fields' => array( - 'fieldtype' => 'checkboxes', - 'name' => 'question', - 'required' => '0', - 'default_values' => "3\r\n5\r\n6", - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always', - '_parameters' => [ - 'checkboxes' => [ - 'range' => [ - 'range_min' => '3', - 'range_max' => '4', - ] - ] - ], - ), - 'data' => null, - 'expectedValue' => array('3', '5', '6'), - 'expectedIsValid' => true - ), - array( - 'fields' => array( - 'fieldtype' => 'checkboxes', - 'name' => 'question', - 'required' => '0', - 'default_values' => "1\r\n2\r\n3\r\n5\r\n6", - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always', - '_parameters' => [ - 'checkboxes' => [ - 'range' => [ - 'range_min' => '3', - 'range_max' => '4', - ] - ] - ], - ), - 'data' => null, - 'expectedValue' => array('1', '2', '3', '5', '6'), - 'expectedIsValid' => false - ), - ); - - return $dataset; - } - - /** - * @dataProvider provider - */ - public function testFieldAvailableValue($fields, $data, $expectedValue, $expectedValidity) { - $section = $this->getSection(); - $fields[$section::getForeignKeyField()] = $section->getID(); - $fieldInstance = new PluginFormcreatorCheckboxesField($fields, $data); - - $availableValues = $fieldInstance->getAvailableValues(); - $expectedAvaliableValues = explode("\r\n", $fields['values']); - - $this->assertCount(count($expectedAvaliableValues), $availableValues); - - foreach ($expectedAvaliableValues as $expectedValue) { - $this->assertContains($expectedValue, $availableValues); - } - } - - /** - * @dataProvider provider - */ - public function testFieldValue($fields, $data, $expectedValue, $expectedValidity) { - $fieldInstance = new PluginFormcreatorCheckboxesField($fields, $data); - - $value = $fieldInstance->getValue(); - $this->assertEquals(count($expectedValue), count($value)); - foreach ($expectedValue as $expectedSubValue) { - $this->assertTrue(in_array($expectedSubValue, $value)); - } - } - - /** - * @dataProvider provider - */ - public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidity) { - $section = $this->getSection(); - $fields[$section::getForeignKeyField()] = $section->getID(); - - $question = new PluginFormcreatorQuestion(); - $question->add($fields); - $question->updateParameters($fields); - - $fieldInstance = new PluginFormcreatorCheckboxesField($question->fields, $data); - $values = json_encode(explode("\r\n", $fields['default_values']), JSON_OBJECT_AS_ARRAY); - $isValid = $fieldInstance->isValid($values); - $this->assertEquals($expectedValidity, $isValid); - } - - public function testPrepareInputForSave() { - $fields = array( - 'fieldtype' => 'checkboxes', - 'name' => 'question', - 'required' => '0', - 'default_values' => "1\r\n2\r\n3\r\n5\r\n6", - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always', - 'range_min' => 3, - 'range_max' => 4, - ); - $fieldInstance = new PluginFormcreatorCheckboxesField($fields); - - // Test a value is mandatory - $input = [ - 'values' => "", - 'name' => 'foo', - ]; - $out = $fieldInstance->prepareQuestionInputForSave($input); - $this->assertEquals(0, count($out)); - - // Test accented chars are kept - $input = [ - 'values' => "éè\r\nsomething else", - 'default_values' => "éè", - ]; - $out = $fieldInstance->prepareQuestionInputForSave($input); - $this->assertEquals("éè\r\nsomething else", $out['values']); - $this->assertEquals("éè", $out['default_values']); - - // Test values are trimmed - $input = [ - 'values' => ' something \r\n something else ', - 'default_values' => " something ", - ]; - $out = $fieldInstance->prepareQuestionInputForSave($input); - $this->assertEquals('something\r\nsomething else', $out['values']); - $this->assertEquals("something", $out['default_values']); - } - - private function getSection() { - $form = new PluginFormcreatorForm(); - $form->add([ - 'name' => 'form' - ]); - $section = new PluginFormcreatorSection(); - $section->add([ - $form::getForeignKeyField() => $form->getID(), - 'name' => 'section', - ]); - return $section; - } -} \ No newline at end of file diff --git a/tests/0005_Unit/CommonTest.php b/tests/0005_Unit/CommonTest.php deleted file mode 100644 index d83070273..000000000 --- a/tests/0005_Unit/CommonTest.php +++ /dev/null @@ -1,41 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class PluginFormcreatorCommonTest extends SuperAdminTestCase { - public function testGetFormcreatorRequestTypeId() { - $requestTypeId = PluginFormcreatorCommon::getFormcreatorRequestTypeId(); - - // The ID must be > 0 (aka found) - $this->assertGreaterThan(0, $requestTypeId); - } -} \ No newline at end of file diff --git a/tests/0005_Unit/FormTest.php b/tests/0005_Unit/FormTest.php deleted file mode 100644 index 77b0f36a2..000000000 --- a/tests/0005_Unit/FormTest.php +++ /dev/null @@ -1,123 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class FormTest extends SuperAdminTestCase { - - protected $formData; - - public function setUp() { - parent::setUp(); - - $this->formData = array( - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'a form', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 0 - ); - } - - public function testCreateForm() { - $form = new PluginFormcreatorForm(); - $formId = $form->add($this->formData); - $this->assertFalse($form->isNewItem()); - - return $form; - } - - /** - * @depends testCreateForm - * @param PluginFormCreatorForm $form - */ - public function testUpdateForm(PluginFormcreatorForm $form) { - $success = $form->update(array( - 'id' => $form->getID(), - 'name' => 'an updated form', - 'validation_required' => 0 - )); - $this->assertTrue($success); - - return $form; - } - - /** - * @depends testUpdateForm - * @param PluginFormCreatorForm $form - */ - public function testPurgeForm(PluginFormcreatorForm $form) { - $success = $form->delete(array( - 'id' => $form->getID(), - ), 1); - $this->assertTrue($success); - } - - public function testCreateValidationNotification() { - global $CFG_GLPI; - Config::setConfigurationValues( - 'core', - ['use_notifications' => 1, 'notifications_mailing' => 1] - ); - $CFG_GLPI['use_notifications'] = 1; - $CFG_GLPI['notifications_mailing'] = 1; - $user = new USer(); - $user->update([ - 'id' => $_SESSION['glpiID'], - '_useremails' => [ - 'glpi@localhost.com', - ] - ]); - $form = new PluginFormcreatorForm(); - $form->add([ - 'name' => 'validation notification', - 'validation_required' => PluginFormcreatorForm_Validator::VALIDATION_USER, - '_validator_users' => [$_SESSION['glpiID']], - ]); - $section = new PluginFormcreatorSection(); - $section->add([ - $form::getForeignKeyField() => $form->getID(), - 'name' => 'section', - ]); - - $notification = new QueuedNotification(); - $notificationCount = count($notification->find()); - $formAnswer = new PluginFormcreatorForm_Answer(); - $formAnswer->saveAnswers([ - 'formcreator_form' => $form->getID(), - 'formcreator_validator' => $_SESSION['glpiID'], - ]); - // 1 notification to the validator - // 1 notification to the requester - $this->assertCount($notificationCount + 2, $notification->find()); - } -} diff --git a/tests/0005_Unit/RadiosFieldTest.php b/tests/0005_Unit/RadiosFieldTest.php deleted file mode 100644 index df29a26da..000000000 --- a/tests/0005_Unit/RadiosFieldTest.php +++ /dev/null @@ -1,75 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class RadiossFieldTest extends SuperAdminTestCase { - public function testPrepareInputForSave() { - $fields = array( - 'fieldtype' => 'radios', - 'name' => 'question', - 'required' => '0', - 'default_values' => "1\r\n2\r\n3\r\n5\r\n6", - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always', - 'range_min' => 3, - 'range_max' => 4, - ); - $fieldInstance = new PluginFormcreatorRadiosField($fields); - - // Test a value is mandatory - $input = [ - 'values' => "", - 'name' => 'foo', - ]; - $out = $fieldInstance->prepareQuestionInputForSave($input); - $this->assertEquals(0, count($out)); - - // Test accented chars are kept - $input = [ - 'values' => "éè\r\nsomething else", - 'default_values' => "éè", - ]; - $out = $fieldInstance->prepareQuestionInputForSave($input); - $this->assertEquals("éè\r\nsomething else", $out['values']); - $this->assertEquals("éè", $out['default_values']); - - // Test values are trimmed - $input = [ - 'values' => ' something \r\n something else ', - 'default_values' => " something ", - ]; - $out = $fieldInstance->prepareQuestionInputForSave($input); - $this->assertEquals('something\r\nsomething else', $out['values']); - $this->assertEquals("something", $out['default_values']); - } -} \ No newline at end of file diff --git a/tests/0005_Unit/SelectFieldTest.php b/tests/0005_Unit/SelectFieldTest.php deleted file mode 100644 index 2301163a6..000000000 --- a/tests/0005_Unit/SelectFieldTest.php +++ /dev/null @@ -1,195 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class SelectFieldTest extends SuperAdminTestCase { - - public function provider() { - - $dataset = array( - array( - 'fields' => array( - 'fieldtype' => 'select', - 'name' => 'question', - 'required' => '0', - 'show_empty' => '0', - 'default_values' => '', - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => '1', - 'expectedIsValid' => true - ), - array( - 'fields' => array( - 'fieldtype' => 'select', - 'name' => 'question', - 'required' => '0', - 'show_empty' => '1', - 'default_values' => '', - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => '', - 'expectedIsValid' => true - ), - array( - 'fields' => array( - 'fieldtype' => 'select', - 'name' => 'question', - 'required' => '0', - 'show_empty' => '0', - 'default_values' => '3', - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => '3', - 'expectedIsValid' => true - ), - array( - 'fields' => array( - 'fieldtype' => 'select', - 'name' => 'question', - 'required' => '1', - 'show_empty' => '0', - 'default_values' => '', - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => '1', - 'expectedIsValid' => false - ), - array( - 'fields' => array( - 'fieldtype' => 'select', - 'name' => 'question', - 'required' => '1', - 'show_empty' => '1', - 'default_values' => '', - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always' - ), - 'data' => null, - 'expectedValue' => '', - 'expectedIsValid' => false - ), - ); - - return $dataset; - } - - /** - * @dataProvider provider - */ - public function testFieldAvailableValue($fields, $data, $expectedValue, $expectedValidity) { - $fieldInstance = new PluginFormcreatorSelectField($fields, $data); - - $availableValues = $fieldInstance->getAvailableValues(); - $expectedAvaliableValues = explode("\r\n", $fields['values']); - - $this->assertCount(count($expectedAvaliableValues), $availableValues); - - foreach ($expectedAvaliableValues as $expectedValue) { - $this->assertContains($expectedValue, $availableValues); - } - } - - /** - * @dataProvider provider - */ - public function testFieldValue($fields, $data, $expectedValue, $expectedValidity) { - $fieldInstance = new PluginFormcreatorSelectField($fields, $data); - - $value = $fieldInstance->getValue(); - $this->assertEquals($expectedValue, $value); - } - - /** - * @dataProvider provider - */ - public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidity) { - $fieldInstance = new PluginFormcreatorSelectField($fields, $data); - - $isValid = $fieldInstance->isValid($fields['default_values']); - $this->assertEquals($expectedValidity, $isValid); - } - - public function testPrepareInputForSave() { - $fields = array( - 'fieldtype' => 'select', - 'name' => 'question', - 'required' => '0', - 'default_values' => "1\r\n2\r\n3\r\n5\r\n6", - 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", - 'order' => '1', - 'show_rule' => 'always', - 'range_min' => 3, - 'range_max' => 4, - ); - $fieldInstance = new PluginFormcreatorSelectField($fields); - - // Test a value is mandatory - $input = [ - 'values' => "", - 'name' => 'foo', - ]; - $out = $fieldInstance->prepareQuestionInputForSave($input); - $this->assertEquals(0, count($out)); - - // Test accented chars are kept - $input = [ - 'values' => "éè\r\nsomething else", - 'default_values' => "éè", - ]; - $out = $fieldInstance->prepareQuestionInputForSave($input); - $this->assertEquals("éè\r\nsomething else", $out['values']); - $this->assertEquals("éè", $out['default_values']); - - // Test values are trimmed - $input = [ - 'values' => ' something \r\n something else ', - 'default_values' => " something ", - ]; - $out = $fieldInstance->prepareQuestionInputForSave($input); - $this->assertEquals('something\r\nsomething else', $out['values']); - $this->assertEquals("something", $out['default_values']); - } -} \ No newline at end of file diff --git a/tests/0005_Unit/TargetTest.php b/tests/0005_Unit/TargetTest.php deleted file mode 100644 index e20843772..000000000 --- a/tests/0005_Unit/TargetTest.php +++ /dev/null @@ -1,91 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class TargetTest extends SuperAdminTestCase { - - public function addUpdateFormProvider() { - return [ - [ - 'input' => [ - 'name' => '', - 'itemtype' => PluginFormcreatorTargetTicket::class - ], - 'expected' => false, - ], - [ - 'input' => [ - 'name' => 'should fail', - 'itemtype' => '' - ], - 'expected' => false, - ], - [ - 'input' => [ - 'name' => 'should pass', - 'itemtype' => PluginFormcreatorTargetTicket::class - ], - 'expected' => true, - ], - [ - 'input' => [ - 'name' => 'être ou ne pas être', - 'itemtype' => PluginFormcreatorTargetTicket::class - ], - 'expected' => true, - ], - [ - 'input' => [ - 'name' => 'test d\\\'apostrophe', - 'itemtype' => PluginFormcreatorTargetTicket::class - ], - 'expected' => true, - ], - ]; - } - - /** - * @dataProvider addUpdateFormProvider - * @param array $input - * @param boolean $expected - */ - public function testPrepareInputForAdd($input, $expected) { - $target = new PluginFormcreatorTarget(); - $output = $target->prepareInputForAdd($input); - if ($expected === false) { - $this->assertCount(0, $output); - } else { - $this->assertEquals($input['name'], $output['name']); - $this->assertArrayHasKey('uuid', $output); - } - } -} diff --git a/tests/0005_Unit/TargetTicketTest.php b/tests/0005_Unit/TargetTicketTest.php deleted file mode 100644 index 47e2f395d..000000000 --- a/tests/0005_Unit/TargetTicketTest.php +++ /dev/null @@ -1,107 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class PluginFormcreatorTargetTicketTest extends SuperAdminTestCase { - - /** - * Tests that deleting a target ticket of a form also deletes relations between tickets and generated tickets - * - * @covers PluginFormcreatorTargetTicket::pre_deleteItem - */ - public function testDeleteLinkedTickets() { - // setup the test - $ticket = new Ticket(); - $ticket->add([ - 'name' => 'ticket', - 'content' => 'help !' - ]); - $this->assertFalse($ticket->isNewItem()); - - $form = new PluginFormcreatorForm(); - $formFk = PluginFormcreatorForm::getForeignKeyField(); - $form->add([ - 'name' => 'a form' - ]); - $this->assertFalse($form->isNewItem()); - - $target_1 = new PluginFormcreatorTarget(); - $target_1->add([ - 'name' => 'target 1', - $formFk => $form->getID(), - 'itemtype' => PluginFormcreatorTargetTicket::class, - ]); - $this->assertFalse($target_1->isNewItem()); - - $target_2 = new PluginFormcreatorTarget(); - $target_2->add([ - 'name' => 'target 2', - $formFk => $form->getID(), - 'itemtype' => PluginFormcreatorTargetTicket::class, - ]); - $this->assertFalse($target_2->isNewItem()); - - $targetTicket_1 = new PluginFormcreatorTargetTicket(); - $targetTicket_1->getFromDB($target_1->getField('items_id')); - $this->assertFalse($targetTicket_1->isNewItem()); - - $targetTicket_2 = new PluginFormcreatorTargetTicket(); - $targetTicket_2->getFromDB($target_2->getField('items_id')); - $this->assertFalse($targetTicket_2->isNewItem()); - - $targetTicketFk = PluginFormcreatorTargetTicket::getForeignKeyField(); - $item_targetticket_1 = new PluginFormcreatorItem_TargetTicket(); - $item_targetticket_1->add([ - $targetTicketFk => $targetTicket_1->getID(), - 'link' => Ticket_Ticket::LINK_TO, - 'itemtype' => Ticket::class, - 'items_id' => $ticket->getID(), - ]); - $this->assertFalse($item_targetticket_1->isNewItem()); - - $item_targetticket_2 = new PluginFormcreatorItem_TargetTicket(); - $item_targetticket_2->add([ - $targetTicketFk => $targetTicket_1->getID(), - 'link' => Ticket_Ticket::LINK_TO, - 'itemtype' => PluginFormcreatorTargetTicket::class, - 'items_id' => $targetTicket_2->getID(), - ]); - $this->assertFalse($item_targetticket_2->isNewItem()); - - // delete the target ticket - $target_1->delete(['id' => $target_1->getID()]); - - // Check the linked ticket or target ticket are deleted - $this->assertFalse($item_targetticket_1->getFromDB($item_targetticket_1->getID())); - $this->assertFalse($item_targetticket_2->getFromDB($item_targetticket_2->getID())); - } -} \ No newline at end of file diff --git a/tests/0010_Integration/CloneTest.php b/tests/0010_Integration/CloneTest.php deleted file mode 100644 index 4d2296449..000000000 --- a/tests/0010_Integration/CloneTest.php +++ /dev/null @@ -1,137 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class CloneTest extends SuperAdminTestCase { - public static function setUpBeforeClass() { - parent::setupBeforeClass(); - - self::login('glpi', 'glpi'); - - // instanciate classes - $form = new PluginFormcreatorForm; - $form_section = new PluginFormcreatorSection; - $form_question = new PluginFormcreatorQuestion; - $form_condition = new PluginFormcreatorQuestion_Condition; - $form_validator = new PluginFormcreatorForm_Validator; - $form_target = new PluginFormcreatorTarget; - $form_profile = new PluginFormcreatorForm_Profile; - - // create objects - $forms_id = $form->add(['name' => "test clone form", - 'is_active' => true, - 'validation_required' => PluginFormcreatorForm_Validator::VALIDATION_USER]); - - $sections_id = $form_section->add(['name' => "test clone section", - 'plugin_formcreator_forms_id' => $forms_id]); - - $questions_id_1 = $form_question->add(['name' => "test clone question 1", - 'fieldtype' => 'text', - 'plugin_formcreator_sections_id' => $sections_id, - '_parameters' => [ - 'text' => [ - 'regex' => '', - 'range' => ['min' => '', 'max' => ''], - ] - ], - ]); - $questions_id_2 = $form_question->add(['name' => "test clone question 2", - 'fieldtype' => 'textarea', - 'plugin_formcreator_sections_id' => $sections_id]); - } - - /** - * @cover PluginFormcreatorSection::clone - */ - public function testCloneSection() { - $section = new PluginFormcreatorSection; - $new_section = new PluginFormcreatorSection; - $form_question = new PluginFormcreatorQuestion; - - //get section - plugin_formcreator_getFromDBByField($section, 'name', "test clone section"); - - //clone it - $this->assertTrue($section->duplicate()); - - //get cloned section - $originalId = $section->getID(); - $new_section->getFromDBByCrit([ - 'AND' => [ - 'name' => 'test clone section', - 'NOT' => ['uuid' => $section->getField('uuid')], // operator <> available in GLPI 9.3+ only - 'plugin_formcreator_forms_id' => $section->getField('plugin_formcreator_forms_id') - ] - ]); - $this->assertFalse($new_section->isNewItem()); - - // check questions - $all_questions = $form_question->find("plugin_formcreator_sections_id = ".$section->getID()); - $all_new_questions = $form_question->find("plugin_formcreator_sections_id = ".$new_section->getID()); - $this->assertEquals(count($all_questions), count($all_new_questions)); - - // check that all question uuid are new - $uuids = $new_uuids = []; - foreach ($all_questions as $question) { - $uuids[] = $question['uuid']; - } - foreach ($all_new_questions as $question) { - $new_uuids[] = $question['uuid']; - } - $this->assertEquals($new_uuids, array_diff($new_uuids, $uuids)); - } - - /** - * @cover PluginFormcreatorQuestion::clone - */ - public function testCloneQuestion() { - $question = new PluginFormcreatorQuestion; - $new_question = new PluginFormcreatorQuestion; - - //get question - plugin_formcreator_getFromDBByField($question, 'name', "test clone question 1"); - - //clone it - $this->assertNotFalse($question->duplicate()); - - //get cloned section - $originalId = $question->getID(); - $new_question->getFromDBByCrit([ - 'AND' => [ - 'name' => 'test clone question 1', - 'NOT' => ['uuid' => $question->getField('uuid')], // operator <> available in GLPI 9.3+ only - 'plugin_formcreator_sections_id' => $question->getField('plugin_formcreator_sections_id') - ] - ]); - $this->assertFalse($new_question->isNewItem()); - } -} \ No newline at end of file diff --git a/tests/0010_Integration/FormAnswerValidationTest.php b/tests/0010_Integration/FormAnswerValidationTest.php deleted file mode 100644 index 0c15fd62b..000000000 --- a/tests/0010_Integration/FormAnswerValidationTest.php +++ /dev/null @@ -1,178 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class FormAnswerValidationTest extends SuperAdminTestCase { - - public function setUp() { - parent::setUp(); - - $this->formData = array( - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'a form', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => PluginFormcreatorForm_Validator::VALIDATION_USER, - ); - - $this->sectionData = array( - 'name' => 'a section', - ); - - $this->userValidatorData = array( - 'itemtype' => 'User', - 'users_id' => '2', // user is glpi - ); - - $this->formAnswersData = array( - 'status' => 'waiting', - 'formcreator_validator' => '2', - ); - - $this->otherValidatorUser = array( - 'name' => 'superadmin', - 'password' => 'superadmin', - '_profiles_id' => '4', - '_entities_id' => 0, - '_is_recursive' => 1, - ); - } - - public function testInitCreateForm() { - $form = new PluginFormcreatorForm(); - $form->add($this->formData); - $this->assertFalse($form->isNewItem()); - - return $form; - } - - /** - * @depends testInitCreateForm - * @param PluginFormcreatorForm $form - */ - public function testInitCreateSection(PluginFormcreatorForm $form) { - $section = new PluginFormcreatorSection(); - $this->sectionData = $this->sectionData + array( - 'plugin_formcreator_forms_id' => $form->getID() - ); - $section->add($this->sectionData); - $this->assertFalse($section->isNewItem()); - - return $section; - } - - /** - * @depends testInitCreateForm - * @param PluginFormcreatorForm $form - */ - public function testInitCreateValidator(PluginFormcreatorForm $form) { - $formValidator = new PluginFormcreatorForm_Validator(); - $formValidator->add( - $this->userValidatorData - + array('plugin_formcreator_forms_id' => $form->getID()) - ); - $this->assertFalse($formValidator->isNewItem()); - - return $formValidator; - } - - /** - * @depends testInitCreateForm - * @param PluginFormcreatorForm $form - */ - public function testInitCreateFormAnswer(PluginFormcreatorForm $form) { - global $DB; - - $this->formAnswersData['formcreator_form'] = $form->getID(); - - $formAnswer = new PluginFormcreatorForm_Answer(); - $formAnswer_table = PluginFormcreatorForm_Answer::getTable(); - - $result = $DB->query("SELECT MAX(`id`) AS `max_id` FROM `$formAnswer_table`"); - $maxId = $DB->fetch_assoc($result); - $maxId = $maxId['max_id']; - $maxId === null ? 0 : $maxId; - - $form->saveForm($this->formAnswersData); - - $result = $DB->query("SELECT MAX(`id`) AS `max_id` FROM `$formAnswer_table`"); - $newId = $DB->fetch_assoc($result); - $newId = $newId['max_id']; - - $this->assertGreaterThan($maxId, $newId); - $formAnswer->getFromDB($newId); - $this->assertFalse($formAnswer->isNewItem()); - - return $formAnswer; - } - - public function testInitCreateUser() { - $this->otherValidatorUser['password2'] = $this->otherValidatorUser['password']; - - $user = new User(); - $user->add($this->otherValidatorUser); - $this->assertFalse($user->isNewItem()); - - return $user; - } - - /** - * @depends testInitCreateUser - * @depends testInitCreateForm - * @depends testInitCreateFormAnswer - * @param User $user - * @param PluginFormcreatorForm $form - * @param PluginFormcreatorForm_Answer $formAnswer - */ - public function testOtherUserValidates(User $user, PluginFormcreatorForm $form, PluginFormcreatorForm_Answer $formAnswer) { - // Login as other user - $this->assertTrue(self::login('superadmin', 'superadmin', true)); - - $this->assertFalse($formAnswer->canValidate($form, $formAnswer)); - } - - /** - * @depends testInitCreateUser - * @depends testInitCreateForm - * @depends testInitCreateFormAnswer - * @param User $user - * @param PluginFormcreatorForm $form - * @param PluginFormcreatorForm_Answer $formAnswer - */ - public function testUserValidates(User $user, PluginFormcreatorForm $form, PluginFormcreatorForm_Answer $formAnswer) { - // Login as glpi - $this->assertTrue(self::login('glpi', 'glpi', true)); - - $this->assertTrue($formAnswer->canValidate($form, $formAnswer)); - } -} \ No newline at end of file diff --git a/tests/0010_Integration/Form_AnswerTest.php b/tests/0010_Integration/Form_AnswerTest.php deleted file mode 100644 index 284be8c41..000000000 --- a/tests/0010_Integration/Form_AnswerTest.php +++ /dev/null @@ -1,84 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class Form_AnswerTest extends SuperAdminTestCase { - - public function testNotificationFormAnswerCreated() { - global $DB, $CFG_GLPI; - - $user = new User(); - $user->getFromDBbyName('glpi'); - $user->update([ - 'id' => $user->getID(), - '_useremails' => ['glpi@localhost.local'], - ]); - - config::setConfigurationValues('core', ['notifications_mailing' => '1']); - $CFG_GLPI['notifications_mailing'] = '1'; - - $form = new PluginFormcreatorForm(); - $form->add([ - 'name' => 'a form', - 'validation_required' => '0' - ]); - $this->assertFalse($form->isNewItem()); - - // Answer the form - $form->saveForm(['formcreator_form' => $form->getID()]); - - // Check a notification was created with the expected template - $result = $DB->request([ - 'SELECT' => Notification_NotificationTemplate::getTable() . '.' . NotificationTemplate::getForeignKeyField(), - 'FROM' => Notification_NotificationTemplate::getTable(), - 'INNER JOIN' => [ - Notification::getTable() => [ - 'FKEY' => [ - Notification::getTable() => 'id', - Notification_NotificationTemplate::getTable() => Notification::getForeignKeyField() - ] - ] - ], - 'WHERE' => [ - 'itemtype' => PluginFormcreatorForm_Answer::class, - 'event' => 'plugin_formcreator_form_created', - ] - ]); - $this->assertCount(1, $result); - $row = $result->next(); - $queued = new QueuedNotification(); - $queued->getFromDBByCrit([NotificationTemplate::getForeignKeyField() => $row[NotificationTemplate::getForeignKeyField()]]); - - // Check the notification is linked to the expected itemtype - $this->assertEquals($queued->getField('itemtype'), PluginFormcreatorForm_Answer::class); - } -} \ No newline at end of file diff --git a/tests/0010_Integration/Form_ValidatorTest.php b/tests/0010_Integration/Form_ValidatorTest.php deleted file mode 100644 index 1e60a9844..000000000 --- a/tests/0010_Integration/Form_ValidatorTest.php +++ /dev/null @@ -1,111 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class Form_ValidatorTest extends SuperAdminTestCase { - - public function setUp() { - parent::setUp(); - - $this->formDataForGroup = array( - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'a form for group validator', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => PluginFormcreatorForm_Validator::VALIDATION_GROUP - ); - - $this->formDataForUser = array( - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'a form for user validator', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => PluginFormcreatorForm_Validator::VALIDATION_USER - ); - $this->groupData = array( - 'entities_id' => $_SESSION['glpiactive_entity'], - 'completename' => 'a group', - ); - } - - public function testInitCreateGroup() { - $group = new Group(); - $group->import($this->groupData); - - $this->assertFalse($group->isNewItem()); - - return $group; - } - - /** - * @depends testInitCreateGroup - * @return PluginFormcreatorForm - */ - public function testCreateFormForGroup(Group $group) { - $this->formDataForGroup = $this->formDataForGroup + array( - '_validator_groups' => array($group->getID()) - ); - $form = new PluginFormcreatorForm(); - $formId = $form->add($this->formDataForGroup); - $this->assertFalse($form->isNewItem()); - - $form_validator = new PluginFormcreatorForm_Validator(); - $form_validator->getFromDBForItems($form, $group); - $this->assertFalse($form_validator->isNewItem()); - - return $form; - } - - /** - * @return PluginFormcreatorForm - */ - public function testCreateFormForUser() { - $user = new User; - $user->getFromDBbyName('tech'); - $this->assertFalse($user->isNewItem()); - - $this->formDataForUser = $this->formDataForUser + array( - '_validator_users' => array($user->getID()) - ); - $form = new PluginFormcreatorForm(); - $formId = $form->add($this->formDataForUser); - $this->assertFalse($form->isNewItem()); - - $form_validator = new PluginFormcreatorForm_Validator(); - $form_validator->getFromDBForItems($form, $user); - $this->assertFalse($form_validator->isNewItem()); - - return $form; - } -} \ No newline at end of file diff --git a/tests/0010_Integration/IssueTest.php b/tests/0010_Integration/IssueTest.php deleted file mode 100644 index 24d7c7ccf..000000000 --- a/tests/0010_Integration/IssueTest.php +++ /dev/null @@ -1,440 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class IssueTest extends SuperAdminTestCase { - - - /** - * - */ - public function testAddTicket() { - $this->assertTrue(true); - $ticket = new Ticket(); - $ticket->add(array( - 'name' => 'ticket without form_answer', - 'content' => 'My computer is down !' - )); - $this->assertFalse($ticket->isNewItem()); - - $ticketId = $ticket->getID(); - $issue = new PluginFormcreatorIssue(); - // one and only one issue must exist. If several created, getFromDB will fail - $issue->getFromDBByCrit([ - 'AND' => [ - 'sub_itemtype' => Ticket::class, - 'original_id' => $ticketId - ] - ]); - $this->assertFalse($issue->isNewItem()); - } - - public function testAddFormAnswerWithoutTargetTicket() { - // create a form with a target ticket - $form = new PluginFormcreatorForm(); - $form->add(array( - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'form with 1 target ticket', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 0 - )); - $this->assertFalse($form->isNewItem()); - - // answer the form (no matter it is empty) - $formId = $form->getID(); - - // saveForm returns true if form data is valid - $this->assertTrue($form->saveForm(['formcreator_form' => $formId])); - - // find the generated form answer - $form_answer = new PluginFormcreatorForm_Answer(); - $form_answer->getFromDBByCrit(['plugin_formcreator_forms_id' => $formId]); - $this->assertFalse($form_answer->isNewItem()); - - // check an issue was created for the form answer - $formanswerId = $form_answer->getID(); - $form_answerIssue = new PluginFormcreatorIssue(); - $rows = $form_answerIssue->find("`sub_itemtype` = 'PluginFormcreatorForm_Answer' AND `original_id` = '$formanswerId'"); - $this->assertCount(1, $rows); - } - - public function testAddFormAnswerWithOneTargetTicket() { - // create a form with a target ticket - $form = new PluginFormcreatorForm(); - $form->add(array( - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'form with 1 target ticket', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 0 - )); - $this->assertFalse($form->isNewItem()); - - $target = new PluginFormcreatorTarget(); - $target->add(array( - 'name' => 'target', - 'itemtype' => 'PluginFormcreatorTargetTicket', - 'plugin_formcreator_forms_id' => $form->getID(), - )); - $this->assertFalse($target->isNewItem()); - - // answer the form (no matter it is empty) - $formId = $form->getID(); - - // saveForm returns true if form data is valid - $this->assertTrue($form->saveForm(['formcreator_form' => $formId])); - - // find the generated form answer - $form_answer = new PluginFormcreatorForm_Answer(); - $form_answer->getFromDBByCrit(['plugin_formcreator_forms_id' => $formId]); - $this->assertFalse($form_answer->isNewItem()); - - // find the generated ticket - $formanswerId = $form_answer->getID(); - $item_ticket = new Item_Ticket(); - $item_ticket->getFromDBByCrit([ - 'AND' => [ - 'itemtype' => PluginFormcreatorForm_Answer::class, - 'items_id' => $formanswerId - ] - ]); - $this->assertFalse($item_ticket->isNewItem()); - $ticket = new Ticket(); - $ticket->getFromDB($item_ticket->getField('tickets_id')); - $this->assertFalse($ticket->isNewItem()); - - // check an issue was created for the ticket - $ticketId = $ticket->getID(); - $ticketIssue = new PluginFormcreatorIssue(); - $ticketIssue->getFromDBByCrit([ - 'AND' => [ - 'sub_itemtype' => Ticket::class, - 'original_id' => $ticketId - ] - ]); - $this->assertFalse($ticketIssue->isNewItem()); - - // check no issue was created for the form answer - $form_answerIssue = new PluginFormcreatorIssue(); - $rows = $form_answerIssue->find("`sub_itemtype` = 'PluginFormcreatorForm_Answer' AND `original_id` = '$formanswerId'"); - $this->assertCount(0, $rows); - } - - public function testAddFormAnswerWithSeveralTargetTickets() { - // create form - $form = new PluginFormcreatorForm(); - $form->add(array( - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'form with 2 target tickets', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 0 - )); - - // create first target ticket - $target = new PluginFormcreatorTarget(); - $target->add(array( - 'name' => 'target 1', - 'itemtype' => 'PluginFormcreatorTargetTicket', - 'plugin_formcreator_forms_id' => $form->getID(), - )); - $this->assertFalse($target->isNewItem()); - - // create second target ticket - $target = new PluginFormcreatorTarget(); - $target->add(array( - 'name' => 'target 2', - 'itemtype' => 'PluginFormcreatorTargetTicket', - 'plugin_formcreator_forms_id' => $form->getID(), - )); - $this->assertFalse($target->isNewItem()); - - // answer the form (no matter it is empty) - $formId = $form->getID(); - - // saveForm returns true if form data is valid - $this->assertTrue($form->saveForm(['formcreator_form' => $formId])); - - // find the generated form answer - $form_answer = new PluginFormcreatorForm_Answer(); - $form_answer->getFromDBByCrit(['plugin_formcreator_forms_id' => $formId]); - $this->assertFalse($form_answer->isNewItem()); - - // find the generated tickets - $formanswerId = $form_answer->getID(); - $item_ticket = new Item_Ticket(); - $item_ticketRows = $item_ticket->find("`itemtype` = 'PluginFormcreatorForm_Answer' AND `items_id` = '$formanswerId'"); - $this->assertCount(2, $item_ticketRows); - - // check an issue was created for the form answer - $form_answerIssue = new PluginFormcreatorIssue(); - $rows = $form_answerIssue->find("`sub_itemtype` = 'PluginFormcreatorForm_Answer' AND `original_id` = '$formanswerId'"); - $this->assertCount(1, $rows); - - // check no issue was created for each generatred ticket - foreach ($item_ticketRows as $id => $row) { - $ticketId = $row['tickets_id']; - $rows = $form_answerIssue->find("`sub_itemtype` = 'Ticket' AND `original_id` = '$ticketId'"); - $this->assertCount(0, $rows); - } - } - - /** - * - */ - public function testDeleteTicket() { - $this->assertTrue(true); - $ticket = new Ticket(); - $ticket->add([ - 'name' => 'ticket to delete', - 'content' => 'My computer is down (again) !' - ]); - $this->assertFalse($ticket->isNewItem()); - - $ticketId = $ticket->getID(); - $issue = new PluginFormcreatorIssue(); - // one and only one issue must exist. If several created, getFromDB will fail - $issue->getFromDBByCrit([ - 'AND' => [ - 'sub_itemtype' => Ticket::class, - 'original_id' => $ticketId - ] - ]); - $this->assertFalse($issue->isNewItem()); - - $ticket->delete([ - 'id' => $ticketId - ]); - - $rows = $issue->find("`sub_itemtype` = 'Ticket' AND `original_id` = '$ticketId'"); - $this->assertCount(0, $rows); - } - - public function testDeleteFormAnswer() { - // create a form with a target ticket - $form = new PluginFormcreatorForm(); - $form->add([ - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'form with 1 target ticket', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 0 - ]); - $this->assertFalse($form->isNewItem()); - - // answer the form (no matter it is empty) - $formId = $form->getID(); - - // saveForm returns true if form data is valid - $this->assertTrue($form->saveForm(['formcreator_form' => $formId])); - - // find the generated form answer - $form_answer = new PluginFormcreatorForm_Answer(); - $form_answer->getFromDBByCrit(['plugin_formcreator_forms_id' => $formId]); - $this->assertFalse($form_answer->isNewItem()); - - // check an issue was created for the form answer - $formanswerId = $form_answer->getID(); - $form_answerIssue = new PluginFormcreatorIssue(); - $rows = $form_answerIssue->find("`sub_itemtype` = 'PluginFormcreatorForm_Answer' AND `original_id` = '$formanswerId'"); - $this->assertCount(1, $rows); - - $form_answer->delete(array( - 'id' => $formanswerId - )); - } - - public function testValidateFormAnswerSingleTargetTicket() { - // create a form with a target ticket - $userId = $_SESSION['glpiID']; - $form = new PluginFormcreatorForm(); - $form->add(array( - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'form to validate with 1 target ticket', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 1, - '_validator_users' => array($userId) - )); - $this->assertFalse($form->isNewItem()); - - $target = new PluginFormcreatorTarget(); - $target->add(array( - 'name' => 'target', - 'itemtype' => 'PluginFormcreatorTargetTicket', - 'plugin_formcreator_forms_id' => $form->getID(), - )); - $this->assertFalse($target->isNewItem()); - - // answer the form (no matter it is empty) - $formId = $form->getID(); - $saveFormData = array( - 'formcreator_form' => $formId, - 'formcreator_validator' => $_SESSION['glpiID'] - ); - - // saveForm returns true if form data is valid - $this->assertTrue($form->saveForm($saveFormData), json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); - - // find the generated form answer - $form_answer = new PluginFormcreatorForm_Answer(); - $form_answer->getFromDBByCrit(['plugin_formcreator_forms_id' => $formId]); - $this->assertFalse($form_answer->isNewItem()); - - // check no tickets are linked to the form answer - $formanswerId = $form_answer->getID(); - $item_ticket = new Item_Ticket(); - $item_ticketRows = $item_ticket->find("`itemtype` = 'PluginFormcreatorForm_Answer' AND `items_id` = '$formanswerId'"); - $this->assertCount(0, $item_ticketRows); - - // check an issue was created for the form answer - $form_answerIssue = new PluginFormcreatorIssue(); - $rows = $form_answerIssue->find("`sub_itemtype` = 'PluginFormcreatorForm_Answer' AND `original_id` = '$formanswerId'"); - $this->assertCount(1, $rows); - - // accept answers - $input = array( - 'formcreator_form' => $formId - ); - $form_answer->acceptAnswers($input); - - // find the generated ticket - $item_ticket = new Item_Ticket(); - $item_ticket->getFromDBByCrit([ - 'AND' => [ - 'itemtype' => PluginFormcreatorForm_Answer::class, - 'items_id' => $formanswerId - ] - ]); - $this->assertFalse($item_ticket->isNewItem()); - $ticket = new Ticket(); - $ticket->getFromDB($item_ticket->getField('tickets_id')); - $this->assertFalse($ticket->isNewItem()); - - // check an issue was created for the ticket - $ticketId = $ticket->getID(); - $ticketIssue = new PluginFormcreatorIssue(); - $rows = $ticketIssue->find("`sub_itemtype` = 'Ticket' AND `original_id` = '$ticketId'"); - $this->assertCount(1, $rows); - - // check no issue was created for the form answer - $form_answerIssue = new PluginFormcreatorIssue(); - $rows = $form_answerIssue->find("`sub_itemtype` = 'PluginFormcreatorForm_Answer' AND `original_id` = '$formanswerId'"); - $this->assertCount(0, $rows); - } - - public function testValidateFormAnswerMultipleTargetTicket() { - // create a form with a target ticket - $userId = $_SESSION['glpiID']; - $form = new PluginFormcreatorForm(); - $form->add(array( - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'form to validate with 2 target tickets', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 1, - '_validator_users' => array($userId) - )); - $this->assertFalse($form->isNewItem()); - - // create first target ticket - $target = new PluginFormcreatorTarget(); - $target->add(array( - 'name' => 'target 1', - 'itemtype' => 'PluginFormcreatorTargetTicket', - 'plugin_formcreator_forms_id' => $form->getID(), - )); - $this->assertFalse($target->isNewItem()); - - // create second target ticket - $target = new PluginFormcreatorTarget(); - $target->add(array( - 'name' => 'target 2', - 'itemtype' => 'PluginFormcreatorTargetTicket', - 'plugin_formcreator_forms_id' => $form->getID(), - )); - $this->assertFalse($target->isNewItem()); - - // answer the form (no matter it is empty) - $formId = $form->getID(); - $saveFormData = [ - 'formcreator_form' => $formId, - 'formcreator_validator' => $_SESSION['glpiID'] - ]; - - // saveForm returns true if form data is valid - $this->assertTrue($form->saveForm($saveFormData), json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); - - // find the generated form answer - $form_answer = new PluginFormcreatorForm_Answer(); - $form_answer->getFromDBByCrit(['plugin_formcreator_forms_id' => $formId]); - $this->assertFalse($form_answer->isNewItem()); - $formanswerId = $form_answer->getID(); - - // check an issue was created for the form answer - $form_answerIssue = new PluginFormcreatorIssue(); - $rows = $form_answerIssue->find("`sub_itemtype` = 'PluginFormcreatorForm_Answer' AND `original_id` = '$formanswerId'"); - $this->assertCount(1, $rows); - - // accept answers - $input = array( - 'formcreator_form' => $formId - ); - $form_answer->acceptAnswers($input); - - // check there is still an issue for the form answer - $form_answerIssue = new PluginFormcreatorIssue(); - $rows = $form_answerIssue->find("`sub_itemtype` = 'PluginFormcreatorForm_Answer' AND `original_id` = '$formanswerId'"); - $this->assertCount(1, $rows); - - // find the generated tickets - $formanswerId = $form_answer->getID(); - $item_ticket = new Item_Ticket(); - $item_ticketRows = $item_ticket->find("`itemtype` = 'PluginFormcreatorForm_Answer' AND `items_id` = '$formanswerId'"); - $this->assertCount(2, $item_ticketRows); - - // check no issue was created for each generatred ticket - foreach ($item_ticketRows as $id => $row) { - $ticketId = $row['tickets_id']; - $rows = $form_answerIssue->find("`sub_itemtype` = 'Ticket' AND `original_id` = '$ticketId'"); - $this->assertCount(0, $rows); - } - - } -} \ No newline at end of file diff --git a/tests/0010_Integration/Item_TargetTicketTest.php b/tests/0010_Integration/Item_TargetTicketTest.php deleted file mode 100644 index a73a8a492..000000000 --- a/tests/0010_Integration/Item_TargetTicketTest.php +++ /dev/null @@ -1,130 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class PluginFormcreatorItem_TargetTicketTest extends SuperAdminTestCase { - - /** - * - */ - public function testBuildCompositeRelations() { - // setup the test - $ticket = new Ticket(); - $ticket->add([ - 'name' => 'ticket', - 'content' => 'help !' - ]); - $this->assertFalse($ticket->isNewItem()); - - $form = new PluginFormcreatorForm(); - $formFk = PluginFormcreatorForm::getForeignKeyField(); - $form->add([ - 'name' => 'a form', - 'validation_required' => '0' - ]); - $this->assertFalse($form->isNewItem()); - - $target_1 = new PluginFormcreatorTarget(); - $target_1->add([ - 'name' => 'target 1', - $formFk => $form->getID(), - 'itemtype' => PluginFormcreatorTargetTicket::class, - ]); - $this->assertFalse($target_1->isNewItem()); - - $target_2 = new PluginFormcreatorTarget(); - $target_2->add([ - 'name' => 'target 2', - $formFk => $form->getID(), - 'itemtype' => PluginFormcreatorTargetTicket::class, - ]); - $this->assertFalse($target_2->isNewItem()); - - $targetTicket_1 = new PluginFormcreatorTargetTicket(); - $targetTicket_1->getFromDB($target_1->getField('items_id')); - $this->assertFalse($targetTicket_1->isNewItem()); - - $targetTicket_2 = new PluginFormcreatorTargetTicket(); - $targetTicket_2->getFromDB($target_2->getField('items_id')); - $this->assertFalse($targetTicket_2->isNewItem()); - - $targetTicketFk = PluginFormcreatorTargetTicket::getForeignKeyField(); - $item_targetticket_1 = new PluginFormcreatorItem_TargetTicket(); - $item_targetticket_1->add([ - $targetTicketFk => $targetTicket_1->getID(), - 'link' => Ticket_Ticket::LINK_TO, - 'itemtype' => Ticket::class, - 'items_id' => $ticket->getID(), - ]); - $this->assertFalse($item_targetticket_1->isNewItem()); - - $item_targetticket_2 = new PluginFormcreatorItem_TargetTicket(); - $item_targetticket_2->add([ - $targetTicketFk => $targetTicket_1->getID(), - 'link' => Ticket_Ticket::LINK_TO, - 'itemtype' => PluginFormcreatorTargetTicket::class, - 'items_id' => $targetTicket_2->getID(), - ]); - $this->assertFalse($item_targetticket_2->isNewItem()); - - // Answer the form - $form->saveForm([ - 'formcreator_form' => $form->getID() - ]); - - // Check the tickets are generated - $generatedTicket_1 = new Ticket(); - $generatedTicket_1->getFromDB($ticket->getID() + 1); - $this->assertFalse($generatedTicket_1->isNewItem()); - - $generatedTicket_2 = new Ticket(); - $generatedTicket_2->getFromDB($ticket->getID() + 2); - $this->assertFalse($generatedTicket_2->isNewItem()); - - // Check the generated tickets have expected relations - $ticket_ticket_1 = new Ticket_Ticket(); - $ticket_ticket_1->getFromDBByCrit([ - 'tickets_id_1' => $generatedTicket_1->getID(), - 'tickets_id_2' => $ticket->getID(), - 'link' => Ticket_Ticket::LINK_TO - ]); - $this->assertFalse($ticket_ticket_1->isNewItem()); - - $ticket_ticket_2 = new Ticket_Ticket(); - $ticket_ticket_2->getFromDBByCrit([ - 'tickets_id_1' => $generatedTicket_1->getID(), - 'tickets_id_2' => $generatedTicket_2->getID(), - 'link' => Ticket_Ticket::LINK_TO - ]); - $this->assertFalse($ticket_ticket_2->isNewItem()); - } -} \ No newline at end of file diff --git a/tests/0010_Integration/SectionTest.php b/tests/0010_Integration/SectionTest.php deleted file mode 100644 index afd09dd32..000000000 --- a/tests/0010_Integration/SectionTest.php +++ /dev/null @@ -1,95 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class SectionTest extends SuperAdminTestCase { - - public function setUp() { - parent::setUp(); - - $this->formData = array( - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'a form', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 0 - ); - - $this->sectionData = array( - 'name' => 'a section', - ); - } - - public function testInitCreateForm() { - $form = new PluginFormcreatorForm(); - $form->add($this->formData); - - return $form; - } - - /** - * @depends testInitCreateForm - * @param PluginFormCreatorForm $form - */ - public function testCreateSection(PluginFormCreatorForm $form) { - $section = new PluginFormcreatorSection(); - $this->sectionData = $this->sectionData + array('plugin_formcreator_forms_id' => $form->getID()); - $section->add($this->sectionData); - $this->assertFalse($section->isNewItem()); - - return $section; - } - - /** - * @depends testCreateSection - * @param PluginFormCreatorSection $section - */ - public function testUpdateSection(PluginFormCreatorSection $section) { - $success = $section->update(array( - 'id' => $section->getID(), - 'name' => 'section renamed' - )); - $this->assertTrue($success); - } - - /** - * @depends testCreateSection - * @param PluginFormCreatorSection $section - */ - public function testPurgeSection(PluginFormCreatorSection $section) { - $success = $section->delete(array( - 'id' => $section->getID() - ), 1); - $this->assertTrue($success); - } -} diff --git a/tests/0010_Integration/TargetChangeTest.php b/tests/0010_Integration/TargetChangeTest.php deleted file mode 100644 index b7e8e8003..000000000 --- a/tests/0010_Integration/TargetChangeTest.php +++ /dev/null @@ -1,124 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class TargetChangeTest extends SuperAdminTestCase { - - public function setUp() { - parent::setUp(); - - $this->formData = array( - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'a form', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 0 - ); - - $this->target = array( - 'name' => 'a target', - 'itemtype' => 'PluginFormcreatorTargetChange' - ); - } - - public function testInitCreateForm() { - $form = new PluginFormcreatorForm(); - $form->add($this->formData); - $this->assertFalse($form->isNewItem()); - - return $form; - } - - /** - * @depends testInitCreateForm - * @param PluginFormcreatorForm $form - */ - public function testCreateTarget(PluginFormcreatorForm $form) { - $target = new PluginFormcreatorTarget(); - $this->target = $this->target + array( - 'plugin_formcreator_forms_id' => $form->getID() - ); - $target->add($this->target); - $this->assertFalse($target->isNewItem()); - $this->assertEquals($form->getID(), $target->getField('plugin_formcreator_forms_id')); - $this->assertEquals('PluginFormcreatorTargetChange', $target->getField('itemtype')); - - return $target; - } - - /** - * @depends testInitCreateForm - * @depends testCreateTarget - * @param PluginFormcreatorForm $form - * @param PluginFormcreatorTarget $target - */ - public function testTargetChange(PluginFormcreatorForm $form, PluginFormcreatorTarget $target) { - $targetChange = $target->getField('items_id'); - $targetChange = new PluginFormcreatorTargetChange(); - $targetChange->getFromDB($target->getField('items_id')); - $this->assertFalse($targetChange->isNewItem()); - $this->assertEquals($target->getField('name'), $targetChange->getField('name')); - - return $targetChange; - } - - /** - * @depends testTargetChange - * @param PluginFormcreatorTargetTicket $target - */ - public function testTargetTicketActors(PluginFormcreatorTargetChange $targetChange) { - $requesterActor = new PluginFormcreatorTargetChange_Actor(); - $observerActor = new PluginFormcreatorTargetChange_Actor(); - $targetChangeId = $targetChange->getID(); - - $requesterActor->getFromDBByCrit([ - 'AND' => [ - 'plugin_formcreator_targetchanges_id' => $targetChangeId, - 'actor_role' => 'requester', - 'actor_type' => 'creator' - ] - ]); - $observerActor->getFromDBByCrit([ - 'AND' => [ - 'plugin_formcreator_targetchanges_id' => $targetChangeId, - 'actor_role' => 'observer', - 'actor_type' => 'validator' - ] - ]); - - $this->assertFalse($requesterActor->isNewItem()); - $this->assertFalse($observerActor->isNewItem()); - $this->assertEquals(1, $requesterActor->getField('use_notification')); - $this->assertEquals(1, $observerActor->getField('use_notification')); - } -} \ No newline at end of file diff --git a/tests/0010_Integration/TargetTicketTest.php b/tests/0010_Integration/TargetTicketTest.php deleted file mode 100644 index eef55e999..000000000 --- a/tests/0010_Integration/TargetTicketTest.php +++ /dev/null @@ -1,124 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class TargetTicketTest extends SuperAdminTestCase { - - public function setUp() { - parent::setUp(); - - $this->formData = array( - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'a form', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 0 - ); - - $this->target = array( - 'name' => 'a target', - 'itemtype' => 'PluginFormcreatorTargetTicket' - ); - } - - public function testInitCreateForm() { - $form = new PluginFormcreatorForm(); - $form->add($this->formData); - $this->assertFalse($form->isNewItem()); - - return $form; - } - - /** - * @depends testInitCreateForm - * @param PluginFormcreatorForm $form - */ - public function testCreateTarget(PluginFormcreatorForm $form) { - $target = new PluginFormcreatorTarget(); - $this->target = $this->target + array( - 'plugin_formcreator_forms_id' => $form->getID() - ); - $target->add($this->target); - $this->assertFalse($target->isNewItem()); - $this->assertEquals($form->getID(), $target->getField('plugin_formcreator_forms_id')); - $this->assertEquals('PluginFormcreatorTargetTicket', $target->getField('itemtype')); - - return $target; - } - - /** - * @depends testInitCreateForm - * @depends testCreateTarget - * @param PluginFormcreatorForm $form - * @param PluginFormcreatorTarget $target - */ - public function testTargetTicket(PluginFormcreatorForm $form, PluginFormcreatorTarget $target) { - $targetTicket = $target->getField('items_id'); - $targetTicket = new PluginFormcreatorTargetTicket(); - $targetTicket->getFromDB($target->getField('items_id')); - $this->assertFalse($targetTicket->isNewItem()); - $this->assertEquals($target->getField('name'), $targetTicket->getField('name')); - - return $targetTicket; - } - - /** - * @depends testTargetTicket - * @param PluginFormcreatorTargetTicket $target - */ - public function testTargetTicketActors(PluginFormcreatorTargetTicket $targetTicket) { - $requesterActor = new PluginFormcreatorTargetTicket_Actor(); - $observerActor = new PluginFormcreatorTargetTicket_Actor(); - $targetTicketId = $targetTicket->getID(); - - $requesterActor->getFromDBByCrit([ - 'AND' => [ - 'plugin_formcreator_targettickets_id' => $targetTicketId, - 'actor_role' => 'requester', - 'actor_type' => 'creator' - ] - ]); - $observerActor->getFromDBByCrit([ - 'AND' => [ - 'plugin_formcreator_targettickets_id' => $targetTicketId, - 'actor_role' => 'observer', - 'actor_type' => 'validator' - ] - ]); - - $this->assertFalse($requesterActor->isNewItem()); - $this->assertFalse($observerActor->isNewItem()); - $this->assertEquals(1, $requesterActor->getField('use_notification')); - $this->assertEquals(1, $observerActor->getField('use_notification')); - } -} \ No newline at end of file diff --git a/tests/9000_Uninstall/PluginUninstallTest.php b/tests/9000_Uninstall/PluginUninstallTest.php deleted file mode 100644 index 84cd80462..000000000 --- a/tests/9000_Uninstall/PluginUninstallTest.php +++ /dev/null @@ -1,76 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class PluginUninstallTest extends SuperAdminTestCase -{ - public function testUninstall() { - global $DB; - - $plugin = new Plugin(); - $plugin->getFromDBbyDir("formcreator"); - - // Uninstall the plugin - ob_start(function($in) { return ''; }); - $plugin->uninstall($plugin->getID()); - ob_end_clean(); - - // Check all tables are dropped - $tables = []; - $result = $DB->query("SHOW TABLES LIKE 'glpi_plugin_formcreator_%'"); - while ($row = $DB->fetch_assoc($result)) { - $tables[] = array_pop($row); - } - $this->assertCount(0, $tables, "not deleted tables \n" . json_encode($tables, JSON_PRETTY_PRINT)); - - // Check the request type still exists - $requestType = new RequestType(); - $rows = $requestType->find("`name` = 'Formcreator'"); - $this->assertCount(1, $rows); - - // Check the notifications of the plugin no longer exist - $notification = new Notification(); - $rows = $notification->find("`itemtype` = 'PluginFormcreatorForm_Answer'"); - $this->assertCount(0, $rows); - - $template = new NotificationTemplate(); - $rows = $template->find("`itemtype` = 'PluginFormcreatorForm_Answer'"); - $this->assertCount(0, $rows); - - $config = Config::getConfigurationValues('formcreator'); - $this->assertArrayNotHasKey('schema_version', $config); - - // TODO: need to find a reliable way to detect not clenaed - // - NotificationTemplateTranslation - // - Notification_NotificationTemplate - } -} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php index b6a5c132a..4ac047b8b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,65 +1,40 @@ . - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - // fix empty CFG_GLPI on boostrap; see https://github.com/sebastianbergmann/phpunit/issues/325 global $CFG_GLPI; -class UnitTestAutoload -{ - - public static function register() { - spl_autoload_register(array('UnitTestAutoload', 'autoload')); - } +//disable session cookies +ini_set('session.use_cookies', 0); +ini_set("memory_limit", "-1"); +ini_set("max_execution_time", "0"); - public static function autoload($className) { - $file = __DIR__ . "/inc/$className.php"; - if (is_readable($file) && is_file($file)) { - include_once(__DIR__ . "/inc/$className.php"); - return true; - } - return false; - } +require_once __DIR__ . '/../vendor/autoload.php'; -} +define('TEST_PLUGIN_NAME', 'formcreator'); -ini_set('session.use_cookies', 0); //disable session cookies +// glpi/inc/oolbox.class.php tests TU_USER to decide if it warns or not about mcrypt extension +define('TU_USER', '_test_user'); -UnitTestAutoload::register(); - -define('GLPI_ROOT', dirname(dirname(dirname(__DIR__)))); +define('GLPI_ROOT', realpath(__DIR__ . '/../../../')); define("GLPI_CONFIG_DIR", GLPI_ROOT . "/tests"); if (!file_exists(GLPI_CONFIG_DIR . '/config_db.php')) { echo "config_db.php missing. Did GLPI successfully initialized ?\n"; exit(1); } +define('GLPI_LOG_DIR', __DIR__ . '/logs'); +@mkdir(GLPI_LOG_DIR); +if (!defined('STDERR')) { + define('STDERR', fopen(GLPI_LOG_DIR . 'stderr.log', 'w')); +} + +// Giving --debug argument to atoum will be detected by GLPI too +// the error handler in Toolbox may output to stdout a message and break process communication +// in atoum +$key = array_search('--debug', $_SERVER['argv']); +if ($key) { + unset($_SERVER['argv'][$key]); +} + include (GLPI_ROOT . "/inc/includes.php"); + +// If GLPI debug mode is disabled, atoum cannot produce backtaces +//\Toolbox::setDebugMode(Session::DEBUG_MODE); diff --git a/tests/functional/.empty b/tests/functional/.empty new file mode 100644 index 000000000..e69de29bb diff --git a/tests/functional/testCentralHasTab.js b/tests/functional/testCentralHasTab.js new file mode 100644 index 000000000..ce42ce863 --- /dev/null +++ b/tests/functional/testCentralHasTab.js @@ -0,0 +1,46 @@ +'use strict' +const Nightmare = require('nightmare') +const expect = require('chai').expect +const testSettings = require('../functionalTest.dist.js') + +describe('Check the tab of forms appears on the homepage of helpdesk', function() { + this.timeout('5s') + + const screenshotPath = require('path').dirname(__dirname) + '/logs'; + const login = 'glpi' + const passwd = 'glpi' + + let nightmare = null + beforeEach(() => { + nightmare = new Nightmare({ + waitTimeout: 4000, // milliseconds + loadTimeout: 2000, // in milliseconds + show: testSettings.show + }) + }) + + describe('Helpdesk home page', () => { + it('should show a new tab to get available forms', done => { + nightmare + .viewport(1280, 1024) + .goto(testSettings.baseUrl) + .wait('#boxlogin .submit') + .type('input#login_name', login) + .type('input#login_password', passwd) + .click('#boxlogin > form input.submit') + .wait('#footer') + .html(testSettings.screenshot + '/error.html', 'HTMLOnly') + .evaluate(() => { + return document.querySelectorAll('#page > div > div > ul > li > a[title="Forms"]').length + }) + .end() + .then(result => { + expect(result).to.eql(1) + done() + }) + .catch(error => { + console.error('test failed:', error) + }) + }) + }) +}) diff --git a/tests/functionalTest.dist.js b/tests/functionalTest.dist.js new file mode 100644 index 000000000..2a2454e80 --- /dev/null +++ b/tests/functionalTest.dist.js @@ -0,0 +1,16 @@ +'use strict' + +const fs = require('fs') +var settings + +if (!fs.existsSync(__dirname + '/functionalTest.json')) { + settings = { + "baseUrl": "http://localhost:8088" + } +} else { + settings = require(__dirname + '/functionalTest.json') +} +settings.screenshot = __dirname + '/logs' + +console.log(settings) +module.exports = settings diff --git a/tests/functionalTest.json b/tests/functionalTest.json new file mode 100644 index 000000000..01738e8af --- /dev/null +++ b/tests/functionalTest.json @@ -0,0 +1,4 @@ +{ + "baseUrl": "http://localhost:8088", + "show": true +} \ No newline at end of file diff --git a/tests/inc/CommonDBTestCase.php b/tests/inc/CommonDBTestCase.php deleted file mode 100644 index 7d53bff47..000000000 --- a/tests/inc/CommonDBTestCase.php +++ /dev/null @@ -1,206 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class CommonDBTestCase extends PHPUnit\Framework\TestCase { - - protected static function drop_database($dbuser='', $dbhost='', $dbdefault='', $dbpassword='') { - - $cmd = self::construct_mysql_options($dbuser, $dbhost, $dbpassword, 'mysql'); - - if (is_array($cmd)) { - return $cmd; - } - - $cmd = 'echo "DROP DATABASE IF EXISTS \`'.$dbdefault .'\`; CREATE DATABASE \`'.$dbdefault.'\`" | ' . $cmd ." 2>&1"; - - $returncode = 0; - $output = []; - exec( - $cmd, - $output, - $returncode - ); - array_unshift($output, "Output of '{$cmd}'"); - return array( - 'returncode'=>$returncode, - 'output' => $output - ); - } - - protected static function load_mysql_file($dbuser='', $dbhost='', $dbdefault='', $dbpassword='', $file = NULL) { - - if (!file_exists($file)) { - return array( - 'returncode' => 1, - 'output' => array("ERROR: File '{$file}' does not exist !") - ); - } - - $result = self::construct_mysql_options($dbuser, $dbhost, $dbpassword, 'mysql'); - - if (is_array($result)) { - return $result; - } - - $cmd = $result . " " . $dbdefault . " < ". $file ." 2>&1"; - - $returncode = 0; - $output = []; - exec( - $cmd, - $output, - $returncode - ); - array_unshift($output, "Output of '{$cmd}'"); - return array( - 'returncode'=>$returncode, - 'output' => $output - ); - } - - protected static function construct_mysql_options($dbuser='', $dbhost='', $dbpassword='', $cmd_base='mysql') { - $cmd = []; - - if (empty($dbuser) || empty($dbhost)) { - return array( - 'returncode' => 2, - 'output' => array("ERROR: missing mysql parameters (user='{$dbuser}', host='{$dbhost}')") - ); - } - $cmd = array($cmd_base); - - if (strpos($dbhost, ':') !== FALSE) { - $dbhost = explode( ':', $dbhost); - if (!empty($dbhost[0])) { - $cmd[] = "--host ".$dbhost[0]; - } - if (is_numeric($dbhost[1])) { - $cmd[] = "--port ".$dbhost[1]; - } else { - // The dbhost's second part is assumed to be a socket file if it is not numeric. - $cmd[] = "--socket ".$dbhost[1]; - } - } else { - $cmd[] = "--host ".$dbhost; - } - - $cmd[] = "--user ".$dbuser; - - if (!empty($dbpassword)) { - $cmd[] = "-p'".urldecode($dbpassword)."'"; - } - - return implode(' ', $cmd); - } - - protected static function mysql_dump($dbuser = '', $dbhost = '', $dbpassword = '', $dbdefault = '', $file = NULL) { - if (is_null($file) or empty($file)) { - return array( - 'returncode' => 1, - 'output' => array("ERROR: mysql_dump()'s file argument must neither be null nor empty") - ); - } - - if (empty($dbdefault)) { - return array( - 'returncode' => 2, - 'output' => array("ERROR: mysql_dump() is missing dbdefault argument.") - ); - } - - $result = self::construct_mysql_options($dbuser, $dbhost, $dbpassword, 'mysqldump'); - if (is_array($result)) { - return $result; - } - - $cmd = $result . ' --opt '. $dbdefault.' > ' . $file; - $returncode = 0; - $output = []; - exec( - $cmd, - $output, - $returncode - ); - array_unshift($output, "Output of '{$cmd}'"); - return array( - 'returncode'=>$returncode, - 'output' => $output - ); - } - - protected static function setupGLPIFramework() { - global $CFG_GLPI, $DB, $LOADED_PLUGINS, $PLUGIN_HOOKS, $AJAX_INCLUDE, $PLUGINS_INCLUDED; - - if (session_status() == PHP_SESSION_ACTIVE) { - session_write_close(); - } - $LOADED_PLUGINS = null; - $PLUGINS_INCLUDED = null; - $AJAX_INCLUDE = null; - $_SESSION = []; - $_SESSION['glpi_use_mode'] = Session::NORMAL_MODE; // Prevents notice in execution of GLPI_ROOT . /inc/includes.php - if (is_readable(GLPI_ROOT . "/config/config.php")) { - $configFile = "/config/config.php"; - } else { - $configFile = "/inc/config.php"; - } - include (GLPI_ROOT . $configFile); - require (GLPI_ROOT . "/inc/includes.php"); - $_SESSION['glpi_use_mode'] = Session::DEBUG_MODE; - \Toolbox::setDebugMode(); - - include_once (GLPI_ROOT . "/inc/timer.class.php"); - - // Security of PHP_SELF - $_SERVER['PHP_SELF']=Html::cleanParametersURL($_SERVER['PHP_SELF']); - - ini_set("memory_limit", "-1"); - ini_set("max_execution_time", "0"); - - if (session_status() == PHP_SESSION_ACTIVE) { - session_write_close(); - } - session_start(); - $_SESSION['MESSAGE_AFTER_REDIRECT'] = []; - } - - protected static function login($name, $password, $noauto = false) { - Session::start(); - $_SESSION['glpi_use_mode'] = Session::NORMAL_MODE; - $auth = new Auth(); - $result = $auth->Login($name, $password, $noauto); - $_SESSION['MESSAGE_AFTER_REDIRECT'] = []; - - return $result; - } -} diff --git a/tests/inc/CommonTestCase.php b/tests/inc/CommonTestCase.php deleted file mode 100644 index b093eb406..000000000 --- a/tests/inc/CommonTestCase.php +++ /dev/null @@ -1,74 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -abstract class CommonTestCase extends CommonDBTestCase -{ - - protected static function resetState() { - - self::resetGLPILogs(); - - $DBvars = get_class_vars('DB'); - $result = self::drop_database( - $DBvars['dbuser'], - $DBvars['dbhost'], - $DBvars['dbdefault'], - $DBvars['dbpassword'] - ); - - $result = self::load_mysql_file($DBvars['dbuser'], - $DBvars['dbhost'], - $DBvars['dbdefault'], - $DBvars['dbpassword'], - './save.sql' - ); - - } - - protected static function resetGLPILogs() { - // Reset error logs - file_put_contents(GLPI_LOG_DIR."/sql-errors.log", ''); - file_put_contents(GLPI_LOG_DIR."/php-errors.log", ''); - } - - protected function tearDown() { - // Check logs - $fileSqlContent = file_get_contents(GLPI_LOG_DIR."/sql-errors.log"); - $filePhpContent = file_get_contents(GLPI_LOG_DIR."/php-errors.log"); - - self::resetGLPILogs(); - - $this->assertEquals('', $fileSqlContent, 'sql-errors.log not empty'); - $this->assertEquals('', $filePhpContent, 'php-errors.log not empty'); - } -} \ No newline at end of file diff --git a/tests/inc/GLPIlogs.php b/tests/inc/GLPIlogs.php deleted file mode 100644 index de585e5ef..000000000 --- a/tests/inc/GLPIlogs.php +++ /dev/null @@ -1,68 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class GLPIlogs extends PHPUnit\Framework\TestCase { - - public function testSQLlogs() { - - $filecontent = file_get_contents(GLPI_LOG_DIR."/sql-errors.log"); - - $this->assertEquals('', $filecontent, 'sql-errors.log not empty'); - // Reinitialize file - file_put_contents(GLPI_LOG_DIR."/sql-errors.log", ''); - } - - - - public function testPHPlogs() { - - $filecontent = file_get_contents(GLPI_LOG_DIR."/php-errors.log"); - - $this->assertEquals('', $filecontent, 'php-errors.log not empty'); - // Reinitialize file - file_put_contents(GLPI_LOG_DIR."/php-errors.log", ''); - } - -} - - - -class GLPIlogs_AllTests { - - public static function suite() { - - $suite = new PHPUnit\Framework\TestSuite('GLPIlogs'); - return $suite; - } -} - diff --git a/tests/inc/PluginDB.php b/tests/inc/PluginDB.php deleted file mode 100644 index cc333e54d..000000000 --- a/tests/inc/PluginDB.php +++ /dev/null @@ -1,157 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class PluginDB extends PHPUnit\Framework\Assert{ - - public function checkInstall($pluginname='', $when='') { - global $DB; - - if ($pluginname == '') { - return; - } - - $comparaisonSQLFile = "plugin_".$pluginname."_empty.sql"; - // See http://joefreeman.co.uk/blog/2009/07/php-script-to-compare-mysql-database-schemas/ - - $file_content = file_get_contents(GLPI_ROOT."/plugins/".$pluginname."/install/mysql/".$comparaisonSQLFile); - $a_lines = explode("\n", $file_content); - - $a_tables_ref = []; - $current_table = ''; - foreach ($a_lines as $line) { - if (strstr($line, "CREATE TABLE ") - OR strstr($line, "CREATE VIEW")) { - $matches = []; - preg_match("/`(.*)`/", $line, $matches); - $current_table = $matches[1]; - } else { - if (preg_match("/^`/", trim($line))) { - $line = preg_replace('/\s+/', ' ', $line); - $s_line = explode("`", $line); - $s_type = explode("COMMENT", $s_line[2]); - $s_type[0] = trim($s_type[0]); - $s_type[0] = str_replace(" COLLATE utf8_unicode_ci", "", $s_type[0]); - $s_type[0] = str_replace(" CHARACTER SET utf8", "", $s_type[0]); - $a_tables_ref[$current_table][$s_line[1]] = str_replace(",", "", $s_type[0]); - } - } - } - - // * Get tables from MySQL - $a_tables_db = []; - $a_tables = []; - // SHOW TABLES; - $query = "SHOW TABLES"; - $result = $DB->query($query); - while ($data=$DB->fetch_array($result)) { - if (strstr($data[0], "formcreator")) { - - $data[0] = str_replace(" COLLATE utf8_unicode_ci", "", $data[0]); - $data[0] = str_replace("( ", "(", $data[0]); - $data[0] = str_replace(" )", ")", $data[0]); - $a_tables[] = $data[0]; - } - } - - $toIgnore = []; - foreach ($a_tables as $table) { - $query = "SHOW CREATE TABLE ".$table; - $result = $DB->query($query); - while ($data=$DB->fetch_array($result)) { - if (!isset($data['Create Table'])) { - // This is not a table (a view for example) - $toIgnore[$table] = $table; - continue; - } - $a_lines = explode("\n", $data['Create Table']); - - foreach ($a_lines as $line) { - if (strstr($line, "CREATE TABLE ") - OR strstr($line, "CREATE VIEW")) { - $matches = []; - preg_match("/`(.*)`/", $line, $matches); - $current_table = $matches[1]; - } else { - if (preg_match("/^`/", trim($line))) { - $line = preg_replace('/\s+/', ' ', $line); - $s_line = explode("`", $line); - $s_type = explode("COMMENT", $s_line[2]); - $s_type[0] = trim($s_type[0]); - $s_type[0] = str_replace(" COLLATE utf8_unicode_ci", "", $s_type[0]); - $s_type[0] = str_replace(" CHARACTER SET utf8", "", $s_type[0]); - $s_type[0] = str_replace(",", "", $s_type[0]); - $a_tables_db[$current_table][$s_line[1]] = $s_type[0]; - } - } - } - } - } - - $a_tables_ref_tableonly = []; - foreach ($a_tables_ref as $table=>$data) { - if (!isset($toIgnore[$table])) { - $a_tables_ref_tableonly[] = $table; - } - } - $a_tables_db_tableonly = []; - foreach ($a_tables_db as $table=>$data) { - $a_tables_db_tableonly[] = $table; - } - - // Compare - $tables_toremove = array_diff($a_tables_db_tableonly, $a_tables_ref_tableonly); - $tables_toadd = array_diff($a_tables_ref_tableonly, $a_tables_db_tableonly); - - // See tables missing or to delete - $this->assertEquals(count($tables_toadd), 0, 'Tables missing '.$when.' '.print_r($tables_toadd, TRUE)); - $this->assertEquals(count($tables_toremove), 0, 'Tables to delete '.$when.' '.print_r($tables_toremove, TRUE)); - - // See if fields are same - foreach ($a_tables_db as $table=>$data) { - if (isset($a_tables_ref[$table])) { - $fields_toremove = array_diff_assoc($data, $a_tables_ref[$table]); - $fields_toadd = array_diff_assoc($a_tables_ref[$table], $data); - $diff = "======= DB ============== Ref =======> ".$table."\n"; - $diff .= print_r($data, TRUE); - $diff .= print_r($a_tables_ref[$table], TRUE); - - // See tables missing or to delete - $this->assertEquals(count($fields_toadd), 0, 'Fields missing/not good in '.$when.' '.$table.' '.print_r($fields_toadd, TRUE)." into ".$diff); - $this->assertEquals(count($fields_toremove), 0, 'Fields to delete in '.$when.' '.$table.' '.print_r($fields_toremove, TRUE)." into ".$diff); - - } - } - - } -} - diff --git a/tests/inc/SuperAdminTestCase.php b/tests/inc/SuperAdminTestCase.php deleted file mode 100644 index 2866ea949..000000000 --- a/tests/inc/SuperAdminTestCase.php +++ /dev/null @@ -1,48 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class SuperAdminTestCase extends CommonTestCase -{ - - public static function setupBeforeClass() { - parent::setupBeforeClass(); - self::resetState(); - self::setupGLPIFramework(); - } - - public function setUp() { - self::setupGLPIFramework(); - $this->assertTrue(self::login('glpi', 'glpi', true)); - } - -} \ No newline at end of file diff --git a/tests/logs/.empty b/tests/logs/.empty new file mode 100644 index 000000000..e69de29bb diff --git a/tests/src/CommonDBTestCase.php b/tests/src/CommonDBTestCase.php new file mode 100644 index 000000000..68f483c24 --- /dev/null +++ b/tests/src/CommonDBTestCase.php @@ -0,0 +1,248 @@ +construct_mysql_options($dbuser, $dbhost, $dbpassword, 'mysql'); + + if (is_array($cmd)) { + return $cmd; + } + + $cmd = 'echo "DROP DATABASE IF EXISTS \`'.$dbdefault .'\`; CREATE DATABASE \`'.$dbdefault.'\`" | ' . $cmd ." 2>&1"; + + $returncode = 0; + $output = array(); + exec( + $cmd, + $output, + $returncode + ); + array_unshift($output, "Output of '{$cmd}'"); + return array( + 'returncode' => $returncode, + 'output' => $output + ); + } + + protected function load_mysql_file($dbuser='', $dbhost='', $dbdefault='', $dbpassword='', $file = NULL) { + + if (!file_exists($file)) { + return array( + 'returncode' => 1, + 'output' => array("ERROR: File '$file' does not exist !") + ); + } + + $result = $this->construct_mysql_options($dbuser, $dbhost, $dbpassword, 'mysql'); + + if (is_array($result)) { + return $result; + } + + $cmd = $result . " " . $dbdefault . " < ". $file ." 2>&1"; + + $returncode = 0; + $output = array(); + exec( + $cmd, + $output, + $returncode + ); + array_unshift($output, "Output of '$cmd'"); + return array( + 'returncode' => $returncode, + 'output' => $output + ); + } + + protected function construct_mysql_options($dbuser='', $dbhost='', $dbpassword='', $cmd_base='mysql') { + $cmd = array(); + + if (empty($dbuser) || empty($dbhost)) { + return array( + 'returncode' => 2, + 'output' => array("ERROR: missing mysql parameters (user='{$dbuser}', host='{$dbhost}')") + ); + } + $cmd = array($cmd_base); + + if (strpos($dbhost, ':') !== FALSE) { + $dbhost = explode( ':', $dbhost); + if (!empty($dbhost[0])) { + $cmd[] = "--host ".$dbhost[0]; + } + if (is_numeric($dbhost[1])) { + $cmd[] = "--port ".$dbhost[1]; + } else { + // The dbhost's second part is assumed to be a socket file if it is not numeric. + $cmd[] = "--socket ".$dbhost[1]; + } + } else { + $cmd[] = "--host ".$dbhost; + } + + $cmd[] = "--user ".$dbuser; + + if (!empty($dbpassword)) { + $cmd[] = "-p'".urldecode($dbpassword)."'"; + } + + return implode(' ', $cmd); + } + + protected function mysql_dump($dbuser = '', $dbhost = '', $dbpassword = '', $dbdefault = '', $file = NULL) { + if (is_null($file) or empty($file)) { + return array( + 'returncode' => 1, + 'output' => array("ERROR: mysql_dump()'s file argument must neither be null nor empty") + ); + } + + if (empty($dbdefault)) { + return array( + 'returncode' => 2, + 'output' => array("ERROR: mysql_dump() is missing dbdefault argument.") + ); + } + + $result = self::construct_mysql_options($dbuser, $dbhost, $dbpassword, 'mysqldump'); + if (is_array($result)) { + return $result; + } + + $cmd = $result . ' --opt '. $dbdefault.' > ' . $file; + $returncode = 0; + $output = array(); + exec( + $cmd, + $output, + $returncode + ); + array_unshift($output, "Output of '{$cmd}'"); + return array( + 'returncode'=>$returncode, + 'output' => $output + ); + } + + /** + * compare a .sql schema against the database + * @param string $pluginname + * @param string Tables of the t ested DB having this string in their name are checked + * @param string $when + */ + public function checkInstall($filename = '', $filter = 'glpi_', $when = '') { + global $DB; + + if ($filename == '') { + return; + } + + // See http://joefreeman.co.uk/blog/2009/07/php-script-to-compare-mysql-database-schemas/ + $file_content = file_get_contents($filename); + $a_lines = explode("\n", $file_content); + + $a_tables_ref = array(); + $current_table = ''; + foreach ($a_lines as $line) { + if (strstr($line, "CREATE TABLE ") || strstr($line, "CREATE VIEW ")) { + $matches = array(); + preg_match("/`(.*)`/", $line, $matches); + $current_table = $matches[1]; + } else { + if (preg_match("/^`/", trim($line))) { + $line = preg_replace('/\s+/', ' ', $line); + $s_line = explode("`", $line); + $s_type = explode("COMMENT", $s_line[2]); + $s_type[0] = trim($s_type[0]); + $s_type[0] = str_replace(" COLLATE utf8_unicode_ci", "", $s_type[0]); + $s_type[0] = str_replace(" CHARACTER SET utf8", "", $s_type[0]); + if (strpos(trim($s_type[0]), 'text') === 0 + || strpos(trim($s_type[0]), 'longtext') === 0) { + $s_type[0] = str_replace(" DEFAULT NULL", "", $s_type[0]); + } + $s_type[0] = str_replace(", ", "", $s_type[0]); + $a_tables_ref[$current_table][$s_line[1]] = str_replace(",", "", $s_type[0]); + } + } + } + + // * Get tables from MySQL + $a_tables_db = array(); + $a_tables = array(); + // SHOW TABLES; + $query = "SHOW TABLES LIKE '$filter%'"; + $result = $DB->query($query); + while ($data = $DB->fetch_array($result)) { + $data[0] = str_replace(" COLLATE utf8_unicode_ci", "", $data[0]); + $data[0] = str_replace("( ", "(", $data[0]); + $data[0] = str_replace(" )", ")", $data[0]); + $a_tables[] = $data[0]; + } + + foreach ($a_tables as $table) { + $query = "SHOW CREATE TABLE ".$table; + $result = $DB->query($query); + while ($data=$DB->fetch_array($result)) { + $a_lines = explode("\n", $data['Create Table']); + + foreach ($a_lines as $line) { + if (strstr($line, "CREATE TABLE ") + OR strstr($line, "CREATE VIEW")) { + $matches = array(); + preg_match("/`(.*)`/", $line, $matches); + $current_table = $matches[1]; + } else { + if (preg_match("/^`/", trim($line))) { + $line = preg_replace('/\s+/', ' ', $line); + $s_line = explode("`", $line); + $s_type = explode("COMMENT", $s_line[2]); + $s_type[0] = trim($s_type[0]); + $s_type[0] = str_replace(" COLLATE utf8_unicode_ci", "", $s_type[0]); + $s_type[0] = str_replace(" CHARACTER SET utf8", "", $s_type[0]); + $s_type[0] = str_replace(", ", "", $s_type[0]); + $a_tables_db[$current_table][$s_line[1]] = str_replace(",", "", $s_type[0]); + } + } + } + } + } + + $a_tables_ref_tableonly = array(); + foreach ($a_tables_ref as $table=>$data) { + $a_tables_ref_tableonly[] = $table; + } + $a_tables_db_tableonly = array(); + foreach ($a_tables_db as $table=>$data) { + $a_tables_db_tableonly[] = $table; + } + + // Compare + $tables_toremove = array_diff($a_tables_db_tableonly, $a_tables_ref_tableonly); + $tables_toadd = array_diff($a_tables_ref_tableonly, $a_tables_db_tableonly); + + // See tables missing or to delete + $this->integer(count($tables_toadd))->isEqualTo(0, "Tables missing $when " . print_r($tables_toadd, TRUE)); + $this->integer(count($tables_toremove))->isEqualTo(0, "Tables to delete $when " . print_r($tables_toremove, TRUE)); + + // See if fields are same + foreach ($a_tables_db as $table=>$data) { + if (isset($a_tables_ref[$table])) { + $fields_toremove = array_diff_assoc($data, $a_tables_ref[$table]); + $fields_toadd = array_diff_assoc($a_tables_ref[$table], $data); + $diff = "======= DB ============== Ref =======> ".$table."\n"; + $diff .= print_r($data, TRUE); + $diff .= print_r($a_tables_ref[$table], TRUE); + + // See tables missing or to delete + $this->integer(count($fields_toadd))->isEqualTo(0, "Fields missing/not good during $when $table " . print_r($fields_toadd, TRUE)." into ".$diff); + $this->integer(count($fields_toremove))->isEqualTo(0, "Fields to delete during $when $table " . print_r($fields_toremove, TRUE)." into ".$diff); + } + } + } + +} diff --git a/tests/src/CommonTestCase.php b/tests/src/CommonTestCase.php new file mode 100644 index 000000000..54ac328b9 --- /dev/null +++ b/tests/src/CommonTestCase.php @@ -0,0 +1,157 @@ +drop_database( + $DBvars['dbuser'], + $DBvars['dbhost'], + $DBvars['dbdefault'], + $DBvars['dbpassword'] + ); + + $result = $this->load_mysql_file($DBvars['dbuser'], + $DBvars['dbhost'], + $DBvars['dbdefault'], + $DBvars['dbpassword'], + './save.sql' + ); + } + + protected function resetGLPILogs() { + // Reset error logs + file_put_contents(GLPI_LOG_DIR."/sql-errors.log", ''); + file_put_contents(GLPI_LOG_DIR."/php-errors.log", ''); + } + + protected function setupGLPIFramework() { + global $CFG_GLPI, $DB, $LOADED_PLUGINS, $PLUGIN_HOOKS, $AJAX_INCLUDE, $PLUGINS_INCLUDED; + + if (session_status() == PHP_SESSION_ACTIVE) { + session_write_close(); + } + $LOADED_PLUGINS = null; + $PLUGINS_INCLUDED = null; + $AJAX_INCLUDE = null; + $_SESSION = array(); + if (is_readable(GLPI_ROOT . "/config/config.php")) { + $configFile = "/config/config.php"; + } else { + $configFile = "/inc/config.php"; + } + include (GLPI_ROOT . $configFile); + require (GLPI_ROOT . "/inc/includes.php"); + //\Toolbox::setDebugMode(Session::DEBUG_MODE); + + $DB = new DB(); + + include_once (GLPI_ROOT . "/inc/timer.class.php"); + + // Security of PHP_SELF + $_SERVER['PHP_SELF'] = Html::cleanParametersURL($_SERVER['PHP_SELF']); + + if (session_status() == PHP_SESSION_ACTIVE) { + session_write_close(); + } + ini_set('session.use_cookies', 0); //disable session cookies + session_start(); + $_SESSION['MESSAGE_AFTER_REDIRECT'] = []; + } + + protected function login($name, $password, $noauto = false) { + Session::start(); + $auth = new Auth(); + $result = $auth->login($name, $password, $noauto); + $_SESSION['MESSAGE_AFTER_REDIRECT'] = []; + $this->setupGLPIFramework(); + + return $result; + } + + public function afterTestMethod($method) { + // Check logs + $fileSqlContent = file_get_contents(GLPI_LOG_DIR."/sql-errors.log"); + $filePhpContent = file_get_contents(GLPI_LOG_DIR."/php-errors.log"); + + $class = static::class; + $class = str_replace('\\', '_', $class); + if ($fileSqlContent != '') { + rename(GLPI_LOG_DIR."/sql-errors.log", GLPI_LOG_DIR."/sql-errors__${class}__$method.log"); + } + if ($fileSqlContent != '') { + rename(GLPI_LOG_DIR."/php-errors.log", GLPI_LOG_DIR."/php-errors__${class}__$method.log"); + } + + // Reset log files + self::resetGLPILogs(); + + // Test content + $this->variable($fileSqlContent)->isEqualTo('', 'sql-errors.log not empty'); + $this->variable($filePhpContent)->isEqualTo('', 'php-errors.log not empty'); + } + + protected function loginWithUserToken($userToken) { + // Login as guest user + $_REQUEST['user_token'] = $userToken; + Session::destroy(); + self::login('', '', false); + unset($_REQUEST['user_token']); + } + + /** + * Get a unique random string + */ + protected function getUniqueString() { + if (is_null($this->str)) { + return $this->str = uniqid('str'); + } + return $this->str .= 'x'; + } + + protected function getUniqueEmail() { + return $this->getUniqueString() . "@example.com"; + } + + public function getMockForItemtype($classname, $methods = []) { + // create mock + $mock = $this->getMockBuilder($classname) + ->setMethods($methods) + ->getMock(); + + //Override computation of table to match the original class name + // see CommonDBTM::getTable() + $_SESSION['glpi_table_of'][get_class($mock)] = getTableForItemType($classname); + + return $mock; + } + + protected function terminateSession() { + if (session_status() == PHP_SESSION_ACTIVE) { + session_write_close(); + } + } + + protected function restartSession() { + if (session_status() != PHP_SESSION_ACTIVE) { + session_start(); + session_regenerate_id(); + session_id(); + //$_SESSION["MESSAGE_AFTER_REDIRECT"] = []; + } + } +} diff --git a/tests/suite-install/Config.php b/tests/suite-install/Config.php new file mode 100644 index 000000000..4af3236d5 --- /dev/null +++ b/tests/suite-install/Config.php @@ -0,0 +1,121 @@ +given(self::setupGLPIFramework()) + ->and($this->boolean($DB->connected)->isTrue()) + ->and($this->configureGLPI()) + ->and($this->installDependancies()); + + //Drop plugin configuration if exists + $config = $this->newTestedInstance(); + $config->deleteByCriteria(['context' => $pluginname]); + + // Drop tables of the plugin if they exist + $query = "SHOW TABLES"; + $result = $DB->query($query); + while ($data = $DB->fetch_array($result)) { + if (strstr($data[0], "glpi_plugin_$pluginname") !== false) { + $DB->query("DROP TABLE " . $data[0]); + } + } + + // Reset logs + $this->resetGLPILogs(); + + $plugin = new \Plugin(); + $plugin->getFromDBbyDir($pluginname); + + // Install the plugin + ob_start(function($in) { return ''; }); + $plugin->install($plugin->fields['id']); + ob_end_clean(); + + // Assert the database matches the schema + $filename = GLPI_ROOT."/plugins/$pluginname/install/mysql/plugin_" . $pluginname . "_empty.sql"; + $this->checkInstall($filename, 'glpi_plugin_' . $pluginname . '_', 'install'); + + // Enable the plugin + $plugin->activate($plugin->fields['id']); + $this->boolean($plugin->isActivated($pluginname))->isTrue('Cannot enable the plugin'); + + // Enable debug mode for enrollment messages + \Config::setConfigurationValues($pluginname, ['debug_enrolment' => '1']); + + // Take a snapshot of the database before any test + $this->mysql_dump($DB->dbuser, $DB->dbhost, $DB->dbpassword, $DB->dbdefault, './save.sql'); + + $this->boolean(file_exists("./save.sql"))->isTrue(); + $filestats = stat("./save.sql"); + $length = $filestats[7]; + $this->integer($length)->isGreaterThan(0); + } + + /** + * Configure GLPI to isntall the plugin + */ + private function configureGLPI() { + global $CFG_GLPI; + + $settings = [ + 'use_notifications' => '1', + 'notifications_mailing' => '1', + 'enable_api' => '1', + 'enable_api_login_credentials' => '1', + 'enable_api_login_external_token' => '1', + ]; + \Config::setConfigurationValues('core', $settings); + + $CFG_GLPI = $settings + $CFG_GLPI; + + $settings = [ + 'mqtt_broker_port' => '1884', + ]; + \Config::setConfigurationValues('flyvemdm', $settings); + } + + /** + * install requirements for the plugin + */ + private function installDependancies() { + } + +} diff --git a/tests/suite-integration/PluginFormcreatorForm.php b/tests/suite-integration/PluginFormcreatorForm.php new file mode 100644 index 000000000..64a434f3e --- /dev/null +++ b/tests/suite-integration/PluginFormcreatorForm.php @@ -0,0 +1,477 @@ +add(['name' => "test export form", + 'is_active' => true, + 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER]); + + $sections_id = $form_section->add(['name' => "test export section", + 'plugin_formcreator_forms_id' => $forms_id]); + + $questions_id_1 = $form_question->add(['name' => "test export question 1", + 'fieldtype' => 'text', + 'plugin_formcreator_sections_id' => $sections_id]); + $questions_id_2 = $form_question->add(['name' => "test export question 2", + 'fieldtype' => 'textarea', + 'plugin_formcreator_sections_id' => $sections_id]); + + $form_condition->add(['plugin_formcreator_questions_id' => $questions_id_1, + 'show_field' => $questions_id_2, + 'show_condition' => '==', + 'show_value' => 'test']); + + $form_validator->add(['plugin_formcreator_forms_id' => $forms_id, + 'itemtype' => 'User', + 'items_id' => 2]); + $form_validator->add(['plugin_formcreator_forms_id' => $forms_id, + 'itemtype' => 'User', + 'items_id' => 3]); + + $targets_id = $form_target->add(['plugin_formcreator_forms_id' => $forms_id, + 'itemtype' => \PluginFormcreatorTargetTicket::class, + 'name' => "test export target"]); + + $targetTicket_id = $targetTicket->add(['name' => $form_target->getField('name'), + ]); + + $form_target->getFromDB($targets_id); + $targettickets_id = $form_target->fields['items_id']; + + $form_profiles_id = $form_profile->add(['plugin_formcreator_forms_id' => $forms_id, + 'profiles_id' => 1]); + + $item_targetTicket->add(['plugin_formcreator_targettickets_id' => $targetTicket_id, + 'link' => \Ticket_Ticket::LINK_TO, + 'itemtype' => $form_target->getField('itemtype'), + 'items_id' => $targets_id + ]); + } + + public function beforeTestMethod($method) { + switch ($method) { + case 'testExportImportForm': + case 'testDuplicateForm': + $_SESSION['glpiactive_entity'] = 0; + break; + } + } + + /** + * @cover PluginFormcreatorForm::export + */ + public function testExportImportForm() { + // Export the form + $form = new \PluginFormcreatorForm; + plugin_formcreator_getFromDBByField($form, 'name', "test export form"); + $this->boolean($form->isNewItem())->isFalse(); + $export = $form->export(); + + $this->array($export)->notHasKeys([ + 'id', + 'plugin_formcreator_categories_id', + 'entities_id', + 'usage_count', + ])->hasKeys([ + 'is_recursive', + 'access_rights', + 'is_recursive', + 'access_rights', + 'requesttype', + 'name', + 'description', + 'content', + 'is_active', + 'language', + 'helpdesk_home', + 'is_deleted', + 'validation_required', + 'is_default', + 'uuid', + '_sections', + '_validators', + '_targets', + '_profiles', + ]); + + foreach ($export["_sections"] as $section) { + $this->_checkSection($section); + } + + foreach ($export["_validators"] as $validator) { + $this->_checkValidator($validator); + } + + foreach ($export["_targets"] as $target) { + $this->_checkTarget($target); + } + + foreach ($export["_profiles"] as $form_profile) { + $this->checkFormProfile($form_profile); + } + + // Test import form + $forms_id = \PluginFormcreatorForm::import($export); + + $this->variable($forms_id)->isNotFalse(); + } + + public function testExportImportSection() { + // Export a section + $section = new \PluginFormcreatorSection; + plugin_formcreator_getFromDBByField($section, 'name', "test export section"); + $export = $section->export(); + $this->_checkSection($export); + + // Import a section + $form = new \PluginFormcreatorForm; + plugin_formcreator_getFromDBByField($form, 'name', "test export form"); + $sections_id = \PluginFormcreatorSection::import($form->getID(), $export); + $this->variable($sections_id)->isNotFalse(); + } + + public function testExportImportQuestion() { + // Export a question + $question = new \PluginFormcreatorQuestion; + plugin_formcreator_getFromDBByField($question, 'name', "test export question 1"); + $export = $question->export(); + $this->_checkQuestion($export); + + plugin_formcreator_getFromDBByField($question, 'name', "test export question 2"); + $export = $question->export(); + $this->_checkQuestion($export); + + // Import a question + $section = new \PluginFormcreatorSection; + plugin_formcreator_getFromDBByField($section, 'name', "test export section"); + $questions_id = \PluginFormcreatorQuestion::import($section->getID(), $export); + $this->variable($questions_id)->isNotFalse(); + } + + public function testExportImportTarget() { + // Export a target + $target = new \PluginFormcreatorTarget; + plugin_formcreator_getFromDBByField($target, 'name', "test export target"); + $export = $target->export(); + $this->_checkTarget($export); + + // Import a target + $form = new \PluginFormcreatorForm; + plugin_formcreator_getFromDBByField($form, 'name', "test export form"); + $targets_id = \PluginFormcreatorTarget::import($form->getID(), $export); + + $this->variable($targets_id)->isNotFalse(); + + return $targets_id; + } + + public function _checkSection($section = []) { + $keys = [ + 'name', + 'order', + 'uuid', + '_questions', + ]; + $this->array($section)->notHasKeys([ + 'id', + 'plugin_formcreator_forms_id', + ]); + $this->array($section) + ->hasKeys($keys) + ->size->isEqualTo(count($keys)); + + foreach ($section["_questions"] as $question) { + $this->_checkQuestion($question); + } + } + + public function _checkQuestion($question = []) { + $keys = [ + 'fieldtype', + 'name', + 'required', + 'show_empty', + 'default_values', + 'values', + 'range_min', + 'range_max', + 'description', + 'regex', + 'order', + 'show_rule', + 'uuid', + '_conditions', + ]; + + $this->array($question)->notHasKeys([ + 'id', + 'plugin_formcreator_sections_id', + ])->hasKeys($keys) + ->size->isEqualTo(count($keys));; + + foreach ($question["_conditions"] as $condition) { + $this->_checkCondition($condition); + } + } + + public function _checkCondition($condition = []) { + $keys = [ + 'show_field', + 'show_condition', + 'show_value', + 'show_logic', + 'order', + 'uuid', + ]; + + $this->array($condition)->notHasKeys([ + 'id', + 'plugin_formcreator_questions_id', + ])->hasKeys($keys) + ->size->isEqualTo(count($keys)); + } + + public function _checkValidator($validator = []) { + $this->array($validator)->notHasKeys([ + 'id', + 'plugin_formcreator_forms_id', + 'items_id', + ])->hasKeys([ + 'itemtype', + '_item', + 'uuid', + ]); + } + + public function _checkTarget($target = []) { + $this->array($target)->notHasKeys([ + 'id', + 'plugin_formcreator_forms_id', + 'items_id', + ])->hasKeys([ + 'itemtype', + '_data', + 'uuid', + ]); + $this->array($target['_data'])->hasKeys(['_actors']); + + if ($target['itemtype'] === \PluginFormcreatorTargetTicket::class) { + $this->_checkTargetTicket($target['_data']); + } + + foreach ($target["_data"]['_actors'] as $actor) { + $this->_checkActor($actor); + } + } + + public function _checkTargetTicket($targetticket = []) { + $keys = [ + 'title', + 'comment', + 'due_date_rule', + 'due_date_question', + 'due_date_value', + 'due_date_period', + 'urgency_rule', + 'urgency_question', + 'location_rule', + 'location_question', + 'validation_followup', + 'destination_entity', + 'destination_entity_value', + 'tag_type', + 'tag_questions', + 'tag_specifics', + 'category_rule', + 'category_question', + '_actors', + '_ticket_relations', + ]; + $this->array($targetticket)->notHasKeys([ + 'id', + 'tickettemplates_id', + ])->hasKeys($keys) + ->size->isEqualTo(count($keys)); + } + + public function _checkActor($actor = []) { + $this->array($actor)->notHasKeys([ + 'id', + 'plugin_formcreator_targettickets_id', + ])->hasKeys([ + 'use_notification', + 'uuid', + ]); + //we should have only one of theses keys : actor_value ,_question ,_user ,_group ,_supplier + $actor_value_found_keys = preg_grep('/((actor_value)|(_question)|(_user)|(_group)|(_supplier))/', + array_keys($actor)); + $this->array($actor_value_found_keys)->size->isEqualTo(1); + + } + + public function checkFormProfile($form_profile = []) { + $this->array($form_profile)->notHasKeys([ + 'id', + 'plugin_formcreator_forms_id', + 'profiles_id' + ])->hasKeys([ + '_profile', + 'uuid', + ]); + } + + public function testDuplicateForm() { + $formData = [ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'name' => 'a form', + 'description' => 'form description', + 'content' => 'a content', + 'is_active' => 1, + 'validation_required' => 0 + ]; + + $sectionData = [ + [ + 'name' => 'a section', + 'questions' => [ + [ + 'name' => 'text question', + 'fieldtype' => 'text' + ], + [ + 'name' => 'other text question', + 'fieldtype' => 'text' + ], + ], + ], + [ + 'name' => 'an other section', + 'questions' => [ + [ + 'name' => 'text question', + 'fieldtype' => 'text' + ], + [ + 'name' => 'other text question', + 'fieldtype' => 'text', + 'show_rule' => 'hidden', + 'show_field' => 'text question', + 'show_condition' => '==', + 'show_value' => 'azerty', + ], + ], + ], + ]; + + $targetData = [ + [ + 'name' => 'target ticket 1', + 'itemtype' => 'PluginFormcreatorTargetTicket', + ], + [ + 'name' => 'target ticket 2', + 'itemtype' => 'PluginFormcreatorTargetTicket', + ] + ]; + + $form = new \PluginFormcreatorForm(); + $formId = $form->add($formData); + $this->boolean($form->isNewItem())->isFalse(); + + foreach ($sectionData as $sectionData) { + // Keep questions data set apart from sections data + $questionsData = $sectionData['questions']; + unset($sectionData['questions']); + + // Create section + $sectionData['plugin_formcreator_forms_id'] = $form->getID(); + $section = new \PluginFormcreatorSection(); + $section->add($sectionData); + $this->boolean($section->isNewItem())->isFalse(); + $sectionId = $section->getID(); + foreach ($questionsData as $questionData) { + // Create question + $questionData ['plugin_formcreator_sections_id'] = $section->getID(); + $question = new \PluginFormcreatorQuestion(); + $question->add($questionData); + $this->boolean($question->isNewItem(), $_SESSION['MESSAGE_AFTER_REDIRECT'])->isFalse(); + + $questionData['id'] = $question->getID(); + if (isset($questionData['show_rule']) && $questionData['show_rule'] != 'always') { + $showFieldName = $questionData['show_field']; + $showfield = new \PluginFormcreatorQuestion(); + $showfield->getFromDBByCrit([ + 'AND' => [ + 'plugin_formcreator_sections_id' => $sectionId, + 'name' => $showFieldName + ] + ]); + $questionData['show_field'] = $showfield->getID(); + $question->updateConditions($questionData); + } + } + foreach ($targetData as $targetDataItem) { + $target = new \PluginFormcreatorTarget(); + $targetDataItem['plugin_formcreator_forms_id'] = $formId; + $target->add($targetDataItem); + $this->boolean($target->isNewItem())->isFalse(); + } + } + + $sourceFormId = $form->getID(); + $this->boolean($form->duplicate())->isTrue(); + + // Check the ID of the form changed + $newFormId = $form->getID(); + $this->integer((int) $newFormId)->isNotEqualTo($sourceFormId); + + // Check sections were copied + $section = new \PluginFormcreatorSection(); + $sourceRows = $section->find("`plugin_formcreator_forms_id` = '$sourceFormId'"); + $newRows = $section->find("`plugin_formcreator_forms_id` = '$newFormId'"); + $this->integer(count($newRows))->isEqualTo(count($sourceRows)); + + // Check questions were copied + $table_section = \PluginFormcreatorSection::getTable(); + $question = new \PluginFormcreatorQuestion(); + $sourceRows = $question->find("`plugin_formcreator_sections_id` IN ( + SELECT `id` FROM `$table_section` WHERE `$table_section`.`plugin_formcreator_forms_id` = '$sourceFormId' + )"); + $newRows = $question->find("`plugin_formcreator_sections_id` IN ( + SELECT `id` FROM `$table_section` WHERE `$table_section`.`plugin_formcreator_forms_id` = '$newFormId' + )"); + $this->integer(count($newRows))->isEqualTo(count($sourceRows)); + + // check target were created + $target = new \PluginFormcreatorTarget(); + $sourceRows = $target->find("`plugin_formcreator_forms_id` = '$sourceFormId'"); + $newRows = $target->find("`plugin_formcreator_forms_id` = '$sourceFormId'"); + $this->integer(count($newRows))->isEqualTo(count($sourceRows)); + + // check target tickets were created + foreach ($newRows as $targetId => $newTarget) { + if ($newTarget['itemtype'] == 'PluginFormcreatorTargetTicket') { + $targetTicket = new \PluginFormcreatorTArgetTicket(); + $targetTicket->getFromDB($newTarget['items_id']); + $this->boolean($targetTicket->isNewItem())->isFalse(); + } + } + } +} \ No newline at end of file diff --git a/tests/suite-integration/PluginFormcreatorForm_Answer.php b/tests/suite-integration/PluginFormcreatorForm_Answer.php new file mode 100644 index 000000000..57fd376f1 --- /dev/null +++ b/tests/suite-integration/PluginFormcreatorForm_Answer.php @@ -0,0 +1,169 @@ +boolean(self::login('glpi', 'glpi', true))->isTrue(); + break; + } + } + + public function afterTestMethod($method) { + parent::afterTestMethod($method); + switch ($method) { + case 'testNotificationFormAnswerCreated': + $user = new \User(); + $user->getFromDBbyName('glpi'); + $userEmail = new \Useremail(); + $userEmail->deleteByCriteria([ + 'users_id' => $user->getID(), + ]); + break; + } + } + + public function testNotificationFormAnswerCreated() { + global $DB, $CFG_GLPI; + + $user = new \User(); + $user->getFromDBbyName('glpi'); + $user->update([ + 'id' => $user->getID(), + '_useremails' => ['glpi@localhost.local'], + ]); + + \config::setConfigurationValues('core', ['notifications_mailing' => '1']); + $CFG_GLPI['notifications_mailing'] = '1'; + + $form = new \PluginFormcreatorForm(); + $form->add([ + 'name' => __METHOD__, + 'validation_required' => '0' + ]); + $this->boolean($form->isNewItem())->isFalse(); + + // Answer the form + $form->saveForm(['formcreator_form' => $form->getID()]); + + // Check a notification was created with the expected template + $result = $DB->request([ + 'SELECT' => \Notification_NotificationTemplate::getTable() . '.' . \NotificationTemplate::getForeignKeyField(), + 'FROM' => \Notification_NotificationTemplate::getTable(), + 'INNER JOIN' => [ + \Notification::getTable() => [ + 'FKEY' => [ + \Notification::getTable() => 'id', + \Notification_NotificationTemplate::getTable() => \Notification::getForeignKeyField() + ] + ] + ], + 'WHERE' => [ + 'itemtype' => \PluginFormcreatorForm_Answer::class, + 'event' => 'plugin_formcreator_form_created', + ] + ]); + $this->integer($result->count())->isEqualTo(1); + $row = $result->next(); + + $formAnswer = new \PluginFormcreatorForm_Answer(); + $formAnswer->getFromDBByCrit([ + 'plugin_formcreator_forms_id' => $form->getID(), + ]); + $this->boolean($formAnswer->isNewItem())->isFalse(); + $queued = new \QueuedNotification(); + $queued->getFromDBByCrit([ + \NotificationTemplate::getForeignKeyField() => $row[\NotificationTemplate::getForeignKeyField()], + 'itemtype' => \PluginFormcreatorForm_Answer::class, + 'items_id' => $formAnswer->getID(), + ]); + + // Check the notification is linked to the expected itemtype + $this->boolean($queued->isNewItem())->isFalse(); + } + + public function testOtherUserValidates() { + global $DB; + + $form = new \PluginFormcreatorForm(); + $form->add([ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'name' => __METHOD__, + 'description' => 'form description', + 'content' => 'a content', + 'is_active' => 1, + 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER, + ]); + $this->boolean($form->isNewItem())->isFalse(); + + $section = new \PluginFormcreatorSection(); + $section->add([ + 'name' => 'a section', + 'plugin_formcreator_forms_id' => $form->getID() + ]); + $this->boolean($section->isNewItem())->isFalse(); + + $formValidator = new \PluginFormcreatorForm_Validator(); + $formValidator->add([ + 'itemtype' => 'User', + 'users_id' => '2', // user is glpi + 'plugin_formcreator_forms_id' => $form->getID() + ]); + $this->boolean($formValidator->isNewItem())->isFalse(); + + $formAnswer = new \PluginFormcreatorForm_Answer(); + $formAnswer_table = \PluginFormcreatorForm_Answer::getTable(); + + $result = $DB->query("SELECT MAX(`id`) AS `max_id` FROM `$formAnswer_table`"); + $maxId = $DB->fetch_assoc($result); + $maxId = $maxId['max_id']; + $maxId === null ? 0 : $maxId; + + $form->saveForm([ + 'formcreator_form' => $form->getID(), + 'status' => 'waiting', + 'formcreator_validator' => $_SESSION['glpiID'], + ]); + + $result = $DB->query("SELECT MAX(`id`) AS `max_id` FROM `$formAnswer_table`"); + $newId = $DB->fetch_assoc($result); + $newId = $newId['max_id']; + + $this->integer((int) $newId)->isGreaterThan((int) $maxId); + $formAnswer->getFromDB($newId); + $this->boolean($formAnswer->isNewItem())->isFalse(); + + $login = $this->getUniqueString(); + $user = new \User(); + $user->add([ + 'name' => $login, + 'password' => 'superadmin', + 'password2' => 'superadmin', + '_profiles_id' => '4', + '_entities_id' => 0, + '_is_recursive' => 1, + ]); + $this->boolean($user->isNewItem()) + ->isFalse(json_encode( + $_SESSION['MESSAGE_AFTER_REDIRECT'], + JSON_PRETTY_PRINT)); + + // Login as other user + $this->boolean(self::login($login, 'superadmin', true))->isTrue(); + + $this->boolean($formAnswer->canValidate($form, $formAnswer))->isFalse(); + + // Login as glpi + $this->boolean(self::login('glpi', 'glpi', true))->istrue(); + + $this->boolean($formAnswer->canValidate($form, $formAnswer))->isTrue(); + } +} \ No newline at end of file diff --git a/tests/suite-integration/PluginFormcreatorForm_Validator.php b/tests/suite-integration/PluginFormcreatorForm_Validator.php new file mode 100644 index 000000000..be14952cb --- /dev/null +++ b/tests/suite-integration/PluginFormcreatorForm_Validator.php @@ -0,0 +1,65 @@ +boolean(self::login('glpi', 'glpi', true))->isTrue(); + break; + } + } + + public function testCreateFormForGroup() { + $group = new \Group(); + $groupId = $group->import([ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'completename' => 'a group', + ]); + + $group->getFromDB($groupId); + $this->boolean($group->isNewItem())->isFalse(); + + $form = new \PluginFormcreatorForm(); + $formId = $form->add([ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'name' => 'a form for group validator', + 'description' => 'form description', + 'content' => 'a content', + 'is_active' => 1, + 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_GROUP, + '_validator_groups' => [$group->getID()] + ]); + $this->boolean($form->isNewItem())->isFalse(); + + $form_validator = new \PluginFormcreatorForm_Validator(); + $form_validator->getFromDBForItems($form, $group); + $this->boolean($form_validator->isNewItem())->isFalse(); + } + + public function testCreateFormForUser() { + $user = new \User; + $user->getFromDBbyName('tech'); + $this->boolean($user->isNewItem())->isFalse(); + + $form = new \PluginFormcreatorForm(); + $formId = $form->add([ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'name' => 'a form for user validator', + 'description' => 'form description', + 'content' => 'a content', + 'is_active' => 1, + 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER, + '_validator_users' => [$user->getID()] + ]); + $this->boolean($form->isNewItem())->isFalse(); + + $form_validator = new \PluginFormcreatorForm_Validator(); + $form_validator->getFromDBForItems($form, $user); + $this->boolean($form_validator->isNewItem())->isFalse(); + } +} \ No newline at end of file diff --git a/tests/suite-integration/PluginFormcreatorQuestion.php b/tests/suite-integration/PluginFormcreatorQuestion.php new file mode 100644 index 000000000..98f8311dc --- /dev/null +++ b/tests/suite-integration/PluginFormcreatorQuestion.php @@ -0,0 +1,102 @@ +login('glpi', 'glpi'); + break; + } + } + + public function testCreateQuestionText() { + $this->formData = [ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'name' => 'a form', + 'description' => 'form description', + 'content' => 'a content', + 'is_active' => 1, + 'validation_required' => 0 + ]; + + $this->sectionData = [ + 'name' => 'a section', + ]; + + $this->questionTextData = [ + 'name' => 'text question', + 'fieldtype' => 'text' + ]; + + $form = new \PluginFormcreatorForm(); + $form->add($this->formData); + $this->boolean($form->isNewItem())->isFalse(); + + $section = new \PluginFormcreatorSection(); + $this->sectionData = $this->sectionData + [ + 'plugin_formcreator_forms_id' => $form->getID() + ]; + $section->add($this->sectionData); + $this->boolean($section->isNewItem())->isFalse(); + + $question = new \PluginFormcreatorQuestion(); + $this->questionTextData = $this->questionTextData + ['plugin_formcreator_sections_id' => $section->getID()]; + $question->add($this->questionTextData); + $this->boolean($question->isNewItem())->isFalse(); + + return $question; + } + + public function testCloneQuestion() { + $form = new \PluginFormcreatorForm; + $section = new \PluginFormcreatorSection; + $question = new \PluginFormcreatorQuestion; + + // create objects + $forms_id = $form->add(['name' => "test clone form", + 'is_active' => true, + 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER]); + + $sections_id = $section->add(['name' => "test clone section", + 'plugin_formcreator_forms_id' => $forms_id]); + + $questions_id_1 = $question->add(['name' => "test clone question 1", + 'fieldtype' => 'text', + 'plugin_formcreator_sections_id' => $sections_id, + '_parameters' => [ + 'text' => [ + 'regex' => '', + 'range' => ['min' => '', 'max' => ''], + ] + ], + ]); + $new_question = new PluginFormcreatorQuestion; + + //get question + plugin_formcreator_getFromDBByField($question, 'name', "test clone question 1"); + + //clone it + $this->boolean($question->duplicate())->isTrue(); + + //get cloned section + $originalId = $question->getID(); + $new_question->getFromDBByCrit([ + 'AND' => [ + 'name' => 'test clone question 1', + 'NOT' => ['uuid' => $question->getField('uuid')], // operator <> available in GLPI 9.3+ only + 'plugin_formcreator_sections_id' => $question->getField('plugin_formcreator_sections_id') + ] + ]); + $this->boolean($new_question->isNewItem())->isFalse(); + } +} \ No newline at end of file diff --git a/tests/suite-integration/PluginFormcreatorSection.php b/tests/suite-integration/PluginFormcreatorSection.php new file mode 100644 index 000000000..8b2b8f524 --- /dev/null +++ b/tests/suite-integration/PluginFormcreatorSection.php @@ -0,0 +1,135 @@ +login('glpi', 'glpi'); + $this->form = new \PluginFormcreatorForm(); + $this->form->add([ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'name' => $method . ' ' . $this->getUniqueString(), + 'description' => 'form description', + 'content' => 'a content', + 'is_active' => 1, + 'validation_required' => 0 + ]); + break; + + case 'testDuplicate': + $this->login('glpi', 'glpi'); + break; + } + } + + public function testAdd() { + $instance = new \PluginFormcreatorSection(); + $instance->add([ + 'plugin_formcreator_forms_id' => $this->form->getID(), + 'name' => $this->getUniqueString() + ]); + $this->boolean($instance->isNewItem())->isFalse(); + } + + public function testUpdate() { + $instance = new \PluginFormcreatorSection(); + $instance->add([ + 'plugin_formcreator_forms_id' => $this->form->getID(), + 'name' => $this->getUniqueString() + ]); + $this->boolean($instance->isNewItem())->isFalse(); + + $success = $instance->update([ + 'id' => $instance->getID(), + 'name' => 'section renamed' + ]); + $this->boolean($success)->isTrue(); + } + + public function testDelete() { + $instance = new \PluginFormcreatorSection(); + $instance->add([ + 'plugin_formcreator_forms_id' => $this->form->getID(), + 'name' => $this->getUniqueString() + ]); + $this->boolean($instance->isNewItem())->isFalse(); + + $success = $instance->delete([ + 'id' => $instance->getID() + ], 1); + $this->boolean($success)->isTrue(); + } + + /** + * + */ + public function testDuplicate() { + $form = new \PluginFormcreatorForm; + $section = new \PluginFormcreatorSection; + $question = new \PluginFormcreatorQuestion; + + // create objects + $forms_id = $form->add(['name' => "test clone form", + 'is_active' => true, + 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER]); + + $sections_id = $section->add(['name' => "test clone section", + 'plugin_formcreator_forms_id' => $forms_id]); + + $questions_id_1 = $question->add(['name' => "test clone question 1", + 'fieldtype' => 'text', + 'plugin_formcreator_sections_id' => $sections_id, + '_parameters' => [ + 'text' => [ + 'regex' => '', + 'range' => ['min' => '', 'max' => ''], + ] + ], + ]); + $questions_id_2 = $question->add(['name' => "test clone question 2", + 'fieldtype' => 'textarea', + 'plugin_formcreator_sections_id' => $sections_id + ]); + + //clone it + $this->boolean($section->duplicate())->isTrue(); + + //get cloned section + $originalId = $section->getID(); + $new_section = new \PluginFormcreatorSection; + $new_section->getFromDBByCrit([ + 'AND' => [ + 'name' => 'test clone section', + 'NOT' => ['uuid' => $section->getField('uuid')], // operator <> available in GLPI 9.3+ only + 'plugin_formcreator_forms_id' => $section->getField('plugin_formcreator_forms_id') + ] + ]); + $this->boolean($new_section->isNewItem())->isFalse(); + + // check questions + $all_questions = $form_question->find("plugin_formcreator_sections_id = ".$section->getID()); + $all_new_questions = $form_question->find("plugin_formcreator_sections_id = ".$new_section->getID()); + $this->integer(count($all_new_questions))->isEqualTo(count($all_questions)); + + // check that all question uuid are new + $uuids = $new_uuids = []; + foreach ($all_questions as $question) { + $uuids[] = $question['uuid']; + } + foreach ($all_new_questions as $question) { + $new_uuids[] = $question['uuid']; + } + $this->integer(count(array_diff($new_uuids, $uuids)))->isEqualTo(count($new_uuids); + } +} diff --git a/tests/suite-integration/PluginFormcreatorTargetChange.php b/tests/suite-integration/PluginFormcreatorTargetChange.php new file mode 100644 index 000000000..60355f31f --- /dev/null +++ b/tests/suite-integration/PluginFormcreatorTargetChange.php @@ -0,0 +1,68 @@ +login('glpi', 'glpi'); + } + + public function testTargetTicketActors() { + $form = new \PluginFormcreatorForm(); + $form->add([ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'name' => 'a form', + 'description' => 'form description', + 'content' => 'a content', + 'is_active' => 1, + 'validation_required' => 0 + ]); + $this->boolean($form->isNewItem())->isFalse(); + + $target = new \PluginFormcreatorTarget(); + $target->add([ + 'name' => 'a target', + 'itemtype' => \PluginFormcreatorTargetChange::class, + 'plugin_formcreator_forms_id' => $form->getID() + ]); + $this->boolean($target->isNewItem())->isFalse(); + $this->integer((int) $target->getField('plugin_formcreator_forms_id')) + ->isEqualTo((int) $form->getID()); + $this->string($target->getField('itemtype')) + ->isEqualTo(\PluginFormcreatorTargetChange::class); + + $targetChange = $target->getField('items_id'); + $targetChange = new \PluginFormcreatorTargetChange(); + $targetChange->getFromDB($target->getField('items_id')); + $this->boolean($targetChange->isNewItem())->isFalse(); + $this->string($targetChange->getField('name')) + ->isEqualTo($target->getField('name')); + + $requesterActor = new \PluginFormcreatorTargetChange_Actor(); + $observerActor = new \PluginFormcreatorTargetChange_Actor(); + $targetChangeId = $targetChange->getID(); + + $requesterActor->getFromDBByCrit([ + 'AND' => [ + 'plugin_formcreator_targetchanges_id' => $targetChangeId, + 'actor_role' => 'requester', + 'actor_type' => 'creator' + ] + ]); + $observerActor->getFromDBByCrit([ + 'AND' => [ + 'plugin_formcreator_targetchanges_id' => $targetChangeId, + 'actor_role' => 'observer', + 'actor_type' => 'validator' + ] + ]); + + $this->boolean($requesterActor->isNewItem())->isFalse(); + $this->boolean($observerActor->isNewItem())->isFalse(); + $this->integer((int) $requesterActor->getField('use_notification'))->isEqualTo(1); + $this->integer((int) $observerActor->getField('use_notification'))->isEqualTo(1); + } +} \ No newline at end of file diff --git a/tests/suite-integration/PluginFormcreatorTargetTicket.php b/tests/suite-integration/PluginFormcreatorTargetTicket.php new file mode 100644 index 000000000..4320a04f8 --- /dev/null +++ b/tests/suite-integration/PluginFormcreatorTargetTicket.php @@ -0,0 +1,258 @@ +login('glpi', 'glpi'); + } + + public function testTargetTicketActors() { + $form = new \PluginFormcreatorForm(); + $form->add([ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'name' => __METHOD__, + 'description' => 'form description', + 'content' => 'a content', + 'is_active' => 1, + 'validation_required' => 0 + ]); + $this->boolean($form->isNewItem())->isFalse(); + + $target = new \PluginFormcreatorTarget(); + $target->add([ + 'name' => 'a target', + 'itemtype' => \PluginFormcreatorTargetTicket::class, + 'plugin_formcreator_forms_id' => $form->getID() + ]); + $this->boolean($target->isNewItem())->isFalse(); + $this->integer((int) $target->getField('plugin_formcreator_forms_id')) + ->isEqualTo((int) $form->getID()); + $this->string($target->getField('itemtype')) + ->isEqualTo(\PluginFormcreatorTargetTicket::class); + + $targetTicket = $target->getField('items_id'); + $targetTicket = new \PluginFormcreatorTargetTicket(); + $targetTicket->getFromDB($target->getField('items_id')); + $this->boolean($targetTicket->isNewItem())->isFalse(); + $this->string($targetTicket + ->getField('name')) + ->isEqualTo($target->getField('name')); + + $requesterActor = new \PluginFormcreatorTargetTicket_Actor(); + $observerActor = new \PluginFormcreatorTargetTicket_Actor(); + $targetTicketId = $targetTicket->getID(); + + $requesterActor->getFromDBByCrit([ + 'AND' => [ + 'plugin_formcreator_targettickets_id' => $targetTicketId, + 'actor_role' => 'requester', + 'actor_type' => 'creator' + ] + ]); + $observerActor->getFromDBByCrit([ + 'AND' => [ + 'plugin_formcreator_targettickets_id' => $targetTicketId, + 'actor_role' => 'observer', + 'actor_type' => 'validator' + ] + ]); + + $this->boolean($requesterActor->isNewItem())->isFalse(); + $this->boolean($observerActor->isNewItem())->isFalse(); + $this->integer((int) $requesterActor->getField('use_notification')) + ->isEqualTo(1); + $this->integer((int) $observerActor->getField('use_notification')) + ->isEqualTo(1); + } + + public function testUrgency() { + $form = new \PluginFormcreatorForm(); + $formId = $form->add([ + 'entities_id' => $_SESSION['glpiactive_entity'], + 'name' => __METHOD__, + 'description' => 'form description', + 'content' => 'a content', + 'is_active' => 1, + 'validation_required' => 0 + ]); + $this->boolean($form->isNewItem())->isFalse(); + + $sectionsData = [ + [ + 'name' => 'a section', + 'questions' => [ + [ + 'name' => 'text question', + 'fieldtype' => 'text' + ], + [ + 'name' => 'custom urgency', + 'fieldtype' => 'urgency' + ], + ], + ], + ]; + foreach ($sectionsData as $sectionData) { + // Keep questions data set apart from sections data + $questionsData = $sectionData['questions']; + unset($sectionData['questions']); + + // Create section + $sectionData['plugin_formcreator_forms_id'] = $form->getID(); + $section = new \PluginFormcreatorSection(); + $section->add($sectionData); + $this->boolean($section->isNewItem())->isFalse(); + $sectionId = $section->getID(); + foreach ($questionsData as $questionData) { + // Create question + $questionData ['plugin_formcreator_sections_id'] = $section->getID(); + $question = new \PluginFormcreatorQuestion(); + $question->add($questionData); + $this->boolean($question->isNewItem())->isFalse($_SESSION['MESSAGE_AFTER_REDIRECT']); + + $questionData['id'] = $question->getID(); + if (isset($questionData['show_rule']) && $questionData['show_rule'] != 'always') { + $showFieldName = $questionData['show_field']; + $showfield = new \PluginFormcreatorQuestion(); + $showfield->getFromDBByCrit([ + 'AND' => [ + 'plugin_formcreator_sections_id' => $sectionId, + 'name' => $showFieldName + ] + ]); + $question->updateConditions($questionData); + } + } + } + + $urgencyQuestions = []; + $formId = $form->getID(); + $targetTicketsData = [ + [ + 'name' => 'target 1', + 'itemtype' => 'PluginFormcreatorTargetTicket', + 'urgency_rule' => 'answer', + 'urgency_question' => 'custom urgency', + 'expected' => 5 + ], + [ + 'name' => 'target 2', + 'itemtype' => 'PluginFormcreatorTargetTicket', + 'urgency_rule' => 'none', + 'urgency_question' => '', + 'expected' => 3 + ] + ]; + foreach ($targetTicketsData as $targetData) { + // Create target + $targetData['plugin_formcreator_forms_id'] = $formId; + $target = new \PluginFormcreatorTarget(); + $target->add($targetData); + $this->boolean($target->isNewItem())->isFalse(); + + // Create target ticket + $itemtype = $target->getField('itemtype'); + $targetTicket = new $itemtype(); + $targetTicket->getFromDB($target->getField('items_id')); + $this->boolean($targetTicket->isNewItem())->isFalse(); + + // Find urgency question + if (!empty($targetData['urgency_question'])) { + $questionName = $targetData['urgency_question']; + $question = new \PluginFormcreatorQuestion(); + $table_section = \PluginFormcreatorSection::getTable(); + $table_form = \PluginFormcreatorForm::getTable(); + $table_question = \PluginFormcreatorQuestion::getTable(); + if (!method_exists($question, 'getFromDBByRequest')) { + $question->getFromDBByQuery("LEFT JOIN `$table_section` `s` ON (`s`.`id` = `plugin_formcreator_sections_id`) + LEFT JOIN `$table_form` `f` ON (`f`.`id` = `s`.`plugin_formcreator_forms_id`) + WHERE `$table_question`.`name` = '$questionName' AND `plugin_formcreator_forms_id` = '$formId'"); + } else { + $question->getFromDBByRequest([ + 'LEFT JOIN' => [ + \PluginFormcreatorSection::getTable() => [ + 'FKEY' => [ + \PluginFormcreatorSection::getTable() => 'id', + \PluginFormcreatorQuestion::getTable() => \PluginFormcreatorSection::getForeignKeyField() + ] + ], + \PluginFormcreatorForm::getTable() => [ + 'FKEY' => [ + \PluginFormcreatorForm::getTable() => 'id', + \PluginFormcreatorSection::getTable() => \PluginFormcreatorForm::getForeignKeyField() + ] + ] + ], + 'WHERE' => [ + 'AND' => [ + \PluginFormcreatorQuestion::getTable() . '.name' => $questionName, + \PluginFormcreatorForm::getForeignKeyField() => $formId, + ] + ] + ]); + } + $this->boolean($question->isNewItem())->isFalse(); + $questionId = $question->getID(); + $urgencyQuestions[] = [ + 'question' => $question, + 'targetTicket' => $targetTicket, + 'expected' => $targetData['expected'] + ]; + } else { + $urgencyQuestions[] = [ + 'question' => null, + 'targetTicket' => $targetTicket, + 'expected' => $targetData['expected'] + ]; + } + + // Update target ticket + $targetTicketData = $targetTicket->fields; + $targetTicketData['id'] = $targetTicket->getID(); + $targetTicketData['title'] = $targetTicketData['name']; + $targetTicketData['urgency_rule'] = $targetData['urgency_rule']; + $targetTicketData['_urgency_question'] = $questionId; + $this->boolean($targetTicket->update($targetTicketData))->isTrue(); + } + + $saveFormData = []; + foreach ($urgencyQuestions as $question) { + if ($question['question'] !== null) { + $saveFormData['formcreator_field_' . $question['question']->getID()] = $question['expected']; + } + } + $saveFormData['formcreator_form'] = $form->getID(); + $form->saveForm($saveFormData); + $formAnswer = new \PluginFormcreatorForm_Answer(); + $formAnswer->getFromDbByCrit([ + 'plugin_formcreator_forms_id' => $form->getID(), + ]); + + // Check urgency for each target ticket + foreach ($urgencyQuestions as $question) { + $targetTicket = $question['targetTicket']; + $targetName = $targetTicket->getField('name'); + $itemTicket = new \Item_Ticket(); + $tickets = []; + $rows = $itemTicket->find("`itemtype` = 'PluginFormcreatorForm_Answer' + AND `items_id` = '" . $formAnswer->getID() . "'"); + foreach ($rows as $row) { + $tickets[] = $row['tickets_id']; + } + $ticket = new \Ticket(); + $ticket->getFromDBByCrit([ + 'name' => $targetName, + 'id' => $tickets + ]); + $this->boolean($ticket->isNewItem())->isFalse(); + $this->integer((int) $ticket->getField('urgency'))->isEqualTo($question['expected']); + } + } +} \ No newline at end of file diff --git a/tests/suite-uninstall/Config.php b/tests/suite-uninstall/Config.php new file mode 100644 index 000000000..9f0f57f7a --- /dev/null +++ b/tests/suite-uninstall/Config.php @@ -0,0 +1,88 @@ +resetState(); + parent::beforeTestMethod($method); + $this->setupGLPIFramework(); + } + + public function testUninstallPlugin() { + global $DB; + + $pluginName = TEST_PLUGIN_NAME; + + $plugin = new \Plugin(); + $plugin->getFromDBbyDir($pluginName); + + // Uninstall the plugin + $log = ''; + ob_start(function($in) use ($log) { + $log .= $in; + return ''; + }); + $plugin->uninstall($plugin->getID()); + ob_end_clean(); + $this->boolean($plugin->isInstalled($pluginName))->isFalse($log); + + // Check the plugin is not installed + $this->boolean($plugin->isInstalled($pluginName))->isFalse(); + + // Check all plugin's tables are dropped + $tables = []; + $result = $DB->query("SHOW TABLES LIKE 'glpi_plugin_" . $pluginName . "_%'"); + while ($row = $DB->fetch_assoc($result)) { + $tables[] = array_pop($row); + } + $this->integer(count($tables))->isEqualTo(0, "not deleted tables \n" . json_encode($tables, JSON_PRETTY_PRINT)); + + // Check the notifications of the plugin no longer exist + $notification = new \Notification(); + $rows = $notification->find("`itemtype` = 'PluginFormcreatorForm_Answer'"); + $this->integer(count($rows))->isEqualTo(0); + + $template = new \NotificationTemplate(); + $rows = $template->find("`itemtype` = 'PluginFormcreatorForm_Answer'"); + $this->integer(count($rows))->isEqualTo(0); + + // TODO: need to find a reliable way to detect not clenaed + // - NotificationTemplateTranslation + // - Notification_NotificationTemplate + + } + +} diff --git a/tests/suite-unit/PluginFormcreatorActorField.php b/tests/suite-unit/PluginFormcreatorActorField.php new file mode 100644 index 000000000..30750d71b --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorActorField.php @@ -0,0 +1,153 @@ +getFromDBbyName('glpi'); + $userId = $user->getID(); + $dataset = [ + [ + 'fields' => [ + 'fieldtype' => 'actor', + 'name' => 'question', + 'required' => '0', + 'default_values' => '', + 'values' => '', + 'order' => '1', + 'show_rule' => 'always' + ], + 'data' => null, + 'expectedValue' => [''], + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'actor', + 'name' => 'question', + 'required' => '0', + 'default_values' => '', + 'values' => 'glpi', + 'order' => '1', + 'show_rule' => 'always' + ], + 'data' => null, + 'expectedValue' => [''], + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'actor', + 'name' => 'question', + 'required' => '0', + 'default_values' => 'nonexistent', + 'values' => '', + 'order' => '1', + 'show_rule' => 'always' + ], + 'data' => null, + 'expectedValue' => [''], + 'expectedIsValid' => false + ], + [ + 'fields' => [ + 'fieldtype' => 'actor', + 'name' => 'question', + 'required' => '0', + 'default_values' => 'email@incomplete', + 'values' => '', + 'order' => '1', + 'show_rule' => 'always' + ], + 'data' => null, + 'expectedValue' => [''], + 'expectedIsValid' => false + ], + [ + 'fields' => [ + 'fieldtype' => 'actor', + 'name' => 'question', + 'required' => '0', + 'default_values' => 'email@something.com', + 'values' => '', + 'order' => '1', + 'show_rule' => 'always' + ], + 'data' => null, + 'expectedValue' => ['email@something.com'], + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'actor', + 'name' => 'question', + 'required' => '0', + 'default_values' => $userId . ',email@something.com', + 'values' => '', + 'order' => '1', + 'show_rule' => 'always' + ], + 'data' => null, + 'expectedValue' => ['glpi', 'email@something.com'], + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'actor', + 'name' => 'question', + 'required' => '0', + 'default_values' => $userId . ',email@something.com,nonexistent', + 'values' => '', + 'order' => '1', + 'show_rule' => 'always' + ], + 'data' => null, + 'expectedValue' => ['glpi', 'email@something.com'], + 'expectedIsValid' => false + ], + [ + 'fields' => [ + 'fieldtype' => 'actor', + 'name' => 'question', + 'required' => '0', + 'default_values' => $userId . ',email@something.com,email@incomplete', + 'values' => '', + 'order' => '1', + 'show_rule' => 'always' + ], + 'data' => null, + 'expectedValue' => ['glpi', 'email@something.com'], + 'expectedIsValid' => false + ], + ]; + + return $dataset; + } + + /** + * @dataProvider provider + */ + public function testGetValue($fields, $data, $expectedValue, $expectedValidity) { + $fieldInstance = new \PluginFormcreatorActorField($fields, $data); + + $value = $fieldInstance->getValue(); + $this->integer(count(explode(',', $value)))->isEqualTo(count($expectedValue)); + foreach ($expectedValue as $expectedSubValue) { + if (!empty($expectedSubValue)) { + $this->boolean(in_array($expectedSubValue, explode(',', $value)))->isTrue(); + } + } + } + + /** + * @dataProvider provider + */ + public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidity) { + $fieldInstance = new \PluginFormcreatorActorField($fields, $data); + + $values = $fields['default_values']; + $isValid = $fieldInstance->isValid($values); + $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); + } +} diff --git a/tests/suite-unit/PluginFormcreatorCheckboxesField.php b/tests/suite-unit/PluginFormcreatorCheckboxesField.php new file mode 100644 index 000000000..30b462a08 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorCheckboxesField.php @@ -0,0 +1,245 @@ + [ + 'fieldtype' => 'checkboxes', + 'name' => 'question', + 'required' => '0', + 'default_values' => '', + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => [''], + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'checkboxes', + 'name' => 'question', + 'required' => '0', + 'default_values' => '2', + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => ['2'], + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'checkboxes', + 'name' => 'question', + 'required' => '0', + 'default_values' => "3\r\n5", + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => ['3', '5'], + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'checkboxes', + 'name' => 'question', + 'required' => '0', + 'default_values' => "3\r\n5", + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '3', + 'range_max' => '4', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => ['3', '5'], + 'expectedIsValid' => false + ], + [ + 'fields' => [ + 'fieldtype' => 'checkboxes', + 'name' => 'question', + 'required' => '0', + 'default_values' => "3\r\n5\r\n6", + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '3', + 'range_max' => '4', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => ['3', '5', '6'], + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'checkboxes', + 'name' => 'question', + 'required' => '0', + 'default_values' => "1\r\n2\r\n3\r\n5\r\n6", + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '3', + 'range_max' => '4', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => ['1', '2', '3', '5', '6'], + 'expectedIsValid' => false + ], + ]; + + return $dataset; + } + + /** + * @dataProvider provider + */ + public function testGetAvailableValues($fields, $data, $expectedValue, $expectedValidity) { + $fieldInstance = new \PluginFormcreatorCheckboxesField($fields, $data); + + $availableValues = $fieldInstance->getAvailableValues(); + $expectedAvaliableValues = explode("\r\n", $fields['values']); + + $this->integer(count($availableValues))->isEqualTo(count($expectedAvaliableValues)); + + foreach ($expectedAvaliableValues as $expectedValue) { + $this->array($availableValues)->contains($expectedValue); + } + } + + /** + * @dataProvider provider + */ + public function testGetValue($fields, $data, $expectedValue, $expectedValidity) { + $fieldInstance = new \PluginFormcreatorCheckboxesField($fields, $data); + + $value = $fieldInstance->getValue(); + $this->integer(count($value))->isEqualTo(count($expectedValue)); + foreach ($expectedValue as $expectedSubValue) { + $this->array($value)->contains($expectedSubValue); + } + } + + /** + * @dataProvider provider + */ + public function testIsValid($fields, $data, $expectedValue, $expectedValidity) { + $section = $this->getSection(); + $fields[$section::getForeignKeyField()] = $section->getID(); + + $question = new PluginFormcreatorQuestion(); + $question->add($fields); + $question->updateParameters($fields); + + $fieldInstance = new \PluginFormcreatorCheckboxesField($question->fields, $data); + + $values = json_encode(explode("\r\n", $fields['default_values']), JSON_OBJECT_AS_ARRAY); + $isValid = $fieldInstance->isValid($values); + $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); + } + + public function testPrepareInputForSave() { + $fields = array( + 'fieldtype' => 'checkboxes', + 'name' => 'question', + 'required' => '0', + 'default_values' => "1\r\n2\r\n3\r\n5\r\n6", + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + 'range_min' => 3, + 'range_max' => 4, + ); + $fieldInstance = new \PluginFormcreatorCheckboxesField($fields); + + // Test a value is mandatory + $input = [ + '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' => "éè", + ]; + $out = $fieldInstance->prepareQuestionInputForSave($input); + $this->string($out['values'])->isEqualTo("éè\r\nsomething else"); + $this->string($out['default_values'])->isEqualTo("éè"); + + // Test values are trimmed + $input = [ + 'values' => ' something \r\n something else ', + 'default_values' => " something ", + ]; + $out = $fieldInstance->prepareQuestionInputForSave($input); + $this->string($out['values'])->isEqualTo('something\r\nsomething else'); + $this->string($out['default_values'])->isEqualTo("something"); + } + + private function getSection() { + $form = new PluginFormcreatorForm(); + $form->add([ + 'name' => 'form' + ]); + $section = new PluginFormcreatorSection(); + $section->add([ + $form::getForeignKeyField() => $form->getID(), + 'name' => 'section', + ]); + return $section; + } +} \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorCommon.php b/tests/suite-unit/PluginFormcreatorCommon.php new file mode 100644 index 000000000..182261b94 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorCommon.php @@ -0,0 +1,12 @@ + 0 (aka found) + $this->integer((integer) $requestTypeId)->isGreaterThan(0); + } +} \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorFields.php b/tests/suite-unit/PluginFormcreatorFields.php new file mode 100644 index 000000000..42cb9f455 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorFields.php @@ -0,0 +1,263 @@ + [ + 'always', + [ + 'show_logic' => [], + 'show_field' => [], + 'show_condition' => [], + 'show_value' => [], + ], + [], + true, + ], + 'simple condition' => [ + 'hidden', + [ + 'show_logic' => [ + 'OR', + ], + 'show_field' => [ + 0, + ], + 'show_condition' => [ + '==', + ], + 'show_value' => [ + 'foo', + ], + ], + [ + 0 => 'foo', + ], + true, + ], + 'failed condition' => [ + 'hidden', + [ + 'show_logic' => [ + 'OR', + ], + 'show_field' => [ + 0, + ], + 'show_condition' => [ + '==', + ], + 'show_value' => [ + 'bar', + ], + ], + [ + 0 => 'foo', + ], + false, + ], + 'multiple condition OR' => [ + 'hidden', + [ + 'show_logic' => [ + 'OR', + 'OR', + ], + 'show_field' => [ + 0, + 1, + ], + 'show_condition' => [ + '==', + '==', + ], + 'show_value' => [ + 'val1', + 'val2', + ], + ], + [ + 0 => 'val1', + 1 => 'val2', + ], + true, + ], + 'failed multiple condition OR' => [ + 'hidden', + [ + 'show_logic' => [ + 'OR', + 'OR', + ], + 'show_field' => [ + 0, + 1, + ], + 'show_condition' => [ + '==', + '==', + ], + 'show_value' => [ + 'val1', + 'val2', + ], + ], + [ + 0 => 'val1', + 1 => 'not val2', + ], + true, + ], + 'multiple condition AND' => [ + 'hidden', + [ + 'show_logic' => [ + 'OR', + 'AND', + ], + 'show_field' => [ + 0, + 1, + ], + 'show_condition' => [ + '==', + '==', + ], + 'show_value' => [ + 'val1', + 'val2', + ], + ], + [ + 0 => 'val1', + 1 => 'val2', + ], + true, + ], + 'failed multiple condition AND' => [ + 'hidden', + [ + 'show_logic' => [ + 'OR', + 'AND', + ], + 'show_field' => [ + 0, + 1, + ], + 'show_condition' => [ + '==', + '==', + ], + 'show_value' => [ + 'val1', + 'val2', + ], + ], + [ + 0 => 'val1', + 1 => 'not val2', + ], + false, + ], + 'operator priority' => [ + 'hidden', + [ + 'show_logic' => [ + 'OR', + 'AND', + 'OR', + 'AND', + ], + 'show_field' => [ + 0, + 1, + 2, + 3, + ], + 'show_condition' => [ + '==', + '==', + '==', + '==', + ], + 'show_value' => [ + 'val1', + 'val2', + 'val3', + 'val4', + ], + ], + [ + 0 => 'val1', + 1 => 'val2', + 2 => 'val8', + 3 => 'val9', + ], + true, + ], + ]; + } + + /** + * @dataProvider answersProvider + */ + public function testIsVisible($show_rule, $conditions, $answers, $expectedVisibility) { + // create form + $form = new \PluginFormcreatorForm(); + $form->add([ + 'entities_id' => '0', + 'name' => 'a form', + 'description' => 'form description', + 'content' => 'a content', + 'is_active' => 1, + 'validation_required' => 0 + ]); + + // Create section + $section = new \PluginFormcreatorSection(); + $section->add([ + 'name' => 'a section', + 'plugin_formcreator_forms_id' => $form->getID(), + ]); + + // Create a question + $question = new \PluginFormcreatorQuestion(); + $question->add([ + 'name' => 'text question', + 'fieldtype' => 'text', + 'plugin_formcreator_sections_id' => $section->getID(), + ]); + + $questionPool = []; + for ($i = 0; $i < 4; $i++) { + $item = new \PluginFormcreatorQuestion(); + $item->add([ + 'fieldtype' => 'text', + 'name' => "question $i", + 'plugin_formcreator_sections_id' => $section->getID(), + ]); + $questionPool[$i] = $item->getID(); + } + + foreach ($conditions['show_field'] as $id => &$showField) { + $showField = $questionPool[$showField]; + } + $realAnswers = []; + foreach ($answers as $id => $answer) { + $realAnswers['formcreator_field_' . $questionPool[$id]] = $answers[$id]; + } + $input = $conditions + [ + 'id' => $question->getID(), + 'fieldtype' => 'text', + 'show_rule' => $show_rule, + ]; + $question->update($input); + $question->updateConditions($input); + $isVisible = \PluginFormcreatorFields::isVisible($question->getID(), $realAnswers); + $this->boolean((boolean) $isVisible)->isEqualTo($expectedVisibility); + } +} diff --git a/tests/0005_Unit/FloatFieldTest.php b/tests/suite-unit/PluginFormcreatorFloatField.php similarity index 92% rename from tests/0005_Unit/FloatFieldTest.php rename to tests/suite-unit/PluginFormcreatorFloatField.php index 1f0fb9266..748c6cee1 100644 --- a/tests/0005_Unit/FloatFieldTest.php +++ b/tests/suite-unit/PluginFormcreatorFloatField.php @@ -31,7 +31,10 @@ * --------------------------------------------------------------------- */ -class FloatFieldTest extends SuperAdminTestCase { +namespace tests\units; +use GlpiPlugin\Formcreator\Tests\CommonTestCase; + +class PluginFormcreatorFloatField extends CommonTestCase { public function provider() { $dataset = [ @@ -162,11 +165,11 @@ public function provider() { /** * @dataProvider provider */ - public function testFieldValue($fields, $data, $expectedValue, $expectedValidity) { - $fieldInstance = new PluginFormcreatorFloatField($fields, $data); + public function testGetValue($fields, $data, $expectedValue, $expectedValidity) { + $fieldInstance = new \PluginFormcreatorFloatField($fields, $data); $value = $fieldInstance->getValue(); - $this->assertEquals($expectedValue, $value); + $this->string($value)->isEqualTo($expectedValue); } /** @@ -178,12 +181,12 @@ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidi $question = new PluginFormcreatorQuestion(); $question->add($fields); - $this->assertFalse($question->isNewItem(), json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); + $this->boolean($question->isNewItem())->isFalse(json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); $question->updateParameters($fields); $fieldInstance = new PluginFormcreatorFloatField($question->fields, $data); $isValid = $fieldInstance->isValid($fields['default_values']); - $this->assertEquals($expectedValidity, $isValid); + $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); } private function getSection() { diff --git a/tests/suite-unit/PluginFormcreatorForm.php b/tests/suite-unit/PluginFormcreatorForm.php new file mode 100644 index 000000000..5829d41a6 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorForm.php @@ -0,0 +1,133 @@ + '0', + 'name' => 'a form', + 'description' => 'form description', + 'content' => 'a content', + 'is_active' => 1, + 'validation_required' => 0 + ] + ] + ]; + } + + /** + * @dataProvider formProvider + */ + public function testCreateForm($formData) { + $form = new \PluginFormcreatorForm(); + $form->add($formData); + $this->boolean($form->isNewItem())->isFalse(); + } + + /** + * @dataProvider formProvider + */ + public function testUpdateForm($formData) { + $form = new \PluginFormcreatorForm(); + $form->add($formData); + $this->boolean($form->isNewItem())->isFalse(); + + $success = $form->update(array( + 'id' => $form->getID(), + 'name' => 'an updated form', + 'validation_required' => 0 + )); + $this->boolean($success)->isTrue(json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); + } + + /** + * @dataProvider formProvider + */ + public function testPurgeForm($formData) { + $form = new \PluginFormcreatorForm(); + $form->add($formData); + $this->boolean($form->isNewItem())->isFalse(); + + $success = $form->delete(array( + 'id' => $form->getID(), + ), 1); + $this->boolean($success)->isTrue(); + } + + public function testCreateValidationNotification() { + \Config::setConfigurationValues( + 'core', + ['use_notifications' => 1, 'notifications_mailing' => 1] + ); + $CFG_GLPI['use_notifications'] = 1; + $CFG_GLPI['notifications_mailing'] = 1; + $user = new \User(); + $user->getFromDBbyName('glpi'); + $_SESSION['glpiID'] = $user->getID(); + $user->update([ + 'id' => $_SESSION['glpiID'], + '_useremails' => [ + 'glpi@localhost.com', + ] + ]); + $form = new \PluginFormcreatorForm(); + $form->add([ + 'name' => 'validation notification', + 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER, + '_validator_users' => [$_SESSION['glpiID']], + ]); + $section = new \PluginFormcreatorSection(); + $section->add([ + $form::getForeignKeyField() => $form->getID(), + 'name' => 'section', + ]); + + $formAnswer = new \PluginFormcreatorForm_Answer(); + $formAnswerId = $formAnswer->saveAnswers([ + 'formcreator_form' => $form->getID(), + 'formcreator_validator' => $_SESSION['glpiID'], + ]); + $this->integer($formAnswerId)->isGreaterThan(0); + + // 1 notification to the validator + // 1 notification to the requester + $notification = new \QueuedNotification(); + $foundNotifications = $notification->find("`itemtype` = 'PluginFormcreatorForm_Answer' AND `items_id` = '$formAnswerId'"); + $this->integer(count($foundNotifications))->isEqualTo(2); + } + + /** + * @cover PluginFormcreatorForm::export + */ + public function testExportForm() { + $form = new \PluginFormcreatorForm; + plugin_formcreator_getFromDBByField($form, 'name', "test export form"); + $export = $form->export(); + + $this->_checkForm($export); + + foreach ($export["_sections"] as $section) { + $this->_checkSection($section); + } + + foreach ($export["_validators"] as $validator) { + $this->_checkValidator($validator); + } + + foreach ($export["_targets"] as $target) { + $this->_checkTarget($target); + } + + foreach ($export["_profiles"] as $form_profile) { + $this->_checkFormProfile($form_profile); + } + + return $export; + } +} diff --git a/tests/0005_Unit/IntegerFieldTest.php b/tests/suite-unit/PluginFormcreatorIntegerField.php similarity index 87% rename from tests/0005_Unit/IntegerFieldTest.php rename to tests/suite-unit/PluginFormcreatorIntegerField.php index 366aba2e5..a6f7c16b3 100644 --- a/tests/0005_Unit/IntegerFieldTest.php +++ b/tests/suite-unit/PluginFormcreatorIntegerField.php @@ -31,12 +31,15 @@ * --------------------------------------------------------------------- */ -class IntegerFieldTest extends SuperAdminTestCase { + namespace tests\units; +use GlpiPlugin\Formcreator\Tests\CommonTestCase; + +class PluginFormcreatorIntegerField extends CommonTestCase { public function provider() { - $dataset = array( - array( - 'fields' => array( + $dataset = [ + [ + 'fields' => [ 'fieldtype' => 'integer', 'name' => 'question', 'required' => '0', @@ -54,13 +57,13 @@ public function provider() { 'regex' => ['regex' => ''], ] ], - ), + ], 'data' => null, 'expectedValue' => '', 'expectedIsValid' => true - ), - array( - 'fields' => array( + ], + [ + 'fields' => [ 'fieldtype' => 'integer', 'name' => 'question', 'required' => '0', @@ -78,13 +81,13 @@ public function provider() { 'regex' => ['regex' => ''], ] ], - ), + ], 'data' => null, 'expectedValue' => '2', 'expectedIsValid' => true - ), - array( - 'fields' => array( + ], + [ + 'fields' => [ 'fieldtype' => 'integer', 'name' => 'question', 'required' => '0', @@ -101,13 +104,13 @@ public function provider() { 'regex' => ['regex' => ''], ] ], - ), + ], 'data' => null, 'expectedValue' => '2', 'expectedIsValid' => false - ), - array( - 'fields' => array( + ], + [ + 'fields' => [ 'fieldtype' => 'integer', 'name' => 'question', 'required' => '0', @@ -125,13 +128,13 @@ public function provider() { 'regex' => ['regex' => ''], ] ], - ), + ], 'data' => null, 'expectedValue' => '5', 'expectedIsValid' => false - ), - array( - 'fields' => array( + ], + [ + 'fields' => [ 'fieldtype' => 'integer', 'name' => 'question', 'required' => '0', @@ -149,13 +152,13 @@ public function provider() { 'regex' => ['regex' => ''], ] ], - ), + ], 'data' => null, 'expectedValue' => '3.4', 'expectedIsValid' => false - ), - array( - 'fields' => array( + ], + [ + 'fields' => [ 'fieldtype' => 'integer', 'name' => 'question', 'required' => '0', @@ -173,12 +176,12 @@ public function provider() { 'regex' => ['regex' => ''], ] ], - ), + ], 'data' => null, 'expectedValue' => '4', 'expectedIsValid' => true - ), - ); + ], + ]; return $dataset; } @@ -186,11 +189,11 @@ public function provider() { /** * @dataProvider provider */ - public function testFieldValue($fields, $data, $expectedValue, $expectedValidity) { - $fieldInstance = new PluginFormcreatorIntegerField($fields, $data); + public function testGetValue($fields, $data, $expectedValue, $expectedValidity) { + $fieldInstance = new \PluginFormcreatorIntegerField($fields, $data); $value = $fieldInstance->getValue(); - $this->assertEquals($expectedValue, $value); + $this->integer((integer) $value)->isEqualTo((integer) $expectedValue); } /** @@ -204,9 +207,10 @@ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidi $question->add($fields); $question->updateParameters($fields); - $fieldInstance = new PluginFormcreatorIntegerField($question->fields, $data); + $fieldInstance = new \PluginFormcreatorIntegerField($question->fields, $data); + $isValid = $fieldInstance->isValid($fields['default_values']); - $this->assertEquals($expectedValidity, $isValid); + $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); } private function getSection() { diff --git a/tests/0005_Unit/MultiselectFieldTest.php b/tests/suite-unit/PluginFormcreatorMultiSelectField.php similarity index 63% rename from tests/0005_Unit/MultiselectFieldTest.php rename to tests/suite-unit/PluginFormcreatorMultiSelectField.php index c4d87e95d..96e37ef9d 100644 --- a/tests/0005_Unit/MultiselectFieldTest.php +++ b/tests/suite-unit/PluginFormcreatorMultiSelectField.php @@ -1,44 +1,15 @@ . - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ +namespace tests\units; +use GlpiPlugin\Formcreator\Tests\CommonTestCase; -class MultielectFieldTest extends SuperAdminTestCase { +class PluginFormcreatorMultiSelectField extends CommonTestCase { public function provider() { - $dataset = array( - array( - 'fields' => array( - 'fieldtype' => 'multiselect', + $dataset = [ + [ + 'fields' => [ + 'fieldtype' => 'select', 'name' => 'question', 'required' => '0', 'show_empty' => '0', @@ -54,14 +25,14 @@ public function provider() { ] ] ], - ), + ], 'data' => null, - 'expectedValue' => array(''), + 'expectedValue' => [''], 'expectedIsValid' => true - ), - array( - 'fields' => array( - 'fieldtype' => 'multiselect', + ], + [ + 'fields' => [ + 'fieldtype' => 'select', 'name' => 'question', 'required' => '0', 'show_empty' => '0', @@ -77,14 +48,14 @@ public function provider() { ] ] ], - ), + ], 'data' => null, - 'expectedValue' => array('3'), + 'expectedValue' => ['3'], 'expectedIsValid' => true - ), - array( - 'fields' => array( - 'fieldtype' => 'multiselect', + ], + [ + 'fields' => [ + 'fieldtype' => 'select', 'name' => 'question', 'required' => '0', 'show_empty' => '0', @@ -100,14 +71,14 @@ public function provider() { ] ] ], - ), + ], 'data' => null, - 'expectedValue' => array('3'), + 'expectedValue' => ['3'], 'expectedIsValid' => false - ), - array( - 'fields' => array( - 'fieldtype' => 'multiselect', + ], + [ + 'fields' => [ + 'fieldtype' => 'select', 'name' => 'question', 'required' => '0', 'show_empty' => '0', @@ -123,14 +94,14 @@ public function provider() { ] ] ], - ), + ], 'data' => null, - 'expectedValue' => array('3', '4'), + 'expectedValue' => ['3', '4'], 'expectedIsValid' => true - ), - array( - 'fields' => array( - 'fieldtype' => 'multiselect', + ], + [ + 'fields' => [ + 'fieldtype' => 'select', 'name' => 'question', 'required' => '0', 'show_empty' => '0', @@ -146,12 +117,12 @@ public function provider() { ] ] ], - ), + ], 'data' => null, - 'expectedValue' => array('3', '4', '2', '1', '6'), + 'expectedValue' => ['3', '4', '2', '1', '6'], 'expectedIsValid' => false - ), - ); + ], + ]; return $dataset; } @@ -160,17 +131,14 @@ public function provider() { * @dataProvider provider */ public function testFieldAvailableValue($fields, $data, $expectedValue, $expectedValidity) { - $section = $this->getSection(); - $fields[$section::getForeignKeyField()] = $section->getID(); - $fieldInstance = new PluginFormcreatorMultiSelectField($fields, $data); + $fieldInstance = new \PluginFormcreatorMultiSelectField($fields, $data); $availableValues = $fieldInstance->getAvailableValues(); $expectedAvaliableValues = explode("\r\n", $fields['values']); - $this->assertCount(count($expectedAvaliableValues), $availableValues); - + $this->integer(count($availableValues))->isEqualTo(count($expectedAvaliableValues)); foreach ($expectedAvaliableValues as $expectedValue) { - $this->assertContains($expectedValue, $availableValues); + $this->array($availableValues)->contains($expectedValue); } } @@ -178,12 +146,12 @@ public function testFieldAvailableValue($fields, $data, $expectedValue, $expecte * @dataProvider provider */ public function testFieldValue($fields, $data, $expectedValue, $expectedValidity) { - $fieldInstance = new PluginFormcreatorMultiSelectField($fields, $data); + $fieldInstance = new \PluginFormcreatorMultiSelectField($fields, $data); $value = $fieldInstance->getValue(); - $this->assertEquals(count($expectedValue), count($value)); + $this->integer(count($value))->isEqualTo(count($expectedValue)); foreach ($expectedValue as $expectedSubValue) { - $this->assertTrue(in_array($expectedSubValue, $value)); + $this->array($value)->contains($expectedSubValue); } } @@ -198,14 +166,15 @@ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidi $question->add($fields); $question->updateParameters($fields); - $fieldInstance = new PluginFormcreatorMultiSelectField($question->fields, $data); + $fieldInstance = new \PluginFormcreatorMultiSelectField($question->fields, $data); + $values = json_encode(explode("\r\n", $fields['default_values']), JSON_OBJECT_AS_ARRAY); $isValid = $fieldInstance->isValid($values); - $this->assertEquals($expectedValidity, $isValid); + $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); } public function testPrepareInputForSave() { - $fields = array( + $fields = [ 'fieldtype' => 'multiselect', 'name' => 'question', 'required' => '0', @@ -213,10 +182,23 @@ public function testPrepareInputForSave() { 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", 'order' => '1', 'show_rule' => 'always', - 'range_min' => 3, - 'range_max' => 4, - ); - $fieldInstance = new PluginFormcreatorMultiselectField($fields); + '_parameters' => [ + 'multiselect' => [ + 'range' => [ + 'range_min' => '3', + 'range_max' => '4', + ] + ] + ], + ]; + $section = $this->getSection(); + $fields[$section::getForeignKeyField()] = $section->getID(); + + $question = new PluginFormcreatorQuestion(); + $question->add($fields); + $question->updateParameters($fields); + + $fieldInstance = new \PluginFormcreatorMultiSelectField($question->fields, $data); // Test a value is mandatory $input = [ @@ -224,7 +206,7 @@ public function testPrepareInputForSave() { 'name' => 'foo', ]; $out = $fieldInstance->prepareQuestionInputForSave($input); - $this->assertEquals(0, count($out)); + $this->integer(count($out))->isEqualTo(0); // Test accented chars are kept $input = [ @@ -232,8 +214,8 @@ public function testPrepareInputForSave() { 'default_values' => "éè", ]; $out = $fieldInstance->prepareQuestionInputForSave($input); - $this->assertEquals("éè\r\nsomething else", $out['values']); - $this->assertEquals("éè", $out['default_values']); + $this->string($out['values'])->isEqualTo("éè\r\nsomething else"); + $this->string($out['default_values'])->isEqualTo("éè"); // Test values are trimmed $input = [ @@ -241,8 +223,8 @@ public function testPrepareInputForSave() { 'default_values' => " something ", ]; $out = $fieldInstance->prepareQuestionInputForSave($input); - $this->assertEquals('something\r\nsomething else', $out['values']); - $this->assertEquals("something", $out['default_values']); + $this->string($out['values'])->isEqualTo('something\r\nsomething else'); + $this->string($out['default_values'])->isEqualTo("something"); } private function getSection() { diff --git a/tests/suite-unit/PluginFormcreatorQuestion.php b/tests/suite-unit/PluginFormcreatorQuestion.php new file mode 100644 index 000000000..6636d76d8 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorQuestion.php @@ -0,0 +1,147 @@ +add([ + 'name' => "test clone form", + 'is_active' => true, + 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER + ]); + + $sections_id = $form_section->add([ + 'name' => "test clone section", + 'plugin_formcreator_forms_id' => $forms_id + ]); + + $questions_id_1 = $form_question->add([ + 'name' => "test clone question 1", + 'fieldtype' => 'text', + 'plugin_formcreator_sections_id' => $sections_id + ]); + $questions_id_2 = $form_question->add([ + 'name' => "test clone question 2", + 'fieldtype' => 'textarea', + 'plugin_formcreator_sections_id' => $sections_id + ]); + } + + public function beforeTestMethod($method) { + parent::beforeTestMethod($method); + switch ($method) { + case 'testPrepareInputForAdd': + case 'testPrepareInputForUpdate': + $this->form = new \PluginFormcreatorForm; + $this->section = new \PluginFormcreatorSection; + $this->form->add([ + 'name' => "$method" + ]); + $this->boolean($this->form->isNewItem())->isFalse(); + $this->section->add([ + 'name' => 'section', + 'plugin_formcreator_forms_id' => $this->form->getID(), + ]); + $this->boolean($this->section->isNewItem())->isFalse(); + } + } + + /** + * @cover PluginFormcreatorQuestion::clone + */ + public function testDuplicate() { + $question = new \PluginFormcreatorQuestion; + $new_question = new \PluginFormcreatorQuestion; + + //get question + plugin_formcreator_getFromDBByField($question, 'name', "test clone question 1"); + + //clone it + $newQuestion_id = $question->duplicate(); + $this->integer($newQuestion_id)->isGreaterThan(0); + + //get cloned section + $new_question->getFromDB($newQuestion_id); + + // check uuid + $this->string($new_question->getField('uuid'))->isNotEqualTo($question->getField('uuid')); + } + + public function providerPrepareInputForAdd() { + return [ + [ + 'input' => [ + 'plugin_formcreator_sections_id' => $this->section->getID(), + 'fieldtype' => 'radios', + 'name' => "it\'s nice", + 'values' => "it\'s nice\r\nit's good", + 'required' => '1', + 'show_empty' => '0', + 'default_values' => 'it\'s nice', + 'desription' => "it\'s excellent", + 'order' => '1', + 'show_rule' => 'always', + ], + 'expected' => [ + 'plugin_formcreator_sections_id' => $this->section->getID(), + 'fieldtype' => 'radios', + 'name' => "it\'s nice", + 'values' => "it\'s nice\r\nit's good", + 'required' => '1', + 'show_empty' => '0', + 'default_values' => 'it\'s nice', + 'desription' => "it\'s excellent", + 'order' => '1', + 'show_rule' => 'always', + ] + ], + ]; + } + + public function providerPrepareInputForUpdate() { + return providerPrepareInputForAdd(); + } + + /** + * @dataProvider providerPrepareInputForAdd + */ + public function testPrepareInputForAdd($input, $expected) { + $instance = new \PluginFormcreatorQuestion(); + $output = $instance->prepareInputForAdd($input); + $this->array($output)->hasKeys(array_keys($expected)); + /* + // Disabled for now + $this->array($output)->containsValues($expected); + */ + $this->array($output)->hasKey('uuid'); + // The method added a UUID key + $this->array($output)->size->isEqualTo(count($expected) + 1); + } + + /** + * @dataProvider providerPrepareInputForUpdate + */ + public function prepareInputForUpdate($input, $expected) { + $instance = new \PluginFormcreatorQuestion(); + $output = $instance->prepareInputForUpdate($input); + $this->array($output)->hasKeys(array_keys($expected)); + $this->array($output)->containsValues($expected); + $this->array($output)->hasKey('uuid'); + $this->array($output)->size->isEqualTo(count($expected)); + } +} diff --git a/tests/0005_Unit/Question_ConditionTest.php b/tests/suite-unit/PluginFormcreatorQuestion_Condition.php similarity index 91% rename from tests/0005_Unit/Question_ConditionTest.php rename to tests/suite-unit/PluginFormcreatorQuestion_Condition.php index 55fd83dfa..1e2dd3585 100644 --- a/tests/0005_Unit/Question_ConditionTest.php +++ b/tests/suite-unit/PluginFormcreatorQuestion_Condition.php @@ -37,68 +37,10 @@ class Question_ConditionTest extends SuperAdminTestCase { static $questionPool = []; - public static function setUpBeforeClass() { - parent::setupBeforeClass(); + public static function beforeTestMethod($method) { + parent::beforeTestMethod(); self::login('glpi', 'glpi'); - - // create form - $form = new PluginFormcreatorForm(); - $form->add(array( - 'entities_id' => '0', - 'name' => 'a form', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 0 - )); - - // Create section - $section = new PluginFormcreatorSection(); - $section->add(array( - 'name' => 'a section', - 'plugin_formcreator_forms_id' => $form->getID(), - )); - - // Create a question - self::$question = new PluginFormcreatorQuestion(); - self::$question->add([ - 'name' => 'text question', - 'fieldtype' => 'text', - 'plugin_formcreator_sections_id' => $section->getID(), - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ], - ]); - - for ($i = 0; $i < 4; $i++) { - $item = new PluginFormcreatorQuestion(); - $item->add([ - 'fieldtype' => 'text', - 'name' => "question $i", - 'plugin_formcreator_sections_id' => $section->getID(), - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ], - ]); - self::$questionPool[$i] = $item->getID(); - } } public function answersProvider() { @@ -307,6 +249,64 @@ public function answersProvider() { * @dataProvider answersProvider */ public function testConditionsEvaluation($show_rule, $conditions, $answers, $expectedVisibility) { + // create form + $form = new PluginFormcreatorForm(); + $form->add([ + 'entities_id' => '0', + 'name' => __METHOD__, + 'description' => 'form description', + 'content' => 'a content', + 'is_active' => 1, + 'validation_required' => 0 + ]); + + // Create section + $section = new PluginFormcreatorSection(); + $section->add([ + 'name' => 'a section', + 'plugin_formcreator_forms_id' => $form->getID(), + ]); + + // Create a question + self::$question = new PluginFormcreatorQuestion(); + self::$question->add([ + 'name' => 'text question', + 'fieldtype' => 'text', + 'plugin_formcreator_sections_id' => $section->getID(), + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ]); + + for ($i = 0; $i < 4; $i++) { + $item = new PluginFormcreatorQuestion(); + $item->add([ + 'fieldtype' => 'text', + 'name' => "question $i", + 'plugin_formcreator_sections_id' => $section->getID(), + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ]); + self::$questionPool[$i] = $item->getID(); + } + foreach ($conditions['show_field'] as $id => &$showField) { $showField = self::$questionPool[$showField]; } @@ -314,10 +314,10 @@ public function testConditionsEvaluation($show_rule, $conditions, $answers, $exp foreach ($answers as $id => $answer) { $realAnswers['formcreator_field_' . self::$questionPool[$id]] = $answers[$id]; } - $input = $conditions + array( - 'id' => self::$question->getID(), - 'fieldtype' => 'text', - 'show_rule' => $show_rule, + $input = $conditions + [ + 'id' => self::$question->getID(), + 'fieldtype' => 'text', + 'show_rule' => $show_rule, '_parameters' => [ 'text' => [ 'range' => [ @@ -329,11 +329,11 @@ public function testConditionsEvaluation($show_rule, $conditions, $answers, $exp ] ] ], - ); + ]; self::$question->update($input); self::$question->updateConditions($input); $isVisible = PluginFormcreatorFields::isVisible(self::$question->getID(), $realAnswers); - $this->assertEquals($expectedVisibility, $isVisible); + $this->boolean($isVisible)->isEqualTo($expectedVisibility); } } diff --git a/tests/suite-unit/PluginFormcreatorRadiosField.php b/tests/suite-unit/PluginFormcreatorRadiosField.php new file mode 100644 index 000000000..c27ca6698 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorRadiosField.php @@ -0,0 +1,46 @@ + 'radios', + 'name' => 'question', + 'required' => '0', + 'default_values' => "1\r\n2\r\n3\r\n5\r\n6", + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always', + 'range_min' => 3, + 'range_max' => 4, + ]; + $fieldInstance = new \PluginFormcreatorRadiosField($fields); + + // Test a value is mandatory + $input = [ + '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' => "éè", + ]; + $out = $fieldInstance->prepareQuestionInputForSave($input); + $this->string($out['values'])->isEqualTo("éè\r\nsomething else"); + $this->string($out['default_values'])->isEqualTo("éè"); + + // Test values are trimmed + $input = [ + 'values' => ' something \r\n something else ', + 'default_values' => " something ", + ]; + $out = $fieldInstance->prepareQuestionInputForSave($input); + $this->string($out['values'])->isEqualTo('something\r\nsomething else'); + $this->string($out['default_values'])->isEqualTo("something"); + } +} \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorSection.php b/tests/suite-unit/PluginFormcreatorSection.php new file mode 100644 index 000000000..5dc9280d3 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorSection.php @@ -0,0 +1,76 @@ +add([ + 'name' => "test clone form", + 'is_active' => true, + 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER + ]); + + $sections_id = $form_section->add([ + 'name' => "test clone section", + 'plugin_formcreator_forms_id' => $forms_id + ]); + + $questions_id_1 = $form_question->add([ + 'name' => "test clone question 1", + 'fieldtype' => 'text', + 'plugin_formcreator_sections_id' => $sections_id + ]); + $questions_id_2 = $form_question->add([ + 'name' => "test clone question 2", + 'fieldtype' => 'textarea', + 'plugin_formcreator_sections_id' => $sections_id + ]); + } + + /** + * @cover PluginFormcreatorSection::clone + */ + public function testDuplicate() { + $section = new \PluginFormcreatorSection; + $new_section = new \PluginFormcreatorSection; + $form_question = new \PluginFormcreatorQuestion; + + //get section + plugin_formcreator_getFromDBByField($section, 'name', "test clone section"); + + //clone it + $newSection_id = $section->duplicate(); + $this->integer($newSection_id)->isGreaterThan(0); + + //get cloned section + $new_section->getFromDB($newSection_id); + + // check uuid + $this->string($new_section->getField('uuid'))->isNotEqualTo($section->getField('uuid')); + + // check questions + $all_questions = $form_question->find("plugin_formcreator_sections_id = ".$section->getID()); + $all_new_questions = $form_question->find("plugin_formcreator_sections_id = ".$new_section->getID()); + $this->integer(count($all_new_questions))->isEqualTo(count($all_questions)); + + // check that all question uuid are new + $uuids = $new_uuids = []; + foreach ($all_questions as $question) { + $uuids[] = $question['uuid']; + } + foreach ($all_new_questions as $question) { + $new_uuids[] = $question['uuid']; + } + $this->integer(count(array_diff($new_uuids, $uuids)))->isEqualTo(count($new_uuids)); + } +} diff --git a/tests/suite-unit/PluginFormcreatorSelectField.php b/tests/suite-unit/PluginFormcreatorSelectField.php new file mode 100644 index 000000000..cf884ffe6 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorSelectField.php @@ -0,0 +1,125 @@ + [ + 'fieldtype' => 'select', + 'name' => 'question', + 'required' => '0', + 'show_empty' => '0', + 'default_values' => '', + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always' + ], + 'data' => null, + 'expectedValue' => '1', + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'select', + 'name' => 'question', + 'required' => '0', + 'show_empty' => '1', + 'default_values' => '', + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always' + ], + 'data' => null, + 'expectedValue' => '', + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'select', + 'name' => 'question', + 'required' => '0', + 'show_empty' => '0', + 'default_values' => '3', + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always' + ], + 'data' => null, + 'expectedValue' => '3', + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'select', + 'name' => 'question', + 'required' => '1', + 'show_empty' => '0', + 'default_values' => '', + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always' + ], + 'data' => null, + 'expectedValue' => '1', + 'expectedIsValid' => false + ], + [ + 'fields' => [ + 'fieldtype' => 'select', + 'name' => 'question', + 'required' => '1', + 'show_empty' => '1', + 'default_values' => '', + 'values' => "1\r\n2\r\n3\r\n4\r\n5\r\n6", + 'order' => '1', + 'show_rule' => 'always' + ], + 'data' => null, + 'expectedValue' => '', + 'expectedIsValid' => false + ], + ]; + + return $dataset; + } + + /** + * @dataProvider provider + */ + public function testFieldAvailableValue($fields, $data, $expectedValue, $expectedValidity) { + $fieldInstance = new \PluginFormcreatorSelectField($fields, $data); + + $availableValues = $fieldInstance->getAvailableValues(); + $expectedAvaliableValues = explode("\r\n", $fields['values']); + + $this->integer(count($availableValues))->isEqualTo(count($expectedAvaliableValues)); + + foreach ($expectedAvaliableValues as $expectedValue) { + $this->array($availableValues)->contains($expectedValue); + } + } + + /** + * @dataProvider provider + */ + public function testGetValue($fields, $data, $expectedValue, $expectedValidity) { + $fieldInstance = new \PluginFormcreatorSelectField($fields, $data); + + $value = $fieldInstance->getValue(); + $this->string($value)->isEqualTo($expectedValue); + } + + /** + * @dataProvider provider + */ + public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidity) { + $fieldInstance = new \PluginFormcreatorSelectField($fields, $data); + + $isValid = $fieldInstance->isValid($fields['default_values']); + $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); + } +} \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorTarget.php b/tests/suite-unit/PluginFormcreatorTarget.php new file mode 100644 index 000000000..f0652fd07 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorTarget.php @@ -0,0 +1,62 @@ + [ + 'name' => '', + 'itemtype' => \PluginFormcreatorTargetTicket::class + ], + 'expected' => false, + ], + [ + 'input' => [ + 'name' => 'should fail', + 'itemtype' => '' + ], + 'expected' => false, + ], + [ + 'input' => [ + 'name' => 'should pass', + 'itemtype' => \PluginFormcreatorTargetTicket::class + ], + 'expected' => true, + ], + [ + 'input' => [ + 'name' => 'être ou ne pas être', + 'itemtype' => \PluginFormcreatorTargetTicket::class + ], + 'expected' => true, + ], + [ + 'input' => [ + 'name' => 'test d\\\'apostrophe', + 'itemtype' => \PluginFormcreatorTargetTicket::class + ], + 'expected' => true, + ], + ]; + } + + /** + * @dataProvider addUpdateFormProvider + * @param array $input + * @param boolean $expected + */ + public function testPrepareInputForAdd($input, $expected) { + $target = new \PluginFormcreatorTarget(); + $output = $target->prepareInputForAdd($input); + if ($expected === false) { + $this->integer(count($output))->isEqualTo(0); + } else { + $this->string($output['name'])->isEqualTo($input['name']); + $this->array($output)->hasKey('uuid'); + } + } +} diff --git a/tests/suite-unit/PluginFormcreatorTargetTicket.php b/tests/suite-unit/PluginFormcreatorTargetTicket.php new file mode 100644 index 000000000..e3de432c8 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorTargetTicket.php @@ -0,0 +1,84 @@ +add([ + 'name' => 'ticket', + 'content' => 'help !', + 'users_id_recipient' => '0', + ]); + $this->boolean($ticket->isNewItem())->isFalse(); + + $form = new \PluginFormcreatorForm(); + $formFk = \PluginFormcreatorForm::getForeignKeyField(); + $form->add([ + 'name' => 'a form' + ]); + $this->boolean($form->isNewItem())->isFalse(); + + $target_1 = new \PluginFormcreatorTarget(); + $target_1->add([ + 'name' => 'target 1', + $formFk => $form->getID(), + 'itemtype' => \PluginFormcreatorTargetTicket::class, + ]); + $this->boolean($target_1->isNewItem())->isFalse(); + + $target_2 = new \PluginFormcreatorTarget(); + $target_2->add([ + 'name' => 'target 2', + $formFk => $form->getID(), + 'itemtype' => \PluginFormcreatorTargetTicket::class, + ]); + $this->boolean($target_2->isNewItem())->isFalse(); + + $targetTicket_1 = new \PluginFormcreatorTargetTicket(); + $targetTicket_1->getFromDB($target_1->getField('items_id')); + $this->boolean($targetTicket_1->isNewItem())->isFalse(); + + $targetTicket_2 = new \PluginFormcreatorTargetTicket(); + $targetTicket_2->getFromDB($target_2->getField('items_id')); + $this->boolean($targetTicket_2->isNewItem())->isFalse(); + + $targetTicketFk = \PluginFormcreatorTargetTicket::getForeignKeyField(); + $item_targetticket_1 = new \PluginFormcreatorItem_TargetTicket(); + $item_targetticket_1->add([ + $targetTicketFk => $targetTicket_1->getID(), + 'link' => \Ticket_Ticket::LINK_TO, + 'itemtype' => \Ticket::class, + 'items_id' => $ticket->getID(), + ]); + $this->boolean($item_targetticket_1->isNewItem())->isFalse(); + + $item_targetticket_2 = new \PluginFormcreatorItem_TargetTicket(); + $item_targetticket_2->add([ + $targetTicketFk => $targetTicket_1->getID(), + 'link' => \Ticket_Ticket::LINK_TO, + 'itemtype' => \PluginFormcreatorTargetTicket::class, + 'items_id' => $targetTicket_2->getID(), + ]); + $this->boolean($item_targetticket_2->isNewItem())->isFalse(); + + // delete the target ticket + $target_1->delete(['id' => $target_1->getID()]); + + // Check the linked ticket or target ticket are deleted + $this->boolean($item_targetticket_1->getFromDB($item_targetticket_1->getID()))->isFalse(); + $this->boolean($item_targetticket_2->getFromDB($item_targetticket_2->getID()))->isFalse(); + } +} \ No newline at end of file diff --git a/tests/0005_Unit/QuestionTest.php b/tests/suite-unit/QuestionTest.php similarity index 100% rename from tests/0005_Unit/QuestionTest.php rename to tests/suite-unit/QuestionTest.php diff --git a/tests/0005_Unit/TextFieldTest.php b/tests/suite-unit/TextFieldTest.php similarity index 100% rename from tests/0005_Unit/TextFieldTest.php rename to tests/suite-unit/TextFieldTest.php diff --git a/tests/testall.sh b/tests/testall.sh new file mode 100755 index 000000000..096c8fa4a --- /dev/null +++ b/tests/testall.sh @@ -0,0 +1,32 @@ +#!/bin/sh +SELF=`readlink -f $0` +SELFDIR=`dirname $SELF` +DBNAME=unit_test_01 +PHP=php7.0 +ATOUM=~/.config/composer/vendor/bin/atoum + +oldpath=`pwd` +cd $SELFDIR/.. +mysql -u glpi -pglpi -e "DROP DATABASE IF EXISTS \`$DBNAME\`" +$PHP ../../scripts/cliinstall.php --db=$DBNAME --user=glpi --pass=glpi --tests --force +#php -S localhost:8088 -t ../.. ../../tests/router.php &>/dev/null & +#PID=$! +#echo $PID + +echo "=== Install tests ===" +$PHP $ATOUM --debug -bf atoum/bootstrap.php -no-cc --max-children-number 1 -d atoum/suite-install --no-cc + +echo "=== Unit tests ===" +$PHP $ATOUM --debug -bf atoum/bootstrap.php -no-cc --max-children-number 1 -d atoum/suite-unit --no-cc + +echo "=== Integration tests ===" +#$PHP $ATOUM --debug -bf atoum/bootstrap.php -no-cc --max-children-number 1 -d atoum/suite-integration + +#echo "=== Functional tests ===" + +echo "=== Uninstall tests ===" +$PHP $ATOUM --debug -bf atoum/bootstrap.php -no-cc --max-children-number 1 -d atoum/suite-uninstall --no-cc +cd $oldpath +#kill $PID + +#vendor/bin/phpcbf -p --standard=vendor/glpi-project/coding-standard/GlpiStandard/ *.php install/ inc/ front/ ajax/ tests/ \ No newline at end of file diff --git a/tests/testinstall.sh b/tests/testinstall.sh new file mode 100755 index 000000000..b0093e9aa --- /dev/null +++ b/tests/testinstall.sh @@ -0,0 +1,17 @@ +#!/bin/sh +SELF=`readlink -f $0` +SELFDIR=`dirname $SELF` +DB=unit_test_01 +PHP=`which php7.0` + +oldpath=`pwd` +cd $SELFDIR/.. +mysql -u glpi -pglpi -e "DROP DATABASE IF EXISTS \`$DB\`" +php ../../scripts/cliinstall.php --db=$DB --user=glpi --pass=glpi --lang=en_US --tests --force +#php tools/cliinstall.php --tests +php -S localhost:8088 -t ../.. ../../tests/router.php & +PID=$! +#echo $PID +echo "=== Install tests ===" +$PHP vendor/bin/atoum -ncc -bf tests/bootstrap.php -d tests/suite-install + diff --git a/tests/testone.sh b/tests/testone.sh new file mode 100755 index 000000000..5b1310e19 --- /dev/null +++ b/tests/testone.sh @@ -0,0 +1,19 @@ +#!/bin/sh +SELF=`readlink -f $0` +SELFDIR=`dirname $SELF` +DB=unit_test_01 +PHP=`which php7.0` + +oldpath=`pwd` +cd $SELFDIR/.. +oldpath=`pwd` +cd $SELFDIR/.. + +echo "=== Unit tests ===" +if [ -f $1 ]; then + RESOURCE_TYPE="-f" +elif [ -d $1 ]; then + RESOURCE_TYPE="-d" +fi +$PHP vendor/bin/atoum --debug -bf tests/bootstrap.php -no-cc $RESOURCE_TYPE $1 + From 1b33b957b9c3d6caec689e723742522290560ca8 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 9 Jul 2018 11:49:13 +0200 Subject: [PATCH 006/192] update unit tests Signed-off-by: btry --- tests/src/CommonTestCase.php | 14 ++++ .../PluginFormcreatorCheckboxesField.php | 15 +--- tests/suite-unit/PluginFormcreatorFields.php | 41 +++++++++- .../PluginFormcreatorFloatField.php | 17 +--- .../PluginFormcreatorIntegerField.php | 13 --- .../PluginFormcreatorMultiSelectField.php | 13 --- .../suite-unit/PluginFormcreatorQuestion.php | 28 +++++++ .../PluginFormcreatorQuestion_Condition.php | 8 +- ...est.php => PluginFormcreatorTextField.php} | 24 ++---- tests/suite-unit/QuestionTest.php | 82 ------------------- 10 files changed, 95 insertions(+), 160 deletions(-) rename tests/suite-unit/{TextFieldTest.php => PluginFormcreatorTextField.php} (89%) delete mode 100644 tests/suite-unit/QuestionTest.php diff --git a/tests/src/CommonTestCase.php b/tests/src/CommonTestCase.php index 54ac328b9..4a0f863ac 100644 --- a/tests/src/CommonTestCase.php +++ b/tests/src/CommonTestCase.php @@ -154,4 +154,18 @@ protected function restartSession() { //$_SESSION["MESSAGE_AFTER_REDIRECT"] = []; } } + + protected function getSection() { + $form = new \PluginFormcreatorForm(); + $form->add([ + 'name' => 'form' + ]); + $section = new \PluginFormcreatorSection(); + $section->add([ + $form::getForeignKeyField() => $form->getID(), + 'name' => 'section', + ]); + return $section; + } + } diff --git a/tests/suite-unit/PluginFormcreatorCheckboxesField.php b/tests/suite-unit/PluginFormcreatorCheckboxesField.php index 30b462a08..4912701ea 100644 --- a/tests/suite-unit/PluginFormcreatorCheckboxesField.php +++ b/tests/suite-unit/PluginFormcreatorCheckboxesField.php @@ -178,7 +178,7 @@ public function testIsValid($fields, $data, $expectedValue, $expectedValidity) { $section = $this->getSection(); $fields[$section::getForeignKeyField()] = $section->getID(); - $question = new PluginFormcreatorQuestion(); + $question = new \PluginFormcreatorQuestion(); $question->add($fields); $question->updateParameters($fields); @@ -229,17 +229,4 @@ public function testPrepareInputForSave() { $this->string($out['values'])->isEqualTo('something\r\nsomething else'); $this->string($out['default_values'])->isEqualTo("something"); } - - private function getSection() { - $form = new PluginFormcreatorForm(); - $form->add([ - 'name' => 'form' - ]); - $section = new PluginFormcreatorSection(); - $section->add([ - $form::getForeignKeyField() => $form->getID(), - 'name' => 'section', - ]); - return $section; - } } \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorFields.php b/tests/suite-unit/PluginFormcreatorFields.php index 42cb9f455..ba6dc1983 100644 --- a/tests/suite-unit/PluginFormcreatorFields.php +++ b/tests/suite-unit/PluginFormcreatorFields.php @@ -204,6 +204,7 @@ public function answersProvider() { /** * @dataProvider answersProvider + * @engine inline */ public function testIsVisible($show_rule, $conditions, $answers, $expectedVisibility) { // create form @@ -230,7 +231,19 @@ public function testIsVisible($show_rule, $conditions, $answers, $expectedVisibi 'name' => 'text question', 'fieldtype' => 'text', 'plugin_formcreator_sections_id' => $section->getID(), + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], ]); + $this->boolean($question->isNewItem())->isFalse(); $questionPool = []; for ($i = 0; $i < 4; $i++) { @@ -239,6 +252,17 @@ public function testIsVisible($show_rule, $conditions, $answers, $expectedVisibi 'fieldtype' => 'text', 'name' => "question $i", 'plugin_formcreator_sections_id' => $section->getID(), + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ] ]); $questionPool[$i] = $item->getID(); } @@ -251,9 +275,20 @@ public function testIsVisible($show_rule, $conditions, $answers, $expectedVisibi $realAnswers['formcreator_field_' . $questionPool[$id]] = $answers[$id]; } $input = $conditions + [ - 'id' => $question->getID(), - 'fieldtype' => 'text', - 'show_rule' => $show_rule, + 'id' => $question->getID(), + 'fieldtype' => 'text', + 'show_rule' => $show_rule, + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ] ]; $question->update($input); $question->updateConditions($input); diff --git a/tests/suite-unit/PluginFormcreatorFloatField.php b/tests/suite-unit/PluginFormcreatorFloatField.php index 748c6cee1..5fcfdad9b 100644 --- a/tests/suite-unit/PluginFormcreatorFloatField.php +++ b/tests/suite-unit/PluginFormcreatorFloatField.php @@ -179,26 +179,13 @@ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidi $section = $this->getSection(); $fields[$section::getForeignKeyField()] = $section->getID(); - $question = new PluginFormcreatorQuestion(); + $question = new \PluginFormcreatorQuestion(); $question->add($fields); $this->boolean($question->isNewItem())->isFalse(json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); $question->updateParameters($fields); - $fieldInstance = new PluginFormcreatorFloatField($question->fields, $data); + $fieldInstance = new \PluginFormcreatorFloatField($question->fields, $data); $isValid = $fieldInstance->isValid($fields['default_values']); $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); } - - private function getSection() { - $form = new PluginFormcreatorForm(); - $form->add([ - 'name' => 'form' - ]); - $section = new PluginFormcreatorSection(); - $section->add([ - $form::getForeignKeyField() => $form->getID(), - 'name' => 'section', - ]); - return $section; - } } diff --git a/tests/suite-unit/PluginFormcreatorIntegerField.php b/tests/suite-unit/PluginFormcreatorIntegerField.php index a6f7c16b3..721dd9d43 100644 --- a/tests/suite-unit/PluginFormcreatorIntegerField.php +++ b/tests/suite-unit/PluginFormcreatorIntegerField.php @@ -212,17 +212,4 @@ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidi $isValid = $fieldInstance->isValid($fields['default_values']); $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); } - - private function getSection() { - $form = new PluginFormcreatorForm(); - $form->add([ - 'name' => 'form' - ]); - $section = new PluginFormcreatorSection(); - $section->add([ - $form::getForeignKeyField() => $form->getID(), - 'name' => 'section', - ]); - return $section; - } } \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorMultiSelectField.php b/tests/suite-unit/PluginFormcreatorMultiSelectField.php index 96e37ef9d..c48c5f485 100644 --- a/tests/suite-unit/PluginFormcreatorMultiSelectField.php +++ b/tests/suite-unit/PluginFormcreatorMultiSelectField.php @@ -226,17 +226,4 @@ public function testPrepareInputForSave() { $this->string($out['values'])->isEqualTo('something\r\nsomething else'); $this->string($out['default_values'])->isEqualTo("something"); } - - private function getSection() { - $form = new PluginFormcreatorForm(); - $form->add([ - 'name' => 'form' - ]); - $section = new PluginFormcreatorSection(); - $section->add([ - $form::getForeignKeyField() => $form->getID(), - 'name' => 'section', - ]); - return $section; - } } \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorQuestion.php b/tests/suite-unit/PluginFormcreatorQuestion.php index 6636d76d8..b6c7f94fe 100644 --- a/tests/suite-unit/PluginFormcreatorQuestion.php +++ b/tests/suite-unit/PluginFormcreatorQuestion.php @@ -96,6 +96,17 @@ public function providerPrepareInputForAdd() { 'desription' => "it\'s excellent", 'order' => '1', 'show_rule' => 'always', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], ], 'expected' => [ 'plugin_formcreator_sections_id' => $this->section->getID(), @@ -108,6 +119,17 @@ public function providerPrepareInputForAdd() { 'desription' => "it\'s excellent", 'order' => '1', 'show_rule' => 'always', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], ] ], ]; @@ -121,6 +143,9 @@ public function providerPrepareInputForUpdate() { * @dataProvider providerPrepareInputForAdd */ public function testPrepareInputForAdd($input, $expected) { + $section = $this->getSection(); + $input[$section::getForeignKeyField()] = $section->getID(); + $instance = new \PluginFormcreatorQuestion(); $output = $instance->prepareInputForAdd($input); $this->array($output)->hasKeys(array_keys($expected)); @@ -137,6 +162,9 @@ public function testPrepareInputForAdd($input, $expected) { * @dataProvider providerPrepareInputForUpdate */ public function prepareInputForUpdate($input, $expected) { + $section = $this->getSection(); + $input[$section::getForeignKeyField()] = $section->getID(); + $instance = new \PluginFormcreatorQuestion(); $output = $instance->prepareInputForUpdate($input); $this->array($output)->hasKeys(array_keys($expected)); diff --git a/tests/suite-unit/PluginFormcreatorQuestion_Condition.php b/tests/suite-unit/PluginFormcreatorQuestion_Condition.php index 1e2dd3585..c7bd0fdde 100644 --- a/tests/suite-unit/PluginFormcreatorQuestion_Condition.php +++ b/tests/suite-unit/PluginFormcreatorQuestion_Condition.php @@ -31,14 +31,16 @@ * --------------------------------------------------------------------- */ -class Question_ConditionTest extends SuperAdminTestCase { +namespace tests\units; +use GlpiPlugin\Formcreator\Tests\CommonTestCase; +class Question_ConditionTest extends CommonTestCase { static $question; static $questionPool = []; - public static function beforeTestMethod($method) { - parent::beforeTestMethod(); + public function beforeTestMethod($method) { + parent::beforeTestMethod($method); self::login('glpi', 'glpi'); } diff --git a/tests/suite-unit/TextFieldTest.php b/tests/suite-unit/PluginFormcreatorTextField.php similarity index 89% rename from tests/suite-unit/TextFieldTest.php rename to tests/suite-unit/PluginFormcreatorTextField.php index 1f4128269..cb5c5dfe5 100644 --- a/tests/suite-unit/TextFieldTest.php +++ b/tests/suite-unit/PluginFormcreatorTextField.php @@ -1,5 +1,8 @@ getSection(); $fields[$section::getForeignKeyField()] = $section->getID(); - $question = new PluginFormcreatorQuestion(); + $question = new \PluginFormcreatorQuestion(); $question->add($fields); $question->updateParameters($fields); - $fieldInstance = new PluginFormcreatorTextField($question->fields, $data); + $fieldInstance = new \PluginFormcreatorTextField($question->fields, $data); $isValid = $fieldInstance->isValid($fields['default_values']); - $this->assertEquals($expectedValidity, $isValid, $_SESSION['MESSAGE_AFTER_REDIRECT']); - } - - private function getSection() { - $form = new PluginFormcreatorForm(); - $form->add([ - 'name' => 'form' - ]); - $section = new PluginFormcreatorSection(); - $section->add([ - $form::getForeignKeyField() => $form->getID(), - 'name' => 'section', - ]); - return $section; + $this->boolean($isValid)->isEqualTo($expectedValidity, json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); } } \ No newline at end of file diff --git a/tests/suite-unit/QuestionTest.php b/tests/suite-unit/QuestionTest.php deleted file mode 100644 index 41be91043..000000000 --- a/tests/suite-unit/QuestionTest.php +++ /dev/null @@ -1,82 +0,0 @@ - [ - 'input' => [ - 'fieldtype' => 'text', - 'name' => "here is a single quote (')", - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ], - ], - 'expected' => [ - 'fieldtype' => 'text', - 'name' => "here is a single quote (\')", - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ], - ] - ], - ]; - } - - /** - * @dataProvider inputProvider - * @param array $input - * @param array $expected - */ - public function testPrepareInputForAdd($input, $expected) { - $section = $this->getSection(); - $input[$section::getForeignKeyField()] = $section->getID(); - - $question = new PluginFormcreatorQuestion(); - $output = $question->prepareInputForAdd($input); - $this->assertEquals($expected['name'], $output['name'], json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); - $this->assertArrayHasKey('uuid', $output); - } - - /** - * @dataProvider inputProvider - * @param array $input - * @param array $expected - */ - public function testPrepareInputForUpdate($input, $expected) { - $section = $this->getSection(); - $input[$section::getForeignKeyField()] = $section->getID(); - - $question = new PluginFormcreatorQuestion(); - $output = $question->prepareInputForAdd($input); - $this->assertEquals($expected['name'], $output['name']); - } - - private function getSection() { - $form = new PluginFormcreatorForm(); - $form->add([ - 'name' => 'form' - ]); - $section = new PluginFormcreatorSection(); - $section->add([ - $form::getForeignKeyField() => $form->getID(), - 'name' => 'section', - ]); - return $section; - } -} \ No newline at end of file From 970de6a911c73c6ff95ef9450c04cf828aabff5b Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 9 Jul 2018 17:48:49 +0200 Subject: [PATCH 007/192] test: update tests Signed-off-by: btry --- inc/form.class.php | 5 +- inc/question.class.php | 9 + inc/section.class.php | 26 +- tests/0010_Integration/ExportImportTest.php | 383 ----------------- tests/src/CommonTestCase.php | 288 ++++++++++++- .../PluginFormcreatorForm.php | 391 ++++-------------- .../PluginFormcreatorQuestion.php | 70 +--- .../PluginFormcreatorSection.php | 25 +- .../PluginFormcreatorTargetTicket.php | 17 +- tests/suite-unit/PluginFormcreatorForm.php | 83 +++- .../PluginFormcreatorIntegerField.php | 2 +- .../PluginFormcreatorMultiSelectField.php | 18 +- .../suite-unit/PluginFormcreatorQuestion.php | 7 +- .../PluginFormcreatorQuestion_Condition.php | 12 +- tests/suite-unit/PluginFormcreatorSection.php | 26 +- 15 files changed, 535 insertions(+), 827 deletions(-) delete mode 100644 tests/0010_Integration/ExportImportTest.php diff --git a/inc/form.class.php b/inc/form.class.php index dd9bceb6a..74a2c4238 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1352,13 +1352,14 @@ public function duplicate() { } } + // TODO: duplicates code in Question::duplicate() // Form questions parameters foreach ($tab_questions as $questions_id => $new_questions_id) { $oldQuestion = new PluginFormcreatorQuestion(); $oldQuestion->getFromDB($questions_id); $fieldType = 'PluginFormcreator' . ucfirst($oldQuestion->fields['fieldtype']) . 'Field'; - $this->field = new $fieldType($oldQuestion->fields); - $parameters = $this->field->getUsedParameters(); + $field = new $fieldType($oldQuestion->fields); + $parameters = $field->getUsedParameters(); foreach ($parameters as $fieldName => $parameter) { $parameter->getFromDBByCrit([ 'plugin_formcreator_questions_id' => $questions_id, diff --git a/inc/question.class.php b/inc/question.class.php index a224a6504..cabaa03fc 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -560,6 +560,7 @@ public function moveDown() { /** * Updates the conditions of the question * @param array $input + * @return boolean true if success, false otherwise */ public function updateConditions($input) { // Delete all existing conditions for the question @@ -592,11 +593,17 @@ public function updateConditions($input) { 'show_logic' => $showLogic, 'order' => $order, ]); + if ($question_condition->isNewItem()) { + return false; + } } + return true; } } } } + + return false; } /** @@ -1319,6 +1326,8 @@ public function duplicate() { $row = $this->fields; unset($row['id'], $row['uuid']); + + $row['_skip_checks'] = true; $newQuestion_id = $newQuestion->add($row); if ($newQuestion_id === false) { return false; diff --git a/inc/section.class.php b/inc/section.class.php index 638610f8d..acbc82ce4 100644 --- a/inc/section.class.php +++ b/inc/section.class.php @@ -209,18 +209,20 @@ public function duplicate() { } // Form questions conditions - $questionIds = implode("', '", array_keys($tab_questions)); - $rows = $question_condition->find("`plugin_formcreator_questions_id` IN ('$questionIds')"); - foreach ($rows as $row) { - unset($row['id'], - $row['uuid']); - if (isset($tab_questions[$row['show_field']])) { - // update show_field if id in show_field belongs to the section being duplicated - $row['show_field'] = $tab_questions[$row['show_field']]; - } - $row['plugin_formcreator_questions_id'] = $tab_questions[$row['plugin_formcreator_questions_id']]; - if (!$question_condition->add($row)) { - return false; + if (count($tab_questions) > 0) { + $questionIds = implode("', '", array_keys($tab_questions)); + $rows = $question_condition->find("`plugin_formcreator_questions_id` IN ('$questionIds')"); + foreach ($rows as $row) { + unset($row['id'], + $row['uuid']); + if (isset($tab_questions[$row['show_field']])) { + // update show_field if id in show_field belongs to the section being duplicated + $row['show_field'] = $tab_questions[$row['show_field']]; + } + $row['plugin_formcreator_questions_id'] = $tab_questions[$row['plugin_formcreator_questions_id']]; + if (!$question_condition->add($row)) { + return false; + } } } diff --git a/tests/0010_Integration/ExportImportTest.php b/tests/0010_Integration/ExportImportTest.php deleted file mode 100644 index b13df8dee..000000000 --- a/tests/0010_Integration/ExportImportTest.php +++ /dev/null @@ -1,383 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class ExportImporTest extends SuperAdminTestCase { - public static function setUpBeforeClass() { - parent::setupBeforeClass(); - - self::login('glpi', 'glpi'); - - // instanciate classes - $form = new PluginFormcreatorForm; - $form_section = new PluginFormcreatorSection; - $form_question = new PluginFormcreatorQuestion; - $form_condition = new PluginFormcreatorQuestion_Condition; - $form_validator = new PluginFormcreatorForm_Validator; - $form_target = new PluginFormcreatorTarget; - $form_profile = new PluginFormcreatorForm_Profile; - $targetTicket = new PluginFormcreatorTargetTicket(); - $item_targetTicket = new PluginFormcreatorItem_TargetTicket(); - - // create objects - $forms_id = $form->add(['name' => "test export form", - 'is_active' => true, - 'validation_required' => PluginFormcreatorForm_Validator::VALIDATION_USER]); - - $sections_id = $form_section->add(['name' => "test export section", - 'plugin_formcreator_forms_id' => $forms_id]); - - $questions_id_1 = $form_question->add([ - 'name' => "test export question 1", - 'fieldtype' => 'text', - 'plugin_formcreator_sections_id' => $sections_id, - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ], - ]); - $questions_id_2 = $form_question->add([ - 'name' => "test export question 2", - 'fieldtype' => 'textarea', - 'plugin_formcreator_sections_id' => $sections_id, - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ], - ]); - - $form_condition->add(['plugin_formcreator_questions_id' => $questions_id_1, - 'show_field' => $questions_id_2, - 'show_condition' => '==', - 'show_value' => 'test']); - - $form_validator->add(['plugin_formcreator_forms_id' => $forms_id, - 'itemtype' => 'User', - 'items_id' => 2]); - $form_validator->add(['plugin_formcreator_forms_id' => $forms_id, - 'itemtype' => 'User', - 'items_id' => 3]); - - $targets_id = $form_target->add(['plugin_formcreator_forms_id' => $forms_id, - 'itemtype' => PluginFormcreatorTargetTicket::class, - 'name' => "test export target"]); - - $targetTicket_id = $targetTicket->add(['name' => $form_target->getField('name'), - ]); - - $form_target->getFromDB($targets_id); - $targettickets_id = $form_target->fields['items_id']; - - $form_profiles_id = $form_profile->add(['plugin_formcreator_forms_id' => $forms_id, - 'profiles_id' => 1]); - - $item_targetTicket->add(['plugin_formcreator_targettickets_id' => $targetTicket_id, - 'link' => Ticket_Ticket::LINK_TO, - 'itemtype' => $form_target->getField('itemtype'), - 'items_id' => $targets_id - ]); - } - - /** - * @cover PluginFormcreatorForm::export - */ - public function testExportForm() { - $form = new PluginFormcreatorForm; - plugin_formcreator_getFromDBByField($form, 'name', "test export form"); - $export = $form->export(); - - $this->assertArrayNotHasKey('id', $export); - $this->assertArrayNotHasKey('plugin_formcreator_categories_id', $export); - $this->assertArrayNotHasKey('entities_id', $export); - $this->assertArrayNotHasKey('usage_count', $export); - $this->assertArrayHasKey('is_recursive', $export); - $this->assertArrayHasKey('access_rights', $export); - $this->assertArrayHasKey('requesttype', $export); - $this->assertArrayHasKey('name', $export); - $this->assertArrayHasKey('description', $export); - $this->assertArrayHasKey('content', $export); - $this->assertArrayHasKey('is_active', $export); - $this->assertArrayHasKey('language', $export); - $this->assertArrayHasKey('helpdesk_home', $export); - $this->assertArrayHasKey('is_deleted', $export); - $this->assertArrayHasKey('validation_required', $export); - $this->assertArrayHasKey('is_default', $export); - $this->assertArrayHasKey('uuid', $export); - $this->assertArrayHasKey('_sections', $export); - $this->assertArrayHasKey('_validators', $export); - $this->assertArrayHasKey('_targets', $export); - $this->assertArrayHasKey('_profiles', $export); - - foreach ($export["_sections"] as $section) { - $this->_checkSection($section); - } - - foreach ($export["_validators"] as $validator) { - $this->_checkValidator($validator); - } - - foreach ($export["_targets"] as $target) { - $this->_checkTarget($target); - } - - foreach ($export["_profiles"] as $form_profile) { - $this->_checkFormProfile($form_profile); - } - - return $export; - } - - /** - * @cover PluginFormcreatorSection::export - */ - public function testExportSection() { - $section = new PluginFormcreatorSection; - plugin_formcreator_getFromDBByField($section, 'name', "test export section"); - $export = $section->export(); - $this->_checkSection($export); - - return $export; - } - - /** - * @cover PluginFormcreatorQuestion::export - */ - public function testExportQuestion() { - $question = new PluginFormcreatorQuestion; - plugin_formcreator_getFromDBByField($question, 'name', "test export question 1"); - $export = $question->export(); - $this->_checkQuestion($export); - - plugin_formcreator_getFromDBByField($question, 'name', "test export question 2"); - $export = $question->export(); - $this->_checkQuestion($export); - - return $export; - } - - /** - * @cover PluginFormcreatorTarget::export - */ - public function testExportTarget() { - $target = new PluginFormcreatorTarget; - plugin_formcreator_getFromDBByField($target, 'name', "test export target"); - $export = $target->export(); - $this->_checkTarget($export); - - return $export; - } - - /** - * @cover PluginFormcreatorForm::import - * @depends testExportForm - */ - public function testImportForm($export = []) { - $importLinker = new PluginFormcreatorImportLinker(); - $forms_id = PluginFormcreatorForm::import($importLinker, $export); - - $this->assertNotFalse($forms_id); - - return $forms_id; - } - - /** - * @cover PluginFormcreatorSection::import - * @depends testImportForm - * @depends testExportSection - */ - public function testImportSection($forms_id, $export = []) { - $importLinker = new PluginFormcreatorImportLinker(); - $sections_id = PluginFormcreatorSection::import($importLinker, $forms_id, $export); - - $this->assertNotFalse($sections_id); - - return $sections_id; - } - - /** - * @cover PluginFormcreatorQuestion::import - * @depends testImportSection - * @depends testExportQuestion - */ - public function testImportQuestion($sections_id, $export = []) { - $importLinker = new PluginFormcreatorImportLinker(); - $questions_id = PluginFormcreatorQuestion::import($importLinker, $sections_id, $export); - - $this->assertNotFalse($questions_id); - - return $questions_id; - } - - /** - * @cover PluginFormcreatorTarget::import - * @depends testImportForm - * @depends testExportTarget - */ - public function testImportTarget($forms_id, $export = []) { - $targets_id = PluginFormcreatorTarget::import($forms_id, $export); - - $this->assertNotFalse($targets_id); - - return $targets_id; - } - - public function _checkSection($section = []) { - $this->assertArrayNotHasKey('id', $section); - $this->assertArrayNotHasKey('plugin_formcreator_forms_id', $section); - $this->assertArrayHasKey('name', $section); - $this->assertArrayHasKey('order', $section); - $this->assertArrayHasKey('uuid', $section); - $this->assertArrayHasKey('_questions', $section); - - foreach ($section["_questions"] as $question) { - $this->_checkQuestion($question); - } - } - - public function _checkQuestion($question = []) { - $this->assertArrayNotHasKey('id', $question); - $this->assertArrayNotHasKey('plugin_formcreator_sections_id', $question); - $this->assertArrayHasKey('fieldtype', $question); - $this->assertArrayHasKey('name', $question); - $this->assertArrayHasKey('required', $question); - $this->assertArrayHasKey('required', $question); - $this->assertArrayHasKey('show_empty', $question); - $this->assertArrayHasKey('default_values', $question); - $this->assertArrayHasKey('values', $question); - $this->assertArrayHasKey('range_min', $question); - $this->assertArrayHasKey('range_max', $question); - $this->assertArrayHasKey('range_max', $question); - $this->assertArrayHasKey('description', $question); - $this->assertArrayHasKey('regex', $question); - $this->assertArrayHasKey('regex', $question); - $this->assertArrayHasKey('order', $question); - $this->assertArrayHasKey('show_rule', $question); - $this->assertArrayHasKey('uuid', $question); - $this->assertArrayHasKey('_conditions', $question); - - foreach ($question["_conditions"] as $condition) { - $this->_checkCondition($condition); - } - } - - public function _checkCondition($condition = []) { - $this->assertArrayNotHasKey('id', $condition); - $this->assertArrayNotHasKey('plugin_formcreator_questions_id', $condition); - $this->assertArrayHasKey('show_field', $condition); - $this->assertArrayHasKey('show_condition', $condition); - $this->assertArrayHasKey('show_value', $condition); - $this->assertArrayHasKey('show_logic', $condition); - $this->assertArrayHasKey('uuid', $condition); - } - - public function _checkValidator($validator = []) { - $this->assertArrayNotHasKey('id', $validator); - $this->assertArrayNotHasKey('plugin_formcreator_forms_id', $validator); - $this->assertArrayNotHasKey('items_id', $validator); - $this->assertArrayHasKey('itemtype', $validator); - $this->assertArrayHasKey('_item', $validator); - $this->assertArrayHasKey('uuid', $validator); - } - - public function _checkTarget($target = []) { - $this->assertArrayNotHasKey('id', $target); - $this->assertArrayNotHasKey('plugin_formcreator_forms_id', $target); - $this->assertArrayNotHasKey('items_id', $target); - $this->assertArrayHasKey('itemtype', $target); - $this->assertArrayHasKey('_data', $target); - $this->assertArrayHasKey('_actors', $target['_data']); - $this->assertArrayHasKey('uuid', $target); - - if ($target['itemtype'] == 'PluginFormcreatorTargetTicket') { - $this->_checkTargetTicket($target['_data']); - } - - foreach ($target["_data"]['_actors'] as $actor) { - $this->_checkActor($actor); - } - } - - public function _checkTargetTicket($targetticket = []) { - $this->assertArrayNotHasKey('id', $targetticket); - $this->assertArrayNotHasKey('tickettemplates_id', $targetticket); - $this->assertArrayHasKey('title', $targetticket); - $this->assertArrayHasKey('comment', $targetticket); - $this->assertArrayHasKey('due_date_rule', $targetticket); - $this->assertArrayHasKey('due_date_question', $targetticket); - $this->assertArrayHasKey('due_date_value', $targetticket); - $this->assertArrayHasKey('due_date_period', $targetticket); - $this->assertArrayHasKey('urgency_rule', $targetticket); - $this->assertArrayHasKey('urgency_question', $targetticket); - $this->assertArrayHasKey('validation_followup', $targetticket); - $this->assertArrayHasKey('destination_entity', $targetticket); - $this->assertArrayHasKey('destination_entity', $targetticket); - $this->assertArrayHasKey('destination_entity_value', $targetticket); - $this->assertArrayHasKey('tag_type', $targetticket); - $this->assertArrayHasKey('tag_questions', $targetticket); - $this->assertArrayHasKey('tag_specifics', $targetticket); - } - - public function _checkActor($actor = []) { - $this->assertArrayNotHasKey('id', $actor); - $this->assertArrayNotHasKey('plugin_formcreator_targettickets_id', $actor); - $this->assertArrayHasKey('actor_role', $actor); - $this->assertArrayHasKey('actor_type', $actor); - //we should have only one of theses keys : actor_value ,_question ,_user ,_group ,_supplier - $actor_value_found_keys = preg_grep('/((actor_value)|(_question)|(_user)|(_group)|(_supplier))/', - array_keys($actor)); - $this->assertCount(1, $actor_value_found_keys); - $this->assertArrayHasKey('use_notification', $actor); - $this->assertArrayHasKey('uuid', $actor); - } - - public function _checkFormProfile($form_profile = []) { - $this->assertArrayNotHasKey('id', $form_profile); - $this->assertArrayNotHasKey('plugin_formcreator_forms_id', $form_profile); - $this->assertArrayNotHasKey('profiles_id', $form_profile); - $this->assertArrayHasKey('_profile', $form_profile); - $this->assertArrayHasKey('uuid', $form_profile); - } -} \ No newline at end of file diff --git a/tests/src/CommonTestCase.php b/tests/src/CommonTestCase.php index 4a0f863ac..8231df9fc 100644 --- a/tests/src/CommonTestCase.php +++ b/tests/src/CommonTestCase.php @@ -155,11 +155,17 @@ protected function restartSession() { } } - protected function getSection() { + protected function getForm() { $form = new \PluginFormcreatorForm(); $form->add([ 'name' => 'form' ]); + + return $form; + } + + protected function getSection() { + $form = $this->getForm(); $section = new \PluginFormcreatorSection(); $section->add([ $form::getForeignKeyField() => $form->getID(), @@ -168,4 +174,284 @@ protected function getSection() { return $section; } + protected function getQuestion() { + $section = $this->getSection(); + $question = new \PluginFormcreatorQuestion(); + $question->add([ + 'name' => 'question', + 'plugin_formcreator_sections_id' => $section->getID(), + 'fieldtype' => 'text', + 'values' => "", + 'required' => '0', + 'show_empty' => '0', + 'default_values' => '', + 'desription' => '', + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ]); + + return $question; + } + + protected function _checkForm($form = []) { + $this->assertArrayNotHasKey('id', $export); + $this->assertArrayNotHasKey('plugin_formcreator_categories_id', $export); + $this->assertArrayNotHasKey('entities_id', $export); + $this->assertArrayNotHasKey('usage_count', $export); + $this->assertArrayHasKey('is_recursive', $export); + $this->assertArrayHasKey('access_rights', $export); + $this->assertArrayHasKey('requesttype', $export); + $this->assertArrayHasKey('name', $export); + $this->assertArrayHasKey('description', $export); + $this->assertArrayHasKey('content', $export); + $this->assertArrayHasKey('is_active', $export); + $this->assertArrayHasKey('language', $export); + $this->assertArrayHasKey('helpdesk_home', $export); + $this->assertArrayHasKey('is_deleted', $export); + $this->assertArrayHasKey('validation_required', $export); + $this->assertArrayHasKey('is_default', $export); + $this->assertArrayHasKey('uuid', $export); + $this->assertArrayHasKey('_sections', $export); + $this->assertArrayHasKey('_validators', $export); + $this->assertArrayHasKey('_targets', $export); + $this->assertArrayHasKey('_profiles', $export); + } + + protected function _checkSection($section = []) { + $keys = [ + 'name', + 'order', + 'uuid', + '_questions', + ]; + $this->array($section)->notHasKeys([ + 'id', + 'plugin_formcreator_forms_id', + ]); + $this->array($section) + ->hasKeys($keys) + ->size->isEqualTo(count($keys)); + + foreach ($section["_questions"] as $question) { + $this->_checkQuestion($question); + } + } + + protected function _checkQuestion($question = []) { + $keys = [ + 'fieldtype', + 'name', + 'required', + 'show_empty', + 'default_values', + 'values', + 'range_min', + 'range_max', + 'description', + 'regex', + 'order', + 'show_rule', + 'uuid', + '_conditions', + ]; + + $this->array($question)->notHasKeys([ + 'id', + 'plugin_formcreator_sections_id', + ])->hasKeys($keys) + ->size->isEqualTo(count($keys));; + + foreach ($question["_conditions"] as $condition) { + $this->_checkCondition($condition); + } + } + + protected function _checkCondition($condition = []) { + $keys = [ + 'show_field', + 'show_condition', + 'show_value', + 'show_logic', + 'order', + 'uuid', + ]; + + $this->array($condition)->notHasKeys([ + 'id', + 'plugin_formcreator_questions_id', + ])->hasKeys($keys) + ->size->isEqualTo(count($keys)); + } + + protected function _checkValidator($validator = []) { + $this->array($validator)->notHasKeys([ + 'id', + 'plugin_formcreator_forms_id', + 'items_id', + ])->hasKeys([ + 'itemtype', + '_item', + 'uuid', + ]); + } + + protected function _checkTarget($target = []) { + $this->array($target)->notHasKeys([ + 'id', + 'plugin_formcreator_forms_id', + 'items_id', + ])->hasKeys([ + 'itemtype', + '_data', + 'uuid', + ]); + $this->array($target['_data'])->hasKeys(['_actors']); + + if ($target['itemtype'] === \PluginFormcreatorTargetTicket::class) { + $this->_checkTargetTicket($target['_data']); + } + + foreach ($target["_data"]['_actors'] as $actor) { + $this->_checkActor($actor); + } + } + + protected function _checkTargetTicket($targetticket = []) { + $keys = [ + 'title', + 'comment', + 'due_date_rule', + 'due_date_question', + 'due_date_value', + 'due_date_period', + 'urgency_rule', + 'urgency_question', + 'location_rule', + 'location_question', + 'validation_followup', + 'destination_entity', + 'destination_entity_value', + 'tag_type', + 'tag_questions', + 'tag_specifics', + 'category_rule', + 'category_question', + '_actors', + '_ticket_relations', + ]; + $this->array($targetticket)->notHasKeys([ + 'id', + 'tickettemplates_id', + ])->hasKeys($keys) + ->size->isEqualTo(count($keys)); + } + + protected function _checkActor($actor = []) { + $this->array($actor)->notHasKeys([ + 'id', + 'plugin_formcreator_targettickets_id', + ])->hasKeys([ + 'use_notification', + 'uuid', + ]); + //we should have only one of theses keys : actor_value ,_question ,_user ,_group ,_supplier + $actor_value_found_keys = preg_grep('/((actor_value)|(_question)|(_user)|(_group)|(_supplier))/', + array_keys($actor)); + $this->array($actor_value_found_keys)->size->isEqualTo(1); + + } + + protected function _checkFormProfile($form_profile = []) { + $this->array($form_profile)->notHasKeys([ + 'id', + 'plugin_formcreator_forms_id', + 'profiles_id' + ])->hasKeys([ + '_profile', + 'uuid', + ]); + } + + /** + * Create a whole form + * Method incomplete, some new things needs to be implemented + */ + protected function createFullForm( + $formData, + $sectionsData, + $targetsData + ) { + $form = new \PluginFormcreatorForm(); + $formId = $form->add($formData); + $this->boolean($form->isNewItem())->isFalse(); + + $sections = []; + $questions = []; + foreach ($sectionsData as $sectionData) { + // Keep questions data set apart from sections data + $questionsData = $sectionData['questions']; + unset($sectionData['questions']); + + // Create section + $sectionData['plugin_formcreator_forms_id'] = $form->getID(); + $section = new \PluginFormcreatorSection(); + $section->add($sectionData); + $this->boolean($section->isNewItem())->isFalse(); + $sections[] = $section; + $sectionId = $section->getID(); + foreach ($questionsData as $questionData) { + // Create question + $questionData ['plugin_formcreator_sections_id'] = $section->getID(); + $question = new \PluginFormcreatorQuestion(); + $question->add($questionData); + $this->boolean($question->isNewItem())->isFalse(json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); + $question->updateParameters($questionData); + $questions[] = $question; + $questionData['id'] = $question->getID(); + if (isset($questionData['show_rule']) && $questionData['show_rule'] != 'always') { + $showFields = []; + foreach ($questionData['show_field'] as $showFieldName) { + $showfield = new \PluginFormcreatorQuestion(); + $showfield->getFromDBByCrit([ + 'AND' => [ + 'plugin_formcreator_sections_id' => $sectionId, + 'name' => $showFieldName + ] + ]); + $this->boolean($showfield->isNewItem())->isFalse(); + $showFields[] = $showfield->getID(); + } + $questionData['show_field'] = $showFields; + $success = $question->updateConditions($questionData); + $this->boolean($success)->isTrue(); + } + } + } + $targets = []; + foreach ($targetsData as $targetData) { + $target = new \PluginFormcreatorTarget(); + $targetData['plugin_formcreator_forms_id'] = $formId; + $target->add($targetData); + $this->boolean($target->isNewItem())->isFalse(); + $targets[] = $target; + } + + return [ + $form, + $sections, + $questions, + $targets, + ]; + } } diff --git a/tests/suite-integration/PluginFormcreatorForm.php b/tests/suite-integration/PluginFormcreatorForm.php index 64a434f3e..2b9bd6142 100644 --- a/tests/suite-integration/PluginFormcreatorForm.php +++ b/tests/suite-integration/PluginFormcreatorForm.php @@ -8,14 +8,14 @@ public function setUp() { parent::setUp(); // instanciate classes - $form = new \PluginFormcreatorForm; - $form_section = new \PluginFormcreatorSection; - $form_question = new \PluginFormcreatorQuestion; - $form_condition = new \PluginFormcreatorQuestion_Condition; - $form_validator = new \PluginFormcreatorForm_Validator; - $form_target = new \PluginFormcreatorTarget; - $form_profile = new \PluginFormcreatorForm_Profile; - $targetTicket = new \PluginFormcreatorTargetTicket(); + $form = new \PluginFormcreatorForm; + $form_section = new \PluginFormcreatorSection; + $form_question = new \PluginFormcreatorQuestion; + $form_condition = new \PluginFormcreatorQuestion_Condition; + $form_validator = new \PluginFormcreatorForm_Validator; + $form_target = new \PluginFormcreatorTarget; + $form_profile = new \PluginFormcreatorForm_Profile; + $targetTicket = new \PluginFormcreatorTargetTicket(); $item_targetTicket = new \PluginFormcreatorItem_TargetTicket(); // create objects @@ -75,268 +75,8 @@ public function beforeTestMethod($method) { } /** - * @cover PluginFormcreatorForm::export + * */ - public function testExportImportForm() { - // Export the form - $form = new \PluginFormcreatorForm; - plugin_formcreator_getFromDBByField($form, 'name', "test export form"); - $this->boolean($form->isNewItem())->isFalse(); - $export = $form->export(); - - $this->array($export)->notHasKeys([ - 'id', - 'plugin_formcreator_categories_id', - 'entities_id', - 'usage_count', - ])->hasKeys([ - 'is_recursive', - 'access_rights', - 'is_recursive', - 'access_rights', - 'requesttype', - 'name', - 'description', - 'content', - 'is_active', - 'language', - 'helpdesk_home', - 'is_deleted', - 'validation_required', - 'is_default', - 'uuid', - '_sections', - '_validators', - '_targets', - '_profiles', - ]); - - foreach ($export["_sections"] as $section) { - $this->_checkSection($section); - } - - foreach ($export["_validators"] as $validator) { - $this->_checkValidator($validator); - } - - foreach ($export["_targets"] as $target) { - $this->_checkTarget($target); - } - - foreach ($export["_profiles"] as $form_profile) { - $this->checkFormProfile($form_profile); - } - - // Test import form - $forms_id = \PluginFormcreatorForm::import($export); - - $this->variable($forms_id)->isNotFalse(); - } - - public function testExportImportSection() { - // Export a section - $section = new \PluginFormcreatorSection; - plugin_formcreator_getFromDBByField($section, 'name', "test export section"); - $export = $section->export(); - $this->_checkSection($export); - - // Import a section - $form = new \PluginFormcreatorForm; - plugin_formcreator_getFromDBByField($form, 'name', "test export form"); - $sections_id = \PluginFormcreatorSection::import($form->getID(), $export); - $this->variable($sections_id)->isNotFalse(); - } - - public function testExportImportQuestion() { - // Export a question - $question = new \PluginFormcreatorQuestion; - plugin_formcreator_getFromDBByField($question, 'name', "test export question 1"); - $export = $question->export(); - $this->_checkQuestion($export); - - plugin_formcreator_getFromDBByField($question, 'name', "test export question 2"); - $export = $question->export(); - $this->_checkQuestion($export); - - // Import a question - $section = new \PluginFormcreatorSection; - plugin_formcreator_getFromDBByField($section, 'name', "test export section"); - $questions_id = \PluginFormcreatorQuestion::import($section->getID(), $export); - $this->variable($questions_id)->isNotFalse(); - } - - public function testExportImportTarget() { - // Export a target - $target = new \PluginFormcreatorTarget; - plugin_formcreator_getFromDBByField($target, 'name', "test export target"); - $export = $target->export(); - $this->_checkTarget($export); - - // Import a target - $form = new \PluginFormcreatorForm; - plugin_formcreator_getFromDBByField($form, 'name', "test export form"); - $targets_id = \PluginFormcreatorTarget::import($form->getID(), $export); - - $this->variable($targets_id)->isNotFalse(); - - return $targets_id; - } - - public function _checkSection($section = []) { - $keys = [ - 'name', - 'order', - 'uuid', - '_questions', - ]; - $this->array($section)->notHasKeys([ - 'id', - 'plugin_formcreator_forms_id', - ]); - $this->array($section) - ->hasKeys($keys) - ->size->isEqualTo(count($keys)); - - foreach ($section["_questions"] as $question) { - $this->_checkQuestion($question); - } - } - - public function _checkQuestion($question = []) { - $keys = [ - 'fieldtype', - 'name', - 'required', - 'show_empty', - 'default_values', - 'values', - 'range_min', - 'range_max', - 'description', - 'regex', - 'order', - 'show_rule', - 'uuid', - '_conditions', - ]; - - $this->array($question)->notHasKeys([ - 'id', - 'plugin_formcreator_sections_id', - ])->hasKeys($keys) - ->size->isEqualTo(count($keys));; - - foreach ($question["_conditions"] as $condition) { - $this->_checkCondition($condition); - } - } - - public function _checkCondition($condition = []) { - $keys = [ - 'show_field', - 'show_condition', - 'show_value', - 'show_logic', - 'order', - 'uuid', - ]; - - $this->array($condition)->notHasKeys([ - 'id', - 'plugin_formcreator_questions_id', - ])->hasKeys($keys) - ->size->isEqualTo(count($keys)); - } - - public function _checkValidator($validator = []) { - $this->array($validator)->notHasKeys([ - 'id', - 'plugin_formcreator_forms_id', - 'items_id', - ])->hasKeys([ - 'itemtype', - '_item', - 'uuid', - ]); - } - - public function _checkTarget($target = []) { - $this->array($target)->notHasKeys([ - 'id', - 'plugin_formcreator_forms_id', - 'items_id', - ])->hasKeys([ - 'itemtype', - '_data', - 'uuid', - ]); - $this->array($target['_data'])->hasKeys(['_actors']); - - if ($target['itemtype'] === \PluginFormcreatorTargetTicket::class) { - $this->_checkTargetTicket($target['_data']); - } - - foreach ($target["_data"]['_actors'] as $actor) { - $this->_checkActor($actor); - } - } - - public function _checkTargetTicket($targetticket = []) { - $keys = [ - 'title', - 'comment', - 'due_date_rule', - 'due_date_question', - 'due_date_value', - 'due_date_period', - 'urgency_rule', - 'urgency_question', - 'location_rule', - 'location_question', - 'validation_followup', - 'destination_entity', - 'destination_entity_value', - 'tag_type', - 'tag_questions', - 'tag_specifics', - 'category_rule', - 'category_question', - '_actors', - '_ticket_relations', - ]; - $this->array($targetticket)->notHasKeys([ - 'id', - 'tickettemplates_id', - ])->hasKeys($keys) - ->size->isEqualTo(count($keys)); - } - - public function _checkActor($actor = []) { - $this->array($actor)->notHasKeys([ - 'id', - 'plugin_formcreator_targettickets_id', - ])->hasKeys([ - 'use_notification', - 'uuid', - ]); - //we should have only one of theses keys : actor_value ,_question ,_user ,_group ,_supplier - $actor_value_found_keys = preg_grep('/((actor_value)|(_question)|(_user)|(_group)|(_supplier))/', - array_keys($actor)); - $this->array($actor_value_found_keys)->size->isEqualTo(1); - - } - - public function checkFormProfile($form_profile = []) { - $this->array($form_profile)->notHasKeys([ - 'id', - 'plugin_formcreator_forms_id', - 'profiles_id' - ])->hasKeys([ - '_profile', - 'uuid', - ]); - } - public function testDuplicateForm() { $formData = [ 'entities_id' => $_SESSION['glpiactive_entity'], @@ -347,17 +87,39 @@ public function testDuplicateForm() { 'validation_required' => 0 ]; - $sectionData = [ + $sectionsData = [ [ 'name' => 'a section', 'questions' => [ [ 'name' => 'text question', - 'fieldtype' => 'text' + 'fieldtype' => 'text', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], ], [ 'name' => 'other text question', - 'fieldtype' => 'text' + 'fieldtype' => 'text', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '', + ] + ] + ], ], ], ], @@ -366,21 +128,44 @@ public function testDuplicateForm() { 'questions' => [ [ 'name' => 'text question', - 'fieldtype' => 'text' + 'fieldtype' => 'text', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], ], [ 'name' => 'other text question', 'fieldtype' => 'text', 'show_rule' => 'hidden', - 'show_field' => 'text question', - 'show_condition' => '==', - 'show_value' => 'azerty', + 'show_field' => ['text question'], + 'show_condition' => ['=='], + 'show_value' => ['azerty'], + 'show_logic' => ['AND'], + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], ], ], ], ]; - $targetData = [ + $targetsData = [ [ 'name' => 'target ticket 1', 'itemtype' => 'PluginFormcreatorTargetTicket', @@ -391,49 +176,15 @@ public function testDuplicateForm() { ] ]; - $form = new \PluginFormcreatorForm(); - $formId = $form->add($formData); - $this->boolean($form->isNewItem())->isFalse(); - - foreach ($sectionData as $sectionData) { - // Keep questions data set apart from sections data - $questionsData = $sectionData['questions']; - unset($sectionData['questions']); - - // Create section - $sectionData['plugin_formcreator_forms_id'] = $form->getID(); - $section = new \PluginFormcreatorSection(); - $section->add($sectionData); - $this->boolean($section->isNewItem())->isFalse(); - $sectionId = $section->getID(); - foreach ($questionsData as $questionData) { - // Create question - $questionData ['plugin_formcreator_sections_id'] = $section->getID(); - $question = new \PluginFormcreatorQuestion(); - $question->add($questionData); - $this->boolean($question->isNewItem(), $_SESSION['MESSAGE_AFTER_REDIRECT'])->isFalse(); - - $questionData['id'] = $question->getID(); - if (isset($questionData['show_rule']) && $questionData['show_rule'] != 'always') { - $showFieldName = $questionData['show_field']; - $showfield = new \PluginFormcreatorQuestion(); - $showfield->getFromDBByCrit([ - 'AND' => [ - 'plugin_formcreator_sections_id' => $sectionId, - 'name' => $showFieldName - ] - ]); - $questionData['show_field'] = $showfield->getID(); - $question->updateConditions($questionData); - } - } - foreach ($targetData as $targetDataItem) { - $target = new \PluginFormcreatorTarget(); - $targetDataItem['plugin_formcreator_forms_id'] = $formId; - $target->add($targetDataItem); - $this->boolean($target->isNewItem())->isFalse(); - } - } + list($form, + $sections, + $questions, + $targets + ) = $this->createFullForm( + $formData, + $sectionsData, + $targetsData + ); $sourceFormId = $form->getID(); $this->boolean($form->duplicate())->isTrue(); diff --git a/tests/suite-integration/PluginFormcreatorQuestion.php b/tests/suite-integration/PluginFormcreatorQuestion.php index 98f8311dc..336cbe9a3 100644 --- a/tests/suite-integration/PluginFormcreatorQuestion.php +++ b/tests/suite-integration/PluginFormcreatorQuestion.php @@ -4,12 +4,6 @@ class PluginFormcreatorQuestion extends CommonTestCase { - private $formData = null; - - private $sectionData = null; - - private $questionTextData = null; - public function beforeTestMethod($method) { parent::beforeTestMethod($method); switch ($method) { @@ -19,77 +13,27 @@ public function beforeTestMethod($method) { } } - public function testCreateQuestionText() { - $this->formData = [ - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'a form', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 0 - ]; - - $this->sectionData = [ - 'name' => 'a section', - ]; - - $this->questionTextData = [ - 'name' => 'text question', - 'fieldtype' => 'text' - ]; - - $form = new \PluginFormcreatorForm(); - $form->add($this->formData); - $this->boolean($form->isNewItem())->isFalse(); - - $section = new \PluginFormcreatorSection(); - $this->sectionData = $this->sectionData + [ - 'plugin_formcreator_forms_id' => $form->getID() - ]; - $section->add($this->sectionData); - $this->boolean($section->isNewItem())->isFalse(); + public function testDuplicate() { + $section = $this->getSection(); $question = new \PluginFormcreatorQuestion(); - $this->questionTextData = $this->questionTextData + ['plugin_formcreator_sections_id' => $section->getID()]; - $question->add($this->questionTextData); - $this->boolean($question->isNewItem())->isFalse(); - - return $question; - } - - public function testCloneQuestion() { - $form = new \PluginFormcreatorForm; - $section = new \PluginFormcreatorSection; - $question = new \PluginFormcreatorQuestion; - - // create objects - $forms_id = $form->add(['name' => "test clone form", - 'is_active' => true, - 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER]); - - $sections_id = $section->add(['name' => "test clone section", - 'plugin_formcreator_forms_id' => $forms_id]); - $questions_id_1 = $question->add(['name' => "test clone question 1", 'fieldtype' => 'text', - 'plugin_formcreator_sections_id' => $sections_id, + 'plugin_formcreator_sections_id' => $section->getID(), '_parameters' => [ 'text' => [ - 'regex' => '', + 'regex' => ['regex' => ''], 'range' => ['min' => '', 'max' => ''], ] ], ]); - $new_question = new PluginFormcreatorQuestion; - - //get question - plugin_formcreator_getFromDBByField($question, 'name', "test clone question 1"); - //clone it - $this->boolean($question->duplicate())->isTrue(); + //clone the question + $this->integer($question->duplicate()); //get cloned section $originalId = $question->getID(); + $new_question = new \PluginFormcreatorQuestion(); $new_question->getFromDBByCrit([ 'AND' => [ 'name' => 'test clone question 1', diff --git a/tests/suite-integration/PluginFormcreatorSection.php b/tests/suite-integration/PluginFormcreatorSection.php index 8b2b8f524..da2c0f82c 100644 --- a/tests/suite-integration/PluginFormcreatorSection.php +++ b/tests/suite-integration/PluginFormcreatorSection.php @@ -75,27 +75,22 @@ public function testDelete() { * */ public function testDuplicate() { - $form = new \PluginFormcreatorForm; - $section = new \PluginFormcreatorSection; - $question = new \PluginFormcreatorQuestion; - - // create objects - $forms_id = $form->add(['name' => "test clone form", - 'is_active' => true, - 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER]); + $form = $this->getForm(); + $section = new \PluginFormcreatorSection(); + $question = new \PluginFormcreatorQuestion(); $sections_id = $section->add(['name' => "test clone section", - 'plugin_formcreator_forms_id' => $forms_id]); + 'plugin_formcreator_forms_id' => $form->getID()]); $questions_id_1 = $question->add(['name' => "test clone question 1", 'fieldtype' => 'text', 'plugin_formcreator_sections_id' => $sections_id, '_parameters' => [ 'text' => [ - 'regex' => '', + 'regex' => ['regex' => ''], 'range' => ['min' => '', 'max' => ''], ] - ], + ], ]); $questions_id_2 = $question->add(['name' => "test clone question 2", 'fieldtype' => 'textarea', @@ -103,7 +98,7 @@ public function testDuplicate() { ]); //clone it - $this->boolean($section->duplicate())->isTrue(); + $this->integer($section->duplicate()); //get cloned section $originalId = $section->getID(); @@ -118,8 +113,8 @@ public function testDuplicate() { $this->boolean($new_section->isNewItem())->isFalse(); // check questions - $all_questions = $form_question->find("plugin_formcreator_sections_id = ".$section->getID()); - $all_new_questions = $form_question->find("plugin_formcreator_sections_id = ".$new_section->getID()); + $all_questions = $question->find("plugin_formcreator_sections_id = ".$section->getID()); + $all_new_questions = $question->find("plugin_formcreator_sections_id = ".$new_section->getID()); $this->integer(count($all_new_questions))->isEqualTo(count($all_questions)); // check that all question uuid are new @@ -130,6 +125,6 @@ public function testDuplicate() { foreach ($all_new_questions as $question) { $new_uuids[] = $question['uuid']; } - $this->integer(count(array_diff($new_uuids, $uuids)))->isEqualTo(count($new_uuids); + $this->integer(count(array_diff($new_uuids, $uuids)))->isEqualTo(count($new_uuids)); } } diff --git a/tests/suite-integration/PluginFormcreatorTargetTicket.php b/tests/suite-integration/PluginFormcreatorTargetTicket.php index 4320a04f8..ae4865746 100644 --- a/tests/suite-integration/PluginFormcreatorTargetTicket.php +++ b/tests/suite-integration/PluginFormcreatorTargetTicket.php @@ -13,6 +13,9 @@ public function beforeTestMethod($method) { $this->login('glpi', 'glpi'); } + /** + * @engine inline + */ public function testTargetTicketActors() { $form = new \PluginFormcreatorForm(); $form->add([ @@ -90,11 +93,17 @@ public function testUrgency() { 'questions' => [ [ 'name' => 'text question', - 'fieldtype' => 'text' + 'fieldtype' => 'text', + '_parameters' => [ + 'text' => [ + 'regex' => ['regex' => ''], + 'range' => ['min' => '', 'max' => ''], + ] + ], ], [ 'name' => 'custom urgency', - 'fieldtype' => 'urgency' + 'fieldtype' => 'urgency', ], ], ], @@ -115,8 +124,8 @@ public function testUrgency() { $questionData ['plugin_formcreator_sections_id'] = $section->getID(); $question = new \PluginFormcreatorQuestion(); $question->add($questionData); - $this->boolean($question->isNewItem())->isFalse($_SESSION['MESSAGE_AFTER_REDIRECT']); - + $this->boolean($question->isNewItem())->isFalse(json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); + $question->updateParameters($questionData); $questionData['id'] = $question->getID(); if (isset($questionData['show_rule']) && $questionData['show_rule'] != 'always') { $showFieldName = $questionData['show_field']; diff --git a/tests/suite-unit/PluginFormcreatorForm.php b/tests/suite-unit/PluginFormcreatorForm.php index 5829d41a6..85c91cc36 100644 --- a/tests/suite-unit/PluginFormcreatorForm.php +++ b/tests/suite-unit/PluginFormcreatorForm.php @@ -104,10 +104,58 @@ public function testCreateValidationNotification() { /** * @cover PluginFormcreatorForm::export + * @engine inline */ public function testExportForm() { - $form = new \PluginFormcreatorForm; - plugin_formcreator_getFromDBByField($form, 'name', "test export form"); + // instanciate classes + $form = new \PluginFormcreatorForm; + $form_section = new \PluginFormcreatorSection; + $form_question = new \PluginFormcreatorQuestion; + $form_condition = new \PluginFormcreatorQuestion_Condition; + $form_validator = new \PluginFormcreatorForm_Validator; + $form_target = new \PluginFormcreatorTarget; + $form_profile = new \PluginFormcreatorForm_Profile; + $targetTicket = new \PluginFormcreatorTargetTicket(); + $item_targetTicket = new \PluginFormcreatorItem_TargetTicket(); + + // create objects + $forms_id = $form->add(['name' => "test export form", + 'is_active' => true, + 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER]); + $sections_id = $form_section->add(['name' => "test export section", + 'plugin_formcreator_forms_id' => $forms_id]); + $questions_id_1 = $form_question->add(['name' => "test export question 1", + 'fieldtype' => 'text', + 'plugin_formcreator_sections_id' => $sections_id]); + $questions_id_2 = $form_question->add(['name' => "test export question 2", + 'fieldtype' => 'textarea', + 'plugin_formcreator_sections_id' => $sections_id]); + $form_condition->add(['plugin_formcreator_questions_id' => $questions_id_1, + 'show_field' => $questions_id_2, + 'show_condition' => '==', + 'show_value' => 'test']); + $form_validator->add(['plugin_formcreator_forms_id' => $forms_id, + 'itemtype' => 'User', + 'items_id' => 2]); + $form_validator->add(['plugin_formcreator_forms_id' => $forms_id, + 'itemtype' => 'User', + 'items_id' => 3]); + $targets_id = $form_target->add(['plugin_formcreator_forms_id' => $forms_id, + 'itemtype' => \PluginFormcreatorTargetTicket::class, + 'name' => "test export target"]); + $targetTicket_id = $targetTicket->add(['name' => $form_target->getField('name'), + ]); + $form_target->getFromDB($targets_id); + $targettickets_id = $form_target->fields['items_id']; + $form_profiles_id = $form_profile->add(['plugin_formcreator_forms_id' => $forms_id, + 'profiles_id' => 1]); + $item_targetTicket->add(['plugin_formcreator_targettickets_id' => $targetTicket_id, + 'link' => \Ticket_Ticket::LINK_TO, + 'itemtype' => $form_target->getField('itemtype'), + 'items_id' => $targets_id + ]); + + $form->getFromDB($form->getID()); $export = $form->export(); $this->_checkForm($export); @@ -130,4 +178,35 @@ public function testExportForm() { return $export; } + + protected function _checkForm($form = []) { + $keys = [ + 'is_recursive', + 'access_rights', + 'requesttype', + 'name', + 'description', + 'content', + 'is_active', + 'language', + 'helpdesk_home', + 'is_deleted', + 'validation_required', + 'is_default', + 'uuid', + '_sections', + '_validators', + '_targets', + '_profiles', + ]; + $this->array($form)->notHasKeys([ + 'id', + 'plugin_formcreator_categories_id', + 'entities_id', + 'usage_count', + ]); + $this->array($form) + ->hasKeys($keys) + ->size->isEqualTo(count($keys)); + } } diff --git a/tests/suite-unit/PluginFormcreatorIntegerField.php b/tests/suite-unit/PluginFormcreatorIntegerField.php index 721dd9d43..4e5df50bb 100644 --- a/tests/suite-unit/PluginFormcreatorIntegerField.php +++ b/tests/suite-unit/PluginFormcreatorIntegerField.php @@ -203,7 +203,7 @@ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidi $section = $this->getSection(); $fields[$section::getForeignKeyField()] = $section->getID(); - $question = new PluginFormcreatorQuestion(); + $question = new \PluginFormcreatorQuestion(); $question->add($fields); $question->updateParameters($fields); diff --git a/tests/suite-unit/PluginFormcreatorMultiSelectField.php b/tests/suite-unit/PluginFormcreatorMultiSelectField.php index c48c5f485..90caed5c9 100644 --- a/tests/suite-unit/PluginFormcreatorMultiSelectField.php +++ b/tests/suite-unit/PluginFormcreatorMultiSelectField.php @@ -9,7 +9,7 @@ public function provider() { $dataset = [ [ 'fields' => [ - 'fieldtype' => 'select', + 'fieldtype' => 'multiselect', 'name' => 'question', 'required' => '0', 'show_empty' => '0', @@ -32,7 +32,7 @@ public function provider() { ], [ 'fields' => [ - 'fieldtype' => 'select', + 'fieldtype' => 'multiselect', 'name' => 'question', 'required' => '0', 'show_empty' => '0', @@ -55,7 +55,7 @@ public function provider() { ], [ 'fields' => [ - 'fieldtype' => 'select', + 'fieldtype' => 'multiselect', 'name' => 'question', 'required' => '0', 'show_empty' => '0', @@ -78,7 +78,7 @@ public function provider() { ], [ 'fields' => [ - 'fieldtype' => 'select', + 'fieldtype' => 'multiselect', 'name' => 'question', 'required' => '0', 'show_empty' => '0', @@ -101,7 +101,7 @@ public function provider() { ], [ 'fields' => [ - 'fieldtype' => 'select', + 'fieldtype' => 'multiselect', 'name' => 'question', 'required' => '0', 'show_empty' => '0', @@ -162,8 +162,10 @@ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidi $section = $this->getSection(); $fields[$section::getForeignKeyField()] = $section->getID(); - $question = new PluginFormcreatorQuestion(); + $question = new \PluginFormcreatorQuestion(); $question->add($fields); + // Re-load the question from the DB + $question->getFromDB($question->getID()); $question->updateParameters($fields); $fieldInstance = new \PluginFormcreatorMultiSelectField($question->fields, $data); @@ -194,11 +196,11 @@ public function testPrepareInputForSave() { $section = $this->getSection(); $fields[$section::getForeignKeyField()] = $section->getID(); - $question = new PluginFormcreatorQuestion(); + $question = new \PluginFormcreatorQuestion(); $question->add($fields); $question->updateParameters($fields); - $fieldInstance = new \PluginFormcreatorMultiSelectField($question->fields, $data); + $fieldInstance = new \PluginFormcreatorMultiSelectField($question->fields); // Test a value is mandatory $input = [ diff --git a/tests/suite-unit/PluginFormcreatorQuestion.php b/tests/suite-unit/PluginFormcreatorQuestion.php index b6c7f94fe..ac2af3d9e 100644 --- a/tests/suite-unit/PluginFormcreatorQuestion.php +++ b/tests/suite-unit/PluginFormcreatorQuestion.php @@ -65,17 +65,14 @@ public function beforeTestMethod($method) { * @cover PluginFormcreatorQuestion::clone */ public function testDuplicate() { - $question = new \PluginFormcreatorQuestion; - $new_question = new \PluginFormcreatorQuestion; - - //get question - plugin_formcreator_getFromDBByField($question, 'name', "test clone question 1"); + $question = $this->getQuestion(); //clone it $newQuestion_id = $question->duplicate(); $this->integer($newQuestion_id)->isGreaterThan(0); //get cloned section + $new_question = new \PluginFormcreatorQuestion; $new_question->getFromDB($newQuestion_id); // check uuid diff --git a/tests/suite-unit/PluginFormcreatorQuestion_Condition.php b/tests/suite-unit/PluginFormcreatorQuestion_Condition.php index c7bd0fdde..1d913563b 100644 --- a/tests/suite-unit/PluginFormcreatorQuestion_Condition.php +++ b/tests/suite-unit/PluginFormcreatorQuestion_Condition.php @@ -33,7 +33,7 @@ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; -class Question_ConditionTest extends CommonTestCase { +class PluginFormcreatorQuestion_Condition extends CommonTestCase { static $question; @@ -252,7 +252,7 @@ public function answersProvider() { */ public function testConditionsEvaluation($show_rule, $conditions, $answers, $expectedVisibility) { // create form - $form = new PluginFormcreatorForm(); + $form = new \PluginFormcreatorForm(); $form->add([ 'entities_id' => '0', 'name' => __METHOD__, @@ -263,14 +263,14 @@ public function testConditionsEvaluation($show_rule, $conditions, $answers, $exp ]); // Create section - $section = new PluginFormcreatorSection(); + $section = new \PluginFormcreatorSection(); $section->add([ 'name' => 'a section', 'plugin_formcreator_forms_id' => $form->getID(), ]); // Create a question - self::$question = new PluginFormcreatorQuestion(); + self::$question = new \PluginFormcreatorQuestion(); self::$question->add([ 'name' => 'text question', 'fieldtype' => 'text', @@ -289,7 +289,7 @@ public function testConditionsEvaluation($show_rule, $conditions, $answers, $exp ]); for ($i = 0; $i < 4; $i++) { - $item = new PluginFormcreatorQuestion(); + $item = new \PluginFormcreatorQuestion(); $item->add([ 'fieldtype' => 'text', 'name' => "question $i", @@ -334,7 +334,7 @@ public function testConditionsEvaluation($show_rule, $conditions, $answers, $exp ]; self::$question->update($input); self::$question->updateConditions($input); - $isVisible = PluginFormcreatorFields::isVisible(self::$question->getID(), $realAnswers); + $isVisible = \PluginFormcreatorFields::isVisible(self::$question->getID(), $realAnswers); $this->boolean($isVisible)->isEqualTo($expectedVisibility); } diff --git a/tests/suite-unit/PluginFormcreatorSection.php b/tests/suite-unit/PluginFormcreatorSection.php index 5dc9280d3..a4826d01b 100644 --- a/tests/suite-unit/PluginFormcreatorSection.php +++ b/tests/suite-unit/PluginFormcreatorSection.php @@ -41,9 +41,23 @@ public function setup() { * @cover PluginFormcreatorSection::clone */ public function testDuplicate() { - $section = new \PluginFormcreatorSection; - $new_section = new \PluginFormcreatorSection; - $form_question = new \PluginFormcreatorQuestion; + // instanciate classes + $form = new \PluginFormcreatorForm; + $section = new \PluginFormcreatorSection; + $question = new \PluginFormcreatorQuestion; + + // create objects + $forms_id = $form->add(array('name' => "test clone form", + 'is_active' => true, + 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER)); + $sections_id = $section->add(array('name' => "test clone section", + 'plugin_formcreator_forms_id' => $forms_id)); + $questions_id_1 = $question->add(array('name' => "test clone question 1", + 'fieldtype' => 'text', + 'plugin_formcreator_sections_id' => $sections_id)); + $questions_id_2 = $question->add(array('name' => "test clone question 2", + 'fieldtype' => 'textarea', + 'plugin_formcreator_sections_id' => $sections_id)); //get section plugin_formcreator_getFromDBByField($section, 'name', "test clone section"); @@ -53,14 +67,16 @@ public function testDuplicate() { $this->integer($newSection_id)->isGreaterThan(0); //get cloned section + $new_section = new \PluginFormcreatorSection; + $question = new \PluginFormcreatorQuestion; $new_section->getFromDB($newSection_id); // check uuid $this->string($new_section->getField('uuid'))->isNotEqualTo($section->getField('uuid')); // check questions - $all_questions = $form_question->find("plugin_formcreator_sections_id = ".$section->getID()); - $all_new_questions = $form_question->find("plugin_formcreator_sections_id = ".$new_section->getID()); + $all_questions = $question->find("plugin_formcreator_sections_id = ".$section->getID()); + $all_new_questions = $question->find("plugin_formcreator_sections_id = ".$new_section->getID()); $this->integer(count($all_new_questions))->isEqualTo(count($all_questions)); // check that all question uuid are new From 017e4e76632284fb080d96e2b9af3d52f718515e Mon Sep 17 00:00:00 2001 From: btry Date: Thu, 12 Jul 2018 09:03:07 +0200 Subject: [PATCH 008/192] style: fix code style Signed-off-by: btry --- tests/suite-integration/PluginFormcreatorQuestion.php | 2 +- tests/suite-integration/PluginFormcreatorSection.php | 2 +- tests/suite-unit/PluginFormcreatorCheckboxesField.php | 4 ++-- tests/suite-unit/PluginFormcreatorForm.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/suite-integration/PluginFormcreatorQuestion.php b/tests/suite-integration/PluginFormcreatorQuestion.php index 336cbe9a3..f479b8b8a 100644 --- a/tests/suite-integration/PluginFormcreatorQuestion.php +++ b/tests/suite-integration/PluginFormcreatorQuestion.php @@ -24,7 +24,7 @@ public function testDuplicate() { 'text' => [ 'regex' => ['regex' => ''], 'range' => ['min' => '', 'max' => ''], - ] + ] ], ]); diff --git a/tests/suite-integration/PluginFormcreatorSection.php b/tests/suite-integration/PluginFormcreatorSection.php index da2c0f82c..421694bd0 100644 --- a/tests/suite-integration/PluginFormcreatorSection.php +++ b/tests/suite-integration/PluginFormcreatorSection.php @@ -74,7 +74,7 @@ public function testDelete() { /** * */ - public function testDuplicate() { + public function testDuplicate() { $form = $this->getForm(); $section = new \PluginFormcreatorSection(); diff --git a/tests/suite-unit/PluginFormcreatorCheckboxesField.php b/tests/suite-unit/PluginFormcreatorCheckboxesField.php index 4912701ea..e4bac0ce4 100644 --- a/tests/suite-unit/PluginFormcreatorCheckboxesField.php +++ b/tests/suite-unit/PluginFormcreatorCheckboxesField.php @@ -22,7 +22,7 @@ public function provider() { ] ] ], - ], + ], 'data' => null, 'expectedValue' => [''], 'expectedIsValid' => true @@ -44,7 +44,7 @@ public function provider() { ] ] ], - ], + ], 'data' => null, 'expectedValue' => ['2'], 'expectedIsValid' => true diff --git a/tests/suite-unit/PluginFormcreatorForm.php b/tests/suite-unit/PluginFormcreatorForm.php index 85c91cc36..a66fe1408 100644 --- a/tests/suite-unit/PluginFormcreatorForm.php +++ b/tests/suite-unit/PluginFormcreatorForm.php @@ -106,7 +106,7 @@ public function testCreateValidationNotification() { * @cover PluginFormcreatorForm::export * @engine inline */ - public function testExportForm() { + public function testExportForm() { // instanciate classes $form = new \PluginFormcreatorForm; $form_section = new \PluginFormcreatorSection; From 97b6011129921ca75dd501e4fe3f217553f908df Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 7 Aug 2018 11:41:00 +0200 Subject: [PATCH 009/192] test(form): add tests Signed-off-by: btry --- tests/suite-unit/PluginFormcreatorForm.php | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tests/suite-unit/PluginFormcreatorForm.php b/tests/suite-unit/PluginFormcreatorForm.php index a66fe1408..7322a0a6d 100644 --- a/tests/suite-unit/PluginFormcreatorForm.php +++ b/tests/suite-unit/PluginFormcreatorForm.php @@ -30,6 +30,80 @@ public function testCreateForm($formData) { $this->boolean($form->isNewItem())->isFalse(); } + public function providerPrepareInputForAdd() { + return [ + [ + + 'input' => [ + 'name' => '', + 'description' => '', + 'content' => '', + ], + 'expected' => false, // An empty name should be rejected + ], + [ + 'input' => [ + 'name' => 'être ou ne pas être', + 'description' => 'être ou ne pas être', + 'content' => '<p>être ou ne pas être</p>', + ], + 'expected' => true, + ], + [ + 'input' => [ + 'name' => 'test d\\\'apostrophe', + 'description' => 'test d\\\'apostrophe', + 'content' => '<p>test d\\\'apostrophe</p>', + ], + 'expected' => true, + ], + ]; + } + + /** + * @dataProvider providerPrepareInputForAdd + * @param array $input + * @param boolean $expected + */ + public function testPrepareInputForAdd($input, $expected) { + $form = new \PluginFormcreatorForm(); + $output = $form->prepareInputForAdd($input); + if ($expected === false) { + $this->array($output)->size->isEqualTo(0); + } else { + $this->string($output['name'])->isEqualTo($input['name']); + $this->string($output['description'])->isEqualTo($output['description']); + $this->string($output['content'])->isEqualTo($output['content']); + $this->array($output)->hasKey('uuid'); + } + } + + + public function providerPrepareInputForUpdate() { + return $this->providerPrepareInputForAdd(); + } + + /** + * @dataProvider providerPrepareInputForUpdate + * @param array $input + * @param boolean $expected + */ + public function testPrepareInputForUpdate($input, $expected) { + $form = new \PluginFormcreatorForm(); + $form->add([ + 'name' => 'anything', + ]); + $output = $form->prepareInputForUpdate($input); + if ($expected === false) { + $this->array($output)->size->isEqualTo(0); + } else { + $this->string($output['name'])->isEqualTo($input['name']); + $this->string($output['description'])->isEqualTo($output['description']); + $this->string($output['content'])->isEqualTo($output['content']); + } + } + + /** * @dataProvider formProvider */ From 5b5f13a993989e84674897da815acaee3e0ae319 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 7 Aug 2018 11:46:11 +0200 Subject: [PATCH 010/192] test(form_answer): add tests Signed-off-by: btry --- .../PluginFormcreatorForm_Answer.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/suite-integration/PluginFormcreatorForm_Answer.php b/tests/suite-integration/PluginFormcreatorForm_Answer.php index 57fd376f1..79bf5e6d1 100644 --- a/tests/suite-integration/PluginFormcreatorForm_Answer.php +++ b/tests/suite-integration/PluginFormcreatorForm_Answer.php @@ -31,6 +31,37 @@ public function afterTestMethod($method) { } } + public function providerPrepareInputForAdd() { + return [ + [ + 'input' => [ + 'name' => 'être ou ne pas être', + ], + ], + [ + 'input' => [ + 'name' => 'test d\\\'apostrophe', + ], + ], + ]; + } + + /** + * @dataProvider providerPrepareInputForAdd + * @param array $input + */ + public function testPrepareInputForAdd($input) { + $form = new \PluginFormcreatorForm(); + $form->add($input); + + $formAnswer = new \PluginFormcreatorForm_Answer(); + $output = $formAnswer->prepareInputForAdd([ + $form::getForeignKeyField() => $form->getID(), + ]); + $this->string($output['name'])->isEqualTo($input['name']); + } + + public function testNotificationFormAnswerCreated() { global $DB, $CFG_GLPI; From 160b567c9664e1664928c297c7f9f32595677d52 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 7 Aug 2018 17:26:56 +0200 Subject: [PATCH 011/192] test: disable new tests for now Signed-off-by: btry --- .../PluginFormcreatorForm_Answer.php | 3 ++- tests/suite-unit/PluginFormcreatorForm.php | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/suite-integration/PluginFormcreatorForm_Answer.php b/tests/suite-integration/PluginFormcreatorForm_Answer.php index 79bf5e6d1..f262bafb8 100644 --- a/tests/suite-integration/PluginFormcreatorForm_Answer.php +++ b/tests/suite-integration/PluginFormcreatorForm_Answer.php @@ -50,6 +50,7 @@ public function providerPrepareInputForAdd() { * @dataProvider providerPrepareInputForAdd * @param array $input */ + /* public function testPrepareInputForAdd($input) { $form = new \PluginFormcreatorForm(); $form->add($input); @@ -60,7 +61,7 @@ public function testPrepareInputForAdd($input) { ]); $this->string($output['name'])->isEqualTo($input['name']); } - + */ public function testNotificationFormAnswerCreated() { global $DB, $CFG_GLPI; diff --git a/tests/suite-unit/PluginFormcreatorForm.php b/tests/suite-unit/PluginFormcreatorForm.php index 7322a0a6d..64d2df18e 100644 --- a/tests/suite-unit/PluginFormcreatorForm.php +++ b/tests/suite-unit/PluginFormcreatorForm.php @@ -65,6 +65,7 @@ public function providerPrepareInputForAdd() { * @param array $input * @param boolean $expected */ + /* public function testPrepareInputForAdd($input, $expected) { $form = new \PluginFormcreatorForm(); $output = $form->prepareInputForAdd($input); @@ -77,7 +78,7 @@ public function testPrepareInputForAdd($input, $expected) { $this->array($output)->hasKey('uuid'); } } - + */ public function providerPrepareInputForUpdate() { return $this->providerPrepareInputForAdd(); @@ -88,6 +89,7 @@ public function providerPrepareInputForUpdate() { * @param array $input * @param boolean $expected */ + /* public function testPrepareInputForUpdate($input, $expected) { $form = new \PluginFormcreatorForm(); $form->add([ @@ -102,7 +104,7 @@ public function testPrepareInputForUpdate($input, $expected) { $this->string($output['content'])->isEqualTo($output['content']); } } - + */ /** * @dataProvider formProvider @@ -112,11 +114,11 @@ public function testUpdateForm($formData) { $form->add($formData); $this->boolean($form->isNewItem())->isFalse(); - $success = $form->update(array( + $success = $form->update([ 'id' => $form->getID(), 'name' => 'an updated form', 'validation_required' => 0 - )); + ]); $this->boolean($success)->isTrue(json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); } @@ -128,9 +130,9 @@ public function testPurgeForm($formData) { $form->add($formData); $this->boolean($form->isNewItem())->isFalse(); - $success = $form->delete(array( + $success = $form->delete([ 'id' => $form->getID(), - ), 1); + ], 1); $this->boolean($success)->isTrue(); } From 200e7a162ccfd13234474021e1e0d85ec510c7c5 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 7 Aug 2018 19:00:06 +0200 Subject: [PATCH 012/192] test: fix unit test Signed-off-by: btry --- tests/suite-integration/PluginFormcreatorForm_Answer.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/suite-integration/PluginFormcreatorForm_Answer.php b/tests/suite-integration/PluginFormcreatorForm_Answer.php index f262bafb8..362f7220b 100644 --- a/tests/suite-integration/PluginFormcreatorForm_Answer.php +++ b/tests/suite-integration/PluginFormcreatorForm_Answer.php @@ -70,10 +70,13 @@ public function testNotificationFormAnswerCreated() { $user->getFromDBbyName('glpi'); $user->update([ 'id' => $user->getID(), - '_useremails' => ['glpi@localhost.local'], + '_useremails' => [$this->getUniqueEmail()], ]); - \config::setConfigurationValues('core', ['notifications_mailing' => '1']); + \config::setConfigurationValues( + 'core', + ['notifications_mailing' => '1'] + ); $CFG_GLPI['notifications_mailing'] = '1'; $form = new \PluginFormcreatorForm(); From f7f182a9403b6e355fdbcdda687558e8e0803d82 Mon Sep 17 00:00:00 2001 From: btry Date: Wed, 8 Aug 2018 09:40:33 +0200 Subject: [PATCH 013/192] ci: remove useless var Signed-off-by: btry --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 84be8a82f..ce20c557c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ language: php env: global: - GLPI_SOURCE="https://github.com/glpi-project/glpi" - - PHPUNIT_ARGS="--verbose --debug" - CS=7.2 matrix: - GLPI_BRANCH=9.2.1 From e3b1d579dd31d40ebf562478fcbbba7342390c31 Mon Sep 17 00:00:00 2001 From: btry Date: Wed, 8 Aug 2018 09:47:38 +0200 Subject: [PATCH 014/192] ci(travis): fix allow_failures Signed-off-by: btry --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ce20c557c..a8745db5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,9 +17,10 @@ php: - 7.2 - nightly -allow_failures: - - php: nightly - - env: GLPI_BRANCH=master +matrix: + allow_failures: + - php: nightly + - env: GLPI_BRANCH=master before_script: - mysql -u root -e 'create database glpitest;' From fea2712bdd44a0ada51dce7176bf4b78239c78ae Mon Sep 17 00:00:00 2001 From: btry Date: Thu, 9 Aug 2018 10:07:49 +0200 Subject: [PATCH 015/192] ci(travis): enhance build Signed-off-by: btry --- .travis.yml | 26 +++++++++++++++----------- tests/before_script.sh | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 11 deletions(-) create mode 100755 tests/before_script.sh diff --git a/.travis.yml b/.travis.yml index a8745db5d..18373cec9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,9 @@ env: global: - GLPI_SOURCE="https://github.com/glpi-project/glpi" - CS=7.2 + - DBNAME=glpitest + - OLDDBNAME=glpiupgradetest + - AFTER_SUCCESS_BRANCH=9.3/bugfixes matrix: - GLPI_BRANCH=9.2.1 - GLPI_BRANCH=9.2/bugfixes @@ -23,20 +26,21 @@ matrix: - env: GLPI_BRANCH=master before_script: - - mysql -u root -e 'create database glpitest;' - - git clone --depth=1 $GLPI_SOURCE -b $GLPI_BRANCH ../glpi && cd ../glpi - - mv ../formcreator plugins/formcreator - - composer install --no-dev - - if [ -e scripts/cliinstall.php ] ; then php scripts/cliinstall.php --db=glpitest --user=root --tests ; fi - - if [ -e tools/cliinstall.php ] ; then php tools/cliinstall.php --db=glpitest --user=root --tests ; fi - - cd plugins/formcreator - - rm composer.lock - - composer install + - "./tests/before_script.sh" script: + - if [ "${TRAVIS_PHP_VERSION:0:3}" = "$CS" ] && [ "$GLPI_BRANCH" = "$AFTER_SUCCESS_BRANCH" ]; then COVERAGE="--nccfc CommonTreeDropdown CommonDropdown CommonDBTM CommonGLPI"; else COVERAGE="-ncc"; fi + - #if [ -e ../../scripts/cliinstall.php ] ; then php ../../scripts/cliinstall.php --db=$OLDDBNAME --user=root --tests ; fi + - #if [ -e ../../tools/cliinstall.php ] ; then php ../../tools/cliinstall.php --db=$OLDDBNAME --user=root --tests ; fi + - #mysql -u root $OLDDBNAME < tests/plugin_flyvemdm_empty_2.0.0-rc.1.sql + - #mysql -u root $OLDDBNAME < tests/plugin_flyvemdm_config_2.0.0-rc.1.sql + - #php tools/cli_install.php --test + - #rm ../../tests/config_db.php + - if [ -e ../../scripts/cliinstall.php ] ; then php ../../scripts/cliinstall.php --db=$DBNAME --user=root --tests ; fi + - if [ -e ../../tools/cliinstall.php ] ; then php ../../tools/cliinstall.php --db=$DBNAME --user=root --tests ; fi - vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-install -ncc - - vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-unit --ncc - - vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-integration --ncc + - vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-integration $COVERAGE + - vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-unit $COVERAGE - vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-uninstall -ncc - if [[ ${TRAVIS_PHP_VERSION:0:3} == "$CS" ]] ; then vendor/bin/robo --no-interaction code:cs; fi diff --git a/tests/before_script.sh b/tests/before_script.sh new file mode 100755 index 000000000..f743f2757 --- /dev/null +++ b/tests/before_script.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# +# Before script for Travis CI +# + +# defined in travis.yml +# DBNAME : database name for tests +# OLDDBNAME : database name for upgrade test of the plugin +# GLPI_SOURCE : URL to GLPI GIT repository +# GLPI_BRANCH : branch of GLPI to test with the project + +# defined by Travis CI +# TRAVIS_REPO_SLUG : see Travis CI: https://docs.travis-ci.com/user/environment-variables + +# defined in travis settings / environment variables +# GH_OAUTH + +# config composer +if [ "$TRAVIS_SECURE_ENV_VARS" = "true" ]; then + mkdir ~/.composer -p + touch ~/.composer/composer.json + composer config -g github-oauth.github.com $GH_OAUTH +fi + +# setup GLPI and its plugins +mysql -u root -e 'create database $DBNAME;' +mysql -u root -e 'create database $OLDDBNAME;' +git clone --depth=35 $GLPI_SOURCE -b $GLPI_BRANCH ../glpi && cd ../glpi +composer install --no-dev --no-interaction +IFS=/ read -a repo <<< $TRAVIS_REPO_SLUG +mv ../${repo[1]} plugins/formcreator + +# prepare plugin to test +cd plugins/formcreator + From 97df0471bd23e34eabe9a98c470c867203ab16dd Mon Sep 17 00:00:00 2001 From: btry Date: Thu, 9 Aug 2018 10:13:32 +0200 Subject: [PATCH 016/192] style: fix code style Signed-off-by: btry --- .travis.yml | 2 +- inc/fieldinterface.class.php | 2 +- tests/before_script.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 18373cec9..20a8c2346 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,7 @@ script: - vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-integration $COVERAGE - vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-unit $COVERAGE - vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-uninstall -ncc - - if [[ ${TRAVIS_PHP_VERSION:0:3} == "$CS" ]] ; then vendor/bin/robo --no-interaction code:cs; fi + - if [ ${TRAVIS_PHP_VERSION:0:3} == "$CS" ] && [ "$GLPI_BRANCH" = "$AFTER_SUCCESS_BRANCH" ]; then vendor/bin/robo --no-interaction code:cs; fi cache: directories: diff --git a/inc/fieldinterface.class.php b/inc/fieldinterface.class.php index 41abbf129..666cc641b 100644 --- a/inc/fieldinterface.class.php +++ b/inc/fieldinterface.class.php @@ -59,7 +59,7 @@ public function prepareQuestionInputForTarget($input); * @param string $input * @return string */ - public function prepareQuestionValuesForEdit($input); + public function prepareQuestionValuesForEdit($input); /** * Gets the parameters of the field diff --git a/tests/before_script.sh b/tests/before_script.sh index f743f2757..2c116c42a 100755 --- a/tests/before_script.sh +++ b/tests/before_script.sh @@ -33,4 +33,4 @@ mv ../${repo[1]} plugins/formcreator # prepare plugin to test cd plugins/formcreator - +composer install From cd884748883a7591b38ba193a4527403d5c165cf Mon Sep 17 00:00:00 2001 From: btry Date: Thu, 9 Aug 2018 10:27:32 +0200 Subject: [PATCH 017/192] build(composer): lock dependencies to PHP 5.6 Signed-off-by: btry --- composer.json | 5 +- composer.lock | 1822 ++++--------------------------------------------- 2 files changed, 152 insertions(+), 1675 deletions(-) diff --git a/composer.json b/composer.json index a640c00be..99e6b8647 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,8 @@ "platform": { "php": "5.6.0" }, - "optimize-autoloader": true + "optimize-autoloader": true, + "apcu-autoloader": true }, "require": { "php": ">= 5.6.0", @@ -19,7 +20,7 @@ "ext-bz2": "*", "pear/archive_tar": "^1.4", "atoum/atoum": "^3.3", - "atoum/stubs": "^2.5" + "atoum/stubs": "^2.5", "glpi-project/tools": "^0.1.0", "glpi-project/coding-standard": "0.5.0" }, diff --git a/composer.lock b/composer.lock index 42418b790..8a8d38186 100644 --- a/composer.lock +++ b/composer.lock @@ -4,11 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], -<<<<<<< HEAD - "content-hash": "c61213958ef3f4c2b3bdbc0aa90a9d9e", -======= - "content-hash": "120b50e50e3e04e6aae2ad36fd20dd40", ->>>>>>> 0612117... test: migrate to atoum + "content-hash": "f45f667c100fe8ba8924ac08d306d8f8", "packages": [ { "name": "docopt/docopt", @@ -242,7 +238,6 @@ }, { "name": "consolidation/config", -<<<<<<< HEAD "version": "1.1.0", "source": { "type": "git", @@ -253,18 +248,6 @@ "type": "zip", "url": "https://api.github.com/repos/consolidation/config/zipball/c9fc25e9088a708637e18a256321addc0670e578", "reference": "c9fc25e9088a708637e18a256321addc0670e578", -======= - "version": "1.0.11", - "source": { - "type": "git", - "url": "https://github.com/consolidation/config.git", - "reference": "ede41d946078e97e7a9513aadc3352f1c26817af" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/consolidation/config/zipball/ede41d946078e97e7a9513aadc3352f1c26817af", - "reference": "ede41d946078e97e7a9513aadc3352f1c26817af", ->>>>>>> 0612117... test: migrate to atoum "shasum": "" }, "require": { @@ -274,11 +257,7 @@ }, "require-dev": { "g1a/composer-test-scenarios": "^1", -<<<<<<< HEAD "phpunit/phpunit": "^5", -======= - "phpunit/phpunit": "^4", ->>>>>>> 0612117... test: migrate to atoum "satooshi/php-coveralls": "^1.0", "squizlabs/php_codesniffer": "2.*", "symfony/console": "^2.5|^3|^4", @@ -309,11 +288,7 @@ } ], "description": "Provide configuration services for a commandline tool.", -<<<<<<< HEAD "time": "2018-08-07T22:57:00+00:00" -======= - "time": "2018-05-27T01:17:02+00:00" ->>>>>>> 0612117... test: migrate to atoum }, { "name": "consolidation/log", @@ -425,21 +400,12 @@ "source": { "type": "git", "url": "https://github.com/consolidation/Robo.git", -<<<<<<< HEAD "reference": "967b88fad6f554e990407047f44a794ce9c773af" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/consolidation/Robo/zipball/967b88fad6f554e990407047f44a794ce9c773af", "reference": "967b88fad6f554e990407047f44a794ce9c773af", -======= - "reference": "48e7e55b2b739cb4e0a1246c3ec22e566dfc06ca" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/consolidation/Robo/zipball/48e7e55b2b739cb4e0a1246c3ec22e566dfc06ca", - "reference": "48e7e55b2b739cb4e0a1246c3ec22e566dfc06ca", ->>>>>>> 0612117... test: migrate to atoum "shasum": "" }, "require": { @@ -447,10 +413,7 @@ "consolidation/config": "^1.0.10", "consolidation/log": "~1", "consolidation/output-formatters": "^3.1.13", -<<<<<<< HEAD "g1a/composer-test-scenarios": "^2", -======= ->>>>>>> 0612117... test: migrate to atoum "grasmash/yaml-expander": "^1.3", "league/container": "^2.2", "php": ">=5.5.0", @@ -467,10 +430,6 @@ "codeception/aspect-mock": "^1|^2.1.1", "codeception/base": "^2.3.7", "codeception/verify": "^0.3.2", -<<<<<<< HEAD -======= - "g1a/composer-test-scenarios": "^2", ->>>>>>> 0612117... test: migrate to atoum "goaop/framework": "~2.1.2", "goaop/parser-reflection": "^1.1.0", "natxet/cssmin": "3.0.4", @@ -513,11 +472,7 @@ } ], "description": "Modern task runner", -<<<<<<< HEAD "time": "2018-08-12 00:17:46" -======= - "time": "2018-06-28 14:57:16" ->>>>>>> 0612117... test: migrate to atoum }, { "name": "container-interop/container-interop", @@ -553,68 +508,6 @@ { "name": "dflydev/dot-access-data", "version": "v1.1.0", -<<<<<<< HEAD - "source": { - "type": "git", - "url": "https://github.com/dflydev/dflydev-dot-access-data.git", - "reference": "3fbd874921ab2c041e899d044585a2ab9795df8a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/dflydev/dflydev-dot-access-data/zipball/3fbd874921ab2c041e899d044585a2ab9795df8a", - "reference": "3fbd874921ab2c041e899d044585a2ab9795df8a", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-0": { - "Dflydev\\DotAccessData": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Dragonfly Development Inc.", - "email": "info@dflydev.com", - "homepage": "http://dflydev.com" - }, - { - "name": "Beau Simensen", - "email": "beau@dflydev.com", - "homepage": "http://beausimensen.com" - }, - { - "name": "Carlos Frutos", - "email": "carlos@kiwing.it", - "homepage": "https://github.com/cfrutos" - } - ], - "description": "Given a deep data structure, access data by dot notation.", - "homepage": "https://github.com/dflydev/dflydev-dot-access-data", - "keywords": [ - "access", - "data", - "dot", - "notation" - ], - "time": "2017-01-20T21:14:22+00:00" - }, - { - "name": "doctrine/instantiator", - "version": "1.0.5", -======= ->>>>>>> 0612117... test: migrate to atoum "source": { "type": "git", "url": "https://github.com/dflydev/dflydev-dot-access-data.git", @@ -790,7 +683,6 @@ "tools" ], "time": "2018-01-02T10:48:41+00:00" -<<<<<<< HEAD }, { "name": "grasmash/expander", @@ -899,39 +791,45 @@ "type": "zip", "url": "https://api.github.com/repos/thephpleague/container/zipball/43f35abd03a12977a60ffd7095efd6a7808488c0", "reference": "43f35abd03a12977a60ffd7095efd6a7808488c0", -======= - }, - { - "name": "grasmash/expander", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/grasmash/expander.git", - "reference": "95d6037344a4be1dd5f8e0b0b2571a28c397578f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/grasmash/expander/zipball/95d6037344a4be1dd5f8e0b0b2571a28c397578f", - "reference": "95d6037344a4be1dd5f8e0b0b2571a28c397578f", ->>>>>>> 0612117... test: migrate to atoum "shasum": "" }, "require": { - "dflydev/dot-access-data": "^1.1.0", - "php": ">=5.4" + "container-interop/container-interop": "^1.2", + "php": "^5.4.0 || ^7.0" + }, + "provide": { + "container-interop/container-interop-implementation": "^1.2", + "psr/container-implementation": "^1.0" + }, + "replace": { + "orno/di": "~2.0" }, "require-dev": { - "greg-1-anderson/composer-test-scenarios": "^1", - "phpunit/phpunit": "^4|^5.5.4", - "satooshi/php-coveralls": "^1.0.2|dev-master", - "squizlabs/php_codesniffer": "^2.7" + "phpunit/phpunit": "4.*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.x-dev" + "dev-2.x": "2.x-dev", + "dev-1.x": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Container\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Phil Bennett", + "email": "philipobenito@gmail.com", + "homepage": "http://www.philipobenito.com", + "role": "Developer" } -<<<<<<< HEAD ], "description": "A fast and intuitive dependency injection container.", "homepage": "https://github.com/thephpleague/container", @@ -946,53 +844,6 @@ ], "time": "2017-05-10T09:20:27+00:00" }, - { - "name": "myclabs/deep-copy", - "version": "1.7.0", - "source": { - "type": "git", - "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0" - }, - "require-dev": { - "doctrine/collections": "^1.0", - "doctrine/common": "^2.6", - "phpunit/phpunit": "^4.1" -======= ->>>>>>> 0612117... test: migrate to atoum - }, - "autoload": { - "psr-4": { -<<<<<<< HEAD - "DeepCopy\\": "src/DeepCopy/" - }, - "files": [ - "src/DeepCopy/deep_copy.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Create deep copies (clones) of your objects", - "keywords": [ - "clone", - "copy", - "duplicate", - "object", - "object graph" - ], - "time": "2017-10-19T19:58:43+00:00" - }, { "name": "natxet/CssMin", "version": "v3.0.6", @@ -1295,24 +1146,21 @@ "time": "2015-02-10T20:07:52+00:00" }, { - "name": "phpdocumentor/reflection-common", - "version": "1.0.1", + "name": "psr/container", + "version": "1.0.0", "source": { "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" + "url": "https://github.com/php-fig/container.git", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", "shasum": "" }, "require": { - "php": ">=5.5" - }, - "require-dev": { - "phpunit/phpunit": "^4.6" + "php": ">=5.3.0" }, "type": "library", "extra": { @@ -1322,9 +1170,7 @@ }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src" - ] + "Psr\\Container\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -1333,51 +1179,47 @@ ], "authors": [ { - "name": "Jaap van Otterdijk", - "email": "opensource@ijaap.nl" + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" } ], - "description": "Common reflection classes used by phpdocumentor to reflect the code structure", - "homepage": "http://www.phpdoc.org", + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", "keywords": [ - "FQSEN", - "phpDocumentor", - "phpdoc", - "reflection", - "static analysis" + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" ], - "time": "2017-09-11T18:02:19+00:00" + "time": "2017-02-14T16:28:37+00:00" }, { - "name": "phpdocumentor/reflection-docblock", - "version": "3.3.2", + "name": "psr/log", + "version": "1.0.2", "source": { "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "bf329f6c1aadea3299f08ee804682b7c45b326a2" + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bf329f6c1aadea3299f08ee804682b7c45b326a2", - "reference": "bf329f6c1aadea3299f08ee804682b7c45b326a2", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0", - "phpdocumentor/reflection-common": "^1.0.0", - "phpdocumentor/type-resolver": "^0.4.0", - "webmozart/assert": "^1.0" - }, - "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^4.4" + "php": ">=5.3.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] + "Psr\\Log\\": "Psr/Log/" } }, "notification-url": "https://packagist.org/downloads/", @@ -1386,1248 +1228,127 @@ ], "authors": [ { - "name": "Mike van Riel", - "email": "me@mikevanriel.com" + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" } ], - "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-11-10T14:09:06+00:00" + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10T12:19:37+00:00" }, { - "name": "phpdocumentor/type-resolver", - "version": "0.4.0", + "name": "squizlabs/php_codesniffer", + "version": "2.9.1", "source": { "type": "git", - "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/dcbed1074f8244661eecddfc2a675430d8d33f62", + "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62", "shasum": "" }, "require": { - "php": "^5.5 || ^7.0", - "phpdocumentor/reflection-common": "^1.0" + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.1.2" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^5.2||^4.8.24" + "phpunit/phpunit": "~4.0" }, + "bin": [ + "scripts/phpcs", + "scripts/phpcbf" + ], "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.x-dev" } }, "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] - } + "classmap": [ + "CodeSniffer.php", + "CodeSniffer/CLI.php", + "CodeSniffer/Exception.php", + "CodeSniffer/File.php", + "CodeSniffer/Fixer.php", + "CodeSniffer/Report.php", + "CodeSniffer/Reporting.php", + "CodeSniffer/Sniff.php", + "CodeSniffer/Tokens.php", + "CodeSniffer/Reports/", + "CodeSniffer/Tokenizers/", + "CodeSniffer/DocGenerators/", + "CodeSniffer/Standards/AbstractPatternSniff.php", + "CodeSniffer/Standards/AbstractScopeSniff.php", + "CodeSniffer/Standards/AbstractVariableSniff.php", + "CodeSniffer/Standards/IncorrectPatternException.php", + "CodeSniffer/Standards/Generic/Sniffs/", + "CodeSniffer/Standards/MySource/Sniffs/", + "CodeSniffer/Standards/PEAR/Sniffs/", + "CodeSniffer/Standards/PSR1/Sniffs/", + "CodeSniffer/Standards/PSR2/Sniffs/", + "CodeSniffer/Standards/Squiz/Sniffs/", + "CodeSniffer/Standards/Zend/Sniffs/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" ], "authors": [ { - "name": "Mike van Riel", - "email": "me@mikevanriel.com" + "name": "Greg Sherwood", + "role": "lead" } ], - "time": "2017-07-14T14:27:02+00:00" + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "http://www.squizlabs.com/php-codesniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2017-05-22T02:43:20+00:00" }, { - "name": "phpspec/prophecy", - "version": "1.8.0", + "name": "symfony/console", + "version": "v3.4.14", "source": { "type": "git", - "url": "https://github.com/phpspec/prophecy.git", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" + "url": "https://github.com/symfony/console.git", + "reference": "6b217594552b9323bcdcfc14f8a0ce126e84cd73" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "url": "https://api.github.com/repos/symfony/console/zipball/6b217594552b9323bcdcfc14f8a0ce126e84cd73", + "reference": "6b217594552b9323bcdcfc14f8a0ce126e84cd73", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.0.2", - "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", - "sebastian/comparator": "^1.1|^2.0|^3.0", - "sebastian/recursion-context": "^1.0|^2.0|^3.0" + "php": "^5.5.9|>=7.0.8", + "symfony/debug": "~2.8|~3.0|~4.0", + "symfony/polyfill-mbstring": "~1.0" }, - "require-dev": { - "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.8.x-dev" - } - }, - "autoload": { - "psr-0": { - "Prophecy\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - }, - { - "name": "Marcello Duarte", - "email": "marcello.duarte@gmail.com" - } - ], - "description": "Highly opinionated mocking framework for PHP 5.3+", - "homepage": "https://github.com/phpspec/prophecy", - "keywords": [ - "Double", - "Dummy", - "fake", - "mock", - "spy", - "stub" - ], - "time": "2018-08-05T17:53:17+00:00" - }, - { - "name": "phpunit/php-code-coverage", - "version": "4.0.8", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef7b2f56815df854e66ceaee8ebe9393ae36a40d", - "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-xmlwriter": "*", - "php": "^5.6 || ^7.0", - "phpunit/php-file-iterator": "^1.3", - "phpunit/php-text-template": "^1.2", - "phpunit/php-token-stream": "^1.4.2 || ^2.0", - "sebastian/code-unit-reverse-lookup": "^1.0", - "sebastian/environment": "^1.3.2 || ^2.0", - "sebastian/version": "^1.0 || ^2.0" - }, - "require-dev": { - "ext-xdebug": "^2.1.4", - "phpunit/phpunit": "^5.7" - }, - "suggest": { - "ext-xdebug": "^2.5.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", - "homepage": "https://github.com/sebastianbergmann/php-code-coverage", - "keywords": [ - "coverage", - "testing", - "xunit" - ], - "time": "2017-04-02T07:44:40+00:00" - }, - { - "name": "phpunit/php-file-iterator", - "version": "1.4.5", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", - "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "FilterIterator implementation that filters files based on a list of suffixes.", - "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", - "keywords": [ - "filesystem", - "iterator" - ], - "time": "2017-11-27T13:52:08+00:00" - }, - { - "name": "phpunit/php-text-template", - "version": "1.2.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", - "keywords": [ - "template" - ], - "time": "2015-06-21T13:50:34+00:00" - }, - { - "name": "phpunit/php-timer", - "version": "1.0.9", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", - "shasum": "" - }, - "require": { - "php": "^5.3.3 || ^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Utility class for timing", - "homepage": "https://github.com/sebastianbergmann/php-timer/", - "keywords": [ - "timer" - ], - "time": "2017-02-26T11:10:40+00:00" - }, - { - "name": "phpunit/php-token-stream", - "version": "1.4.12", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/1ce90ba27c42e4e44e6d8458241466380b51fa16", - "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Wrapper around PHP's tokenizer extension.", - "homepage": "https://github.com/sebastianbergmann/php-token-stream/", - "keywords": [ - "tokenizer" - ], - "time": "2017-12-04T08:55:13+00:00" - }, - { - "name": "phpunit/phpunit", - "version": "5.7.27", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", - "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-json": "*", - "ext-libxml": "*", - "ext-mbstring": "*", - "ext-xml": "*", - "myclabs/deep-copy": "~1.3", - "php": "^5.6 || ^7.0", - "phpspec/prophecy": "^1.6.2", - "phpunit/php-code-coverage": "^4.0.4", - "phpunit/php-file-iterator": "~1.4", - "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": "^1.0.6", - "phpunit/phpunit-mock-objects": "^3.2", - "sebastian/comparator": "^1.2.4", - "sebastian/diff": "^1.4.3", - "sebastian/environment": "^1.3.4 || ^2.0", - "sebastian/exporter": "~2.0", - "sebastian/global-state": "^1.1", - "sebastian/object-enumerator": "~2.0", - "sebastian/resource-operations": "~1.0", - "sebastian/version": "^1.0.6|^2.0.1", - "symfony/yaml": "~2.1|~3.0|~4.0" - }, - "conflict": { - "phpdocumentor/reflection-docblock": "3.0.2" - }, - "require-dev": { - "ext-pdo": "*" - }, - "suggest": { - "ext-xdebug": "*", - "phpunit/php-invoker": "~1.1" - }, - "bin": [ - "phpunit" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.7.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "The PHP Unit Testing framework.", - "homepage": "https://phpunit.de/", - "keywords": [ - "phpunit", - "testing", - "xunit" - ], - "time": "2018-02-01T05:50:59+00:00" - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "3.4.4", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "a23b761686d50a560cc56233b9ecf49597cc9118" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/a23b761686d50a560cc56233b9ecf49597cc9118", - "reference": "a23b761686d50a560cc56233b9ecf49597cc9118", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.0.2", - "php": "^5.6 || ^7.0", - "phpunit/php-text-template": "^1.2", - "sebastian/exporter": "^1.2 || ^2.0" - }, - "conflict": { - "phpunit/phpunit": "<5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "^5.4" - }, - "suggest": { - "ext-soap": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ], - "time": "2017-06-30T09:13:00+00:00" - }, - { - "name": "psr/container", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/container.git", - "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", - "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Container\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common Container Interface (PHP FIG PSR-11)", - "homepage": "https://github.com/php-fig/container", - "keywords": [ - "PSR-11", - "container", - "container-interface", - "container-interop", - "psr" - ], - "time": "2017-02-14T16:28:37+00:00" - }, - { - "name": "psr/log", - "version": "1.0.2", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Log\\": "Psr/Log/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "homepage": "https://github.com/php-fig/log", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "time": "2016-10-10T12:19:37+00:00" - }, - { - "name": "sebastian/code-unit-reverse-lookup", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^5.7 || ^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Looks up which function or method a line of code belongs to", - "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2017-03-04T06:30:41+00:00" - }, - { - "name": "sebastian/comparator", - "version": "1.2.4", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", - "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "sebastian/diff": "~1.2", - "sebastian/exporter": "~1.2 || ~2.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides the functionality to compare PHP values for equality", - "homepage": "http://www.github.com/sebastianbergmann/comparator", - "keywords": [ - "comparator", - "compare", - "equality" - ], - "time": "2017-01-29T09:50:25+00:00" - }, - { - "name": "sebastian/diff", - "version": "1.4.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4", - "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4", - "shasum": "" - }, - "require": { - "php": "^5.3.3 || ^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Diff implementation", - "homepage": "https://github.com/sebastianbergmann/diff", - "keywords": [ - "diff" - ], - "time": "2017-05-22T07:24:03+00:00" - }, - { - "name": "sebastian/environment", - "version": "2.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", - "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^5.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] -======= - "Grasmash\\Expander\\": "src/" - } ->>>>>>> 0612117... test: migrate to atoum - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Matthew Grasmick" - } - ], - "description": "Expands internal property references in PHP arrays file.", - "time": "2017-12-21T22:14:55+00:00" - }, - { - "name": "grasmash/yaml-expander", - "version": "1.4.0", - "source": { - "type": "git", - "url": "https://github.com/grasmash/yaml-expander.git", - "reference": "3f0f6001ae707a24f4d9733958d77d92bf9693b1" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/grasmash/yaml-expander/zipball/3f0f6001ae707a24f4d9733958d77d92bf9693b1", - "reference": "3f0f6001ae707a24f4d9733958d77d92bf9693b1", - "shasum": "" - }, - "require": { - "dflydev/dot-access-data": "^1.1.0", - "php": ">=5.4", - "symfony/yaml": "^2.8.11|^3|^4" - }, - "require-dev": { - "greg-1-anderson/composer-test-scenarios": "^1", - "phpunit/phpunit": "^4.8|^5.5.4", - "satooshi/php-coveralls": "^1.0.2|dev-master", - "squizlabs/php_codesniffer": "^2.7" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Grasmash\\YamlExpander\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Matthew Grasmick" - } - ], - "description": "Expands internal property references in a yaml file.", - "time": "2017-12-16T16:06:03+00:00" - }, - { - "name": "league/container", - "version": "2.4.1", - "source": { - "type": "git", - "url": "https://github.com/thephpleague/container.git", - "reference": "43f35abd03a12977a60ffd7095efd6a7808488c0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/thephpleague/container/zipball/43f35abd03a12977a60ffd7095efd6a7808488c0", - "reference": "43f35abd03a12977a60ffd7095efd6a7808488c0", - "shasum": "" - }, - "require": { - "container-interop/container-interop": "^1.2", - "php": "^5.4.0 || ^7.0" - }, - "provide": { - "container-interop/container-interop-implementation": "^1.2", - "psr/container-implementation": "^1.0" - }, - "replace": { - "orno/di": "~2.0" - }, - "require-dev": { - "phpunit/phpunit": "4.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-2.x": "2.x-dev", - "dev-1.x": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "League\\Container\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Phil Bennett", - "email": "philipobenito@gmail.com", - "homepage": "http://www.philipobenito.com", - "role": "Developer" - } - ], - "description": "A fast and intuitive dependency injection container.", - "homepage": "https://github.com/thephpleague/container", - "keywords": [ - "container", - "dependency", - "di", - "injection", - "league", - "provider", - "service" - ], - "time": "2017-05-10T09:20:27+00:00" - }, - { - "name": "natxet/CssMin", - "version": "v3.0.6", - "source": { - "type": "git", - "url": "https://github.com/natxet/CssMin.git", - "reference": "d5d9f4c3e5cedb1ae96a95a21731f8790e38f1dd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/natxet/CssMin/zipball/d5d9f4c3e5cedb1ae96a95a21731f8790e38f1dd", - "reference": "d5d9f4c3e5cedb1ae96a95a21731f8790e38f1dd", - "shasum": "" - }, - "require": { - "php": ">=5.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Joe Scylla", - "email": "joe.scylla@gmail.com", - "homepage": "https://profiles.google.com/joe.scylla" - } - ], - "description": "Minifying CSS", - "homepage": "http://code.google.com/p/cssmin/", - "keywords": [ - "css", - "minify" - ], - "time": "2018-01-09T11:15:01+00:00" - }, - { - "name": "patchwork/jsqueeze", - "version": "v1.0.7", - "source": { - "type": "git", - "url": "https://github.com/tchwork/jsqueeze.git", - "reference": "f90a933213534b93e4ff3c2c3026ff7458f7721b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/tchwork/jsqueeze/zipball/f90a933213534b93e4ff3c2c3026ff7458f7721b", - "reference": "f90a933213534b93e4ff3c2c3026ff7458f7721b", - "shasum": "" - }, - "require": { - "php": ">=5.1.4" - }, - "type": "library", - "autoload": { - "psr-0": { - "JSqueeze": "class/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "(Apache-2.0 or GPL-2.0)" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - } - ], - "description": "Efficient JavaScript minification in PHP", - "homepage": "https://github.com/tchwork/jsqueeze", - "keywords": [ - "compression", - "javascript", - "minification" - ], - "time": "2015-03-25T10:11:08+00:00" - }, - { - "name": "psr/container", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/container.git", - "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", - "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Container\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common Container Interface (PHP FIG PSR-11)", - "homepage": "https://github.com/php-fig/container", - "keywords": [ - "PSR-11", - "container", - "container-interface", - "container-interop", - "psr" - ], - "time": "2017-02-14T16:28:37+00:00" - }, - { - "name": "psr/log", - "version": "1.0.2", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Log\\": "Psr/Log/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "homepage": "https://github.com/php-fig/log", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "time": "2016-10-10T12:19:37+00:00" - }, - { - "name": "squizlabs/php_codesniffer", - "version": "2.9.1", - "source": { - "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/dcbed1074f8244661eecddfc2a675430d8d33f62", - "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62", - "shasum": "" - }, - "require": { - "ext-simplexml": "*", - "ext-tokenizer": "*", - "ext-xmlwriter": "*", - "php": ">=5.1.2" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "bin": [ - "scripts/phpcs", - "scripts/phpcbf" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.x-dev" - } - }, - "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Fixer.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Greg Sherwood", - "role": "lead" - } - ], - "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "http://www.squizlabs.com/php-codesniffer", - "keywords": [ - "phpcs", - "standards" - ], - "time": "2017-05-22T02:43:20+00:00" - }, - { - "name": "symfony/console", -<<<<<<< HEAD - "version": "v3.4.14", - "source": { - "type": "git", - "url": "https://github.com/symfony/console.git", - "reference": "6b217594552b9323bcdcfc14f8a0ce126e84cd73" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/6b217594552b9323bcdcfc14f8a0ce126e84cd73", - "reference": "6b217594552b9323bcdcfc14f8a0ce126e84cd73", - "shasum": "" - }, - "require": { - "php": "^5.5.9|>=7.0.8", - "symfony/debug": "~2.8|~3.0|~4.0", -======= - "version": "v4.1.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/console.git", - "reference": "70591cda56b4b47c55776ac78e157c4bb6c8b43f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/70591cda56b4b47c55776ac78e157c4bb6c8b43f", - "reference": "70591cda56b4b47c55776ac78e157c4bb6c8b43f", - "shasum": "" - }, - "require": { - "php": "^7.1.3", ->>>>>>> 0612117... test: migrate to atoum - "symfony/polyfill-mbstring": "~1.0" - }, - "conflict": { - "symfony/dependency-injection": "<3.4", - "symfony/process": "<3.3" + "conflict": { + "symfony/dependency-injection": "<3.4", + "symfony/process": "<3.3" }, "require-dev": { "psr/log": "~1.0", -<<<<<<< HEAD "symfony/config": "~3.3|~4.0", "symfony/dependency-injection": "~3.4|~4.0", "symfony/event-dispatcher": "~2.8|~3.0|~4.0", "symfony/lock": "~3.4|~4.0", "symfony/process": "~3.3|~4.0" -======= - "symfony/config": "~3.4|~4.0", - "symfony/dependency-injection": "~3.4|~4.0", - "symfony/event-dispatcher": "~3.4|~4.0", - "symfony/lock": "~3.4|~4.0", - "symfony/process": "~3.4|~4.0" ->>>>>>> 0612117... test: migrate to atoum }, "suggest": { "psr/log-implementation": "For using the console logger", @@ -2638,11 +1359,7 @@ "type": "library", "extra": { "branch-alias": { -<<<<<<< HEAD "dev-master": "3.4-dev" -======= - "dev-master": "4.1-dev" ->>>>>>> 0612117... test: migrate to atoum } }, "autoload": { @@ -2669,7 +1386,6 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", -<<<<<<< HEAD "time": "2018-07-26T11:19:56+00:00" }, { @@ -2689,58 +1405,22 @@ "require": { "php": "^5.5.9|>=7.0.8", "psr/log": "~1.0" -======= - "time": "2018-05-31T10:17:53+00:00" - }, - { - "name": "symfony/event-dispatcher", - "version": "v4.1.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "2391ed210a239868e7256eb6921b1bd83f3087b5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/2391ed210a239868e7256eb6921b1bd83f3087b5", - "reference": "2391ed210a239868e7256eb6921b1bd83f3087b5", - "shasum": "" - }, - "require": { - "php": "^7.1.3" ->>>>>>> 0612117... test: migrate to atoum }, "conflict": { - "symfony/dependency-injection": "<3.4" + "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2" }, "require-dev": { -<<<<<<< HEAD "symfony/http-kernel": "~2.8|~3.0|~4.0" -======= - "psr/log": "~1.0", - "symfony/config": "~3.4|~4.0", - "symfony/dependency-injection": "~3.4|~4.0", - "symfony/expression-language": "~3.4|~4.0", - "symfony/stopwatch": "~3.4|~4.0" - }, - "suggest": { - "symfony/dependency-injection": "", - "symfony/http-kernel": "" ->>>>>>> 0612117... test: migrate to atoum }, "type": "library", "extra": { "branch-alias": { -<<<<<<< HEAD "dev-master": "3.4-dev" -======= - "dev-master": "4.1-dev" ->>>>>>> 0612117... test: migrate to atoum } }, "autoload": { "psr-4": { - "Symfony\\Component\\EventDispatcher\\": "" + "Symfony\\Component\\Debug\\": "" }, "exclude-from-classmap": [ "/Tests/" @@ -2760,9 +1440,8 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony EventDispatcher Component", + "description": "Symfony Debug Component", "homepage": "https://symfony.com", -<<<<<<< HEAD "time": "2018-07-26T11:19:56+00:00" }, { @@ -2795,41 +1474,16 @@ "suggest": { "symfony/dependency-injection": "", "symfony/http-kernel": "" -======= - "time": "2018-04-06T07:35:57+00:00" - }, - { - "name": "symfony/filesystem", - "version": "v4.1.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/filesystem.git", - "reference": "562bf7005b55fd80d26b582d28e3e10f2dd5ae9c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/562bf7005b55fd80d26b582d28e3e10f2dd5ae9c", - "reference": "562bf7005b55fd80d26b582d28e3e10f2dd5ae9c", - "shasum": "" - }, - "require": { - "php": "^7.1.3", - "symfony/polyfill-ctype": "~1.8" ->>>>>>> 0612117... test: migrate to atoum }, "type": "library", "extra": { "branch-alias": { -<<<<<<< HEAD "dev-master": "3.4-dev" -======= - "dev-master": "4.1-dev" ->>>>>>> 0612117... test: migrate to atoum } }, "autoload": { "psr-4": { - "Symfony\\Component\\Filesystem\\": "" + "Symfony\\Component\\EventDispatcher\\": "" }, "exclude-from-classmap": [ "/Tests/" @@ -2849,9 +1503,8 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony Filesystem Component", + "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", -<<<<<<< HEAD "time": "2018-07-26T09:06:28+00:00" }, { @@ -2871,40 +1524,16 @@ "require": { "php": "^5.5.9|>=7.0.8", "symfony/polyfill-ctype": "~1.8" -======= - "time": "2018-05-30T07:26:09+00:00" - }, - { - "name": "symfony/finder", - "version": "v4.1.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/finder.git", - "reference": "84714b8417d19e4ba02ea78a41a975b3efaafddb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/84714b8417d19e4ba02ea78a41a975b3efaafddb", - "reference": "84714b8417d19e4ba02ea78a41a975b3efaafddb", - "shasum": "" - }, - "require": { - "php": "^7.1.3" ->>>>>>> 0612117... test: migrate to atoum }, "type": "library", "extra": { "branch-alias": { -<<<<<<< HEAD "dev-master": "3.4-dev" -======= - "dev-master": "4.1-dev" ->>>>>>> 0612117... test: migrate to atoum } }, "autoload": { "psr-4": { - "Symfony\\Component\\Finder\\": "" + "Symfony\\Component\\Filesystem\\": "" }, "exclude-from-classmap": [ "/Tests/" @@ -2924,9 +1553,8 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony Finder Component", + "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", -<<<<<<< HEAD "time": "2018-07-26T11:19:56+00:00" }, { @@ -2945,43 +1573,19 @@ }, "require": { "php": "^5.5.9|>=7.0.8" -======= - "time": "2018-06-19T21:38:16+00:00" - }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.8.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/7cc359f1b7b80fc25ed7796be7d96adc9b354bae", - "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" ->>>>>>> 0612117... test: migrate to atoum }, "type": "library", "extra": { "branch-alias": { -<<<<<<< HEAD "dev-master": "3.4-dev" -======= - "dev-master": "1.8-dev" ->>>>>>> 0612117... test: migrate to atoum } }, "autoload": { "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" + "Symfony\\Component\\Finder\\": "" }, - "files": [ - "bootstrap.php" + "exclude-from-classmap": [ + "/Tests/" ] }, "notification-url": "https://packagist.org/downloads/", @@ -2990,17 +1594,16 @@ ], "authors": [ { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "name": "Fabien Potencier", + "email": "fabien@symfony.com" }, { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony polyfill for ctype functions", + "description": "Symfony Finder Component", "homepage": "https://symfony.com", -<<<<<<< HEAD "time": "2018-07-26T11:19:56+00:00" }, { @@ -3053,15 +1656,12 @@ ], "description": "Symfony polyfill for ctype functions", "homepage": "https://symfony.com", -======= ->>>>>>> 0612117... test: migrate to atoum "keywords": [ "compatibility", "ctype", "polyfill", "portable" ], -<<<<<<< HEAD "time": "2018-08-06T14:22:27+00:00" }, { @@ -3076,22 +1676,6 @@ "type": "zip", "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8", "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8", -======= - "time": "2018-04-30T19:57:29+00:00" - }, - { - "name": "symfony/polyfill-mbstring", - "version": "v1.8.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "3296adf6a6454a050679cde90f95350ad604b171" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171", - "reference": "3296adf6a6454a050679cde90f95350ad604b171", ->>>>>>> 0612117... test: migrate to atoum "shasum": "" }, "require": { @@ -3103,11 +1687,7 @@ "type": "library", "extra": { "branch-alias": { -<<<<<<< HEAD "dev-master": "1.9-dev" -======= - "dev-master": "1.8-dev" ->>>>>>> 0612117... test: migrate to atoum } }, "autoload": { @@ -3141,7 +1721,6 @@ "portable", "shim" ], -<<<<<<< HEAD "time": "2018-08-06T14:22:27+00:00" }, { @@ -3160,35 +1739,11 @@ }, "require": { "php": "^5.5.9|>=7.0.8" -======= - "time": "2018-04-26T10:06:28+00:00" - }, - { - "name": "symfony/process", - "version": "v4.1.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/process.git", - "reference": "1d1677391ecf00d1c5b9482d6050c0c27aa3ac3a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/1d1677391ecf00d1c5b9482d6050c0c27aa3ac3a", - "reference": "1d1677391ecf00d1c5b9482d6050c0c27aa3ac3a", - "shasum": "" - }, - "require": { - "php": "^7.1.3" ->>>>>>> 0612117... test: migrate to atoum }, "type": "library", "extra": { "branch-alias": { -<<<<<<< HEAD "dev-master": "3.4-dev" -======= - "dev-master": "4.1-dev" ->>>>>>> 0612117... test: migrate to atoum } }, "autoload": { @@ -3215,7 +1770,6 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", -<<<<<<< HEAD "time": "2018-07-26T11:19:56+00:00" }, { @@ -3234,26 +1788,6 @@ }, "require": { "php": "^5.5.9|>=7.0.8", -======= - "time": "2018-05-31T10:17:53+00:00" - }, - { - "name": "symfony/yaml", - "version": "v4.1.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/yaml.git", - "reference": "80e4bfa9685fc4a09acc4a857ec16974a9cd944e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/80e4bfa9685fc4a09acc4a857ec16974a9cd944e", - "reference": "80e4bfa9685fc4a09acc4a857ec16974a9cd944e", - "shasum": "" - }, - "require": { - "php": "^7.1.3", ->>>>>>> 0612117... test: migrate to atoum "symfony/polyfill-ctype": "~1.8" }, "conflict": { @@ -3268,11 +1802,7 @@ "type": "library", "extra": { "branch-alias": { -<<<<<<< HEAD "dev-master": "3.4-dev" -======= - "dev-master": "4.1-dev" ->>>>>>> 0612117... test: migrate to atoum } }, "autoload": { @@ -3299,61 +1829,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", -<<<<<<< HEAD "time": "2018-07-26T11:19:56+00:00" - }, - { - "name": "webmozart/assert", - "version": "1.3.0", - "source": { - "type": "git", - "url": "https://github.com/webmozart/assert.git", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a", - "shasum": "" - }, - "require": { - "php": "^5.3.3 || ^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3-dev" - } - }, - "autoload": { - "psr-4": { - "Webmozart\\Assert\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" - } - ], - "description": "Assertions to validate method input/output with nice error messages.", - "keywords": [ - "assert", - "check", - "validate" - ], - "time": "2018-01-29T19:49:41+00:00" -======= - "time": "2018-05-30T07:26:09+00:00" ->>>>>>> 0612117... test: migrate to atoum } ], "aliases": [], From 0f5572bcf228487cb51547c08028c3b7cf708d4f Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 13 Aug 2018 21:32:15 +0200 Subject: [PATCH 018/192] fix(install: typo in GLPI name Signed-off-by: btry --- scripts/cliinstall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cliinstall.php b/scripts/cliinstall.php index e1adf499a..0cbd3e7ba 100644 --- a/scripts/cliinstall.php +++ b/scripts/cliinstall.php @@ -41,7 +41,7 @@ Options: --as-user USER Do install/upgrade as specified USER. If not provided, 'glpi' user will be used - --tests Use GLPi test database + --tests Use GLPI test database DOC; From cbb04b6e2e25811a24c6e703431261724d0e6818 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 13 Aug 2018 21:32:34 +0200 Subject: [PATCH 019/192] test(install): add unit tests for upgrade Signed-off-by: btry --- .travis.yml | 12 +- tests/plugin_formcreator_config_2.5.0.sql | 15 ++ tests/plugin_formcreator_empty_2.5.0.sql | 244 ++++++++++++++++++++++ tests/suite-install/Config.php | 32 +++ 4 files changed, 297 insertions(+), 6 deletions(-) create mode 100644 tests/plugin_formcreator_config_2.5.0.sql create mode 100644 tests/plugin_formcreator_empty_2.5.0.sql diff --git a/.travis.yml b/.travis.yml index 20a8c2346..260c74da3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,12 +30,12 @@ before_script: script: - if [ "${TRAVIS_PHP_VERSION:0:3}" = "$CS" ] && [ "$GLPI_BRANCH" = "$AFTER_SUCCESS_BRANCH" ]; then COVERAGE="--nccfc CommonTreeDropdown CommonDropdown CommonDBTM CommonGLPI"; else COVERAGE="-ncc"; fi - - #if [ -e ../../scripts/cliinstall.php ] ; then php ../../scripts/cliinstall.php --db=$OLDDBNAME --user=root --tests ; fi - - #if [ -e ../../tools/cliinstall.php ] ; then php ../../tools/cliinstall.php --db=$OLDDBNAME --user=root --tests ; fi - - #mysql -u root $OLDDBNAME < tests/plugin_flyvemdm_empty_2.0.0-rc.1.sql - - #mysql -u root $OLDDBNAME < tests/plugin_flyvemdm_config_2.0.0-rc.1.sql - - #php tools/cli_install.php --test - - #rm ../../tests/config_db.php + - if [ -e ../../scripts/cliinstall.php ] ; then php ../../scripts/cliinstall.php --db=$OLDDBNAME --user=root --tests ; fi + - if [ -e ../../tools/cliinstall.php ] ; then php ../../tools/cliinstall.php --db=$OLDDBNAME --user=root --tests ; fi + - mysql -u root $OLDDBNAME < tests/plugin_formcreator_empty_2.5.0.sql + - mysql -u root $OLDDBNAME < tests/plugin_formcreator_config_2.5.0.sql + - php scripts/cliinstall.php --tests + - rm ../../tests/config_db.php - if [ -e ../../scripts/cliinstall.php ] ; then php ../../scripts/cliinstall.php --db=$DBNAME --user=root --tests ; fi - if [ -e ../../tools/cliinstall.php ] ; then php ../../tools/cliinstall.php --db=$DBNAME --user=root --tests ; fi - vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-install -ncc diff --git a/tests/plugin_formcreator_config_2.5.0.sql b/tests/plugin_formcreator_config_2.5.0.sql new file mode 100644 index 000000000..df2cc25fc --- /dev/null +++ b/tests/plugin_formcreator_config_2.5.0.sql @@ -0,0 +1,15 @@ +-- configuration of Formcreator in a GLPI instance + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET NAMES utf8 */; +/*!50503 SET NAMES utf8mb4 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; + + +INSERT INTO `glpi_configs` (`id`, `context`, `name`, `value`) VALUES + (NULL, 'flyvemdm', 'schema_version', '2.5'); + +/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; +/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; diff --git a/tests/plugin_formcreator_empty_2.5.0.sql b/tests/plugin_formcreator_empty_2.5.0.sql new file mode 100644 index 000000000..e4cc8783c --- /dev/null +++ b/tests/plugin_formcreator_empty_2.5.0.sql @@ -0,0 +1,244 @@ +-- Database schema +-- Do NOT drop anything here + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_answers` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plugin_formcreator_forms_answers_id` int(11) NOT NULL, + `plugin_formcreator_question_id` int(11) NOT NULL, + `answer` text, + PRIMARY KEY (`id`), + INDEX `plugin_formcreator_forms_answers_id` (`plugin_formcreator_forms_answers_id`), + INDEX `plugin_formcreator_question_id` (`plugin_formcreator_question_id`) +) ENGINE=MyISAM AUTO_INCREMENT=19 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_categories` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL DEFAULT '', + `comment` text, + `completename` varchar(255) DEFAULT NULL, + `plugin_formcreator_categories_id` int(11) NOT NULL DEFAULT '0', + `level` int(11) NOT NULL DEFAULT '1', + `sons_cache` longtext, + `ancestors_cache` longtext, + `knowbaseitemcategories_id` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + INDEX `name` (`name`), + INDEX `knowbaseitemcategories_id` (`knowbaseitemcategories_id`), + INDEX `plugin_formcreator_categories_id` (`plugin_formcreator_categories_id`) +) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_entityconfigs` ( + `id` int(11) NOT NULL, + `replace_helpdesk` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `entities_id` int(11) NOT NULL DEFAULT '0', + `is_recursive` tinyint(1) NOT NULL DEFAULT '0', + `access_rights` tinyint(1) NOT NULL DEFAULT '1', + `requesttype` int(11) NOT NULL DEFAULT '0', + `name` varchar(255) NOT NULL, + `description` varchar(255) DEFAULT NULL, + `content` longtext, + `plugin_formcreator_categories_id` int(11) unsigned NOT NULL DEFAULT '0', + `is_active` tinyint(1) NOT NULL DEFAULT '0', + `language` varchar(5) NOT NULL, + `helpdesk_home` tinyint(1) NOT NULL DEFAULT '0', + `is_deleted` tinyint(1) NOT NULL DEFAULT '0', + `validation_required` tinyint(1) NOT NULL DEFAULT '0', + `usage_count` int(11) NOT NULL DEFAULT '0', + `is_default` tinyint(1) NOT NULL DEFAULT '0', + `uuid` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + INDEX `entities_id` (`entities_id`), + INDEX `plugin_formcreator_categories_id` (`plugin_formcreator_categories_id`), + FULLTEXT KEY `Search` (`name`,`description`) +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms_answers` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL DEFAULT '', + `entities_id` int(11) NOT NULL DEFAULT '0', + `is_recursive` tinyint(1) NOT NULL DEFAULT '0', + `plugin_formcreator_forms_id` int(11) NOT NULL, + `requester_id` int(11) DEFAULT NULL, + `validator_id` int(11) DEFAULT NULL, + `request_date` datetime NOT NULL, + `status` enum('waiting','refused','accepted') NOT NULL DEFAULT 'waiting', + `comment` text, + `is_deleted` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + INDEX `plugin_formcreator_forms_id` (`plugin_formcreator_forms_id`), + INDEX `entities_id_is_recursive` (`entities_id`, `is_recursive`), + INDEX `requester_id` (`requester_id`), + INDEX `validator_id` (`validator_id`) +) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms_profiles` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plugin_formcreator_forms_id` int(11) NOT NULL, + `profiles_id` int(11) NOT NULL, + `uuid` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unicity` (`plugin_formcreator_forms_id`,`profiles_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms_validators` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plugin_formcreator_forms_id` int(11) NOT NULL, + `itemtype` varchar(255) NOT NULL DEFAULT '', + `items_id` int(11) NOT NULL, + `uuid` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unicity` (`plugin_formcreator_forms_id`,`itemtype`,`items_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questions` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plugin_formcreator_sections_id` int(11) NOT NULL, + `fieldtype` varchar(30) NOT NULL DEFAULT 'text', + `name` varchar(255) NOT NULL, + `required` tinyint(1) NOT NULL DEFAULT '0', + `show_empty` tinyint(1) NOT NULL DEFAULT '0', + `default_values` text, + `values` text, + `range_min` varchar(10) DEFAULT NULL, + `range_max` varchar(10) DEFAULT NULL, + `description` text NOT NULL, + `regex` varchar(255) DEFAULT NULL, + `order` int(11) NOT NULL DEFAULT '0', + `show_rule` enum('always','hidden','shown') NOT NULL DEFAULT 'always', + `uuid` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + INDEX `plugin_formcreator_sections_id` (`plugin_formcreator_sections_id`), + FULLTEXT KEY `Search` (`name`,`description`) +) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questions_conditions` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plugin_formcreator_questions_id` int(11) NOT NULL, + `show_field` int(11) DEFAULT NULL, + `show_condition` enum('==','!=','<','>','<=','>=') DEFAULT NULL, + `show_value` varchar(255) DEFAULT NULL, + `show_logic` enum('AND','OR') DEFAULT NULL, + `order` int(11) NOT NULL DEFAULT '1', + `uuid` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + INDEX `plugin_formcreator_questions_id` (`plugin_formcreator_questions_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_sections` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plugin_formcreator_forms_id` int(11) NOT NULL, + `name` varchar(255) NOT NULL, + `order` int(11) NOT NULL DEFAULT '0', + `uuid` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + INDEX `plugin_formcreator_forms_id` (`plugin_formcreator_forms_id`) +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targetchanges` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL DEFAULT '', + `changetemplates_id` int(11) DEFAULT NULL, + `comment` text, + `impactcontent` text, + `controlistcontent` text, + `rolloutplancontent` text, + `backoutplancontent` text, + `checklistcontent` text, + `due_date_rule` enum('answer','change','calcul') DEFAULT NULL, + `due_date_question` int(11) DEFAULT NULL, + `due_date_value` tinyint(4) DEFAULT NULL, + `due_date_period` enum('minute','hour','day','month') DEFAULT NULL, + `validation_followup` tinyint(1) NOT NULL DEFAULT '1', + `destination_entity` enum('current','requester','requester_dynamic_first','requester_dynamic_last','form','validator','specific','user','entity') NOT NULL DEFAULT 'requester', + `destination_entity_value` int(11) DEFAULT NULL, + `tag_type` enum('none','questions','specifics','questions_and_specific','questions_or_specific') NOT NULL DEFAULT 'none', + `tag_questions` varchar(255) NOT NULL, + `tag_specifics` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + INDEX `changetemplates_id` (`changetemplates_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targetchanges_actors` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plugin_formcreator_targetchanges_id` int(11) NOT NULL, + `actor_role` enum('requester','observer','assigned') NOT NULL, + `actor_type` enum('creator','validator','person','question_person','group','question_group','supplier','question_supplier') NOT NULL, + `actor_value` int(11) DEFAULT NULL, + `use_notification` tinyint(1) NOT NULL DEFAULT '1', + `uuid` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + INDEX `plugin_formcreator_targetchanges_id` (`plugin_formcreator_targetchanges_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targets` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plugin_formcreator_forms_id` int(11) NOT NULL, + `itemtype` varchar(100) NOT NULL DEFAULT 'PluginFormcreatorTargetTicket', + `items_id` int(11) NOT NULL DEFAULT '0', + `name` varchar(255) NOT NULL DEFAULT '', + `uuid` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + INDEX `plugin_formcreator_forms_id` (`plugin_formcreator_forms_id`), + INDEX `itemtype_items_id` (`itemtype`, `items_id`) +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targettickets` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL DEFAULT '', + `tickettemplates_id` int(11) DEFAULT NULL, + `comment` text, + `due_date_rule` enum('answer','ticket','calcul') DEFAULT NULL, + `due_date_question` int(11) DEFAULT NULL, + `due_date_value` tinyint(4) DEFAULT NULL, + `due_date_period` enum('minute','hour','day','month') DEFAULT NULL, + `urgency_rule` enum('none','specific','answer') NOT NULL DEFAULT 'none', + `urgency_question` int(11) NOT NULL DEFAULT '0', + `validation_followup` tinyint(1) NOT NULL DEFAULT '1', + `destination_entity` enum('current','requester','requester_dynamic_first','requester_dynamic_last','form','validator','specific','user','entity') NOT NULL DEFAULT 'current', + `destination_entity_value` int(11) DEFAULT NULL, + `tag_type` enum('none','questions','specifics','questions_and_specific','questions_or_specific') NOT NULL DEFAULT 'none', + `tag_questions` varchar(255) NOT NULL, + `tag_specifics` varchar(255) NOT NULL, + `category_rule` enum('none','answer') NOT NULL DEFAULT 'none', + `category_question` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + INDEX `tickettemplates_id` (`tickettemplates_id`) +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targettickets_actors` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plugin_formcreator_targettickets_id` int(11) NOT NULL, + `actor_role` enum('requester','observer','assigned') NOT NULL, + `actor_type` enum('creator','validator','person','question_person','group','question_group','supplier','question_supplier','question_actors') NOT NULL, + `actor_value` int(11) DEFAULT NULL, + `use_notification` tinyint(1) NOT NULL DEFAULT '1', + `uuid` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + INDEX `plugin_formcreator_targettickets_id` (`plugin_formcreator_targettickets_id`) +) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_issues` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `display_id` varchar(255) NOT NULL, + `original_id` int(11) NOT NULL DEFAULT '0', + `sub_itemtype` varchar(100) NOT NULL DEFAULT '', + `name` varchar(255) NOT NULL DEFAULT '', + `status` varchar(255) NOT NULL DEFAULT '', + `date_creation` datetime NOT NULL, + `date_mod` datetime NOT NULL, + `entities_id` int(11) NOT NULL DEFAULT '0', + `is_recursive` tinyint(1) NOT NULL DEFAULT '0', + `requester_id` int(11) NOT NULL DEFAULT '0', + `validator_id` int(11) NOT NULL DEFAULT '0', + `comment` text, + PRIMARY KEY (`id`), + INDEX `original_id_sub_itemtype` (`original_id`, `sub_itemtype`), + INDEX `entities_id` (`entities_id`), + INDEX `requester_id` (`requester_id`), + INDEX `validator_id` (`validator_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/tests/suite-install/Config.php b/tests/suite-install/Config.php index 4af3236d5..02f83ad63 100644 --- a/tests/suite-install/Config.php +++ b/tests/suite-install/Config.php @@ -118,4 +118,36 @@ private function configureGLPI() { private function installDependancies() { } + public function testUpgradePlugin() { + global $DB; + + $pluginName = TEST_PLUGIN_NAME; + + $fresh_tables = $DB->listTables("glpi_plugin_${pluginName}_%"); + while ($fresh_table = $fresh_tables->next()) { + $table = $fresh_table['TABLE_NAME']; + $this->boolean($this->olddb->tableExists($table, false)) + ->isTrue("Table $table does not exists from migration!"); + + // To be replaced by call to dbmysql::getTableSchema + // when GLPI 9.2.x support drops + $create = $this->getTableSchema($DB, $table); + $fresh = $create['schema']; + $fresh_idx = $create['index']; + + // To be replaced by call to dbmysql::getTableSchema + // when GLPI 9.2.x support drops + $update = $this->getTableSchema($this->olddb, $table); + $updated = $update['schema']; + $updated_idx = $update['index']; + + //compare table schema + $this->string($updated)->isIdenticalTo($fresh); + //check index + $fresh_diff = array_diff($fresh_idx, $updated_idx); + $this->array($fresh_diff)->isEmpty("Index missing in update for $table: " . implode(', ', $fresh_diff)); + $update_diff = array_diff($updated_idx, $fresh_idx); + $this->array($update_diff)->isEmpty("Index missing in empty for $table: " . implode(', ', $update_diff)); + } + } } From b1666b8645a15e38fd0f67ca484d9d75edddfad7 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 14 Aug 2018 10:27:12 +0200 Subject: [PATCH 020/192] fix(install): harmonize upgrade methods Signed-off-by: btry --- install/update_2.6.2_2.6.3.php | 5 ++++- install/update_2.6_2.7.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/install/update_2.6.2_2.6.3.php b/install/update_2.6.2_2.6.3.php index f5ecc5305..40d7d7b25 100644 --- a/install/update_2.6.2_2.6.3.php +++ b/install/update_2.6.2_2.6.3.php @@ -31,7 +31,10 @@ * --------------------------------------------------------------------- */ -function plugin_formcreator_update_2_6_3() { +/** + * @param Migration $migration + */ +function plugin_formcreator_update_2_6_3(Migration $migration) { global $DB; // Change id of search option for status of form_answer diff --git a/install/update_2.6_2.7.php b/install/update_2.6_2.7.php index cea60c215..23daddde3 100644 --- a/install/update_2.6_2.7.php +++ b/install/update_2.6_2.7.php @@ -5,7 +5,7 @@ * * @return void */ -function plugin_formcreator_update_2_7() { +function plugin_formcreator_update_2_7(Migration $migration) { global $DB; // Migrate regex question parameters From 256195346a767c08a0adab55cbac8e97d9fefd2f Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 14 Aug 2018 14:29:21 +0200 Subject: [PATCH 021/192] ci(travis): drop support for GLPI 9.2.x Signed-off-by: btry --- .travis.yml | 3 +-- inc/fields/selectfield.class.php | 6 +----- inc/issue.class.php | 4 ---- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 260c74da3..a74d83d55 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,7 @@ env: - OLDDBNAME=glpiupgradetest - AFTER_SUCCESS_BRANCH=9.3/bugfixes matrix: - - GLPI_BRANCH=9.2.1 - - GLPI_BRANCH=9.2/bugfixes + - GLPI_BRANCH=9.3.0 - GLPI_BRANCH=9.3/bugfixes - GLPI_BRANCH=master diff --git a/inc/fields/selectfield.class.php b/inc/fields/selectfield.class.php index e69e04bf1..eafeddbe4 100644 --- a/inc/fields/selectfield.class.php +++ b/inc/fields/selectfield.class.php @@ -43,11 +43,7 @@ public function displayField($canEdit = true) { if (!empty($this->fields['values'])) { foreach ($values as $value) { if ((trim($value) != '')) { - if (version_compare(GLPI_VERSION, '9.2.1') <= 0) { - $tab_values[Html::entities_deep($value)] = $value; - } else { - $tab_values[$value] = $value; - } + $tab_values[$value] = $value; } } diff --git a/inc/issue.class.php b/inc/issue.class.php index d7c8064b2..2d5c9e96f 100644 --- a/inc/issue.class.php +++ b/inc/issue.class.php @@ -495,10 +495,6 @@ public static function giveItem($itemtype, $option_id, $data, $num) { switch ($data['raw']['sub_itemtype']) { case 'Ticket': $status = Ticket::getStatus($data['raw']["ITEM_$num"]); - if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), '9.3') < 0) { - return "\"$status\" $status"; - } return Ticket::getStatusIcon($data['raw']["ITEM_$num"]); break; From 659670a0b3424a4d8ee10e45c259ff258b3d50e2 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 14 Aug 2018 16:52:06 +0200 Subject: [PATCH 022/192] test: upgrade test repair Signed-off-by: btry --- inc/fields/actorfield.class.php | 120 ++++++------------ tests/suite-install/Config.php | 71 +++++------ .../PluginFormcreatorActorField.php | 52 +++++++- tests/testall.sh | 32 ----- tests/testinstall.sh | 17 --- tests/testone.sh | 19 --- 6 files changed, 119 insertions(+), 192 deletions(-) delete mode 100755 tests/testall.sh delete mode 100755 tests/testinstall.sh delete mode 100755 tests/testone.sh diff --git a/inc/fields/actorfield.class.php b/inc/fields/actorfield.class.php index f5fe0a2e1..d7b951f28 100644 --- a/inc/fields/actorfield.class.php +++ b/inc/fields/actorfield.class.php @@ -57,93 +57,47 @@ public function displayField($canEdit = true) { } $initialValue = json_encode($initialValue); // Value needs to be non empty to allow execition of select2's initSelection - if (version_compare(GLPI_VERSION, "9.3") >= 0) { - echo ''; + echo Html::scriptBlock('$(function() { + $("#formcreator_field_' . $this->fields['id']. '").select2({ + tokenSeparators: [",", ";"], + minimumInputLength: 0, + ajax: { + url: "' . $CFG_GLPI['root_doc'] . '/ajax/getDropdownUsers.php", + type: "POST", + dataType: "json", + data: function (params, page) { + return { + entity_restrict: -1, + searchText: params.term, + page_limit: 100, + page: page } }, - createSearchChoice: function itemCreator(term, data) { - if ($(data).filter(function() { - return this.text.localeCompare(term) === 0; - }).length === 0) { - return { id: term, text: term }; - } - }, - initSelection: function (element, callback) { - callback(JSON.parse(\'' . $initialValue . '\')); + results: function (data, page) { + var more = (data.count >= 100); + return {results: data.results, pagination: {"more": more}}; } - }) - $("#formcreator_field_' . $this->fields['id'] . '").on("change", function(e) { - var selectedValues = $("#formcreator_field_' . $this->fields['id'] . '").val(); - formcreatorChangeValueOf (' . $this->fields['id']. ', selectedValues); - }); - });'); - } else { - echo ''; - echo Html::scriptBlock('$(function() { - $("#formcreator_field_' . $this->fields['id']. '").select2({ - multiple: true, - tokenSeparators: [",", ";"], - minimumInputLength: 0, - ajax: { - url: "' . $CFG_GLPI['root_doc'] . '/ajax/getDropdownUsers.php", - type: "POST", - dataType: "json", - data: function (term, page) { - return { - entity_restrict: -1, - searchText: term, - page_limit: 100, - page: page - } - }, - results: function (data, page) { - var more = (data.count >= 100); - return {results: data.results, more: more}; - } - }, - createSearchChoice: function itemCreator(term, data) { - if ($(data).filter(function() { - return this.text.localeCompare(term) === 0; - }).length === 0) { - return { id: term, text: term }; - } - }, - initSelection: function (element, callback) { - callback(JSON.parse(\'' . $initialValue . '\')); + }, + createSearchChoice: function itemCreator(term, data) { + if ($(data).filter(function() { + return this.text.localeCompare(term) === 0; + }).length === 0) { + return { id: term, text: term }; } - }) - $("#formcreator_field_' . $this->fields['id'] . '").on("change", function(e) { - var selectedValues = $("#formcreator_field_' . $this->fields['id'] . '").val(); - formcreatorChangeValueOf (' . $this->fields['id']. ', selectedValues); - }); - });'); - } + }, + initSelection: function (element, callback) { + callback(JSON.parse(\'' . $initialValue . '\')); + } + }) + $("#formcreator_field_' . $this->fields['id'] . '").on("change", function(e) { + var selectedValues = $("#formcreator_field_' . $this->fields['id'] . '").val(); + formcreatorChangeValueOf (' . $this->fields['id']. ', selectedValues); + }); + });'); } public function serializeValue($value) { diff --git a/tests/suite-install/Config.php b/tests/suite-install/Config.php index 02f83ad63..f6e00a538 100644 --- a/tests/suite-install/Config.php +++ b/tests/suite-install/Config.php @@ -33,7 +33,37 @@ use GlpiPlugin\Formcreator\Tests\CommonTestCase; +/** + * @engine inline + */ class Config extends CommonTestCase { + private $olddb; + + public function beforeTestMethod($method) { + parent::beforeTestMethod($method); + switch ($method) { + case 'testInstallPlugin': + $this->login('glpi', 'glpi'); + break; + + case 'testUpgradePlugin': + $this->olddb = new \DB(); + $this->string(getenv('OLDDBNAME')); + $this->olddb->dbdefault = getenv('OLDDBNAME'); + $this->olddb->connect(); + $this->boolean($this->olddb->connected)->isTrue(); + break; + } + } + + public function afterTestMethod($method) { + parent::afterTestMethod($method); + switch ($method) { + case 'testUpgradePlugin': + $this->olddb->close(); + break; + } + } public function testInstallPlugin() { global $DB; @@ -41,9 +71,7 @@ public function testInstallPlugin() { $pluginname = TEST_PLUGIN_NAME; $this->given(self::setupGLPIFramework()) - ->and($this->boolean($DB->connected)->isTrue()) - ->and($this->configureGLPI()) - ->and($this->installDependancies()); + ->and($this->boolean($DB->connected)->isTrue()); //Drop plugin configuration if exists $config = $this->newTestedInstance(); @@ -89,35 +117,6 @@ public function testInstallPlugin() { $this->integer($length)->isGreaterThan(0); } - /** - * Configure GLPI to isntall the plugin - */ - private function configureGLPI() { - global $CFG_GLPI; - - $settings = [ - 'use_notifications' => '1', - 'notifications_mailing' => '1', - 'enable_api' => '1', - 'enable_api_login_credentials' => '1', - 'enable_api_login_external_token' => '1', - ]; - \Config::setConfigurationValues('core', $settings); - - $CFG_GLPI = $settings + $CFG_GLPI; - - $settings = [ - 'mqtt_broker_port' => '1884', - ]; - \Config::setConfigurationValues('flyvemdm', $settings); - } - - /** - * install requirements for the plugin - */ - private function installDependancies() { - } - public function testUpgradePlugin() { global $DB; @@ -129,15 +128,11 @@ public function testUpgradePlugin() { $this->boolean($this->olddb->tableExists($table, false)) ->isTrue("Table $table does not exists from migration!"); - // To be replaced by call to dbmysql::getTableSchema - // when GLPI 9.2.x support drops - $create = $this->getTableSchema($DB, $table); + $create = $DB->getTableSchema($DB, $table); $fresh = $create['schema']; $fresh_idx = $create['index']; - // To be replaced by call to dbmysql::getTableSchema - // when GLPI 9.2.x support drops - $update = $this->getTableSchema($this->olddb, $table); + $update = $DB->getTableSchema($this->olddb, $table); $updated = $update['schema']; $updated_idx = $update['index']; diff --git a/tests/suite-unit/PluginFormcreatorActorField.php b/tests/suite-unit/PluginFormcreatorActorField.php index 30750d71b..b110ede61 100644 --- a/tests/suite-unit/PluginFormcreatorActorField.php +++ b/tests/suite-unit/PluginFormcreatorActorField.php @@ -3,7 +3,13 @@ use GlpiPlugin\Formcreator\Tests\CommonTestCase; class PluginFormcreatorActorField extends CommonTestCase { - public function provider() { + + public function testGetName() { + $output = \PluginFormcreatorActorField::getName(); + $this->string($output)->isEqualTo('Actor'); + } + + public function providerGetValue() { $user = new \User(); $user->getFromDBbyName('glpi'); $userId = $user->getID(); @@ -126,7 +132,7 @@ public function provider() { } /** - * @dataProvider provider + * @dataProvider providerGetValue */ public function testGetValue($fields, $data, $expectedValue, $expectedValidity) { $fieldInstance = new \PluginFormcreatorActorField($fields, $data); @@ -140,8 +146,12 @@ public function testGetValue($fields, $data, $expectedValue, $expectedValidity) } } + public function providerFieldIsValid() { + return providerGetValue(); + } + /** - * @dataProvider provider + * @dataProvider providerFieldIsValid */ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidity) { $fieldInstance = new \PluginFormcreatorActorField($fields, $data); @@ -150,4 +160,40 @@ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidi $isValid = $fieldInstance->isValid($values); $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); } + + public function providerSerializeValue() { + return [ + [ + 'value' => 'glpi', + 'expected' => [2] + ], + [ + 'value' => "glpi\r\nnormal", + 'expected' => [2 => 'glpi', 5 => 'normal'] + ], + [ + 'value' => "glpi\r\nnormal\r\nuser@localhost.local", + 'expected' => [ + 2 => 'glpi', + 5 => 'normal', + 'user@localhost.local' => 'user@localhost.local' + ] + ], + [ + 'value' => 'user@localhost.local', + 'expected' => ['user@localhost.local' => 'user@localhost.local'] + ], + ]; + } + + /** + * @dataProvider providerSerializeValue + */ + public function testSerializeValue($value, $expected) { + $fieldInstance = new \PluginFormcreatorActorField($fields, $data); + $output = $fieldInstance->serializeValue($value); + $this->array($output)->hasKeys(array_keys($expected)) + ->containsValues($expected) + ->size->isEqualTo(count($expected)); + } } diff --git a/tests/testall.sh b/tests/testall.sh deleted file mode 100755 index 096c8fa4a..000000000 --- a/tests/testall.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh -SELF=`readlink -f $0` -SELFDIR=`dirname $SELF` -DBNAME=unit_test_01 -PHP=php7.0 -ATOUM=~/.config/composer/vendor/bin/atoum - -oldpath=`pwd` -cd $SELFDIR/.. -mysql -u glpi -pglpi -e "DROP DATABASE IF EXISTS \`$DBNAME\`" -$PHP ../../scripts/cliinstall.php --db=$DBNAME --user=glpi --pass=glpi --tests --force -#php -S localhost:8088 -t ../.. ../../tests/router.php &>/dev/null & -#PID=$! -#echo $PID - -echo "=== Install tests ===" -$PHP $ATOUM --debug -bf atoum/bootstrap.php -no-cc --max-children-number 1 -d atoum/suite-install --no-cc - -echo "=== Unit tests ===" -$PHP $ATOUM --debug -bf atoum/bootstrap.php -no-cc --max-children-number 1 -d atoum/suite-unit --no-cc - -echo "=== Integration tests ===" -#$PHP $ATOUM --debug -bf atoum/bootstrap.php -no-cc --max-children-number 1 -d atoum/suite-integration - -#echo "=== Functional tests ===" - -echo "=== Uninstall tests ===" -$PHP $ATOUM --debug -bf atoum/bootstrap.php -no-cc --max-children-number 1 -d atoum/suite-uninstall --no-cc -cd $oldpath -#kill $PID - -#vendor/bin/phpcbf -p --standard=vendor/glpi-project/coding-standard/GlpiStandard/ *.php install/ inc/ front/ ajax/ tests/ \ No newline at end of file diff --git a/tests/testinstall.sh b/tests/testinstall.sh deleted file mode 100755 index b0093e9aa..000000000 --- a/tests/testinstall.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -SELF=`readlink -f $0` -SELFDIR=`dirname $SELF` -DB=unit_test_01 -PHP=`which php7.0` - -oldpath=`pwd` -cd $SELFDIR/.. -mysql -u glpi -pglpi -e "DROP DATABASE IF EXISTS \`$DB\`" -php ../../scripts/cliinstall.php --db=$DB --user=glpi --pass=glpi --lang=en_US --tests --force -#php tools/cliinstall.php --tests -php -S localhost:8088 -t ../.. ../../tests/router.php & -PID=$! -#echo $PID -echo "=== Install tests ===" -$PHP vendor/bin/atoum -ncc -bf tests/bootstrap.php -d tests/suite-install - diff --git a/tests/testone.sh b/tests/testone.sh deleted file mode 100755 index 5b1310e19..000000000 --- a/tests/testone.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh -SELF=`readlink -f $0` -SELFDIR=`dirname $SELF` -DB=unit_test_01 -PHP=`which php7.0` - -oldpath=`pwd` -cd $SELFDIR/.. -oldpath=`pwd` -cd $SELFDIR/.. - -echo "=== Unit tests ===" -if [ -f $1 ]; then - RESOURCE_TYPE="-f" -elif [ -d $1 ]; then - RESOURCE_TYPE="-d" -fi -$PHP vendor/bin/atoum --debug -bf tests/bootstrap.php -no-cc $RESOURCE_TYPE $1 - From d1eb8dae0cbc9be83c2d10ca4e36d28c9afb02b0 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 14 Aug 2018 17:08:16 +0200 Subject: [PATCH 023/192] test: fix tests Signed-off-by: btry --- .../PluginFormcreatorForm_Answer.php | 6 ++- .../PluginFormcreatorActorField.php | 48 ++++++++++++------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/tests/suite-integration/PluginFormcreatorForm_Answer.php b/tests/suite-integration/PluginFormcreatorForm_Answer.php index 362f7220b..5e333cd4e 100644 --- a/tests/suite-integration/PluginFormcreatorForm_Answer.php +++ b/tests/suite-integration/PluginFormcreatorForm_Answer.php @@ -75,8 +75,12 @@ public function testNotificationFormAnswerCreated() { \config::setConfigurationValues( 'core', - ['notifications_mailing' => '1'] + [ + 'use_notifications' => '1', + 'notifications_mailing' => '1' + ] ); + $CFG_GLPI['use_notifications'] = '1'; $CFG_GLPI['notifications_mailing'] = '1'; $form = new \PluginFormcreatorForm(); diff --git a/tests/suite-unit/PluginFormcreatorActorField.php b/tests/suite-unit/PluginFormcreatorActorField.php index b110ede61..72d8b7361 100644 --- a/tests/suite-unit/PluginFormcreatorActorField.php +++ b/tests/suite-unit/PluginFormcreatorActorField.php @@ -146,14 +146,14 @@ public function testGetValue($fields, $data, $expectedValue, $expectedValidity) } } - public function providerFieldIsValid() { - return providerGetValue(); + public function providerIsValid() { + return $this->providerGetValue(); } /** - * @dataProvider providerFieldIsValid + * @dataProvider providerIsValid */ - public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidity) { + public function testIsValid($fields, $data, $expectedValue, $expectedValidity) { $fieldInstance = new \PluginFormcreatorActorField($fields, $data); $values = $fields['default_values']; @@ -165,23 +165,19 @@ public function providerSerializeValue() { return [ [ 'value' => 'glpi', - 'expected' => [2] + 'expected' => '2', ], [ 'value' => "glpi\r\nnormal", - 'expected' => [2 => 'glpi', 5 => 'normal'] + 'expected' => '2,5', ], [ 'value' => "glpi\r\nnormal\r\nuser@localhost.local", - 'expected' => [ - 2 => 'glpi', - 5 => 'normal', - 'user@localhost.local' => 'user@localhost.local' - ] + 'expected' => '2,5,user@localhost.local', ], [ 'value' => 'user@localhost.local', - 'expected' => ['user@localhost.local' => 'user@localhost.local'] + 'expected' => 'user@localhost.local', ], ]; } @@ -190,10 +186,28 @@ public function providerSerializeValue() { * @dataProvider providerSerializeValue */ public function testSerializeValue($value, $expected) { - $fieldInstance = new \PluginFormcreatorActorField($fields, $data); - $output = $fieldInstance->serializeValue($value); - $this->array($output)->hasKeys(array_keys($expected)) - ->containsValues($expected) - ->size->isEqualTo(count($expected)); + $instance = new \PluginFormcreatorActorField([]); + $output = $instance->serializeValue($value); + $this->string($output)->isEqualTo($expected); + } + + public function providerDeserializeValue() { + // swap value and expected + $dataSet = $this->providerSerializeValue(); + foreach ($dataSet as &$data) { + $tmp = $data['expected']; + $data['expected'] = $data['value']; + $data['value'] = $tmp; + } + return $dataSet; + } + + /** + * @dataProvider providerDeserializeValue + */ + public function testDeserializeValue($value, $expected) { + $instance = new \PluginFormcreatorActorField([]); + $output = $instance->deserializeValue($value); + $this->string($output)->isEqualTo($expected); } } From 11a1656da4ca67fbe6ab4154629fa04d917c87f9 Mon Sep 17 00:00:00 2001 From: p-bo Date: Thu, 23 Aug 2018 08:01:02 +0200 Subject: [PATCH 024/192] =?UTF-8?q?l10n=20=E2=80=93=20added=20Czech=20tran?= =?UTF-8?q?slation=20into=20xml=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added short and long description as well as language code and tags in Czech language. Sorted alphabetically to correct displaying order on plugins.glpi-project.org --- plugin.xml | 78 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/plugin.xml b/plugin.xml index 1b109e8b3..da9eac4d6 100644 --- a/plugin.xml +++ b/plugin.xml @@ -5,30 +5,30 @@ https://raw.githubusercontent.com/pluginsGLPI/formcreator/master/icon.png - Formcreator est un plugin permettant la création de formulaires personnalisés simples d'accès aux utilisateurs aboutissant à la création d'un ou plusieurs tickets GLPI. + Vytváření formulářů je zásuvný modul který umožňuje vytváření vlastních, snadno přístupných formulářů pro uživatele, když chtějí vytvořit jeden nebo více požadavků v GLPI. Formcreator is a plugin that allow creation of custom, easy to access forms for users when they want to create one or more GLPI tickets. + Formcreator est un plugin permettant la création de formulaires personnalisés simples d'accès aux utilisateurs aboutissant à la création d'un ou plusieurs tickets GLPI. - -Formcreator est un plugin permettant la création de formulaires personnalisés simples d'accès aux utilisateurs aboutissant à la création d'un ou plusieurs tickets GLPI. - -Fonctionnalités ---------------- + +Vytváření formulářů je zásuvný modul který umožňuje vytváření vlastních, snadno přístupných formulářů pro uživatele, když chtějí vytvořit jeden nebo více požadavků v GLPI. -1. Accès par menu direct en interface self-service -2. Mise en avant de formulaires en pages d'accueil -3. Accès des formulaires contrôlés : accès public, accès utilisateurs identifiés, accès restreint à certains profils -4. Des formulaires simples et personnalisables -5. Des formulaires organisés par catégories, par entités et par langues. -6. Des questions ouvertes ou fermées, de tout type de présentation : Champs textes, listes, LDAP, fichiers, etc. -7. Organisation des questions par sections. Choix de l'ordre d'affichage. -8. Possibilité de n'afficher une question que selon certains critères (réponse à une autre question) -9. Un contrôle pointu sur les réponses de formulaires : Texte, nombres, taille des champs, e-mail, champs obligatoires, expressions réguliaires, etc. -10. Création d'un ou plusieurs tickets ou changements à partir des réponses aux formulaires -11. Ajout de description par champs, par section de questions, par formulaires, par entités et langues. -12. Formatage du/des ticket(s) créé(s) : réponses aux questions à afficher, gabarits de tickets. -13. Prévisualisation du formulaire créé directement dans la configuration. - +Funkce +-------- +1. Přímý přístup k samoobslužným formulářům v hlavní nabídce +2. Zvýrazňování formulářů v domovských stránkách +3. Řízený přístup k formulářům: veřejný přístup, přístup identifikovanému uživateli, přístup jen některým uživatelům +4. Jednoduché a přizpůsobitelné formuláře +5. Formuláře uspořádané podle kategorií, entit a jazyků. +6. Dotazy v libovolné formě: textové oblasti, seznamy, LDAP, soubory, atd. +7. Dotazy uspořádané v sekcích. Volba pořadí zobrazení. +8. Možnost zobrazit dotaz na základě určitých kritérií (odpověď na další otázku) +9. Podrobná kontrola odpovědí z formulářů: text, čísla, délka v kolonkách, e-mail, povinné kolonky, regulární výrazy, atd. +10. Vytváření jednoho nebo více požadavků nebo změn na základě odpovědí ve formuláři +11. Přidání popisu k jednotlivým kolonkám, sekcím, formulářům, entitám nebo jazykům. +12. Formátování sady požadavku: zobrazené odpovědi na dotazy, šablony požadavků. +13. Náhled vytvořeného formuláře přímo v nastavení. + Formcreator is a plugin that allow creation of custom, easy to access forms for users when they want to create one or more GLPI tickets. @@ -48,6 +48,26 @@ Features 12. Formatting the ticket set: answers to questions displayed, tickets templates. 13. Preview form created directly in the configuration. + +Formcreator est un plugin permettant la création de formulaires personnalisés simples d'accès aux utilisateurs aboutissant à la création d'un ou plusieurs tickets GLPI. + +Fonctionnalités +--------------- + +1. Accès par menu direct en interface self-service +2. Mise en avant de formulaires en pages d'accueil +3. Accès des formulaires contrôlés : accès public, accès utilisateurs identifiés, accès restreint à certains profils +4. Des formulaires simples et personnalisables +5. Des formulaires organisés par catégories, par entités et par langues. +6. Des questions ouvertes ou fermées, de tout type de présentation : Champs textes, listes, LDAP, fichiers, etc. +7. Organisation des questions par sections. Choix de l'ordre d'affichage. +8. Possibilité de n'afficher une question que selon certains critères (réponse à une autre question) +9. Un contrôle pointu sur les réponses de formulaires : Texte, nombres, taille des champs, e-mail, champs obligatoires, expressions réguliaires, etc. +10. Création d'un ou plusieurs tickets ou changements à partir des réponses aux formulaires +11. Ajout de description par champs, par section de questions, par formulaires, par entités et langues. +12. Formatage du/des ticket(s) créé(s) : réponses aux questions à afficher, gabarits de tickets. +13. Prévisualisation du formulaire créé directement dans la configuration. + https://pluginsglpi.github.io/formcreator/ @@ -255,18 +275,24 @@ Features GPL v2+ - - helpdesk - données - configuration - formulaire - + + služba podpory + data + nastavení + formuláře + helpdesk data setup forms + + helpdesk + données + configuration + formulaire + https://raw.githubusercontent.com/pluginsGLPI/formcreator/master/screenshot.png From a4b9899bea1701d52b047ffab0b465e51c3ebe73 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 27 Aug 2018 09:43:35 +0200 Subject: [PATCH 025/192] fix(wizard): warnings fix #1076 Signed-off-by: btry --- inc/wizard.class.php | 86 ++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 47 deletions(-) diff --git a/inc/wizard.class.php b/inc/wizard.class.php index 13e1c7f86..8e23f252b 100644 --- a/inc/wizard.class.php +++ b/inc/wizard.class.php @@ -241,53 +241,45 @@ public static function showTicketSummary() { echo ""; $status_count = PluginFormcreatorIssue::getTicketSummary(); - if (count($status_count[Ticket::INCOMING]) > 0) { - echo " -
- ". - $status_count[Ticket::INCOMING]." - - - - "; - } - - if (count($status_count[Ticket::WAITING]) > 0) { - echo " - - ". - $status_count[Ticket::WAITING]." - - - - "; - } - - if (count($status_count['to_validate']) > 0) { - echo " - - ". - $status_count['to_validate']." - - - - "; - } - - if (count($status_count[Ticket::SOLVED]) > 0) { - echo " - - ". - $status_count[Ticket::SOLVED]." - - - - "; - } + echo " + + ". + $status_count[Ticket::INCOMING]." + + + + "; + + echo " + + ". + $status_count[Ticket::WAITING]." + + + + "; + + echo " + + ". + $status_count['to_validate']." + + + + "; + + echo " + + ". + $status_count[Ticket::SOLVED]." + + + + "; echo ''; // formcreator_servicecatalogue_ticket_summary } From 73b4515554a571b53d535c13176ddaf3e137b743 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 27 Aug 2018 16:35:46 +0200 Subject: [PATCH 026/192] fix(install): bad sql for upgrade Signed-off-by: btry --- install/update_2.6_2.7.php | 6 ++++-- setup.php | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/install/update_2.6_2.7.php b/install/update_2.6_2.7.php index 23daddde3..05c0e57f5 100644 --- a/install/update_2.6_2.7.php +++ b/install/update_2.6_2.7.php @@ -78,13 +78,15 @@ function plugin_formcreator_update_2_7(Migration $migration) { foreach ($DB->request($request) as $row) { $values = html_entity_decode($row['values']); $defaultValues = html_entity_decode($row['default_values']); - $DB->query("UDATE `glpi_plugin_formcreator_questions` SET `values` = '$values', `default_values` = '$defaultValues'"); + $id = $row['id']; + $DB->query("UPDATE `glpi_plugin_formcreator_questions` SET `values` = '$values', `default_values` = '$defaultValues' WHERE `id` = '$id'"); } // decode html entities in name of questions foreach ($DB->request(['FROM' => 'glpi_plugin_formcreator_questions']) as $row) { $name = html_entity_decode($row['name']); - $DB->query("UPDATE `glpi_plugin_formcreator_questions` SET `name`='$name'"); + $id = $row['id']; + $DB->query("UPDATE `glpi_plugin_formcreator_questions` SET `name`='$name' WHERE `id` = '$id'"); } } \ No newline at end of file diff --git a/setup.php b/setup.php index 8502f811b..77220e4b0 100644 --- a/setup.php +++ b/setup.php @@ -33,9 +33,9 @@ global $CFG_GLPI; // Version of the plugin -define('PLUGIN_FORMCREATOR_VERSION', '2.6.4'); +define('PLUGIN_FORMCREATOR_VERSION', 'develop'); // Schema version of this version -define('PLUGIN_FORMCREATOR_SCHEMA_VERSION', '2.6'); +define('PLUGIN_FORMCREATOR_SCHEMA_VERSION', '2.7'); // is or is not an official release of the plugin define('PLUGIN_FORMCREATOR_IS_OFFICIAL_RELEASE', false); From 3cf510a181f982da6f9f07a8f54a654b161eb63b Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 22 May 2018 15:30:35 +0200 Subject: [PATCH 027/192] fix(question): limit assets dropdowns to my assets Signed-off-by: btry --- inc/fields/dropdownfield.class.php | 105 +++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 20 deletions(-) diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index 999cd1f8c..a69378703 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -34,6 +34,8 @@ class PluginFormcreatorDropdownField extends PluginFormcreatorField { public function displayField($canEdit = true) { + global $DB, $CFG_GLPI; + if ($canEdit) { if (!empty($this->fields['values'])) { $rand = mt_rand(); @@ -50,26 +52,53 @@ public function displayField($canEdit = true) { 'comments' => false, 'rand' => $rand]; - if ($itemtype == "User") { - $dparams['right'] = 'all'; - } else if ($itemtype == "ITILCategory") { - $dparams['condition'] = '1'; - if (isset ($_SESSION['glpiactiveprofile']['interface']) - && $_SESSION['glpiactiveprofile']['interface'] == 'helpdesk') { - $dparams['condition'] .= " AND `is_helpdeskvisible` = '1'"; - } - switch ($decodedValues['show_ticket_categories']) { - case 'request': - $dparams['condition'] .= " AND `is_request` = '1'"; - break; - case 'incident': - $dparams['condition'] .= " AND `is_incident` = '1'"; - break; - } - if (isset($decodedValues['show_ticket_categories_depth']) - && $decodedValues['show_ticket_categories_depth'] > 0) { - $dparams['condition'] .= " AND `level` <= '" . $decodedValues['show_ticket_categories_depth'] . "'"; - } + switch ($itemtype) { + case User::class: + $dparams['right'] = 'all'; + break; + + case ITILCategory::class: + $dparams['condition'] = '1'; + if (isset ($_SESSION['glpiactiveprofile']['interface']) + && $_SESSION['glpiactiveprofile']['interface'] == 'helpdesk') { + $dparams['condition'] .= " AND `is_helpdeskvisible` = '1'"; + } + switch ($decodedValues['show_ticket_categories']) { + case 'request': + $dparams['condition'] .= " AND `is_request` = '1'"; + break; + case 'incident': + $dparams['condition'] .= " AND `is_incident` = '1'"; + break; + } + if (isset($decodedValues['show_ticket_categories_depth']) + && $decodedValues['show_ticket_categories_depth'] > 0) { + $dparams['condition'] .= " AND `level` <= '" . $decodedValues['show_ticket_categories_depth'] . "'"; + } + break; + + default: + if (in_array($itemtype, $CFG_GLPI['ticket_types'])) { + $userFk = User::getForeignKeyField(); + $groupFk = Group::getForeignKeyField(); + $canViewAllHardware = Session::haveRight('helpdesk_hardware', pow(2, Ticket::HELPDESK_ALL_HARDWARE)); + $canViewMyHardware = Session::haveRight('helpdesk_hardware', pow(2, Ticket::HELPDESK_MY_HARDWARE)); + $canViewGroupHardware = Session::haveRight('show_group_hardware', '1'); + $groups = []; + if ($canViewGroupHardware) { + $groups = $this->getMyGroups(Session::getLoginUserID()); + } + if ($DB->fieldExists($itemtype::getTable(), $userFk) + && !$canViewAllHardware && $canViewMyHardware) { + $userId = $_SESSION['glpiID']; + $dparams['condition'] = "`$userFk`='$userId'"; + } + if ($DB->fieldExists($itemtype::getTable(), $groupFk) + && !$canViewAllHardware && count($groups) > 0) { + $groups = implode("', '", $groups); + $dparams['condition'] .= " OR `$groupFk` IN ('$groups')"; + } + } } $itemtype::dropdown($dparams); @@ -180,4 +209,40 @@ public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['dropdown'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + private function getMyGroups($userID) { + global $DB; + + // from Item_Ticket::dropdownMyDevices() + $DbUtil = new DbUtils(); + $group_where = ""; + $query = "SELECT `glpi_groups_users`.`groups_id`, `glpi_groups`.`name` + FROM `glpi_groups_users` + LEFT JOIN `glpi_groups` + ON (`glpi_groups`.`id` = `glpi_groups_users`.`groups_id`) + WHERE `glpi_groups_users`.`users_id` = '$userID' " . + $DbUtil->getEntitiesRestrictRequest( + "AND", + "glpi_groups", + "", + $_SESSION['glpiactive_entity'], + $_SESSION['glpiactive_entity_recursive']); + $result = $DB->query($query); + + $first = true; + $devices = []; + if ($DB->numrows($result) === 0) { + return []; + } + while ($data = $DB->fetch_assoc($result)) { + if ($first) { + $first = false; + } else { + $group_where .= " OR "; + } + $a_groups = getAncestorsOf("glpi_groups", $data["groups_id"]); + $a_groups[$data["groups_id"]] = $data["groups_id"]; + } + return $a_groups; + } } From 0385c20ddff6ae167ad25ca91eb4a60c1f7e7b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Tue, 21 Aug 2018 12:26:11 +0200 Subject: [PATCH 028/192] feat(install): Use InnoDB as DB table engine Signed-off-by: btry --- install/mysql/plugin_formcreator_empty.sql | 40 +++++++++++----------- install/update_2.6_2.7.php | 1 - 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/install/mysql/plugin_formcreator_empty.sql b/install/mysql/plugin_formcreator_empty.sql index 9a5191514..570b42f7e 100644 --- a/install/mysql/plugin_formcreator_empty.sql +++ b/install/mysql/plugin_formcreator_empty.sql @@ -9,7 +9,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_answers` ( PRIMARY KEY (`id`), INDEX `plugin_formcreator_forms_answers_id` (`plugin_formcreator_forms_answers_id`), INDEX `plugin_formcreator_questions_id` (`plugin_formcreator_questions_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_categories` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -25,13 +25,13 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_categories` ( INDEX `name` (`name`), INDEX `knowbaseitemcategories_id` (`knowbaseitemcategories_id`), INDEX `plugin_formcreator_categories_id` (`plugin_formcreator_categories_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_entityconfigs` ( `id` int(11) NOT NULL, `replace_helpdesk` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -55,7 +55,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms` ( INDEX `entities_id` (`entities_id`), INDEX `plugin_formcreator_categories_id` (`plugin_formcreator_categories_id`), FULLTEXT KEY `Search` (`name`,`description`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms_answers` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -76,7 +76,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms_answers` ( INDEX `requester_id` (`requester_id`), INDEX `users_id_validator` (`users_id_validator`), INDEX `groups_id_validator` (`groups_id_validator`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms_profiles` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -85,7 +85,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms_profiles` ( `uuid` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `unicity` (`plugin_formcreator_forms_id`,`profiles_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms_validators` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -95,7 +95,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms_validators` ( `uuid` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `unicity` (`plugin_formcreator_forms_id`,`itemtype`,`items_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questions` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -116,7 +116,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questions` ( PRIMARY KEY (`id`), INDEX `plugin_formcreator_sections_id` (`plugin_formcreator_sections_id`), FULLTEXT KEY `Search` (`name`,`description`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questions_conditions` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -129,7 +129,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questions_conditions` ( `uuid` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), INDEX `plugin_formcreator_questions_id` (`plugin_formcreator_questions_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_sections` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -139,7 +139,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_sections` ( `uuid` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), INDEX `plugin_formcreator_forms_id` (`plugin_formcreator_forms_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targetchanges` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -167,7 +167,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targetchanges` ( `category_question` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), INDEX `changetemplates_id` (`changetemplates_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targetchanges_actors` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -179,7 +179,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targetchanges_actors` ( `uuid` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), INDEX `plugin_formcreator_targetchanges_id` (`plugin_formcreator_targetchanges_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targets` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -191,7 +191,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targets` ( PRIMARY KEY (`id`), INDEX `plugin_formcreator_forms_id` (`plugin_formcreator_forms_id`), INDEX `itemtype_items_id` (`itemtype`, `items_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targettickets` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -216,7 +216,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targettickets` ( `category_question` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), INDEX `tickettemplates_id` (`tickettemplates_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targettickets_actors` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -228,7 +228,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targettickets_actors` ( `uuid` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), INDEX `plugin_formcreator_targettickets_id` (`plugin_formcreator_targettickets_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_issues` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -249,7 +249,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_issues` ( INDEX `entities_id` (`entities_id`), INDEX `requester_id` (`requester_id`), INDEX `validator_id` (`validator_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_items_targettickets` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -261,7 +261,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_items_targettickets` ( PRIMARY KEY (`id`), INDEX `plugin_formcreator_targettickets_id` (`plugin_formcreator_targettickets_id`), INDEX `item` (`itemtype`,`items_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questiondependencies` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -272,7 +272,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questiondependencies` ( PRIMARY KEY (`id`), INDEX `plugin_formcreator_questions_id` (`plugin_formcreator_questions_id`), INDEX `plugin_formcreator_questions_id_2` (`plugin_formcreator_questions_id_2`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questionregexes` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -282,7 +282,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questionregexes` ( `uuid` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), INDEX `plugin_formcreator_questions_id` (`plugin_formcreator_questions_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questionranges` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -293,4 +293,4 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questionranges` ( `uuid` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), INDEX `plugin_formcreator_questions_id` (`plugin_formcreator_questions_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/install/update_2.6_2.7.php b/install/update_2.6_2.7.php index 05c0e57f5..39a3f06fb 100644 --- a/install/update_2.6_2.7.php +++ b/install/update_2.6_2.7.php @@ -88,5 +88,4 @@ function plugin_formcreator_update_2_7(Migration $migration) { $id = $row['id']; $DB->query("UPDATE `glpi_plugin_formcreator_questions` SET `name`='$name' WHERE `id` = '$id'"); } - } \ No newline at end of file From 56a4b5f7edef73d46cde933d80ecc6b5a4f3a907 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 27 Aug 2018 17:31:12 +0200 Subject: [PATCH 029/192] fix(install): remove useless field see code in upgrade from 2.6 to 2.7 Signed-off-by: btry --- install/mysql/plugin_formcreator_empty.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/install/mysql/plugin_formcreator_empty.sql b/install/mysql/plugin_formcreator_empty.sql index 570b42f7e..4fecaa735 100644 --- a/install/mysql/plugin_formcreator_empty.sql +++ b/install/mysql/plugin_formcreator_empty.sql @@ -109,7 +109,6 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questions` ( `range_min` varchar(10) DEFAULT NULL, `range_max` varchar(10) DEFAULT NULL, `description` text NOT NULL, - `regex` text, `order` int(11) NOT NULL DEFAULT '0', `show_rule` enum('always','hidden','shown') NOT NULL DEFAULT 'always', `uuid` varchar(255) DEFAULT NULL, From 72a643a15717ccf0a6c4c516f2e911f5d0fb54c6 Mon Sep 17 00:00:00 2001 From: amolecho <33320701+amolecho@users.noreply.github.com> Date: Thu, 2 Nov 2017 15:06:20 +0100 Subject: [PATCH 030/192] feat(field): hostname field this field picks the hostname using its IP address Signed-off-by: btry --- inc/fields/hostnamefield.class.php | 43 +++++++++++++++++++++++++++++ pics/ui-hostname-field.png | Bin 0 -> 212 bytes 2 files changed, 43 insertions(+) create mode 100644 inc/fields/hostnamefield.class.php create mode 100644 pics/ui-hostname-field.png diff --git a/inc/fields/hostnamefield.class.php b/inc/fields/hostnamefield.class.php new file mode 100644 index 000000000..3069103f3 --- /dev/null +++ b/inc/fields/hostnamefield.class.php @@ -0,0 +1,43 @@ +fields['id'] . '" + id="formcreator_field_' . $this->fields['id'] . '" + value="' . $hostname . '" />' . PHP_EOL; + } else { + parent::show($canEdit); + } + } + + public function isValid($value) { + return true; + } + + public static function getName() { + return _n('Hostname', 'Hostname', 1); + } + + public static function getPrefs() { + return [ + 'required' => 0, + 'default_values' => 0, + 'values' => 0, + 'range' => 0, + 'show_empty' => 0, + 'regex' => 0, + 'show_type' => 0, + 'dropdown_value' => 0, + 'glpi_objects' => 0, + 'ldap_values' => 0, + ]; + } + + public static function getJSFields() { + $prefs = self::getPrefs(); + return "tab_fields_fields['hostname'] = 'showFields(" . implode(', ', $prefs) . ");';"; + } +} diff --git a/pics/ui-hostname-field.png b/pics/ui-hostname-field.png new file mode 100644 index 0000000000000000000000000000000000000000..6324c2add83276ef61519764d590378d1c8d2e6d GIT binary patch literal 212 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!aez;VE087?EM|2(3DhG{666=m zz{teP#wnVfJ!$IpQ!ju2U0z+fA1LSG>Eak75uW_ufw%)x3=hwr932mbhMA5Ht&E%u zm0tuOIG3|qcX?YTdhKLonNYfj^TPqt4@ONteC}`@=n7zCXV@9X%JJ>mm5Cs?dAj Date: Tue, 28 Aug 2018 12:07:14 +0200 Subject: [PATCH 031/192] refactor(question): add showForForm method Signed-off-by: btry --- inc/question.class.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/inc/question.class.php b/inc/question.class.php index cabaa03fc..84094ddf9 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -117,8 +117,15 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { * @return null Nothing, just display the list */ public static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { - global $CFG_GLPI; + switch (get_class($item)) { + case PluginFormcreatorForm::class: + static::showForForm($item, $withtemplate); + break; + } + } + public static function showForForm(CommonDBTM $item, $withtemplate = '') { + global $CFG_GLPI; // TODO: move the content of this method into a new showForForm() method echo ''; From 91cc6cec856add94674ad1088e3d4250e7e7819c Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 28 Aug 2018 11:56:11 +0200 Subject: [PATCH 032/192] feat: handle rich text mode for GLPI 9.4 Signed-off-by: btry --- inc/fields/checkboxesfield.class.php | 2 +- inc/fields/multiselectfield.class.php | 2 +- inc/issue.class.php | 2 +- inc/targetbase.class.php | 2 +- inc/targetchange.class.php | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index e5f1df9b2..e78ce6782 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -203,7 +203,7 @@ public function prepareQuestionInputForTarget($input) { } } - if ($CFG_GLPI['use_rich_text']) { + if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { $value = '
' . implode('
', $value); } else { $value = '\r\n' . implode('\r\n', $value); diff --git a/inc/fields/multiselectfield.class.php b/inc/fields/multiselectfield.class.php index 2a92f9eae..e6850726f 100644 --- a/inc/fields/multiselectfield.class.php +++ b/inc/fields/multiselectfield.class.php @@ -138,7 +138,7 @@ public function prepareQuestionInputForTarget($input) { $value[] = addslashes($input); } } - if ($CFG_GLPI['use_rich_text']) { + if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { $value = '
' . implode('
', $value); } else { $value = '\r\n' . implode('\r\n', $value); diff --git a/inc/issue.class.php b/inc/issue.class.php index 2d5c9e96f..9d64fcd01 100644 --- a/inc/issue.class.php +++ b/inc/issue.class.php @@ -152,7 +152,7 @@ public function display($options = []) { if (!in_array($itemtype, ['Ticket', 'PluginFormcreatorForm_Answer'])) { html::displayRightError(); } - if ($CFG_GLPI['use_rich_text']) { + if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { Html::requireJs('tinymce'); } if (plugin_formcreator_replaceHelpdesk() == PluginFormcreatorEntityconfig::CONFIG_SIMPLIFIED_SERVICE_CATALOG) { diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index d5a39045b..147b4092a 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -810,7 +810,7 @@ protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer, $value = $fieldObject->prepareQuestionInputForTarget($fieldObject->getValue()); } if (is_array($value)) { - if ($CFG_GLPI['use_rich_text']) { + if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { $value = '
' . implode('
', $value); } else { $value = "\r\n" . implode("\r\n", $value); diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index aeaac8f6f..02e3c3a3a 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -858,7 +858,7 @@ public function prepareInputForUpdate($input) { return []; } - if ($CFG_GLPI['use_rich_text']) { + if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { $input['comment'] = Html::entity_decode_deep($input['comment']); } @@ -996,7 +996,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { if (strpos($data[$changeField], '##FULLFORM##') !== false) { $data[$changeField] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data[$changeField]); } - if ($CFG_GLPI['use_rich_text']) { + if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { // replace HTML P tags with DIV tags $data['content'] = str_replace(['

', '

'], ['
', '
'], $data['content']); } From 22809ce07a6f337ebabdcefec375d55f57c7a9cf Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 28 Aug 2018 17:48:03 +0200 Subject: [PATCH 033/192] fix(dropdown): change to ticket category changing from an other droptown causes php warnings also add upgrade code Signed-off-by: btry --- inc/question.class.php | 8 ++++++-- install/update_2.6_2.7.php | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/inc/question.class.php b/inc/question.class.php index 84094ddf9..e20adbbed 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -961,7 +961,9 @@ function plugin_formcreator_hideAllParameters() { ]; dropdown::showFromArray('show_ticket_categories', $ticketCategoriesOptions, [ 'rand' => $rand, - 'value' => $decodedValues['show_ticket_categories'] + 'value' => isset($decodedValues['show_ticket_categories']) + ? $decodedValues['show_ticket_categories'] + : 'both' ]); echo ''; echo '
'; echo ''; echo ''; echo ''; @@ -852,14 +852,14 @@ public function prepareInputForUpdate($input) { return []; } - // - comment is required - if (empty($input['comment'])) { + // - content is required + if (empty($input['content'])) { Session::addMessageAfterRedirect(__('The description cannot be empty!', 'formcreator'), false, ERROR); return []; } if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { - $input['comment'] = Html::entity_decode_deep($input['comment']); + $input['content'] = Html::entity_decode_deep($input['content']); } switch ($input['destination_entity']) { @@ -984,13 +984,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { 'checklistcontent' ]; foreach ($changeFields as $changeField) { - //TODO: 2.7.0 rename PluginFormcreatorTargetChange's comment into content - if ($changeField != 'content') { - // This handles mismatch of the column content in Change itemtype and comment in TargetChange itemtype - $data[$changeField] = $this->fields[$changeField]; - } else { - $data[$changeField] = $this->fields['comment']; - } + $data[$changeField] = $this->fields[$changeField]; $data[$changeField] = addslashes($data[$changeField]); $data[$changeField] = str_replace("\r\n", '\r\n', $data[$changeField]); if (strpos($data[$changeField], '##FULLFORM##') !== false) { @@ -998,7 +992,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { } if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { // replace HTML P tags with DIV tags - $data['content'] = str_replace(['

', '

'], ['
', '
'], $data['content']); + $data[$changeField] = str_replace(['

', '

'], ['
', '
'], $data[$changeField]); } $data[$changeField] = $this->parseTags($data[$changeField], $formanswer); diff --git a/install/mysql/plugin_formcreator_empty.sql b/install/mysql/plugin_formcreator_empty.sql index 4fecaa735..0534a8987 100644 --- a/install/mysql/plugin_formcreator_empty.sql +++ b/install/mysql/plugin_formcreator_empty.sql @@ -144,12 +144,12 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targetchanges` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL DEFAULT '', `changetemplates_id` int(11) DEFAULT NULL, - `comment` text, - `impactcontent` text, - `controlistcontent` text, - `rolloutplancontent` text, - `backoutplancontent` text, - `checklistcontent` text, + `content` longtext, + `impactcontent` longtext, + `controlistcontent` longtext, + `rolloutplancontent` longtext, + `backoutplancontent` longtext, + `checklistcontent` longtext, `due_date_rule` enum('answer','change','calcul') DEFAULT NULL, `due_date_question` int(11) DEFAULT NULL, `due_date_value` tinyint(4) DEFAULT NULL, diff --git a/install/update_2.6_2.7.php b/install/update_2.6_2.7.php index 151ad43d8..33ee17cfc 100644 --- a/install/update_2.6_2.7.php +++ b/install/update_2.6_2.7.php @@ -158,4 +158,14 @@ function plugin_formcreator_update_2_7(Migration $migration) { $DB->query("UPDATE `glpi_plugin_formcreator_answers` SET `answer` = '$answer' WHERE `id` = '$id'"); } } + + // Update target change columns + $table = 'glpi_plugin_formcreator_targetchanges'; + $migration->changeField($table, 'comment', 'content', 'longtext'); + $migration->changeField($table, 'impactcontent', 'impactcontent', 'longtext'); + $migration->changeField($table, 'controlistcontent', 'controlistcontent', 'longtext'); + $migration->changeField($table, 'rolloutplancontent', 'rolloutplancontent', 'longtext'); + $migration->changeField($table, 'backoutplancontent', 'backoutplancontent', 'longtext'); + $migration->changeField($table, 'checklistcontent', 'checklistcontent', 'longtext'); + } From 9dc1da553b54e8075def10a0c077405d5df07fc3 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 10 Sep 2018 18:10:06 +0200 Subject: [PATCH 073/192] fix(targetticket): harmonize comumns name and type wih glpi ticket itemtype Signed-off-by: btry --- inc/form.class.php | 6 +- inc/target.class.php | 2 +- inc/targetticket.class.php | 18 ++--- install/mysql/plugin_formcreator_empty.sql | 2 +- install/update_2.6_2.7.php | 3 + tests/src/CommonTestCase.php | 2 +- .../PluginFormcreatorTargetTicket.php | 2 + tests/suite-unit/PluginFormcreatorForm.php | 68 ++++++++++++------- 8 files changed, 63 insertions(+), 40 deletions(-) diff --git a/inc/form.class.php b/inc/form.class.php index 1b0e05af5..f5a413e9b 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1406,8 +1406,8 @@ public function duplicate() { foreach ($tab_questions as $id => $value) { $update_target_ticket['name'] = str_replace('##question_' . $id . '##', '##question_' . $value . '##', $update_target_ticket['name']); $update_target_ticket['name'] = str_replace('##answer_' . $id . '##', '##answer_' . $value . '##', $update_target_ticket['name']); - $update_target_ticket['comment'] = str_replace('##question_' . $id . '##', '##question_' . $value . '##', $update_target_ticket['comment']); - $update_target_ticket['comment'] = str_replace('##answer_' . $id . '##', '##answer_' . $value . '##', $update_target_ticket['comment']); + $update_target_ticket['content'] = str_replace('##question_' . $id . '##', '##question_' . $value . '##', $update_target_ticket['content']); + $update_target_ticket['content'] = str_replace('##answer_' . $id . '##', '##answer_' . $value . '##', $update_target_ticket['content']); } // update time to resolve rule @@ -1439,7 +1439,7 @@ public function duplicate() { $new_target_ticket = new PluginFormcreatorTargetTicket(); $update_target_ticket['title'] = Toolbox::addslashes_deep($update_target_ticket['name']); - $update_target_ticket['comment'] = Toolbox::addslashes_deep($update_target_ticket['comment']); + $update_target_ticket['content'] = Toolbox::addslashes_deep($update_target_ticket['content']); if (!$new_target_ticket->update($update_target_ticket)) { return false; } diff --git a/inc/target.class.php b/inc/target.class.php index b075bea2b..01cf4ce8e 100644 --- a/inc/target.class.php +++ b/inc/target.class.php @@ -153,7 +153,7 @@ public function prepareInputForAdd($input) { $targetticket = new PluginFormcreatorTargetTicket(); $id_targetticket = $targetticket->add([ 'name' => $input['name'], - 'comment' => '##FULLFORM##' + 'content' => '##FULLFORM##' ]); $input['items_id'] = $id_targetticket; diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index e28cc47a6..eed50d4aa 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -116,9 +116,9 @@ public function showForm($options = []) { echo ''; echo ''; echo ''; echo ''; @@ -845,13 +845,13 @@ public function prepareInputForUpdate($input) { } // - comment is required - if (empty($input['comment'])) { + if (strlen($input['content']) < 1) { Session::addMessageAfterRedirect(__('The description cannot be empty!', 'formcreator'), false, ERROR); return []; } if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { - $input['comment'] = Html::entity_decode_deep($input['comment']); + $input['content'] = Html::entity_decode_deep($input['content']); } switch ($input['destination_entity']) { @@ -1109,7 +1109,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { $data['name'] = addslashes($this->fields['name']); $data['name'] = $this->parseTags($data['name'], $formanswer); - $data['content'] = addslashes($this->fields['comment']); + $data['content'] = addslashes($this->fields['content']); $data['content'] = str_replace("\r\n", '\r\n', $data['content']); if (strpos($data['content'], '##FULLFORM##') !== false) { $data['content'] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data['content']); @@ -1497,10 +1497,10 @@ public static function import($targetitems_id = 0, $target_data = []) { $content = str_replace("##answer_$uuid##", "##answer_$id##", $content); $target_data['name'] = $content; - $content = $target_data['comment']; + $content = $target_data['content']; $content = str_replace("##question_$uuid##", "##question_$id##", $content); $content = str_replace("##answer_$uuid##", "##answer_$id##", $content); - $target_data['comment'] = $content; + $target_data['content'] = $content; } } @@ -1563,10 +1563,10 @@ public function export($remove_uuid = false) { $content = str_replace("##answer_$id##", "##answer_$uuid##", $content); $target_data['name'] = $content; - $content = $target_data['comment']; + $content = $target_data['content']; $content = str_replace("##question_$id##", "##question_$uuid##", $content); $content = str_replace("##answer_$id##", "##answer_$uuid##", $content); - $target_data['comment'] = $content; + $target_data['content'] = $content; } } diff --git a/install/mysql/plugin_formcreator_empty.sql b/install/mysql/plugin_formcreator_empty.sql index 0534a8987..b6f245503 100644 --- a/install/mysql/plugin_formcreator_empty.sql +++ b/install/mysql/plugin_formcreator_empty.sql @@ -196,7 +196,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targettickets` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL DEFAULT '', `tickettemplates_id` int(11) DEFAULT NULL, - `comment` text, + `content` longtext, `due_date_rule` enum('answer','ticket','calcul') DEFAULT NULL, `due_date_question` int(11) DEFAULT NULL, `due_date_value` tinyint(4) DEFAULT NULL, diff --git a/install/update_2.6_2.7.php b/install/update_2.6_2.7.php index 33ee17cfc..1d9e59c3d 100644 --- a/install/update_2.6_2.7.php +++ b/install/update_2.6_2.7.php @@ -168,4 +168,7 @@ function plugin_formcreator_update_2_7(Migration $migration) { $migration->changeField($table, 'backoutplancontent', 'backoutplancontent', 'longtext'); $migration->changeField($table, 'checklistcontent', 'checklistcontent', 'longtext'); + // Update target target columns + $table = 'glpi_plugin_formcreator_targettickets'; + $migration->changeField($table, 'comment', 'content', 'longtext'); } diff --git a/tests/src/CommonTestCase.php b/tests/src/CommonTestCase.php index 6570862d9..a8ef3e957 100644 --- a/tests/src/CommonTestCase.php +++ b/tests/src/CommonTestCase.php @@ -330,7 +330,7 @@ protected function _checkTarget($target = []) { protected function _checkTargetTicket($targetticket = []) { $keys = [ 'title', - 'comment', + 'content', 'due_date_rule', 'due_date_question', 'due_date_value', diff --git a/tests/suite-integration/PluginFormcreatorTargetTicket.php b/tests/suite-integration/PluginFormcreatorTargetTicket.php index 5fb4940da..9ba4bb7e7 100644 --- a/tests/suite-integration/PluginFormcreatorTargetTicket.php +++ b/tests/suite-integration/PluginFormcreatorTargetTicket.php @@ -176,6 +176,7 @@ public function testUrgency() { $targetTicketsData = [ [ 'name' => 'target 1', + 'content' => '##FULLFORM##', 'itemtype' => 'PluginFormcreatorTargetTicket', 'urgency_rule' => 'answer', 'urgency_question' => 'custom urgency', @@ -183,6 +184,7 @@ public function testUrgency() { ], [ 'name' => 'target 2', + 'content' => '##FULLFORM##', 'itemtype' => 'PluginFormcreatorTargetTicket', 'urgency_rule' => 'none', 'urgency_question' => '', diff --git a/tests/suite-unit/PluginFormcreatorForm.php b/tests/suite-unit/PluginFormcreatorForm.php index 2df50e2d0..8425cfbf9 100644 --- a/tests/suite-unit/PluginFormcreatorForm.php +++ b/tests/suite-unit/PluginFormcreatorForm.php @@ -225,31 +225,49 @@ public function testExportForm() { $item_targetTicket = new \PluginFormcreatorItem_TargetTicket(); // create objects - $forms_id = $form->add(['name' => "test export form", - 'is_active' => true, - 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER]); - $sections_id = $form_section->add(['name' => "test export section", - 'plugin_formcreator_forms_id' => $forms_id]); - $questions_id_1 = $form_question->add(['name' => "test export question 1", - 'fieldtype' => 'text', - 'plugin_formcreator_sections_id' => $sections_id]); - $questions_id_2 = $form_question->add(['name' => "test export question 2", - 'fieldtype' => 'textarea', - 'plugin_formcreator_sections_id' => $sections_id]); - $form_condition->add(['plugin_formcreator_questions_id' => $questions_id_1, - 'show_field' => $questions_id_2, - 'show_condition' => '==', - 'show_value' => 'test']); - $form_validator->add(['plugin_formcreator_forms_id' => $forms_id, - 'itemtype' => 'User', - 'items_id' => 2]); - $form_validator->add(['plugin_formcreator_forms_id' => $forms_id, - 'itemtype' => 'User', - 'items_id' => 3]); - $targets_id = $form_target->add(['plugin_formcreator_forms_id' => $forms_id, - 'itemtype' => \PluginFormcreatorTargetTicket::class, - 'name' => "test export target"]); - $targetTicket_id = $targetTicket->add(['name' => $form_target->getField('name'), + $forms_id = $form->add([ + 'name' => "test export form", + 'is_active' => true, + 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER + ]); + $sections_id = $form_section->add([ + 'name' => "test export section", + 'plugin_formcreator_forms_id' => $forms_id + ]); + $questions_id_1 = $form_question->add([ + 'name' => "test export question 1", + 'fieldtype' => 'text', + 'plugin_formcreator_sections_id' => $sections_id + ]); + $questions_id_2 = $form_question->add([ + 'name' => "test export question 2", + 'fieldtype' => 'textarea', + 'plugin_formcreator_sections_id' => $sections_id + ]); + $form_condition->add([ + 'plugin_formcreator_questions_id' => $questions_id_1, + 'show_field' => $questions_id_2, + 'show_condition' => '==', + 'show_value' => 'test' + ]); + $form_validator->add([ + 'plugin_formcreator_forms_id' => $forms_id, + 'itemtype' => 'User', + 'items_id' => 2 + ]); + $form_validator->add([ + 'plugin_formcreator_forms_id' => $forms_id, + 'itemtype' => 'User', + 'items_id' => 3 + ]); + $targets_id = $form_target->add([ + 'plugin_formcreator_forms_id' => $forms_id, + 'itemtype' => \PluginFormcreatorTargetTicket::class, + 'name' => "test export target" + ]); + $targetTicket_id = $targetTicket->add([ + 'name' => $form_target->getField('name'), + 'content' => '##FULLFORM##' ]); $form_target->getFromDB($targets_id); $targettickets_id = $form_target->fields['items_id']; From 20e035246a3fef4d1f0c13ddd4ee9b0b3897a40e Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 11 Sep 2018 22:14:52 +0200 Subject: [PATCH 074/192] refactor: move js for actor, checkboxes, date, datetime and dropdown Signed-off-by: Thierry Bugier --- inc/fields/actorfield.class.php | 45 ++------------- inc/fields/checkboxesfield.class.php | 25 +++----- inc/fields/datefield.class.php | 14 ++--- inc/fields/datetimefield.class.php | 16 ++---- inc/fields/dropdownfield.class.php | 13 ++--- js/scripts.js.php | 86 ++++++++++++++++++++++++++++ 6 files changed, 114 insertions(+), 85 deletions(-) diff --git a/inc/fields/actorfield.class.php b/inc/fields/actorfield.class.php index 27f179866..10f15c86b 100644 --- a/inc/fields/actorfield.class.php +++ b/inc/fields/actorfield.class.php @@ -56,48 +56,15 @@ public function displayField($canEdit = true) { ]; } $initialValue = json_encode($initialValue); + $id = $this->fields['id']; // Value needs to be non empty to allow execition of select2's initSelection echo '' . PHP_EOL; + name="formcreator_field_' . $id . '" value="" />' . PHP_EOL; $values = []; $values = $this->getAvailableValues(); @@ -51,12 +52,12 @@ public function displayField($canEdit = true) { $current_value = $this->getValue(); echo "
"; echo Html::getCheckbox(['title' => $value, - 'id' => 'formcreator_field_'.$this->fields['id'].'_'.$i, - 'name' => 'formcreator_field_'.$this->fields['id'] . '[]', + 'id' => 'formcreator_field_'.$id.'_'.$i, + 'name' => 'formcreator_field_'.$id . '[]', 'value' => $value, 'zero_on_empty' => false, 'checked' => (!empty($current_value) && in_array($value, $current_value))]); - echo '
"; @@ -64,19 +65,9 @@ public function displayField($canEdit = true) { } echo ''; } - echo ''; + echo Html::scriptBlock("$(function() { + pluginFormcreatorInitializeCheckboxes($id); + });"); } else { $answer = null; diff --git a/inc/fields/datefield.class.php b/inc/fields/datefield.class.php index b0314aa12..f563ebb6f 100644 --- a/inc/fields/datefield.class.php +++ b/inc/fields/datefield.class.php @@ -35,6 +35,7 @@ class PluginFormcreatorDateField extends PluginFormcreatorField { public function displayField($canEdit = true) { if ($canEdit) { + $id = $this->fields['id']; $required = ($canEdit && $this->fields['required']) ? ' required' : ''; $rand = mt_rand(); @@ -42,16 +43,9 @@ public function displayField($canEdit = true) { 'value' => $this->getValue(), 'rand' => $rand, ]); - echo ''; + echo Html::scriptBlock("$(function() { + pluginFormcreatorInitializeDate($id, '$rand'); + });"); } else { echo $this->getAnswer(); diff --git a/inc/fields/datetimefield.class.php b/inc/fields/datetimefield.class.php index b6c2e9ebd..e58fcb9ed 100644 --- a/inc/fields/datetimefield.class.php +++ b/inc/fields/datetimefield.class.php @@ -35,23 +35,17 @@ class PluginFormcreatorDatetimeField extends PluginFormcreatorField { public function displayField($canEdit = true) { if ($canEdit) { + $id = $this->fields['id']; $required = ($canEdit && $this->fields['required']) ? ' required' : ''; $rand = mt_rand(); - Html::showDateTimeField('formcreator_field_' . $this->fields['id'], [ + Html::showDateTimeField('formcreator_field_' . $id, [ 'value' => $this->getValue(), 'rand' => $rand, ]); - echo ''; + echo Html::scriptBlock("$(function() { + pluginFormcreatorInitializeDate($id, '$rand'); + });"); } else { echo $this->getAnswer(); diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index f97527632..a317f2e2c 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -37,6 +37,7 @@ public function displayField($canEdit = true) { global $DB, $CFG_GLPI; if ($canEdit) { + $id = $this->fields['id']; if (!empty($this->fields['values'])) { $rand = mt_rand(); $required = $this->fields['required'] ? ' required' : ''; @@ -47,7 +48,7 @@ public function displayField($canEdit = true) { $itemtype = $decodedValues['itemtype']; } - $dparams = ['name' => 'formcreator_field_' . $this->fields['id'], + $dparams = ['name' => 'formcreator_field_' . $id, 'value' => $this->getValue(), 'comments' => false, 'rand' => $rand]; @@ -104,13 +105,9 @@ public function displayField($canEdit = true) { $itemtype::dropdown($dparams); } echo PHP_EOL; - echo ''; + echo Html::scriptBlock("$(function() { + pluginFormcreatorInitializeDropdown($id, '$rand'); + });"); } else { echo $this->getAnswer(); } diff --git a/js/scripts.js.php b/js/scripts.js.php index d9e9eb2f0..ac5473e78 100644 --- a/js/scripts.js.php +++ b/js/scripts.js.php @@ -700,3 +700,89 @@ function formcreatorChangeActorAssigned(value) { case 'question_supplier' : $('#block_assigned_question_supplier').show(); break; } } + +// === FIELDS === + + + + +/** + * Initialize an actor field + */ +function pluginFormcreatorInitializeActor(id, initialValue) { + fieldName = 'formcreator_field_' + id; + $("#" + fieldName).select2({ + tokenSeparators: [",", ";"], + minimumInputLength: 0, + ajax: { + url: rootDoc + "/ajax/getDropdownUsers.php", + type: "POST", + dataType: "json", + data: function (params, page) { + return { + entity_restrict: -1, + searchText: params.term, + page_limit: 100, + page: page + } + }, + results: function (data, page) { + var more = (data.count >= 100); + return {results: data.results, pagination: {"more": more}}; + } + }, + createSearchChoice: function itemCreator(term, data) { + if ($(data).filter(function() { + return this.text.localeCompare(term) === 0; + }).length === 0) { + return { id: term, text: term }; + } + }, + initSelection: function (element, callback) { + callback(JSON.parse(initialValue)); + } + }) + $("#" + fieldName).on("change", function(e) { + var selectedValues = $("#" + fieldName).val(); + formcreatorChangeValueOf(id, selectedValues); + }); +} + +/** + * Initialize a checkboxes field + */ +function pluginFormcreatorInitializeCheckboxes(id) { + fieldName = 'formcreator_field_' + id; + jQuery("input[name='" + fieldName + "[]']").on("change", function() { + var tab_values = new Array(); + jQuery("input[name='" + fieldName + "[]']").each(function() { + if (this.checked == true) { + tab_values.push(this.value); + } + }); + formcreatorChangeValueOf(id, tab_values); + }); +} + +/** + * Initialize a date field + */ +function pluginFormcreatorInitializeDate(id, rand) { + fieldName = 'formcreator_field_' + id; + $("#showdate" + rand).on("change", function() { + formcreatorChangeValueOf(id, this.value); + }); + $("#resetdate" + rand).on("click", function() { + formcreatorChangeValueOf(id, ""); + }); +} + +/** + * Initialize a dropdown field + */ +function pluginFormcreatorInitializeDropdown(id, rand) { + fieldName = 'formcreator_field_' + id; + jQuery("#dropdown_formcreator_field_" + id + rand).on("select2-selecting", function(e) { + formcreatorChangeValueOf (id, e.val); + }); +} From a086d00e84e4169a53067bee3e9e465bed7fca0a Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 11 Sep 2018 23:19:48 +0200 Subject: [PATCH 075/192] refactor: move js for radios, multiselect, select and urgency field Signed-off-by: Thierry Bugier --- inc/fields/checkboxesfield.class.php | 2 +- inc/fields/radiosfield.class.php | 14 ++------ inc/fields/selectfield.class.php | 11 ++---- inc/fields/tagfield.class.php | 11 +++--- inc/fields/urgencyfield.class.php | 10 ++---- js/scripts.js.php | 53 +++++++++++++++++++++++++--- 6 files changed, 63 insertions(+), 38 deletions(-) diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index a9f6b6656..fd8b9827e 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -66,7 +66,7 @@ public function displayField($canEdit = true) { echo ''; } echo Html::scriptBlock("$(function() { - pluginFormcreatorInitializeCheckboxes($id); + pluginFormcreatorInitializeCheckboxes($id, ''); });"); } else { diff --git a/inc/fields/radiosfield.class.php b/inc/fields/radiosfield.class.php index 8d50705af..e38bffb4e 100644 --- a/inc/fields/radiosfield.class.php +++ b/inc/fields/radiosfield.class.php @@ -57,17 +57,9 @@ public function displayField($canEdit = true) { } echo ''; } - echo ''; + echo Html::scriptBlock("$(function() { + pluginFormcreatorInitializeRadios($id, '$rand'); + });"); } else { echo $this->getAnswer(); diff --git a/inc/fields/selectfield.class.php b/inc/fields/selectfield.class.php index ed95d16cb..0d2f623fe 100644 --- a/inc/fields/selectfield.class.php +++ b/inc/fields/selectfield.class.php @@ -58,14 +58,9 @@ public function displayField($canEdit = true) { ]); } echo PHP_EOL; - echo ''; + echo Html::scriptBlock("$(function() { + pluginFormcreatorInitializeRadios($id, '$rand'); + });"); } else { echo nl2br($this->getAnswer()); echo PHP_EOL; diff --git a/inc/fields/tagfield.class.php b/inc/fields/tagfield.class.php index ed5a775ec..eb62abc6a 100644 --- a/inc/fields/tagfield.class.php +++ b/inc/fields/tagfield.class.php @@ -53,6 +53,7 @@ public function displayField($canEdit = true) { $values[$id] = $data['name']; } + $id = $this->fields['id']; Dropdown::showFromArray('formcreator_field_' . $this->fields['id'], $values, [ 'values' => $this->getValue(), 'comments' => false, @@ -60,13 +61,9 @@ public function displayField($canEdit = true) { 'multiple' => true, ]); echo PHP_EOL; - echo ''; + echo Html::scriptBlock("$(function() { + pluginFormcreatorInitializeTag($id, '$rand'); + });"); } else { $answer = $this->getAnswer(); echo '
'; diff --git a/inc/fields/urgencyfield.class.php b/inc/fields/urgencyfield.class.php index b27bb71cd..d7858b13f 100644 --- a/inc/fields/urgencyfield.class.php +++ b/inc/fields/urgencyfield.class.php @@ -43,13 +43,9 @@ public function displayField($canEdit = true) { 'rand' => $rand] ); echo PHP_EOL; - echo ''; + echo Html::scriptBlock("$(function() { + pluginFormcreatorInitializeUrgency($id, '$rand'); + });"); } else { echo Ticket::getPriorityName($this->getValue()); } diff --git a/js/scripts.js.php b/js/scripts.js.php index ac5473e78..f550b31b5 100644 --- a/js/scripts.js.php +++ b/js/scripts.js.php @@ -703,9 +703,6 @@ function formcreatorChangeActorAssigned(value) { // === FIELDS === - - - /** * Initialize an actor field */ @@ -751,7 +748,7 @@ function pluginFormcreatorInitializeActor(id, initialValue) { /** * Initialize a checkboxes field */ -function pluginFormcreatorInitializeCheckboxes(id) { +function pluginFormcreatorInitializeCheckboxes(id, rand) { fieldName = 'formcreator_field_' + id; jQuery("input[name='" + fieldName + "[]']").on("change", function() { var tab_values = new Array(); @@ -783,6 +780,54 @@ function pluginFormcreatorInitializeDate(id, rand) { function pluginFormcreatorInitializeDropdown(id, rand) { fieldName = 'formcreator_field_' + id; jQuery("#dropdown_formcreator_field_" + id + rand).on("select2-selecting", function(e) { + formcreatorChangeValueOf(id, e.val); + }); +} + +/** + * Initialize a radios field + */ +function pluginFormcreatorInitializeRadios(id, rand) { + fieldName = 'formcreator_field_' + id; + jQuery("input[name='" + fieldName + "']").on("change", function() { + jQuery("input[name='" + fieldName + "']").each(function() { + if (this.checked == true) { + formcreatorChangeValueOf(id, this.value); + } + }); + }); +} + +/** + * Initialize a select field + */ +function pluginFormcreatorInitializSelect(id, rand) { + fieldName = 'formcreator_field_' + id + rand; + jQuery("input[name='" + fieldName + "']").on("change", function() { + jQuery("input[name='" + fieldName + "']").each(function() { + if (this.checked == true) { + formcreatorChangeValueOf(id, this.value); + } + }); + }); +} + +/** + * Initialize a select field + */ +function pluginFormcreatorInitializeTag(id, rand) { + fieldName = 'dropdown_formcreator_field_' + id + rand; + jQuery("#" + fieldName).on("select2-selecting", function(e) { + formcreatorChangeValueOf (id, e.val); + }); +} + +/** + * Initialize a select field + */ +function pluginFormcreatorInitializeUrgency(id, rand) { + fieldName = 'formcreator_field_' + id + rand; + jQuery("#" + fieldName).on("select2-selecting", function(e) { formcreatorChangeValueOf (id, e.val); }); } From c3c26124dfaf7e359760de1b6f2e1e445c495773 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Sat, 15 Sep 2018 09:34:21 +0200 Subject: [PATCH 076/192] fix(install): check for composer autoload Signed-off-by: Thierry Bugier --- scripts/cliinstall.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/cliinstall.php b/scripts/cliinstall.php index 08733b2b4..2a85fd3c8 100644 --- a/scripts/cliinstall.php +++ b/scripts/cliinstall.php @@ -31,11 +31,15 @@ * --------------------------------------------------------------------- */ -(PHP_SAPI == 'cli') or die("Only available from command line"); +(PHP_SAPI == 'cli') or die('Only available from command line'); chdir(dirname($_SERVER["SCRIPT_FILENAME"])); -include (__DIR__ . "/../vendor/docopt/docopt/src/docopt.php"); +if (!is_readable(__DIR__ . '/../vendor/autoload.php')) { + echo 'Please run composer install --no-dev in the plugin directory' . PHP_EOL; + exit(1); +} +include (__DIR__ . '/../vendor/docopt/docopt/src/docopt.php'); $doc = << Date: Sat, 15 Sep 2018 09:15:48 +0200 Subject: [PATCH 077/192] refactor: reorder some columns in db Signed-off-by: Thierry Bugier --- install/mysql/plugin_formcreator_empty.sql | 8 ++++---- install/update_2.6_2.7.php | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/install/mysql/plugin_formcreator_empty.sql b/install/mysql/plugin_formcreator_empty.sql index b6f245503..d77084da5 100644 --- a/install/mysql/plugin_formcreator_empty.sql +++ b/install/mysql/plugin_formcreator_empty.sql @@ -35,11 +35,11 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_entityconfigs` ( CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms` ( `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, `entities_id` int(11) NOT NULL DEFAULT '0', `is_recursive` tinyint(1) NOT NULL DEFAULT '0', `access_rights` tinyint(1) NOT NULL DEFAULT '1', `requesttype` int(11) NOT NULL DEFAULT '0', - `name` varchar(255) NOT NULL, `description` varchar(255) DEFAULT NULL, `content` longtext, `plugin_formcreator_categories_id` int(11) unsigned NOT NULL DEFAULT '0', @@ -99,9 +99,9 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms_validators` ( CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questions` ( `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, `plugin_formcreator_sections_id` int(11) NOT NULL, `fieldtype` varchar(30) NOT NULL DEFAULT 'text', - `name` varchar(255) NOT NULL, `required` tinyint(1) NOT NULL DEFAULT '0', `show_empty` tinyint(1) NOT NULL DEFAULT '0', `default_values` text, @@ -132,8 +132,8 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questions_conditions` ( CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_sections` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `plugin_formcreator_forms_id` int(11) NOT NULL, `name` varchar(255) NOT NULL, + `plugin_formcreator_forms_id` int(11) NOT NULL, `order` int(11) NOT NULL DEFAULT '0', `uuid` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), @@ -231,10 +231,10 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targettickets_actors` ( CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_issues` ( `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL DEFAULT '', `display_id` varchar(255) NOT NULL, `original_id` int(11) NOT NULL DEFAULT '0', `sub_itemtype` varchar(100) NOT NULL DEFAULT '', - `name` varchar(255) NOT NULL DEFAULT '', `status` varchar(255) NOT NULL DEFAULT '', `date_creation` datetime NOT NULL, `date_mod` datetime NOT NULL, diff --git a/install/update_2.6_2.7.php b/install/update_2.6_2.7.php index 1d9e59c3d..e24e98979 100644 --- a/install/update_2.6_2.7.php +++ b/install/update_2.6_2.7.php @@ -171,4 +171,15 @@ function plugin_formcreator_update_2_7(Migration $migration) { // Update target target columns $table = 'glpi_plugin_formcreator_targettickets'; $migration->changeField($table, 'comment', 'content', 'longtext'); + + // Reorder columns on some tables + $tables = [ + 'glpi_plugin_formcreator_forms', + 'glpi_plugin_formcreator_questions', + 'glpi_plugin_formcreator_sections', + 'glpi_plugin_formcreator_issues', + ]; + foreach ($tables as $table) { + $migration->changeField($table, 'name', 'name', 'string', ['after' => 'id']); + } } From 9d38a45fb765b80ef80988d20dfee30f3161783f Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Sat, 15 Sep 2018 14:52:57 +0200 Subject: [PATCH 078/192] fix(actor): fix broken select tag Signed-off-by: Thierry Bugier --- inc/fields/actorfield.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/fields/actorfield.class.php b/inc/fields/actorfield.class.php index 27f179866..a624c17fa 100644 --- a/inc/fields/actorfield.class.php +++ b/inc/fields/actorfield.class.php @@ -60,7 +60,7 @@ public function displayField($canEdit = true) { echo ''; echo Html::scriptBlock('$(function() { $("#formcreator_field_' . $this->fields['id']. '").select2({ tokenSeparators: [",", ";"], From d80bd4ce67e39f63433fb30d64bcb1462bbfd9fe Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Sat, 15 Sep 2018 16:05:36 +0200 Subject: [PATCH 079/192] refactor: code refactor Signed-off-by: Thierry Bugier --- ajax/dropdown_values.php | 2 +- inc/exportableinterface.class.php | 32 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/ajax/dropdown_values.php b/ajax/dropdown_values.php index 9c5fe2407..a5085e70e 100644 --- a/ajax/dropdown_values.php +++ b/ajax/dropdown_values.php @@ -33,7 +33,7 @@ include ('../../../inc/includes.php'); -Session::checkRight("entity", UPDATE); +Session::checkRight('entity', UPDATE); if ($_REQUEST['dropdown_itemtype'] == '0' || !class_exists($_REQUEST['dropdown_itemtype'])) { Dropdown::showFromArray("dropdown_default_value", [], ['display_emptychoice' => true]); diff --git a/inc/exportableinterface.class.php b/inc/exportableinterface.class.php index bc1fc1da9..d49c90b27 100644 --- a/inc/exportableinterface.class.php +++ b/inc/exportableinterface.class.php @@ -1,4 +1,36 @@ . + * --------------------------------------------------------------------- + * @author Thierry Bugier + * @author Jérémy Moreau + * @copyright Copyright © 2011 - 2018 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + interface PluginFormcreatorExportableInterface { public function export($remove_uuid = false); From b7fd8eb3e21b49f36e9aaceff504947c8240340e Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Sat, 15 Sep 2018 20:17:29 +0200 Subject: [PATCH 080/192] refactor(form): remove useless argument to method Signed-off-by: Thierry Bugier --- front/formdisplay.php | 2 +- inc/form.class.php | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/front/formdisplay.php b/front/formdisplay.php index f3b5aae8c..67b7690d7 100644 --- a/front/formdisplay.php +++ b/front/formdisplay.php @@ -80,7 +80,7 @@ } } - $form->displayUserForm($form); + $form->displayUserForm(); } else { Html::displayNotFoundError(); diff --git a/inc/form.class.php b/inc/form.class.php index f5a413e9b..bdf9dd882 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -903,11 +903,9 @@ protected function showMyLastForms() { /** * Display the Form end-user form to be filled * - * @param CommonGLPI $item Instance of the Form to be displayed - * * @return Null Nothing, just display the form */ - public function displayUserForm(CommonGLPI $item) { + public function displayUserForm() { global $CFG_GLPI, $DB; if (isset($_SESSION['formcreator']['data'])) { @@ -921,19 +919,19 @@ public function displayUserForm(CommonGLPI $item) { echo Html::css("plugins/formcreator/css/print_form.css", ['media' => 'print']); // Display form - echo ""; echo "

"; - echo $item->fields['name']." "; + echo $this->fields['name']." "; echo ""; echo '

'; // Form Header - if (!empty($item->fields['content'])) { + if (!empty($this->fields['content'])) { echo '
'; - echo html_entity_decode($item->fields['content']); + echo html_entity_decode($this->fields['content']); echo '
'; } // Get and display sections of the form @@ -941,7 +939,7 @@ class='formcreator_form form_horizontal'>"; $questions = []; $section_class = new PluginFormcreatorSection(); - $find_sections = $section_class->find('plugin_formcreator_forms_id = ' . $item->getID(), '`order` ASC'); + $find_sections = $section_class->find('plugin_formcreator_forms_id = ' . $this->getID(), '`order` ASC'); echo '
'; foreach ($find_sections as $section_line) { echo '

' . $section_line['name'] . '

'; @@ -965,12 +963,12 @@ class='formcreator_form form_horizontal'>"; })'); // Show validator selector - if ($item->fields['validation_required'] > 0) { + if ($this->fields['validation_required'] > 0) { $table_form_validator = PluginFormcreatorForm_Validator::getTable(); $validators = [0 => Dropdown::EMPTY_VALUE]; // Groups - if ($item->fields['validation_required'] == 2) { + if ($this->fields['validation_required'] == 2) { $query = "SELECT g.`id`, g.`completename` FROM `glpi_groups` g LEFT JOIN `$table_form_validator` fv ON fv.`items_id` = g.`id` AND fv.itemtype = 'Group' @@ -1005,9 +1003,9 @@ class='formcreator_form form_horizontal'>"; echo ''; echo '
'; - echo ''; + echo ''; echo Html::hidden('_glpi_csrf_token', ['value' => Session::getNewCSRFToken()]); - echo ''; + echo ''; echo ''; } From a210e9a4a02c0c1e33a153465483a77b4d88e508 Mon Sep 17 00:00:00 2001 From: btry Date: Wed, 12 Sep 2018 10:20:02 +0200 Subject: [PATCH 081/192] fix(actorfield): default value not correctly handled Signed-off-by: Thierry Bugier --- ajax/dropdown_values.php | 2 +- ajax/showfields.php | 3 +- front/form.form.php | 1 + front/formdisplay.php | 2 +- front/question.form.php | 6 +- inc/comparisonexception.class.php | 38 +++ inc/exportableinterface.class.php | 34 +- inc/field.class.php | 87 ++--- inc/fieldinterface.class.php | 65 +++- inc/fields.class.php | 154 ++++----- inc/fields/actorfield.class.php | 201 ++++++++---- inc/fields/checkboxesfield.class.php | 116 +++++-- inc/fields/datefield.class.php | 72 +++- inc/fields/datetimefield.class.php | 72 +++- inc/fields/descriptionfield.class.php | 38 ++- inc/fields/dropdownfield.class.php | 110 ++++++- inc/fields/emailfield.class.php | 101 +++++- inc/fields/filefield.class.php | 55 +++- inc/fields/floatfield.class.php | 85 ++++- inc/fields/glpiselectfield.class.php | 45 ++- inc/fields/hiddenfield.class.php | 51 ++- inc/fields/hostnamefield.class.php | 49 ++- inc/fields/integerfield.class.php | 87 ++++- inc/fields/ipfield.class.php | 61 +++- inc/fields/ldapselectfield.class.php | 204 +++++++----- inc/fields/multiselectfield.class.php | 159 ++++++++- inc/fields/radiosfield.class.php | 106 +++++- inc/fields/selectfield.class.php | 116 +++++-- inc/fields/tagfield.class.php | 98 +++++- inc/fields/textareafield.class.php | 81 ++++- inc/fields/textfield.class.php | 61 +++- inc/fields/urgencyfield.class.php | 85 ++++- inc/form.class.php | 97 ++---- inc/form_answer.class.php | 26 +- inc/importlinker.class.php | 34 +- inc/question.class.php | 236 ++++---------- inc/questionparameter.class.php | 2 +- inc/questionparameterinterface.class.php | 34 +- inc/unknownfieldexception.class.php | 38 +++ js/scripts.js.php | 308 ++++++++++++------ .../PluginFormcreatorActorField.php | 227 +++++++++++-- tests/suite-unit/PluginFormcreatorForm.php | 2 - .../PluginFormcreatorMultiSelectField.php | 7 +- .../PluginFormcreatorSelectField.php | 6 +- 44 files changed, 2573 insertions(+), 889 deletions(-) create mode 100644 inc/comparisonexception.class.php create mode 100644 inc/unknownfieldexception.class.php diff --git a/ajax/dropdown_values.php b/ajax/dropdown_values.php index 9c5fe2407..a5085e70e 100644 --- a/ajax/dropdown_values.php +++ b/ajax/dropdown_values.php @@ -33,7 +33,7 @@ include ('../../../inc/includes.php'); -Session::checkRight("entity", UPDATE); +Session::checkRight('entity', UPDATE); if ($_REQUEST['dropdown_itemtype'] == '0' || !class_exists($_REQUEST['dropdown_itemtype'])) { Dropdown::showFromArray("dropdown_default_value", [], ['display_emptychoice' => true]); diff --git a/ajax/showfields.php b/ajax/showfields.php index a962014de..21f8ea013 100644 --- a/ajax/showfields.php +++ b/ajax/showfields.php @@ -33,7 +33,6 @@ include ('../../../inc/includes.php'); -$currentValues = json_decode(stripslashes($_POST['values']), true); -$visibility = PluginFormcreatorFields::updateVisibility($currentValues); +$visibility = PluginFormcreatorFields::updateVisibility($_POST); echo json_encode($visibility); exit(); diff --git a/front/form.form.php b/front/form.form.php index cc2811e50..ce60d251f 100644 --- a/front/form.form.php +++ b/front/form.form.php @@ -132,6 +132,7 @@ } else if (plugin_formcreator_replaceHelpdesk()) { Html::redirect('issue.php'); } else { + Html::back(); Html::redirect('formlist.php'); } } diff --git a/front/formdisplay.php b/front/formdisplay.php index f3b5aae8c..67b7690d7 100644 --- a/front/formdisplay.php +++ b/front/formdisplay.php @@ -80,7 +80,7 @@ } } - $form->displayUserForm($form); + $form->displayUserForm(); } else { Html::displayNotFoundError(); diff --git a/front/question.form.php b/front/question.form.php index 43a545832..bbe142fdd 100644 --- a/front/question.form.php +++ b/front/question.form.php @@ -43,6 +43,8 @@ $question = new PluginFormcreatorQuestion(); +// force checks in PrepareInputForAdd or PrepareInputrForUpdate +unset($_POST['_skip_checks']); if (isset($_POST["add"])) { // Add a new Question Session::checkRight("entity", UPDATE); @@ -80,14 +82,14 @@ // Set a Question required $question = new PluginFormcreatorQuestion(); $question->getFromDB((int) $_POST['id']); - $question->update(['required' => $_POST['value']] + $question->fields); + $question->setRequired($_POST['value']); } else if (isset($_POST["move"])) { // Move a Question Session::checkRight("entity", UPDATE); if ($question->getFromDB((int) $_POST['id'])) { - if ($_POST["way"] == 'up') { + if ($_POST['way'] == 'up') { $question->moveUp(); } else { $question->moveDown(); diff --git a/inc/comparisonexception.class.php b/inc/comparisonexception.class.php new file mode 100644 index 000000000..aa8d98448 --- /dev/null +++ b/inc/comparisonexception.class.php @@ -0,0 +1,38 @@ +. + * --------------------------------------------------------------------- + * @author Thierry Bugier + * @author Jérémy Moreau + * @copyright Copyright © 2011 - 2018 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + +if (!defined('GLPI_ROOT')) { + die("Sorry. You can't access this file directly"); +} + +class PluginFormcreatorComparisonException extends Exception{} \ No newline at end of file diff --git a/inc/exportableinterface.class.php b/inc/exportableinterface.class.php index bc1fc1da9..66f4e92ef 100644 --- a/inc/exportableinterface.class.php +++ b/inc/exportableinterface.class.php @@ -1,5 +1,37 @@ . + * --------------------------------------------------------------------- + * @author Thierry Bugier + * @author Jérémy Moreau + * @copyright Copyright © 2011 - 2018 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + + interface PluginFormcreatorExportableInterface { public function export($remove_uuid = false); } \ No newline at end of file diff --git a/inc/field.class.php b/inc/field.class.php index 7debb8be9..7f53f14b3 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -39,22 +39,24 @@ abstract class PluginFormcreatorField implements PluginFormcreatorFieldInterface { - const IS_MULTIPLE = false; - /** @var array $fields Fields of an instance of PluginFormcreatorQuestion */ protected $fields = []; + /** @var mixed $answer Value of the field */ + protected $value = null; + /** * * @param array $fields fields of a PluginFormcreatorQuestion instance * @param array $data value of all fields */ public function __construct($fields, $data = []) { - $this->fields = $fields; - $this->fields['answer'] = $data; + $this->fields = $fields; + $this->value = $data; } public function prepareQuestionInputForSave($input) { + $this->value = $input['default_values']; return $input; } @@ -62,10 +64,6 @@ public function prepareQuestionInputForTarget($input) { return Toolbox::addslashes_deep($input); } - public function prepareQuestionValuesForEdit($input) { - return $input; - } - /** * Output HTML to display the field * @param boolean $canEdit is the field editable ? @@ -89,17 +87,6 @@ public function show($canEdit = true) { echo '
'; $value = is_array($this->getAnswer()) ? json_encode($this->getAnswer()) : $this->getAnswer(); // $value = json_encode($this->getAnswer()); - if ($this->fields['fieldtype'] == 'dropdown') { - echo Html::scriptBlock('$(function() { - formcreatorAddValueOf(' . $this->fields['id'] . ', "' - . str_replace("\r\n", "\\r\\n", addslashes($this->fields['answer'])) . '"); - })'); - } else { - echo Html::scriptBlock('$(function() { - formcreatorAddValueOf(' . $this->fields['id'] . ', "' - . str_replace("\r\n", "\\r\\n", addslashes(html_entity_decode($value))) . '"); - })'); - } } /** @@ -107,12 +94,19 @@ public function show($canEdit = true) { * @param string $canEdit */ public function displayField($canEdit = true) { + $id = $this->fields['id']; + $rand = mt_rand(); + $fieldName = 'formcreator_field_' . $id; + $domId = $fieldName . '_' . $rand; + $defaultValue = Html::cleanInputText($this->getAnswer()); if ($canEdit) { echo ''; + name="' . $fieldName . '" + id="' . $domId . '" + value="' . $defaultValue . '" />'; + echo Html::scriptBlock("$(function() { + pluginFormcreatorInitializeField('$fieldName', '$rand'); + });"); } else { echo $this->getAnswer(); } @@ -127,51 +121,30 @@ public function getLabel() { return $this->fields['name']; } + /** + * Get the value of the answer + * @return mixed + */ public function getValue() { - if (isset($this->fields['answer'])) { - if (!is_array($this->fields['answer']) && is_array(json_decode($this->fields['answer']))) { - return json_decode($this->fields['answer']); - } - return $this->fields['answer']; - } else { - if (static::IS_MULTIPLE) { - return explode("\r\n", $this->fields['default_values']); - } - if (!$this->fields['show_empty'] && empty($this->fields['default_values'])) { - $availableValues = $this->getAvailableValues(); - return array_shift($availableValues); - } - return $this->fields['default_values']; - } + return $this->value; } - public function getAnswer() { + /** + * Get the value of the answer + * @return mixed + */ + public function getAnswer() { return $this->getValue(); } /** * Gets the available values for the field - * - * @return array + * @return array available values */ public function getAvailableValues() { return explode("\r\n", $this->fields['values']); } - public function isValid($value) { - // If the field is required it can't be empty - if ($this->isRequired() && empty($value)) { - Session::addMessageAfterRedirect( - __('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(), - false, - ERROR); - return false; - } - - // All is OK - return true; - } - public function isRequired() { return $this->fields['required']; } @@ -182,9 +155,9 @@ public function isRequired() { * @return string */ protected function trimValue($value) { - $value = explode('\\r\\n', $value); + $value = explode('\r\n', $value); $value = array_map('trim', $value); - return implode('\\r\\n', $value); + return implode('\r\n', $value); } public function getFieldTypeName() { diff --git a/inc/fieldinterface.class.php b/inc/fieldinterface.class.php index a397a94f8..e4226ae10 100644 --- a/inc/fieldinterface.class.php +++ b/inc/fieldinterface.class.php @@ -52,7 +52,7 @@ public static function getJSFields(); * @param string $value * @return boolean True if the field has a valid value, false otherwise */ - public function isValid($value); + //public function isValid($value); /** * Is the field required? @@ -60,6 +60,30 @@ public function isValid($value); */ public function isRequired(); + /** + * Serialize a value for save in the database + * Used to save a default value or a value + * + * @return string JSON encoded string + */ + public function serializeValue(); + + /** + * Deserialize a JSON encoded value or default value + * Used to retrieve the default value from a question + * or the value of an answer + * + * @param string $value + */ + public function deserializeValue($value); + + /** + * Get the value of the field for display in the form designer + * + * @return string + */ + public function getValueForDesign(); + /** * Transform input to properly save it in the database * @param array $input data to transform before save @@ -68,19 +92,18 @@ public function isRequired(); public function prepareQuestionInputForSave($input); /** - * Prepares an answer value for output in a target object - * @param string|array $input the answer to format for a target (ticket or change) - * @return string + * Read the value of the field from answers + * @param array $input answers of all questions of the form + * @return boolean true on sucess, false otherwise */ - public function prepareQuestionInputForTarget($input); + public function parseAnswerValues($input); /** - * Prepares a default value or set of values for question edition - * - * @param string $input + * Prepares an answer value for output in a target object + * @param string|array $input the answer to format for a target (ticket or change) * @return string */ - public function prepareQuestionValuesForEdit($input); + public function prepareQuestionInputForTarget($input); /** * Gets the parameters of the field @@ -120,4 +143,28 @@ public function updateParameters(PluginFormcreatorQuestion $question, array $inp * @return boolean true if success, false otherwise */ public function deleteParameters(PluginFormcreatorQuestion $question); + + /** + * Tests if the given value equals the field value + * @return boolean True if the value equals the field value + */ + public function equals($value); + + /** + * Tests if the given value is not equal to field value + * @return boolean True if the value is not equal to the field value + */ + public function notEquals($value); + + /** + * Tests if the given value is greater than the field value + * @return boolean True if the value is greater than the field value + */ + public function greaterThan($value); + + /** + * Tests if the given value is less than the field value + * @return boolean True if the value is less than the field value + */ + public function LessThan($value); } diff --git a/inc/fields.class.php b/inc/fields.class.php index 81da16e0e..0052c5f93 100644 --- a/inc/fields.class.php +++ b/inc/fields.class.php @@ -120,34 +120,34 @@ public static function printAllTabFieldsForJS() { return $tabFieldsForJS; } - /** - * - * @param array $field fields of a PluginFormcreatorQuestion instance - * @param mixed|null $data - * @param boolean $edit - */ - public static function showField($field, $data = null, $edit = true) { - // Get field types and file path - $tab_field_types = self::getTypes(); - - if (array_key_exists($field['fieldtype'], $tab_field_types)) { - $fieldClass = 'PluginFormcreator'.ucfirst($field['fieldtype']).'Field'; - - $plugin = new Plugin(); - if ($fieldClass == 'PluginFormcreatorTagField' && !$plugin->isActivated('tag')) { - return; - } - - $obj = new $fieldClass($field, $data); - $obj->show($edit); - } - } + // /** + // * + // * @param array $field fields of a PluginFormcreatorQuestion instance + // * @param mixed|null $data + // * @param boolean $edit + // */ + // public static function showField($field, $data = null, $edit = true) { + // // Get field types and file path + // $tab_field_types = self::getTypes(); + + // if (array_key_exists($field['fieldtype'], $tab_field_types)) { + // $fieldClass = 'PluginFormcreator'.ucfirst($field['fieldtype']).'Field'; + + // $plugin = new Plugin(); + // if ($fieldClass == 'PluginFormcreatorTagField' && !$plugin->isActivated('tag')) { + // return; + // } + + // $obj = new $fieldClass($field, $data); + // $obj->show($edit); + // } + // } /** * Check if a field should be shown or not * - * @param Integer $id ID of the current question - * @param Array $values Array of current fields values (id => value) + * @param integer $id ID of the current question + * @param array $values Array of current fields values (id => value) * @return boolean Should be shown or not */ public static function isVisible($id, $values) { @@ -156,7 +156,7 @@ public static function isVisible($id, $values) { */ static $evalQuestion = []; if (isset($evalQuestion[$id])) { - // TODO : how to deal a infinite loop while evaulating visibility of question ? + // TODO : how to deal a infinite loop while evaluating visibility of question ? return true; } $evalQuestion[$id] = $id; @@ -208,61 +208,61 @@ public static function isVisible($id, $values) { $values[$condition['field']] = ''; } + // TODO: find the best behavior if the question does not exists + $conditionQuestion = new PluginFormcreatorQuestion(); + $conditionQuestion->getFromDB($condition['field']); + $conditionField = PluginFormcreatorFields::getFieldInstance($conditionQuestion->fields['fieldtype'], $conditionQuestion); + $conditionField->prepareAnswerValueForSave($values[$condition['field']]); switch ($condition['operator']) { case '!=' : - if (empty($values[$condition['field']])) { - $value = true; - } else { - if (is_array($values[$condition['field']])) { - $decodedConditionField = null; - } else { - $decodedConditionField = json_decode($values[$condition['field']]); - } - if (is_array($values[$condition['field']])) { - $value = !in_array($condition['value'], $values[$condition['field']]); - } else if ($decodedConditionField !== null && $decodedConditionField != $values[$condition['field']]) { - $value = !in_array($condition['value'], $decodedConditionField); - } else { - $value = $condition['value'] != $values[$condition['field']]; - } + try { + $value = $conditionField->notEquals($condition['value']); + } catch (PluginFormcreatorComparisonException $e) { + $value = false; } break; case '==' : - if (empty($condition['value'])) { + try { + $value = $conditionField->equals($condition['value']); + } catch (PluginFormcreatorComparisonException $e) { + $value = false; + } + break; + + case '>': + try { + $value = $conditionField->greaterThan($condition['value']); + } catch (PluginFormcreatorComparisonException $e) { $value = false; - } else { - if (is_array($values[$condition['field']])) { - $decodedConditionField = null; - } else { - $decodedConditionField = json_decode($values[$condition['field']]); - } - if (is_array($values[$condition['field']])) { - $value = in_array($condition['value'], $values[$condition['field']]); - } else if ($decodedConditionField !== null && $decodedConditionField != $values[$condition['field']]) { - $value = in_array($condition['value'], $decodedConditionField); - } else { - $value = $condition['value'] == $values[$condition['field']]; - } } break; - default: - if (is_array($values[$condition['field']])) { - $decodedConditionField = null; - } else { - $decodedConditionField = json_decode($values[$condition['field']]); + case '<': + try { + $value = $conditionField->lessThan($condition['value']); + } catch (PluginFormcreatorComparisonException $e) { + $value = false; } - if (is_array($values[$condition['field']])) { - eval('$value = "'.$condition['value'].'" '.$condition['operator'] - .' Array('.implode(',', $values[$condition['field']]).');'); - } else if ($decodedConditionField !== null && $decodedConditionField != $values[$condition['field']]) { - eval('$value = "'.$condition['value'].'" '.$condition['operator'] - .' Array(' .implode(',', $decodedConditionField).');'); - } else { - eval('$value = "'.$values[$condition['field']].'" ' - .$condition['operator'].' "'.$condition['value'].'";'); + break; + + case '>=': + try { + $value = $conditionField->greaterThan($condition['value']) + || $conditionField->equals($condition['value']); + } catch (PluginFormcreatorComparisonException $e) { + $value = false; } + break; + + case '<=': + try { + $value = $conditionField->lessThan($condition['value']) + || $conditionField->equals($condition['value']); + } catch (PluginFormcreatorComparisonException $e) { + $value = false; + } + break; } // Combine all condition with respect of operator precedence @@ -325,22 +325,6 @@ public static function isVisible($id, $values) { * @rturn array */ public static function updateVisibility($currentValues) { - foreach ($currentValues as &$value) { - if (is_array($value)) { - foreach ($value as &$sub_value) { - $sub_value = plugin_formcreator_encode($sub_value, false); - } - } else if (is_array(json_decode($value))) { - $tab = json_decode($value); - foreach ($tab as &$sub_value) { - $sub_value = plugin_formcreator_encode($sub_value, false); - } - $value = json_encode($tab); - } else { - $value = stripslashes($value); - } - } - unset ($value); $questionToShow = []; foreach ($currentValues as $id => $value) { $questionToShow[$id] = PluginFormcreatorFields::isVisible($id, $currentValues); @@ -377,7 +361,7 @@ public static function fieldTypeExists($type) { * @param array $data additional data * @return null|PluginFormcreatorFieldInterface */ - public static function getFieldInstance($type, PluginFormcreatorQuestion $question, $data = []) { + public static function getFieldInstance($type, PluginFormcreatorQuestion $question, $data = null) { $className = self::getFieldClassname($type); if (!self::fieldTypeExists($type)) { return null; diff --git a/inc/fields/actorfield.class.php b/inc/fields/actorfield.class.php index 10f15c86b..28967ca47 100644 --- a/inc/fields/actorfield.class.php +++ b/inc/fields/actorfield.class.php @@ -33,8 +33,6 @@ class PluginFormcreatorActorField extends PluginFormcreatorField { - const IS_MULTIPLE = true; - public static function getName() { return _n('Actor', 'Actors', 1, 'formcreator'); } @@ -43,8 +41,8 @@ public function displayField($canEdit = true) { global $CFG_GLPI; $readonly = $canEdit ? 'false' : 'true'; - if (isset($this->fields['answer'])) { - $value = $this->sanitizeValue($this->fields['answer']); + if (isset($this->value)) { + $value = $this->sanitizeValue($this->value); } else { $value = $this->sanitizeValue($this->fields['default_values']); } @@ -56,79 +54,81 @@ public function displayField($canEdit = true) { ]; } $initialValue = json_encode($initialValue); - $id = $this->fields['id']; + $id = $this->fields['id']; + $rand = mt_rand(); + $fieldName = 'formcreator_field_' . $id; + $domId = $fieldName . '_' . $rand; + // Value needs to be non empty to allow execition of select2's initSelection echo ''; echo Html::scriptBlock("$(function() { - pluginFormcreatorInitializeActor($id, '$initialValue'); + pluginFormcreatorInitializeActor('$fieldName', '$rand', '$initialValue'); });"); } - public function serializeValue($value) { - $serialized = []; - $value = explode("\r\n", $value); - foreach ($value as $item) { - if (filter_var($item, FILTER_VALIDATE_EMAIL)) { - // a single email address - $serialized[$item] = $item; - } else { - $user = new User(); - $user->getFromDBbyName($item); - if (!$user->isNewItem()) { - // A user known in the DB - $serialized[$user->getID()] = $item; - } - } + public function serializeValue() { + if ($this->value === null || $this->value === '') { + return ''; } - return implode(',', (array_keys($serialized))); + return implode(',', $this->value); } public function deserializeValue($value) { $deserialized = []; - $serialized = explode(',', $value); - if ($serialized !== null) { - foreach ($serialized as $item) { - $item = trim($item); - if (filter_var($item, FILTER_VALIDATE_EMAIL) !== false) { - $deserialized[$item] = $item; - } else if (!empty($item) && ctype_digit($item) && intval($item)) { - $user = new User(); - $user->getFromDB($item); - if (!$user->isNewItem()) { - // A user known in the DB - $deserialized[$user->getID()] = $user->getField('name'); - } - } + $serialized = ($value !== null && $value !== '') + ? explode(',', $value) + : []; + foreach ($serialized as $item) { + $item = trim($item); + if (filter_var($item, FILTER_VALIDATE_EMAIL) !== false) { + $deserialized[] = $item; + } else if (!empty($item) && ctype_digit($item) && intval($item)) { + $deserialized[] = $item; } } - return implode("\r\n", $deserialized); + $this->value = $deserialized; } - protected function sanitizeValue($value) { - $value = trim($value); - if (is_array(json_decode($value))) { - // For GLPI 9.3+ - // the HTML field is no longer an HTML input - // it is now a HTML select - $answerValue = array_filter(json_decode($value)); - } else { - // for GLPI < 9.3 and default values from DB regardless GLPI version - $answerValue = array_filter(explode(',', $value)); + public function getValueForDesign() { + if ($this->value === null) { + return ''; + } + + $value = []; + foreach ($this->value as $item) { + if (filter_var($item, FILTER_VALIDATE_EMAIL) !== false) { + $value[] = $item; + } else { + $user = new User(); + $user->getFromDB($item); + if (!$user->isNewItem()) { + // A user known in the DB + $value[] = $user->getField('name'); + } + } } + return implode("\r\n", $value); + } + /** + * Sanitize the list of users or emails + * @param array list of users and emails + * @return array cleaned list of users and emails + */ + protected function sanitizeValue($value) { $unknownUsers = []; $knownUsers = []; $idToCheck = []; - foreach ($answerValue as $item) { + foreach ($value as $item) { $item = trim($item); if (filter_var($item, FILTER_VALIDATE_EMAIL) !== false) { $unknownUsers[$item] = $item; - } else if (!empty($item) && ctype_digit($item) && intval($item)) { + } else if (strlen($item) > 0 && ctype_digit($item)) { $user = new User(); $user->getFromDB($item); if (!$user->isNewItem()) { @@ -140,37 +140,24 @@ protected function sanitizeValue($value) { return $knownUsers + $unknownUsers; } - public function isValid($value) { - $sanitized = $this->sanitizeValue($value); - - // Ignore empty values - $value = trim($value); - $value = array_filter(explode(',', $value)); + public function isValid() { + $value = $this->value; + $sanitized = $this->sanitizeValue($this->value); // If the field is required it can't be empty - if ($this->isRequired() && count($value) == 0) { + if ($this->isRequired() && count($this->value) === 0) { Session::addMessageAfterRedirect(__('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(), false, ERROR); return false; } // If an item has been removed by sanitization, then the data is not valid - if (count($sanitized) != count($value)) { + if (count($sanitized) != count($this->value)) { Session::addMessageAfterRedirect(__('Invalid value:', 'formcreator') . ' ' . $this->getLabel(), false, ERROR); return false; } return true; } - public function getValue() { - if (isset($this->fields['answer'])) { - $value = $this->sanitizeValue($this->fields['answer']); - } else { - $value = $this->sanitizeValue($this->fields['default_values']); - } - - return implode(',', $value); - } - public static function getPrefs() { return [ 'required' => 1, @@ -191,7 +178,77 @@ public static function getJSFields() { return "tab_fields_fields['actor'] = 'showFields(" . implode(', ', $prefs) . ");';"; } - public function prepareQuestionValuesForEdit($input) { - return $this->deserializeValue($input); + public function prepareQuestionInputForSave($input) { + $parsed = []; + $defaultValue = $input['default_values']; + $serialized = ($defaultValue !== null && $defaultValue !== '') + ? explode('\r\n', $defaultValue) + : []; + foreach ($serialized as $item) { + $item = trim($item); + if (filter_var($item, FILTER_VALIDATE_EMAIL) !== false) { + $parsed[] = $item; + } else if (!empty($item)) { + $user = new User(); + $user->getFromDBByName($item); + if (!$user->isNewItem()) { + // A user known in the DB + $parsed[] = $user->getID(); + } + } + } + + $this->value = $parsed; + $input['default_values'] = $this->serializeValue(); + + return $input; + } + + public function parseAnswerValues($input) { + $key = 'formcreator_field_' . $this->fields['id']; + if (!is_array($input[$key])) { + return false; + } + + $this->value = $input[$key]; + return true; + } + + public function equals($value) { + $user = new User(); + if (!$user->getFromDBByName($value)) { + // value does not match any user, test if it is an email address + if (filter_var($value, FILTER_VALIDATE_EMAIL) === false) { + // Not an email address, + // no need to test against the values of the field + return false; + } + + if (!is_array($this->value)) { + // No content in the field, but a email in the other operand + return false; + } + + // find the email address in the values of the field + return in_array($value, $this->value); + } + if (!is_array($this->value)) { + // No user selected + return false; + } + + return in_array($user->getID(), $this->value); + } + + public function notEquals($value) { + return !$this->equals($value); + } + + public function greaterThan($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } + + public function lessThan($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); } } diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index fd8b9827e..2689ad84e 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -33,12 +33,14 @@ class PluginFormcreatorCheckboxesField extends PluginFormcreatorField { - const IS_MULTIPLE = true; public function displayField($canEdit = true) { if ($canEdit) { - $id = $this->fields['id']; - echo '' . PHP_EOL; + $id = $this->fields['id']; + $rand = mt_rand(); + $fieldName = 'formcreator_field_' . $id; + $domId = $fieldName . '_' . $rand; + // echo '' . PHP_EOL; $values = []; $values = $this->getAvailableValues(); @@ -51,14 +53,16 @@ public function displayField($canEdit = true) { $current_value = null; $current_value = $this->getValue(); echo "
"; - echo Html::getCheckbox(['title' => $value, - 'id' => 'formcreator_field_'.$id.'_'.$i, - 'name' => 'formcreator_field_'.$id . '[]', - 'value' => $value, - 'zero_on_empty' => false, - 'checked' => (!empty($current_value) && in_array($value, $current_value))]); - echo '
"; } @@ -66,7 +70,7 @@ public function displayField($canEdit = true) { echo ''; } echo Html::scriptBlock("$(function() { - pluginFormcreatorInitializeCheckboxes($id, ''); + pluginFormcreatorInitializeCheckboxes('$fieldName', '$rand'); });"); } else { @@ -86,14 +90,51 @@ public function displayField($canEdit = true) { } } - public function isValid($value) { - $value = json_decode($value); + public function serializeValue() { + if ($this->value === null || $this->value === '') { + return ''; + } + + return implode("\r\n", $this->value); + } + + public function deserializeValue($value) { + $deserialized = []; + $this->value = ($value !== null && $value !== '') + ? explode("\r\n", $value) + : []; + } + + public function getValueForDesign() { + if ($this->value === null) { + return ''; + } + + return implode("\r\n", $this->value); + } + + public function parseAnswerValues($input) { + $key = 'formcreator_field_' . $this->fields['id']; + if (!isset($input[$key])) { + $input[$key] = []; + } else { + if (!is_array($input[$key])) { + return false; + } + } + + $this->value = $input[$key]; + return true; + } + + public function isValid() { + $value = $this->value; if (is_null($value)) { $value = []; } // If the field is required it can't be empty - if ($this->isRequired() && empty($value)) { + if ($this->isRequired() && count($value) <= 0) { Session::addMessageAfterRedirect( __('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(), false, @@ -101,11 +142,7 @@ public function isValid($value) { return false; } - if (!$this->isValidValue($value)) { - return false; - } - - return true; + return $this->isValidValue($value); } private function isValidValue($value) { @@ -135,17 +172,6 @@ public static function getName() { return __('Checkboxes', 'formcreator'); } - public function getValue() { - if (isset($this->fields['answer'])) { - if (!is_array($this->fields['answer']) && is_array(json_decode($this->fields['answer']))) { - return json_decode($this->fields['answer']); - } - return $this->fields['answer']; - } else { - return explode("\r\n", $this->fields['default_values']); - } - } - public function prepareQuestionInputForSave($input) { if (isset($input['values'])) { if (empty($input['values'])) { @@ -159,7 +185,11 @@ public function prepareQuestionInputForSave($input) { } } if (isset($input['default_values'])) { - $input['default_values'] = $this->trimValue($input['default_values']); + $this->value = explode('\r\n', $input['default_values']); + $this->value = array_map('trim', $this->value); + $this->value = array_filter($this->value, function($value) { + return ($value !== ''); + }); } return $input; } @@ -228,4 +258,24 @@ public function getEmptyParameters() { ), ]; } + + public function equals($value) { + if (!is_array( $this->value)) { + // No checkbox enabled + return ($value === ''); + } + return in_array($value, $this->value); + } + + public function notEquals($value) { + return !$this->equals($value); + } + + public function greaterThan($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } + + public function lessThan($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } } diff --git a/inc/fields/datefield.class.php b/inc/fields/datefield.class.php index f563ebb6f..a78c2c5ac 100644 --- a/inc/fields/datefield.class.php +++ b/inc/fields/datefield.class.php @@ -35,16 +35,18 @@ class PluginFormcreatorDateField extends PluginFormcreatorField { public function displayField($canEdit = true) { if ($canEdit) { - $id = $this->fields['id']; - $required = ($canEdit && $this->fields['required']) ? ' required' : ''; - $rand = mt_rand(); + $id = $this->fields['id']; + $rand = mt_rand(); + $fieldName = 'formcreator_field_' . $id; + $domId = $fieldName . '_' . $rand; + $required = ($canEdit && $this->fields['required']) ? ' required' : ''; - Html::showDateField('formcreator_field_' . $this->fields['id'], [ + Html::showDateField($fieldName, [ 'value' => $this->getValue(), 'rand' => $rand, ]); echo Html::scriptBlock("$(function() { - pluginFormcreatorInitializeDate($id, '$rand'); + pluginFormcreatorInitializeDate('$fieldName', '$rand'); });"); } else { @@ -53,8 +55,8 @@ public function displayField($canEdit = true) { } public function getValue() { - if (isset($this->fields['answer'])) { - $date = $this->fields['answer']; + if (isset($this->value)) { + $date = $this->value; } else { $date = $this->fields['default_values']; } @@ -65,9 +67,21 @@ public function getAnswer() { return Html::convDate($this->getValue()); } - public function isValid($value) { + public function serializeValue() { + return ''; + } + + public function deserializeValue($value) { + $this->value = ''; + } + + public function getValueForDesign() { + return ''; + } + + public function isValid() { // If the field is required it can't be empty - if ($this->isRequired() && (strtotime($value) == '')) { + if ($this->isRequired() && (strtotime($this->value) === false)) { Session::addMessageAfterRedirect( __('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(), false, @@ -102,4 +116,44 @@ public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['date'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + public function equals($value) { + if (empty($this->value)) { + $answer = '0000-00-00 00:00'; + } else { + $answer = $this->value; + } + $answerDatetime = DateTime::createFromFormat("Y-m-d", $answer); + $compareDatetime = DateTime::createFromFormat("Y-m-d", $value); + return $answerDatetime == $compareDatetime; + } + + public function notEquals($value) { + return !$this->equals($value); + } + + public function greaterThan($value) { + if (empty($this->value)) { + $answer = '0000-00-00 00:00'; + } else { + $answer = $this->value; + } + $answerDatetime = DateTime::createFromFormat("Y-m-d", $answer); + $compareDatetime = DateTime::createFromFormat("Y-m-d", $value); + return $answerDatetime > $compareDatetime; + } + + public function lessThan($value) { + return !$this->greaterThan($value) && !$this->equals($value); + } + + public function parseAnswerValues($input) { + $key = 'formcreator_field_' . $this->fields['id']; + if (!is_string($input[$key])) { + return false; + } + + $this->value = $input[$key]; + return true; + } } diff --git a/inc/fields/datetimefield.class.php b/inc/fields/datetimefield.class.php index e58fcb9ed..d105fe711 100644 --- a/inc/fields/datetimefield.class.php +++ b/inc/fields/datetimefield.class.php @@ -35,16 +35,18 @@ class PluginFormcreatorDatetimeField extends PluginFormcreatorField { public function displayField($canEdit = true) { if ($canEdit) { - $id = $this->fields['id']; - $required = ($canEdit && $this->fields['required']) ? ' required' : ''; - $rand = mt_rand(); + $id = $this->fields['id']; + $rand = mt_rand(); + $fieldName = 'formcreator_field_' . $id; + $domId = $fieldName . '_' . $rand; + $required = ($canEdit && $this->fields['required']) ? ' required' : ''; - Html::showDateTimeField('formcreator_field_' . $id, [ + Html::showDateTimeField($fieldName, [ 'value' => $this->getValue(), 'rand' => $rand, ]); echo Html::scriptBlock("$(function() { - pluginFormcreatorInitializeDate($id, '$rand'); + pluginFormcreatorInitializeDate('$fieldName', '$rand'); });"); } else { @@ -52,9 +54,21 @@ public function displayField($canEdit = true) { } } + public function serializeValue() { + return ''; + } + + public function deserializeValue($value) { + $this->value = ''; + } + + public function getValueForDesign() { + return ''; + } + public function getValue() { - if (isset($this->fields['answer'])) { - $date = $this->fields['answer']; + if (isset($this->value)) { + $date = $this->value; } else { $date = $this->fields['default_values']; } @@ -65,9 +79,9 @@ public function getAnswer() { return Html::convDateTime($this->getValue()); } - public function isValid($value) { + public function isValid() { // If the field is required it can't be empty - if ($this->isRequired() && (strtotime($value) == '')) { + if ($this->isRequired() && (strtotime($this->value) == '')) { Session::addMessageAfterRedirect( __('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(), false, @@ -102,4 +116,44 @@ public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['datetime'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + public function equals($value) { + if (empty($this->value)) { + $answer = '0000-00-00 00:00'; + } else { + $answer = $this->value; + } + $answerDatetime = DateTime::createFromFormat("Y-m-d H:i", $answer); + $compareDatetime = DateTime::createFromFormat("Y-m-d H:i", $value); + return $answerDatetime == $compareDatetime; + } + + public function notEquals($value) { + return !$this->equals($value); + } + + public function greaterThan($value) { + if (empty($this->value)) { + $answer = '0000-00-00 00:00'; + } else { + $answer = $this->value; + } + $answerDatetime = DateTime::createFromFormat("Y-m-d H:i", $answer); + $compareDatetime = DateTime::createFromFormat("Y-m-d H:i", $value); + return $answerDatetime > $compareDatetime; + } + + public function lessThan($value) { + return !$this->greaterThan($value) && !$this->equals($value); + } + + public function parseAnswerValues($input) { + $key = 'formcreator_field_' . $this->fields['id']; + if (!is_string($input[$key])) { + return false; + } + + $this->value = $input[$key]; + return true; + } } diff --git a/inc/fields/descriptionfield.class.php b/inc/fields/descriptionfield.class.php index 1f6cd609d..65f87088f 100644 --- a/inc/fields/descriptionfield.class.php +++ b/inc/fields/descriptionfield.class.php @@ -37,12 +37,21 @@ public function show($canEdit = true) { echo '
'; echo nl2br(html_entity_decode($this->fields['description'])); echo '
' . PHP_EOL; - echo Html::scriptBlock('$(function() { - formcreatorAddValueOf(' . $this->fields['id'] . ', ""); - })'); } - public function isValid($value) { + public function serializeValue() { + return ''; + } + + public function deserializeValue($value) { + $this->value = ''; + } + + public function getValueForDesign() { + return ''; + } + + public function isValid() { return true; } @@ -61,6 +70,7 @@ public function prepareQuestionInputForSave($input) { } $input['description'] = addslashes($input['description']); } + $this->value = ''; return $input; } @@ -84,4 +94,24 @@ public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['description'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + public function equals($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } + + public function notEquals($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } + + public function greaterThan($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } + + public function lessThan($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } + + public function parseAnswerValues($input) { + return true; + } } diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index a317f2e2c..dd19e4dc2 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -37,10 +37,12 @@ public function displayField($canEdit = true) { global $DB, $CFG_GLPI; if ($canEdit) { - $id = $this->fields['id']; + $id = $this->fields['id']; + $rand = mt_rand(); + $fieldName = 'formcreator_field_' . $id; + $domId = $fieldName . '_' . $rand; + $required = $this->fields['required'] ? ' required' : ''; if (!empty($this->fields['values'])) { - $rand = mt_rand(); - $required = $this->fields['required'] ? ' required' : ''; $decodedValues = json_decode($this->fields['values'], JSON_OBJECT_AS_ARRAY); if ($decodedValues === null) { $itemtype = $this->fields['values']; @@ -48,7 +50,7 @@ public function displayField($canEdit = true) { $itemtype = $decodedValues['itemtype']; } - $dparams = ['name' => 'formcreator_field_' . $id, + $dparams = ['name' => $fieldName, 'value' => $this->getValue(), 'comments' => false, 'rand' => $rand]; @@ -106,16 +108,38 @@ public function displayField($canEdit = true) { } echo PHP_EOL; echo Html::scriptBlock("$(function() { - pluginFormcreatorInitializeDropdown($id, '$rand'); + pluginFormcreatorInitializeDropdown('$fieldName', '$rand'); });"); } else { echo $this->getAnswer(); } } + public function serializeValue() { + if ($this->value === null || $this->value === '') { + return ''; + } + + return $this->value; + } + + public function deserializeValue($value) { + $this->value = ($value !== null && $value !== '') + ? $value + : ''; + } + + public function getValueForDesign() { + if ($this->value === null) { + return ''; + } + + return $this->value; + } + public function getValue() { - if (isset($this->fields['answer'])) { - return $this->fields['answer']; + if (isset($this->value)) { + return $this->value; } if (!empty($this->fields['default_values'])) { return $this->fields['default_values']; @@ -146,6 +170,23 @@ public static function getName() { return _n('Dropdown', 'Dropdowns', 1); } + public function isValid() { + // If the field is required it can't be empty + $itemtype = json_decode($this->fields['values'], true); + $itemtype = $itemtype['itemtype']; + $dropdown = new $itemtype(); + if ($this->isRequired() && $dropdown->isNewId($this->value)) { + Session::addMessageAfterRedirect( + __('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(), + false, + ERROR); + return false; + } + + // All is OK + return true; + } + public function prepareQuestionInputForSave($input) { if (isset($input['dropdown_values'])) { if (empty($input['dropdown_values'])) { @@ -181,8 +222,9 @@ public function prepareQuestionInputForSave($input) { $input['values'] = json_encode($input['values']); unset($input['show_ticket_categories']); unset($input['show_ticket_categories_depth']); - $input['default_values'] = isset($input['dropdown_default_value']) ? $input['dropdown_default_value'] : ''; + $this->value = isset($input['dropdown_default_value']) ? $input['dropdown_default_value'] : ''; } + return $input; } @@ -241,4 +283,56 @@ private function getMyGroups($userID) { } return $a_groups; } + + public function equals($value) { + $value = html_entity_decode($value); + $itemtype = json_decode($this->fields['values'], true); + $itemtype = $itemtype['itemtype']; + $dropdown = new $itemtype(); + if ($dropdown->isNewId($this->value)) { + return ($value === ''); + } + if (!$dropdown->getFromDB($this->value)) { + throw new PluginFormcreatorComparisonException('Item not found for comparison'); + } + if (is_a($dropdown, CommonTreeDropdown::class)) { + $name = $dropdown->getField($dropdown->getCompleteNameField()); + } else { + $name = $dropdown->getField($dropdown->getNameField()); + } + return $name == $value; + } + + public function notEquals($value) { + return !$this->equals($value); + } + + public function greaterThan($value) { + $value = html_entity_decode($value); + $itemtype = $this->fields['values']; + $dropdown = new $itemtype(); + if (!$dropdown->getFromDB($this->value)) { + throw new PluginFormcreatorComparisonException('Item not found for comparison'); + } + if (is_a($dropdown, CommonTreeDropdown::class)) { + $name = $dropdown->getField($dropdown->getCompleteNameField()); + } else { + $name = $dropdown->getField($dropdown->getNameField()); + } + return $name > $value; + } + + public function lessThan($value) { + return !$this->greaterThan($value) && !$this->equals($value); + } + + public function parseAnswerValues($input) { + $key = 'formcreator_field_' . $this->fields['id']; + if (!is_string($input[$key])) { + return false; + } + + $this->value = $input[$key]; + return true; + } } diff --git a/inc/fields/emailfield.class.php b/inc/fields/emailfield.class.php index 789c1575d..3a51da684 100644 --- a/inc/fields/emailfield.class.php +++ b/inc/fields/emailfield.class.php @@ -35,27 +35,61 @@ class PluginFormcreatorEmailField extends PluginFormcreatorField { public function displayField($canEdit = true) { if ($canEdit) { - $required = $this->fields['required'] ? ' required' : ''; + $id = $this->fields['id']; + $rand = mt_rand(); + $fieldName = 'formcreator_field_' . $id; + $domId = $fieldName . '_' . $rand; + $required = $this->fields['required'] ? ' required' : ''; + $defaultValue = Html::cleanInputText($this->getValue()); echo ''; + name="' . $fieldName . '" + id="' . $domId . '" + value="' . $defaultValue . '" />'; + echo Html::scriptBlock("$(function() { + pluginFormcreatorInitializeEmail('$fieldName', '$rand'); + });"); } else { echo $this->getAnswer(); } } - public function isValid($value) { - if (!parent::isValid($value)) { - return false; + public function serializeValue() { + if ($this->value === null || $this->value === '') { + return ''; } - // Specific format not set or well match - if (!empty($value) && !filter_var($value, FILTER_VALIDATE_EMAIL)) { - Session::addMessageAfterRedirect(__('This is not a valid e-mail:', 'formcreator') . ' ' . $this->getLabel(), false, ERROR); - return false; + return $this->value; + } + + public function deserializeValue($value) { + $this->value = ($value !== null && $value !== '') + ? $value + : ''; + } + + public function getValueForDesign() { + if ($this->value === null) { + return ''; + } + + return $this->value; + } + + public function isValid() { + if ($this->value == '') { + if ($this->isRequired()) { + Session::addMessageAfterRedirect( + __('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(), + false, + ERROR); + return false; + } + } else { + if (!filter_var($this->value, FILTER_VALIDATE_EMAIL)) { + Session::addMessageAfterRedirect(__('This is not a valid e-mail:', 'formcreator') . ' ' . $this->getLabel(), false, ERROR); + return false; + } } // All is OK @@ -85,4 +119,47 @@ public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['email'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + public function getValue() { + if (isset($this->value)) { + return $this->value; + } else { + return $this->fields['default_values']; + } + } + + public function prepareQuestionInputForSave($input) { + $input['values'] = ''; + $this->value = $input['default_values']; + return $input; + } + + public function parseAnswerValues($input) { + $key = 'formcreator_field_' . $this->fields['id']; + if (!is_string($input[$key])) { + return false; + } + if (!filter_var($value, FILTER_VALIDATE_EMAIL)) { + return false; + } + + $this->value = $input[$key]; + return true; + } + + public function equals($value) { + return $this->getValue() == $value; + } + + public function notEquals($value) { + return !$this->equals($value); + } + + public function greaterThan($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } + + public function lessThan($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } } diff --git a/inc/fields/filefield.class.php b/inc/fields/filefield.class.php index 6988f4080..d7f112196 100644 --- a/inc/fields/filefield.class.php +++ b/inc/fields/filefield.class.php @@ -33,6 +33,8 @@ class PluginFormcreatorFileField extends PluginFormcreatorField { + private $uploadData = []; + public function displayField($canEdit = true) { if ($canEdit) { $required = $this->isRequired() ? ' required' : ''; @@ -49,27 +51,41 @@ public function displayField($canEdit = true) { } else { $doc = new Document(); $answer = $this->getAnswer(); - if (is_numeric($answer)) { + if (!is_array($answer)) { $answer = [$answer]; } foreach ($answer as $item) { - if ($doc->getFromDB($item)) { + if (is_numeric($item) && $doc->getFromDB($item)) { echo $doc->getDownloadLink(); } } } } - public function isValid($value) { - // If the field is required it can't be empty + public function serializeValue() { + return ''; + } + public function deserializeValue($value) { + $this->value = ''; + } + + public function getValueForDesign() { + return ''; + } + + public function isValid() { if (!$this->isRequired()) { return true; } - if (is_array($_POST['_formcreator_field_' . $this->fields['id']]) - && count($_POST['_formcreator_field_' . $this->fields['id']]) > 0) { - foreach ($_POST['_formcreator_field_' . $this->fields['id']] as $file) { + return $this->isValidValue($this->value); + } + + private function isValidValue($value) { + // If the field is required it can't be empty + if (count($this->uploadData) > 0) { + foreach ($this->uploadData as $file) { if (!is_file(GLPI_TMP_DIR . '/' . $file)) { Session::addMessageAfterRedirect(__('A required file is missing:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); return false; @@ -103,4 +119,29 @@ public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['file'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + public function parseAnswerValues($input) { + $key = 'formcreator_field_' . $this->fields['id']; + if (!is_array($input[$key])) { + return false; + } + $this->uploadData = $input["_$key"]; + return true; + } + + public function equals($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } + + public function notEquals($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } + + public function greaterThan($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } + + public function lessThan($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } } diff --git a/inc/fields/floatfield.class.php b/inc/fields/floatfield.class.php index e70d24a65..8c2024bd8 100644 --- a/inc/fields/floatfield.class.php +++ b/inc/fields/floatfield.class.php @@ -33,12 +33,46 @@ class PluginFormcreatorFloatField extends PluginFormcreatorField { - public function isValid($value) { - if (!parent::isValid($value)) { + public function getValue() { + if (isset($this->value)) { + return $this->value; + } else { + return $this->fields['default_values']; + } + } + + public function serializeValue() { + if ($this->value === null || $this->value === '') { + return ''; + } + + return strval((float) $this->value); + } + + public function deserializeValue($value) { + $this->value = ($value !== null && $value !== '') + ? $value + : ''; + } + + public function getValueForDesign() { + if ($this->value === null) { + return ''; + } + + return $this->value; + } + + public function isValid() { + if ($this->isRequired() && $this->value == '') { + Session::addMessageAfterRedirect( + __('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(), + false, + ERROR); return false; } - if (!$this->isValidValue($value)) { + if (!$this->isValidValue($this->value)) { return false; } @@ -107,22 +141,27 @@ public function prepareQuestionInputForSave($input) { return false; } - if (isset($input['range_min']) - && isset($input['range_max']) - && isset($input['default_values'])) { - $input['default_values'] = !empty($input['default_values']) - ? (float) str_replace(',', '.', $input['default_values']) - : null; - $input['range_min'] = !empty($input['range_min']) - ? (float) str_replace(',', '.', $input['range_min']) - : null; - $input['range_max'] = !empty($input['range_max']) - ? (float) str_replace(',', '.', $input['range_max']) - : null; + if (isset($input['default_values'])) { + $this->value = (float) str_replace(',', '.', $input['default_values']); } + $input['values'] = ''; + return $input; } + public function parseAnswerValues($input) { + $key = 'formcreator_field_' . $this->fields['id']; + if (!is_string($input[$key])) { + return false; + } + if ($input[$key] != (float) str_replace(',', '.', $input[$key])) { + return false; + } + + $this->value = $input[$key]; + return true; + } + public static function getPrefs() { return [ 'required' => 1, @@ -168,4 +207,20 @@ public function getEmptyParameters() { ]; } + + public function equals($value) { + return ((float) $this->getValue()) === ((float) $value); + } + + public function notEquals($value) { + return !$this->equals($value); + } + + public function greaterThan($value) { + return ((float) $this->getValue()) > ((float) $value); + } + + public function lessThan($value) { + return !$this->greaterThan($value) && !$this->equals($value); + } } diff --git a/inc/fields/glpiselectfield.class.php b/inc/fields/glpiselectfield.class.php index 06cfdb5cd..f442769a6 100644 --- a/inc/fields/glpiselectfield.class.php +++ b/inc/fields/glpiselectfield.class.php @@ -47,18 +47,20 @@ public function prepareQuestionInputForSave($input) { return []; } $input['values'] = $input['glpi_objects']; - $input['default_values'] = isset($input['dropdown_default_value']) ? $input['dropdown_default_value'] : ''; + $this->value = isset($input['dropdown_default_value']) ? $input['dropdown_default_value'] : ''; } return $input; } - public function isValid($value) { + public function isValid() { // If the field is required it can't be empty (0 is a valid value for entity) - if ($this->isRequired() && empty($value) && ($value == '0' && $this->fields['values'] != Entity::class)) { + $itemtype = $this->fields['values']; + $item = new $itemtype(); + if ($this->isRequired() && $item->isNewID($this->value)) { Session::addMessageAfterRedirect( - __('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(), - false, - ERROR); + __('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(), + false, + ERROR); return false; } @@ -95,4 +97,35 @@ public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['glpiselect'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + public function equals($value) { + $value = html_entity_decode($value); + $itemtype = $this->fields['values']; + $item = new $itemtype(); + if ($item->isNewId($this->value)) { + return ($value === ''); + } + if (!$item->getFromDB($this->value)) { + throw new PluginFormcreatorComparisonException('Item not found for comparison'); + } + return $item->getField($item->getNameField()) == $value; + } + + public function notEquals($value) { + return !$this->equals($value); + } + + public function greaterThan($value) { + $value = html_entity_decode($value); + $itemtype = $this->fields['values']; + $item = new $itemtype(); + if (!$item->getFromDB($this->value)) { + throw new PluginFormcreatorComparisonException('Item not found for comparison'); + } + return $item->getField($item->getNameField()) > $value; + } + + public function lessThan($value) { + return !$this->greaterThan($value) && !$this->equals($value); + } } diff --git a/inc/fields/hiddenfield.class.php b/inc/fields/hiddenfield.class.php index e457b1ab3..ba7399cd4 100644 --- a/inc/fields/hiddenfield.class.php +++ b/inc/fields/hiddenfield.class.php @@ -34,13 +34,30 @@ class PluginFormcreatorHiddenField extends PluginFormcreatorField { public function show($canEdit = true) { + $id = $this->fields['id']; + $rand = mt_rand(); + $fieldName = 'formcreator_field_' . $id; + $domId = $fieldName . '_' . $rand; + $defaultValue = Html::cleanInputText($this->fields['default_values']); echo '' . PHP_EOL; + name="' . $fieldName . '" + id="' . $domId . '" + value="' . $defaultValue . '" />' . PHP_EOL; } - public function isValid($value) { + public function serializeValue() { + return $this->value; + } + + public function deserializeValue($value) { + $this->value = $value; + } + + public function getValueForDesign() { + return $this->value; + } + + public function isValid() { return true; } @@ -68,8 +85,34 @@ public static function getPrefs() { ]; } + public function parseAnswerValues($input) { + $key = 'formcreator_field_' . $this->fields['id']; + if (!is_string($input[$key])) { + return false; + } + + $this->value = $input[$key]; + return true; + } + public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['hidden'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + public function equals($value) { + return $this->getValue() == $value; + } + + public function notEquals($value) { + return !$this->equals($value); + } + + public function greaterThan($value) { + return $this->getValue() > $value; + } + + public function lessThan($value) { + return !$this->greaterThan($value) && !$this->equals($value); + } } diff --git a/inc/fields/hostnamefield.class.php b/inc/fields/hostnamefield.class.php index 3069103f3..183161245 100644 --- a/inc/fields/hostnamefield.class.php +++ b/inc/fields/hostnamefield.class.php @@ -2,18 +2,35 @@ class PluginFormcreatorHostnameField extends PluginFormcreatorField { public function show($canEdit = true) { + $id = $this->fields['id']; + $rand = mt_rand(); + $fieldName = 'formcreator_field_' . $id; + $domId = $fieldName . '_' . $rand; if ($canEdit) { $hostname = gethostbyaddr(Toolbox::getRemoteIpAddress()); + $hostname = Html::cleanInputText($hostname); echo '' . PHP_EOL; } else { parent::show($canEdit); } } - public function isValid($value) { + public function serializeValue() { + return ''; + } + + public function deserializeValue($value) { + $this->value = ''; + } + + public function getValueForDesign() { + return ''; + } + + public function isValid() { return true; } @@ -36,8 +53,34 @@ public static function getPrefs() { ]; } + public function parseAnswerValues($input) { + $key = 'formcreator_field_' . $this->fields['id']; + if (!is_string($input[$key])) { + return false; + } + + $this->value = $input[$key]; + return true; + } + public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['hostname'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + public function equals($value) { + return $this->getValue() == $value; + } + + public function notEquals($value) { + return !$this->equals($value); + } + + public function greaterThan($value) { + return $this->getValue() > $value; + } + + public function lessThan($value) { + return !$this->greaterThan($value) && !$this->equals($value); + } } diff --git a/inc/fields/integerfield.class.php b/inc/fields/integerfield.class.php index cdaf53126..c23eb1b2a 100644 --- a/inc/fields/integerfield.class.php +++ b/inc/fields/integerfield.class.php @@ -33,19 +33,54 @@ class PluginFormcreatorIntegerField extends PluginFormcreatorField { - public function isValid($value) { - if (!parent::isValid($value)) { + public function getValue() { + if (isset($this->value)) { + return $this->value; + } else { + return $this->fields['default_values']; + } + } + + public function serializeValue() { + if ($this->value === null || $this->value === '') { + return ''; + } + + return strval((int) $this->value); + } + + public function deserializeValue($value) { + $this->value = ($value !== null && $value !== '') + ? $value + : ''; + } + + public function getValueForDesign() { + if ($this->value === null) { + return ''; + } + + return $this->value; + } + + public function isValid() { + // If the field is required it can't be empty + if ($this->isRequired() && $this->value == '') { + Session::addMessageAfterRedirect( + __('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(), + false, + ERROR); return false; } - if (!$this->isValidValue($value)) { + if (!$this->isValidValue($this->value)) { return false; } return true; } - private function isValidValue($value) { + public function isValidValue() { if (!empty($value) && !ctype_digit($value)) { Session::addMessageAfterRedirect(__('This is not an integer:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); return false; @@ -107,19 +142,11 @@ public function prepareQuestionInputForSave($input) { return false; } - if (isset($input['range_min']) - && isset($input['range_max']) - && isset($input['default_values'])) { - $input['default_values'] = !empty($input['default_values']) - ? (float) str_replace(',', '.', $input['default_values']) - : null; - $input['range_min'] = !empty($input['range_min']) - ? (float) str_replace(',', '.', $input['range_min']) - : null; - $input['range_max'] = !empty($input['range_max']) - ? (float) str_replace(',', '.', $input['range_max']) - : null; + if (isset($input['default_values'])) { + $this->value = (int) $input['default_values']; } + $input['values'] = ''; + return $input; } @@ -168,4 +195,32 @@ public function getEmptyParameters() { ]; } + public function parseAnswerValues($input) { + $key = 'formcreator_field_' . $this->fields['id']; + if (!is_string($input[$key])) { + return false; + } + if ($input[$key] != (int) $input[$key]) { + return false; + } + + $this->value = $input[$key]; + return true; + } + + public function equals($value) { + return ((int) $this->getValue()) === ((int) $value); + } + + public function notEquals($value) { + return !$this->equals($value); + } + + public function greaterThan($value) { + return ((int) $this->getValue()) > ((int) $value); + } + + public function lessThan($value) { + return !$this->greaterThan($value) && !$this->equals($value); + } } diff --git a/inc/fields/ipfield.class.php b/inc/fields/ipfield.class.php index 0cc6406a8..0250db3e2 100644 --- a/inc/fields/ipfield.class.php +++ b/inc/fields/ipfield.class.php @@ -34,14 +34,41 @@ class PluginFormcreatorIpField extends PluginFormcreatorField { public function show($canEdit = true) { + $id = $this->fields['id']; + $rand = mt_rand(); + $fieldName = 'formcreator_field_' . $id; + $domId = $fieldName . '_' . $rand; $ip = Toolbox::getRemoteIpAddress(); + $ip = Html::cleanInputText($ip); echo '' . PHP_EOL; + name="' . $fieldName . '" + id="' . $domId . '" + value="' . $ip . '" />' . PHP_EOL; } - public function isValid($value) { + public function serializeValue() { + if ($this->value === null || $this->value === '') { + return ''; + } + + return $this->value; + } + + public function deserializeValue($value) { + $this->value = ($value !== null && $value !== '') + ? $value + : ''; + } + + public function getValueForDesign() { + if ($this->value === null) { + return ''; + } + + return $this->value; + } + + public function isValid() { return true; } @@ -64,8 +91,34 @@ public static function getPrefs() { ]; } + public function parseAnswerValues($input) { + $key = 'formcreator_field_' . $this->fields['id']; + if (!is_string($input[$key])) { + return false; + } + + $this->value = $input[$key]; + return true; + } + public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['ip'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + public function equals($value) { + return $this->getValue() == $value; + } + + public function notEquals($value) { + return !$this->equals($value); + } + + public function greaterThan($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } + + public function lessThan($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } } diff --git a/inc/fields/ldapselectfield.class.php b/inc/fields/ldapselectfield.class.php index 4233310a9..e5a3dfd2c 100644 --- a/inc/fields/ldapselectfield.class.php +++ b/inc/fields/ldapselectfield.class.php @@ -34,102 +34,134 @@ class PluginFormcreatorLdapselectField extends PluginFormcreatorSelectField { public function getAvailableValues() { - if (!empty($this->fields['values'])) { - $ldap_values = json_decode(plugin_formcreator_decode($this->fields['values'])); - $ldap_dropdown = new RuleRightParameter(); - if (!$ldap_dropdown->getFromDB($ldap_values->ldap_attribute)) { - return []; - } - $attribute = [$ldap_dropdown->fields['value']]; + if (empty($this->fields['values'])) { + return []; + } - $config_ldap = new AuthLDAP(); - if (!$config_ldap->getFromDB($ldap_values->ldap_auth)) { - return []; - } + $ldap_values = json_decode(plugin_formcreator_decode($this->fields['values'])); + $ldap_dropdown = new RuleRightParameter(); + if (!$ldap_dropdown->getFromDB($ldap_values->ldap_attribute)) { + return []; + } + $attribute = [$ldap_dropdown->fields['value']]; - set_error_handler('plugin_formcreator_ldap_warning_handler', E_WARNING); + $config_ldap = new AuthLDAP(); + if (!$config_ldap->getFromDB($ldap_values->ldap_auth)) { + return []; + } - try { - $tab_values = []; + set_error_handler('plugin_formcreator_ldap_warning_handler', E_WARNING); - $ds = $config_ldap->connect(); - ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); + try { + $tab_values = []; - $cookie = ''; - do { - if (AuthLDAP::isLdapPageSizeAvailable($config_ldap)) { - ldap_control_paged_result($ds, $config_ldap->fields['pagesize'], true, $cookie); - } + $ds = $config_ldap->connect(); + ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); - $result = ldap_search($ds, $config_ldap->fields['basedn'], $ldap_values->ldap_filter, $attribute); - $entries = ldap_get_entries($ds, $result); - array_shift($entries); + $cookie = ''; + do { + if (AuthLDAP::isLdapPageSizeAvailable($config_ldap)) { + ldap_control_paged_result($ds, $config_ldap->fields['pagesize'], true, $cookie); + } - foreach ($entries as $id => $attr) { - if (isset($attr[$attribute[0]]) - && !in_array($attr[$attribute[0]][0], $tab_values)) { - $tab_values[$id] = $attr[$attribute[0]][0]; - } - } + $result = ldap_search($ds, $config_ldap->fields['basedn'], $ldap_values->ldap_filter, $attribute); + $entries = ldap_get_entries($ds, $result); + array_shift($entries); - if (AuthLDAP::isLdapPageSizeAvailable($config_ldap)) { - ldap_control_paged_result_response($ds, $result, $cookie); + foreach ($entries as $id => $attr) { + if (isset($attr[$attribute[0]]) + && !in_array($attr[$attribute[0]][0], $tab_values)) { + $tab_values[$id] = $attr[$attribute[0]][0]; } + } - } while ($cookie !== null && $cookie != ''); + if (AuthLDAP::isLdapPageSizeAvailable($config_ldap)) { + ldap_control_paged_result_response($ds, $result, $cookie); + } - asort($tab_values); - return $tab_values; - } catch (Exception $e) { - return []; - } + } while ($cookie !== null && $cookie != ''); - restore_error_handler(); - } else { + asort($tab_values); + return $tab_values; + } catch (Exception $e) { return []; } + + restore_error_handler(); } public static function getName() { return __('LDAP Select', 'formcreator'); } + public function serializeValue() { + return ''; + } + + public function deserializeValue($value) { + $this->value = ''; + } + + public function getValueForDesign() { + return ''; + } + + public function isValid() { + // If the field is required it can't be empty + if ($this->isRequired() && $this->value == '0') { + Session::addMessageAfterRedirect( + __('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(), + false, + ERROR); + return false; + } + + // All is OK + return true; + } + public function prepareQuestionInputForSave($input) { // Fields are differents for dropdown lists, so we need to replace these values into the good ones - if (isset($input['ldap_auth']) - && !empty($input['ldap_auth'])) { - - $config_ldap = new AuthLDAP(); - $config_ldap->getFromDB($input['ldap_auth']); - - if (!empty($input['ldap_attribute'])) { - $ldap_dropdown = new RuleRightParameter(); - $ldap_dropdown->getFromDB($input['ldap_attribute']); - $attribute = [$ldap_dropdown->fields['value']]; - } else { - $attribute = []; - } - - set_error_handler('plugin_formcreator_ldap_warning_handler', E_WARNING); - - try { - $ds = $config_ldap->connect(); - ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); - ldap_control_paged_result($ds, 1); - $sn = ldap_search($ds, $config_ldap->fields['basedn'], $input['ldap_filter'], $attribute); - $entries = ldap_get_entries($ds, $sn); - } catch (Exception $e) { - Session::addMessageAfterRedirect(__('Cannot recover LDAP informations!', 'formcreator'), false, ERROR); - } - - restore_error_handler(); - - $input['values'] = json_encode([ - 'ldap_auth' => $input['ldap_auth'], - 'ldap_filter' => $input['ldap_filter'], - 'ldap_attribute' => strtolower($input['ldap_attribute']), - ]); + if (!isset($input['ldap_auth'])) { + Session::addMessageAfterRedirect(__('LDAP directory not defined!', 'formcreator'), false, ERROR); + return []; } + + $config_ldap = new AuthLDAP(); + $config_ldap->getFromDB($input['ldap_auth']); + if ($config_ldap->isNewItem()) { + Session::addMessageAfterRedirect(__('LDAP directory not found!', 'formcreator'), false, ERROR); + return []; + } + + if (!empty($input['ldap_attribute'])) { + $ldap_dropdown = new RuleRightParameter(); + $ldap_dropdown->getFromDB($input['ldap_attribute']); + $attribute = [$ldap_dropdown->fields['value']]; + } else { + $attribute = []; + } + + set_error_handler('plugin_formcreator_ldap_warning_handler', E_WARNING); + + try { + $ds = $config_ldap->connect(); + ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); + ldap_control_paged_result($ds, 1); + $sn = ldap_search($ds, $config_ldap->fields['basedn'], $input['ldap_filter'], $attribute); + $entries = ldap_get_entries($ds, $sn); + } catch (Exception $e) { + Session::addMessageAfterRedirect(__('Cannot recover LDAP informations!', 'formcreator'), false, ERROR); + } + + restore_error_handler(); + + $input['values'] = json_encode([ + 'ldap_auth' => $input['ldap_auth'], + 'ldap_filter' => $input['ldap_filter'], + 'ldap_attribute' => strtolower($input['ldap_attribute']), + ]); + return $input; } @@ -158,4 +190,30 @@ public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['ldapselect'] = 'showFields(" . implode(', ', $prefs) . ");';"; } + + public function parseAnswerValues($input) { + $key = 'formcreator_field_' . $this->fields['id']; + if (!is_string($input[$key])) { + return false; + } + + $this->value = $input[$key]; + return true; + } + + public function equals($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } + + public function notEquals($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } + + public function greaterThan($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } + + public function lessThan($value) { + throw new PluginFormcreatorComparisonException('Meaningless comparison'); + } } diff --git a/inc/fields/multiselectfield.class.php b/inc/fields/multiselectfield.class.php index af70fa1b1..967231b4c 100644 --- a/inc/fields/multiselectfield.class.php +++ b/inc/fields/multiselectfield.class.php @@ -31,23 +31,77 @@ * --------------------------------------------------------------------- */ -class PluginFormcreatorMultiSelectField extends PluginFormcreatorSelectField +class PluginFormcreatorMultiSelectField extends PluginFormcreatorField { - const IS_MULTIPLE = true; + public function displayField($canEdit = true) { + if ($canEdit) { + $id = $this->fields['id']; + $rand = mt_rand(); + $fieldName = 'formcreator_field_' . $id; + $domId = $fieldName . $rand; + $values = $this->getAvailableValues(); + $tab_values = []; + + if (!empty($this->fields['values'])) { + foreach ($values as $value) { + if ((trim($value) != '')) { + $tab_values[$value] = $value; + } + } + + Dropdown::showFromArray($fieldName, $tab_values, [ + 'display_emptychoice' => $this->fields['show_empty'] == 1, + 'value' => '', + 'values' => $this->getValue(), + 'rand' => $rand, + 'multiple' => true, + ]); + } + echo PHP_EOL; + echo Html::scriptBlock("$(function() { + pluginFormcreatorInitializeMultiselect('$fieldName', '$rand'); + });"); + } else { + $answer = $this->getAnswer(); + echo empty($answer) ? '' : implode('
', $answer); + } + } + + public function serializeValue() { + if ($this->value === null || $this->value === '') { + return ''; + } + + return implode("\r\n", $this->value); + } - public function isValid($value) { - $value = json_decode($value); - if (is_null($value)) { - $value = []; + public function deserializeValue($value) { + $deserialized = []; + $this->value = ($value !== null && $value !== '') + ? explode("\r\n", $value) + : []; + } + + public function getValueForDesign() { + if ($this->value === null) { + return ''; + } + + return implode("\r\n", $this->value); + } + + public function isValid() { + if ($this->value == '') { + $this->value = []; } // If the field is required it can't be empty - if ($this->isRequired() && empty($value)) { + if ($this->isRequired() && $this->value == '') { Session::addMessageAfterRedirect(__('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(), false, ERROR); return false; } - if (!$this->isValidValue($value)) { + if (!$this->isValidValue($this->value)) { return false; } @@ -75,13 +129,16 @@ private function isValidValue($value) { return true; } - public function displayField($canEdit = true) { - if ($canEdit) { - parent::displayField($canEdit); - } else { - $answer = $this->getAnswer(); - echo empty($answer) ? '' : implode('
', $answer); + public function getValue() { + if (isset($this->value)) { + $value = $this->value; } + $value = $this->fields['default_values']; + if ($value == '') { + return []; + } + + return explode("\r\n", $value); } public function getAnswer() { @@ -109,6 +166,30 @@ public function getAnswer() { return $return; } + public function prepareQuestionInputForSave($input) { + if (isset($input['values'])) { + if (empty($input['values'])) { + Session::addMessageAfterRedirect( + __('The field value is required:', 'formcreator') . ' ' . $input['name'], + false, + ERROR); + return []; + } else { + // trim values + $input['values'] = $this->trimValue($input['values']); + } + } + if (isset($input['default_values'])) { + // trim values + $this->value = explode('\r\n', $input['default_values']); + $this->value = array_map('trim', $this->value); + $this->value = array_filter($this->value, function($value) { + return ($value !== ''); + }); + } + return $input; + } + public function prepareQuestionInputForTarget($input) { global $CFG_GLPI; @@ -159,6 +240,20 @@ public static function getPrefs() { ]; } + public function parseAnswerValues($input) { + $key = 'formcreator_field_' . $this->fields['id']; + if (!isset($input[$key])) { + $input[$key] = []; + } else { + if (!is_array($input[$key])) { + return false; + } + } + + $this->value = $input[$key]; + return true; + } + public static function getJSFields() { $prefs = self::getPrefs(); return "tab_fields_fields['multiselect'] = 'showFields(" . implode(', ', $prefs) . ");';"; @@ -176,4 +271,40 @@ public function getEmptyParameters() { ), ]; } + + public function equals($value) { + if (!is_array( $this->value)) { + // No selection + return ($value === ''); + } + return in_array($value, $this->value); + } + + public function notEquals($value) { + return !$this->equals($value); + } + + public function greaterThan($value) { + if (count($this->value) < 1) { + return false; + } + foreach ($this->value as $answer) { + if ($answer <= $value) { + return false; + } + } + return true; + } + + public function lessThan($value) { + if (count($this->value) < 1) { + return false; + } + foreach ($this->value as $answer) { + if ($answer >= $value) { + return false; + } + } + return true; + } } diff --git a/inc/fields/radiosfield.class.php b/inc/fields/radiosfield.class.php index e38bffb4e..71bbf01a4 100644 --- a/inc/fields/radiosfield.class.php +++ b/inc/fields/radiosfield.class.php @@ -35,8 +35,14 @@ class PluginFormcreatorRadiosField extends PluginFormcreatorField { public function displayField($canEdit = true) { if ($canEdit) { - echo '' . PHP_EOL; + $id = $this->fields['id']; + $rand = mt_rand(); + $fieldName = 'formcreator_field_' . $id; + $domId = $fieldName . '_' . $rand; + // echo '' . PHP_EOL; $values = $this->getAvailableValues(); if (!empty($values)) { @@ -47,10 +53,10 @@ public function displayField($canEdit = true) { $i++; $checked = ($this->getValue() == $value) ? ' checked' : ''; echo ' '; - echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; @@ -247,9 +243,6 @@ public function showForm($options = []) { echo ''; echo ''; echo ''; @@ -257,9 +250,6 @@ public function showForm($options = []) { echo ''; echo ''; echo ''; @@ -267,9 +257,6 @@ public function showForm($options = []) { echo ''; echo ''; echo ''; @@ -277,9 +264,6 @@ public function showForm($options = []) { echo ''; echo ''; echo ''; @@ -287,9 +271,6 @@ public function showForm($options = []) { echo ''; echo ''; echo ''; From 5cac2b89643b976b1c272c23c19ba6a08085911f Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 22 Oct 2018 11:47:04 +0200 Subject: [PATCH 117/192] fix(targetticket): fix HTML Signed-off-by: btry --- inc/targetticket.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index eed50d4aa..da04eaf65 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -98,7 +98,7 @@ public function showForm($options = []) { echo ''; echo ''; - echo ''; echo ''; echo '
'; @@ -972,7 +974,9 @@ function plugin_formcreator_hideAllParameters() { echo ''; dropdown::showNumber('show_ticket_categories_depth', [ 'rand' => $rand, - 'value' => $decodedValues['show_ticket_categories_depth'], + 'value' => isset($decodedValues['show_ticket_categories_depth']) + ? $decodedValues['show_ticket_categories_depth'] + : 0, 'min' => 1, 'max' => 16, 'toadd' => [0 => __('No limit', 'formcreator')], diff --git a/install/update_2.6_2.7.php b/install/update_2.6_2.7.php index 39a3f06fb..353e2cd56 100644 --- a/install/update_2.6_2.7.php +++ b/install/update_2.6_2.7.php @@ -88,4 +88,24 @@ function plugin_formcreator_update_2_7(Migration $migration) { $id = $row['id']; $DB->query("UPDATE `glpi_plugin_formcreator_questions` SET `name`='$name' WHERE `id` = '$id'"); } + + // Add properties for dropdown of ticket categories + $request = [ + 'FROM' => 'glpi_plugin_formcreator_questions', + 'WHERE' => [ + 'fieldtype' => 'dropdown' + ], + ]; + foreach ($DB->request($request) as $row) { + $values = json_decode($row['values'], true); + if (!isset($values['show_ticket_categories'])) { + $values['show_ticket_categories'] = 'both'; + } + if (!isset($values['show_ticket_categories_depth'])) { + $values['show_ticket_categories_depth'] = '0'; + } + $id = $row['id']; + $values = json_encode($values); + $DB->query("UPDATE `glpi_plugin_formcreator_questions` SET `values`='$values' WHERE `id` = '$id'"); + } } \ No newline at end of file From d0a56e5a4cc28e121ac20149d73eaa8713bac844 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 28 Aug 2018 23:53:02 +0200 Subject: [PATCH 034/192] fix(form): php warning when a form is filed but does not meet requirements, checkboxes are not properly populated from previous submission. A php warning occurs Signed-off-by: Thierry Bugier --- inc/form.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/form.class.php b/inc/form.class.php index 74a2c4238..9c00aa891 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -951,7 +951,7 @@ class='formcreator_form form_horizontal'>"; foreach ($questions as $question_line) { if (isset($data['formcreator_field_' . $question_line['id']])) { // multiple choice question are saved as JSON and needs to be decoded - $answer = (in_array($question_line['fieldtype'], ['checkboxes', 'multiselect'])) + $answer = (in_array($question_line['fieldtype'], ['multiselect'])) ? json_decode($data['formcreator_field_' . $question_line['id']]) : $data['formcreator_field_' . $question_line['id']]; } else { From 30e405724afd5e8075fcf74b4c2d87009c965f58 Mon Sep 17 00:00:00 2001 From: LEANDRO Barbosa Teles <01075947146@poupex.com.br> Date: Wed, 21 Mar 2018 14:49:31 -0300 Subject: [PATCH 035/192] feat(file): multiple file upload for a single file field --- inc/fields/filefield.class.php | 12 +++++-- inc/form_answer.class.php | 63 ++++++++++++++++++++-------------- inc/targetbase.class.php | 16 +++++---- install/update_2.6_2.7.php | 26 +++++++++++++- 4 files changed, 81 insertions(+), 36 deletions(-) diff --git a/inc/fields/filefield.class.php b/inc/fields/filefield.class.php index ea0af00fb..31cab6a58 100644 --- a/inc/fields/filefield.class.php +++ b/inc/fields/filefield.class.php @@ -43,13 +43,19 @@ public function displayField($canEdit = true) { echo Html::file([ 'name' => 'formcreator_field_' . $this->fields['id'], 'display' => false, + 'multiple' => 'multiple', ]); } else { $doc = new Document(); $answer = $this->getAnswer(); - if ($doc->getFromDB($answer)) { - echo $doc->getDownloadLink(); + if (is_numeric($answer)) { + $answer = [$answer]; + } + foreach ($answer as $item) { + if ($doc->getFromDB($item)) { + echo $doc->getDownloadLink(); + } } } } @@ -62,7 +68,7 @@ public function isValid($value) { } if (is_array($_POST['_formcreator_field_' . $this->fields['id']]) - && count($_POST['_formcreator_field_' . $this->fields['id']]) === 1) { + && count($_POST['_formcreator_field_' . $this->fields['id']]) > 0) { $file = current($_POST['_formcreator_field_' . $this->fields['id']]); if (is_file(GLPI_TMP_DIR . '/' . $file)) { return true; diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index 405da2481..47823ffa3 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -654,19 +654,24 @@ public function saveAnswers($data) { // $answer_value may be still null if the field type is file and no file was uploaded if ($answer_value !== null) { - // Update the answer to the question - $questionId = $question->getID(); - $answer = new PluginFormcreatorAnswer(); - $answer->getFromDBByCrit([ - 'AND' => [ - 'plugin_formcreator_forms_answers_id' => $formanswers_id, - 'plugin_formcreator_questions_id' => $questionId - ] - ]); - $answer->update([ - 'id' => $answer->getID(), - 'answer' => $answer_value, - ], 0); + if (!is_array(answer_value)) { + $answer_value = [$answer_value]; + } + foreach ($answer_value as $value) { + // Update the answer to the question + $questionId = $question->getID(); + $answer = new PluginFormcreatorAnswer(); + $answer->getFromDBByCrit([ + 'AND' => [ + 'plugin_formcreator_forms_answers_id' => $formanswers_id, + 'plugin_formcreator_questions_id' => $questionId + ] + ]); + $answer->update([ + 'id' => $answer->getID(), + 'answer' => $value, + ], 0); + } } } } @@ -718,12 +723,17 @@ public function saveAnswers($data) { $answer_value = $this->transformAnswerValue($question, $data['formcreator_field_' . $question->getID()]); if ($answer_value !== null) { - // Save the answer to the question - $answer->add([ - 'plugin_formcreator_forms_answers_id' => $id, - 'plugin_formcreator_questions_id' => $question->getID(), - 'answer' => $answer_value, - ], [], 0); + if (!is_array($answer_value)) { + $answer_value = [$answer_value]; + } + foreach ($answer_value as $val) { + // Save the answer to the question + $answer->add([ + 'plugin_formcreator_forms_answers_id' => $id, + 'plugin_formcreator_questions_id' => $question->getID(), + 'answer' => $val, + ], [], 0); + } } } $is_newFormAnswer = true; @@ -921,12 +931,15 @@ private function transformAnswerValue(PluginFormcreatorQuestion $question, $valu } else { $answer_value = ''; } - } else if (is_array($_POST['_formcreator_field_' . $question->getID()]) - && count($_POST['_formcreator_field_' . $question->getID()]) === 1) { - $file = current($_POST['_formcreator_field_' . $question->getID()]); - if (is_file(GLPI_TMP_DIR . '/' . $file)) { - $answer_value = $this->saveDocument($form, $question, $file); + } else if (isset($_POST['_formcreator_field_' . $question->getID()])) { + $documents = $_POST['_formcreator_field_' . $question->getID()]; + $answer_value = []; + foreach ($documents as $document) { + if (is_file(GLPI_TMP_DIR . '/' . $document)) { + $answer_value[] = $this->saveDocument($form, $question, $document); + } } + $answer_value = json_encode($answer_value); } return $answer_value; @@ -957,7 +970,7 @@ private function saveDocument(PluginFormcreatorForm $form, PluginFormcreatorQues if ($docID = $doc->add($file_data)) { $docID = intval($docID); $table = Document::getTable(); - $filename = addslashes($file); + $filename = substr(addslashes($file), 23); $query = "UPDATE `$table` SET `filename` = '$filename' WHERE `id` = '$docID'"; $DB->query($query); diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index 147b4092a..5d232ee92 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -809,25 +809,27 @@ protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer, $name = $question_line['name']; $value = $fieldObject->prepareQuestionInputForTarget($fieldObject->getValue()); } - if (is_array($value)) { + + if ($question_line['fieldtype'] !== 'file') { if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { $value = '
' . implode('
', $value); } else { $value = "\r\n" . implode("\r\n", $value); } - } - - if ($question_line['fieldtype'] !== 'file') { $content = str_replace('##question_' . $id . '##', addslashes($name), $content); $content = str_replace('##answer_' . $id . '##', $value, $content); } else { if (strpos($content, '##answer_' . $id . '##') !== false) { $content = str_replace('##question_' . $id . '##', addslashes($name), $content); - if ($value !== '') { + if (!is_array($value)) { + $value = [$value]; + } + if (count($value)) { $content = str_replace('##answer_' . $id . '##', __('Attached document', 'formcreator'), $content); - // keep the ID of the document - $this->attachedDocuments[$value] = true; + foreach ($value as $documentId) { + $this->attachedDocuments[$documentId] = true; + } } else { $content = str_replace('##answer_' . $id . '##', '', $content); } diff --git a/install/update_2.6_2.7.php b/install/update_2.6_2.7.php index 353e2cd56..a558f96a8 100644 --- a/install/update_2.6_2.7.php +++ b/install/update_2.6_2.7.php @@ -108,4 +108,28 @@ function plugin_formcreator_update_2_7(Migration $migration) { $values = json_encode($values); $DB->query("UPDATE `glpi_plugin_formcreator_questions` SET `values`='$values' WHERE `id` = '$id'"); } -} \ No newline at end of file + + // multiple files upload per field + $request = [ + 'SELECT' => 'glpi_plugin_formcreator_answers.*', + 'FROM' => 'glpi_plugin_formcreator_answers', + 'LEFT JOIN' => [ + 'glpi_plugin_formcreator_questions' => [ + 'FKEY' => [ + 'glpi_plugin_formcreator_questions' => 'id', + 'glpi_plugin_formcreator_answers' => 'plugin_formcreator_questions_id' + ] + ] + ], + 'WHERE' => [ + 'fieldtype' => 'file', + ] + ]; + foreach ($DB->request($request) as $row) { + if (!is_array(json_decode($row['answer']))) { + $id = $row['id']; + $answer = json_encode([$row['answer']]); + $DB->query("UPDATE `glpi_plugin_formcreator_answers` SET `answer` = '$answer' WHERE `id` = '$id'"); + } + } +} From 557a0c43b6f3bfb25f1c1ef373d29f416a4b20fd Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 27 Aug 2018 11:07:25 +0200 Subject: [PATCH 036/192] refactor(form_answer): better implementation for file handling Signed-off-by: btry --- inc/form_answer.class.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index 47823ffa3..e910fe1c0 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -965,16 +965,11 @@ private function saveDocument(PluginFormcreatorForm $form, PluginFormcreatorQues ? $_SESSION['glpiactive_entity'] : $form->getField('entities_id'); $file_data["is_recursive"] = $form->getField('is_recursive'); - Document::moveDocument($file_data, $file); + $file_data['_filename'] = [$file]; if ($docID = $doc->add($file_data)) { $docID = intval($docID); $table = Document::getTable(); - $filename = substr(addslashes($file), 23); - $query = "UPDATE `$table` SET `filename` = '$filename' - WHERE `id` = '$docID'"; - $DB->query($query); - $docItem = new Document_Item(); $docItem->add([ 'documents_id' => $docID, From b1b8560f9a1d8f87b4122f3b798381050baacbc7 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 28 Aug 2018 18:43:02 +0200 Subject: [PATCH 037/192] fix(target): prevent imploding a non-array Signed-off-by: btry --- inc/targetbase.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index 5d232ee92..59f3eac49 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -810,7 +810,7 @@ protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer, $value = $fieldObject->prepareQuestionInputForTarget($fieldObject->getValue()); } - if ($question_line['fieldtype'] !== 'file') { + if (is_array($value) && $question_line['fieldtype'] !== 'file') { if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { $value = '
' . implode('
', $value); } else { From ebfbd953e539d1a619c82e710c28627133a46c3f Mon Sep 17 00:00:00 2001 From: btry Date: Wed, 29 Aug 2018 15:18:21 +0200 Subject: [PATCH 038/192] style: update CS rules and apply them Signed-off-by: btry --- composer.json | 2 +- composer.lock | 214 +++++++++-------- inc/entityconfig.class.php | 6 +- inc/fields/tagfield.class.php | 4 +- inc/form.class.php | 20 +- inc/form_answer.class.php | 8 +- inc/form_profile.class.php | 6 +- inc/issue.class.php | 2 +- inc/notificationtargetform_answer.class.php | 6 +- inc/question.class.php | 4 +- inc/question_condition.class.php | 2 +- inc/targetchange.class.php | 2 +- inc/targetticket.class.php | 14 +- install/install.php | 2 +- .../0010_Integration/FormDuplicationTest.php | 52 ++-- .../QuestionConditionTest.php | 14 +- tests/0010_Integration/UrgencyTest.php | 12 +- tests/src/CommonDBTestCase.php | 82 +++---- tests/src/CommonTestCase.php | 2 +- .../PluginFormcreatorCheckboxesField.php | 4 +- .../PluginFormcreatorQuestion_Condition.php | 224 +++++++++--------- tests/suite-unit/PluginFormcreatorSection.php | 16 +- 22 files changed, 361 insertions(+), 337 deletions(-) diff --git a/composer.json b/composer.json index 99e6b8647..a64cbf629 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "atoum/atoum": "^3.3", "atoum/stubs": "^2.5", "glpi-project/tools": "^0.1.0", - "glpi-project/coding-standard": "0.5.0" + "glpi-project/coding-standard": "0.7.1" }, "autoload-dev": { "psr-4": { diff --git a/composer.lock b/composer.lock index 8a8d38186..08c93a68e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "f45f667c100fe8ba8924ac08d306d8f8", + "content-hash": "af76c4947f8c9078a9376794cf914f00", "packages": [ { "name": "docopt/docopt", @@ -186,16 +186,16 @@ }, { "name": "consolidation/annotated-command", - "version": "2.8.4", + "version": "2.8.5", "source": { "type": "git", "url": "https://github.com/consolidation/annotated-command.git", - "reference": "651541a0b68318a2a202bda558a676e5ad92223c" + "reference": "1e8ff512072422b850b44aa721b5b303e4a5ebb3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/consolidation/annotated-command/zipball/651541a0b68318a2a202bda558a676e5ad92223c", - "reference": "651541a0b68318a2a202bda558a676e5ad92223c", + "url": "https://api.github.com/repos/consolidation/annotated-command/zipball/1e8ff512072422b850b44aa721b5b303e4a5ebb3", + "reference": "1e8ff512072422b850b44aa721b5b303e4a5ebb3", "shasum": "" }, "require": { @@ -234,7 +234,7 @@ } ], "description": "Initialize Symfony Console commands from annotated command class methods.", - "time": "2018-05-25T18:04:25+00:00" + "time": "2018-08-18T23:51:49+00:00" }, { "name": "consolidation/config", @@ -396,16 +396,16 @@ }, { "name": "consolidation/robo", - "version": "dev-master", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/consolidation/Robo.git", - "reference": "967b88fad6f554e990407047f44a794ce9c773af" + "reference": "31f2d2562c4e1dcde70f2659eefd59aa9c7f5b2d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/consolidation/Robo/zipball/967b88fad6f554e990407047f44a794ce9c773af", - "reference": "967b88fad6f554e990407047f44a794ce9c773af", + "url": "https://api.github.com/repos/consolidation/Robo/zipball/31f2d2562c4e1dcde70f2659eefd59aa9c7f5b2d", + "reference": "31f2d2562c4e1dcde70f2659eefd59aa9c7f5b2d", "shasum": "" }, "require": { @@ -413,6 +413,7 @@ "consolidation/config": "^1.0.10", "consolidation/log": "~1", "consolidation/output-formatters": "^3.1.13", + "consolidation/self-update": "^1", "g1a/composer-test-scenarios": "^2", "grasmash/yaml-expander": "^1.3", "league/container": "^2.2", @@ -472,7 +473,57 @@ } ], "description": "Modern task runner", - "time": "2018-08-12 00:17:46" + "time": "2018-08-17T18:44:18+00:00" + }, + { + "name": "consolidation/self-update", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/consolidation/self-update.git", + "reference": "de33822f907e0beb0ffad24cf4b1b4fae5ada318" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/consolidation/self-update/zipball/de33822f907e0beb0ffad24cf4b1b4fae5ada318", + "reference": "de33822f907e0beb0ffad24cf4b1b4fae5ada318", + "shasum": "" + }, + "require": { + "php": ">=5.5.0", + "symfony/console": "^2.8|^3|^4", + "symfony/filesystem": "^2.5|^3|^4" + }, + "bin": [ + "scripts/release" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "SelfUpdate\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Greg Anderson", + "email": "greg.1.anderson@greenknowe.org" + }, + { + "name": "Alexander Menk", + "email": "menk@mestrona.net" + } + ], + "description": "Provides a self:update command for Symfony Console applications.", + "time": "2018-08-24T17:01:46+00:00" }, { "name": "container-interop/container-interop", @@ -599,30 +650,30 @@ }, { "name": "glpi-project/coding-standard", - "version": "0.5", + "version": "0.7.1", "source": { "type": "git", "url": "https://github.com/glpi-project/coding-standard.git", - "reference": "e19495c896a01199a2fec2e65b7613310598cf96" + "reference": "1cef37d764aecf8fd7d5d167db25da97e289cb03" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/glpi-project/coding-standard/zipball/e19495c896a01199a2fec2e65b7613310598cf96", - "reference": "e19495c896a01199a2fec2e65b7613310598cf96", + "url": "https://api.github.com/repos/glpi-project/coding-standard/zipball/1cef37d764aecf8fd7d5d167db25da97e289cb03", + "reference": "1cef37d764aecf8fd7d5d167db25da97e289cb03", "shasum": "" }, "require": { - "squizlabs/php_codesniffer": "~2.0" + "squizlabs/php_codesniffer": "^3.3" }, "type": "library", "notification-url": "https://packagist.org/downloads/", "license": [ - "GPLv3" + "GPL-2.0-or-later" ], "authors": [ { "name": "Teclib'", - "email": "contact@teclib.com", + "email": "glpi@teclib.com", "homepage": "https://teclib.com" } ], @@ -632,27 +683,27 @@ "glpi", "phpcs" ], - "time": "2017-01-06T11:10:46+00:00" + "time": "2018-06-07T08:45:05+00:00" }, { "name": "glpi-project/tools", - "version": "0.1.3", + "version": "0.1.5", "source": { "type": "git", "url": "https://github.com/glpi-project/tools.git", - "reference": "b3ed8524ac663e1bbe2027c8c99e42da22f3aa7b" + "reference": "5ff99fa5967b468af3d3ba2d7a69ede1214273ea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/glpi-project/tools/zipball/b3ed8524ac663e1bbe2027c8c99e42da22f3aa7b", - "reference": "b3ed8524ac663e1bbe2027c8c99e42da22f3aa7b", + "url": "https://api.github.com/repos/glpi-project/tools/zipball/5ff99fa5967b468af3d3ba2d7a69ede1214273ea", + "reference": "5ff99fa5967b468af3d3ba2d7a69ede1214273ea", "shasum": "" }, "require": { - "consolidation/robo": "dev-master@dev", - "glpi-project/coding-standard": "~0.5", - "natxet/cssmin": "~3.0", - "patchwork/jsqueeze": "~1.0" + "consolidation/robo": "^1.3", + "glpi-project/coding-standard": "^0.7", + "natxet/cssmin": "^3.0", + "patchwork/jsqueeze": "^1.0" }, "bin": [ "tools/plugin-release", @@ -667,7 +718,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "GPLv3" + "GPL-3.0-or-later" ], "authors": [ { @@ -682,7 +733,7 @@ "plugins", "tools" ], - "time": "2018-01-02T10:48:41+00:00" + "time": "2018-06-21T11:59:33+00:00" }, { "name": "grasmash/expander", @@ -1048,20 +1099,20 @@ }, { "name": "pear/pear-core-minimal", - "version": "v1.10.3", + "version": "v1.10.6", "source": { "type": "git", "url": "https://github.com/pear/pear-core-minimal.git", - "reference": "070f0b600b2caca2501e2c9b7e553016e4b0d115" + "reference": "052868b244d31f822796e7e9981f62557eb256d4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pear/pear-core-minimal/zipball/070f0b600b2caca2501e2c9b7e553016e4b0d115", - "reference": "070f0b600b2caca2501e2c9b7e553016e4b0d115", + "url": "https://api.github.com/repos/pear/pear-core-minimal/zipball/052868b244d31f822796e7e9981f62557eb256d4", + "reference": "052868b244d31f822796e7e9981f62557eb256d4", "shasum": "" }, "require": { - "pear/console_getopt": "~1.4", + "pear/console_getopt": "~1.3", "pear/pear_exception": "~1.0" }, "replace": { @@ -1088,7 +1139,7 @@ } ], "description": "Minimal set of PEAR core files to be used as composer dependency", - "time": "2017-02-28T16:46:11+00:00" + "time": "2018-08-22T19:28:09+00:00" }, { "name": "pear/pear_exception", @@ -1243,64 +1294,37 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "2.9.1", + "version": "3.3.1", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62" + "reference": "628a481780561150481a9ec74709092b9759b3ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/dcbed1074f8244661eecddfc2a675430d8d33f62", - "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/628a481780561150481a9ec74709092b9759b3ec", + "reference": "628a481780561150481a9ec74709092b9759b3ec", "shasum": "" }, "require": { "ext-simplexml": "*", "ext-tokenizer": "*", "ext-xmlwriter": "*", - "php": ">=5.1.2" + "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "bin": [ - "scripts/phpcs", - "scripts/phpcbf" + "bin/phpcs", + "bin/phpcbf" ], "type": "library", "extra": { "branch-alias": { - "dev-master": "2.x-dev" + "dev-master": "3.x-dev" } }, - "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Fixer.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" - ] - }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" @@ -1317,11 +1341,11 @@ "phpcs", "standards" ], - "time": "2017-05-22T02:43:20+00:00" + "time": "2018-07-26T23:47:18+00:00" }, { "name": "symfony/console", - "version": "v3.4.14", + "version": "v3.4.15", "source": { "type": "git", "url": "https://github.com/symfony/console.git", @@ -1390,16 +1414,16 @@ }, { "name": "symfony/debug", - "version": "v3.4.14", + "version": "v3.4.15", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "d5a058ff6ecad26b30c1ba452241306ea34c65cc" + "reference": "c4625e75341e4fb309ce0c049cbf7fb84b8897cd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/d5a058ff6ecad26b30c1ba452241306ea34c65cc", - "reference": "d5a058ff6ecad26b30c1ba452241306ea34c65cc", + "url": "https://api.github.com/repos/symfony/debug/zipball/c4625e75341e4fb309ce0c049cbf7fb84b8897cd", + "reference": "c4625e75341e4fb309ce0c049cbf7fb84b8897cd", "shasum": "" }, "require": { @@ -1442,11 +1466,11 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2018-07-26T11:19:56+00:00" + "time": "2018-08-03T10:42:44+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v3.4.14", + "version": "v3.4.15", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", @@ -1509,16 +1533,16 @@ }, { "name": "symfony/filesystem", - "version": "v3.4.14", + "version": "v3.4.15", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "a59f917e3c5d82332514cb4538387638f5bde2d6" + "reference": "285ce5005cb01a0aeaa5b0cf590bd0cc40bb631c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/a59f917e3c5d82332514cb4538387638f5bde2d6", - "reference": "a59f917e3c5d82332514cb4538387638f5bde2d6", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/285ce5005cb01a0aeaa5b0cf590bd0cc40bb631c", + "reference": "285ce5005cb01a0aeaa5b0cf590bd0cc40bb631c", "shasum": "" }, "require": { @@ -1555,11 +1579,11 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2018-07-26T11:19:56+00:00" + "time": "2018-08-10T07:29:05+00:00" }, { "name": "symfony/finder", - "version": "v3.4.14", + "version": "v3.4.15", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", @@ -1725,16 +1749,16 @@ }, { "name": "symfony/process", - "version": "v3.4.14", + "version": "v3.4.15", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "0414db29bd770ec5a4152683e655f55efd4fa60f" + "reference": "4d6b125d5293cbceedc2aa10f2c71617e76262e7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/0414db29bd770ec5a4152683e655f55efd4fa60f", - "reference": "0414db29bd770ec5a4152683e655f55efd4fa60f", + "url": "https://api.github.com/repos/symfony/process/zipball/4d6b125d5293cbceedc2aa10f2c71617e76262e7", + "reference": "4d6b125d5293cbceedc2aa10f2c71617e76262e7", "shasum": "" }, "require": { @@ -1770,20 +1794,20 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2018-07-26T11:19:56+00:00" + "time": "2018-08-03T10:42:44+00:00" }, { "name": "symfony/yaml", - "version": "v3.4.14", + "version": "v3.4.15", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "810af2d35fc72b6cf5c01116806d2b65ccaaf2e2" + "reference": "c2f4812ead9f847cb69e90917ca7502e6892d6b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/810af2d35fc72b6cf5c01116806d2b65ccaaf2e2", - "reference": "810af2d35fc72b6cf5c01116806d2b65ccaaf2e2", + "url": "https://api.github.com/repos/symfony/yaml/zipball/c2f4812ead9f847cb69e90917ca7502e6892d6b8", + "reference": "c2f4812ead9f847cb69e90917ca7502e6892d6b8", "shasum": "" }, "require": { @@ -1829,7 +1853,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2018-07-26T11:19:56+00:00" + "time": "2018-08-10T07:34:36+00:00" } ], "aliases": [], diff --git a/inc/entityconfig.class.php b/inc/entityconfig.class.php index 708858f58..8e71af292 100644 --- a/inc/entityconfig.class.php +++ b/inc/entityconfig.class.php @@ -50,7 +50,7 @@ class PluginFormcreatorEntityconfig extends CommonDBTM { */ public $dohistory = true; - public function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { $tabNames = []; if (!$withtemplate) { @@ -61,7 +61,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { return $tabNames; } - public static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { if ($item->getType() == 'Entity') { $config = new self(); @@ -141,7 +141,7 @@ public function showFormForEntity(Entity $entity) { * @param $fieldval string name of the field that we want value (default '') * @param $default_value integer value to return (default -2) */ - static function getUsedConfig($fieldref, $entities_id, $fieldval='', $default_value=-2) { + static function getUsedConfig($fieldref, $entities_id, $fieldval = '', $default_value = -2) { // for calendar if (empty($fieldval)) { diff --git a/inc/fields/tagfield.class.php b/inc/fields/tagfield.class.php index 66c6ad3fa..d78ae3bb8 100644 --- a/inc/fields/tagfield.class.php +++ b/inc/fields/tagfield.class.php @@ -97,7 +97,7 @@ public static function getName() { } public static function getPrefs() { - return array( + return [ 'required' => 0, 'default_values' => 0, 'values' => 0, @@ -108,7 +108,7 @@ public static function getPrefs() { 'dropdown_value' => 0, 'glpi_objects' => 0, 'ldap_values' => 0, - ); + ]; } public static function getJSFields() { diff --git a/inc/form.class.php b/inc/form.class.php index 9c00aa891..153b3856e 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -246,7 +246,7 @@ public function rawSearchOptions() { * * @return String Html string to be displayed for the form field */ - public static function getSpecificValueToSelect($field, $name='', $values='', array $options=[]) { + public static function getSpecificValueToSelect($field, $name = '', $values = '', array $options = []) { if (!is_array($values)) { $values = [$field => $values]; @@ -354,7 +354,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options * * @return NULL Nothing, just display the form */ - public function showForm($ID, $options=[]) { + public function showForm($ID, $options = []) { global $DB; $this->initForm($ID, $options); @@ -528,7 +528,7 @@ public function showForm($ID, $options=[]) { * * @return String Name to be displayed */ - public function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { switch ($item->getType()) { case "PluginFormcreatorConfig": $object = new self; @@ -557,7 +557,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { * * @return null Nothing, just display the list */ - public static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { $uri = strrchr($_SERVER['HTTP_REFERER'], '/'); if (strpos($uri, '?')) { $uri = substr($uri, 0, strpos($uri, '?')); @@ -578,7 +578,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $wi } - public function defineTabs($options=[]) { + public function defineTabs($options = []) { $ong = []; $this->addDefaultFormTab($ong); $this->addStandardTab('PluginFormcreatorQuestion', $ong, $options); @@ -1596,7 +1596,7 @@ public static function showMassiveActionsSubForm(MassiveAction $ma) { * * @see CommonDBTM::processMassiveActionsForOneItemtype() */ - static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { + static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'Duplicate' : foreach ($ids as $id) { @@ -1762,22 +1762,22 @@ public function showImportForm() { if ($canAddType) { $destination = PluginFormcreatorForm::getFormURL(); $message .= __('You may allow JSON files right now.', 'formcreator'); - $button = Html::submit(_x('button', 'Create', 'formcreator'), array('name' => 'filetype_create')); + $button = Html::submit(_x('button', 'Create', 'formcreator'), ['name' => 'filetype_create']); } else { $destination = PluginFormcreatorForm::getSearchURL(); $message .= __('Please contact your GLPI administrator.', 'formcreator'); - $button = Html::submit(_x('button', 'Back', 'formcreator'), array('name' => 'filetype_back')); + $button = Html::submit(_x('button', 'Back', 'formcreator'), ['name' => 'filetype_back']); } } else { $message = __('Upload of JSON files not enabled.', 'formcreator'); if ($canUpdateType) { $destination = PluginFormcreatorForm::getFormURL(); $message .= __('You may enable JSON files right now.', 'formcreator'); - $button = Html::submit(_x('button', 'Enable', 'formcreator'), array('name' => 'filetype_enable')); + $button = Html::submit(_x('button', 'Enable', 'formcreator'), ['name' => 'filetype_enable']); } else { $message .= __('You may enable JSON files right now.', 'formcreator'); $message .= __('Please contact your GLPI administrator.', 'formcreator'); - $button = Html::submit(_x('button', 'Back', 'formcreator'), array('name' => 'filetype_back')); + $button = Html::submit(_x('button', 'Back', 'formcreator'), ['name' => 'filetype_back']); } } echo '
'; diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index e910fe1c0..ce8042d50 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -264,7 +264,7 @@ public function rawSearchOptions() { * @param Array $options Options (optional) * @return Mixed Value to be displayed */ - public static function getSpecificValueToDisplay($field, $values, array $options=[]) { + public static function getSpecificValueToDisplay($field, $values, array $options = []) { global $CFG_GLPI; if (!is_array($values)) { @@ -292,7 +292,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options * * @return String Html string to be displayed for the form field */ - public static function getSpecificValueToSelect($field, $name='', $values='', array $options = []) { + public static function getSpecificValueToSelect($field, $name = '', $values = '', array $options = []) { if (!is_array($values)) { $values = [$field => $values]; } @@ -322,7 +322,7 @@ public static function getSpecificValueToSelect($field, $name='', $values='', ar * * @return null Nothing, just display the list */ - public static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { if ($item instanceof PluginFormcreatorForm) { self::showForForm($item); } else { @@ -350,7 +350,7 @@ public function defineTabs($options = []) { * * @return String Name to be displayed */ - public function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if ($item instanceof PluginFormcreatorForm) { $dbUtils = new DbUtils(); $number = $dbUtils->countElementsInTableForMyEntities( diff --git a/inc/form_profile.class.php b/inc/form_profile.class.php index 0f8950b72..c9b76698f 100644 --- a/inc/form_profile.class.php +++ b/inc/form_profile.class.php @@ -42,11 +42,11 @@ class PluginFormcreatorForm_Profile extends CommonDBRelation static public $itemtype_2 = 'Profile'; static public $items_id_2 = 'profiles_id'; - static function getTypeName($nb=0) { + static function getTypeName($nb = 0) { return _n('Target', 'Targets', $nb, 'formcreator'); } - function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { + function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { return self::getTypeName(2); } @@ -67,7 +67,7 @@ public function prepareInputForAdd($input) { return $input; } - static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { + static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { global $DB, $CFG_GLPI; echo " $values]; diff --git a/inc/notificationtargetform_answer.class.php b/inc/notificationtargetform_answer.class.php index 2f2c64562..ff1cad61d 100644 --- a/inc/notificationtargetform_answer.class.php +++ b/inc/notificationtargetform_answer.class.php @@ -41,13 +41,13 @@ class PluginFormcreatorNotificationTargetForm_answer extends NotificationTarget const APPROVER = 102; public function getEvents() { - $events = array ( + $events = [ 'plugin_formcreator_form_created' => __('The form as been saved', 'formcreator'), 'plugin_formcreator_need_validation' => __('A form need to be validate', 'formcreator'), 'plugin_formcreator_refused' => __('The form is refused', 'formcreator'), 'plugin_formcreator_accepted' => __('The form is accepted', 'formcreator'), 'plugin_formcreator_deleted' => __('The form is deleted', 'formcreator'), - ); + ]; return $events; } @@ -96,7 +96,7 @@ public function getTags() { } } - public function addAdditionalTargets($event='') { + public function addAdditionalTargets($event = '') { $this->addTarget(self::AUTHOR, __('Author')); $this->addTarget(self::APPROVER, __('Approver')); } diff --git a/inc/question.class.php b/inc/question.class.php index e20adbbed..4d5f150d7 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -84,7 +84,7 @@ function addMessageOnPurgeAction() {} * * @return String Name to be displayed */ - public function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { switch ($item->getType()) { case PluginFormcreatorForm::class: $number = 0; @@ -116,7 +116,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { * * @return null Nothing, just display the list */ - public static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { switch (get_class($item)) { case PluginFormcreatorForm::class: static::showForForm($item, $withtemplate); diff --git a/inc/question_condition.class.php b/inc/question_condition.class.php index 19d0d105f..e80c1dd7d 100644 --- a/inc/question_condition.class.php +++ b/inc/question_condition.class.php @@ -228,7 +228,7 @@ public function getConditionHtml($form_id, $questionId = 0, $isFirst = false) { $html.= '
'; $html.= Dropdown::showFromArray('show_field[]', $questions_tab, [ 'display' => false, - 'used' => array($questionId => ''), + 'used' => [$questionId => ''], 'value' => $show_field, 'rand' => $rand, ]); diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index 02e3c3a3a..3b4dbd5c2 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -196,7 +196,7 @@ public static function import($targetitems_id = 0, $target_data = []) { * * @return NULL Nothing, just display the form */ - public function showForm($options=[]) { + public function showForm($options = []) { global $CFG_GLPI, $DB; $rand = mt_rand(); diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index dedab6b56..dc75c4079 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -76,7 +76,7 @@ protected function getCategoryFilter() { * * @return NULL Nothing, just display the form */ - public function showForm($options=[]) { + public function showForm($options = []) { global $CFG_GLPI, $DB; $rand = mt_rand(); @@ -555,21 +555,21 @@ public function showForm($options=[]) { echo '
'; echo ''; echo ''; echo ''; echo '
'; diff --git a/install/install.php b/install/install.php index bb3133f43..355c73ade 100644 --- a/install/install.php +++ b/install/install.php @@ -138,7 +138,7 @@ protected function getSchemaVersion() { protected function getSchemaVersionFromGlpiConfig() { global $DB; - $config = Config::getConfigurationValues('formcreator', array('schema_version')); + $config = Config::getConfigurationValues('formcreator', ['schema_version']); if (!isset($config['schema_version'])) { // No schema version in GLPI config, then this is older than 2.5 if ($DB->tableExists('glpi_plugin_formcreator_items_targettickets')) { diff --git a/tests/0010_Integration/FormDuplicationTest.php b/tests/0010_Integration/FormDuplicationTest.php index 440fa4a80..16febf757 100644 --- a/tests/0010_Integration/FormDuplicationTest.php +++ b/tests/0010_Integration/FormDuplicationTest.php @@ -41,20 +41,20 @@ class FormDuplicationTest extends SuperAdminTestCase public function setUp() { parent::setUp(); - $this->formData = array( + $this->formData = [ 'entities_id' => $_SESSION['glpiactive_entity'], 'name' => 'a form', 'description' => 'form description', 'content' => 'a content', 'is_active' => 1, 'validation_required' => 0 - ); + ]; - $this->sectionData = array( - array( + $this->sectionData = [ + [ 'name' => 'a section', - 'questions' => array ( - array( + 'questions' => [ + [ 'name' => 'text question', 'fieldtype' => 'text', '_parameters' => [ @@ -68,8 +68,8 @@ public function setUp() { ] ] ], - ), - array( + ], + [ 'name' => 'other text question', 'fieldtype' => 'text', '_parameters' => [ @@ -83,13 +83,13 @@ public function setUp() { ] ] ], - ), - ), - ), - array( + ], + ], + ], + [ 'name' => 'an other section', - 'questions' => array ( - array( + 'questions' => [ + [ 'name' => 'text question', 'fieldtype' => 'text', '_parameters' => [ @@ -103,8 +103,8 @@ public function setUp() { ] ] ], - ), - array( + ], + [ 'name' => 'other text question', 'fieldtype' => 'text', 'show_rule' => 'hidden', @@ -122,21 +122,21 @@ public function setUp() { ] ] ], - ), - ), - ), - ); + ], + ], + ], + ]; - $this->targetData = array( - array( + $this->targetData = [ + [ 'name' => 'target ticket 1', 'itemtype' => 'PluginFormcreatorTargetTicket', - ), - array( + ], + [ 'name' => 'target ticket 2', 'itemtype' => 'PluginFormcreatorTargetTicket', - ) - ); + ] + ]; } public function testInitCreateForm() { diff --git a/tests/0010_Integration/QuestionConditionTest.php b/tests/0010_Integration/QuestionConditionTest.php index 636159242..df6a8a36c 100644 --- a/tests/0010_Integration/QuestionConditionTest.php +++ b/tests/0010_Integration/QuestionConditionTest.php @@ -206,10 +206,10 @@ public function testConditionForSingleValue($condition) { $question->updateConditions($condition); //Run the condition - $currentValues = array( + $currentValues = [ "formcreator_field_$firstQuestionId" => $condition['show_value'][0] . " and now for something completely different", "formcreator_field_$secondQuestionId" => '', - ); + ]; $visibility = PluginFormcreatorFields::updateVisibility($currentValues); // Check the result @@ -221,10 +221,10 @@ public function testConditionForSingleValue($condition) { $this->assertEquals($expected, $visibility["formcreator_field_$secondQuestionId"]); // Run the reversed condition - $currentValues = array( + $currentValues = [ "formcreator_field_$firstQuestionId" => $condition['show_value'][0], "formcreator_field_$secondQuestionId" => '', - ); + ]; $visibility = PluginFormcreatorFields::updateVisibility($currentValues); // Check the result @@ -263,10 +263,10 @@ public function testConditionForMultipleValue($condition) { $this->assertEquals($expected, $visibility["formcreator_field_$secondQuestionId"]); // Run the reversed condition - $currentValues = array( - "formcreator_field_$firstQuestionId" => array($condition['show_value'][0]), + $currentValues = [ + "formcreator_field_$firstQuestionId" => [$condition['show_value'][0]], "formcreator_field_$secondQuestionId" => '', - ); + ]; $visibility = PluginFormcreatorFields::updateVisibility($currentValues); // Check the result diff --git a/tests/0010_Integration/UrgencyTest.php b/tests/0010_Integration/UrgencyTest.php index b13fda4be..048e2656c 100644 --- a/tests/0010_Integration/UrgencyTest.php +++ b/tests/0010_Integration/UrgencyTest.php @@ -41,14 +41,14 @@ class UrgencyTest extends SuperAdminTestCase public function setUp() { parent::setUp(); - $this->formData = array( + $this->formData = [ 'entities_id' => $_SESSION['glpiactive_entity'], 'name' => 'a form', 'description' => 'form description', 'content' => 'a content', 'is_active' => 1, 'validation_required' => 0 - ); + ]; $this->sectionData = [ [ @@ -194,17 +194,17 @@ public function testInitCreateTargetTicket(PluginFormcreatorForm $form) { } $this->assertFalse($question->isNewItem()); $questionId = $question->getID(); - $urgencyQuestions[] = array( + $urgencyQuestions[] = [ 'question' => $question, 'targetTicket' => $targetTicket, 'expected' => $targetData['expected'] - ); + ]; } else { - $urgencyQuestions[] = array( + $urgencyQuestions[] = [ 'question' => null, 'targetTicket' => $targetTicket, 'expected' => $targetData['expected'] - ); + ]; } // Update target ticket diff --git a/tests/src/CommonDBTestCase.php b/tests/src/CommonDBTestCase.php index 68f483c24..485968513 100644 --- a/tests/src/CommonDBTestCase.php +++ b/tests/src/CommonDBTestCase.php @@ -4,7 +4,7 @@ class CommonDBTestCase extends atoum { - protected function drop_database($dbuser='', $dbhost='', $dbdefault='', $dbpassword='') { + protected function drop_database($dbuser = '', $dbhost = '', $dbdefault = '', $dbpassword = '') { $cmd = $this->construct_mysql_options($dbuser, $dbhost, $dbpassword, 'mysql'); @@ -15,26 +15,26 @@ protected function drop_database($dbuser='', $dbhost='', $dbdefault='', $dbpassw $cmd = 'echo "DROP DATABASE IF EXISTS \`'.$dbdefault .'\`; CREATE DATABASE \`'.$dbdefault.'\`" | ' . $cmd ." 2>&1"; $returncode = 0; - $output = array(); + $output = []; exec( $cmd, $output, $returncode ); array_unshift($output, "Output of '{$cmd}'"); - return array( + return [ 'returncode' => $returncode, 'output' => $output - ); + ]; } - protected function load_mysql_file($dbuser='', $dbhost='', $dbdefault='', $dbpassword='', $file = NULL) { + protected function load_mysql_file($dbuser = '', $dbhost = '', $dbdefault = '', $dbpassword = '', $file = null) { if (!file_exists($file)) { - return array( + return [ 'returncode' => 1, - 'output' => array("ERROR: File '$file' does not exist !") - ); + 'output' => ["ERROR: File '$file' does not exist !"] + ]; } $result = $this->construct_mysql_options($dbuser, $dbhost, $dbpassword, 'mysql'); @@ -46,31 +46,31 @@ protected function load_mysql_file($dbuser='', $dbhost='', $dbdefault='', $dbpas $cmd = $result . " " . $dbdefault . " < ". $file ." 2>&1"; $returncode = 0; - $output = array(); + $output = []; exec( $cmd, $output, $returncode ); array_unshift($output, "Output of '$cmd'"); - return array( + return [ 'returncode' => $returncode, 'output' => $output - ); + ]; } - protected function construct_mysql_options($dbuser='', $dbhost='', $dbpassword='', $cmd_base='mysql') { - $cmd = array(); + protected function construct_mysql_options($dbuser = '', $dbhost = '', $dbpassword = '', $cmd_base = 'mysql') { + $cmd = []; if (empty($dbuser) || empty($dbhost)) { - return array( + return [ 'returncode' => 2, - 'output' => array("ERROR: missing mysql parameters (user='{$dbuser}', host='{$dbhost}')") - ); + 'output' => ["ERROR: missing mysql parameters (user='{$dbuser}', host='{$dbhost}')"] + ]; } - $cmd = array($cmd_base); + $cmd = [$cmd_base]; - if (strpos($dbhost, ':') !== FALSE) { + if (strpos($dbhost, ':') !== false) { $dbhost = explode( ':', $dbhost); if (!empty($dbhost[0])) { $cmd[] = "--host ".$dbhost[0]; @@ -94,19 +94,19 @@ protected function construct_mysql_options($dbuser='', $dbhost='', $dbpassword=' return implode(' ', $cmd); } - protected function mysql_dump($dbuser = '', $dbhost = '', $dbpassword = '', $dbdefault = '', $file = NULL) { + protected function mysql_dump($dbuser = '', $dbhost = '', $dbpassword = '', $dbdefault = '', $file = null) { if (is_null($file) or empty($file)) { - return array( + return [ 'returncode' => 1, - 'output' => array("ERROR: mysql_dump()'s file argument must neither be null nor empty") - ); + 'output' => ["ERROR: mysql_dump()'s file argument must neither be null nor empty"] + ]; } if (empty($dbdefault)) { - return array( + return [ 'returncode' => 2, - 'output' => array("ERROR: mysql_dump() is missing dbdefault argument.") - ); + 'output' => ["ERROR: mysql_dump() is missing dbdefault argument."] + ]; } $result = self::construct_mysql_options($dbuser, $dbhost, $dbpassword, 'mysqldump'); @@ -116,17 +116,17 @@ protected function mysql_dump($dbuser = '', $dbhost = '', $dbpassword = '', $dbd $cmd = $result . ' --opt '. $dbdefault.' > ' . $file; $returncode = 0; - $output = array(); + $output = []; exec( $cmd, $output, $returncode ); array_unshift($output, "Output of '{$cmd}'"); - return array( + return [ 'returncode'=>$returncode, 'output' => $output - ); + ]; } /** @@ -146,11 +146,11 @@ public function checkInstall($filename = '', $filter = 'glpi_', $when = '') { $file_content = file_get_contents($filename); $a_lines = explode("\n", $file_content); - $a_tables_ref = array(); + $a_tables_ref = []; $current_table = ''; foreach ($a_lines as $line) { if (strstr($line, "CREATE TABLE ") || strstr($line, "CREATE VIEW ")) { - $matches = array(); + $matches = []; preg_match("/`(.*)`/", $line, $matches); $current_table = $matches[1]; } else { @@ -172,8 +172,8 @@ public function checkInstall($filename = '', $filter = 'glpi_', $when = '') { } // * Get tables from MySQL - $a_tables_db = array(); - $a_tables = array(); + $a_tables_db = []; + $a_tables = []; // SHOW TABLES; $query = "SHOW TABLES LIKE '$filter%'"; $result = $DB->query($query); @@ -193,7 +193,7 @@ public function checkInstall($filename = '', $filter = 'glpi_', $when = '') { foreach ($a_lines as $line) { if (strstr($line, "CREATE TABLE ") OR strstr($line, "CREATE VIEW")) { - $matches = array(); + $matches = []; preg_match("/`(.*)`/", $line, $matches); $current_table = $matches[1]; } else { @@ -212,11 +212,11 @@ public function checkInstall($filename = '', $filter = 'glpi_', $when = '') { } } - $a_tables_ref_tableonly = array(); + $a_tables_ref_tableonly = []; foreach ($a_tables_ref as $table=>$data) { $a_tables_ref_tableonly[] = $table; } - $a_tables_db_tableonly = array(); + $a_tables_db_tableonly = []; foreach ($a_tables_db as $table=>$data) { $a_tables_db_tableonly[] = $table; } @@ -226,8 +226,8 @@ public function checkInstall($filename = '', $filter = 'glpi_', $when = '') { $tables_toadd = array_diff($a_tables_ref_tableonly, $a_tables_db_tableonly); // See tables missing or to delete - $this->integer(count($tables_toadd))->isEqualTo(0, "Tables missing $when " . print_r($tables_toadd, TRUE)); - $this->integer(count($tables_toremove))->isEqualTo(0, "Tables to delete $when " . print_r($tables_toremove, TRUE)); + $this->integer(count($tables_toadd))->isEqualTo(0, "Tables missing $when " . print_r($tables_toadd, true)); + $this->integer(count($tables_toremove))->isEqualTo(0, "Tables to delete $when " . print_r($tables_toremove, true)); // See if fields are same foreach ($a_tables_db as $table=>$data) { @@ -235,12 +235,12 @@ public function checkInstall($filename = '', $filter = 'glpi_', $when = '') { $fields_toremove = array_diff_assoc($data, $a_tables_ref[$table]); $fields_toadd = array_diff_assoc($a_tables_ref[$table], $data); $diff = "======= DB ============== Ref =======> ".$table."\n"; - $diff .= print_r($data, TRUE); - $diff .= print_r($a_tables_ref[$table], TRUE); + $diff .= print_r($data, true); + $diff .= print_r($a_tables_ref[$table], true); // See tables missing or to delete - $this->integer(count($fields_toadd))->isEqualTo(0, "Fields missing/not good during $when $table " . print_r($fields_toadd, TRUE)." into ".$diff); - $this->integer(count($fields_toremove))->isEqualTo(0, "Fields to delete during $when $table " . print_r($fields_toremove, TRUE)." into ".$diff); + $this->integer(count($fields_toadd))->isEqualTo(0, "Fields missing/not good during $when $table " . print_r($fields_toadd, true)." into ".$diff); + $this->integer(count($fields_toremove))->isEqualTo(0, "Fields to delete during $when $table " . print_r($fields_toremove, true)." into ".$diff); } } } diff --git a/tests/src/CommonTestCase.php b/tests/src/CommonTestCase.php index 8231df9fc..6570862d9 100644 --- a/tests/src/CommonTestCase.php +++ b/tests/src/CommonTestCase.php @@ -48,7 +48,7 @@ protected function setupGLPIFramework() { $LOADED_PLUGINS = null; $PLUGINS_INCLUDED = null; $AJAX_INCLUDE = null; - $_SESSION = array(); + $_SESSION = []; if (is_readable(GLPI_ROOT . "/config/config.php")) { $configFile = "/config/config.php"; } else { diff --git a/tests/suite-unit/PluginFormcreatorCheckboxesField.php b/tests/suite-unit/PluginFormcreatorCheckboxesField.php index e4bac0ce4..29fb0cce9 100644 --- a/tests/suite-unit/PluginFormcreatorCheckboxesField.php +++ b/tests/suite-unit/PluginFormcreatorCheckboxesField.php @@ -190,7 +190,7 @@ public function testIsValid($fields, $data, $expectedValue, $expectedValidity) { } public function testPrepareInputForSave() { - $fields = array( + $fields = [ 'fieldtype' => 'checkboxes', 'name' => 'question', 'required' => '0', @@ -200,7 +200,7 @@ public function testPrepareInputForSave() { 'show_rule' => 'always', 'range_min' => 3, 'range_max' => 4, - ); + ]; $fieldInstance = new \PluginFormcreatorCheckboxesField($fields); // Test a value is mandatory diff --git a/tests/suite-unit/PluginFormcreatorQuestion_Condition.php b/tests/suite-unit/PluginFormcreatorQuestion_Condition.php index 1d913563b..90d6779cb 100644 --- a/tests/suite-unit/PluginFormcreatorQuestion_Condition.php +++ b/tests/suite-unit/PluginFormcreatorQuestion_Condition.php @@ -46,205 +46,205 @@ public function beforeTestMethod($method) { } public function answersProvider() { - return array( - 'no condition' => array( + return [ + 'no condition' => [ 'always', - array( - 'show_logic' => array( - ), - 'show_field' => array( - ), - 'show_condition' => array( - ), - 'show_value' => array( - ), - ), + [ + 'show_logic' => [ + ], + 'show_field' => [ + ], + 'show_condition' => [ + ], + 'show_value' => [ + ], + ], [], true, - ), - 'simple condition' => array( + ], + 'simple condition' => [ 'hidden', - array( - 'show_logic' => array( + [ + 'show_logic' => [ 'OR', - ), - 'show_field' => array( + ], + 'show_field' => [ 0, - ), - 'show_condition' => array( + ], + 'show_condition' => [ '==', - ), - 'show_value' => array( + ], + 'show_value' => [ 'foo', - ), - ), - array( + ], + ], + [ 0 => 'foo', - ), + ], true, - ), - 'failed condition' => array( + ], + 'failed condition' => [ 'hidden', - array( - 'show_logic' => array( + [ + 'show_logic' => [ 'OR', - ), - 'show_field' => array( + ], + 'show_field' => [ 0, - ), - 'show_condition' => array( + ], + 'show_condition' => [ '==', - ), - 'show_value' => array( + ], + 'show_value' => [ 'bar', - ), - ), - array( + ], + ], + [ 0 => 'foo', - ), + ], false, - ), - 'multiple condition OR' => array( + ], + 'multiple condition OR' => [ 'hidden', - array( - 'show_logic' => array( + [ + 'show_logic' => [ 'OR', 'OR', - ), - 'show_field' => array( + ], + 'show_field' => [ 0, 1, - ), - 'show_condition' => array( + ], + 'show_condition' => [ '==', '==', - ), - 'show_value' => array( + ], + 'show_value' => [ 'val1', 'val2', - ), - ), - array( + ], + ], + [ 0 => 'val1', 1 => 'val2', - ), + ], true, - ), - 'failed multiple condition OR' => array( + ], + 'failed multiple condition OR' => [ 'hidden', - array( - 'show_logic' => array( + [ + 'show_logic' => [ 'OR', 'OR', - ), - 'show_field' => array( + ], + 'show_field' => [ 0, 1, - ), - 'show_condition' => array( + ], + 'show_condition' => [ '==', '==', - ), - 'show_value' => array( + ], + 'show_value' => [ 'val1', 'val2', - ), - ), - array( + ], + ], + [ 0 => 'val1', 1 => 'not val2', - ), + ], true, - ), - 'multiple condition AND' => array( + ], + 'multiple condition AND' => [ 'hidden', - array( - 'show_logic' => array( + [ + 'show_logic' => [ 'OR', 'AND', - ), - 'show_field' => array( + ], + 'show_field' => [ 0, 1, - ), - 'show_condition' => array( + ], + 'show_condition' => [ '==', '==', - ), - 'show_value' => array( + ], + 'show_value' => [ 'val1', 'val2', - ), - ), - array( + ], + ], + [ 0 => 'val1', 1 => 'val2', - ), + ], true, - ), - 'failed multiple condition AND' => array( + ], + 'failed multiple condition AND' => [ 'hidden', - array( - 'show_logic' => array( + [ + 'show_logic' => [ 'OR', 'AND', - ), - 'show_field' => array( + ], + 'show_field' => [ 0, 1, - ), - 'show_condition' => array( + ], + 'show_condition' => [ '==', '==', - ), - 'show_value' => array( + ], + 'show_value' => [ 'val1', 'val2', - ), - ), - array( + ], + ], + [ 0 => 'val1', 1 => 'not val2', - ), + ], false, - ), - 'operator priority' => array( + ], + 'operator priority' => [ 'hidden', - array( - 'show_logic' => array( + [ + 'show_logic' => [ 'OR', 'AND', 'OR', 'AND', - ), - 'show_field' => array( + ], + 'show_field' => [ 0, 1, 2, 3, - ), - 'show_condition' => array( + ], + 'show_condition' => [ '==', '==', '==', '==', - ), - 'show_value' => array( + ], + 'show_value' => [ 'val1', 'val2', 'val3', 'val4', - ), - ), - array( + ], + ], + [ 0 => 'val1', 1 => 'val2', 2 => 'val8', 3 => 'val9', - ), + ], true, - ), - ); + ], + ]; } /** diff --git a/tests/suite-unit/PluginFormcreatorSection.php b/tests/suite-unit/PluginFormcreatorSection.php index a4826d01b..90a6eb6f2 100644 --- a/tests/suite-unit/PluginFormcreatorSection.php +++ b/tests/suite-unit/PluginFormcreatorSection.php @@ -47,17 +47,17 @@ public function testDuplicate() { $question = new \PluginFormcreatorQuestion; // create objects - $forms_id = $form->add(array('name' => "test clone form", + $forms_id = $form->add(['name' => "test clone form", 'is_active' => true, - 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER)); - $sections_id = $section->add(array('name' => "test clone section", - 'plugin_formcreator_forms_id' => $forms_id)); - $questions_id_1 = $question->add(array('name' => "test clone question 1", + 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER]); + $sections_id = $section->add(['name' => "test clone section", + 'plugin_formcreator_forms_id' => $forms_id]); + $questions_id_1 = $question->add(['name' => "test clone question 1", 'fieldtype' => 'text', - 'plugin_formcreator_sections_id' => $sections_id)); - $questions_id_2 = $question->add(array('name' => "test clone question 2", + 'plugin_formcreator_sections_id' => $sections_id]); + $questions_id_2 = $question->add(['name' => "test clone question 2", 'fieldtype' => 'textarea', - 'plugin_formcreator_sections_id' => $sections_id)); + 'plugin_formcreator_sections_id' => $sections_id]); //get section plugin_formcreator_getFromDBByField($section, 'name', "test clone section"); From 3a26922eb3fc52afc9036f47495779cf8dd828ad Mon Sep 17 00:00:00 2001 From: btry Date: Wed, 29 Aug 2018 14:32:50 +0200 Subject: [PATCH 039/192] fix(filefield): check all files, not only one Signed-off-by: btry --- inc/fields/filefield.class.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/inc/fields/filefield.class.php b/inc/fields/filefield.class.php index 31cab6a58..156896afa 100644 --- a/inc/fields/filefield.class.php +++ b/inc/fields/filefield.class.php @@ -69,14 +69,15 @@ public function isValid($value) { if (is_array($_POST['_formcreator_field_' . $this->fields['id']]) && count($_POST['_formcreator_field_' . $this->fields['id']]) > 0) { - $file = current($_POST['_formcreator_field_' . $this->fields['id']]); - if (is_file(GLPI_TMP_DIR . '/' . $file)) { - return true; + foreach ($_POST['_formcreator_field_' . $this->fields['id']] as $file) { + if (!is_file(GLPI_TMP_DIR . '/' . $file)) { + Session::addMessageAfterRedirect(__('A required file is missing:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); + return false; + } } } - Session::addMessageAfterRedirect(__('A required file is missing:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); - return false; + return true; } public static function getName() { From 4f4c24c96fda2c8666b84065e531c99a64ebe372 Mon Sep 17 00:00:00 2001 From: btry Date: Wed, 29 Aug 2018 15:34:55 +0200 Subject: [PATCH 040/192] fix(target): inconsistency in multiple file upload Signed-off-by: btry --- inc/targetbase.class.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index 59f3eac49..016d0c422 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -810,11 +810,13 @@ protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer, $value = $fieldObject->prepareQuestionInputForTarget($fieldObject->getValue()); } - if (is_array($value) && $question_line['fieldtype'] !== 'file') { - if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { - $value = '
' . implode('
', $value); - } else { - $value = "\r\n" . implode("\r\n", $value); + if ($question_line['fieldtype'] !== 'file') { + if (is_array($value)) { + if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { + $value = '
' . implode('
', $value); + } else { + $value = "\r\n" . implode("\r\n", $value); + } } $content = str_replace('##question_' . $id . '##', addslashes($name), $content); $content = str_replace('##answer_' . $id . '##', $value, $content); From 97c8eb5f74394604ec0692e04dd237efcf5e4b30 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 28 Aug 2018 22:55:41 +0200 Subject: [PATCH 041/192] refactor: field instanciation factorization Signed-off-by: Thierry Bugier --- inc/fields.class.php | 11 +++++------ inc/form.class.php | 3 +-- inc/question.class.php | 22 +++++++--------------- inc/questionparameter.class.php | 3 +-- inc/section.class.php | 3 +-- inc/targetbase.class.php | 7 +++---- 6 files changed, 18 insertions(+), 31 deletions(-) diff --git a/inc/fields.class.php b/inc/fields.class.php index 433d99c3c..d10bb291a 100644 --- a/inc/fields.class.php +++ b/inc/fields.class.php @@ -69,8 +69,8 @@ public static function getClasses() { foreach (glob(dirname(__FILE__).'/fields/*field.class.php') as $class_file) { $matches = null; preg_match("#fields/(.+)field\.class.php$#", $class_file, $matches); - $classname = 'PluginFormcreator' . ucfirst($matches[1]) . 'Field'; - if (class_exists($classname)) { + $classname = self::getFieldClassname($matches[1]); + if (self::fieldTypeExists($matches[1])) { $classes[strtolower($matches[1])] = $classname; } } @@ -92,8 +92,8 @@ public static function getNames() { // Get localized names of field types foreach (PluginFormcreatorFields::getClasses() as $field_type => $classname) { - $classname = 'PluginFormcreator' . ucfirst($field_type) . 'Field'; - if ($classname == 'PluginFormcreatorTagField' && !$plugin->isActivated('tag')) { + $classname = self::getFieldClassname($field_type); + if ($classname == PluginFormcreatorTagField::class && !$plugin->isActivated('tag')) { continue; } @@ -112,8 +112,7 @@ public static function printAllTabFieldsForJS() { // Get field types preference for JS foreach (array_keys($tab_field_types) as $field_type) { - $classname = 'PluginFormcreator' . ucfirst($field_type) . 'Field'; - + $classname = PluginFormcreatorFields::getFieldClassname($field_type); if (method_exists($classname, 'getJSFields')) { $tabFieldsForJS .= PHP_EOL.' '.$classname::getJSFields(); } diff --git a/inc/form.class.php b/inc/form.class.php index 153b3856e..e2eecf945 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1357,8 +1357,7 @@ public function duplicate() { foreach ($tab_questions as $questions_id => $new_questions_id) { $oldQuestion = new PluginFormcreatorQuestion(); $oldQuestion->getFromDB($questions_id); - $fieldType = 'PluginFormcreator' . ucfirst($oldQuestion->fields['fieldtype']) . 'Field'; - $field = new $fieldType($oldQuestion->fields); + $field = PluginFormcreatorFields::getFieldInstance($oldQuestion->fields['fieldtype'], $oldQuestion); $parameters = $field->getUsedParameters(); foreach ($parameters as $fieldName => $parameter) { $parameter->getFromDBByCrit([ diff --git a/inc/question.class.php b/inc/question.class.php index 4d5f150d7..ae8d440d8 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -622,8 +622,7 @@ public function updateParameters($input) { return; } - $fieldType = 'PluginFormcreator' . ucfirst($input['fieldtype']) . 'Field'; - $this->field = new $fieldType($this->fields); + $this->field = PluginFormcreatorFields::getFieldInstance($input['fieldtype'], $this); $parameters = $this->field->getUsedParameters(); if (isset($input['_parameters'][$this->fields['fieldtype']])) { foreach ($input['_parameters'][$this->fields['fieldtype']] as $fieldName => $parameterInput) { @@ -644,8 +643,7 @@ public function updateParameters($input) { } public function pre_deleteItem() { - $fieldType = 'PluginFormcreator' . ucfirst($this->fields['fieldtype']) . 'Field'; - $this->field = new $fieldType($this->fields); + $this->field = PluginFormcreatorFields::getFieldInstance($this->getField('fieldtype'), $this); return $this->field->deleteParameters($this); } @@ -656,8 +654,7 @@ public function post_updateItem($history = 1) { } else { // Field type changed // Drop old parameters - $fieldType = 'PluginFormcreator' . ucfirst($this->oldvalues['fieldtype']) . 'Field'; - $oldField = new $fieldType($this->oldvalues); + $oldField = PluginFormcreatorFields::getFieldInstance($this->oldvalues['fieldtype'], $this); $oldField->deleteParameters($this); // add new ones @@ -1345,8 +1342,7 @@ public function duplicate() { } // Form questions parameters - $fieldType = 'PluginFormcreator' . ucfirst($this->fields['fieldtype']) . 'Field'; - $this->field = new $fieldType($this->fields); + $this->field = PluginFormcreatorFields::getFieldInstance($this->getField('fieldtype'), $this); $parameters = $this->field->getUsedParameters(); foreach ($parameters as $fieldName => $parameter) { $parameter->getFromDBByCrit([ @@ -1419,9 +1415,7 @@ public static function import(PluginFormcreatorImportLinker $importLinker, $sect if ($questions_id = plugin_formcreator_getFromDBByField($item, 'uuid', $question['uuid'])) { // add id key $question['id'] = $questions_id; - $fieldType = 'PluginFormcreator' . ucfirst($question['fieldtype']) . 'Field'; - $item->field = new $fieldType($item->fields); - + $item->field = PluginFormcreatorFields::getFieldInstance($question['fieldtype'], $item); // update question $item->update($question); } else { @@ -1438,8 +1432,7 @@ public static function import(PluginFormcreatorImportLinker $importLinker, $sect PluginFormcreatorQuestion_Condition::import($importLinker, $questions_id, $condition); } - $fieldType = 'PluginFormcreator' . ucfirst($question['fieldtype']) . 'Field'; - $field = new $fieldType($item->fields); + $field = PluginFormcreatorFields::getFieldInstance($question['fieldtype'], $question); $parameters = $field->getUsedParameters(); foreach ($parameters as $fieldName => $parameter) { $parameter->getFromDBByCrit([ @@ -1482,8 +1475,7 @@ public function export($remove_uuid = false) { // get question parameters $question['_parameters'] = []; - $fieldType = 'PluginFormcreator' . ucfirst($this->fields['fieldtype']) . 'Field'; - $this->field = new $fieldType($this->fields); + $this->field = PluginFormcreatorFields::getFieldIntance($this->getField('fieldtype'), $this); $parameters = $this->field->getUsedParameters(); foreach ($parameters as $fieldname => $parameter) { $parameter->getFromDBByCrit([ diff --git a/inc/questionparameter.class.php b/inc/questionparameter.class.php index bfb01d92d..c3d0abf67 100644 --- a/inc/questionparameter.class.php +++ b/inc/questionparameter.class.php @@ -80,8 +80,7 @@ public static function import(PluginFormcreatorImportLinker $importLinker, $ques // get a built instance of the parameter $question = new PluginFormcreatorquestion(); $question->getFromDB($questions_id); - $fieldType = 'PluginFormcreator' . ucfirst($question->fields['fieldtype']) . 'Field'; - $field = new $fieldType($question->fields); + $field = PluginFormcreatorFields::getFieldIntance($question->getField('fieldtype'), $question); $parameters = $field->getUsedParameters(); $item = $parameters[$fieldName]; $found = $item->getFromDBByCrit([ diff --git a/inc/section.class.php b/inc/section.class.php index acbc82ce4..9e9ad4818 100644 --- a/inc/section.class.php +++ b/inc/section.class.php @@ -190,8 +190,7 @@ public function duplicate() { foreach ($tab_questions as $questions_id => $new_questions_id) { $oldQuestion = new PluginFormcreatorQuestion(); $oldQuestion->getFromDB($questions_id); - $fieldType = 'PluginFormcreator' . ucfirst($oldQuestion->fields['fieldtype']) . 'Field'; - $this->field = new $fieldType($oldQuestion->fields); + $this->field = PluginFormcreatorFields::getFieldInstance($oldQuestion->getField('fieldtype'), $oldQuestion); $parameters = $this->field->getUsedParameters(); foreach ($parameters as $fieldName => $parameter) { $parameter->getFromDBByCrit([ diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index 016d0c422..0834794d5 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -796,10 +796,9 @@ protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer, ORDER BY `questions`.`order` ASC"; $res_questions = $DB->query($query_questions); while ($question_line = $DB->fetch_assoc($res_questions)) { - $classname = 'PluginFormcreator'.ucfirst($question_line['fieldtype']).'Field'; - if (class_exists($classname)) { - $fieldObject = new $classname($question_line, $question_line['answer']); - } + $question = new PluginFormcreatorQuestion(); + $question->getFromDB($question_line['id']); + $fieldObject = PluginFormcreatorFields::getFieldInstance($question_line['fieldtype'], $question, $question_line['answer']); $id = $question_line['id']; if (!PluginFormcreatorFields::isVisible($question_line['id'], $answers_values)) { From e12d929a93796b989209fdc5109f0bc47552d3d3 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 28 Aug 2018 22:55:57 +0200 Subject: [PATCH 042/192] refactor(question): use query builder Signed-off-by: Thierry Bugier --- inc/question.class.php | 46 ++++++++++++++++++++++---------- inc/questiondependency.class.php | 2 +- inc/targetbase.class.php | 39 +++++++++++---------------- 3 files changed, 49 insertions(+), 38 deletions(-) diff --git a/inc/question.class.php b/inc/question.class.php index ae8d440d8..8d7656400 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -1530,25 +1530,43 @@ public function getForm() { /** * return array of question objects belonging to a form * @param integer $formId + * @param array $crit array for the WHERE clause * @return PluginFormcreatorQuestion[] */ - public function getQuestionsFromForm($formId, $crit = '') { + public function getQuestionsFromForm($formId, $crit = []) { global $DB; - $questions = []; - if ($crit === '') { - $crit = '1'; - } $dbUtil = new DbUtils(); - $table_question = $dbUtil->getTableForItemtype('PluginFormcreatorQuestion'); - $table_section = $dbUtil->getTableForItemtype('PluginFormcreatorSection'); - $result = $DB->query("SELECT `q`.* - FROM $table_question `q` - LEFT JOIN $table_section `s` ON `q`.`plugin_formcreator_sections_id` = `s`.`id` - WHERE `s`.`plugin_formcreator_forms_id` = '$formId' AND $crit - ORDER BY `s`.`order`, `q`.`order`" - ); - while ($row = $DB->fetch_assoc($result)) { + $table_question = PluginFormcreatorQuestion::getTable(); + $table_section = PluginFormcreatorSection::getTable(); + $sectionFk = PluginFormcreatorSection::getForeignKeyField(); + $formFk = PluginFormcreatorForm::getForeignKeyField(); + $request = [ + 'SELECT' => "$table_question.*", + 'FROM' => $table_question, + 'LEFT JOIN' => [ + $table_section => [ + 'FKEY' => [ + $table_question => $sectionFk, + $table_section => 'id', + ], + ], + ], + 'WHERE' => [ + $formFk => $formId, + ], + 'ORDER' => [ + "$table_section.order", + "$table_question.order", + ] + ]; + if (count($crit) > 0) { + $request['WHERE']['AND'] = $crit; + } + + $result = $DB->request($request); + $questions = []; + while ($row = $result->next()) { $question = new self(); $question->getFromDB($row['id']); $questions[$row['id']] = $question; diff --git a/inc/questiondependency.class.php b/inc/questiondependency.class.php index c63dfa9d5..51d4dcfd0 100644 --- a/inc/questiondependency.class.php +++ b/inc/questiondependency.class.php @@ -37,7 +37,7 @@ public function getParameterFormSize() { public function getParameterForm(PluginFormcreatorForm $form, PluginFormcreatorQuestion $question) { // get questions of type text in the form $eligibleQuestions = []; - $criteria = "`fieldtype` IN ('" . implode("', '", $this->fieldtype) . "')"; + $criteria = ['fieldtype' => $this->fieldtype]; foreach ($question->getQuestionsFromForm($form->getID(), $criteria) as $item) { $eligibleQuestions[$item->getID()] = $item->getField('name'); } diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index 0834794d5..152c2d5f6 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -787,29 +787,22 @@ protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer, $sectionsIdString = implode(', ', array_keys($sections)); if (count($sections) > 0) { - $query_questions = "SELECT `questions`.*, `answers`.`answer` - FROM `glpi_plugin_formcreator_questions` AS questions - LEFT JOIN `glpi_plugin_formcreator_answers` AS answers - ON `answers`.`plugin_formcreator_questions_id` = `questions`.`id` - AND `plugin_formcreator_forms_answers_id` = ".$formanswer->getID()." - WHERE `questions`.`plugin_formcreator_sections_id` IN ($sectionsIdString) - ORDER BY `questions`.`order` ASC"; - $res_questions = $DB->query($query_questions); - while ($question_line = $DB->fetch_assoc($res_questions)) { - $question = new PluginFormcreatorQuestion(); - $question->getFromDB($question_line['id']); - $fieldObject = PluginFormcreatorFields::getFieldInstance($question_line['fieldtype'], $question, $question_line['answer']); - - $id = $question_line['id']; - if (!PluginFormcreatorFields::isVisible($question_line['id'], $answers_values)) { + $formFk = PluginFormcreatorForm::getForeignKeyField(); + $questions = (new PluginFormcreatorQuestion()) + ->getQuestionsFromForm($formanswer->getField($formFk)); + foreach ($questions as $questionId => $question) { + $answer = $answers_values['formcreator_field_' . $questionId]; + $fieldObject = PluginFormcreatorFields::getFieldInstance($question->getField('fieldtype'), $question, $answer); + + if (!PluginFormcreatorFields::isVisible($questionId, $answers_values)) { $name = ''; $value = ''; } else { - $name = $question_line['name']; + $name = $question->getField('name'); $value = $fieldObject->prepareQuestionInputForTarget($fieldObject->getValue()); } - if ($question_line['fieldtype'] !== 'file') { + if ($question->getField('fieldtype') !== 'file') { if (is_array($value)) { if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { $value = '
' . implode('
', $value); @@ -817,22 +810,22 @@ protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer, $value = "\r\n" . implode("\r\n", $value); } } - $content = str_replace('##question_' . $id . '##', addslashes($name), $content); - $content = str_replace('##answer_' . $id . '##', $value, $content); + $content = str_replace('##question_' . $questionId . '##', addslashes($name), $content); + $content = str_replace('##answer_' . $questionId . '##', $value, $content); } else { - if (strpos($content, '##answer_' . $id . '##') !== false) { - $content = str_replace('##question_' . $id . '##', addslashes($name), $content); + if (strpos($content, '##answer_' . $questionId . '##') !== false) { + $content = str_replace('##question_' . $questionId . '##', addslashes($name), $content); if (!is_array($value)) { $value = [$value]; } if (count($value)) { - $content = str_replace('##answer_' . $id . '##', __('Attached document', 'formcreator'), $content); + $content = str_replace('##answer_' . $questionId . '##', __('Attached document', 'formcreator'), $content); // keep the ID of the document foreach ($value as $documentId) { $this->attachedDocuments[$documentId] = true; } } else { - $content = str_replace('##answer_' . $id . '##', '', $content); + $content = str_replace('##answer_' . $questionId . '##', '', $content); } } } From 53ee63387b273fd8feee1ab694203e9119562371 Mon Sep 17 00:00:00 2001 From: btry Date: Wed, 29 Aug 2018 13:06:06 +0200 Subject: [PATCH 043/192] test: improve tests Signed-off-by: btry --- inc/fields/checkboxesfield.class.php | 1 - .../PluginFormcreatorCheckboxesField.php | 31 +++- .../suite-unit/PluginFormcreatorDateField.php | 145 ++++++++++++++++++ .../PluginFormcreatorDatetimeField.php | 6 + 4 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 tests/suite-unit/PluginFormcreatorDateField.php create mode 100644 tests/suite-unit/PluginFormcreatorDatetimeField.php diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index e78ce6782..f527b24a7 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -243,5 +243,4 @@ public function getUsedParameters() { ), ]; } - } diff --git a/tests/suite-unit/PluginFormcreatorCheckboxesField.php b/tests/suite-unit/PluginFormcreatorCheckboxesField.php index 29fb0cce9..95e6a6842 100644 --- a/tests/suite-unit/PluginFormcreatorCheckboxesField.php +++ b/tests/suite-unit/PluginFormcreatorCheckboxesField.php @@ -3,7 +3,7 @@ use GlpiPlugin\Formcreator\Tests\CommonTestCase; class PluginFormcreatorCheckboxesField extends CommonTestCase { - public function provider() { + public function providerGetAvailableValues() { $dataset = [ [ 'fields' => [ @@ -143,7 +143,7 @@ public function provider() { } /** - * @dataProvider provider + * @dataProvider providerGetAvailableValues */ public function testGetAvailableValues($fields, $data, $expectedValue, $expectedValidity) { $fieldInstance = new \PluginFormcreatorCheckboxesField($fields, $data); @@ -158,8 +158,12 @@ public function testGetAvailableValues($fields, $data, $expectedValue, $expected } } + public function providerGetValue() { + return $this->providerGetAvailableValues(); + } + /** - * @dataProvider provider + * @dataProvider providerGetValue */ public function testGetValue($fields, $data, $expectedValue, $expectedValidity) { $fieldInstance = new \PluginFormcreatorCheckboxesField($fields, $data); @@ -171,8 +175,12 @@ public function testGetValue($fields, $data, $expectedValue, $expectedValidity) } } + public function providerIsValid() { + return $this->providerGetAvailableValues(); + } + /** - * @dataProvider provider + * @dataProvider providerIsValid */ public function testIsValid($fields, $data, $expectedValue, $expectedValidity) { $section = $this->getSection(); @@ -201,7 +209,7 @@ public function testPrepareInputForSave() { 'range_min' => 3, 'range_max' => 4, ]; - $fieldInstance = new \PluginFormcreatorCheckboxesField($fields); + $fieldInstance = $this->newTestedInstance($fields); // Test a value is mandatory $input = [ @@ -229,4 +237,17 @@ public function testPrepareInputForSave() { $this->string($out['values'])->isEqualTo('something\r\nsomething else'); $this->string($out['default_values'])->isEqualTo("something"); } + + /** + * @engine inline + */ + public function testGetUsedParameters() { + $instance = $this->newTestedInstance([]); + $output = $instance->getUsedParameters(); + $this->array($output) + ->hasKey('range') + ->array($output)->size->isEqualTo(1); + $this->object($output['range']) + ->isInstanceOf(\PluginFormcreatorQuestionRange::class); + } } \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorDateField.php b/tests/suite-unit/PluginFormcreatorDateField.php new file mode 100644 index 000000000..1e8fdf05e --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorDateField.php @@ -0,0 +1,145 @@ + [ + 'fieldtype' => 'date', + 'name' => 'question', + 'required' => '0', + 'default_values' => '', + 'values' => "2018-08-16", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => null, + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'date', + 'name' => 'question', + 'required' => '0', + 'default_values' => '', + 'values' => "", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => '', + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'date', + 'name' => 'question', + 'required' => '1', + 'default_values' => '', + 'values' => "", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => null, + 'expectedIsValid' => false + ], + [ + 'fields' => [ + 'fieldtype' => 'date', + 'name' => 'question', + 'required' => '1', + 'default_values' => '2018-08-16', + 'values' => "", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => '2018-08-16', + 'expectedIsValid' => true + ], + ]; + + return $dataset; + } + + /** + * @dataProvider providerGetValue + */ + public function testGetValue($fields, $data, $expectedValue, $expectedValidity) { + $instance = $this->newTestedInstance($fields, $data); + + $value = $instance->getValue(); + $this->variable($value)->isEqualTo($expectedValue); + } + + public function providerIsValid() { + return $this->providerGetValue(); + } + + public function providerGetAnswer() { + return $this->providerGetValue(); + } + + /** + * @dataProvider providerGetAnswer + */ + public function testGetAnswer($fields, $data, $expectedValue, $expectedValidity) { + $instance = $this->newTestedInstance($fields, $data); + + $expected = \Html::convDate($fields['default_values']); + $output = $instance->getAnswer(); + $this->variable($output)->isEqualTo($expected); + } + + /** + * @dataProvider providerIsValid + */ + public function testIsValid($fields, $data, $expectedValue, $expectedValidity) { + $instance = $this->newTestedInstance($fields, $data); + + $isValid = $instance->isValid($fields['default_values']); + $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); + } + + public function testGetName() { + $output = \PluginFormcreatorDateField::getName(); + $this->string($output)->isEqualTo('Date'); + } +} \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorDatetimeField.php b/tests/suite-unit/PluginFormcreatorDatetimeField.php new file mode 100644 index 000000000..87d347a8e --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorDatetimeField.php @@ -0,0 +1,6 @@ + Date: Wed, 29 Aug 2018 16:25:07 +0200 Subject: [PATCH 044/192] test: cleanup old phpunit tests Signed-off-by: btry --- .../0010_Integration/FormDuplicationTest.php | 236 ---------- .../QuestionConditionTest.php | 419 ------------------ tests/0010_Integration/UrgencyTest.php | 249 ----------- .../suite-unit/PluginFormcreatorDateField.php | 14 +- .../PluginFormcreatorDatetimeField.php | 144 ++++++ 5 files changed, 151 insertions(+), 911 deletions(-) delete mode 100644 tests/0010_Integration/FormDuplicationTest.php delete mode 100644 tests/0010_Integration/QuestionConditionTest.php delete mode 100644 tests/0010_Integration/UrgencyTest.php diff --git a/tests/0010_Integration/FormDuplicationTest.php b/tests/0010_Integration/FormDuplicationTest.php deleted file mode 100644 index 16febf757..000000000 --- a/tests/0010_Integration/FormDuplicationTest.php +++ /dev/null @@ -1,236 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class FormDuplicationTest extends SuperAdminTestCase -{ - - protected $formData; - protected $sectionData; - protected $targetData; - - public function setUp() { - parent::setUp(); - - $this->formData = [ - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'a form', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 0 - ]; - - $this->sectionData = [ - [ - 'name' => 'a section', - 'questions' => [ - [ - 'name' => 'text question', - 'fieldtype' => 'text', - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ], - ], - [ - 'name' => 'other text question', - 'fieldtype' => 'text', - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ], - ], - ], - ], - [ - 'name' => 'an other section', - 'questions' => [ - [ - 'name' => 'text question', - 'fieldtype' => 'text', - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ], - ], - [ - 'name' => 'other text question', - 'fieldtype' => 'text', - 'show_rule' => 'hidden', - 'show_field' => 'text question', - 'show_condition' => '==', - 'show_value' => 'azerty', - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ], - ], - ], - ], - ]; - - $this->targetData = [ - [ - 'name' => 'target ticket 1', - 'itemtype' => 'PluginFormcreatorTargetTicket', - ], - [ - 'name' => 'target ticket 2', - 'itemtype' => 'PluginFormcreatorTargetTicket', - ] - ]; - } - - public function testInitCreateForm() { - $form = new PluginFormcreatorForm(); - $formId = $form->add($this->formData); - $this->assertFalse($form->isNewItem()); - - foreach ($this->sectionData as $sectionData) { - // Keep questions data set apart from sections data - $questionData = $sectionData['questions']; - unset($sectionData['questions']); - - // Create section - $sectionData['plugin_formcreator_forms_id'] = $form->getID(); - $section = new PluginFormcreatorSection(); - $section->add($sectionData); - $this->assertFalse($section->isNewItem()); - $sectionId = $section->getID(); - foreach ($questionData as $oneQuestionData) { - // Create question - $oneQuestionData ['plugin_formcreator_sections_id'] = $section->getID(); - $question = new PluginFormcreatorQuestion(); - $question->add($oneQuestionData); - $this->assertFalse($question->isNewItem(), json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); - - $questionData['id'] = $question->getID(); - if (isset($questionData['show_rule']) && $questionData['show_rule'] != 'always') { - $showFieldName = $oneQuestionData['show_field']; - $showfield = new PluginFormcreatorQuestion(); - $showfield->getFromDBByCrit([ - 'AND' => [ - 'plugin_formcreator_sections_id' => $sectionId, - 'name' => $showFieldName - ] - ]); - $oneQuestionData['show_field'] = $showfield->getID(); - $question->updateConditions($oneQuestionData); - } - $question->updateParameters($oneQuestionData); - } - foreach ($this->targetData as $targetData) { - $target = new PluginFormcreatorTarget(); - $targetData['plugin_formcreator_forms_id'] = $formId; - $target->add($targetData); - $this->assertFalse($target->isNewItem()); - } - } - - return $form; - } - - /** - * @depends testInitCreateForm - * @param PluginFormcreatorForm $form - */ - public function testDuplicateForm(PluginFormcreatorForm $form) { - $sourceFormId = $form->getID(); - $this->assertTrue($form->duplicate()); - - // Check the ID of the form changed - $newFormId = $form->getID(); - $this->assertNotEquals($sourceFormId, $newFormId); - - // Check sections were copied - $section = new PluginFormcreatorSection(); - $sourceRows = $section->find("`plugin_formcreator_forms_id` = '$sourceFormId'"); - $newRows = $section->find("`plugin_formcreator_forms_id` = '$newFormId'"); - $this->assertEquals(count($sourceRows), count ($newRows)); - - // Check questions were copied - $table_section = PluginFormcreatorSection::getTable(); - $question = new PluginFormcreatorQuestion(); - $sourceRows = $question->find("`plugin_formcreator_sections_id` IN ( - SELECT `id` FROM `$table_section` WHERE `$table_section`.`plugin_formcreator_forms_id` = '$sourceFormId' - )"); - $newRows = $question->find("`plugin_formcreator_sections_id` IN ( - SELECT `id` FROM `$table_section` WHERE `$table_section`.`plugin_formcreator_forms_id` = '$newFormId' - )"); - $this->assertEquals(count($sourceRows), count($newRows)); - - // check target were created - $target = new PluginFormcreatorTarget(); - $sourceRows = $target->find("`plugin_formcreator_forms_id` = '$sourceFormId'"); - $newRows = $target->find("`plugin_formcreator_forms_id` = '$sourceFormId'"); - $this->assertEquals(count($sourceRows), count($newRows)); - - // check target tickets were created - foreach ($newRows as $targetId => $newTarget) { - if ($newTarget['itemtype'] == 'PluginFormcreatorTargetTicket') { - $targetTicket = new PluginFormcreatorTArgetTicket(); - $targetTicket->getFromDB($newTarget['items_id']); - $this->assertFalse($targetTicket->isNewItem()); - } - } - - } -} diff --git a/tests/0010_Integration/QuestionConditionTest.php b/tests/0010_Integration/QuestionConditionTest.php deleted file mode 100644 index df6a8a36c..000000000 --- a/tests/0010_Integration/QuestionConditionTest.php +++ /dev/null @@ -1,419 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class QuestionConditionTest extends SuperAdminTestCase -{ - protected static $formData; - protected static $sectionData; - protected static $form; - protected static $targetData; - protected static $sections = []; - protected static $questions = []; - - public static function setUpBeforeClass() { - parent::setUpBeforeClass(); - - self::$formData = [ - 'entities_id' => 0, - 'name' => 'a form', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 0 - ]; - - self::$sectionData = [ - [ - 'name' => 'a section', - 'questions' => [ - [ - 'name' => 'text question', - 'fieldtype' => 'text', - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ] - ], - [ - 'name' => 'other text question', - 'fieldtype' => 'text', - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ] - ], - [ - 'name' => 'third text question', - 'fieldtype' => 'text', - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ] - ], - ], - ], - ]; - - self::$targetData = []; - - self::login('glpi', 'glpi', true); - self::$form = new PluginFormcreatorForm(); - $formId = self::$form->add(self::$formData); - - foreach (self::$sectionData as $sectionData) { - // Keep questions data set apart from sections data - $questionsData = $sectionData['questions']; - unset($sectionData['questions']); - - // Create section - $sectionData['plugin_formcreator_forms_id'] = self::$form->getID(); - $section = new PluginFormcreatorSection(); - $section->add($sectionData); - self::$sections[] = $section; - $sectionId = $section->getID(); - foreach ($questionsData as $questionData) { - // Create question - $questionData['plugin_formcreator_sections_id'] = $section->getID(); - $question = new PluginFormcreatorQuestion(); - $question->add($questionData); - self::$questions[] = $question; - - $questionData['id'] = $question->getID(); - if (isset($questionData['show_rule']) && $questionData['show_rule'] != 'always') { - $showFieldName = $questionData['show_field']; - $showfield = new PluginFormcreatorQuestion(); - $showfield->getFromDBByCrit([ - 'AND' => [ - 'plugin_formcreator_sections_id' => $sectionId, - 'name' => $showFieldName - ] - ]); - $questionData['show_field'] = $showfield->getID(); - $question->updateConditions($questionData); - } - $question->updateParameters($questionData); - } - foreach (self::$targetData as $targetData) { - $target = new PluginFormcreatorTarget(); - $targetData['plugin_formcreator_forms_id'] = $formId; - $target->add($targetData); - } - } - - if (count(self::$questions) < 2) { - throw new Exception("Need at least two questions"); - } - } - - public function conditionDataProvider() { - return [ - [ - [ - 'show_rule' => 'hidden', - 'show_question' => ['dummy'], - 'show_condition' => ['=='], - 'show_value' => ['an accented è character'], - 'show_logic' => ['AND'], - ] - ], - /* This test currently fails due to Html::clean() in plugin_formcreator_encode() - * No solution found yet, then test disabled - [ - [ - 'show_rule' => 'hidden', - 'show_question' => ['dummy'], - 'show_condition' => ['=='], - 'show_value' => ['a doubled space'], - ] - ],*/ - [ - [ - 'show_rule' => 'hidden', - 'show_question' => ['dummy'], - 'show_condition' => ['=='], - 'show_value' => ['a euro € character'], - 'show_logic' => ['AND'], - ] - ], - ]; - } - - /** - * Checks a question shows and hides when conditions applies, assuming the reference question is single valued - * (ie: a text field) - * - * @dataProvider conditionDataProvider - */ - public function testConditionForSingleValue($condition) { - // Setup the condition - $question = self::$questions[1]; - $firstQuestionId = self::$questions[0]->getID(); - $secondQuestionId = $question->getID(); - $condition['show_field'] = [self::$questions[0]->getID()]; - $condition['id'] = $secondQuestionId; - $question->update($condition + self::$sectionData[0]['questions'][1]); - $question->updateConditions($condition); - - //Run the condition - $currentValues = [ - "formcreator_field_$firstQuestionId" => $condition['show_value'][0] . " and now for something completely different", - "formcreator_field_$secondQuestionId" => '', - ]; - $visibility = PluginFormcreatorFields::updateVisibility($currentValues); - - // Check the result - if ($condition['show_rule'] == 'hidden') { - $expected = false; - } else { - $expected = true; - } - $this->assertEquals($expected, $visibility["formcreator_field_$secondQuestionId"]); - - // Run the reversed condition - $currentValues = [ - "formcreator_field_$firstQuestionId" => $condition['show_value'][0], - "formcreator_field_$secondQuestionId" => '', - ]; - $visibility = PluginFormcreatorFields::updateVisibility($currentValues); - - // Check the result - $this->assertEquals(!$expected, $visibility["formcreator_field_$secondQuestionId"]); - - } - - /** - * Checks a question shows and hides when conditions applies, assuming the reference question is multi valued - * (ie: checkboxes field) - * @dataProvider conditionDataProvider - */ - public function testConditionForMultipleValue($condition) { - // Setup the condition - $question = self::$questions[1]; - $firstQuestionId = self::$questions[0]->getID(); - $secondQuestionId = $question->getID(); - $condition['show_field'] = [self::$questions[0]->getID()]; - $condition['id'] = $secondQuestionId; - $question->update($condition + $question->fields); - $question->updateConditions($condition); - - //Run the condition - $currentValues = [ - "formcreator_field_$firstQuestionId" => [$condition['show_value'][0] . " and now for something completely different"], - "formcreator_field_$secondQuestionId" => '', - ]; - $visibility = PluginFormcreatorFields::updateVisibility($currentValues); - - // Check the result - if ($condition['show_rule'] == 'hidden') { - $expected = false; - } else { - $expected = true; - } - $this->assertEquals($expected, $visibility["formcreator_field_$secondQuestionId"]); - - // Run the reversed condition - $currentValues = [ - "formcreator_field_$firstQuestionId" => [$condition['show_value'][0]], - "formcreator_field_$secondQuestionId" => '', - ]; - $visibility = PluginFormcreatorFields::updateVisibility($currentValues); - - // Check the result - $this->assertEquals(!$expected, $visibility["formcreator_field_$secondQuestionId"]); - } - - public function testConditionForManyQuestions() { - $form = new PluginFormcreatorForm(); - $form->add([ - 'entities_id' => 0, - 'name' => 'a form', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 0 - ]); - - $section = new PluginFormcreatorSection(); - $sectionId = $section->add([ - 'name' => 'section', - 'plugin_formcreator_forms_id' => $form->getID(), - ]); - $questions = []; - $questions[0] = new PluginFormcreatorQuestion(); - $questions[1] = new PluginFormcreatorQuestion(); - $questions[2] = new PluginFormcreatorQuestion(); - - // create questions - $firstQuestionId = $questions[0]->add([ - 'name' => 'text question 0', - 'fieldtype' => 'text', - 'plugin_formcreator_sections_id' => $sectionId, - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ] - ]); - $this->assertFalse($questions[0]->isNewItem(), json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); - - $secondQuestionId = $questions[1]->add([ - 'name' => 'text question 1', - 'fieldtype' => 'text', - 'plugin_formcreator_sections_id' => $sectionId, - 'show_rule' => 'hidden', - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ] - ]); - $this->assertFalse($questions[1]->isNewItem(), json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); - - $thirdQuestionId = $questions[2]->add([ - 'name' => 'text question 2', - 'fieldtype' => 'text', - 'plugin_formcreator_sections_id' => $sectionId, - 'show_rule' => 'hidden', - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ] - ]); - $this->assertFalse($questions[2]->isNewItem(), json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); - - // create conditions - $condition = new PluginFormcreatorQuestion_Condition(); - $condition->add([ - 'plugin_formcreator_questions_id' => $secondQuestionId, - 'show_field' => $firstQuestionId, - 'show_condition' => '==', - 'show_value' => 'a', - 'show_logic' => 'OR', - ]); - $condition->add([ - 'plugin_formcreator_questions_id' => $thirdQuestionId, - 'show_field' => $firstQuestionId, - 'show_condition' => '==', - 'show_value' => 'c', - 'show_logic' => 'OR', - ]); - $condition->add([ - 'plugin_formcreator_questions_id' => $thirdQuestionId, - 'show_field' => $secondQuestionId, - 'show_condition' => '==', - 'show_value' => 'c', - 'show_logic' => 'OR', - ]); - - // test the conditions engine - $currentValues = [ - "formcreator_field_$firstQuestionId" => '', - "formcreator_field_$secondQuestionId" => '', - "formcreator_field_$thirdQuestionId" => '', - ]; - $visibility = PluginFormcreatorFields::updateVisibility($currentValues); - $this->assertEquals(true, $visibility["formcreator_field_$firstQuestionId"]); - $this->assertEquals(false, $visibility["formcreator_field_$secondQuestionId"]); - $this->assertEquals(false, $visibility["formcreator_field_$thirdQuestionId"]); - - $currentValues = [ - "formcreator_field_$firstQuestionId" => 'a', - "formcreator_field_$secondQuestionId" => '', - "formcreator_field_$thirdQuestionId" => '', - ]; - $visibility = PluginFormcreatorFields::updateVisibility($currentValues); - $this->assertEquals(true, $visibility["formcreator_field_$firstQuestionId"]); - $this->assertEquals(true, $visibility["formcreator_field_$secondQuestionId"]); - $this->assertEquals(false, $visibility["formcreator_field_$thirdQuestionId"]); - - $currentValues = [ - "formcreator_field_$firstQuestionId" => 'a', - "formcreator_field_$secondQuestionId" => 'c', - "formcreator_field_$thirdQuestionId" => '', - ]; - $visibility = PluginFormcreatorFields::updateVisibility($currentValues); - $this->assertEquals(true, $visibility["formcreator_field_$firstQuestionId"]); - $this->assertEquals(true, $visibility["formcreator_field_$secondQuestionId"]); - $this->assertEquals(true, $visibility["formcreator_field_$thirdQuestionId"]); - - $currentValues = [ - "formcreator_field_$firstQuestionId" => '', - "formcreator_field_$secondQuestionId" => 'c', - "formcreator_field_$thirdQuestionId" => '', - ]; - $visibility = PluginFormcreatorFields::updateVisibility($currentValues); - $this->assertEquals(true, $visibility["formcreator_field_$firstQuestionId"]); - $this->assertEquals(false, $visibility["formcreator_field_$secondQuestionId"]); - $this->assertEquals(true, $visibility["formcreator_field_$thirdQuestionId"]); - } -} diff --git a/tests/0010_Integration/UrgencyTest.php b/tests/0010_Integration/UrgencyTest.php deleted file mode 100644 index 048e2656c..000000000 --- a/tests/0010_Integration/UrgencyTest.php +++ /dev/null @@ -1,249 +0,0 @@ -. - * --------------------------------------------------------------------- - * @author Thierry Bugier - * @author Jérémy Moreau - * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt - * @link https://github.com/pluginsGLPI/formcreator/ - * @link https://pluginsglpi.github.io/formcreator/ - * @link http://plugins.glpi-project.org/#/plugin/formcreator - * --------------------------------------------------------------------- - */ - -class UrgencyTest extends SuperAdminTestCase -{ - - protected $formData; - protected $sectionData; - protected $targetTicketData; - - public function setUp() { - parent::setUp(); - - $this->formData = [ - 'entities_id' => $_SESSION['glpiactive_entity'], - 'name' => 'a form', - 'description' => 'form description', - 'content' => 'a content', - 'is_active' => 1, - 'validation_required' => 0 - ]; - - $this->sectionData = [ - [ - 'name' => 'a section', - 'questions' => [ - [ - 'name' => 'text question', - 'fieldtype' => 'text', - '_parameters' => [ - 'text' => [ - 'range' => [ - 'range_min' => '', - 'range_max' => '', - ], - 'regex' => [ - 'regex' => '' - ] - ] - ], - ], - [ - 'name' => 'custom urgency', - 'fieldtype' => 'urgency', - ], - ], - ], - ]; - - $this->targetTicketData = [ - [ - 'name' => 'target 1', - 'itemtype' => 'PluginFormcreatorTargetTicket', - 'urgency_rule' => 'answer', - 'urgency_question' => 'custom urgency', - 'expected' => 5 - ], - [ - 'name' => 'target 2', - 'itemtype' => 'PluginFormcreatorTargetTicket', - 'urgency_rule' => 'none', - 'urgency_question' => '', - 'expected' => 3 - ] - ]; - } - - public function testInitCreateForm() { - $form = new PluginFormcreatorForm(); - $formId = $form->add($this->formData); - $this->assertFalse($form->isNewItem()); - - foreach ($this->sectionData as $sectionData) { - // Keep questions data set apart from sections data - $questionsData = $sectionData['questions']; - unset($sectionData['questions']); - - // Create section - $sectionData['plugin_formcreator_forms_id'] = $form->getID(); - $section = new PluginFormcreatorSection(); - $section->add($sectionData); - $this->assertFalse($section->isNewItem()); - $sectionId = $section->getID(); - foreach ($questionsData as $questionData) { - // Create question - $questionData ['plugin_formcreator_sections_id'] = $section->getID(); - $question = new PluginFormcreatorQuestion(); - $question->add($questionData); - $this->assertFalse($question->isNewItem(), $_SESSION['MESSAGE_AFTER_REDIRECT']); - - $questionData['id'] = $question->getID(); - if (isset($questionData['show_rule']) && $questionData['show_rule'] != 'always') { - $showFieldName = $questionData['show_field']; - $showfield = new PluginFormcreatorQuestion(); - $showfield->getFromDBByCrit([ - 'AND' => [ - 'plugin_formcreator_sections_id' => $sectionId, - 'name' => $showFieldName - ] - ]); - $question->updateConditions($questionData); - } - $question->updateParameters($questionData); - } - } - - return $form; - } - - /** - * @depends testInitCreateForm - * @param PluginFormcreatorForm $urgencyQuestions - */ - public function testInitCreateTargetTicket(PluginFormcreatorForm $form) { - $urgencyQuestions = []; - $formId = $form->getID(); - foreach ($this->targetTicketData as $targetData) { - // Create target - $targetData['plugin_formcreator_forms_id'] = $formId; - $target = new PluginFormcreatorTarget(); - $target->add($targetData); - $this->assertFalse($target->isNewItem()); - - // Create target ticket - $itemtype = $target->getField('itemtype'); - $targetTicket = new $itemtype(); - $targetTicket->getFromDB($target->getField('items_id')); - $this->assertFalse($targetTicket->isNewItem()); - - // Find urgency question - if (!empty($targetData['urgency_question'])) { - $questionName = $targetData['urgency_question']; - $question = new PluginFormcreatorQuestion(); - $table_section = PluginFormcreatorSection::getTable(); - $table_form = PluginFormcreatorForm::getTable(); - $table_question = PluginFormcreatorQuestion::getTable(); - if (!method_exists($question, 'getFromDBByRequest')) { - $question->getFromDBByQuery("LEFT JOIN `$table_section` `s` ON (`s`.`id` = `plugin_formcreator_sections_id`) - LEFT JOIN `$table_form` `f` ON (`f`.`id` = `s`.`plugin_formcreator_forms_id`) - WHERE `$table_question`.`name` = '$questionName' AND `plugin_formcreator_forms_id` = '$formId'"); - } else { - $question->getFromDBByRequest([ - 'LEFT JOIN' => [ - $table_section => [ - 'FKEY' => [ - $table_section => 'id', - $table_question => 'plugin_formcreator_sections_id' - ] - ], - $table_form => [ - 'FKEY' => [ - $table_form => 'id', - $table_section => 'plugin_formcreator_forms_id' - ] - ] - ], - 'WHERE' => [ - 'AND' => [ - $table_question . '.name' => $questionName, - 'plugin_formcreator_forms_id' => $formId, - ] - ] - ]); - } - $this->assertFalse($question->isNewItem()); - $questionId = $question->getID(); - $urgencyQuestions[] = [ - 'question' => $question, - 'targetTicket' => $targetTicket, - 'expected' => $targetData['expected'] - ]; - } else { - $urgencyQuestions[] = [ - 'question' => null, - 'targetTicket' => $targetTicket, - 'expected' => $targetData['expected'] - ]; - } - - // Update target ticket - $targetTicketData = $targetTicket->fields; - $targetTicketData['id'] = $targetTicket->getID(); - $targetTicketData['title'] = $targetTicketData['name']; - $targetTicketData['urgency_rule'] = $targetData['urgency_rule']; - $targetTicketData['_urgency_question'] = $questionId; - $this->assertTrue($targetTicket->update($targetTicketData)); - } - - return $urgencyQuestions; - } - - /** - * @depends testInitCreateForm - * @depends testInitCreateTargetTicket - * @param PluginFormcreatorForm $form - * @param array $urgencyQuestions - */ - public function testSendForm(PluginFormcreatorForm $form, $urgencyQuestions) { - $saveFormData = []; - foreach ($urgencyQuestions as $question) { - if ($question['question'] !== null) { - $saveFormData['formcreator_field_' . $question['question']->getID()] = $question['expected']; - } - } - $saveFormData['formcreator_form'] = $form->getID(); - $form->saveForm($saveFormData); - - // Check urgency for each target ticket - foreach ($urgencyQuestions as $question) { - $targetTicket = $question['targetTicket']; - $targetName = $targetTicket->getField('name'); - $ticket = new Ticket(); - $ticket->getFromDBByCrit(['name' => $targetName]); - $this->assertFalse($ticket->isNewItem()); - $this->assertEquals($question['expected'], $ticket->getField('urgency')); - } - } - -} diff --git a/tests/suite-unit/PluginFormcreatorDateField.php b/tests/suite-unit/PluginFormcreatorDateField.php index 1e8fdf05e..edf78b888 100644 --- a/tests/suite-unit/PluginFormcreatorDateField.php +++ b/tests/suite-unit/PluginFormcreatorDateField.php @@ -12,7 +12,7 @@ public function providerGetValue() { 'name' => 'question', 'required' => '0', 'default_values' => '', - 'values' => "2018-08-16", + 'values' => "", 'order' => '1', 'show_rule' => 'always', '_parameters' => [ @@ -33,7 +33,7 @@ public function providerGetValue() { 'fieldtype' => 'date', 'name' => 'question', 'required' => '0', - 'default_values' => '', + 'default_values' => '2018-08-16', 'values' => "", 'order' => '1', 'show_rule' => 'always', @@ -47,7 +47,7 @@ public function providerGetValue() { ], ], 'data' => null, - 'expectedValue' => '', + 'expectedValue' => '2018-08-16', 'expectedIsValid' => true ], [ @@ -109,10 +109,6 @@ public function testGetValue($fields, $data, $expectedValue, $expectedValidity) $this->variable($value)->isEqualTo($expectedValue); } - public function providerIsValid() { - return $this->providerGetValue(); - } - public function providerGetAnswer() { return $this->providerGetValue(); } @@ -128,6 +124,10 @@ public function testGetAnswer($fields, $data, $expectedValue, $expectedValidity) $this->variable($output)->isEqualTo($expected); } + public function providerIsValid() { + return $this->providerGetValue(); + } + /** * @dataProvider providerIsValid */ diff --git a/tests/suite-unit/PluginFormcreatorDatetimeField.php b/tests/suite-unit/PluginFormcreatorDatetimeField.php index 87d347a8e..09f52e6b9 100644 --- a/tests/suite-unit/PluginFormcreatorDatetimeField.php +++ b/tests/suite-unit/PluginFormcreatorDatetimeField.php @@ -3,4 +3,148 @@ use GlpiPlugin\Formcreator\Tests\CommonTestCase; class PluginFormcreatorDatetimeField extends CommonTestCase { + + public function providerGetValue() { + $dataset = [ + [ + 'fields' => [ + 'fieldtype' => 'datetime', + 'name' => 'question', + 'required' => '0', + 'default_values' => '', + 'values' => "", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => null, + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'datetime', + 'name' => 'question', + 'required' => '0', + 'default_values' => '2018-08-16 08:12:34', + 'values' => "", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => '2018-08-16 08:12:34', + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'datetime', + 'name' => 'question', + 'required' => '1', + 'default_values' => '', + 'values' => "", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => null, + 'expectedIsValid' => false + ], + [ + 'fields' => [ + 'fieldtype' => 'datetime', + 'name' => 'question', + 'required' => '1', + 'default_values' => '2018-08-16 08:12:34', + 'values' => "", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => '2018-08-16 08:12:34', + 'expectedIsValid' => true + ], + ]; + + return $dataset; + } + + /** + * @dataProvider providerGetValue + */ + public function testGetValue($fields, $data, $expectedValue, $expectedValidity) { + $instance = $this->newTestedInstance($fields, $data); + + $value = $instance->getValue(); + $this->variable($value)->isEqualTo($expectedValue); + } + + public function providerGetAnswer() { + return $this->providerGetValue(); + } + + /** + * @dataProvider providerGetAnswer + * @engine inline + */ + public function testGetAnswer($fields, $data, $expectedValue, $expectedValidity) { + $instance = $this->newTestedInstance($fields, $data); + + $expected = \Html::convDateTime($fields['default_values']); + // FIXME: this shows an inconsistency with this field type + if ($expected == ' ') { + $expected = null; + } + $output = $instance->getAnswer(); + $this->variable($output)->isEqualTo($expected); + } + + public function providerIsValid() { + return $this->providerGetValue(); + } + + /** + * @dataProvider providerIsValid + */ + public function testIsValid($fields, $data, $expectedValue, $expectedValidity) { + $instance = $this->newTestedInstance($fields, $data); + + $isValid = $instance->isValid($fields['default_values']); + $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); + } + + public function testGetName() { + $output = \PluginFormcreatorDatetimeField::getName(); + $this->string($output)->isEqualTo('Date & time'); + } } \ No newline at end of file From ed25ca1de1372262a116eff1a469cf4664868fcf Mon Sep 17 00:00:00 2001 From: btry Date: Wed, 29 Aug 2018 17:45:28 +0200 Subject: [PATCH 045/192] docs: update/add headers Signed-off-by: btry --- inc/questiondependency.class.php | 27 +++++++++++ inc/questionparameter.class.php | 32 +++++++++++-- inc/questionrange.class.php | 27 +++++++++++ inc/questionregex.class.php | 27 +++++++++++ install/update_2.6_2.7.php | 28 +++++++++++- tests/suite-install/Config.php | 45 ++++++++++--------- .../PluginFormcreatorForm.php | 30 +++++++++++++ .../PluginFormcreatorForm_Answer.php | 30 +++++++++++++ .../PluginFormcreatorForm_Validator.php | 30 +++++++++++++ .../PluginFormcreatorQuestion.php | 30 +++++++++++++ .../PluginFormcreatorSection.php | 30 +++++++++++++ .../PluginFormcreatorTargetChange.php | 31 +++++++++++++ .../PluginFormcreatorTargetTicket.php | 30 +++++++++++++ tests/suite-uninstall/Config.php | 43 +++++++++--------- .../PluginFormcreatorActorField.php | 30 +++++++++++++ .../PluginFormcreatorCheckboxesField.php | 30 +++++++++++++ tests/suite-unit/PluginFormcreatorCommon.php | 30 +++++++++++++ .../suite-unit/PluginFormcreatorDateField.php | 30 +++++++++++++ .../PluginFormcreatorDatetimeField.php | 30 +++++++++++++ tests/suite-unit/PluginFormcreatorFields.php | 30 +++++++++++++ tests/suite-unit/PluginFormcreatorForm.php | 30 +++++++++++++ .../PluginFormcreatorMultiSelectField.php | 30 +++++++++++++ .../suite-unit/PluginFormcreatorQuestion.php | 30 +++++++++++++ .../PluginFormcreatorRadiosField.php | 30 +++++++++++++ tests/suite-unit/PluginFormcreatorSection.php | 30 +++++++++++++ .../PluginFormcreatorSelectField.php | 31 +++++++++++++ tests/suite-unit/PluginFormcreatorTarget.php | 31 +++++++++++++ .../PluginFormcreatorTargetTicket.php | 31 +++++++++++++ .../suite-unit/PluginFormcreatorTextField.php | 30 +++++++++++++ 29 files changed, 844 insertions(+), 49 deletions(-) diff --git a/inc/questiondependency.class.php b/inc/questiondependency.class.php index 51d4dcfd0..6c01dc1a2 100644 --- a/inc/questiondependency.class.php +++ b/inc/questiondependency.class.php @@ -1,6 +1,33 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- */ /** diff --git a/inc/questionparameter.class.php b/inc/questionparameter.class.php index c3d0abf67..7af700523 100644 --- a/inc/questionparameter.class.php +++ b/inc/questionparameter.class.php @@ -1,9 +1,33 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- */ abstract class PluginFormcreatorQuestionParameter extends CommonDBChild diff --git a/inc/questionrange.class.php b/inc/questionrange.class.php index aa64f5d2c..846941fd2 100644 --- a/inc/questionrange.class.php +++ b/inc/questionrange.class.php @@ -1,6 +1,33 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- */ /** diff --git a/inc/questionregex.class.php b/inc/questionregex.class.php index dd009867d..28ccadb42 100644 --- a/inc/questionregex.class.php +++ b/inc/questionregex.class.php @@ -1,6 +1,33 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- */ /** diff --git a/install/update_2.6_2.7.php b/install/update_2.6_2.7.php index a558f96a8..6d53e19ca 100644 --- a/install/update_2.6_2.7.php +++ b/install/update_2.6_2.7.php @@ -1,9 +1,33 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- */ function plugin_formcreator_update_2_7(Migration $migration) { global $DB; diff --git a/tests/suite-install/Config.php b/tests/suite-install/Config.php index f6e00a538..776d8b401 100644 --- a/tests/suite-install/Config.php +++ b/tests/suite-install/Config.php @@ -1,32 +1,33 @@ . + * --------------------------------------------------------------------- + * @author Thierry Bugier + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- */ namespace tests\units; diff --git a/tests/suite-integration/PluginFormcreatorForm.php b/tests/suite-integration/PluginFormcreatorForm.php index 2b9bd6142..f9d94ab3a 100644 --- a/tests/suite-integration/PluginFormcreatorForm.php +++ b/tests/suite-integration/PluginFormcreatorForm.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-integration/PluginFormcreatorForm_Answer.php b/tests/suite-integration/PluginFormcreatorForm_Answer.php index 5e333cd4e..9d75e2fb5 100644 --- a/tests/suite-integration/PluginFormcreatorForm_Answer.php +++ b/tests/suite-integration/PluginFormcreatorForm_Answer.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-integration/PluginFormcreatorForm_Validator.php b/tests/suite-integration/PluginFormcreatorForm_Validator.php index be14952cb..aeb36bab1 100644 --- a/tests/suite-integration/PluginFormcreatorForm_Validator.php +++ b/tests/suite-integration/PluginFormcreatorForm_Validator.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-integration/PluginFormcreatorQuestion.php b/tests/suite-integration/PluginFormcreatorQuestion.php index f479b8b8a..7c2b62aa9 100644 --- a/tests/suite-integration/PluginFormcreatorQuestion.php +++ b/tests/suite-integration/PluginFormcreatorQuestion.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-integration/PluginFormcreatorSection.php b/tests/suite-integration/PluginFormcreatorSection.php index 421694bd0..9abb7b27b 100644 --- a/tests/suite-integration/PluginFormcreatorSection.php +++ b/tests/suite-integration/PluginFormcreatorSection.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-integration/PluginFormcreatorTargetChange.php b/tests/suite-integration/PluginFormcreatorTargetChange.php index 60355f31f..acce28987 100644 --- a/tests/suite-integration/PluginFormcreatorTargetChange.php +++ b/tests/suite-integration/PluginFormcreatorTargetChange.php @@ -1,4 +1,35 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-integration/PluginFormcreatorTargetTicket.php b/tests/suite-integration/PluginFormcreatorTargetTicket.php index ae4865746..9537de755 100644 --- a/tests/suite-integration/PluginFormcreatorTargetTicket.php +++ b/tests/suite-integration/PluginFormcreatorTargetTicket.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-uninstall/Config.php b/tests/suite-uninstall/Config.php index 9f0f57f7a..239911b3e 100644 --- a/tests/suite-uninstall/Config.php +++ b/tests/suite-uninstall/Config.php @@ -1,32 +1,33 @@ . + * --------------------------------------------------------------------- * @author Thierry Bugier - * @copyright Copyright © 2018 Teclib - * @license AGPLv3+ http://www.gnu.org/licenses/agpl.txt - * @link https://github.com/flyve-mdm/glpi-plugin - * @link https://flyve-mdm.com/ - * ------------------------------------------------------------------------------ + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- */ namespace tests\units; diff --git a/tests/suite-unit/PluginFormcreatorActorField.php b/tests/suite-unit/PluginFormcreatorActorField.php index 72d8b7361..a8a898a91 100644 --- a/tests/suite-unit/PluginFormcreatorActorField.php +++ b/tests/suite-unit/PluginFormcreatorActorField.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-unit/PluginFormcreatorCheckboxesField.php b/tests/suite-unit/PluginFormcreatorCheckboxesField.php index 95e6a6842..cb51c2712 100644 --- a/tests/suite-unit/PluginFormcreatorCheckboxesField.php +++ b/tests/suite-unit/PluginFormcreatorCheckboxesField.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-unit/PluginFormcreatorCommon.php b/tests/suite-unit/PluginFormcreatorCommon.php index 182261b94..4e7174e66 100644 --- a/tests/suite-unit/PluginFormcreatorCommon.php +++ b/tests/suite-unit/PluginFormcreatorCommon.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-unit/PluginFormcreatorDateField.php b/tests/suite-unit/PluginFormcreatorDateField.php index edf78b888..c5aa75f42 100644 --- a/tests/suite-unit/PluginFormcreatorDateField.php +++ b/tests/suite-unit/PluginFormcreatorDateField.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-unit/PluginFormcreatorDatetimeField.php b/tests/suite-unit/PluginFormcreatorDatetimeField.php index 09f52e6b9..85f1d65a8 100644 --- a/tests/suite-unit/PluginFormcreatorDatetimeField.php +++ b/tests/suite-unit/PluginFormcreatorDatetimeField.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-unit/PluginFormcreatorFields.php b/tests/suite-unit/PluginFormcreatorFields.php index ba6dc1983..09d18ab39 100644 --- a/tests/suite-unit/PluginFormcreatorFields.php +++ b/tests/suite-unit/PluginFormcreatorFields.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-unit/PluginFormcreatorForm.php b/tests/suite-unit/PluginFormcreatorForm.php index 64d2df18e..911a3c957 100644 --- a/tests/suite-unit/PluginFormcreatorForm.php +++ b/tests/suite-unit/PluginFormcreatorForm.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-unit/PluginFormcreatorMultiSelectField.php b/tests/suite-unit/PluginFormcreatorMultiSelectField.php index 90caed5c9..0dc25a35f 100644 --- a/tests/suite-unit/PluginFormcreatorMultiSelectField.php +++ b/tests/suite-unit/PluginFormcreatorMultiSelectField.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-unit/PluginFormcreatorQuestion.php b/tests/suite-unit/PluginFormcreatorQuestion.php index ac2af3d9e..c41531023 100644 --- a/tests/suite-unit/PluginFormcreatorQuestion.php +++ b/tests/suite-unit/PluginFormcreatorQuestion.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-unit/PluginFormcreatorRadiosField.php b/tests/suite-unit/PluginFormcreatorRadiosField.php index c27ca6698..3eb660eb7 100644 --- a/tests/suite-unit/PluginFormcreatorRadiosField.php +++ b/tests/suite-unit/PluginFormcreatorRadiosField.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-unit/PluginFormcreatorSection.php b/tests/suite-unit/PluginFormcreatorSection.php index 90a6eb6f2..442bb4b13 100644 --- a/tests/suite-unit/PluginFormcreatorSection.php +++ b/tests/suite-unit/PluginFormcreatorSection.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-unit/PluginFormcreatorSelectField.php b/tests/suite-unit/PluginFormcreatorSelectField.php index cf884ffe6..e4fc5f12e 100644 --- a/tests/suite-unit/PluginFormcreatorSelectField.php +++ b/tests/suite-unit/PluginFormcreatorSelectField.php @@ -1,4 +1,35 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-unit/PluginFormcreatorTarget.php b/tests/suite-unit/PluginFormcreatorTarget.php index f0652fd07..b8c4968d7 100644 --- a/tests/suite-unit/PluginFormcreatorTarget.php +++ b/tests/suite-unit/PluginFormcreatorTarget.php @@ -1,4 +1,35 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-unit/PluginFormcreatorTargetTicket.php b/tests/suite-unit/PluginFormcreatorTargetTicket.php index e3de432c8..aad8b4b2c 100644 --- a/tests/suite-unit/PluginFormcreatorTargetTicket.php +++ b/tests/suite-unit/PluginFormcreatorTargetTicket.php @@ -1,4 +1,35 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; diff --git a/tests/suite-unit/PluginFormcreatorTextField.php b/tests/suite-unit/PluginFormcreatorTextField.php index cb5c5dfe5..de9772557 100644 --- a/tests/suite-unit/PluginFormcreatorTextField.php +++ b/tests/suite-unit/PluginFormcreatorTextField.php @@ -1,4 +1,34 @@ . + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; From 51b222aecdad7c461d143ca2296e529f5b5c3d4a Mon Sep 17 00:00:00 2001 From: btry Date: Sat, 1 Sep 2018 00:05:50 +0200 Subject: [PATCH 046/192] docs: fix license annotation in headers Signed-off-by: btry --- RoboFile.php | 2 +- RoboFilePlugin.php | 2 +- ajax/dropdown_values.php | 2 +- ajax/homepage_forms.php | 2 +- ajax/homepage_link.php | 2 +- ajax/homepage_wizard.php | 2 +- ajax/ldap_filter.php | 2 +- ajax/question.php | 2 +- ajax/question_condition.php | 2 +- ajax/section.php | 2 +- ajax/showfields.php | 2 +- ajax/target.php | 2 +- css/print_form.css | 2 +- css/print_form_answer.css | 2 +- css/styles.css | 2 +- front/category.form.php | 2 +- front/category.php | 2 +- front/entityconfig.form.php | 2 +- front/export.php | 2 +- front/form.form.php | 2 +- front/form.php | 2 +- front/form_answer.form.php | 2 +- front/form_answer.php | 2 +- front/form_profile.form.php | 2 +- front/formdisplay.php | 2 +- front/formlist.php | 2 +- front/issue.form.php | 2 +- front/issue.php | 2 +- front/item_targetticket.form.php | 2 +- front/knowbaseitem.form.php | 2 +- front/question.form.php | 2 +- front/reservation.form.php | 2 +- front/reservation.php | 2 +- front/reservationitem.php | 2 +- front/section.form.php | 2 +- front/target.form.php | 2 +- front/targetchange.form.php | 2 +- front/targetticket.form.php | 2 +- front/wizard.php | 2 +- front/wizardfeeds.php | 2 +- hook.php | 2 +- inc/answer.class.php | 2 +- inc/category.class.php | 2 +- inc/common.class.php | 2 +- inc/composite.class.php | 2 +- inc/entityconfig.class.php | 2 +- inc/field.class.php | 2 +- inc/fieldinterface.class.php | 2 +- inc/fields.class.php | 2 +- inc/fields/actorfield.class.php | 2 +- inc/fields/checkboxesfield.class.php | 2 +- inc/fields/datefield.class.php | 2 +- inc/fields/datetimefield.class.php | 2 +- inc/fields/descriptionfield.class.php | 2 +- inc/fields/dropdownfield.class.php | 2 +- inc/fields/emailfield.class.php | 2 +- inc/fields/filefield.class.php | 2 +- inc/fields/floatfield.class.php | 2 +- inc/fields/glpiselectfield.class.php | 2 +- inc/fields/hiddenfield.class.php | 2 +- inc/fields/integerfield.class.php | 2 +- inc/fields/ipfield.class.php | 2 +- inc/fields/ldapselectfield.class.php | 2 +- inc/fields/multiselectfield.class.php | 2 +- inc/fields/radiosfield.class.php | 2 +- inc/fields/selectfield.class.php | 2 +- inc/fields/tagfield.class.php | 2 +- inc/fields/textareafield.class.php | 2 +- inc/fields/textfield.class.php | 2 +- inc/fields/urgencyfield.class.php | 2 +- inc/form.class.php | 2 +- inc/form_answer.class.php | 2 +- inc/form_profile.class.php | 2 +- inc/form_validator.class.php | 2 +- inc/formlist.class.php | 2 +- inc/issue.class.php | 2 +- inc/item_targetticket.class.php | 2 +- inc/notificationtargetform_answer.class.php | 2 +- inc/question.class.php | 2 +- inc/question_condition.class.php | 2 +- inc/questiondependency.class.php | 2 +- inc/questionparameter.class.php | 2 +- inc/questionrange.class.php | 2 +- inc/questionregex.class.php | 2 +- inc/section.class.php | 2 +- inc/target.class.php | 2 +- inc/target_actor.class.php | 2 +- inc/targetbase.class.php | 2 +- inc/targetchange.class.php | 2 +- inc/targetchange_actor.class.php | 2 +- inc/targetticket.class.php | 2 +- inc/targetticket_actor.class.php | 2 +- inc/wizard.class.php | 2 +- index.php | 2 +- install/install.php | 2 +- install/update_0.0_2.5.php | 2 +- install/update_2.5_2.6.php | 2 +- install/update_2.6.2_2.6.3.php | 2 +- install/update_2.6_2.6.1.php | 2 +- install/update_2.6_2.7.php | 2 +- js/scripts.js.php | 2 +- scripts/cliinstall.php | 2 +- setup.php | 2 +- tests/suite-install/Config.php | 2 +- tests/suite-integration/PluginFormcreatorForm.php | 2 +- tests/suite-integration/PluginFormcreatorForm_Answer.php | 2 +- .../suite-integration/PluginFormcreatorForm_Validator.php | 2 +- tests/suite-integration/PluginFormcreatorQuestion.php | 2 +- tests/suite-integration/PluginFormcreatorSection.php | 2 +- tests/suite-integration/PluginFormcreatorTargetChange.php | 2 +- tests/suite-integration/PluginFormcreatorTargetTicket.php | 2 +- tests/suite-uninstall/Config.php | 2 +- tests/suite-unit/PluginFormcreatorActorField.php | 2 +- tests/suite-unit/PluginFormcreatorCheckboxesField.php | 2 +- tests/suite-unit/PluginFormcreatorCommon.php | 2 +- tests/suite-unit/PluginFormcreatorDateField.php | 2 +- tests/suite-unit/PluginFormcreatorDatetimeField.php | 2 +- tests/suite-unit/PluginFormcreatorFields.php | 2 +- tests/suite-unit/PluginFormcreatorFloatField.php | 2 +- tests/suite-unit/PluginFormcreatorForm.php | 2 +- tests/suite-unit/PluginFormcreatorIntegerField.php | 2 +- tests/suite-unit/PluginFormcreatorMultiSelectField.php | 2 +- tests/suite-unit/PluginFormcreatorQuestion.php | 2 +- tests/suite-unit/PluginFormcreatorQuestion_Condition.php | 2 +- tests/suite-unit/PluginFormcreatorRadiosField.php | 2 +- tests/suite-unit/PluginFormcreatorSection.php | 2 +- tests/suite-unit/PluginFormcreatorSelectField.php | 2 +- tests/suite-unit/PluginFormcreatorTarget.php | 2 +- tests/suite-unit/PluginFormcreatorTargetTicket.php | 2 +- tests/suite-unit/PluginFormcreatorTextField.php | 2 +- tools/HEADER | 8 ++++---- 131 files changed, 134 insertions(+), 134 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index f53b1d389..70cb529b7 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/RoboFilePlugin.php b/RoboFilePlugin.php index d80e32ad5..09143cccc 100644 --- a/RoboFilePlugin.php +++ b/RoboFilePlugin.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/ajax/dropdown_values.php b/ajax/dropdown_values.php index 2b98cf5fd..9c5fe2407 100644 --- a/ajax/dropdown_values.php +++ b/ajax/dropdown_values.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/ajax/homepage_forms.php b/ajax/homepage_forms.php index 281f70c4e..9148aa2a1 100644 --- a/ajax/homepage_forms.php +++ b/ajax/homepage_forms.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/ajax/homepage_link.php b/ajax/homepage_link.php index 549addcb0..577cdfd39 100644 --- a/ajax/homepage_link.php +++ b/ajax/homepage_link.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/ajax/homepage_wizard.php b/ajax/homepage_wizard.php index 91c1baf1f..96378e048 100644 --- a/ajax/homepage_wizard.php +++ b/ajax/homepage_wizard.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/ajax/ldap_filter.php b/ajax/ldap_filter.php index 717ef0e76..9e9a0c90c 100644 --- a/ajax/ldap_filter.php +++ b/ajax/ldap_filter.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/ajax/question.php b/ajax/question.php index fc0c96e93..977172834 100644 --- a/ajax/question.php +++ b/ajax/question.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/ajax/question_condition.php b/ajax/question_condition.php index 4d30cdeef..73864c64a 100644 --- a/ajax/question_condition.php +++ b/ajax/question_condition.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/ajax/section.php b/ajax/section.php index db204e0b0..d276d1b77 100644 --- a/ajax/section.php +++ b/ajax/section.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/ajax/showfields.php b/ajax/showfields.php index 4d4661a5d..a962014de 100644 --- a/ajax/showfields.php +++ b/ajax/showfields.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/ajax/target.php b/ajax/target.php index c1d55d8b9..9be40bbc0 100644 --- a/ajax/target.php +++ b/ajax/target.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/css/print_form.css b/css/print_form.css index 6a0aa6804..dc5ed0ed7 100644 --- a/css/print_form.css +++ b/css/print_form.css @@ -23,7 +23,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/css/print_form_answer.css b/css/print_form_answer.css index 0bb83ead4..5e3092d3f 100644 --- a/css/print_form_answer.css +++ b/css/print_form_answer.css @@ -23,7 +23,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/css/styles.css b/css/styles.css index 87a318b09..473bb77bb 100644 --- a/css/styles.css +++ b/css/styles.css @@ -23,7 +23,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/category.form.php b/front/category.form.php index 6f9423e9c..d86366f92 100644 --- a/front/category.form.php +++ b/front/category.form.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/category.php b/front/category.php index ea0ba2192..e3c92952c 100644 --- a/front/category.php +++ b/front/category.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/entityconfig.form.php b/front/entityconfig.form.php index 2a1564d1e..12bfc15cd 100644 --- a/front/entityconfig.form.php +++ b/front/entityconfig.form.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/export.php b/front/export.php index 9ed21396b..35c6f43a0 100644 --- a/front/export.php +++ b/front/export.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/form.form.php b/front/form.form.php index b3b2ea42e..cc2811e50 100644 --- a/front/form.form.php +++ b/front/form.form.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/form.php b/front/form.php index 18e0d6179..6bb9bb117 100644 --- a/front/form.php +++ b/front/form.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/form_answer.form.php b/front/form_answer.form.php index 83413f539..f34ebd91f 100644 --- a/front/form_answer.form.php +++ b/front/form_answer.form.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/form_answer.php b/front/form_answer.php index c8696bcb2..1bd58e3bb 100644 --- a/front/form_answer.php +++ b/front/form_answer.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/form_profile.form.php b/front/form_profile.form.php index da5708639..0d9afad33 100644 --- a/front/form_profile.form.php +++ b/front/form_profile.form.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/formdisplay.php b/front/formdisplay.php index 0bc704fd2..f3b5aae8c 100644 --- a/front/formdisplay.php +++ b/front/formdisplay.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/formlist.php b/front/formlist.php index 1a79bf35c..cfbb3f5e6 100644 --- a/front/formlist.php +++ b/front/formlist.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/issue.form.php b/front/issue.form.php index 9a874fbe5..41c127379 100644 --- a/front/issue.form.php +++ b/front/issue.form.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/issue.php b/front/issue.php index 4267b73a2..f4bb2b24d 100644 --- a/front/issue.php +++ b/front/issue.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/item_targetticket.form.php b/front/item_targetticket.form.php index 65a0ded13..0cb8bf6b7 100644 --- a/front/item_targetticket.form.php +++ b/front/item_targetticket.form.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/knowbaseitem.form.php b/front/knowbaseitem.form.php index 8f3ae1eee..b32eea27d 100644 --- a/front/knowbaseitem.form.php +++ b/front/knowbaseitem.form.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/question.form.php b/front/question.form.php index bd0b02e75..43a545832 100644 --- a/front/question.form.php +++ b/front/question.form.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/reservation.form.php b/front/reservation.form.php index 992150974..5b953b2b2 100644 --- a/front/reservation.form.php +++ b/front/reservation.form.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/reservation.php b/front/reservation.php index 791258f18..069d77a6c 100644 --- a/front/reservation.php +++ b/front/reservation.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/reservationitem.php b/front/reservationitem.php index df51737d9..ee2e59d5a 100644 --- a/front/reservationitem.php +++ b/front/reservationitem.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/section.form.php b/front/section.form.php index a28fc34f9..4e88e24fd 100644 --- a/front/section.form.php +++ b/front/section.form.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/target.form.php b/front/target.form.php index a770b1aad..2a9df9e53 100644 --- a/front/target.form.php +++ b/front/target.form.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/targetchange.form.php b/front/targetchange.form.php index 0e855c2b7..bbce1218f 100644 --- a/front/targetchange.form.php +++ b/front/targetchange.form.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/targetticket.form.php b/front/targetticket.form.php index bdd1f9be8..7089e374f 100644 --- a/front/targetticket.form.php +++ b/front/targetticket.form.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/wizard.php b/front/wizard.php index 0ae3e4e4d..397243113 100644 --- a/front/wizard.php +++ b/front/wizard.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/front/wizardfeeds.php b/front/wizardfeeds.php index 579ddde63..53118d67b 100644 --- a/front/wizardfeeds.php +++ b/front/wizardfeeds.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/hook.php b/hook.php index d463ad7f3..b7e7647a5 100644 --- a/hook.php +++ b/hook.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/answer.class.php b/inc/answer.class.php index 8f8367168..e171474ff 100644 --- a/inc/answer.class.php +++ b/inc/answer.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/category.class.php b/inc/category.class.php index bce7b1ebf..0c7250abb 100644 --- a/inc/category.class.php +++ b/inc/category.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/common.class.php b/inc/common.class.php index 1a3052fea..2ee72d77f 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/composite.class.php b/inc/composite.class.php index a975ace93..36eb703bc 100644 --- a/inc/composite.class.php +++ b/inc/composite.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/entityconfig.class.php b/inc/entityconfig.class.php index 8e71af292..fff56f94e 100644 --- a/inc/entityconfig.class.php +++ b/inc/entityconfig.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/field.class.php b/inc/field.class.php index 71b1f459e..798110383 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fieldinterface.class.php b/inc/fieldinterface.class.php index 666cc641b..95cea895f 100644 --- a/inc/fieldinterface.class.php +++ b/inc/fieldinterface.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields.class.php b/inc/fields.class.php index d10bb291a..81da16e0e 100644 --- a/inc/fields.class.php +++ b/inc/fields.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/actorfield.class.php b/inc/fields/actorfield.class.php index d7b951f28..27f179866 100644 --- a/inc/fields/actorfield.class.php +++ b/inc/fields/actorfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index f527b24a7..9c9a988d2 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/datefield.class.php b/inc/fields/datefield.class.php index a64250703..b0314aa12 100644 --- a/inc/fields/datefield.class.php +++ b/inc/fields/datefield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/datetimefield.class.php b/inc/fields/datetimefield.class.php index 6021d2dd2..b6c2e9ebd 100644 --- a/inc/fields/datetimefield.class.php +++ b/inc/fields/datetimefield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/descriptionfield.class.php b/inc/fields/descriptionfield.class.php index 0483d7f98..1f6cd609d 100644 --- a/inc/fields/descriptionfield.class.php +++ b/inc/fields/descriptionfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index a69378703..602becf15 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/emailfield.class.php b/inc/fields/emailfield.class.php index 07fb93b8e..789c1575d 100644 --- a/inc/fields/emailfield.class.php +++ b/inc/fields/emailfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/filefield.class.php b/inc/fields/filefield.class.php index 156896afa..6988f4080 100644 --- a/inc/fields/filefield.class.php +++ b/inc/fields/filefield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/floatfield.class.php b/inc/fields/floatfield.class.php index dd07ad3c6..a70383e01 100644 --- a/inc/fields/floatfield.class.php +++ b/inc/fields/floatfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/glpiselectfield.class.php b/inc/fields/glpiselectfield.class.php index bfe46083a..cf2779398 100644 --- a/inc/fields/glpiselectfield.class.php +++ b/inc/fields/glpiselectfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/hiddenfield.class.php b/inc/fields/hiddenfield.class.php index 95c157515..e457b1ab3 100644 --- a/inc/fields/hiddenfield.class.php +++ b/inc/fields/hiddenfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/integerfield.class.php b/inc/fields/integerfield.class.php index f1fe4a107..9834835d2 100644 --- a/inc/fields/integerfield.class.php +++ b/inc/fields/integerfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/ipfield.class.php b/inc/fields/ipfield.class.php index 89d86d58c..0cc6406a8 100644 --- a/inc/fields/ipfield.class.php +++ b/inc/fields/ipfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/ldapselectfield.class.php b/inc/fields/ldapselectfield.class.php index f32855a53..4233310a9 100644 --- a/inc/fields/ldapselectfield.class.php +++ b/inc/fields/ldapselectfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/multiselectfield.class.php b/inc/fields/multiselectfield.class.php index e6850726f..276ec85d7 100644 --- a/inc/fields/multiselectfield.class.php +++ b/inc/fields/multiselectfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/radiosfield.class.php b/inc/fields/radiosfield.class.php index 1336c2059..8d50705af 100644 --- a/inc/fields/radiosfield.class.php +++ b/inc/fields/radiosfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/selectfield.class.php b/inc/fields/selectfield.class.php index eafeddbe4..ed95d16cb 100644 --- a/inc/fields/selectfield.class.php +++ b/inc/fields/selectfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/tagfield.class.php b/inc/fields/tagfield.class.php index d78ae3bb8..ed5a775ec 100644 --- a/inc/fields/tagfield.class.php +++ b/inc/fields/tagfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/textareafield.class.php b/inc/fields/textareafield.class.php index 4d91fdc29..3846a9453 100644 --- a/inc/fields/textareafield.class.php +++ b/inc/fields/textareafield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/textfield.class.php b/inc/fields/textfield.class.php index 4bba99b71..058bc3540 100644 --- a/inc/fields/textfield.class.php +++ b/inc/fields/textfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/fields/urgencyfield.class.php b/inc/fields/urgencyfield.class.php index 68fc669bc..b27bb71cd 100644 --- a/inc/fields/urgencyfield.class.php +++ b/inc/fields/urgencyfield.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/form.class.php b/inc/form.class.php index e2eecf945..b3c66b60d 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index ce8042d50..6652295e6 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/form_profile.class.php b/inc/form_profile.class.php index c9b76698f..3f6080c42 100644 --- a/inc/form_profile.class.php +++ b/inc/form_profile.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/form_validator.class.php b/inc/form_validator.class.php index 946924d0e..a391358fd 100644 --- a/inc/form_validator.class.php +++ b/inc/form_validator.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/formlist.class.php b/inc/formlist.class.php index c2e0f60cf..4147f6fbb 100644 --- a/inc/formlist.class.php +++ b/inc/formlist.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/issue.class.php b/inc/issue.class.php index 48bf72080..476229351 100644 --- a/inc/issue.class.php +++ b/inc/issue.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/item_targetticket.class.php b/inc/item_targetticket.class.php index 2fe1c3051..193defdca 100644 --- a/inc/item_targetticket.class.php +++ b/inc/item_targetticket.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/notificationtargetform_answer.class.php b/inc/notificationtargetform_answer.class.php index ff1cad61d..8c3ddaa4f 100644 --- a/inc/notificationtargetform_answer.class.php +++ b/inc/notificationtargetform_answer.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/question.class.php b/inc/question.class.php index 8d7656400..c71ba2c6b 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/question_condition.class.php b/inc/question_condition.class.php index e80c1dd7d..c4a583776 100644 --- a/inc/question_condition.class.php +++ b/inc/question_condition.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/questiondependency.class.php b/inc/questiondependency.class.php index 6c01dc1a2..1ef92d683 100644 --- a/inc/questiondependency.class.php +++ b/inc/questiondependency.class.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/questionparameter.class.php b/inc/questionparameter.class.php index 7af700523..03a0be8f1 100644 --- a/inc/questionparameter.class.php +++ b/inc/questionparameter.class.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/questionrange.class.php b/inc/questionrange.class.php index 846941fd2..70a728aa6 100644 --- a/inc/questionrange.class.php +++ b/inc/questionrange.class.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/questionregex.class.php b/inc/questionregex.class.php index 28ccadb42..b916f8cd3 100644 --- a/inc/questionregex.class.php +++ b/inc/questionregex.class.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/section.class.php b/inc/section.class.php index 9e9ad4818..d7d3fa9f5 100644 --- a/inc/section.class.php +++ b/inc/section.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/target.class.php b/inc/target.class.php index 66e086656..b60feedf9 100644 --- a/inc/target.class.php +++ b/inc/target.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/target_actor.class.php b/inc/target_actor.class.php index f07271e96..1798013cf 100644 --- a/inc/target_actor.class.php +++ b/inc/target_actor.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index 152c2d5f6..a08fd68f1 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index 3b4dbd5c2..c2840f3bd 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/targetchange_actor.class.php b/inc/targetchange_actor.class.php index 0b108fd36..fa220e63d 100644 --- a/inc/targetchange_actor.class.php +++ b/inc/targetchange_actor.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index dc75c4079..e28cc47a6 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/targetticket_actor.class.php b/inc/targetticket_actor.class.php index c1bca2889..6ceb1c94f 100644 --- a/inc/targetticket_actor.class.php +++ b/inc/targetticket_actor.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/inc/wizard.class.php b/inc/wizard.class.php index 8e23f252b..ab8a93fb3 100644 --- a/inc/wizard.class.php +++ b/inc/wizard.class.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/index.php b/index.php index dab10da2c..b4110feab 100644 --- a/index.php +++ b/index.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/install/install.php b/install/install.php index 355c73ade..e00553e7c 100644 --- a/install/install.php +++ b/install/install.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/install/update_0.0_2.5.php b/install/update_0.0_2.5.php index 4cd47fb3f..7b02c42d4 100644 --- a/install/update_0.0_2.5.php +++ b/install/update_0.0_2.5.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/install/update_2.5_2.6.php b/install/update_2.5_2.6.php index ba2ac2740..f38f0c0d6 100644 --- a/install/update_2.5_2.6.php +++ b/install/update_2.5_2.6.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/install/update_2.6.2_2.6.3.php b/install/update_2.6.2_2.6.3.php index 40d7d7b25..c5dd34846 100644 --- a/install/update_2.6.2_2.6.3.php +++ b/install/update_2.6.2_2.6.3.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/install/update_2.6_2.6.1.php b/install/update_2.6_2.6.1.php index 1f512ef26..4e3429dd5 100644 --- a/install/update_2.6_2.6.1.php +++ b/install/update_2.6_2.6.1.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/install/update_2.6_2.7.php b/install/update_2.6_2.7.php index 6d53e19ca..f881ace1d 100644 --- a/install/update_2.6_2.7.php +++ b/install/update_2.6_2.7.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/js/scripts.js.php b/js/scripts.js.php index a930bbce3..d9e9eb2f0 100644 --- a/js/scripts.js.php +++ b/js/scripts.js.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/scripts/cliinstall.php b/scripts/cliinstall.php index 0cbd3e7ba..065ef54fa 100644 --- a/scripts/cliinstall.php +++ b/scripts/cliinstall.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/setup.php b/setup.php index 77220e4b0..2d616f218 100644 --- a/setup.php +++ b/setup.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-install/Config.php b/tests/suite-install/Config.php index 776d8b401..8e21359ba 100644 --- a/tests/suite-install/Config.php +++ b/tests/suite-install/Config.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * @author Thierry Bugier * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-integration/PluginFormcreatorForm.php b/tests/suite-integration/PluginFormcreatorForm.php index f9d94ab3a..400032adf 100644 --- a/tests/suite-integration/PluginFormcreatorForm.php +++ b/tests/suite-integration/PluginFormcreatorForm.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-integration/PluginFormcreatorForm_Answer.php b/tests/suite-integration/PluginFormcreatorForm_Answer.php index 9d75e2fb5..2000c4fca 100644 --- a/tests/suite-integration/PluginFormcreatorForm_Answer.php +++ b/tests/suite-integration/PluginFormcreatorForm_Answer.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-integration/PluginFormcreatorForm_Validator.php b/tests/suite-integration/PluginFormcreatorForm_Validator.php index aeb36bab1..c4c38e8ff 100644 --- a/tests/suite-integration/PluginFormcreatorForm_Validator.php +++ b/tests/suite-integration/PluginFormcreatorForm_Validator.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-integration/PluginFormcreatorQuestion.php b/tests/suite-integration/PluginFormcreatorQuestion.php index 7c2b62aa9..1a78e61d3 100644 --- a/tests/suite-integration/PluginFormcreatorQuestion.php +++ b/tests/suite-integration/PluginFormcreatorQuestion.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-integration/PluginFormcreatorSection.php b/tests/suite-integration/PluginFormcreatorSection.php index 9abb7b27b..ca6d88be6 100644 --- a/tests/suite-integration/PluginFormcreatorSection.php +++ b/tests/suite-integration/PluginFormcreatorSection.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-integration/PluginFormcreatorTargetChange.php b/tests/suite-integration/PluginFormcreatorTargetChange.php index acce28987..36c869c3e 100644 --- a/tests/suite-integration/PluginFormcreatorTargetChange.php +++ b/tests/suite-integration/PluginFormcreatorTargetChange.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-integration/PluginFormcreatorTargetTicket.php b/tests/suite-integration/PluginFormcreatorTargetTicket.php index 9537de755..5fb4940da 100644 --- a/tests/suite-integration/PluginFormcreatorTargetTicket.php +++ b/tests/suite-integration/PluginFormcreatorTargetTicket.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-uninstall/Config.php b/tests/suite-uninstall/Config.php index 239911b3e..392c9e65c 100644 --- a/tests/suite-uninstall/Config.php +++ b/tests/suite-uninstall/Config.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * @author Thierry Bugier * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorActorField.php b/tests/suite-unit/PluginFormcreatorActorField.php index a8a898a91..e6deb1b88 100644 --- a/tests/suite-unit/PluginFormcreatorActorField.php +++ b/tests/suite-unit/PluginFormcreatorActorField.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorCheckboxesField.php b/tests/suite-unit/PluginFormcreatorCheckboxesField.php index cb51c2712..dc1e3f964 100644 --- a/tests/suite-unit/PluginFormcreatorCheckboxesField.php +++ b/tests/suite-unit/PluginFormcreatorCheckboxesField.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorCommon.php b/tests/suite-unit/PluginFormcreatorCommon.php index 4e7174e66..cb40e9844 100644 --- a/tests/suite-unit/PluginFormcreatorCommon.php +++ b/tests/suite-unit/PluginFormcreatorCommon.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorDateField.php b/tests/suite-unit/PluginFormcreatorDateField.php index c5aa75f42..dd631e66a 100644 --- a/tests/suite-unit/PluginFormcreatorDateField.php +++ b/tests/suite-unit/PluginFormcreatorDateField.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorDatetimeField.php b/tests/suite-unit/PluginFormcreatorDatetimeField.php index 85f1d65a8..d7d32ef4f 100644 --- a/tests/suite-unit/PluginFormcreatorDatetimeField.php +++ b/tests/suite-unit/PluginFormcreatorDatetimeField.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorFields.php b/tests/suite-unit/PluginFormcreatorFields.php index 09d18ab39..c9ceb2661 100644 --- a/tests/suite-unit/PluginFormcreatorFields.php +++ b/tests/suite-unit/PluginFormcreatorFields.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorFloatField.php b/tests/suite-unit/PluginFormcreatorFloatField.php index 5fcfdad9b..33536f05f 100644 --- a/tests/suite-unit/PluginFormcreatorFloatField.php +++ b/tests/suite-unit/PluginFormcreatorFloatField.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorForm.php b/tests/suite-unit/PluginFormcreatorForm.php index 911a3c957..2df50e2d0 100644 --- a/tests/suite-unit/PluginFormcreatorForm.php +++ b/tests/suite-unit/PluginFormcreatorForm.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorIntegerField.php b/tests/suite-unit/PluginFormcreatorIntegerField.php index 4e5df50bb..1ba43e37d 100644 --- a/tests/suite-unit/PluginFormcreatorIntegerField.php +++ b/tests/suite-unit/PluginFormcreatorIntegerField.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorMultiSelectField.php b/tests/suite-unit/PluginFormcreatorMultiSelectField.php index 0dc25a35f..4ccdb1c52 100644 --- a/tests/suite-unit/PluginFormcreatorMultiSelectField.php +++ b/tests/suite-unit/PluginFormcreatorMultiSelectField.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorQuestion.php b/tests/suite-unit/PluginFormcreatorQuestion.php index c41531023..3726c9f99 100644 --- a/tests/suite-unit/PluginFormcreatorQuestion.php +++ b/tests/suite-unit/PluginFormcreatorQuestion.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorQuestion_Condition.php b/tests/suite-unit/PluginFormcreatorQuestion_Condition.php index 90d6779cb..f35a10024 100644 --- a/tests/suite-unit/PluginFormcreatorQuestion_Condition.php +++ b/tests/suite-unit/PluginFormcreatorQuestion_Condition.php @@ -24,7 +24,7 @@ * @author Thierry Bugier * @author Jérémy Moreau * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorRadiosField.php b/tests/suite-unit/PluginFormcreatorRadiosField.php index 3eb660eb7..c79cc6dec 100644 --- a/tests/suite-unit/PluginFormcreatorRadiosField.php +++ b/tests/suite-unit/PluginFormcreatorRadiosField.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorSection.php b/tests/suite-unit/PluginFormcreatorSection.php index 442bb4b13..470b2eaa0 100644 --- a/tests/suite-unit/PluginFormcreatorSection.php +++ b/tests/suite-unit/PluginFormcreatorSection.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorSelectField.php b/tests/suite-unit/PluginFormcreatorSelectField.php index e4fc5f12e..c1f99460f 100644 --- a/tests/suite-unit/PluginFormcreatorSelectField.php +++ b/tests/suite-unit/PluginFormcreatorSelectField.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorTarget.php b/tests/suite-unit/PluginFormcreatorTarget.php index b8c4968d7..bbf2d74d0 100644 --- a/tests/suite-unit/PluginFormcreatorTarget.php +++ b/tests/suite-unit/PluginFormcreatorTarget.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorTargetTicket.php b/tests/suite-unit/PluginFormcreatorTargetTicket.php index aad8b4b2c..b7bc47213 100644 --- a/tests/suite-unit/PluginFormcreatorTargetTicket.php +++ b/tests/suite-unit/PluginFormcreatorTargetTicket.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tests/suite-unit/PluginFormcreatorTextField.php b/tests/suite-unit/PluginFormcreatorTextField.php index de9772557..1c10cae58 100644 --- a/tests/suite-unit/PluginFormcreatorTextField.php +++ b/tests/suite-unit/PluginFormcreatorTextField.php @@ -23,7 +23,7 @@ * --------------------------------------------------------------------- * * @copyright Copyright © 2011 - 2018 Teclib' - * @license GPLv3+ http://www.gnu.org/licenses/gpl.txt + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/pluginsGLPI/formcreator/ * @link https://pluginsglpi.github.io/formcreator/ * @link http://plugins.glpi-project.org/#/plugin/formcreator diff --git a/tools/HEADER b/tools/HEADER index 64bc6c77f..fe3b54843 100644 --- a/tools/HEADER +++ b/tools/HEADER @@ -1,10 +1,10 @@ --------------------------------------------------------------------- -Formcreator is a plugin which allows creation of custom forms of -easy access. +Formcreator is a plugin which allows creation of custom forms of +easy access. --------------------------------------------------------------------- LICENSE - + This file is part of Formcreator. Formcreator is free software; you can redistribute it and/or modify @@ -23,7 +23,7 @@ along with Formcreator. If not, see . @author Thierry Bugier @author Jérémy Moreau @copyright Copyright © 2011 - 2018 Teclib' -@license GPLv3+ http://www.gnu.org/licenses/gpl.txt +@license http://www.gnu.org/licenses/gpl.txt GPLv3+ @link https://github.com/pluginsGLPI/formcreator/ @link https://pluginsglpi.github.io/formcreator/ @link http://plugins.glpi-project.org/#/plugin/formcreator From f8ba7c7ee34263b5a8310f9a8b4350b6ad9ee6e9 Mon Sep 17 00:00:00 2001 From: btry Date: Sat, 1 Sep 2018 00:02:58 +0200 Subject: [PATCH 047/192] test: add tests for fields Signed-off-by: btry --- inc/fields/dropdownfield.class.php | 12 +- inc/fields/glpiselectfield.class.php | 10 + .../PluginFormcreatorCheckboxesField.php | 7 +- .../PluginFormcreatorDescriptionField.php | 96 +++++++ .../PluginFormcreatorGlpiselectField.php | 261 ++++++++++++++++++ 5 files changed, 377 insertions(+), 9 deletions(-) create mode 100644 tests/suite-unit/PluginFormcreatorDescriptionField.php create mode 100644 tests/suite-unit/PluginFormcreatorGlpiselectField.php diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index 602becf15..034a70f91 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -133,15 +133,11 @@ public function getAnswer() { public function prepareQuestionInputForTarget($input) { $DbUtil = new DbUtils(); - if ($this->fields['values'] == User::class) { - $value = $DbUtil->getUserName($input); + $decodedValues = json_decode($this->fields['values'], JSON_OBJECT_AS_ARRAY); + if (!isset($decodedValues['itemtype'])) { + $value = Dropdown::getDropdownName($DbUtil->getTableForItemType($this->fields['values']), $input); } else { - $decodedValues = json_decode($this->fields['values'], JSON_OBJECT_AS_ARRAY); - if (!isset($decodedValues['itemtype'])) { - $value = Dropdown::getDropdownName($DbUtil->getTableForItemType($this->fields['values']), $input); - } else { - $value = Dropdown::getDropdownName($DbUtil->getTableForItemType($decodedValues['itemtype']), $input); - } + $value = Dropdown::getDropdownName($DbUtil->getTableForItemType($decodedValues['itemtype']), $input); } return addslashes($value); diff --git a/inc/fields/glpiselectfield.class.php b/inc/fields/glpiselectfield.class.php index cf2779398..06cfdb5cd 100644 --- a/inc/fields/glpiselectfield.class.php +++ b/inc/fields/glpiselectfield.class.php @@ -66,6 +66,16 @@ public function isValid($value) { return true; } + public function getAnswer() { + $value = $this->getValue(); + $DbUtil = new DbUtils(); + if ($this->fields['values'] == User::class) { + return $DbUtil->getUserName($value); + } else { + return Dropdown::getDropdownName($DbUtil->getTableForItemType($this->fields['values']), $value); + } + } + public static function getPrefs() { return [ 'required' => 1, diff --git a/tests/suite-unit/PluginFormcreatorCheckboxesField.php b/tests/suite-unit/PluginFormcreatorCheckboxesField.php index dc1e3f964..9efff6e57 100644 --- a/tests/suite-unit/PluginFormcreatorCheckboxesField.php +++ b/tests/suite-unit/PluginFormcreatorCheckboxesField.php @@ -33,6 +33,11 @@ use GlpiPlugin\Formcreator\Tests\CommonTestCase; class PluginFormcreatorCheckboxesField extends CommonTestCase { + public function testGetName() { + $output = \PluginFormcreatorCheckboxesField::getName(); + $this->string($output)->isEqualTo('Checkboxes'); + } + public function providerGetAvailableValues() { $dataset = [ [ @@ -227,7 +232,7 @@ public function testIsValid($fields, $data, $expectedValue, $expectedValidity) { $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); } - public function testPrepareInputForSave() { + public function testPrepareQuestionInputForSave() { $fields = [ 'fieldtype' => 'checkboxes', 'name' => 'question', diff --git a/tests/suite-unit/PluginFormcreatorDescriptionField.php b/tests/suite-unit/PluginFormcreatorDescriptionField.php new file mode 100644 index 000000000..4efa2ed14 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorDescriptionField.php @@ -0,0 +1,96 @@ +. + * --------------------------------------------------------------------- + * @author Thierry Bugier + * @author Jérémy Moreau + * @copyright Copyright © 2011 - 2018 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + +namespace tests\units; +use GlpiPlugin\Formcreator\Tests\CommonTestCase; + +class PluginFormcreatorDescriptionField extends CommonTestCase { + + public function testIsValid() { + $instance = new \PluginFormcreatorDescriptionField([ + 'name' => $this->getUniqueString(), + ], + []); + $this->boolean($instance->isValid(''))->isTrue(); + } + + public function testGetName() { + $output = \PluginFormcreatorDescriptionField::getName(); + $this->string($output)->isEqualTo('Description'); + } + + public function providerPrepareQuestionInputForSave() { + return [ + 'empty description' => [ + 'input' => [ + 'name' => $this->getUniqueString(), + 'description' => '' + ], + 'expected' => [ + ], + 'message' => 'A description field should have a description:', + ], + 'escaping test' => [ + 'input' => [ + 'name' => "test d'apostrophe", + 'description' => "test d'apostrophe", + ], + 'expected' => [ + 'name' => "test d'apostrophe", + 'description' => \Toolbox::addslashes_deep("test d'apostrophe"), + ], + 'message' => 'A description field should have a description:', + ], + ]; + } + /** + * @dataProvider providerPrepareQuestionInputForSave + */ + public function testPrepareQuestionInputForSave($input, $expected, $message) { + $instance = new \PluginFormcreatorDescriptionField([ + 'name' => $this->getUniqueString(), + ]); + $output = $instance->prepareQuestionInputForSave($input); + if (count($expected) === 0 || $expected === false) { + $this->string($_SESSION["MESSAGE_AFTER_REDIRECT"][ERROR][0]) + ->isEqualTo($message . ' ' . $input['name']); + $this->array($output)->isEmpty(); + } else { + $this->array($output)->hasSize(count($expected)); + foreach ($expected as $key => $value) { + $this->array($output)->hasKey($key) + ->variable($output[$key])->isIdenticalTo($value); + } + } + } +} \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorGlpiselectField.php b/tests/suite-unit/PluginFormcreatorGlpiselectField.php new file mode 100644 index 000000000..22b328e9d --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorGlpiselectField.php @@ -0,0 +1,261 @@ +. + * --------------------------------------------------------------------- + * @author Thierry Bugier + * @author Jérémy Moreau + * @copyright Copyright © 2011 - 2018 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + + +namespace tests\units; +use GlpiPlugin\Formcreator\Tests\CommonTestCase; + +class PluginFormcreatorGlpiselectField extends CommonTestCase { + + public function testGetName() { + $output = \PluginFormcreatorGlpiselectField::getName(); + $this->string($output)->isEqualTo('GLPI object'); + } + + public function providerGetAnswer() { + $user = new \User(); + $user->add([ + 'name' => $this->getUniqueString(), + 'realname' => 'John', + 'firstname' => 'Doe', + ]); + $this->boolean($user->isNewItem())->isFalse(); + + $computer = new \Computer(); + $computer->add([ + 'name' => $this->getUniqueString(), + \Entity::getForeignKeyField() => 0, + ]); + $this->boolean($computer->isNewItem())->isFalse(); + + $dataset = [ + [ + 'fields' => [ + 'fieldtype' => 'dropdown', + 'name' => 'question', + 'required' => '0', + 'default_values' => $user->getID(), + 'values' => \User::class, + 'order' => '1', + 'show_rule' => 'always', + 'show_empty' => true, + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => (new \DbUtils())->getUserName($user->getID()), + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'dropdown', + 'name' => 'question', + 'required' => '0', + 'default_values' => '', + 'values' => \User::class, + 'order' => '1', + 'show_rule' => 'always', + 'show_empty' => true, + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => '', + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'dropdown', + 'name' => 'question', + 'required' => '0', + 'default_values' => $user->getID(), + 'values' => \User::class, + 'order' => '1', + 'show_rule' => 'always', + 'show_empty' => false, + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => (new \DbUtils())->getUserName($user->getID()), + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'dropdown', + 'name' => 'question', + 'required' => '0', + 'default_values' => '', + 'values' => \User::class, + 'order' => '1', + 'show_rule' => 'always', + 'show_empty' => false, + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => '', + 'expectedIsValid' => true + ], + + [ + 'fields' => [ + 'fieldtype' => 'dropdown', + 'name' => 'question', + 'required' => '0', + 'default_values' => $computer->getID(), + 'values' => \Computer::class, + 'order' => '1', + 'show_rule' => 'always', + 'show_empty' => true, + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => $computer->getName(), + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'dropdown', + 'name' => 'question', + 'required' => '0', + 'default_values' => '', + 'values' => \Computer::class, + 'order' => '1', + 'show_rule' => 'always', + 'show_empty' => true, + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => ' ', + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'dropdown', + 'name' => 'question', + 'required' => '0', + 'default_values' => $computer->getID(), + 'values' => \Computer::class, + 'order' => '1', + 'show_rule' => 'always', + 'show_empty' => false, + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => $computer->getName(), + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'dropdown', + 'name' => 'question', + 'required' => '0', + 'default_values' => '', + 'values' => \Computer::class, + 'order' => '1', + 'show_rule' => 'always', + 'show_empty' => false, + '_parameters' => [ + 'date' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => ' ', + 'expectedIsValid' => true + ], + ]; + + return $dataset; + } + + /** + * @dataProvider providerGetAnswer + */ + public function testGetAnswer($fields, $data, $expectedValue, $expectedValidity) { + $instance = $this->newTestedInstance($fields, $data); + + $output = $instance->getAnswer(); + $this->variable($output)->isEqualTo($expectedValue); + } +} \ No newline at end of file From 75a815a8bd33243d0723da82181538cf40011355 Mon Sep 17 00:00:00 2001 From: btry Date: Sun, 2 Sep 2018 15:43:06 +0200 Subject: [PATCH 048/192] fix(install): ad specific values only for itilcategory Signed-off-by: btry --- install/update_2.6_2.7.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/install/update_2.6_2.7.php b/install/update_2.6_2.7.php index f881ace1d..62381b7ff 100644 --- a/install/update_2.6_2.7.php +++ b/install/update_2.6_2.7.php @@ -122,15 +122,17 @@ function plugin_formcreator_update_2_7(Migration $migration) { ]; foreach ($DB->request($request) as $row) { $values = json_decode($row['values'], true); - if (!isset($values['show_ticket_categories'])) { - $values['show_ticket_categories'] = 'both'; - } - if (!isset($values['show_ticket_categories_depth'])) { - $values['show_ticket_categories_depth'] = '0'; + if ($values['itemtype'] === ITILCategory::class) { + if (!isset($values['show_ticket_categories'])) { + $values['show_ticket_categories'] = 'both'; + } + if (!isset($values['show_ticket_categories_depth'])) { + $values['show_ticket_categories_depth'] = '0'; + } + $id = $row['id']; + $values = json_encode($values); + $DB->query("UPDATE `glpi_plugin_formcreator_questions` SET `values`='$values' WHERE `id` = '$id'"); } - $id = $row['id']; - $values = json_encode($values); - $DB->query("UPDATE `glpi_plugin_formcreator_questions` SET `values`='$values' WHERE `id` = '$id'"); } // multiple files upload per field From 23f01074f50de78d052745c35e16399faae6c1bc Mon Sep 17 00:00:00 2001 From: btry Date: Sun, 2 Sep 2018 20:52:22 +0200 Subject: [PATCH 049/192] test(dropdownfield): add tests Signed-off-by: btry --- inc/fields/dropdownfield.class.php | 25 +- .../PluginFormcreatorDropdownField.php | 232 ++++++++++++++++++ 2 files changed, 246 insertions(+), 11 deletions(-) create mode 100644 tests/suite-unit/PluginFormcreatorDropdownField.php diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index 034a70f91..f97527632 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -116,19 +116,21 @@ public function displayField($canEdit = true) { } } + public function getValue() { + if (isset($this->fields['answer'])) { + return $this->fields['answer']; + } + if (!empty($this->fields['default_values'])) { + return $this->fields['default_values']; + } + return 0; + } + public function getAnswer() { $value = $this->getValue(); $DbUtil = new DbUtils(); - if ($this->fields['values'] == 'User') { - return $DbUtil->getUserName($value); - } else { - $decodedValues = json_decode($this->fields['values'], JSON_OBJECT_AS_ARRAY); - if (!isset($decodedValues['itemtype'])) { - return Dropdown::getDropdownName($DbUtil->getTableForItemType($this->fields['values']), $value); - } else { - return Dropdown::getDropdownName($DbUtil->getTableForItemType($decodedValues['itemtype']), $value); - } - } + $decodedValues = json_decode($this->fields['values'], JSON_OBJECT_AS_ARRAY); + return Dropdown::getDropdownName($DbUtil->getTableForItemType($decodedValues['itemtype']), $value); } public function prepareQuestionInputForTarget($input) { @@ -157,6 +159,7 @@ public function prepareQuestionInputForSave($input) { return []; } $allowedDropdownValues = []; + $stdtypes = Dropdown::getStandardDropdownItemTypes(); foreach (Dropdown::getStandardDropdownItemTypes() as $categoryOfTypes) { $allowedDropdownValues = array_merge($allowedDropdownValues, array_keys($categoryOfTypes)); } @@ -170,7 +173,7 @@ public function prepareQuestionInputForSave($input) { $input['values'] = [ 'itemtype' => $input['dropdown_values'], ]; - if ($input['dropdown_values'] == 'ITILCategory') { + if ($input['dropdown_values'] == ITILCategory::class) { $input['values']['show_ticket_categories'] = $input['show_ticket_categories']; if ($input['show_ticket_categories_depth'] != (int) $input['show_ticket_categories_depth']) { $input['values']['show_ticket_categories_depth'] = 0; diff --git a/tests/suite-unit/PluginFormcreatorDropdownField.php b/tests/suite-unit/PluginFormcreatorDropdownField.php new file mode 100644 index 000000000..c0665e408 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorDropdownField.php @@ -0,0 +1,232 @@ +. + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ +namespace tests\units; +use GlpiPlugin\Formcreator\Tests\CommonTestCase; + +class PluginFormcreatorDropdownField extends CommonTestCase { + public function beforeTestMethod($method) { + switch ($method) { + case 'testPrepareQuestionInputForSave': + $this->login('glpi', 'glpi'); + } + } + + public function testGetName() { + $instance = $this->newTestedInstance([]); + $output = $instance->getName(); + $this->string($output)->isEqualTo('Dropdown'); + } + + public function providerGetValue() { + $location = new \Location(); + $locationName = $this->getUniqueString(); + $locationId = $location->import([ + 'completename' => $locationName, + 'entities_id' => 0, + 'is_recursive' => 1, + ]); + $this->integer($locationId); + $dataset = [ + [ + 'fields' => [ + 'fieldtype' => 'dropdown', + 'name' => 'question', + 'required' => '0', + 'default_values' => '', + 'values' => json_encode(['itemtype' => \Location::class]), + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => 0, + 'expectedIsValid' => true + ], + [ + 'fields' => [ + 'fieldtype' => 'dropdown', + 'name' => 'question', + 'required' => '0', + 'default_values' => $locationId, + 'values' => json_encode(['itemtype' => \Location::class]), + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => $locationId, + 'expectedIsValid' => true + ], + ]; + return $dataset; + } + + /** + * @dataProvider providerGetValue + */ + public function testGetValue($fields, $data, $expectedValue, $expectedIsValid) { + $instance = new \PluginFormcreatorDropdownField($fields, $data); + $output = $instance->getValue(); + $this->variable($output)->isIdenticalTo($expectedValue); + + } + + public function providerGetAnswer() { + $location = new \Location(); + $locationName = $this->getUniqueString(); + $locationId = $location->import([ + 'completename' => $locationName, + 'entities_id' => 0, + 'is_recursive' => 1, + ]); + $this->integer($locationId); + $dataset = [ + [ + 'fields' => [ + 'fieldtype' => 'dropdown', + 'name' => 'question', + 'required' => '0', + 'default_values' => '', + 'values' => json_encode(['itemtype' => \Location::class]), + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => " ", + ], + [ + 'fields' => [ + 'fieldtype' => 'dropdown', + 'name' => 'question', + 'required' => '0', + 'default_values' => $locationId, + 'values' => json_encode(['itemtype' => \Location::class]), + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ], + 'data' => null, + 'expectedValue' => $locationName, + ], + ]; + return $dataset; + } + + /** + * @dataProvider providerGetAnswer + */ + public function testgetAnswer($fields, $data, $expectedValue) { + $instance = new \PluginFormcreatorDropdownField($fields, $data); + $output = $instance->getAnswer(); + $DbUtil = new \DbUtils(); + $itemtype = json_decode($fields['values'], JSON_OBJECT_AS_ARRAY); + $itemtype = $itemtype['itemtype']; + $this->variable($output)->isIdenticalTo($expectedValue); + } + + public function providerPrepareQuestionInputForSave() { + $name = $this->getUniqueString(); + return [ + [ + 'input' => [ + 'name' => $name, + 'dropdown_values' => \Location::class, + ], + 'expected' => [ + 'name' => $name, + 'values' => json_encode(['itemtype' => \Location::class]), + 'dropdown_values' => \Location::class, + 'default_values' => '', + ] + ], + [ + 'input' => [ + 'name' => $name, + 'dropdown_values' => \ITILCategory::class, + 'show_ticket_categories' => '2', + 'show_ticket_categories_depth' => '3', + ], + 'expected' => [ + 'name' => $name, + 'values' => json_encode([ + 'itemtype' => \ITILCategory::class, + 'show_ticket_categories' => '2', + 'show_ticket_categories_depth' => '3', + ]), + 'dropdown_values' => \ITILCategory::class, + 'default_values' => '', + ] + ], + ]; + } + + /** + * @dataProvider providerPrepareQuestionInputForSave + */ + public function testPrepareQuestionInputForSave($input, $expected) { + $instance = new \PluginFormcreatorDropdownField([]); + $output = $instance->prepareQuestionInputForSave($input); + $this->array($output)->hasSize(count($expected)); + foreach ($expected as $key => $value) { + $this->variable($output[$key])->isIdenticalTo($value); + } + } +} From 0d4393be2e31bb20f7e0a18e2c69d7c75cdf19cd Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 3 Sep 2018 09:52:36 +0200 Subject: [PATCH 050/192] test(glpiselect): add tests Signed-off-by: btry --- .../PluginFormcreatorGlpiselectField.php | 26 +++++++--- .../PluginFormcreatorHiddenField.php | 47 +++++++++++++++++++ 2 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 tests/suite-unit/PluginFormcreatorHiddenField.php diff --git a/tests/suite-unit/PluginFormcreatorGlpiselectField.php b/tests/suite-unit/PluginFormcreatorGlpiselectField.php index 22b328e9d..602cccc9a 100644 --- a/tests/suite-unit/PluginFormcreatorGlpiselectField.php +++ b/tests/suite-unit/PluginFormcreatorGlpiselectField.php @@ -78,7 +78,7 @@ public function providerGetAnswer() { ] ], ], - 'data' => null, + 'data' => $user->getID(), 'expectedValue' => (new \DbUtils())->getUserName($user->getID()), 'expectedIsValid' => true ], @@ -86,7 +86,7 @@ public function providerGetAnswer() { 'fields' => [ 'fieldtype' => 'dropdown', 'name' => 'question', - 'required' => '0', + 'required' => '1', 'default_values' => '', 'values' => \User::class, 'order' => '1', @@ -101,15 +101,15 @@ public function providerGetAnswer() { ] ], ], - 'data' => null, + 'data' => '0', 'expectedValue' => '', - 'expectedIsValid' => true + 'expectedIsValid' => false ], [ 'fields' => [ 'fieldtype' => 'dropdown', 'name' => 'question', - 'required' => '0', + 'required' => '1', 'default_values' => $user->getID(), 'values' => \User::class, 'order' => '1', @@ -124,7 +124,7 @@ public function providerGetAnswer() { ] ], ], - 'data' => null, + 'data' => $user->getID(), 'expectedValue' => (new \DbUtils())->getUserName($user->getID()), 'expectedIsValid' => true ], @@ -254,8 +254,20 @@ public function providerGetAnswer() { */ public function testGetAnswer($fields, $data, $expectedValue, $expectedValidity) { $instance = $this->newTestedInstance($fields, $data); - $output = $instance->getAnswer(); $this->variable($output)->isEqualTo($expectedValue); } + + public function ptroviderIsValid() { + return $this->providerGetAnswer(); + } + + /** + * @dataProvider ptroviderIsValid + */ + public function testIsValid($fields, $data, $expectedValue, $expectedValidity) { + $instance = $this->newTestedInstance($fields, $data); + $output = $instance->isValid($data); + $this->boolean($output)->isEqualTo($expectedValidity); + } } \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorHiddenField.php b/tests/suite-unit/PluginFormcreatorHiddenField.php new file mode 100644 index 000000000..deaa10ac5 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorHiddenField.php @@ -0,0 +1,47 @@ +. + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ +namespace tests\units; +use GlpiPlugin\Formcreator\Tests\CommonTestCase; + +class PluginFormcreatorHiddenField extends CommonTestCase { + public function testGetName() { + $instance = new \PluginFormcreatorHiddenField([]); + $output = $instance->getName(); + $this->string($output)->isEqualTo('Hidden field'); + } + + public function testIsValid() { + $instance = new \PluginFormcreatorHiddenField([]); + $output = $instance->isValid(); + $this->boolean($output)->isTrue(); + } +} \ No newline at end of file From 736199e5924a06e799d887f2eeecd8741788c62c Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 3 Sep 2018 09:53:04 +0200 Subject: [PATCH 051/192] test(ipfield): add tests Signed-off-by: btry --- tests/suite-unit/PluginFormcreatorIpField.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/suite-unit/PluginFormcreatorIpField.php diff --git a/tests/suite-unit/PluginFormcreatorIpField.php b/tests/suite-unit/PluginFormcreatorIpField.php new file mode 100644 index 000000000..4f08923af --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorIpField.php @@ -0,0 +1,50 @@ +. + * --------------------------------------------------------------------- + * @author Thierry Bugier + * @author Jérémy Moreau + * @copyright Copyright © 2011 - 2018 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + + namespace tests\units; +use GlpiPlugin\Formcreator\Tests\CommonTestCase; + +class PluginFormcreatorIpField extends CommonTestCase { + + public function testGetName() { + $instance = new \PluginFormcreatorIpField([]); + $output = $instance->getName(); + $this->string($output)->isEqualTo('IP address'); + } + + public function testIsValid() { + $instance = new \PluginFormcreatorIpField([]); + $output = $instance->isValid(''); + $this->boolean($output)->isTrue(); + } +} \ No newline at end of file From bc4cf02dd8c05935b1f926122c45aecbe714a600 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 3 Sep 2018 10:11:50 +0200 Subject: [PATCH 052/192] test: add tests Signed-off-by: btry --- tests/suite-unit/PluginFormcreatorIntegerField.php | 2 +- .../PluginFormcreatorMultiSelectField.php | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/suite-unit/PluginFormcreatorIntegerField.php b/tests/suite-unit/PluginFormcreatorIntegerField.php index 1ba43e37d..66b2943a7 100644 --- a/tests/suite-unit/PluginFormcreatorIntegerField.php +++ b/tests/suite-unit/PluginFormcreatorIntegerField.php @@ -199,7 +199,7 @@ public function testGetValue($fields, $data, $expectedValue, $expectedValidity) /** * @dataProvider provider */ - public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidity) { + public function testIsValid($fields, $data, $expectedValue, $expectedValidity) { $section = $this->getSection(); $fields[$section::getForeignKeyField()] = $section->getID(); diff --git a/tests/suite-unit/PluginFormcreatorMultiSelectField.php b/tests/suite-unit/PluginFormcreatorMultiSelectField.php index 4ccdb1c52..abb6874b0 100644 --- a/tests/suite-unit/PluginFormcreatorMultiSelectField.php +++ b/tests/suite-unit/PluginFormcreatorMultiSelectField.php @@ -35,7 +35,6 @@ class PluginFormcreatorMultiSelectField extends CommonTestCase { public function provider() { - $dataset = [ [ 'fields' => [ @@ -160,7 +159,7 @@ public function provider() { /** * @dataProvider provider */ - public function testFieldAvailableValue($fields, $data, $expectedValue, $expectedValidity) { + public function testGetAvailableValues($fields, $data, $expectedValue, $expectedValidity) { $fieldInstance = new \PluginFormcreatorMultiSelectField($fields, $data); $availableValues = $fieldInstance->getAvailableValues(); @@ -188,7 +187,7 @@ public function testFieldValue($fields, $data, $expectedValue, $expectedValidity /** * @dataProvider provider */ - public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidity) { + public function testIsValid($fields, $data, $expectedValue, $expectedValidity) { $section = $this->getSection(); $fields[$section::getForeignKeyField()] = $section->getID(); @@ -205,7 +204,7 @@ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidi $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); } - public function testPrepareInputForSave() { + public function testPrepareQuestionInputForSave() { $fields = [ 'fieldtype' => 'multiselect', 'name' => 'question', @@ -258,4 +257,10 @@ public function testPrepareInputForSave() { $this->string($out['values'])->isEqualTo('something\r\nsomething else'); $this->string($out['default_values'])->isEqualTo("something"); } + + public function testGetName() { + $instance = new \PluginFormcreatorMultiSelectField([]); + $output = $instance->getName(); + $this->string($output)->isEqualTo('Multiselect'); + } } \ No newline at end of file From 9e6165af0830d68a016a49f7089faab0e15c5e87 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 3 Sep 2018 10:12:49 +0200 Subject: [PATCH 053/192] test(hiddenfield): fix tests" Signed-off-by: btry --- tests/suite-unit/PluginFormcreatorHiddenField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/suite-unit/PluginFormcreatorHiddenField.php b/tests/suite-unit/PluginFormcreatorHiddenField.php index deaa10ac5..c19d8fef2 100644 --- a/tests/suite-unit/PluginFormcreatorHiddenField.php +++ b/tests/suite-unit/PluginFormcreatorHiddenField.php @@ -41,7 +41,7 @@ public function testGetName() { public function testIsValid() { $instance = new \PluginFormcreatorHiddenField([]); - $output = $instance->isValid(); + $output = $instance->isValid(''); $this->boolean($output)->isTrue(); } } \ No newline at end of file From c5dbab0244802b9a3d24c91be71945a4cd3045b3 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 3 Sep 2018 10:19:48 +0200 Subject: [PATCH 054/192] test(ldapselectfield): add tests Signed-off-by: btry --- .../PluginFormcreatorLdapselectField.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/suite-unit/PluginFormcreatorLdapselectField.php diff --git a/tests/suite-unit/PluginFormcreatorLdapselectField.php b/tests/suite-unit/PluginFormcreatorLdapselectField.php new file mode 100644 index 000000000..7cf14071f --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorLdapselectField.php @@ -0,0 +1,44 @@ +. + * --------------------------------------------------------------------- + * @author Thierry Bugier + * @author Jérémy Moreau + * @copyright Copyright © 2011 - 2018 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + + namespace tests\units; +use GlpiPlugin\Formcreator\Tests\CommonTestCase; + +class PluginFormcreatorLdapselectField extends CommonTestCase { + + public function testGetName() { + $instance = new \PluginFormcreatorLdapselectField([]); + $output = $instance->getName(); + $this->string($output)->isEqualTo('LDAP Select'); + } +} \ No newline at end of file From fa82bcbdfc2bbd994e0acfa1a8835e2c98c480f4 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 3 Sep 2018 10:35:38 +0200 Subject: [PATCH 055/192] test(radiosfield): add tests Signed-off-by: btry --- tests/suite-unit/PluginFormcreatorRadiosField.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/suite-unit/PluginFormcreatorRadiosField.php b/tests/suite-unit/PluginFormcreatorRadiosField.php index c79cc6dec..3fe7789a4 100644 --- a/tests/suite-unit/PluginFormcreatorRadiosField.php +++ b/tests/suite-unit/PluginFormcreatorRadiosField.php @@ -33,7 +33,7 @@ use GlpiPlugin\Formcreator\Tests\CommonTestCase; class PluginFormcreatorRadiosField extends CommonTestCase { - public function testPrepareInputForSave() { + public function testPrepareQuestionInputForSave() { $fields = [ 'fieldtype' => 'radios', 'name' => 'question', @@ -73,4 +73,10 @@ public function testPrepareInputForSave() { $this->string($out['values'])->isEqualTo('something\r\nsomething else'); $this->string($out['default_values'])->isEqualTo("something"); } + + public function testGetName() { + $output = \PluginFormcreatorRadiosField::getName(); + $this->string($output)->isEqualTo('Radios'); + } + } \ No newline at end of file From 9b5157c7415e49ce21a7b3986b7bde271510c596 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 3 Sep 2018 10:38:26 +0200 Subject: [PATCH 056/192] test(selectfield): add tests Signed-off-by: btry --- tests/suite-unit/PluginFormcreatorSelectField.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/suite-unit/PluginFormcreatorSelectField.php b/tests/suite-unit/PluginFormcreatorSelectField.php index c1f99460f..8bb875dfd 100644 --- a/tests/suite-unit/PluginFormcreatorSelectField.php +++ b/tests/suite-unit/PluginFormcreatorSelectField.php @@ -153,4 +153,9 @@ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidi $isValid = $fieldInstance->isValid($fields['default_values']); $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); } + + public function testGetName() { + $output = \PluginFormcreatorSelectField::getName(); + $this->string($output)->isEqualTo('Select'); + } } \ No newline at end of file From d186ef3b63db97702c180d70c0888dabd59bc2fb Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Sun, 9 Sep 2018 21:55:49 +0200 Subject: [PATCH 057/192] fix(targetchange): apply fix #267 to target changes Signed-off-by: Thierry Bugier --- inc/targetchange.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index c2840f3bd..7a37f312a 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -1025,6 +1025,8 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { // Requester's entity case 'current' : $data['entities_id'] = $_SESSION['glpiactive_entity']; + break; + case 'requester' : $userObj = new User(); $userObj->getFromDB($requesters_id); From b171ef3309af9a419228950f7f5feb0590400e89 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 10 Sep 2018 10:30:30 +0200 Subject: [PATCH 058/192] fix(install): avoid warnings Signed-off-by: btry --- scripts/cliinstall.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/cliinstall.php b/scripts/cliinstall.php index 065ef54fa..08733b2b4 100644 --- a/scripts/cliinstall.php +++ b/scripts/cliinstall.php @@ -31,6 +31,10 @@ * --------------------------------------------------------------------- */ +(PHP_SAPI == 'cli') or die("Only available from command line"); + +chdir(dirname($_SERVER["SCRIPT_FILENAME"])); + include (__DIR__ . "/../vendor/docopt/docopt/src/docopt.php"); $doc = <<connected) { die("No DB connection\n"); From c8bc82a19a202e171cf00a6ec1f4ca298c740778 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Sun, 9 Sep 2018 21:58:36 +0200 Subject: [PATCH 059/192] refactor(target): simplify actors handling Signed-off-by: Thierry Bugier --- inc/targetbase.class.php | 75 +++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 16 deletions(-) diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index a08fd68f1..0005db8cd 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -58,14 +58,43 @@ abstract public function export($remove_uuid = false); abstract public function save(PluginFormcreatorForm_Answer $formanswer); + /** + * Gets an instance object for the relation between the target itemtype + * and an user + * + * @return CommonDBTM + */ abstract protected function getItem_User(); + /** + * Gets an instance object for the relation between the target itemtype + * and a group + * + * @return CommonDBTM + */ abstract protected function getItem_Group(); + /** + * Gets an instance object for the relation between the target itemtype + * and supplier + * + * @return CommonDBTM + */ abstract protected function getItem_Supplier(); + /** + * Gets an instance object for the relation between the target itemtype + * and an object of any itemtype + * + * @return CommonDBTM + */ abstract protected function getItem_Item(); + /** + * Gets the class name of the target itemtype + * + * @return string + */ abstract protected function getTargetItemtypeName(); abstract public function getItem_Actor(); @@ -146,7 +175,7 @@ public static function canView() { return true; } - /* + /** * */ public function getForm() { @@ -269,6 +298,14 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF } } + /** + * Adds an user to the given actor role (requester, observer assigned or supplier) + * + * @param string $role role of the user + * @param string $user user ID or email address for anonymous users + * @param boolean $notify true to enable notification for the actor + * @return void + */ protected function addActor($role, $user, $notify) { if (filter_var($user, FILTER_VALIDATE_EMAIL) !== false) { $userId = 0; @@ -278,35 +315,41 @@ protected function addActor($role, $user, $notify) { $alternativeEmail = ''; if ($userId == '0') { // there is no actor - return; + return false; } } + $actorType = null; switch ($role) { case 'requester': - $this->requesters['_users_id_requester'][] = $userId; - $this->requesters['_users_id_requester_notif']['use_notification'][] = ($notify == true); - $this->requesters['_users_id_requester_notif']['alternative_email'][] = $alternativeEmail; + $actorType = &$this->requesters['_users_id_requester']; break; - case 'observer' : - $this->observers['_users_id_observer'][] = $userId; - $this->observers['_users_id_observer_notif']['use_notification'][] = ($notify == true); - $this->observers['_users_id_observer_notif']['alternative_email'][] = $alternativeEmail; + case 'observer': + $actorType = &$this->observers['_users_id_observer']; break; case 'assigned' : - $this->assigned['_users_id_assign'][] = $userId; - $this->assigned['_users_id_assign_notif']['use_notification'][] = ($notify == true); - $this->assigned['_users_id_assign_notif']['alternative_email'][] = $alternativeEmail; + $actorType = &$this->assigned['_users_id_assign']; break; case 'supplier' : - $this->assignedSuppliers['_suppliers_id_assign'][] = $userId; - $this->assignedSuppliers['_suppliers_id_assign_notif']['use_notification'][] = ($notify == true); - $this->assignedSuppliers['_suppliers_id_assign_notif']['alternative_email'][] = $alternativeEmail; + $actorType = &$this->assignedSuppliers['_suppliers_id_assign']; break; + default: + return false; } + $actorType[] = $userId; + $actorType['use_notification'][] = ($notify == true); + $actorType['alternative_email'][] = $alternativeEmail; + + return true; } - protected function addGroupActor($role, $group) { + /** + * Adds a group to the given actor role + * + * @param string $role Role of the group + * @param string $group Group ID + */ + protected function addGroupActor($role, $group) { switch ($role) { case 'requester': $this->requesterGroups['_groups_id_requester'][] = $group; From d5d4e0c44f59bb459671dba4eabcd810db8ec7ae Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Sun, 9 Sep 2018 22:18:53 +0200 Subject: [PATCH 060/192] fix(target): deduplicate actors if an actor is added several times (from ticket template and form settings) then unicity in SQL fails and breaks target creation @see #1089 Signed-off-by: Thierry Bugier --- inc/targetbase.class.php | 55 ++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index 0005db8cd..0b449aca0 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -59,7 +59,7 @@ abstract public function export($remove_uuid = false); abstract public function save(PluginFormcreatorForm_Answer $formanswer); /** - * Gets an instance object for the relation between the target itemtype + * Gets an instance object for the relation between the target itemtype * and an user * * @return CommonDBTM @@ -67,7 +67,7 @@ abstract public function save(PluginFormcreatorForm_Answer $formanswer); abstract protected function getItem_User(); /** - * Gets an instance object for the relation between the target itemtype + * Gets an instance object for the relation between the target itemtype * and a group * * @return CommonDBTM @@ -75,7 +75,7 @@ abstract protected function getItem_User(); abstract protected function getItem_Group(); /** - * Gets an instance object for the relation between the target itemtype + * Gets an instance object for the relation between the target itemtype * and supplier * * @return CommonDBTM @@ -83,7 +83,7 @@ abstract protected function getItem_Group(); abstract protected function getItem_Supplier(); /** - * Gets an instance object for the relation between the target itemtype + * Gets an instance object for the relation between the target itemtype * and an object of any itemtype * * @return CommonDBTM @@ -304,7 +304,7 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF * @param string $role role of the user * @param string $user user ID or email address for anonymous users * @param boolean $notify true to enable notification for the actor - * @return void + * @return boolean true on success, false on error */ protected function addActor($role, $user, $notify) { if (filter_var($user, FILTER_VALIDATE_EMAIL) !== false) { @@ -320,25 +320,40 @@ protected function addActor($role, $user, $notify) { } $actorType = null; + $actorTypeNotif = null; switch ($role) { case 'requester': $actorType = &$this->requesters['_users_id_requester']; + $actorTypeNotif = &$this->requesters['_users_id_requester_notif']; break; case 'observer': $actorType = &$this->observers['_users_id_observer']; + $actorTypeNotif = &$this->observers['_users_id_observer_notif']; break; case 'assigned' : $actorType = &$this->assigned['_users_id_assign']; + $actorTypeNotif = &$this->assigned['_users_id_assign_notif']; break; case 'supplier' : $actorType = &$this->assignedSuppliers['_suppliers_id_assign']; + $actorTypeNotif = &$this->assignedSuppliers['_suppliers_id_assign_notif']; break; default: return false; } - $actorType[] = $userId; - $actorType['use_notification'][] = ($notify == true); - $actorType['alternative_email'][] = $alternativeEmail; + + $actorKey = array_search($userId, $actorType); + if ($actorKey === false) { + // Add the actor + $actorType[] = $userId; + $actorTypeNotif['use_notification'][] = ($notify == true); + $actorTypeNotif['alternative_email'][] = $alternativeEmail; + } else { + // New actor settings takes precedence + $actorType[$actorKey] = $userId; + $actorTypeNotif['use_notification'][$actorKey] = ($notify == true); + $actorTypeNotif['alternative_email'][$actorKey] = $alternativeEmail; + } return true; } @@ -347,20 +362,34 @@ protected function addActor($role, $user, $notify) { * Adds a group to the given actor role * * @param string $role Role of the group - * @param string $group Group ID + * @param string $group Group ID + * @return boolean true on sucess, false on error */ - protected function addGroupActor($role, $group) { + protected function addGroupActor($role, $group) { + $actorType = null; switch ($role) { case 'requester': - $this->requesterGroups['_groups_id_requester'][] = $group; + $actorType = &$this->requesterGroups['_groups_id_requester']; break; case 'observer' : - $this->observerGroups['_groups_id_observer'][] = $group; + $actorType = &$this->observerGroups['_groups_id_observer']; break; case 'assigned' : - $this->assignedGroups['_groups_id_assign'][] = $group; + $actorType = &$this->assignedGroups['_groups_id_assign']; break; + default: + return false; } + + $actorKey = array_search($userId, $actorType); + if ($actorKey !== false) { + return false; + } + + // Add the group actor + $actorType[] = $group; + + return true; } /** From 125baf0112e4f7dd31ee7284bbdfc0f53b248ac2 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 4 Sep 2018 16:46:01 +0200 Subject: [PATCH 061/192] style: correct phpdoc and indentation Signed-off-by: btry --- inc/field.class.php | 12 ------------ inc/fieldinterface.class.php | 6 ++++++ install/update_2.6_2.7.php | 4 ++-- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/inc/field.class.php b/inc/field.class.php index 798110383..d84dbeb27 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -54,22 +54,10 @@ public function __construct($fields, $data = []) { $this->fields['answer'] = $data; } - /** - * Transform input to properly save it in the database - * - * @param array $input data to transform before save - * - * @return array input data to save as is - */ public function prepareQuestionInputForSave($input) { return $input; } - /** - * Prepares an answer value for output in a target object - * @param string|array $input the answer to format for a target (ticket or change) - * @return string - */ public function prepareQuestionInputForTarget($input) { return Toolbox::addslashes_deep($input); } diff --git a/inc/fieldinterface.class.php b/inc/fieldinterface.class.php index 95cea895f..4ca9b8d7b 100644 --- a/inc/fieldinterface.class.php +++ b/inc/fieldinterface.class.php @@ -51,6 +51,12 @@ public static function getJSFields(); * @return array|false input data to save or false if data is rejected */ public function prepareQuestionInputForSave($input); + + /** + * Prepares an answer value for output in a target object + * @param string|array $input the answer to format for a target (ticket or change) + * @return string + */ public function prepareQuestionInputForTarget($input); /** diff --git a/install/update_2.6_2.7.php b/install/update_2.6_2.7.php index 62381b7ff..151ad43d8 100644 --- a/install/update_2.6_2.7.php +++ b/install/update_2.6_2.7.php @@ -50,8 +50,8 @@ function plugin_formcreator_update_2_7(Migration $migration) { $migration->dropField($table, 'regex'); } - // Migrate range question parameters - $table = 'glpi_plugin_formcreator_questions'; + // Migrate range question parameters + $table = 'glpi_plugin_formcreator_questions'; if ($DB->fieldExists($table, 'range_min')) { $request = [ 'FROM' => $table, From 3aaf2c6f9cf19741d39d393ec1926b983f01bc97 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 4 Sep 2018 16:47:56 +0200 Subject: [PATCH 062/192] refactor: rename method Signed-off-by: btry --- inc/field.class.php | 8 ++++---- inc/fieldinterface.class.php | 2 +- inc/fields/checkboxesfield.class.php | 4 ++-- inc/fields/floatfield.class.php | 4 ++-- inc/fields/integerfield.class.php | 4 ++-- inc/fields/multiselectfield.class.php | 4 ++-- inc/fields/textfield.class.php | 4 ++-- inc/form.class.php | 2 +- inc/question.class.php | 12 ++++++------ inc/questionparameter.class.php | 2 +- inc/section.class.php | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/inc/field.class.php b/inc/field.class.php index d84dbeb27..2af203b00 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -206,7 +206,7 @@ public function getFieldTypeName() { return strtolower($matches[1]); } - public function getUsedParameters() { + public function getEmptyParameters() { return []; } @@ -216,7 +216,7 @@ public final function addParameters(PluginFormcreatorQuestion $question, array $ return; } - foreach ($this->getUsedParameters() as $fieldName => $parameter) { + foreach ($this->getEmptyParameters() as $fieldName => $parameter) { $input['_parameters'][$fieldTypeName][$fieldName]['plugin_formcreator_questions_id'] = $question->getID(); $parameter->add($input['_parameters'][$fieldTypeName][$fieldName]); } @@ -228,7 +228,7 @@ public final function updateParameters(PluginFormcreatorQuestion $question, arra return; } - foreach ($this->getUsedParameters() as $fieldName => $parameter) { + foreach ($this->getEmptyParameters() as $fieldName => $parameter) { $parameter->getFromDBByCrit([ 'plugin_formcreator_questions_id' => $question->getID(), 'fieldname' => $fieldName, @@ -245,7 +245,7 @@ public final function updateParameters(PluginFormcreatorQuestion $question, arra } public final function deleteParameters(PluginFormcreatorQuestion $question) { - foreach ($this->getUsedParameters() as $parameter) { + foreach ($this->getEmptyParameters() as $parameter) { if (!$parameter->deleteByCriteria(['plugin_formcreator_questions_id' => $question->getID()])) { // Don't make this error fatal, but log it anyway Toolbox::logInFile('php-errors', 'failed to delete parameter for question ' . $question->getID() . PHP_EOL); diff --git a/inc/fieldinterface.class.php b/inc/fieldinterface.class.php index 4ca9b8d7b..a76effb1d 100644 --- a/inc/fieldinterface.class.php +++ b/inc/fieldinterface.class.php @@ -71,7 +71,7 @@ public function prepareQuestionValuesForEdit($input); * Gets the parameters of the field * @return PluginFormcreatorQuestionParameter[] */ - public function getUsedParameters(); + public function getEmptyParameters(); /** * Gets the name of the field type diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index 9c9a988d2..54f387a35 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -118,7 +118,7 @@ public function isValid($value) { } private function isValidValue($value) { - $parameters = $this->getUsedParameters(); + $parameters = $this->getEmptyParameters(); foreach ($parameters as $fieldname => $parameter) { $parameter->getFromDBByCrit([ 'plugin_formcreator_questions_id' => $this->fields['id'], @@ -231,7 +231,7 @@ public static function getJSFields() { return "tab_fields_fields['checkboxes'] = 'showFields(" . implode(', ', $prefs) . ");';"; } - public function getUsedParameters() { + public function getEmptyParameters() { return [ 'range' => new PluginFormcreatorQuestionRange( $this, diff --git a/inc/fields/floatfield.class.php b/inc/fields/floatfield.class.php index a70383e01..5fcdfa7d6 100644 --- a/inc/fields/floatfield.class.php +++ b/inc/fields/floatfield.class.php @@ -51,7 +51,7 @@ private function isValidValue($value) { return false; } - $parameters = $this->getUsedParameters(); + $parameters = $this->getEmptyParameters(); foreach ($parameters as $fieldname => $parameter) { $parameter->getFromDBByCrit([ 'plugin_formcreator_questions_id' => $this->fields['id'], @@ -149,7 +149,7 @@ public static function getJSFields() { return "tab_fields_fields['float'] = 'showFields(" . implode(', ', $prefs) . ");';"; } - public function getUsedParameters() { + public function getEmptyParameters() { $regexDoc = ''; $regexDoc.= ''; $regexDoc.= '('.__('Regular expression', 'formcreator').')'; diff --git a/inc/fields/integerfield.class.php b/inc/fields/integerfield.class.php index 9834835d2..c99e020cd 100644 --- a/inc/fields/integerfield.class.php +++ b/inc/fields/integerfield.class.php @@ -51,7 +51,7 @@ private function isValidValue($value) { return false; } - $parameters = $this->getUsedParameters(); + $parameters = $this->getEmptyParameters(); foreach ($parameters as $fieldname => $parameter) { $parameter->getFromDBByCrit([ 'plugin_formcreator_questions_id' => $this->fields['id'], @@ -149,7 +149,7 @@ public static function getJSFields() { return "tab_fields_fields['integer'] = 'showFields(" . implode(', ', $prefs) . ");';"; } - public function getUsedParameters() { + public function getEmptyParameters() { $regexDoc = ''; $regexDoc.= ''; $regexDoc.= '('.__('Regular expression', 'formcreator').')'; diff --git a/inc/fields/multiselectfield.class.php b/inc/fields/multiselectfield.class.php index 276ec85d7..163b7b3b7 100644 --- a/inc/fields/multiselectfield.class.php +++ b/inc/fields/multiselectfield.class.php @@ -55,7 +55,7 @@ public function isValid($value) { } private function isValidValue($value) { - $parameters = $this->getUsedParameters(); + $parameters = $this->getEmptyParameters(); foreach ($parameters as $fieldname => $parameter) { $parameter->getFromDBByCrit([ 'plugin_formcreator_questions_id' => $this->fields['id'], @@ -170,7 +170,7 @@ public static function getJSFields() { return "tab_fields_fields['multiselect'] = 'showFields(" . implode(', ', $prefs) . ");';"; } - public function getUsedParameters() { + public function getEmptyParameters() { return [ 'range' => new PluginFormcreatorQuestionRange( $this, diff --git a/inc/fields/textfield.class.php b/inc/fields/textfield.class.php index 058bc3540..682716be4 100644 --- a/inc/fields/textfield.class.php +++ b/inc/fields/textfield.class.php @@ -49,7 +49,7 @@ public function isValid($value) { } private function isValidValue($value) { - $parameters = $this->getUsedParameters(); + $parameters = $this->getEmptyParameters(); foreach ($parameters as $fieldname => $parameter) { $parameter->getFromDBByCrit([ 'plugin_formcreator_questions_id' => $this->fields['id'], @@ -131,7 +131,7 @@ public static function getJSFields() { return "tab_fields_fields['text'] = 'showFields(" . implode(', ', $prefs) . ");';"; } - public function getUsedParameters() { + public function getEmptyParameters() { $regexDoc = ''; $regexDoc.= ''; $regexDoc.= '('.__('Regular expression', 'formcreator').')'; diff --git a/inc/form.class.php b/inc/form.class.php index b3c66b60d..4c222489b 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1358,7 +1358,7 @@ public function duplicate() { $oldQuestion = new PluginFormcreatorQuestion(); $oldQuestion->getFromDB($questions_id); $field = PluginFormcreatorFields::getFieldInstance($oldQuestion->fields['fieldtype'], $oldQuestion); - $parameters = $field->getUsedParameters(); + $parameters = $field->getEmptyParameters(); foreach ($parameters as $fieldName => $parameter) { $parameter->getFromDBByCrit([ 'plugin_formcreator_questions_id' => $questions_id, diff --git a/inc/question.class.php b/inc/question.class.php index c71ba2c6b..0935ab86b 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -317,7 +317,7 @@ private function checkBeforeSave($input) { $this->field = PluginFormcreatorFields::getFieldInstance($input['fieldtype'], $this); // Check the parameters are provided - $parameters = $this->field->getUsedParameters(); + $parameters = $this->field->getEmptyParameters(); if (count($parameters) > 0) { if (!isset($input['_parameters'][$input['fieldtype']])) { // This should not happen @@ -623,7 +623,7 @@ public function updateParameters($input) { } $this->field = PluginFormcreatorFields::getFieldInstance($input['fieldtype'], $this); - $parameters = $this->field->getUsedParameters(); + $parameters = $this->field->getEmptyParameters(); if (isset($input['_parameters'][$this->fields['fieldtype']])) { foreach ($input['_parameters'][$this->fields['fieldtype']] as $fieldName => $parameterInput) { // echo var_dump($parameterInput); @@ -860,7 +860,7 @@ function plugin_formcreator_changeQuestionType() { $showHideForFieldTypeJs.= "case '$fieldType':" . "\n"; $field = new $classname([]); $evenColumnGroup = 0; - foreach ($field->getUsedParameters() as $parameter) { + foreach ($field->getEmptyParameters() as $parameter) { $evenColumnGroup++; if ($parameter->getParameterFormSize() > 0) { // The parameter needs a 4 columns to show its form @@ -1343,7 +1343,7 @@ public function duplicate() { // Form questions parameters $this->field = PluginFormcreatorFields::getFieldInstance($this->getField('fieldtype'), $this); - $parameters = $this->field->getUsedParameters(); + $parameters = $this->field->getEmptyParameters(); foreach ($parameters as $fieldName => $parameter) { $parameter->getFromDBByCrit([ 'plugin_formcreator_questions_id' => $oldQuestionId, @@ -1433,7 +1433,7 @@ public static function import(PluginFormcreatorImportLinker $importLinker, $sect } $field = PluginFormcreatorFields::getFieldInstance($question['fieldtype'], $question); - $parameters = $field->getUsedParameters(); + $parameters = $field->getEmptyParameters(); foreach ($parameters as $fieldName => $parameter) { $parameter->getFromDBByCrit([ 'plugin_formcreator_questions_id' => $item->fields['id'], @@ -1476,7 +1476,7 @@ public function export($remove_uuid = false) { // get question parameters $question['_parameters'] = []; $this->field = PluginFormcreatorFields::getFieldIntance($this->getField('fieldtype'), $this); - $parameters = $this->field->getUsedParameters(); + $parameters = $this->field->getEmptyParameters(); foreach ($parameters as $fieldname => $parameter) { $parameter->getFromDBByCrit([ 'plugin_formcreator_questions_id' => $this->fields['id'], diff --git a/inc/questionparameter.class.php b/inc/questionparameter.class.php index 03a0be8f1..b4f47d42e 100644 --- a/inc/questionparameter.class.php +++ b/inc/questionparameter.class.php @@ -105,7 +105,7 @@ public static function import(PluginFormcreatorImportLinker $importLinker, $ques $question = new PluginFormcreatorquestion(); $question->getFromDB($questions_id); $field = PluginFormcreatorFields::getFieldIntance($question->getField('fieldtype'), $question); - $parameters = $field->getUsedParameters(); + $parameters = $field->getEmptyParameters(); $item = $parameters[$fieldName]; $found = $item->getFromDBByCrit([ 'plugin_formcreator_questions_id' => $questions_id, diff --git a/inc/section.class.php b/inc/section.class.php index d7d3fa9f5..c4d4858c0 100644 --- a/inc/section.class.php +++ b/inc/section.class.php @@ -191,7 +191,7 @@ public function duplicate() { $oldQuestion = new PluginFormcreatorQuestion(); $oldQuestion->getFromDB($questions_id); $this->field = PluginFormcreatorFields::getFieldInstance($oldQuestion->getField('fieldtype'), $oldQuestion); - $parameters = $this->field->getUsedParameters(); + $parameters = $this->field->getEmptyParameters(); foreach ($parameters as $fieldName => $parameter) { $parameter->getFromDBByCrit([ 'plugin_formcreator_questions_id' => $questions_id, From fad88ce0e9d53a5228a2c23fb2786a1abddd0437 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 4 Sep 2018 17:03:03 +0200 Subject: [PATCH 063/192] refactor: factorize parameters loading Signed-off-by: btry --- inc/field.class.php | 34 +++++++++++++-------------- inc/fieldinterface.class.php | 21 +++++++++++++++++ inc/fields/checkboxesfield.class.php | 8 +------ inc/fields/floatfield.class.php | 8 +------ inc/fields/integerfield.class.php | 8 +------ inc/fields/multiselectfield.class.php | 8 +------ inc/fields/textfield.class.php | 8 +------ inc/form.class.php | 6 +---- inc/question.class.php | 25 ++++---------------- inc/section.class.php | 6 +---- 10 files changed, 49 insertions(+), 83 deletions(-) diff --git a/inc/field.class.php b/inc/field.class.php index 2af203b00..7debb8be9 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -158,13 +158,6 @@ public function getAvailableValues() { return explode("\r\n", $this->fields['values']); } - /** - * Is the field valid for the given value? - * - * @param string $value - * - * @return boolean True if the field has a valid value, false otherwise - */ public function isValid($value) { // If the field is required it can't be empty if ($this->isRequired() && empty($value)) { @@ -179,11 +172,6 @@ public function isValid($value) { return true; } - /** - * Is the field required? - * - * @return boolean - */ public function isRequired() { return $this->fields['required']; } @@ -210,6 +198,21 @@ public function getEmptyParameters() { return []; } + public final function getParameters() { + $parameters = $this->getEmptyParameters(); + foreach ($parameters as $fieldname => $parameter) { + $parameter->getFromDBByCrit([ + 'plugin_formcreator_questions_id' => $this->fields['id'], + 'fieldname' => $fieldname, + ]); + if ($parameter->isNewItem()) { + $parameter->getEmpty(); + } + } + + return $parameters; + } + public final function addParameters(PluginFormcreatorQuestion $question, array $input) { $fieldTypeName = $this->getFieldTypeName(); if (!isset($input['_parameters'][$fieldTypeName])) { @@ -228,11 +231,8 @@ public final function updateParameters(PluginFormcreatorQuestion $question, arra return; } - foreach ($this->getEmptyParameters() as $fieldName => $parameter) { - $parameter->getFromDBByCrit([ - 'plugin_formcreator_questions_id' => $question->getID(), - 'fieldname' => $fieldName, - ]); + $parameters = $this->getParameters(); + foreach ($parameters as $fieldName => $parameter) { $input['_parameters'][$fieldTypeName][$fieldName]['plugin_formcreator_questions_id'] = $question->getID(); if ($parameter->isNewItem()) { // In case of the parameter vanished in DB, just recreate it diff --git a/inc/fieldinterface.class.php b/inc/fieldinterface.class.php index a76effb1d..a397a94f8 100644 --- a/inc/fieldinterface.class.php +++ b/inc/fieldinterface.class.php @@ -42,9 +42,24 @@ interface PluginFormcreatorFieldInterface * @return string */ public static function getName(); + public static function getPrefs(); + public static function getJSFields(); + /** + * Is the field valid for the given value? + * @param string $value + * @return boolean True if the field has a valid value, false otherwise + */ + public function isValid($value); + + /** + * Is the field required? + * @return boolean + */ + public function isRequired(); + /** * Transform input to properly save it in the database * @param array $input data to transform before save @@ -73,6 +88,12 @@ public function prepareQuestionValuesForEdit($input); */ public function getEmptyParameters(); + /** + * Gets parameters of the field with their settings + * @return PluginFormcreatorQuestionParameterInterface[] + */ + public function getParameters(); + /** * Gets the name of the field type * @return string diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index 54f387a35..51f3586dd 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -118,13 +118,7 @@ public function isValid($value) { } private function isValidValue($value) { - $parameters = $this->getEmptyParameters(); - foreach ($parameters as $fieldname => $parameter) { - $parameter->getFromDBByCrit([ - 'plugin_formcreator_questions_id' => $this->fields['id'], - 'fieldname' => $fieldname, - ]); - } + $parameters = $this->getParameters(); // Check the field matches the format regex if (!$parameters['range']->isNewItem()) { diff --git a/inc/fields/floatfield.class.php b/inc/fields/floatfield.class.php index 5fcdfa7d6..90ce55f4c 100644 --- a/inc/fields/floatfield.class.php +++ b/inc/fields/floatfield.class.php @@ -51,13 +51,7 @@ private function isValidValue($value) { return false; } - $parameters = $this->getEmptyParameters(); - foreach ($parameters as $fieldname => $parameter) { - $parameter->getFromDBByCrit([ - 'plugin_formcreator_questions_id' => $this->fields['id'], - 'fieldname' => $fieldname, - ]); - } + $parameters = $this->getParameters(); // Check the field matches the format regex if (!$parameters['regex']->isNewItem()) { diff --git a/inc/fields/integerfield.class.php b/inc/fields/integerfield.class.php index c99e020cd..5ac98f7c3 100644 --- a/inc/fields/integerfield.class.php +++ b/inc/fields/integerfield.class.php @@ -51,13 +51,7 @@ private function isValidValue($value) { return false; } - $parameters = $this->getEmptyParameters(); - foreach ($parameters as $fieldname => $parameter) { - $parameter->getFromDBByCrit([ - 'plugin_formcreator_questions_id' => $this->fields['id'], - 'fieldname' => $fieldname, - ]); - } + $parameters = $this->getParameters(); // Check the field matches the format regex if (!$parameters['regex']->isNewItem()) { diff --git a/inc/fields/multiselectfield.class.php b/inc/fields/multiselectfield.class.php index 163b7b3b7..aa449a026 100644 --- a/inc/fields/multiselectfield.class.php +++ b/inc/fields/multiselectfield.class.php @@ -55,13 +55,7 @@ public function isValid($value) { } private function isValidValue($value) { - $parameters = $this->getEmptyParameters(); - foreach ($parameters as $fieldname => $parameter) { - $parameter->getFromDBByCrit([ - 'plugin_formcreator_questions_id' => $this->fields['id'], - 'fieldname' => $fieldname, - ]); - } + $parameters = $this->getParameters(); // Check the field matches the format regex $rangeMin = $parameters['range']->getField('range_min'); diff --git a/inc/fields/textfield.class.php b/inc/fields/textfield.class.php index 682716be4..5d67bfe69 100644 --- a/inc/fields/textfield.class.php +++ b/inc/fields/textfield.class.php @@ -49,13 +49,7 @@ public function isValid($value) { } private function isValidValue($value) { - $parameters = $this->getEmptyParameters(); - foreach ($parameters as $fieldname => $parameter) { - $parameter->getFromDBByCrit([ - 'plugin_formcreator_questions_id' => $this->fields['id'], - 'fieldname' => $fieldname, - ]); - } + $parameters = $this->getParameters(); // Check the field matches the format regex $regex = $parameters['regex']->getField('regex'); diff --git a/inc/form.class.php b/inc/form.class.php index 4c222489b..525effbcc 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1358,12 +1358,8 @@ public function duplicate() { $oldQuestion = new PluginFormcreatorQuestion(); $oldQuestion->getFromDB($questions_id); $field = PluginFormcreatorFields::getFieldInstance($oldQuestion->fields['fieldtype'], $oldQuestion); - $parameters = $field->getEmptyParameters(); + $parameters = $this->getParameters(); foreach ($parameters as $fieldName => $parameter) { - $parameter->getFromDBByCrit([ - 'plugin_formcreator_questions_id' => $questions_id, - 'fieldname' => $fieldName, - ]); $newQuestion = new PluginFormcreatorQuestion(); $newQuestion->getFromDB($new_questions_id); $parameter = $parameter->duplicate($newQuestion, $tab_questions); diff --git a/inc/question.class.php b/inc/question.class.php index 0935ab86b..1f0f54894 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -623,14 +623,9 @@ public function updateParameters($input) { } $this->field = PluginFormcreatorFields::getFieldInstance($input['fieldtype'], $this); - $parameters = $this->field->getEmptyParameters(); + $parameters = $this->getParameters(); if (isset($input['_parameters'][$this->fields['fieldtype']])) { foreach ($input['_parameters'][$this->fields['fieldtype']] as $fieldName => $parameterInput) { - // echo var_dump($parameterInput); - $parameters[$fieldName]->getFromDBByCrit([ - 'plugin_formcreator_questions_id' => $this->getID(), - 'fieldname' => $fieldName, - ]); $parameterInput['plugin_formcreator_questions_id'] = $this->getID(); if ($parameters[$fieldName]->isNewItem()) { $parameters[$fieldName]->add($parameterInput); @@ -1343,12 +1338,8 @@ public function duplicate() { // Form questions parameters $this->field = PluginFormcreatorFields::getFieldInstance($this->getField('fieldtype'), $this); - $parameters = $this->field->getEmptyParameters(); + $parameters = $this->getParameters(); foreach ($parameters as $fieldName => $parameter) { - $parameter->getFromDBByCrit([ - 'plugin_formcreator_questions_id' => $oldQuestionId, - 'fieldname' => $fieldName, - ]); $row = $parameter->fields; $row[PluginFormcreatorQuestion::getForeignKeyField()] = $newQuestion->getID(); unset($row['id']); @@ -1433,12 +1424,8 @@ public static function import(PluginFormcreatorImportLinker $importLinker, $sect } $field = PluginFormcreatorFields::getFieldInstance($question['fieldtype'], $question); - $parameters = $field->getEmptyParameters(); + $parameters = $field->getParameters(); foreach ($parameters as $fieldName => $parameter) { - $parameter->getFromDBByCrit([ - 'plugin_formcreator_questions_id' => $item->fields['id'], - 'fieldname' => $fieldName, - ]); $parameter::import($importLinker, $questions_id, $fieldName, $question['_parameters'][$question['fieldtype']][$fieldName]); } } @@ -1476,12 +1463,8 @@ public function export($remove_uuid = false) { // get question parameters $question['_parameters'] = []; $this->field = PluginFormcreatorFields::getFieldIntance($this->getField('fieldtype'), $this); - $parameters = $this->field->getEmptyParameters(); + $parameters = $this->field->getParameters(); foreach ($parameters as $fieldname => $parameter) { - $parameter->getFromDBByCrit([ - 'plugin_formcreator_questions_id' => $this->fields['id'], - 'fieldname' => $fieldname, - ]); $question['_parameters'][$this->fields['fieldtype']][$fieldname] = $parameter->export(); } diff --git a/inc/section.class.php b/inc/section.class.php index c4d4858c0..f4729ec8f 100644 --- a/inc/section.class.php +++ b/inc/section.class.php @@ -191,12 +191,8 @@ public function duplicate() { $oldQuestion = new PluginFormcreatorQuestion(); $oldQuestion->getFromDB($questions_id); $this->field = PluginFormcreatorFields::getFieldInstance($oldQuestion->getField('fieldtype'), $oldQuestion); - $parameters = $this->field->getEmptyParameters(); + $parameters = $this->field->getParameters(); foreach ($parameters as $fieldName => $parameter) { - $parameter->getFromDBByCrit([ - 'plugin_formcreator_questions_id' => $questions_id, - 'fieldname' => $fieldName, - ]); if (!$parameter->isNewItem()) { // Should always happen $newQuestion = new PluginFormcreatorQuestion(); From 3f100307d0c2fe7b770e4019d3c6a918adb1b100 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 4 Sep 2018 17:28:17 +0200 Subject: [PATCH 064/192] fix(questionparameter): if the parameter is missing in the db, use default values Signed-off-by: btry --- inc/fields/checkboxesfield.class.php | 4 ++-- inc/fields/floatfield.class.php | 6 +++--- inc/fields/integerfield.class.php | 6 +++--- inc/fields/multiselectfield.class.php | 4 ++-- inc/fields/textfield.class.php | 6 +++--- inc/form.class.php | 2 +- inc/question.class.php | 4 ++-- inc/questionrange.class.php | 5 +++++ inc/questionregex.class.php | 4 ++++ 9 files changed, 25 insertions(+), 16 deletions(-) diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index 51f3586dd..3ea802da7 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -122,8 +122,8 @@ private function isValidValue($value) { // Check the field matches the format regex if (!$parameters['range']->isNewItem()) { - $rangeMin = $parameters['range']->getField('range_min'); - $rangeMax = $parameters['range']->getField('range_max'); + $rangeMin = $parameters['range']->fields['range_min']; + $rangeMax = $parameters['range']->fields['range_max']; if (strlen($rangeMin) > 0 && count($value) < $rangeMin) { $message = sprintf(__('The following question needs of at least %d answers', 'formcreator'), $rangeMin); Session::addMessageAfterRedirect($message . ' ' . $this->getLabel(), false, ERROR); diff --git a/inc/fields/floatfield.class.php b/inc/fields/floatfield.class.php index 90ce55f4c..e70d24a65 100644 --- a/inc/fields/floatfield.class.php +++ b/inc/fields/floatfield.class.php @@ -55,7 +55,7 @@ private function isValidValue($value) { // Check the field matches the format regex if (!$parameters['regex']->isNewItem()) { - $regex = $parameters['regex']->getField('regex'); + $regex = $parameters['regex']->fields['regex']; if ($regex !== null && strlen($regex) > 0) { if (!preg_match($regex, $value)) { Session::addMessageAfterRedirect(__('Specific format does not match:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); @@ -66,8 +66,8 @@ private function isValidValue($value) { // Check the field is in the range if (!$parameters['range']->isNewItem()) { - $rangeMin = $parameters['range']->getField('range_min'); - $rangeMax = $parameters['range']->getField('range_max'); + $rangeMin = $parameters['range']->fields['range_min']; + $rangeMax = $parameters['range']->fields['range_max']; if (strlen($rangeMin) > 0 && $value < $rangeMin) { $message = sprintf(__('The following number must be greater than %d:', 'formcreator'), $rangeMin); Session::addMessageAfterRedirect($message . ' ' . $this->fields['name'], false, ERROR); diff --git a/inc/fields/integerfield.class.php b/inc/fields/integerfield.class.php index 5ac98f7c3..cdaf53126 100644 --- a/inc/fields/integerfield.class.php +++ b/inc/fields/integerfield.class.php @@ -55,7 +55,7 @@ private function isValidValue($value) { // Check the field matches the format regex if (!$parameters['regex']->isNewItem()) { - $regex = $parameters['regex']->getField('regex'); + $regex = $parameters['regex']->fields['regex']; if ($regex !== null && strlen($regex) > 0) { if (!preg_match($regex, $value)) { Session::addMessageAfterRedirect(__('Specific format does not match:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); @@ -66,8 +66,8 @@ private function isValidValue($value) { // Check the field is in the range if (!$parameters['range']->isNewItem()) { - $rangeMin = $parameters['range']->getField('range_min'); - $rangeMax = $parameters['range']->getField('range_max'); + $rangeMin = $parameters['range']->fields['range_min']; + $rangeMax = $parameters['range']->fields['range_max']; if (strlen($rangeMin) > 0 && $value < $rangeMin) { $message = sprintf(__('The following number must be greater than %d:', 'formcreator'), $rangeMin); Session::addMessageAfterRedirect($message . ' ' . $this->fields['name'], false, ERROR); diff --git a/inc/fields/multiselectfield.class.php b/inc/fields/multiselectfield.class.php index aa449a026..af70fa1b1 100644 --- a/inc/fields/multiselectfield.class.php +++ b/inc/fields/multiselectfield.class.php @@ -58,8 +58,8 @@ private function isValidValue($value) { $parameters = $this->getParameters(); // Check the field matches the format regex - $rangeMin = $parameters['range']->getField('range_min'); - $rangeMax = $parameters['range']->getField('range_max'); + $rangeMin = $parameters['range']->fields['range_min']; + $rangeMax = $parameters['range']->fields['range_max']; if (strlen($rangeMin) > 0 && count($value) < $rangeMin) { $message = sprintf(__('The following question needs of at least %d answers', 'formcreator'), $rangeMin); Session::addMessageAfterRedirect($message . ' ' . $this->getLabel(), false, ERROR); diff --git a/inc/fields/textfield.class.php b/inc/fields/textfield.class.php index 5d67bfe69..d56469e0c 100644 --- a/inc/fields/textfield.class.php +++ b/inc/fields/textfield.class.php @@ -52,7 +52,7 @@ private function isValidValue($value) { $parameters = $this->getParameters(); // Check the field matches the format regex - $regex = $parameters['regex']->getField('regex'); + $regex = $parameters['regex']->fields['regex']; if ($regex !== null && strlen($regex) > 0) { if (!preg_match($regex, $value)) { Session::addMessageAfterRedirect(__('Specific format does not match:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); @@ -61,8 +61,8 @@ private function isValidValue($value) { } // Check the field is in the range - $rangeMin = $parameters['range']->getField('range_min'); - $rangeMax = $parameters['range']->getField('range_max'); + $rangeMin = $parameters['range']->fields['range_min']; + $rangeMax = $parameters['range']->fields['range_max']; if (strlen($rangeMin) > 0 && strlen($value) < $rangeMin) { Session::addMessageAfterRedirect(sprintf(__('The text is too short (minimum %d characters):', 'formcreator'), $rangeMin) . ' ' . $this->fields['name'], false, ERROR); return false; diff --git a/inc/form.class.php b/inc/form.class.php index 525effbcc..963f6f648 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1358,7 +1358,7 @@ public function duplicate() { $oldQuestion = new PluginFormcreatorQuestion(); $oldQuestion->getFromDB($questions_id); $field = PluginFormcreatorFields::getFieldInstance($oldQuestion->fields['fieldtype'], $oldQuestion); - $parameters = $this->getParameters(); + $parameters = $field->getParameters(); foreach ($parameters as $fieldName => $parameter) { $newQuestion = new PluginFormcreatorQuestion(); $newQuestion->getFromDB($new_questions_id); diff --git a/inc/question.class.php b/inc/question.class.php index 1f0f54894..6bb18cd37 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -623,7 +623,7 @@ public function updateParameters($input) { } $this->field = PluginFormcreatorFields::getFieldInstance($input['fieldtype'], $this); - $parameters = $this->getParameters(); + $parameters = $this->field->getParameters(); if (isset($input['_parameters'][$this->fields['fieldtype']])) { foreach ($input['_parameters'][$this->fields['fieldtype']] as $fieldName => $parameterInput) { $parameterInput['plugin_formcreator_questions_id'] = $this->getID(); @@ -1338,7 +1338,7 @@ public function duplicate() { // Form questions parameters $this->field = PluginFormcreatorFields::getFieldInstance($this->getField('fieldtype'), $this); - $parameters = $this->getParameters(); + $parameters = $this->field->getParameters(); foreach ($parameters as $fieldName => $parameter) { $row = $parameter->fields; $row[PluginFormcreatorQuestion::getForeignKeyField()] = $newQuestion->getID(); diff --git a/inc/questionrange.class.php b/inc/questionrange.class.php index 70a728aa6..3fd7ffbf9 100644 --- a/inc/questionrange.class.php +++ b/inc/questionrange.class.php @@ -76,6 +76,11 @@ public function getParameterForm(PluginFormcreatorForm $form, PluginFormcreatorQ return $out; } + public function post_getEmpty() { + $this->fields['range_min'] = '0'; + $this->fields['range_max'] = '0'; + } + public function getJsShowHideSelector() { return "#" . $this->domId; } diff --git a/inc/questionregex.class.php b/inc/questionregex.class.php index b916f8cd3..8fc91f840 100644 --- a/inc/questionregex.class.php +++ b/inc/questionregex.class.php @@ -72,6 +72,10 @@ public function getParameterForm(PluginFormcreatorForm $form, PluginFormcreatorQ return $out; } + public function post_getEmpty() { + $this->fields['regex'] = null; + } + public function getJsShowHideSelector() { return "#" . $this->domId; } From c00abc475ac9859ddfd654527d4953f6185d76b4 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 4 Sep 2018 17:48:06 +0200 Subject: [PATCH 065/192] test: add tests Signed-off-by: btry --- .../suite-unit/PluginFormcreatorCheckboxesField.php | 6 +++--- tests/suite-unit/PluginFormcreatorFloatField.php | 13 +++++++++++++ .../PluginFormcreatorMultiSelectField.php | 10 ++++++++++ tests/suite-unit/PluginFormcreatorTextField.php | 13 +++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/tests/suite-unit/PluginFormcreatorCheckboxesField.php b/tests/suite-unit/PluginFormcreatorCheckboxesField.php index 9efff6e57..0c17e067e 100644 --- a/tests/suite-unit/PluginFormcreatorCheckboxesField.php +++ b/tests/suite-unit/PluginFormcreatorCheckboxesField.php @@ -274,11 +274,11 @@ public function testPrepareQuestionInputForSave() { } /** - * @engine inline + * */ - public function testGetUsedParameters() { + public function testGetEmptyParameters() { $instance = $this->newTestedInstance([]); - $output = $instance->getUsedParameters(); + $output = $instance->getEmptyParameters(); $this->array($output) ->hasKey('range') ->array($output)->size->isEqualTo(1); diff --git a/tests/suite-unit/PluginFormcreatorFloatField.php b/tests/suite-unit/PluginFormcreatorFloatField.php index 33536f05f..7072072d1 100644 --- a/tests/suite-unit/PluginFormcreatorFloatField.php +++ b/tests/suite-unit/PluginFormcreatorFloatField.php @@ -188,4 +188,17 @@ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidi $isValid = $fieldInstance->isValid($fields['default_values']); $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); } + + public function testGetEmptyParameters() { + $instance = $this->newTestedInstance([]); + $output = $instance->getEmptyParameters(); + $this->array($output) + ->hasKey('range') + ->hasKey('regex') + ->array($output)->size->isEqualTo(2); + $this->object($output['range']) + ->isInstanceOf(\PluginFormcreatorQuestionRange::class); + $this->object($output['regex']) + ->isInstanceOf(\PluginFormcreatorQuestionRegex::class); + } } diff --git a/tests/suite-unit/PluginFormcreatorMultiSelectField.php b/tests/suite-unit/PluginFormcreatorMultiSelectField.php index abb6874b0..9edbbe11b 100644 --- a/tests/suite-unit/PluginFormcreatorMultiSelectField.php +++ b/tests/suite-unit/PluginFormcreatorMultiSelectField.php @@ -263,4 +263,14 @@ public function testGetName() { $output = $instance->getName(); $this->string($output)->isEqualTo('Multiselect'); } + + public function testGetEmptyParameters() { + $instance = $this->newTestedInstance([]); + $output = $instance->getEmptyParameters(); + $this->array($output) + ->hasKey('range') + ->array($output)->size->isEqualTo(1); + $this->object($output['range']) + ->isInstanceOf(\PluginFormcreatorQuestionRange::class); + } } \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorTextField.php b/tests/suite-unit/PluginFormcreatorTextField.php index 1c10cae58..33dad1629 100644 --- a/tests/suite-unit/PluginFormcreatorTextField.php +++ b/tests/suite-unit/PluginFormcreatorTextField.php @@ -186,4 +186,17 @@ public function testFieldIsValid($fields, $data, $expectedValue, $expectedValidi $isValid = $fieldInstance->isValid($fields['default_values']); $this->boolean($isValid)->isEqualTo($expectedValidity, json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); } + + public function testGetEmptyParameters() { + $instance = $this->newTestedInstance([]); + $output = $instance->getEmptyParameters(); + $this->array($output) + ->hasKey('range') + ->hasKey('regex') + ->array($output)->size->isEqualTo(2); + $this->object($output['range']) + ->isInstanceOf(\PluginFormcreatorQuestionRange::class); + $this->object($output['regex']) + ->isInstanceOf(\PluginFormcreatorQuestionRegex::class); + } } \ No newline at end of file From 39a45339baeb6aab65ab11a151a8e592e6872bee Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 3 Sep 2018 11:43:48 +0200 Subject: [PATCH 066/192] test(textareafield): add test Signed-off-by: btry --- tests/suite-unit/PluginFormcreatorTextField.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/suite-unit/PluginFormcreatorTextField.php b/tests/suite-unit/PluginFormcreatorTextField.php index 33dad1629..136e1fe49 100644 --- a/tests/suite-unit/PluginFormcreatorTextField.php +++ b/tests/suite-unit/PluginFormcreatorTextField.php @@ -199,4 +199,9 @@ public function testGetEmptyParameters() { $this->object($output['regex']) ->isInstanceOf(\PluginFormcreatorQuestionRegex::class); } -} \ No newline at end of file + + public function testGetName() { + $output = \PluginFormcreatorTextField::getName(); + $this->string($output)->isEqualTo('Text'); + } +} From 3883c1c832a7518e1fa41ffe5e0f9e86e0737713 Mon Sep 17 00:00:00 2001 From: btry Date: Wed, 12 Sep 2018 11:45:36 +0200 Subject: [PATCH 067/192] fix(form): bad quote in FORM HTML tag Signed-off-by: btry --- inc/form.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/form.class.php b/inc/form.class.php index 963f6f648..79620b45c 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -921,7 +921,7 @@ public function displayUserForm(CommonGLPI $item) { echo Html::css("plugins/formcreator/css/print_form.css", ['media' => 'print']); // Display form - echo "getID()."' method='post' role='form' enctype='multipart/form-data' + echo ""; echo "

"; From 32d940e9e9a2ddcde28608c270be19b87c0bcde4 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 6 Aug 2018 18:00:38 +0200 Subject: [PATCH 068/192] fix(install): upgrade problem in issues table" Signed-off-by: Thierry Bugier --- install/update_0.0_2.5.php | 89 +++++++++++++++++++++++++++++++++++++- install/update_2.5_2.6.php | 43 +++++++++--------- 2 files changed, 110 insertions(+), 22 deletions(-) diff --git a/install/update_0.0_2.5.php b/install/update_0.0_2.5.php index 7b02c42d4..067b620b8 100644 --- a/install/update_0.0_2.5.php +++ b/install/update_0.0_2.5.php @@ -200,6 +200,32 @@ function plugin_formcreator_updateForm_Answer_2_5(Migration $migration) { $migration->addKey('glpi_plugin_formcreator_forms_answers', 'requester_id'); $migration->addKey('glpi_plugin_formcreator_forms_answers', 'validator_id'); $migration->addField('glpi_plugin_formcreator_forms_answers', 'is_deleted', 'bool'); + + // Update Form Answers + $table = 'glpi_plugin_formcreator_forms_answers'; + + if ($DB->fieldExists($table, 'validator_id', false)) { + $migration->addField($table, 'users_id_validator', 'integer', ['after' => 'requester_id']); + $migration->addField($table, 'groups_id_validator', 'integer', ['after' => 'users_id_validator']); + $migration->addKey($table, 'users_id_validator'); + $migration->addKey($table, 'groups_id_validator'); + $migration->migrationOneTable($table); + + $formTable = 'glpi_plugin_formcreator_forms'; + $query = "UPDATE `$table` + INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) + SET `users_id_validator` = 'validator_id' + WHERE `$formTable`.`validation_required` = '1'"; + $DB->query($query) or plugin_formcreator_upgrade_error($migration); + $query = "UPDATE `$table` + INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) + SET `groups_id_validator` = 'validator_id' + WHERE `$formTable`.`validation_required` = '2'"; + $DB->query($query) or plugin_formcreator_upgrade_error($migration); + + $migration->dropKey($table, 'validator_id'); + $migration->dropField($table, 'validator_id'); + } } function plugin_formcreator_updateForm_Profile_2_5(Migration $migration) { @@ -414,8 +440,67 @@ function plugin_formcreator_updateIssue_2_5(Migration $migration) { 'mode' => CronTask::MODE_EXTERNAL ] ); - $task = new CronTask(); - PluginFormcreatorIssue::cronSyncIssues($task); + + $query = "SELECT DISTINCT + NULL AS `id`, + CONCAT('f_',`fanswer`.`id`) AS `display_id`, + `fanswer`.`id` AS `original_id`, + 'PluginFormcreatorForm_Answer' AS `sub_itemtype`, + `f`.`name` AS `name`, + `fanswer`.`status` AS `status`, + `fanswer`.`request_date` AS `date_creation`, + `fanswer`.`request_date` AS `date_mod`, + `fanswer`.`entities_id` AS `entities_id`, + `fanswer`.`is_recursive` AS `is_recursive`, + `fanswer`.`requester_id` AS `requester_id`, + `fanswer`.`users_id_validator` AS `validator_id`, + `fanswer`.`comment` AS `comment` + FROM `glpi_plugin_formcreator_forms_answers` AS `fanswer` + LEFT JOIN `glpi_plugin_formcreator_forms` AS `f` + ON`f`.`id` = `fanswer`.`plugin_formcreator_forms_id` + LEFT JOIN `glpi_items_tickets` AS `itic` + ON `itic`.`items_id` = `fanswer`.`id` + AND `itic`.`itemtype` = 'PluginFormcreatorForm_Answer' + WHERE `fanswer`.`is_deleted` = '0' + GROUP BY `original_id` + HAVING COUNT(`itic`.`tickets_id`) != 1 + + UNION + + SELECT DISTINCT + NULL AS `id`, + CONCAT('t_',`tic`.`id`) AS `display_id`, + `tic`.`id` AS `original_id`, + 'Ticket' AS `sub_itemtype`, + `tic`.`name` AS `name`, + `tic`.`status` AS `status`, + `tic`.`date` AS `date_creation`, + `tic`.`date_mod` AS `date_mod`, + `tic`.`entities_id` AS `entities_id`, + 0 AS `is_recursive`, + `tic`.`users_id_recipient` AS `requester_id`, + 0 AS `validator_id`, + `tic`.`content` AS `comment` + FROM `glpi_tickets` AS `tic` + LEFT JOIN `glpi_items_tickets` AS `itic` + ON `itic`.`tickets_id` = `tic`.`id` + AND `itic`.`itemtype` = 'PluginFormcreatorForm_Answer' + WHERE `tic`.`is_deleted` = 0 + GROUP BY `original_id` + HAVING COUNT(`itic`.`items_id`) <= 1"; + + $countQuery = "SELECT COUNT(*) AS `cpt` FROM ($query) AS `issues`"; + $result = $DB->query($countQuery); + if ($result !== false) { + $count = $DB->fetch_assoc($result); + $table = PluginFormcreatorIssue::getTable(); + if (countElementsInTable($table) != $count['cpt']) { + if ($DB->query("TRUNCATE `$table`")) { + $DB->query("INSERT INTO `$table` SELECT * FROM ($query) as `dt`"); + $volume = 1; + } + } + } } function plugin_formcreator_updateQuestionCondition_2_5(Migration $migration) { diff --git a/install/update_2.5_2.6.php b/install/update_2.5_2.6.php index f38f0c0d6..2cee84dbf 100644 --- a/install/update_2.5_2.6.php +++ b/install/update_2.5_2.6.php @@ -63,27 +63,29 @@ function plugin_formcreator_update_2_6(Migration $migration) { $table = 'glpi_plugin_formcreator_forms_answers'; $migration->displayMessage("Upgrade $table"); - $migration->addField($table, 'users_id_validator', 'integer', ['after' => 'requester_id']); - $migration->addField($table, 'groups_id_validator', 'integer', ['after' => 'users_id_validator']); - $migration->addKey($table, 'users_id_validator'); - $migration->addKey($table, 'groups_id_validator'); - $migration->migrationOneTable($table); - - $formTable = 'glpi_plugin_formcreator_forms'; - $query = "UPDATE `$table` - INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) - SET `users_id_validator` = 'validator_id' - WHERE `$formTable`.`validation_required` = '1'"; - $DB->query($query) or plugin_formcreator_upgrade_error($migration); - $query = "UPDATE `$table` - INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) - SET `groups_id_validator` = 'validator_id' - WHERE `$formTable`.`validation_required` = '2'"; - $DB->query($query) or plugin_formcreator_upgrade_error($migration); - - $migration->dropKey($table, 'validator_id'); - $migration->dropField($table, 'validator_id'); + if ($DB->fieldExists($table, 'validator_id', false)) { + $migration->addField($table, 'users_id_validator', 'integer', ['after' => 'requester_id']); + $migration->addField($table, 'groups_id_validator', 'integer', ['after' => 'users_id_validator']); + $migration->addKey($table, 'users_id_validator'); + $migration->addKey($table, 'groups_id_validator'); + $migration->migrationOneTable($table); + + $formTable = 'glpi_plugin_formcreator_forms'; + $query = "UPDATE `$table` + INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) + SET `users_id_validator` = 'validator_id' + WHERE `$formTable`.`validation_required` = '1'"; + $DB->query($query) or plugin_formcreator_upgrade_error($migration); + $query = "UPDATE `$table` + INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) + SET `groups_id_validator` = 'validator_id' + WHERE `$formTable`.`validation_required` = '2'"; + $DB->query($query) or plugin_formcreator_upgrade_error($migration); + $migration->dropKey($table, 'validator_id'); + $migration->dropField($table, 'validator_id'); + } + // add location rule $enum_location_rule = "'".implode("', '", array_keys(PluginFormcreatorTargetTicket::getEnumLocationRule()))."'"; if (!$DB->fieldExists('glpi_plugin_formcreator_targettickets', 'location_rule', false)) { @@ -135,6 +137,7 @@ function plugin_formcreator_update_2_6(Migration $migration) { $all_targetTickets = $obj->find("`uuid` IS NULL"); foreach ($all_targetTickets as $targetTicket) { $targetTicket['_skip_checks'] = true; + $targetTicket['title'] = $targetTicket['name']; $obj->update($targetTicket); } unset($obj); From 3d6917cda11efb98c09412068d3bc5bdea84d67d Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Sun, 9 Sep 2018 23:48:10 +0200 Subject: [PATCH 069/192] fix(isntal): fix upgrade to 2.5.0 Signed-off-by: Thierry Bugier --- install/update_0.0_2.5.php | 31 ++-------------------------- install/update_2.5_2.6.php | 42 ++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 51 deletions(-) diff --git a/install/update_0.0_2.5.php b/install/update_0.0_2.5.php index 067b620b8..9a43a22ad 100644 --- a/install/update_0.0_2.5.php +++ b/install/update_0.0_2.5.php @@ -200,32 +200,7 @@ function plugin_formcreator_updateForm_Answer_2_5(Migration $migration) { $migration->addKey('glpi_plugin_formcreator_forms_answers', 'requester_id'); $migration->addKey('glpi_plugin_formcreator_forms_answers', 'validator_id'); $migration->addField('glpi_plugin_formcreator_forms_answers', 'is_deleted', 'bool'); - - // Update Form Answers - $table = 'glpi_plugin_formcreator_forms_answers'; - - if ($DB->fieldExists($table, 'validator_id', false)) { - $migration->addField($table, 'users_id_validator', 'integer', ['after' => 'requester_id']); - $migration->addField($table, 'groups_id_validator', 'integer', ['after' => 'users_id_validator']); - $migration->addKey($table, 'users_id_validator'); - $migration->addKey($table, 'groups_id_validator'); - $migration->migrationOneTable($table); - - $formTable = 'glpi_plugin_formcreator_forms'; - $query = "UPDATE `$table` - INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) - SET `users_id_validator` = 'validator_id' - WHERE `$formTable`.`validation_required` = '1'"; - $DB->query($query) or plugin_formcreator_upgrade_error($migration); - $query = "UPDATE `$table` - INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) - SET `groups_id_validator` = 'validator_id' - WHERE `$formTable`.`validation_required` = '2'"; - $DB->query($query) or plugin_formcreator_upgrade_error($migration); - - $migration->dropKey($table, 'validator_id'); - $migration->dropField($table, 'validator_id'); - } + $migration->migrationOneTable('glpi_plugin_formcreator_forms_answers'); } function plugin_formcreator_updateForm_Profile_2_5(Migration $migration) { @@ -453,7 +428,7 @@ function plugin_formcreator_updateIssue_2_5(Migration $migration) { `fanswer`.`entities_id` AS `entities_id`, `fanswer`.`is_recursive` AS `is_recursive`, `fanswer`.`requester_id` AS `requester_id`, - `fanswer`.`users_id_validator` AS `validator_id`, + `fanswer`.`validator_id` AS `validator_id`, `fanswer`.`comment` AS `comment` FROM `glpi_plugin_formcreator_forms_answers` AS `fanswer` LEFT JOIN `glpi_plugin_formcreator_forms` AS `f` @@ -464,9 +439,7 @@ function plugin_formcreator_updateIssue_2_5(Migration $migration) { WHERE `fanswer`.`is_deleted` = '0' GROUP BY `original_id` HAVING COUNT(`itic`.`tickets_id`) != 1 - UNION - SELECT DISTINCT NULL AS `id`, CONCAT('t_',`tic`.`id`) AS `display_id`, diff --git a/install/update_2.5_2.6.php b/install/update_2.5_2.6.php index 2cee84dbf..0ce0bc29f 100644 --- a/install/update_2.5_2.6.php +++ b/install/update_2.5_2.6.php @@ -63,29 +63,27 @@ function plugin_formcreator_update_2_6(Migration $migration) { $table = 'glpi_plugin_formcreator_forms_answers'; $migration->displayMessage("Upgrade $table"); - if ($DB->fieldExists($table, 'validator_id', false)) { - $migration->addField($table, 'users_id_validator', 'integer', ['after' => 'requester_id']); - $migration->addField($table, 'groups_id_validator', 'integer', ['after' => 'users_id_validator']); - $migration->addKey($table, 'users_id_validator'); - $migration->addKey($table, 'groups_id_validator'); - $migration->migrationOneTable($table); - - $formTable = 'glpi_plugin_formcreator_forms'; - $query = "UPDATE `$table` - INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) - SET `users_id_validator` = 'validator_id' - WHERE `$formTable`.`validation_required` = '1'"; - $DB->query($query) or plugin_formcreator_upgrade_error($migration); - $query = "UPDATE `$table` - INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) - SET `groups_id_validator` = 'validator_id' - WHERE `$formTable`.`validation_required` = '2'"; - $DB->query($query) or plugin_formcreator_upgrade_error($migration); + $migration->addField($table, 'users_id_validator', 'integer', ['after' => 'requester_id']); + $migration->addField($table, 'groups_id_validator', 'integer', ['after' => 'users_id_validator']); + $migration->addKey($table, 'users_id_validator'); + $migration->addKey($table, 'groups_id_validator'); + $migration->migrationOneTable($table); + + $formTable = 'glpi_plugin_formcreator_forms'; + $query = "UPDATE `$table` + INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) + SET `users_id_validator` = 'validator_id' + WHERE `$formTable`.`validation_required` = '1'"; + $DB->query($query) or plugin_formcreator_upgrade_error($migration); + $query = "UPDATE `$table` + INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) + SET `groups_id_validator` = 'validator_id' + WHERE `$formTable`.`validation_required` = '2'"; + $DB->query($query) or plugin_formcreator_upgrade_error($migration); + + $migration->dropKey($table, 'validator_id'); + $migration->dropField($table, 'validator_id'); - $migration->dropKey($table, 'validator_id'); - $migration->dropField($table, 'validator_id'); - } - // add location rule $enum_location_rule = "'".implode("', '", array_keys(PluginFormcreatorTargetTicket::getEnumLocationRule()))."'"; if (!$DB->fieldExists('glpi_plugin_formcreator_targettickets', 'location_rule', false)) { From c9874daf7da4d52724be1617133f3b043a85c5fe Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 11 Sep 2018 22:57:37 +0200 Subject: [PATCH 070/192] fix(install): typo for validator id upgrade Signed-off-by: Thierry Bugier --- install/update_2.5_2.6.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install/update_2.5_2.6.php b/install/update_2.5_2.6.php index 0ce0bc29f..65a603d27 100644 --- a/install/update_2.5_2.6.php +++ b/install/update_2.5_2.6.php @@ -72,12 +72,12 @@ function plugin_formcreator_update_2_6(Migration $migration) { $formTable = 'glpi_plugin_formcreator_forms'; $query = "UPDATE `$table` INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) - SET `users_id_validator` = 'validator_id' + SET `users_id_validator` = `validator_id` WHERE `$formTable`.`validation_required` = '1'"; $DB->query($query) or plugin_formcreator_upgrade_error($migration); $query = "UPDATE `$table` INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) - SET `groups_id_validator` = 'validator_id' + SET `groups_id_validator` = `validator_id` WHERE `$formTable`.`validation_required` = '2'"; $DB->query($query) or plugin_formcreator_upgrade_error($migration); From f1ba71b8e041d72d2ccd8dacb09178a1d955ae81 Mon Sep 17 00:00:00 2001 From: btry Date: Fri, 14 Sep 2018 16:47:38 +0200 Subject: [PATCH 071/192] fix(form_answer): deprecated calls Signed-off-by: btry --- inc/form_answer.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index 6652295e6..8e669e8d0 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -387,8 +387,8 @@ static function showForForm(PluginFormcreatorForm $form, $params = []) { $params = Search::manageParams(__CLASS__, $params); $data = Search::prepareDatasForSearch(__CLASS__, $params, $forcedisplay); Search::constructSQL($data); - Search::constructDatas($data); - Search::displayDatas($data); + Search::constructData($data); + Search::displayData($data); // remove previous session var (restore default view) unset($_SESSION['formcreator']['form_search_answers']); @@ -903,7 +903,6 @@ private function transformAnswerValue(PluginFormcreatorQuestion $question, $valu $form = $question->getForm(); if ($question->getField('fieldtype') != 'file') { - // If the answer is set, check if it is an array (then implode id). if (isset($value)) { // If the answer is set, check if it is an array (then implode id). if ($value !== null) { From 1dd58b97664194838a28addd083966c537986b57 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 10 Sep 2018 17:54:47 +0200 Subject: [PATCH 072/192] fix(targetchange): harmonize column name and type with glpi change itemtype Signed-off-by: btry --- inc/form.class.php | 4 ++-- inc/target.class.php | 2 +- inc/targetchange.class.php | 28 +++++++++------------- install/mysql/plugin_formcreator_empty.sql | 12 +++++----- install/update_2.6_2.7.php | 10 ++++++++ 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/inc/form.class.php b/inc/form.class.php index 79620b45c..1b0e05af5 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1458,7 +1458,7 @@ public function duplicate() { foreach ($tab_questions as $id => $value) { $changeFields = [ 'name', - 'comment', + 'content', 'impactcontent', 'controlistcontent', 'rolloutplancontent', @@ -1503,7 +1503,7 @@ public function duplicate() { $new_target_change = new PluginFormcreatorTargetChange(); $update_target_change['title'] = Toolbox::addslashes_deep($update_target_change['name']); - $update_target_change['comment'] = Toolbox::addslashes_deep($update_target_change['comment']); + $update_target_change['content'] = Toolbox::addslashes_deep($update_target_change['content']); if (!$new_target_change->update($update_target_change)) { return false; } diff --git a/inc/target.class.php b/inc/target.class.php index b60feedf9..b075bea2b 100644 --- a/inc/target.class.php +++ b/inc/target.class.php @@ -179,7 +179,7 @@ public function prepareInputForAdd($input) { $targetchange = new PluginFormcreatorTargetChange(); $id_targetchange = $targetchange->add([ 'name' => $input['name'], - 'comment' => '##FULLFORM##' + 'content' => '##FULLFORM##' ]); $input['items_id'] = $id_targetchange; diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index 7a37f312a..fc4ee88c5 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -118,10 +118,10 @@ public function export($remove_uuid = false) { $content = str_replace("##answer_$id##", "##answer_$uuid##", $content); $target_data['name'] = $content; - $content = $target_data['comment']; + $content = $target_data['content']; $content = str_replace("##question_$id##", "##question_$uuid##", $content); $content = str_replace("##answer_$id##", "##answer_$uuid##", $content); - $target_data['comment'] = $content; + $target_data['content'] = $content; } } @@ -169,10 +169,10 @@ public static function import($targetitems_id = 0, $target_data = []) { $content = str_replace("##answer_$uuid##", "##answer_$id##", $content); $target_data['name'] = $content; - $content = $target_data['comment']; + $content = $target_data['content']; $content = str_replace("##question_$uuid##", "##question_$id##", $content); $content = str_replace("##answer_$uuid##", "##answer_$id##", $content); - $target_data['comment'] = $content; + $target_data['content'] = $content; } } @@ -236,9 +236,9 @@ public function showForm($options = []) { echo '

' . __('Description') . ' *'; - echo ''; + echo ''; if ($CFG_GLPI["use_rich_text"]) { - Html::initEditorSystem('comment'); + Html::initEditorSystem('content'); } echo '
' . __('Description') . ' *'; - echo ''; + echo ''; if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI["use_rich_text"]) { - Html::initEditorSystem('comment'); + Html::initEditorSystem('content'); } echo '
'; - $defaultValues = ""; + $defaultValues = ''; if (!$this->isNewItem()) { $fieldObject = PluginFormcreatorFields::getFieldInstance($this->getField('fieldtype'), $this); - $defaultValues = $fieldObject->prepareQuestionValuesForEdit($this->fields['default_values']); + $fieldObject->deserializeValue($this->fields['default_values']); + $defaultValues = $fieldObject->getValueForDesign(); } echo '
' . __('Description') . ' *'; - echo ''; - if ($CFG_GLPI["use_rich_text"]) { - Html::initEditorSystem('content'); - } echo '
' . __('Impacts') . ' '; echo ''; - if ($CFG_GLPI["use_rich_text"]) { - Html::initEditorSystem('impactcontent'); - } echo '
' . __('Control list') . ' '; echo ''; - if ($CFG_GLPI["use_rich_text"]) { - Html::initEditorSystem('controlistcontent'); - } echo '
' . __('Deployment plan') . ' '; echo ''; - if ($CFG_GLPI["use_rich_text"]) { - Html::initEditorSystem('rolloutplancontent'); - } echo '
' . __('Backup plan') . ' '; echo ''; - if ($CFG_GLPI["use_rich_text"]) { - Html::initEditorSystem('backoutplancontent'); - } echo '
' . __('Checklist') . ' '; echo ''; - if ($CFG_GLPI["use_rich_text"]) { - Html::initEditorSystem('checklistcontent'); - } echo '
' . __('Name') . ' *'; + echo '
'; @@ -110,7 +110,7 @@ public function showForm($options = []) { echo ''; echo '' . __('Ticket title', 'formcreator') . ' *'; - echo ''; + echo ''; echo ''; echo ''; From 468ee6b80e89573bf357e0df0ee629bd3cf45189 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 23 Oct 2018 17:41:49 +0200 Subject: [PATCH 118/192] fix(form): remove html entities in db Signed-off-by: Thierry Bugier --- inc/form.class.php | 22 +++++----------------- install/update_2.6_2.7.php | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/inc/form.class.php b/inc/form.class.php index 9011fe873..ff29e9ec8 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1021,13 +1021,6 @@ class='formcreator_form form_horizontal'>"; * @return array the modified $input array */ public function prepareInputForAdd($input) { - // Decode (if already encoded) and encode strings to avoid problems with quotes - foreach ($input as $key => $value) { - if (!is_array($value)) { - $input[$key] = plugin_formcreator_encode($value); - } - } - // generate a unique id if (!isset($input['uuid']) || empty($input['uuid'])) { @@ -1041,15 +1034,6 @@ public function prepareInputForAdd($input) { Session::addMessageAfterRedirect(__('The name cannot be empty!', 'formcreator'), false, ERROR); return []; } - $input['name'] = addslashes($input['name']); - } - - if (isset($input['description'])) { - $input['description'] = addslashes($input['description']); - } - - if (isset($input['content'])) { - $input['content'] = addslashes($input['content']); } if (!isset($input['requesttype'])) { @@ -1934,6 +1918,8 @@ public static function import($form = []) { */ public static function import(PluginFormcreatorImportLinker $importLinker, $form = []) { + global $DB; + $form_obj = new self; $entity = new Entity; $form_cat = new PluginFormcreatorCategory; @@ -1960,7 +1946,9 @@ public static function import(PluginFormcreatorImportLinker $importLinker, $form $form['uuid'])) { // add id key $form['id'] = $forms_id; - + foreach (['name', 'description', 'content'] as $key) { + $form[$key] = $DB->escape($form[$key]); + } // update existing form $form_obj->update($form); } else { diff --git a/install/update_2.6_2.7.php b/install/update_2.6_2.7.php index f722dd16c..47cac7168 100644 --- a/install/update_2.6_2.7.php +++ b/install/update_2.6_2.7.php @@ -100,15 +100,15 @@ function plugin_formcreator_update_2_7(Migration $migration) { ] ]; foreach ($DB->request($request) as $row) { - $values = html_entity_decode($row['values']); - $defaultValues = html_entity_decode($row['default_values']); + $values = Toolbox::addslashes_deep(html_entity_decode($row['values'])); + $defaultValues = Toolbox::addslashes_deep(html_entity_decode($row['default_values'])); $id = $row['id']; $DB->query("UPDATE `glpi_plugin_formcreator_questions` SET `values` = '$values', `default_values` = '$defaultValues' WHERE `id` = '$id'"); } // decode html entities in name of questions foreach ($DB->request(['FROM' => 'glpi_plugin_formcreator_questions']) as $row) { - $name = html_entity_decode($row['name']); + $name = Toolbox::addslashes_deep(html_entity_decode($row['name'])); $id = $row['id']; $DB->query("UPDATE `glpi_plugin_formcreator_questions` SET `name`='$name' WHERE `id` = '$id'"); } @@ -182,4 +182,16 @@ function plugin_formcreator_update_2_7(Migration $migration) { foreach ($tables as $table) { $migration->changeField($table, 'name', 'name', 'string', ['after' => 'id']); } + + //remove html entities in forms + $request = [ + 'FROM' => 'glpi_plugin_formcreator_forms', + ]; + foreach ($DB->request($request) as $row) { + $name = Toolbox::addslashes_deep(html_entity_decode($row['name'])); + $description = Toolbox::addslashes_deep(html_entity_decode($row['description'])); + $content = Toolbox::addslashes_deep(html_entity_decode($row['content'])); + $id = $row['id']; + $DB->query("UPDATE `glpi_plugin_formcreator_forms` SET `name` = '$name', `description` = '$description', `content` = '$content' WHERE `id` = '$id'"); + } } From 4d6d6cc94cb1ac57014887f20b151baecc8db0b9 Mon Sep 17 00:00:00 2001 From: btry Date: Thu, 25 Oct 2018 15:27:23 +0200 Subject: [PATCH 119/192] docs(setup): fix docblock Signed-off-by: btry --- setup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.php b/setup.php index 2d616f218..1b3b5f74a 100644 --- a/setup.php +++ b/setup.php @@ -344,7 +344,7 @@ function plugin_formcreator_getFromDBByField(CommonDBTM $item, $field = '', $val /** * Autoloader - * @param unknown $classname + * @param string $classname */ function plugin_formcreator_autoload($classname) { if (strpos($classname, 'PluginFormcreator') === 0) { From 453bc95718298df977fcecf704bf70459bf090e9 Mon Sep 17 00:00:00 2001 From: btry Date: Thu, 25 Oct 2018 15:27:53 +0200 Subject: [PATCH 120/192] fix(field): prevent use of tag field if the plugin Tag is not available Signed-off-by: btry --- inc/answer.class.php | 44 --------------------------- inc/fieldinterface.class.php | 8 +++-- inc/fields/actorfield.class.php | 4 +++ inc/fields/checkboxesfield.class.php | 4 +++ inc/fields/datefield.class.php | 4 +++ inc/fields/datetimefield.class.php | 4 +++ inc/fields/descriptionfield.class.php | 4 +++ inc/fields/dropdownfield.class.php | 4 +++ inc/fields/emailfield.class.php | 4 +++ inc/fields/filefield.class.php | 4 +++ inc/fields/floatfield.class.php | 4 +++ inc/fields/glpiselectfield.class.php | 4 +++ inc/fields/hiddenfield.class.php | 4 +++ inc/fields/hostnamefield.class.php | 6 +++- inc/fields/integerfield.class.php | 4 +++ inc/fields/ipfield.class.php | 4 +++ inc/fields/multiselectfield.class.php | 4 +++ inc/fields/radiosfield.class.php | 4 +++ inc/fields/selectfield.class.php | 4 +++ inc/fields/tagfield.class.php | 6 +++- inc/fields/textfield.class.php | 4 +++ inc/fields/urgencyfield.class.php | 4 +++ inc/form.class.php | 3 ++ 23 files changed, 91 insertions(+), 48 deletions(-) diff --git a/inc/answer.class.php b/inc/answer.class.php index e171474ff..cc5a4341d 100644 --- a/inc/answer.class.php +++ b/inc/answer.class.php @@ -67,48 +67,4 @@ public static function canView() { public static function getTypeName($nb = 0) { return _n('Answer', 'Answers', $nb, 'formcreator'); } - - /** - * Prepare input data for adding the question - * Check fields values and get the order for the new question - * - * @param array $input data used to add the item - * - * @return array the modified $input array - */ - public function prepareInputForAdd($input) { - global $DB; - - // Decode (if already encoded) and encode strings to avoid problems with quotes - foreach ($input as $key => $value) { - if (is_array($value)) { - foreach ($value as $key2 => $value2) { - $input[$key][$key2] = plugin_formcreator_encode($value2, false); - } - } else if (is_array(json_decode($value))) { - //$value = json_decode($value); - //foreach ($value as $key2 => $value2) { - //$value[$key2] = plugin_formcreator_encode($value2, false); - //} - //$input[$key] = json_encode($value, JSON_UNESCAPED_UNICODE); - $input[$key] = $DB->escape($value); - } else { - $input[$key] = $value; - } - } - - return $input; - } - - /** - * Prepare input data for adding the question - * Check fields values and get the order for the new question - * - * @param array $input data used to add the item - * - * @return array the modified $input array - */ - public function prepareInputForUpdate($input) { - return $this->prepareInputForAdd($input); - } } diff --git a/inc/fieldinterface.class.php b/inc/fieldinterface.class.php index 4c90e2a36..0c2cc8c84 100644 --- a/inc/fieldinterface.class.php +++ b/inc/fieldinterface.class.php @@ -47,12 +47,16 @@ public static function getPrefs(); public static function getJSFields(); + /** + * Are the prerequisites met to use this field ? + */ + public function isPrerequisites(); + /** * Is the field valid for the given value? - * @param string $value * @return boolean True if the field has a valid value, false otherwise */ - //public function isValid($value); + public function isValid(); /** * Is the field required? diff --git a/inc/fields/actorfield.class.php b/inc/fields/actorfield.class.php index 84b7db37b..e524fe760 100644 --- a/inc/fields/actorfield.class.php +++ b/inc/fields/actorfield.class.php @@ -38,6 +38,10 @@ */ class PluginFormcreatorActorField extends PluginFormcreatorField { + public function isPrerequisites() { + return true; + } + public static function getName() { return _n('Actor', 'Actors', 1, 'formcreator'); } diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index 87aa23979..06580c873 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorCheckboxesField extends PluginFormcreatorField { + public function isPrerequisites() { + return true; + } + public function displayField($canEdit = true) { if ($canEdit) { $id = $this->fields['id']; diff --git a/inc/fields/datefield.class.php b/inc/fields/datefield.class.php index 19efa2f09..09c09ffd0 100644 --- a/inc/fields/datefield.class.php +++ b/inc/fields/datefield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorDateField extends PluginFormcreatorField { + public function isPrerequisites() { + return true; + } + public function displayField($canEdit = true) { if ($canEdit) { $id = $this->fields['id']; diff --git a/inc/fields/datetimefield.class.php b/inc/fields/datetimefield.class.php index 5931aa6fc..32c82589f 100644 --- a/inc/fields/datetimefield.class.php +++ b/inc/fields/datetimefield.class.php @@ -36,6 +36,10 @@ class PluginFormcreatorDatetimeField extends PluginFormcreatorField /** @var array $fields Fields of an instance of PluginFormcreatorQuestion */ protected $fields = null; + public function isPrerequisites() { + return true; + } + public function displayField($canEdit = true) { if ($canEdit) { $id = $this->fields['id']; diff --git a/inc/fields/descriptionfield.class.php b/inc/fields/descriptionfield.class.php index e1986393a..5700dba26 100644 --- a/inc/fields/descriptionfield.class.php +++ b/inc/fields/descriptionfield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorDescriptionField extends PluginFormcreatorField { + public function isPrerequisites() { + return true; + } + public function show($canEdit = true) { echo '
'; echo nl2br(html_entity_decode($this->fields['description'])); diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index 43b3d2d71..f11854f48 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorDropdownField extends PluginFormcreatorField { + public function isPrerequisites() { + return true; + } + public function displayField($canEdit = true) { global $DB, $CFG_GLPI; diff --git a/inc/fields/emailfield.class.php b/inc/fields/emailfield.class.php index 323cbe6b2..e2c1db96b 100644 --- a/inc/fields/emailfield.class.php +++ b/inc/fields/emailfield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorEmailField extends PluginFormcreatorField { + public function isPrerequisites() { + return true; + } + public function displayField($canEdit = true) { if ($canEdit) { $id = $this->fields['id']; diff --git a/inc/fields/filefield.class.php b/inc/fields/filefield.class.php index 6187c0a6b..a83f0f79c 100644 --- a/inc/fields/filefield.class.php +++ b/inc/fields/filefield.class.php @@ -35,6 +35,10 @@ class PluginFormcreatorFileField extends PluginFormcreatorField { private $uploadData = []; + public function isPrerequisites() { + return true; + } + public function displayField($canEdit = true) { if ($canEdit) { $required = $this->isRequired() ? ' required' : ''; diff --git a/inc/fields/floatfield.class.php b/inc/fields/floatfield.class.php index 6bce686a8..f35c894c9 100644 --- a/inc/fields/floatfield.class.php +++ b/inc/fields/floatfield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorFloatField extends PluginFormcreatorField { + public function isPrerequisites() { + return true; + } + public function displayField($canEdit = true) { $id = $this->fields['id']; $rand = mt_rand(); diff --git a/inc/fields/glpiselectfield.class.php b/inc/fields/glpiselectfield.class.php index 18d577983..8cd24d794 100644 --- a/inc/fields/glpiselectfield.class.php +++ b/inc/fields/glpiselectfield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorGlpiselectField extends PluginFormcreatorDropdownField { + public function isPrerequisites() { + return true; + } + public static function getName() { return _n('GLPI object', 'GLPI objects', 1, 'formcreator'); } diff --git a/inc/fields/hiddenfield.class.php b/inc/fields/hiddenfield.class.php index 3cbc755c3..501429ab6 100644 --- a/inc/fields/hiddenfield.class.php +++ b/inc/fields/hiddenfield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorHiddenField extends PluginFormcreatorField { + public function isPrerequisites() { + return true; + } + public function show($canEdit = true) { $id = $this->fields['id']; $rand = mt_rand(); diff --git a/inc/fields/hostnamefield.class.php b/inc/fields/hostnamefield.class.php index 2541dec8b..3873a239a 100644 --- a/inc/fields/hostnamefield.class.php +++ b/inc/fields/hostnamefield.class.php @@ -1,7 +1,11 @@ fields['id']; $rand = mt_rand(); $fieldName = 'formcreator_field_' . $id; diff --git a/inc/fields/integerfield.class.php b/inc/fields/integerfield.class.php index db07e95c9..ce42c49d0 100644 --- a/inc/fields/integerfield.class.php +++ b/inc/fields/integerfield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorIntegerField extends PluginFormcreatorField { + public function isPrerequisites() { + return true; + } + public function displayField($canEdit = true) { $id = $this->fields['id']; $rand = mt_rand(); diff --git a/inc/fields/ipfield.class.php b/inc/fields/ipfield.class.php index 9f563ace3..1f2c77804 100644 --- a/inc/fields/ipfield.class.php +++ b/inc/fields/ipfield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorIpField extends PluginFormcreatorField { + public function isPrerequisites() { + return true; + } + public function show($canEdit = true) { $id = $this->fields['id']; $rand = mt_rand(); diff --git a/inc/fields/multiselectfield.class.php b/inc/fields/multiselectfield.class.php index 4a4a0d4b9..119447f80 100644 --- a/inc/fields/multiselectfield.class.php +++ b/inc/fields/multiselectfield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorMultiSelectField extends PluginFormcreatorField { + public function isPrerequisites() { + return true; + } + public function displayField($canEdit = true) { if ($canEdit) { $id = $this->fields['id']; diff --git a/inc/fields/radiosfield.class.php b/inc/fields/radiosfield.class.php index 91587f088..711c2ea4d 100644 --- a/inc/fields/radiosfield.class.php +++ b/inc/fields/radiosfield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorRadiosField extends PluginFormcreatorField { + public function isPrerequisites() { + return true; + } + public function displayField($canEdit = true) { if ($canEdit) { $id = $this->fields['id']; diff --git a/inc/fields/selectfield.class.php b/inc/fields/selectfield.class.php index a9c2695f9..ce55eda0a 100644 --- a/inc/fields/selectfield.class.php +++ b/inc/fields/selectfield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorSelectField extends PluginFormcreatorMultiselectField { + public function isPrerequisites() { + return true; + } + public function displayField($canEdit = true) { if ($canEdit) { $id = $this->fields['id']; diff --git a/inc/fields/tagfield.class.php b/inc/fields/tagfield.class.php index b2d4474cb..6252ba7f2 100644 --- a/inc/fields/tagfield.class.php +++ b/inc/fields/tagfield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorTagField extends PluginFormcreatorDropdownField { + public function isPrerequisites() { + return class_exists(PluginTagTag::class); + } + public function displayField($canEdit = true) { $id = $this->fields['id']; $rand = mt_rand(); @@ -49,7 +53,7 @@ public function displayField($canEdit = true) { $where = "(`type_menu` LIKE '%\"Ticket\"%' OR`type_menu` LIKE '%\"Change\"%' OR `type_menu` LIKE '0')"; $where .= getEntitiesRestrictRequest('AND', getTableForItemType(PluginTagTag::class), '', '', true); - $result = $obj->find($where, "name"); + $result = $obj->find($where, 'name'); foreach ($result AS $id => $data) { $values[$id] = $data['name']; } diff --git a/inc/fields/textfield.class.php b/inc/fields/textfield.class.php index 862f84022..2d9c85973 100644 --- a/inc/fields/textfield.class.php +++ b/inc/fields/textfield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorTextField extends PluginFormcreatorField { + public function isPrerequisites() { + return true; + } + public function displayField($canEdit = true) { $id = $this->fields['id']; $rand = mt_rand(); diff --git a/inc/fields/urgencyfield.class.php b/inc/fields/urgencyfield.class.php index 6002fcacf..d0e7dbff1 100644 --- a/inc/fields/urgencyfield.class.php +++ b/inc/fields/urgencyfield.class.php @@ -33,6 +33,10 @@ class PluginFormcreatorUrgencyField extends PluginFormcreatorField { + public function isPrerequisites() { + return true; + } + public function displayField($canEdit = true) { if ($canEdit) { $id = $this->fields['id']; diff --git a/inc/form.class.php b/inc/form.class.php index ff29e9ec8..8d8c92b64 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -954,6 +954,9 @@ class='formcreator_form form_horizontal'>"; $question->fields['fieldtype'], $question ); + if (!$field->isPrerequisites()) { + continue; + } if (isset($data['formcreator_field_' . $question_line['id']])) { $field->parseAnswerValues($data); } else { From c7fcf8adb5234f7442cc4e1bd543c71683ae1467 Mon Sep 17 00:00:00 2001 From: btry Date: Thu, 25 Oct 2018 16:19:15 +0200 Subject: [PATCH 121/192] fix(tagfield): fatal error if comparison with a tag field when the tag plugin is not available Signed-off-by: btry --- inc/fields.class.php | 19 +++++++++++++++++++ inc/fields/hostnamefield.class.php | 2 +- inc/form.class.php | 3 +++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/inc/fields.class.php b/inc/fields.class.php index 38a8fc99d..b33036b1a 100644 --- a/inc/fields.class.php +++ b/inc/fields.class.php @@ -186,8 +186,12 @@ public static function isVisible($id, $fields) { $conditionQuestion = new PluginFormcreatorQuestion(); $conditionQuestion->getFromDB($condition['field']); $conditionField = $fields[$condition['field']]; + switch ($condition['operator']) { case '!=' : + if (!$conditionField->isPrerequisites()) { + return true; + } try { $value = $conditionField->notEquals($condition['value']); } catch (PluginFormcreatorComparisonException $e) { @@ -196,6 +200,9 @@ public static function isVisible($id, $fields) { break; case '==' : + if (!$conditionField->isPrerequisites()) { + return false; + } try { $value = $conditionField->equals($condition['value']); } catch (PluginFormcreatorComparisonException $e) { @@ -204,6 +211,9 @@ public static function isVisible($id, $fields) { break; case '>': + if (!$conditionField->isPrerequisites()) { + return false; + } try { $value = $conditionField->greaterThan($condition['value']); } catch (PluginFormcreatorComparisonException $e) { @@ -212,6 +222,9 @@ public static function isVisible($id, $fields) { break; case '<': + if (!$conditionField->isPrerequisites()) { + return false; + } try { $value = $conditionField->lessThan($condition['value']); } catch (PluginFormcreatorComparisonException $e) { @@ -220,6 +233,9 @@ public static function isVisible($id, $fields) { break; case '>=': + if (!$conditionField->isPrerequisites()) { + return false; + } try { $value = $conditionField->greaterThan($condition['value']) || $conditionField->equals($condition['value']); @@ -229,6 +245,9 @@ public static function isVisible($id, $fields) { break; case '<=': + if (!$conditionField->isPrerequisites()) { + return false; + } try { $value = $conditionField->lessThan($condition['value']) || $conditionField->equals($condition['value']); diff --git a/inc/fields/hostnamefield.class.php b/inc/fields/hostnamefield.class.php index 3873a239a..cb1bd749b 100644 --- a/inc/fields/hostnamefield.class.php +++ b/inc/fields/hostnamefield.class.php @@ -5,7 +5,7 @@ public function isPrerequisites() { return true; } - public function show($canEdit = true) { + public function show($canEdit = true) { $id = $this->fields['id']; $rand = mt_rand(); $fieldName = 'formcreator_field_' . $id; diff --git a/inc/form.class.php b/inc/form.class.php index 8d8c92b64..9d4261eb1 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1160,6 +1160,9 @@ public function saveForm($input) { if ($valid) { foreach ($found_questions as $id => $question) { + if (!$fields[$id]->isPrerequisites()) { + continue; + } $key = 'formcreator_field_' . $id; if (PluginFormcreatorFields::isVisible($id, $fields) && !$fields[$id]->isValid()) { $valid = false; From 8b79d01a607c8a710cba55d76663865aec84ca92 Mon Sep 17 00:00:00 2001 From: btry Date: Thu, 25 Oct 2018 16:29:52 +0200 Subject: [PATCH 122/192] fix(textareafield): render HTML when viewing an answer Signed-off-by: btry --- inc/fields/textareafield.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/fields/textareafield.class.php b/inc/fields/textareafield.class.php index 2e1e6cbe8..652081f64 100644 --- a/inc/fields/textareafield.class.php +++ b/inc/fields/textareafield.class.php @@ -61,7 +61,7 @@ public function displayField($canEdit = true) { });"); } else { if ($useRichText) { - echo $this->value; + echo Toolbox::getHtmlToDisplay($this->value); } else { echo nl2br($this->value); } From fd5eaed1791d73b617e68579823651cc910ee2f9 Mon Sep 17 00:00:00 2001 From: btry Date: Thu, 25 Oct 2018 16:56:33 +0200 Subject: [PATCH 123/192] refactor(form): remove obsolete call to method this method will be deleted Signed-off-by: btry --- inc/form.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inc/form.class.php b/inc/form.class.php index 9d4261eb1..b95087761 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -792,11 +792,10 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome = if ($DB->numrows($result_forms) > 0) { while ($form = $DB->fetch_array($result_forms)) { - $formDescription = plugin_formcreator_encode($form['description']); $formList[] = [ 'id' => $form['id'], 'name' => $form['name'], - 'description' => $formDescription, + 'description' => $form['description'], 'type' => 'form', 'usage_count' => $form['usage_count'], 'is_default' => true From 0a460ddfca7db3d9adef73e8843d5e245e952319 Mon Sep 17 00:00:00 2001 From: btry Date: Fri, 26 Oct 2018 11:01:45 +0200 Subject: [PATCH 124/192] fix(filefield): fix validity of the field when required Signed-off-by: btry --- inc/fields/filefield.class.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/inc/fields/filefield.class.php b/inc/fields/filefield.class.php index a83f0f79c..fd925350b 100644 --- a/inc/fields/filefield.class.php +++ b/inc/fields/filefield.class.php @@ -108,16 +108,7 @@ public function isValid() { private function isValidValue($value) { // If the field is required it can't be empty - if (count($this->uploadData) > 0) { - foreach ($this->uploadData as $file) { - if (!is_file(GLPI_TMP_DIR . '/' . $file)) { - Session::addMessageAfterRedirect(__('A required file is missing:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR); - return false; - } - } - } - - return true; + return (count($this->uploadData) > 0); } public static function getName() { From 49a1fb68ba5b1349d92aaf4e97ccb6ff2e82bf38 Mon Sep 17 00:00:00 2001 From: btry Date: Thu, 25 Oct 2018 17:02:07 +0200 Subject: [PATCH 125/192] fix: remove call to abusive encoding Signed-off-by: btry --- inc/form.class.php | 4 ++-- inc/question.class.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/form.class.php b/inc/form.class.php index b95087761..5b1a5f6f4 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -2091,7 +2091,7 @@ public function showForCentral() { echo ' '; echo '' + title="' . $form['description'] . '">' . $form['name'] . ''; echo ''; @@ -2131,7 +2131,7 @@ public function showForCentral() { echo ' '; echo '' + title="' . $form['description'] . '">' . $form['name'] . ''; echo ''; diff --git a/inc/question.class.php b/inc/question.class.php index 84b1f8b17..082351933 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -536,9 +536,9 @@ public function updateConditions($input) { $order = 0; while (count($input['show_field']) > 0) { $order++; - $value = plugin_formcreator_encode(array_shift($input['show_value']), false); + $value = array_shift($input['show_value']); $showField = (int) array_shift($input['show_field']); - $showCondition = plugin_formcreator_decode(array_shift($input['show_condition'])); + $showCondition = array_shift($input['show_condition']); $showLogic = array_shift($input['show_logic']); $question_condition = new PluginFormcreatorQuestion_Condition(); $question_condition->add([ From 22a63e9841797cb31784f25d4a7fcbe43f8ef2a4 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 3 Sep 2018 11:44:31 +0200 Subject: [PATCH 126/192] chore(git): update gitignore Signed-off-by: btry --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 003cc7da2..b38845c69 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ vendor/ .settings .buildpath .project +/.gtm/ From 94905b58395046185b3e0b101b1e913155bb1289 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 15 Oct 2018 10:56:57 +0200 Subject: [PATCH 127/192] fix(tagfield): fatal error if the plugin Tag is not available Signed-off-by: btry --- inc/fields/tagfield.class.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/inc/fields/tagfield.class.php b/inc/fields/tagfield.class.php index 6252ba7f2..4a2fabd11 100644 --- a/inc/fields/tagfield.class.php +++ b/inc/fields/tagfield.class.php @@ -43,6 +43,11 @@ public function displayField($canEdit = true) { $fieldName = 'formcreator_field_' . $id; $domId = $fieldName . $rand; if ($canEdit) { + if (!class_exists(PluginTagTag::class)) { + // Plugin Tag not available + echo ''; + return; + } $required = $this->fields['required'] ? ' required' : ''; $values = []; From e4bbdb884f0589c949963419a56006e58bf70754 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 15 Oct 2018 11:34:29 +0200 Subject: [PATCH 128/192] refactor(answer): factorize Signed-off-by: btry --- inc/fields/tagfield.class.php | 5 +++++ inc/form_answer.class.php | 29 ++++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/inc/fields/tagfield.class.php b/inc/fields/tagfield.class.php index 4a2fabd11..d91da6ea1 100644 --- a/inc/fields/tagfield.class.php +++ b/inc/fields/tagfield.class.php @@ -160,6 +160,11 @@ public static function getJSFields() { } public function equals($value) { + if (!class_exists(PluginTagTag::class)) { + // Plugin Tag not available + return false; + } + // find the tag to check for existence $tag = new PluginTagTag(); $tag->getFromDBByRequest([ diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index 915c3b84b..bc713ebc7 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -646,23 +646,32 @@ public function saveAnswers(PluginFormcreatorForm $form, $data, $fields) { $question = new PluginFormcreatorQuestion(); $questions = $question->getQuestionsFromForm($data['formcreator_form']); + //Collect answers + $answer_value = []; + foreach ($questions as $questionId => $question) { + if (!isset($data['formcreator_field_' . $questionId])) { + $answer_value[$questionId] = ''; + } else { + $answer_value[$questionId] = $fields[$questionId] + ->serializeValue($data['formcreator_field_' . $questionId]); + } + } + // Update form answers if (isset($data['save_formanswer'])) { $status = $data['status']; $this->update([ - 'id' => $formanswers_id, - 'status' => $status, - 'comment' => isset($data['comment']) ? $data['comment'] : 'NULL' + 'id' => $formanswers_id, + 'status' => $status, + 'comment' => isset($data['comment']) ? $data['comment'] : 'NULL' ]); // Update questions answers if ($status == 'waiting') { foreach ($questions as $questionId => $question) { - $answer_value = $fields[$questionId]->serializeValue($data['formcreator_field_' . $questionId]); - $answer->update([ 'id' => $answer->getID(), - 'answer' => $answer_value, + 'answer' => $answer_value[$questionId], ], 0); } } @@ -710,16 +719,10 @@ public function saveAnswers(PluginFormcreatorForm $form, $data, $fields) { // Save questions answers foreach ($questions as $questionId => $question) { - if (!isset($data['formcreator_field_' . $questionId])) { - $answer_value = ''; - } else { - $answer_value = $fields[$questionId]->serializeValue($data['formcreator_field_' . $questionId]); - } - $answer->add([ 'plugin_formcreator_forms_answers_id' => $id, 'plugin_formcreator_questions_id' => $question->getID(), - 'answer' => $answer_value, + 'answer' => $answer_value[$questionId], ], [], 0); foreach ($fields[$questionId]->getDocumentsForTarget() as $documentId) { $docItem = new Document_Item(); From fecb8a8f09649739c2cc607dea3a48e21c55a74c Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 15 Oct 2018 14:04:11 +0200 Subject: [PATCH 129/192] fix(checkboxesfield): single quote rendering Signed-off-by: btry --- inc/fields/checkboxesfield.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index 06580c873..1ef8c38c4 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -55,10 +55,10 @@ public function displayField($canEdit = true) { $current_value = $this->value; echo "
"; echo Html::getCheckbox([ - 'title' => $value, + 'title' => htmlentities($value, ENT_QUOTES), 'id' => $domId.'_'.$i, - 'name' => $fieldName . '[]', - 'value' => $value, + 'name' => htmlentities($fieldName, ENT_QUOTES) . '[]', + 'value' => htmlentities($value, ENT_QUOTES), 'zero_on_empty' => false, 'checked' => in_array($value, $this->value) ]); From 9af8996756adea4f8243cbdadaf49ef491f94be3 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 16 Oct 2018 11:24:59 +0200 Subject: [PATCH 130/192] test: add tests Signed-off-by: Thierry Bugier --- inc/category.class.php | 33 +++-- inc/form.class.php | 15 ++- tests/src/CommonTestCase.php | 16 +++ tests/suite-unit/PluginFormcreatorAnswer.php | 103 +++++++++++++++ tests/suite-unit/PluginFormcreatorForm.php | 123 ++++++++++++------ .../PluginFormcreatorTextareaField.php | 46 +++++++ 6 files changed, 274 insertions(+), 62 deletions(-) create mode 100644 tests/suite-unit/PluginFormcreatorAnswer.php create mode 100644 tests/suite-unit/PluginFormcreatorTextareaField.php diff --git a/inc/category.class.php b/inc/category.class.php index 0c7250abb..0e1489c7a 100644 --- a/inc/category.class.php +++ b/inc/category.class.php @@ -57,23 +57,20 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ } } - /** - * @see CommonTreeDropdown::getAdditionalFields() - */ public function getAdditionalFields() { return [ - [ - 'name' => 'knowbaseitemcategories_id', - 'type' => 'dropdownValue', - 'label' => __('Knowbase category', 'formcreator'), - 'list' => false - ], - [ - 'name' => $this->getForeignKeyField(), - 'type' => 'parent', - 'label' => __('As child of'), - 'list' => false - ] + [ + 'name' => KnowbaseItemCategory::getForeignKeyField(), + 'type' => 'dropdownValue', + 'label' => __('Knowbase category', 'formcreator'), + 'list' => false + ], + [ + 'name' => $this->getForeignKeyField(), + 'type' => 'parent', + 'label' => __('As child of'), + 'list' => false + ] ]; } @@ -83,9 +80,9 @@ public function getAdditionalFields() { * @return array Tree of form categories as nested array */ public static function getCategoryTree($rootId = 0, $helpdeskHome = false) { - $cat_table = getTableForItemType('PluginFormcreatorCategory'); - $form_table = getTableForItemType('PluginFormcreatorForm'); - $table_fp = getTableForItemType('PluginFormcreatorForm_Profile'); + $cat_table = PluginFormcreatorCategory::getTable(); + $form_table = PluginFormcreatorForm::getTable(); + $table_fp = PluginFormcreatorForm_Profile::getTable(); if ($helpdeskHome) { $helpdesk = "AND $form_table.`helpdesk_home` = 1"; } else { diff --git a/inc/form.class.php b/inc/form.class.php index 5b1a5f6f4..aa29b539f 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -51,7 +51,7 @@ class PluginFormcreatorForm extends CommonDBTM implements PluginFormcreatorExpor * @return boolean True if he can create and modify requests */ public static function canCreate() { - return Session::haveRight("entity", UPDATE); + return Session::haveRight('entity', UPDATE); } /** @@ -1033,7 +1033,11 @@ public function prepareInputForAdd($input) { // - name is required if (isset($input['name'])) { if (empty($input['name'])) { - Session::addMessageAfterRedirect(__('The name cannot be empty!', 'formcreator'), false, ERROR); + Session::addMessageAfterRedirect( + __('The name cannot be empty!', 'formcreator'), + false, + ERROR + ); return []; } } @@ -2164,11 +2168,10 @@ static function getInterface() { && ($_SESSION['glpiactiveprofile']['interface'] == 'helpdesk')) { if (plugin_formcreator_replaceHelpdesk()) { return 'servicecatalog'; - } else { - return 'self-service'; } - - } else if (!empty($_SESSION['glpiactiveprofile'])) { + return 'self-service'; + } + if (!empty($_SESSION['glpiactiveprofile'])) { return 'central'; } diff --git a/tests/src/CommonTestCase.php b/tests/src/CommonTestCase.php index b13e1f26a..3cec1d80f 100644 --- a/tests/src/CommonTestCase.php +++ b/tests/src/CommonTestCase.php @@ -467,4 +467,20 @@ protected function createFullForm( $targets, ]; } + + /** + * Tests the session has a specific message + * this may be replaced by a custom asserter for atoum + * @see http://docs.atoum.org/en/latest/asserters.html#custom-asserter + * + * @param string $message + * @param integer $message_type + */ + protected function sessionHasMessage($message, $message_type = INFO) { + if (!is_array($message)) { + $message = [$message]; + } + $this->array($_SESSION['MESSAGE_AFTER_REDIRECT'][$message_type]) + ->containsValues($message); + } } diff --git a/tests/suite-unit/PluginFormcreatorAnswer.php b/tests/suite-unit/PluginFormcreatorAnswer.php new file mode 100644 index 000000000..ac9de3287 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorAnswer.php @@ -0,0 +1,103 @@ +. + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ +namespace tests\units; +use GlpiPlugin\Formcreator\Tests\CommonTestCase; + +class PluginFormcreatorAnswer extends CommonTestCase { + public function testCanCreate() { + $output = \PluginFormcreatorAnswer::canCreate(); + $this->boolean($output)->isTrue(); + } + + public function testCanView() { + $output = \PluginFormcreatorAnswer::canView(); + $this->boolean($output)->isTrue(); + } + + public function providerGetTypeName() { + return [ + [ + 'input' => 0, + 'expected' => 'Answers', + ], + [ + 'input' => 1, + 'expected' => 'Answer', + ], + [ + 'input' => 2, + 'expected' => 'Answers', + ], + ]; + } + + /** + * @dataProvider providerGetTypeName + * @param integer $number + * @param string $expected + */ + public function testGetTypeName($number, $expected) { + $output = \PluginFormcreatorAnswer::getTypeName($number); + $this->string($output)->isEqualTo($expected); + } + + public function providerPrepareInputForAdd() { + return [ + [ + + ], + ]; + } + + /** + * @dataProvider providerPrepareInputForAdd + */ + public function testPrepareInputForAdd() { + + } + + public function providerPrepareInputForUpdate() { + return [ + [ + + ], + ]; + } + + /** + * @dataProvider providerPrepareInputForUpdate + */ + public function testPrepareInputForUpdate() { + + } + +} \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorForm.php b/tests/suite-unit/PluginFormcreatorForm.php index c7695c733..9d3395cd5 100644 --- a/tests/suite-unit/PluginFormcreatorForm.php +++ b/tests/suite-unit/PluginFormcreatorForm.php @@ -36,6 +36,36 @@ class PluginFormcreatorForm extends CommonTestCase { protected $formData; + public function providerGetTypeName() { + return [ + [ + 0, + 'Forms' + ], + [ + 1, + 'Form' + ], + [ + 2, + 'Forms' + ], + ]; + } + + /** + * @dataProvider providerGetTypeName + * + * @param integer $nb + * @param string $expected + * @return void + */ + public function testGetTypeName($nb, $expected) { + $instance = new $this->newTestedInstance(); + $output = $instance->getTypeName($nb); + $this->string($output)->isEqualTo($expected); + } + protected function formProvider() { return [ [ @@ -51,25 +81,16 @@ protected function formProvider() { ]; } - /** - * @dataProvider formProvider - */ - public function testCreateForm($formData) { - $form = new \PluginFormcreatorForm(); - $form->add($formData); - $this->boolean($form->isNewItem())->isFalse(); - } - public function providerPrepareInputForAdd() { return [ [ - 'input' => [ 'name' => '', 'description' => '', 'content' => '', ], 'expected' => false, // An empty name should be rejected + 'message' => 'The name cannot be empty!', ], [ 'input' => [ @@ -78,6 +99,7 @@ public function providerPrepareInputForAdd() { 'content' => '<p>être ou ne pas être</p>', ], 'expected' => true, + 'message' => '', ], [ 'input' => [ @@ -86,6 +108,7 @@ public function providerPrepareInputForAdd() { 'content' => '<p>test d\\\'apostrophe</p>', ], 'expected' => true, + 'message' => '', ], ]; } @@ -93,14 +116,15 @@ public function providerPrepareInputForAdd() { /** * @dataProvider providerPrepareInputForAdd * @param array $input - * @param boolean $expected + * @param array|boolean $expected + * @param string $message */ - /* - public function testPrepareInputForAdd($input, $expected) { - $form = new \PluginFormcreatorForm(); - $output = $form->prepareInputForAdd($input); + public function testPrepareInputForAdd($input, $expected, $expectedMessage) { + $instance = $this->newTestedInstance(); + $output = $instance->prepareInputForAdd($input); if ($expected === false) { $this->array($output)->size->isEqualTo(0); + $this->sessionHasMessage($expectedMessage, ERROR); } else { $this->string($output['name'])->isEqualTo($input['name']); $this->string($output['description'])->isEqualTo($output['description']); @@ -108,7 +132,6 @@ public function testPrepareInputForAdd($input, $expected) { $this->array($output)->hasKey('uuid'); } } - */ public function providerPrepareInputForUpdate() { return $this->providerPrepareInputForAdd(); @@ -119,13 +142,12 @@ public function providerPrepareInputForUpdate() { * @param array $input * @param boolean $expected */ - /* - public function testPrepareInputForUpdate($input, $expected) { - $form = new \PluginFormcreatorForm(); - $form->add([ + public function testPrepareInputForUpdate($input, $expected, $expectedMessage) { + $instance = new \PluginFormcreatorForm(); + $instance->add([ 'name' => 'anything', ]); - $output = $form->prepareInputForUpdate($input); + $output = $instance->prepareInputForUpdate($input); if ($expected === false) { $this->array($output)->size->isEqualTo(0); } else { @@ -134,23 +156,6 @@ public function testPrepareInputForUpdate($input, $expected) { $this->string($output['content'])->isEqualTo($output['content']); } } - */ - - /** - * @dataProvider formProvider - */ - public function testUpdateForm($formData) { - $form = new \PluginFormcreatorForm(); - $form->add($formData); - $this->boolean($form->isNewItem())->isFalse(); - - $success = $form->update([ - 'id' => $form->getID(), - 'name' => 'an updated form', - 'validation_required' => 0 - ]); - $this->boolean($success)->isTrue(json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT)); - } /** * @dataProvider formProvider @@ -328,4 +333,46 @@ protected function _checkForm($form = []) { ->hasKeys($keys) ->size->isEqualTo(count($keys)); } + + public function testGetInterface() { + // test Public access + \Session::destroy(); + $output = \PluginFormcreatorForm::getInterface(); + $this->string($output)->isEqualTo('public'); + + // test normal interface + $this->login('glpi', 'glpi'); + $output = \PluginFormcreatorForm::getInterface(); + $this->string($output)->isEqualTo('central'); + + // test simplified interface + $entityConfig = new \PluginFormcreatorEntityConfig(); + $entityConfig->update([ + 'id' => '0', + 'replace_helpdesk' => '0', + ]); + $this->login('post-only', 'postonly'); + $output = \PluginFormcreatorForm::getInterface(); + $this->string($output)->isEqualTo('self-service'); + + // test service catalog + $entityConfig = new \PluginFormcreatorEntityConfig(); + $entityConfig->update([ + 'id' => '0', + 'replace_helpdesk' => \PluginFormcreatorEntityConfig::CONFIG_SIMPLIFIED_SERVICE_CATALOG, + ]); + $this->login('post-only', 'postonly'); + $output = \PluginFormcreatorForm::getInterface(); + $this->string($output)->isEqualTo('servicecatalog'); + + $entityConfig = new \PluginFormcreatorEntityConfig(); + $entityConfig->update([ + 'id' => '0', + 'replace_helpdesk' => \PluginFormcreatorEntityConfig::CONFIG_EXTENDED_SERVICE_CATALOG, + ]); + $this->login('post-only', 'postonly'); + $output = \PluginFormcreatorForm::getInterface(); + $this->string($output)->isEqualTo('servicecatalog'); + + } } diff --git a/tests/suite-unit/PluginFormcreatorTextareaField.php b/tests/suite-unit/PluginFormcreatorTextareaField.php new file mode 100644 index 000000000..15ae055f8 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorTextareaField.php @@ -0,0 +1,46 @@ +. + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ +namespace tests\units; +use GlpiPlugin\Formcreator\Tests\CommonTestCase; + +class PluginFormcreatorTextareaField extends CommonTestCase { + public function testGetName() { + $output = \PluginFormcreatorTextareaField::getName(); + $this->string($output)->isEqualTo('Textarea'); + } + + // public function testIsAnonymousFormCompatible() { + // $instance = new \PluginFormcreatorTextareaField([]); + // $output = $instance->isAnonymousFormCompatible(); + // $this->boolean($output)->isTrue(); + // } +} \ No newline at end of file From 2e113cc39765661f07ef1d43ee2793482f1f13e3 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 16 Oct 2018 11:24:59 +0200 Subject: [PATCH 131/192] test: add tests Signed-off-by: Thierry Bugier From 4969e64d0c4d88481dcfef0e8777e3b852f53934 Mon Sep 17 00:00:00 2001 From: btry Date: Fri, 26 Oct 2018 15:59:30 +0200 Subject: [PATCH 132/192] fix(ldapfield): missing post value when field fails to populate Signed-off-by: btry --- inc/fields/ldapselectfield.class.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/inc/fields/ldapselectfield.class.php b/inc/fields/ldapselectfield.class.php index b861d172e..b938aa02f 100644 --- a/inc/fields/ldapselectfield.class.php +++ b/inc/fields/ldapselectfield.class.php @@ -187,6 +187,9 @@ public static function getJSFields() { public function parseAnswerValues($input) { $key = 'formcreator_field_' . $this->fields['id']; + if (!isset($input[$key])) { + $input[$key] = ''; + } if (!is_string($input[$key])) { return false; } From ac557e3c099dd5c06239bb438d5e647b48d63feb Mon Sep 17 00:00:00 2001 From: btry Date: Fri, 26 Oct 2018 13:09:08 +0200 Subject: [PATCH 133/192] feat(question): forbid use of some qustion types with public forms Signed-off-by: btry --- inc/fieldinterface.class.php | 6 ++ inc/fields/actorfield.class.php | 4 + inc/fields/checkboxesfield.class.php | 4 + inc/fields/datefield.class.php | 4 + inc/fields/datetimefield.class.php | 4 + inc/fields/descriptionfield.class.php | 4 + inc/fields/dropdownfield.class.php | 4 + inc/fields/emailfield.class.php | 4 + inc/fields/filefield.class.php | 4 + inc/fields/floatfield.class.php | 4 + inc/fields/glpiselectfield.class.php | 4 + inc/fields/hiddenfield.class.php | 4 + inc/fields/hostnamefield.class.php | 4 + inc/fields/integerfield.class.php | 4 + inc/fields/ipfield.class.php | 4 + inc/fields/ldapselectfield.class.php | 4 + inc/fields/multiselectfield.class.php | 4 + inc/fields/radiosfield.class.php | 4 + inc/fields/selectfield.class.php | 4 + inc/fields/tagfield.class.php | 4 + inc/fields/textareafield.class.php | 4 + inc/fields/textfield.class.php | 4 + inc/fields/urgencyfield.class.php | 4 + inc/form.class.php | 23 ++++ inc/question.class.php | 36 +++++-- tests/src/CommonTestCase.php | 11 +- .../PluginFormcreatorActorField.php | 7 ++ .../PluginFormcreatorCheckboxesField.php | 6 ++ .../suite-unit/PluginFormcreatorDateField.php | 6 ++ .../PluginFormcreatorDatetimeField.php | 7 ++ .../PluginFormcreatorDescriptionField.php | 6 ++ .../PluginFormcreatorDropdownField.php | 6 ++ .../PluginFormcreatorFloatField.php | 6 ++ tests/suite-unit/PluginFormcreatorForm.php | 62 +++++++++++ .../PluginFormcreatorGlpiselectField.php | 6 ++ .../PluginFormcreatorHiddenField.php | 6 ++ .../PluginFormcreatorIntegerField.php | 6 ++ tests/suite-unit/PluginFormcreatorIpField.php | 6 ++ .../PluginFormcreatorLdapselectField.php | 6 ++ .../PluginFormcreatorMultiSelectField.php | 8 +- .../suite-unit/PluginFormcreatorQuestion.php | 102 +++++++++++++++--- .../PluginFormcreatorRadiosField.php | 8 +- .../PluginFormcreatorSelectField.php | 8 +- .../suite-unit/PluginFormcreatorTextField.php | 6 ++ 44 files changed, 401 insertions(+), 31 deletions(-) diff --git a/inc/fieldinterface.class.php b/inc/fieldinterface.class.php index 0c2cc8c84..a0ad74dbc 100644 --- a/inc/fieldinterface.class.php +++ b/inc/fieldinterface.class.php @@ -192,4 +192,10 @@ public function greaterThan($value); * @return boolean True if the value is less than the field value */ public function LessThan($value); + + /** + * Is the field compatible with anonymous form ? + * @return boolean true if the field can work with anonymous forms + */ + public function isAnonymousFormCompatible(); } diff --git a/inc/fields/actorfield.class.php b/inc/fields/actorfield.class.php index e524fe760..2cffb34f8 100644 --- a/inc/fields/actorfield.class.php +++ b/inc/fields/actorfield.class.php @@ -293,4 +293,8 @@ public function greaterThan($value) { public function lessThan($value) { throw new PluginFormcreatorComparisonException('Meaningless comparison'); } + + public function isAnonymousFormCompatible() { + return false; + } } diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index 1ef8c38c4..98632b87c 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -280,4 +280,8 @@ public function greaterThan($value) { public function lessThan($value) { throw new PluginFormcreatorComparisonException('Meaningless comparison'); } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/datefield.class.php b/inc/fields/datefield.class.php index 09c09ffd0..e5aca09cd 100644 --- a/inc/fields/datefield.class.php +++ b/inc/fields/datefield.class.php @@ -160,4 +160,8 @@ public function parseAnswerValues($input) { $this->value = $input[$key]; return true; } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/datetimefield.class.php b/inc/fields/datetimefield.class.php index 32c82589f..42ff66e3a 100644 --- a/inc/fields/datetimefield.class.php +++ b/inc/fields/datetimefield.class.php @@ -162,4 +162,8 @@ public function parseAnswerValues($input) { $this->value = $input[$key]; return true; } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/descriptionfield.class.php b/inc/fields/descriptionfield.class.php index 5700dba26..53f607ff4 100644 --- a/inc/fields/descriptionfield.class.php +++ b/inc/fields/descriptionfield.class.php @@ -130,4 +130,8 @@ public function lessThan($value) { public function parseAnswerValues($input) { return true; } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index f11854f48..5cf43e0dc 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -330,4 +330,8 @@ public function parseAnswerValues($input) { $this->value = $input[$key]; return true; } + + public function isAnonymousFormCompatible() { + return false; + } } diff --git a/inc/fields/emailfield.class.php b/inc/fields/emailfield.class.php index e2c1db96b..525dc8db4 100644 --- a/inc/fields/emailfield.class.php +++ b/inc/fields/emailfield.class.php @@ -173,4 +173,8 @@ public function greaterThan($value) { public function lessThan($value) { throw new PluginFormcreatorComparisonException('Meaningless comparison'); } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/filefield.class.php b/inc/fields/filefield.class.php index fd925350b..c3223c62d 100644 --- a/inc/fields/filefield.class.php +++ b/inc/fields/filefield.class.php @@ -228,4 +228,8 @@ public function greaterThan($value) { public function lessThan($value) { throw new PluginFormcreatorComparisonException('Meaningless comparison'); } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/floatfield.class.php b/inc/fields/floatfield.class.php index f35c894c9..ff0af4319 100644 --- a/inc/fields/floatfield.class.php +++ b/inc/fields/floatfield.class.php @@ -250,4 +250,8 @@ public function greaterThan($value) { public function lessThan($value) { return !$this->greaterThan($value) && !$this->equals($value); } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/glpiselectfield.class.php b/inc/fields/glpiselectfield.class.php index 8cd24d794..4b8262ec7 100644 --- a/inc/fields/glpiselectfield.class.php +++ b/inc/fields/glpiselectfield.class.php @@ -122,4 +122,8 @@ public function greaterThan($value) { public function lessThan($value) { return !$this->greaterThan($value) && !$this->equals($value); } + + public function isAnonymousFormCompatible() { + return false; + } } diff --git a/inc/fields/hiddenfield.class.php b/inc/fields/hiddenfield.class.php index 501429ab6..b9b4fe2e0 100644 --- a/inc/fields/hiddenfield.class.php +++ b/inc/fields/hiddenfield.class.php @@ -126,4 +126,8 @@ public function greaterThan($value) { public function lessThan($value) { return !$this->greaterThan($value) && !$this->equals($value); } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/hostnamefield.class.php b/inc/fields/hostnamefield.class.php index cb1bd749b..41300e509 100644 --- a/inc/fields/hostnamefield.class.php +++ b/inc/fields/hostnamefield.class.php @@ -99,4 +99,8 @@ public function greaterThan($value) { public function lessThan($value) { return !$this->greaterThan($value) && !$this->equals($value); } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/integerfield.class.php b/inc/fields/integerfield.class.php index ce42c49d0..2c8682e18 100644 --- a/inc/fields/integerfield.class.php +++ b/inc/fields/integerfield.class.php @@ -250,4 +250,8 @@ public function greaterThan($value) { public function lessThan($value) { return !$this->greaterThan($value) && !$this->equals($value); } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/ipfield.class.php b/inc/fields/ipfield.class.php index 1f2c77804..60b68f9b5 100644 --- a/inc/fields/ipfield.class.php +++ b/inc/fields/ipfield.class.php @@ -137,4 +137,8 @@ public function greaterThan($value) { public function lessThan($value) { throw new PluginFormcreatorComparisonException('Meaningless comparison'); } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/ldapselectfield.class.php b/inc/fields/ldapselectfield.class.php index b938aa02f..0e22b17de 100644 --- a/inc/fields/ldapselectfield.class.php +++ b/inc/fields/ldapselectfield.class.php @@ -213,4 +213,8 @@ public function greaterThan($value) { public function lessThan($value) { throw new PluginFormcreatorComparisonException('Meaningless comparison'); } + + public function isAnonymousFormCompatible() { + return false; + } } diff --git a/inc/fields/multiselectfield.class.php b/inc/fields/multiselectfield.class.php index 119447f80..93c853e23 100644 --- a/inc/fields/multiselectfield.class.php +++ b/inc/fields/multiselectfield.class.php @@ -283,4 +283,8 @@ public function lessThan($value) { } return true; } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/radiosfield.class.php b/inc/fields/radiosfield.class.php index 711c2ea4d..1b46f6c6e 100644 --- a/inc/fields/radiosfield.class.php +++ b/inc/fields/radiosfield.class.php @@ -212,4 +212,8 @@ public function greaterThan($value) { public function lessThan($value) { return !$this->greaterThan($value) && !$this->equals($value); } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/selectfield.class.php b/inc/fields/selectfield.class.php index ce55eda0a..706b61c8c 100644 --- a/inc/fields/selectfield.class.php +++ b/inc/fields/selectfield.class.php @@ -166,4 +166,8 @@ public function greaterThan($value) { public function lessThan($value) { return !$this->greaterThan($value) && !$this->equals($value); } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/tagfield.class.php b/inc/fields/tagfield.class.php index d91da6ea1..51e967d17 100644 --- a/inc/fields/tagfield.class.php +++ b/inc/fields/tagfield.class.php @@ -200,4 +200,8 @@ public function greaterThan($value) { public function lessThan($value) { throw new PluginFormcreatorComparisonException('Meaningless comparison'); } + + public function isAnonymousFormCompatible() { + return false; + } } diff --git a/inc/fields/textareafield.class.php b/inc/fields/textareafield.class.php index 652081f64..ea26814e9 100644 --- a/inc/fields/textareafield.class.php +++ b/inc/fields/textareafield.class.php @@ -138,4 +138,8 @@ public function greaterThan($value) { public function lessThan($value) { return !$this->greaterThan($value) && !$this->equals($value); } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/textfield.class.php b/inc/fields/textfield.class.php index 2d9c85973..b78749407 100644 --- a/inc/fields/textfield.class.php +++ b/inc/fields/textfield.class.php @@ -233,4 +233,8 @@ public function greaterThan($value) { public function lessThan($value) { return !$this->greaterThan($value) && !$this->equals($value); } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/fields/urgencyfield.class.php b/inc/fields/urgencyfield.class.php index d0e7dbff1..f7c5f32d3 100644 --- a/inc/fields/urgencyfield.class.php +++ b/inc/fields/urgencyfield.class.php @@ -172,4 +172,8 @@ public function greaterThan($value) { public function lessThan($value) { return !$this->greaterThan($value) && !$this->equals($value); } + + public function isAnonymousFormCompatible() { + return true; + } } diff --git a/inc/form.class.php b/inc/form.class.php index aa29b539f..00d889f44 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -2215,4 +2215,27 @@ static function footer() { return Html::nullFooter(); } } + + /** + * Is the form accessible anonymously (without being logged in) ? + * @return boolean true if the form is accessible anonymously + */ + public function isPublicAccess() { + if ($this->isNewItem()) { + return false; + } + return ($this->getField('access_rights') === (string) \PluginFormcreatorForm::ACCESS_PUBLIC); + } + + /** + * gets the form containing the given section + * @param PluginFormcreatorSection $section + * @return boolean true if success else false + */ + public function getFromDBBySection(PluginFormcreatorSection $section) { + if ($section->isNewItem()) { + return false; + } + return $this->getFromDB($section->getField(self::getForeignKeyField())); + } } diff --git a/inc/question.class.php b/inc/question.class.php index 082351933..0fb7182ee 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -264,13 +264,8 @@ public static function showForForm(CommonDBTM $item, $withtemplate = '') { /** * Validate form fields before add or update a question - * * @param Array $input Datas used to add the item - * * @return Array The modified $input array - * - * @param array $input - * @return array */ private function checkBeforeSave($input) { // Control fields values : @@ -303,19 +298,46 @@ private function checkBeforeSave($input) { $input['fieldtype'], $this ); + if ($this->field === null) { + Session::addMessageAfterRedirect( + // TRANS: $%1$s is a type of field, %2$s is the label of a question + sprintf( + __('Field type %1$s is not available for question %2$s.', 'formcreator'), + $input['fieldtype'], + $input['name'] + ), + false, + ERROR + ); + return []; + } + // - field type is compatible with accessibility of the form + $section = new PluginFormcreatorSection(); + $sectionFk = PluginFormcreatorSection::getForeignKeyField(); + if (isset($input[$sectionFk])) { + $section->getFromDB($input[$sectionFk]); + } else { + $section->getFromDB($this->fields[$sectionFk]); + } + $form = new PluginFormcreatorForm(); + $form->getFromDBBySection($section); + if ($form->isPublicAccess() && !$this->field->isAnonymousFormCompatible()) { + Session::addMessageAfterRedirect(__('This type of question is not compatible with public forms.', 'formcreator'), false, ERROR); + return []; + } // Check the parameters are provided $parameters = $this->field->getEmptyParameters(); if (count($parameters) > 0) { if (!isset($input['_parameters'][$input['fieldtype']])) { // This should not happen - Session::addMessageAfterRedirect(__('This type of question requires parameters', 'formcreator')); + Session::addMessageAfterRedirect(__('This type of question requires parameters', 'formcreator'), false, ERROR); return []; } foreach ($parameters as $parameter) { if (!isset($input['_parameters'][$input['fieldtype']][$parameter->getFieldName()])) { // This should not happen - Session::addMessageAfterRedirect(__('A parameter is missing for this question type', 'formcreator')); + Session::addMessageAfterRedirect(__('A parameter is missing for this question type', 'formcreator'), false, ERROR); return []; } } diff --git a/tests/src/CommonTestCase.php b/tests/src/CommonTestCase.php index 3cec1d80f..c14803bc4 100644 --- a/tests/src/CommonTestCase.php +++ b/tests/src/CommonTestCase.php @@ -151,32 +151,33 @@ protected function restartSession() { session_start(); session_regenerate_id(); session_id(); - //$_SESSION["MESSAGE_AFTER_REDIRECT"] = []; } } protected function getForm($input = []) { if (!isset($input['name'])) { - $input['name'] = 'form'; + $input['name'] = $this->getUniqueString(); } $form = new \PluginFormcreatorForm(); $form->add($input); + $this->boolean($form->isNewItem())->isFalse(); $form->getFromDB($form->getID()); return $form; } - protected function getSection($input = []) { + protected function getSection($input = [], $formInput = []) { $formFk = \PluginFormcreatorForm::getForeignKeyField(); if (!isset($input[$formFk])) { - $formId = $this->getForm()->getID(); + $formId = $this->getForm($formInput)->getID(); $input[$formFk] = $formId; } if (!isset($input['name'])) { - $input['name'] = 'section'; + $input['name'] = $this->getUniqueString(); } $section = new \PluginFormcreatorSection(); $section->add($input); + $this->boolean($section->isNewItem())->isFalse(); return $section; } diff --git a/tests/suite-unit/PluginFormcreatorActorField.php b/tests/suite-unit/PluginFormcreatorActorField.php index 7490e613d..4fd30dd10 100644 --- a/tests/suite-unit/PluginFormcreatorActorField.php +++ b/tests/suite-unit/PluginFormcreatorActorField.php @@ -368,4 +368,11 @@ function() { } )->isInstanceOf(\PluginFormcreatorComparisonException::class); } + + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorActorField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isFalse(); + } } diff --git a/tests/suite-unit/PluginFormcreatorCheckboxesField.php b/tests/suite-unit/PluginFormcreatorCheckboxesField.php index f2ab49756..74ce8a30e 100644 --- a/tests/suite-unit/PluginFormcreatorCheckboxesField.php +++ b/tests/suite-unit/PluginFormcreatorCheckboxesField.php @@ -269,4 +269,10 @@ public function testGetEmptyParameters() { $this->object($output['range']) ->isInstanceOf(\PluginFormcreatorQuestionRange::class); } + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorCheckboxesField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isTrue(); + } } \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorDateField.php b/tests/suite-unit/PluginFormcreatorDateField.php index eced8b211..0bdbde478 100644 --- a/tests/suite-unit/PluginFormcreatorDateField.php +++ b/tests/suite-unit/PluginFormcreatorDateField.php @@ -148,4 +148,10 @@ public function testGetName() { $output = \PluginFormcreatorDateField::getName(); $this->string($output)->isEqualTo('Date'); } + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorDateField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isTrue(); + } } \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorDatetimeField.php b/tests/suite-unit/PluginFormcreatorDatetimeField.php index 1a27f6015..0c87137c9 100644 --- a/tests/suite-unit/PluginFormcreatorDatetimeField.php +++ b/tests/suite-unit/PluginFormcreatorDatetimeField.php @@ -210,4 +210,11 @@ public function providerSerializeValue() { public function testSerializeValue() { $instance = $this->newTestedInstance([]); } + + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorDatetimeField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isTrue(); + } } \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorDescriptionField.php b/tests/suite-unit/PluginFormcreatorDescriptionField.php index 4efa2ed14..0eac5b05f 100644 --- a/tests/suite-unit/PluginFormcreatorDescriptionField.php +++ b/tests/suite-unit/PluginFormcreatorDescriptionField.php @@ -93,4 +93,10 @@ public function testPrepareQuestionInputForSave($input, $expected, $message) { } } } + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorDescriptionField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isTrue(); + } } \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorDropdownField.php b/tests/suite-unit/PluginFormcreatorDropdownField.php index 779cec5b2..688e5ba18 100644 --- a/tests/suite-unit/PluginFormcreatorDropdownField.php +++ b/tests/suite-unit/PluginFormcreatorDropdownField.php @@ -91,4 +91,10 @@ public function testPrepareQuestionInputForSave($input, $expected) { $this->variable($output[$key])->isIdenticalTo($value); } } + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorDropdownField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isFalse(); + } } diff --git a/tests/suite-unit/PluginFormcreatorFloatField.php b/tests/suite-unit/PluginFormcreatorFloatField.php index 197b39672..5d6be64d0 100644 --- a/tests/suite-unit/PluginFormcreatorFloatField.php +++ b/tests/suite-unit/PluginFormcreatorFloatField.php @@ -192,4 +192,10 @@ public function testGetEmptyParameters() { $this->object($output['regex']) ->isInstanceOf(\PluginFormcreatorQuestionRegex::class); } + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorFloatField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isTrue(); + } } diff --git a/tests/suite-unit/PluginFormcreatorForm.php b/tests/suite-unit/PluginFormcreatorForm.php index 9d3395cd5..7f7e1afda 100644 --- a/tests/suite-unit/PluginFormcreatorForm.php +++ b/tests/suite-unit/PluginFormcreatorForm.php @@ -375,4 +375,66 @@ public function testGetInterface() { $this->string($output)->isEqualTo('servicecatalog'); } + + + public function providerIsPublicAcess() { + return [ + 'not public' =>[ + 'input' => [ + 'access_rights' => (string) \PluginFormcreatorForm::ACCESS_PRIVATE, + 'name' => $this->getUniqueString() + ], + 'expected' => false, + ], + 'public' =>[ + 'input' => [ + 'access_rights' => (string) \PluginFormcreatorForm::ACCESS_PUBLIC, + 'name' => $this->getUniqueString() + ], + 'expected' => true, + ], + 'by profile' =>[ + 'input' => [ + 'access_rights' => (string) \PluginFormcreatorForm::ACCESS_RESTRICTED, + 'name' => $this->getUniqueString() + ], + 'expected' => false, + ], + ]; + } + + /** + * @dataProvider providerIsPublicAcess + */ + public function testIsPublicAcess($input, $expected) { + $instance = new $this->newTestedInstance(); + $instance->add($input); + $this->boolean($instance->isNewItem())->isFalse(); + $output = $instance->isPublicAccess(); + $this->boolean($output)->isEqualTo($expected); + } + public function providerGetFromSection() { + $section = $this->getSection(); + $formId = $section->getField(\PluginFormcreatorForm::getForeignKeyField()); + $dataset = [ + [ + 'section' => $section, + 'expectedId' => true, + ], + [ + 'section' => new \PluginFormcreatorSection(), + 'expected' => false, + ], + ]; + return $dataset; + } + + /** + * @dataProvider providerGetFromSection + */ + public function testgetFormFromSection($section, $expected) { + $form = new \PluginFormcreatorForm(); + $output = $form->getFromDBBySection($section); + $this->boolean($output)->isEqualTo($expected); + } } diff --git a/tests/suite-unit/PluginFormcreatorGlpiselectField.php b/tests/suite-unit/PluginFormcreatorGlpiselectField.php index e84b41f15..e76544c00 100644 --- a/tests/suite-unit/PluginFormcreatorGlpiselectField.php +++ b/tests/suite-unit/PluginFormcreatorGlpiselectField.php @@ -263,4 +263,10 @@ public function testIsValid($fields, $data, $expectedValue, $expectedValidity) { $output = $instance->isValid(); $this->boolean($output)->isEqualTo($expectedValidity); } + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorGlpiselectField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isFalse(); + } } \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorHiddenField.php b/tests/suite-unit/PluginFormcreatorHiddenField.php index c19d8fef2..676d1489f 100644 --- a/tests/suite-unit/PluginFormcreatorHiddenField.php +++ b/tests/suite-unit/PluginFormcreatorHiddenField.php @@ -44,4 +44,10 @@ public function testIsValid() { $output = $instance->isValid(''); $this->boolean($output)->isTrue(); } + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorHiddenField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isTrue(); + } } \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorIntegerField.php b/tests/suite-unit/PluginFormcreatorIntegerField.php index 314909897..8fc10ee52 100644 --- a/tests/suite-unit/PluginFormcreatorIntegerField.php +++ b/tests/suite-unit/PluginFormcreatorIntegerField.php @@ -203,4 +203,10 @@ public function testIsValid($fields, $data, $expectedValue, $expectedValidity) { $isValid = $instance->isValid(); $this->boolean((boolean) $isValid)->isEqualTo($expectedValidity); } + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorIntegerField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isTrue(); + } } \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorIpField.php b/tests/suite-unit/PluginFormcreatorIpField.php index 4f08923af..d18b3b0e4 100644 --- a/tests/suite-unit/PluginFormcreatorIpField.php +++ b/tests/suite-unit/PluginFormcreatorIpField.php @@ -47,4 +47,10 @@ public function testIsValid() { $output = $instance->isValid(''); $this->boolean($output)->isTrue(); } + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorIpField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isTrue(); + } } \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorLdapselectField.php b/tests/suite-unit/PluginFormcreatorLdapselectField.php index 7cf14071f..34707599c 100644 --- a/tests/suite-unit/PluginFormcreatorLdapselectField.php +++ b/tests/suite-unit/PluginFormcreatorLdapselectField.php @@ -41,4 +41,10 @@ public function testGetName() { $output = $instance->getName(); $this->string($output)->isEqualTo('LDAP Select'); } + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorLdapselectField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isFalse(); + } } \ No newline at end of file diff --git a/tests/suite-unit/PluginFormcreatorMultiSelectField.php b/tests/suite-unit/PluginFormcreatorMultiSelectField.php index 5024a7804..3976d7b8a 100644 --- a/tests/suite-unit/PluginFormcreatorMultiSelectField.php +++ b/tests/suite-unit/PluginFormcreatorMultiSelectField.php @@ -259,4 +259,10 @@ public function testGetEmptyParameters() { $this->object($output['range']) ->isInstanceOf(\PluginFormcreatorQuestionRange::class); } -} \ No newline at end of file + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorMultiSelectField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isTrue(); + } +} diff --git a/tests/suite-unit/PluginFormcreatorQuestion.php b/tests/suite-unit/PluginFormcreatorQuestion.php index 3a34b5019..fe167e5c5 100644 --- a/tests/suite-unit/PluginFormcreatorQuestion.php +++ b/tests/suite-unit/PluginFormcreatorQuestion.php @@ -110,10 +110,20 @@ public function testDuplicate() { } public function providerPrepareInputForAdd() { - return [ + $section1 = $this->getSection( + [], + [] + ); + $section2 = $this->getSection( + [], + [ + 'access_rights' => \PluginFormcreatorForm::ACCESS_PUBLIC, + ] + ); + $dataset = [ [ 'input' => [ - 'plugin_formcreator_sections_id' => $this->section->getID(), + 'plugin_formcreator_sections_id' => $section1->getID(), 'fieldtype' => 'radios', 'name' => "it\'s nice", 'values' => "it\'s nice\r\nit's good", @@ -136,7 +146,7 @@ public function providerPrepareInputForAdd() { ], ], 'expected' => [ - 'plugin_formcreator_sections_id' => $this->section->getID(), + 'plugin_formcreator_sections_id' => $section1->getID(), 'fieldtype' => 'radios', 'name' => "it\'s nice", 'values' => "it\'s nice\r\nit's good", @@ -157,9 +167,66 @@ public function providerPrepareInputForAdd() { ] ] ], - ] + ], + 'expecetedError' => null, + ], + 'field type incompatible' => [ + 'input' => [ + 'plugin_formcreator_sections_id' => $section2->getID(), + 'fieldtype' => 'actor', + 'name' => "a question", + 'values' => "", + 'required' => '1', + 'show_empty' => '0', + 'default_values' => 'it\'s nice', + 'desription' => "it\'s excellent", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ], + 'expected' => [], + 'expecetedError' => 'This type of question is not compatible with public forms.', + ], + 'non existent field type' => [ + 'input' => [ + 'plugin_formcreator_sections_id' => $section2->getID(), + 'fieldtype' => 'nonexistent', + 'name' => "question-name", + 'values' => "", + 'required' => '1', + 'show_empty' => '0', + 'default_values' => 'it\'s nice', + 'desription' => "it\'s excellent", + 'order' => '1', + 'show_rule' => 'always', + '_parameters' => [ + 'text' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ], + 'regex' => [ + 'regex' => '' + ] + ] + ], + ], + 'expected' => [], + 'expecetedError' => 'Field type nonexistent is not available for question question-name.', ], ]; + + return $dataset; } public function providerPrepareInputForUpdate() { @@ -169,20 +236,23 @@ public function providerPrepareInputForUpdate() { /** * @dataProvider providerPrepareInputForAdd */ - public function testPrepareInputForAdd($input, $expected) { - $section = $this->getSection(); - $input[$section::getForeignKeyField()] = $section->getID(); - + public function testPrepareInputForAdd($input, $expected, $expectedError) { $instance = new \PluginFormcreatorQuestion(); $output = $instance->prepareInputForAdd($input); - $this->array($output)->hasKeys(array_keys($expected)); - /* - // Disabled for now - $this->array($output)->containsValues($expected); - */ - $this->array($output)->hasKey('uuid'); - // The method added a UUID key - $this->array($output)->size->isEqualTo(count($expected) + 1); + + if ($expectedError !== null) { + $this->sessionHasMessage($expectedError, ERROR); + $this->array($output)->hasSize(0); + } else { + $this->array($output)->hasKeys(array_keys($expected)); + /* + // Disabled for now + $this->array($output)->containsValues($expected); + */ + $this->array($output)->hasKey('uuid'); + // The method added a UUID key + $this->array($output)->size->isEqualTo(count($expected) + 1); + } } /** diff --git a/tests/suite-unit/PluginFormcreatorRadiosField.php b/tests/suite-unit/PluginFormcreatorRadiosField.php index 3fe7789a4..e353878b5 100644 --- a/tests/suite-unit/PluginFormcreatorRadiosField.php +++ b/tests/suite-unit/PluginFormcreatorRadiosField.php @@ -79,4 +79,10 @@ public function testGetName() { $this->string($output)->isEqualTo('Radios'); } -} \ No newline at end of file + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorRadiosField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isTrue(); + } +} diff --git a/tests/suite-unit/PluginFormcreatorSelectField.php b/tests/suite-unit/PluginFormcreatorSelectField.php index 6f7d712a9..3397aa254 100644 --- a/tests/suite-unit/PluginFormcreatorSelectField.php +++ b/tests/suite-unit/PluginFormcreatorSelectField.php @@ -149,4 +149,10 @@ public function testGetName() { $output = \PluginFormcreatorSelectField::getName(); $this->string($output)->isEqualTo('Select'); } -} \ No newline at end of file + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorSelectField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isTrue(); + } +} diff --git a/tests/suite-unit/PluginFormcreatorTextField.php b/tests/suite-unit/PluginFormcreatorTextField.php index 136e1fe49..19fe8aa01 100644 --- a/tests/suite-unit/PluginFormcreatorTextField.php +++ b/tests/suite-unit/PluginFormcreatorTextField.php @@ -204,4 +204,10 @@ public function testGetName() { $output = \PluginFormcreatorTextField::getName(); $this->string($output)->isEqualTo('Text'); } + + public function testIsAnonymousFormCompatible() { + $instance = new \PluginFormcreatorTextField([]); + $output = $instance->isAnonymousFormCompatible(); + $this->boolean($output)->isTrue(); + } } From 7c9733dfa12ffd83c2d263011e6e69ce2a9f2311 Mon Sep 17 00:00:00 2001 From: btry Date: Fri, 26 Oct 2018 16:33:18 +0200 Subject: [PATCH 134/192] feat(form): forbid change of access right if incompatible questions found Signed-off-by: btry --- inc/form.class.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/inc/form.class.php b/inc/form.class.php index 00d889f44..1b116537d 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1072,6 +1072,30 @@ public function prepareInputForUpdate($input) { if (isset($input['access_rights']) || isset($_POST['massiveaction']) || isset($input['usage_count'])) { + + if (isset($input['access_rights']) + && $input['access_right'] == self::ACCESS_PUBLIC + ) { + // check that accessibility to eh form is compatible with its questions + $question = new PluginFormcreatorQuestion(); + $questions = $question->getQuestionsFromForm($this->getID()); + $incompatibleQuestion = false; + foreach ($questions as $question) { + $field = PluginFormcreatorFields::getFieldInstance( + $question->fields['fieldtype'], + $question + ); + if (!$field->isAnonymousFormCompatible()) { + $incompatibleQuestion = true; + $message = __('The question %s is not compatible with public forms', 'formcreator'); + Session::addMessageAfterRedirect(sprintf($message, $question->fields['name']), false, ERROR); + } + } + if ($incompatibleQuestion) { + return []; + } + } + return $input; } else { $this->updateValidators(); From f65887faaebdfcdfe4b3a0b236a42c9a57dea120 Mon Sep 17 00:00:00 2001 From: btry Date: Fri, 26 Oct 2018 18:14:27 +0200 Subject: [PATCH 135/192] fix(question): move up/down broken Signed-off-by: btry --- inc/question.class.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/inc/question.class.php b/inc/question.class.php index 0fb7182ee..de953444b 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -419,8 +419,7 @@ public function prepareInputForUpdate($input) { $input['uuid'] = plugin_formcreator_getUuid(); } - if (!empty($input) - && isset($input['plugin_formcreator_sections_id'])) { + if (isset($input['plugin_formcreator_sections_id'])) { // If change section, reorder questions if ($input['plugin_formcreator_sections_id'] != $this->fields['plugin_formcreator_sections_id']) { $oldId = $this->fields['plugin_formcreator_sections_id']; @@ -484,11 +483,12 @@ public function moveUp() { $this->update([ 'id' => $this->getID(), 'order' => $otherItem->getField('order'), + '_skip_checks' => true, ]); $otherItem->update([ - '_skip_checks' => true, 'id' => $otherItem->getID(), 'order' => $order, + '_skip_checks' => true, ]); } } @@ -497,8 +497,9 @@ public function moveUp() { * Moves the question down in the ordered list of questions in the section */ public function moveDown() { - $order = $this->fields['order']; - $sectionId = $this->fields['plugin_formcreator_sections_id']; + $order = $this->fields['order']; + $sectionId = $this->fields['plugin_formcreator_sections_id']; + $otherItem = new static(); $otherItem->getFromDBByRequest([ 'WHERE' => [ 'AND' => [ @@ -513,11 +514,12 @@ public function moveDown() { $this->update([ 'id' => $this->getID(), 'order' => $otherItem->getField('order'), + '_skip_checks' => true, ]); $otherItem->update([ - '_skip_checks' => true, 'id' => $otherItem->getID(), 'order' => $order, + '_skip_checks' => true, ]); } } @@ -622,7 +624,10 @@ public function pre_deleteItem() { public function post_updateItem($history = 1) { if (!in_array('fieldtype', $this->updates)) { // update question parameters into the database - $this->field->updateParameters($this, $this->input); + if ($this->field instanceof PluginFormcreatorFieldInterface) { + // Set by self::checkBeforeSave() + $this->field->updateParameters($this, $this->input); + } } else { // Field type changed // Drop old parameters From 171579675e26fa7d10bcb49020d1d274a378c691 Mon Sep 17 00:00:00 2001 From: btry Date: Fri, 26 Oct 2018 23:27:43 +0200 Subject: [PATCH 136/192] test: update tests for GLPI 9.4 Signed-off-by: btry --- tests/bootstrap.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4ac047b8b..3c6bf31a7 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,6 +1,6 @@ Date: Sun, 28 Oct 2018 18:25:46 +0100 Subject: [PATCH 137/192] fix(targetbase): deduplication of group raises a warning Signed-off-by: btry --- inc/targetbase.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index 3ee77f2eb..1923a6fd9 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -381,7 +381,7 @@ protected function addGroupActor($role, $group) { return false; } - $actorKey = array_search($userId, $actorType); + $actorKey = array_search($group, $actorType); if ($actorKey !== false) { return false; } From f087ad0841d3b764702f5acdc02869db969f0805 Mon Sep 17 00:00:00 2001 From: btry Date: Sun, 28 Oct 2018 17:58:39 +0100 Subject: [PATCH 138/192] fix(targetchange): time to resolve not populated when required Signed-off-by: btry --- inc/targetbase.class.php | 52 ++++++++++++++++++++++++++++++++++++++ inc/targetchange.class.php | 40 +---------------------------- inc/targetticket.class.php | 32 ----------------------- 3 files changed, 53 insertions(+), 71 deletions(-) diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index 3ee77f2eb..ae5c4c911 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -980,4 +980,56 @@ function change_location() { echo ''; echo ''; } + + /** + * Sets the time to resolve of the target object + * + * @param array $data data of the target object + * @param PluginFormcreatorForm_Answer $formanswer Answers previously saved + * @return array updated data of the target object + */ + protected function setTargetDueDate($data, PluginFormcreatorForm_Answer $formanswer) { + global $DB; + + $answer = new PluginFormcreatorAnswer(); + if ($this->fields['due_date_question'] !== null) { + $request = [ + 'FROM' => $answer::getTable(), + 'WHERE' => [ + 'AND' => [ + $formanswer::getForeignKeyField() => $formanswer->fields['id'], + PluginFormcreatorQuestion::getForeignKeyField() => $this->fields['due_date_question'], + ], + ], + ]; + $iterator = $DB->request($request); + if ($iterator->count() > 0) { + $iterator->rewind(); + $date = $iterator->current(); + } + } else { + $date = null; + } + $str = "+" . $this->fields['due_date_value'] . " " . $this->fields['due_date_period']; + + switch ($this->fields['due_date_rule']) { + case 'answer': + $due_date = $date['answer']; + break; + case 'ticket': + $due_date = date('Y-m-d H:i:s', strtotime($str)); + break; + case 'calcul': + $due_date = date('Y-m-d H:i:s', strtotime($date['answer'] . " " . $str)); + break; + default: + $due_date = null; + break; + } + if (!is_null($due_date)) { + $data['time_to_resolve'] = $due_date; + } + + return $data; + } } diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index 3848ff240..ea6190992 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -1083,44 +1083,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { break; } - // Define due date - if ($this->fields['due_date_question'] !== null) { - $request = [ - 'FROM' => $answer::getTable(), - 'WHERE' => [ - 'AND' => [ - $formanswer::getForeignKeyField() => $formanswer->fields['id'], - PluginFormcreatorQuestion::getForeignKeyField() => $this->fields['due_date_question'], - ], - ], - ]; - $iterator = $DB->request($request); - if ($iterator->count() > 0) { - $iterator->rewind(); - $date = $iterator->current(); - } - } else { - $date = null; - } - $str = "+" . $this->fields['due_date_value'] . " " . $this->fields['due_date_period']; - - switch ($this->fields['due_date_rule']) { - case 'answer': - $due_date = $date['answer']; - break; - case 'ticket': - $due_date = date('Y-m-d H:i:s', strtotime($str)); - break; - case 'calcul': - $due_date = date('Y-m-d H:i:s', strtotime($date['answer'] . " " . $str)); - break; - default: - $due_date = null; - break; - } - if (!is_null($due_date)) { - $data['due_date'] = $due_date; - } + $data = $this->setTargetDueDate($data, $formanswer); $data = $this->requesters + $this->observers + $this->assigned + $this->assignedSuppliers + $data; $data = $this->requesterGroups + $this->observerGroups + $this->assignedGroups + $data; @@ -1133,7 +1096,6 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { // Add tag if presents $plugin = new Plugin(); if ($plugin->isActivated('tag')) { - $tagObj = new PluginTagTagItem(); $tags = []; diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index da04eaf65..e66a72a13 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -1370,38 +1370,6 @@ protected function setTargetCategory($data, $formanswer) { return $data; } - protected function setTargetDueDate($data, $formanswer) { - $answer = new PluginFormcreatorAnswer(); - if ($this->fields['due_date_question'] !== null) { - $found = $answer->find('`plugin_formcreator_forms_answers_id` = '.$formanswer->fields['id']. - ' AND `plugin_formcreator_questions_id` = '.$this->fields['due_date_question']); - $date = array_shift($found); - } else { - $date = null; - } - $str = "+" . $this->fields['due_date_value'] . " " . $this->fields['due_date_period']; - - switch ($this->fields['due_date_rule']) { - case 'answer': - $due_date = $date['answer']; - break; - case 'ticket': - $due_date = date('Y-m-d H:i:s', strtotime($str)); - break; - case 'calcul': - $due_date = date('Y-m-d H:i:s', strtotime($date['answer'] . " " . $str)); - break; - default: - $due_date = null; - break; - } - if (!is_null($due_date)) { - $data['time_to_resolve'] = $due_date; - } - - return $data; - } - protected function setTargetUrgency($data, $formanswer) { switch ($this->fields['urgency_rule']) { case 'answer': From f3701fb18959324e0bf5ea12d8c2c79fe3fb4749 Mon Sep 17 00:00:00 2001 From: btry Date: Sun, 28 Oct 2018 18:18:09 +0100 Subject: [PATCH 139/192] fix(targetchange): title edition fails Signed-off-by: btry --- inc/targetchange.class.php | 15 +++++++++++++++ inc/targetticket.class.php | 13 ++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index ea6190992..8c203dde4 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -236,6 +236,7 @@ public function showForm($options = []) { echo ''; echo '' . __('Description') . ' *'; echo ''; + echo ''; echo ''; echo ''; @@ -891,6 +892,20 @@ public function prepareInputForUpdate($input) { } } + $target = new PluginFormcreatorTarget(); + $target->getFromDBByCrit([ + 'itemtype' => self::class, + 'items_id' => $this->getID() + ]); + if (!$target->isNewItem()) { + $target->update([ + 'id' => $target->getID(), + 'name' => $input['name'], + ]); + } + $input['name'] = $input['title']; + unset($input['title']); + return $input; } diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index e66a72a13..522b4cfed 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -924,9 +924,16 @@ public function prepareInputForUpdate($input) { } $target = new PluginFormcreatorTarget(); - $found = $target->find('items_id = ' . $this->getID()); - $found = array_shift($found); - $target->update(['id' => $found['id'], 'name' => $input['name']]); + $target->getFromDBByCrit([ + 'itemtype' => self::class, + 'items_id' => $this->getID() + ]); + if (!$target->isNewItem()) { + $target->update([ + 'id' => $target->getID(), + 'name' => $input['name'], + ]); + } $input['name'] = $input['title']; unset($input['title']); From 83247c2a6b75f3fbfe14f0767fe1d33100595ec4 Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Mon, 29 Oct 2018 09:56:04 +0100 Subject: [PATCH 140/192] feat(core): add status label on list --- inc/issue.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/inc/issue.class.php b/inc/issue.class.php index 476229351..a40c482b7 100644 --- a/inc/issue.class.php +++ b/inc/issue.class.php @@ -495,11 +495,12 @@ public static function giveItem($itemtype, $option_id, $data, $num) { switch ($data['raw']['sub_itemtype']) { case 'Ticket': $status = Ticket::getStatus($data['raw']["ITEM_$num"]); - return Ticket::getStatusIcon($data['raw']["ITEM_$num"]); + return Ticket::getStatusIcon($data['raw']["ITEM_$num"])." ".$status; break; case 'PluginFormcreatorForm_Answer': - return PluginFormcreatorForm_Answer::getSpecificValueToDisplay('status', $data['raw']["ITEM_$num"]); + return PluginFormcreatorForm_Answer::getSpecificValueToDisplay('status', $data['raw']["ITEM_$num"]) + ." ".__($data['raw']["ITEM_$num"], 'formcreator'); break; } break; From 8dec5d21a09ca50f10b046804f7da06df56aa377 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 29 Oct 2018 15:59:59 +0100 Subject: [PATCH 141/192] fix(form_answer): refuse and accept form answers Signed-off-by: btry --- inc/form_answer.class.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index bc713ebc7..52f017911 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -929,12 +929,24 @@ public function refuseAnswers($data) { $form = new PluginFormcreatorForm(); $form->getFromDB($data['plugin_formcreator_forms_id']); + $fields = []; + // Prepare form fields for validation + $question = new PluginFormcreatorQuestion(); if (!$this->canValidate($form, $this)) { Session::addMessageAfterRedirect(__('You are not the validator of these answers', 'formcreator'), true, ERROR); return false; } - return $this->saveAnswers($data); + $found_questions = $question->getQuestionsFromForm($this->getID()); + foreach ($found_questions as $id => $question) { + $key = 'formcreator_field_' . $id; + $fields[$id] = PluginFormcreatorFields::getFieldInstance( + $question->fields['fieldtype'], + $question + ); + } + + return $this->saveAnswers($form, $data, $fields); } /** @@ -957,7 +969,24 @@ public function acceptAnswers($data) { return false; } - return $this->saveAnswers($data); + $fields = []; + // Prepare form fields for validation + $question = new PluginFormcreatorQuestion(); + if (!$this->canValidate($form, $this)) { + Session::addMessageAfterRedirect(__('You are not the validator of these answers', 'formcreator'), true, ERROR); + return false; + } + + $found_questions = $question->getQuestionsFromForm($this->getID()); + foreach ($found_questions as $id => $question) { + $key = 'formcreator_field_' . $id; + $fields[$id] = PluginFormcreatorFields::getFieldInstance( + $question->fields['fieldtype'], + $question + ); + } + + return $this->saveAnswers($form, $data, $fields); } /** From 095ce601abd4d8d2fe8cef4a92cd0a2dc9d0db22 Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Mon, 29 Oct 2018 13:47:11 +0100 Subject: [PATCH 142/192] fix(core): clean doc name on create issue --- inc/fields/filefield.class.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/inc/fields/filefield.class.php b/inc/fields/filefield.class.php index c3223c62d..c627ade88 100644 --- a/inc/fields/filefield.class.php +++ b/inc/fields/filefield.class.php @@ -144,7 +144,7 @@ public static function getJSFields() { * * @return integer|NULL */ - private function saveDocument($file) { + private function saveDocument($file, $prefix) { global $DB; $sectionTable = PluginFormcreatorSection::getTable(); @@ -177,14 +177,15 @@ private function saveDocument($file) { return; } - $doc = new Document(); - $file_data = []; - $file_data["name"] = Toolbox::addslashes_deep($form->getField('name'). ' - ' . $this->fields['name']); - $file_data["entities_id"] = isset($_SESSION['glpiactive_entity']) - ? $_SESSION['glpiactive_entity'] - : $form->getField('entities_id'); - $file_data["is_recursive"] = $form->getField('is_recursive'); - $file_data['_filename'] = [$file]; + $doc = new Document(); + $file_data = []; + $file_data["name"] = Toolbox::addslashes_deep($form->getField('name'). ' - ' . $this->fields['name']); + $file_data["entities_id"] = isset($_SESSION['glpiactive_entity']) + ? $_SESSION['glpiactive_entity'] + : $form->getField('entities_id'); + $file_data["is_recursive"] = $form->getField('is_recursive'); + $file_data['_filename'] = [$file]; + $file_data['_prefix_filename'] = [$prefix]; if ($docID = $doc->add($file_data)) { return $docID; } @@ -199,10 +200,13 @@ public function parseAnswerValues($input) { } $answer_value = []; + $index = 0; foreach ($input["_$key"] as $document) { if (is_file(GLPI_TMP_DIR . '/' . $document)) { - $answer_value[] = $this->saveDocument($document); + $prefix = $input['_prefix_formcreator_field_' . $this->fields['id']][$index]; + $answer_value[] = $this->saveDocument($document, $prefix); } + $index++; } $this->uploadData = $answer_value; $this->value = __('Attached document', 'formcreator'); From d7b6dc8691ef4f0a4b04ad1da97d6b78dc162dc3 Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Mon, 29 Oct 2018 14:08:17 +0100 Subject: [PATCH 143/192] feat(core): add requester on validation form --- inc/form_answer.class.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index 52f017911..1303b86ed 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -529,6 +529,12 @@ public function showForm($ID, $options = []) { formcreatorShowFields($("form[name=\'' . $formName . '\']")); })'); + //add requester info + echo '
'; + echo ''; + echo Dropdown::getDropdownName('glpi_users', $this->fields['requester_id']); + echo '
'; + // Display submit button if (($this->fields['status'] == 'refused') && ($_SESSION['glpiID'] == $this->fields['requester_id'])) { echo '
'; From f20acbff5a7c3da4027065cbdf54457b5d7ba72c Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Mon, 29 Oct 2018 15:18:15 +0100 Subject: [PATCH 144/192] feat(core): add options to display ITIL Category question --- inc/fields/dropdownfield.class.php | 9 +++++++++ inc/question.class.php | 8 +++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index 5cf43e0dc..b0b4cb1ce 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -77,6 +77,15 @@ public function displayField($canEdit = true) { case 'incident': $dparams['condition'] .= " AND `is_incident` = '1'"; break; + case 'both': + $dparams['condition'] .= " AND `is_incident` = '1' OR `is_request` = '1' "; + break; + case 'change': + $dparams['condition'] .= " AND `is_change` = '1'"; + break; + case 'all': + $dparams['condition'] .= " AND `is_change` = '1' OR `is_incident` = '1' OR `is_request` = '1'"; + break; } if (isset($decodedValues['show_ticket_categories_depth']) && $decodedValues['show_ticket_categories_depth'] > 0) { diff --git a/inc/question.class.php b/inc/question.class.php index de953444b..3c760561c 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -934,9 +934,11 @@ function plugin_formcreator_hideAllParameters() { echo ''; echo ''; $ticketCategoriesOptions = [ - 'request' => __('Request categories', 'formcreator'), - 'incident' => __('Incident categories', 'formcreator'), - 'both' => __('Both', 'formcreator'), + 'request' => __('Request categories', 'formcreator'), + 'incident' => __('Incident categories', 'formcreator'), + 'both' => __('Request categories', 'formcreator'). " + ".__('Incident categories', 'formcreator'), + 'change' => __('Change'), + 'all' => __('All'), ]; dropdown::showFromArray('show_ticket_categories', $ticketCategoriesOptions, [ 'rand' => $rand, From 5711ef08277f329cf6b1b52768d39b50d4ae58a8 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 30 Oct 2018 16:13:15 +0100 Subject: [PATCH 145/192] fix(targetbase): fix double quote renderiing in targets Signed-off-by: btry --- inc/targetchange.class.php | 4 ++-- inc/targetticket.class.php | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index 8c203dde4..b84ceeb3b 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -981,7 +981,6 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { ]; foreach ($changeFields as $changeField) { $data[$changeField] = $this->fields[$changeField]; - $data[$changeField] = addslashes($data[$changeField]); $data[$changeField] = str_replace("\r\n", '\r\n', $data[$changeField]); if (strpos($data[$changeField], '##FULLFORM##') !== false) { $data[$changeField] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data[$changeField]); @@ -993,10 +992,11 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { $data[$changeField] = $this->parseTags($data[$changeField], $formanswer); - // This targer does not supports rich text + // This target does not supports rich text $data[$changeField] = strip_tags($data[$changeField], '

'); $data[$changeField] = str_replace('

', '', $data[$changeField]); $data[$changeField] = str_replace('

', '\r\n', $data[$changeField]); + $data[$changeField] = Toolbox::addslashes_deep($data[$changeField]); } $data['_users_id_recipient'] = $_SESSION['glpiID']; diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index 522b4cfed..833f1390f 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -1113,10 +1113,10 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { // Parse data // TODO: generate instances of all answers of the form and use them for the fullform computation // and the computation from a admin-defined target ticket template - $data['name'] = addslashes($this->fields['name']); + $data['name'] = $this->fields['name']; $data['name'] = $this->parseTags($data['name'], $formanswer); + $data['name'] = Toolbox::addslashes_deep($data['name']); - $data['content'] = addslashes($this->fields['content']); $data['content'] = str_replace("\r\n", '\r\n', $data['content']); if (strpos($data['content'], '##FULLFORM##') !== false) { $data['content'] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data['content']); @@ -1128,8 +1128,9 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { $data['content'] = $this->parseTags($data['content'], $formanswer); if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { - $data['content'] = htmlentities($data['content']); + $data['content'] = htmlentities($data['content'], ENT_NOQUOTES); } + $data['content'] = Toolbox::addslashes_deep($data['content']); $data['_users_id_recipient'] = $_SESSION['glpiID']; $data['_tickettemplates_id'] = $this->fields['tickettemplates_id']; From fe3e65c67b4c811fa8c0a235e90243a768dab7f7 Mon Sep 17 00:00:00 2001 From: btry Date: Mon, 29 Oct 2018 16:05:22 +0100 Subject: [PATCH 146/192] refactor: remove dead lines of code Signed-off-by: btry --- inc/form.class.php | 1 - inc/form_answer.class.php | 3 --- 2 files changed, 4 deletions(-) diff --git a/inc/form.class.php b/inc/form.class.php index 1b116537d..17b7026bc 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1190,7 +1190,6 @@ public function saveForm($input) { if (!$fields[$id]->isPrerequisites()) { continue; } - $key = 'formcreator_field_' . $id; if (PluginFormcreatorFields::isVisible($id, $fields) && !$fields[$id]->isValid()) { $valid = false; break; diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index 1303b86ed..cab99b753 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -911,7 +911,6 @@ public function updateAnswers($input) { $found_questions = $question->getQuestionsFromForm($this->getID()); foreach ($found_questions as $id => $question) { - $key = 'formcreator_field_' . $id; $fields[$id] = PluginFormcreatorFields::getFieldInstance( $question->fields['fieldtype'], $question @@ -945,7 +944,6 @@ public function refuseAnswers($data) { $found_questions = $question->getQuestionsFromForm($this->getID()); foreach ($found_questions as $id => $question) { - $key = 'formcreator_field_' . $id; $fields[$id] = PluginFormcreatorFields::getFieldInstance( $question->fields['fieldtype'], $question @@ -985,7 +983,6 @@ public function acceptAnswers($data) { $found_questions = $question->getQuestionsFromForm($this->getID()); foreach ($found_questions as $id => $question) { - $key = 'formcreator_field_' . $id; $fields[$id] = PluginFormcreatorFields::getFieldInstance( $question->fields['fieldtype'], $question From 5c6607c1e7b6d06501927b384cd732b99ea7b5c7 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 30 Oct 2018 20:49:41 +0100 Subject: [PATCH 147/192] fix(form): duplicate may fail if a question condition contains a single quote in show_value Signed-off-by: btry --- inc/form.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/form.class.php b/inc/form.class.php index 17b7026bc..85c5741f6 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1372,6 +1372,7 @@ public function duplicate() { $row['uuid']); $row['show_field'] = $tab_questions[$row['show_field']]; $row['plugin_formcreator_questions_id'] = $tab_questions[$row['plugin_formcreator_questions_id']]; + $row['show_value'] = Toolbox::addslashes_deep($row['show_value']); if (!$question_condition->add($row)) { return false; } From 1251ea1f0d4cc694b34f1e5d39c6e3b0a36309a5 Mon Sep 17 00:00:00 2001 From: btry Date: Tue, 30 Oct 2018 21:13:15 +0100 Subject: [PATCH 148/192] fix(form): duplicate may fail when the form has a single quote in its name Signed-off-by: btry --- inc/form.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/inc/form.class.php b/inc/form.class.php index 85c5741f6..977d687cd 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1290,8 +1290,9 @@ public function duplicate() { unset($form_datas['id'], $form_datas['uuid']); - $old_form_id = $this->getID(); - $new_form_id = $this->add($form_datas); + $old_form_id = $this->getID(); + $form_datas = Toolbox::addslashes_deep($form_datas); + $new_form_id = $this->add($form_datas); if ($new_form_id === false) { return false; } From ff5cfb039f7df88d2e1dde2ec39158df0dd915e2 Mon Sep 17 00:00:00 2001 From: btry Date: Fri, 2 Nov 2018 08:37:55 +0100 Subject: [PATCH 149/192] refactor(formlist): remove unused global Signed-off-by: btry --- inc/formlist.class.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/inc/formlist.class.php b/inc/formlist.class.php index 4147f6fbb..05756a795 100644 --- a/inc/formlist.class.php +++ b/inc/formlist.class.php @@ -49,8 +49,6 @@ public static function getTypeName($nb = 0) { } static function getMenuContent() { - global $CFG_GLPI; - $menu = parent::getMenuContent(); $image = ' Date: Fri, 2 Nov 2018 09:06:54 +0100 Subject: [PATCH 150/192] Revert "refactor(formlist): remove unused global" This reverts commit ff5cfb039f7df88d2e1dde2ec39158df0dd915e2. --- inc/formlist.class.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/inc/formlist.class.php b/inc/formlist.class.php index 05756a795..4147f6fbb 100644 --- a/inc/formlist.class.php +++ b/inc/formlist.class.php @@ -49,6 +49,8 @@ public static function getTypeName($nb = 0) { } static function getMenuContent() { + global $CFG_GLPI; + $menu = parent::getMenuContent(); $image = ' Date: Fri, 2 Nov 2018 11:32:36 +0100 Subject: [PATCH 151/192] fix(targetchange): rendering with rich text Signed-off-by: btry --- inc/form_answer.class.php | 14 ++++++++++---- inc/targetchange.class.php | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index cab99b753..3d6dc9790 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -1061,14 +1061,16 @@ public function getForm() { * * @return String Full form questions and answers to be print */ - public function getFullForm() { + public function getFullForm($disableRichText = false) { global $CFG_GLPI, $DB; $question_no = 0; $output = ''; $eol = '\r\n'; - if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { + if ($disableRichText === false + && (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text'])) + { $output .= '

' . __('Form data', 'formcreator') . '

'; } else { $output .= __('Form data', 'formcreator') . $eol; @@ -1109,7 +1111,9 @@ public function getFullForm() { // Get and display current section if needed if ($last_section != $question_line['section_name']) { - if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { + if ($disableRichText === false + && (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text'])) + { $output .= '

' . Toolbox::addslashes_deep($question_line['section_name']) . '

'; } else { $output .= $eol . Toolbox::addslashes_deep($question_line['section_name']) . $eol; @@ -1130,7 +1134,9 @@ public function getFullForm() { if ($question_line['fieldtype'] != 'description') { $question_no++; - if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { + if ($disableRichText === false + && (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text'])) + { $output .= '
'; $output .= '' . $question_no . ') ##question_' . $question_line['id'] . '## : '; $output .= '##answer_' . $question_line['id'] . '##'; diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index b84ceeb3b..53d2c13cf 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -987,12 +987,13 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { } if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { // replace HTML P tags with DIV tags - $data[$changeField] = str_replace(['

', '

'], ['
', '
'], $data[$changeField]); + $data[$changeField] = str_replace('\r\n', "\r\n", $data[$changeField]); } $data[$changeField] = $this->parseTags($data[$changeField], $formanswer); // This target does not supports rich text + $data[$changeField] = str_replace('
', '\r\n', $data[$changeField]); $data[$changeField] = strip_tags($data[$changeField], '

'); $data[$changeField] = str_replace('

', '', $data[$changeField]); $data[$changeField] = str_replace('

', '\r\n', $data[$changeField]); From 90fcf8c5c31da51220df4faff61da11fec4072d1 Mon Sep 17 00:00:00 2001 From: btry Date: Fri, 2 Nov 2018 12:01:46 +0100 Subject: [PATCH 152/192] fix(textarea): rendering without rich text mode Signed-off-by: btry --- inc/form_answer.class.php | 2 +- inc/targetchange.class.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index 3d6dc9790..735c6b778 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -1066,7 +1066,7 @@ public function getFullForm($disableRichText = false) { $question_no = 0; $output = ''; - $eol = '\r\n'; + $eol = "\r\n"; if ($disableRichText === false && (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text'])) diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index 53d2c13cf..d3a815a58 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -983,7 +983,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { $data[$changeField] = $this->fields[$changeField]; $data[$changeField] = str_replace("\r\n", '\r\n', $data[$changeField]); if (strpos($data[$changeField], '##FULLFORM##') !== false) { - $data[$changeField] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data[$changeField]); + $data[$changeField] = str_replace('##FULLFORM##', $formanswer->getFullForm(true), $data[$changeField]); } if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { // replace HTML P tags with DIV tags From e199085365394b971c5db15965dd3561c24e832d Mon Sep 17 00:00:00 2001 From: btry Date: Fri, 2 Nov 2018 15:55:30 +0100 Subject: [PATCH 153/192] fix(targetchange): entity from a question Signed-off-by: btry --- inc/targetchange.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index d3a815a58..c547dcbf9 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -1070,7 +1070,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { // Default entity of a user from the answer of a user's type question case 'user' : - $found = $answer->find('plugin_formcreator_formanwers_id = '.$formanswer->fields['id']. + $found = $answer->find('plugin_formcreator_forms_answers_id = '.$formanswer->fields['id']. ' AND plugin_formcreator_questions_id = '.$this->fields['destination_entity_value']); $user = array_shift($found); $user_id = $user['answer']; @@ -1086,7 +1086,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { // Entity from the answer of an entity's type question case 'entity' : - $found = $answer->find('plugin_formcreator_formanwers_id = '.$formanswer->fields['id']. + $found = $answer->find('plugin_formcreator_forms_answers_id = '.$formanswer->fields['id']. ' AND plugin_formcreator_questions_id = '.$this->fields['destination_entity_value']); $entity = array_shift($found); @@ -1123,7 +1123,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { $query = "SELECT answer FROM `glpi_plugin_formcreator_answers` - WHERE `plugin_formcreator_formanwers_id` = " . (int) $formanswer->fields['id'] . " + WHERE `plugin_formcreator_forms_answers_id` = " . (int) $formanswer->fields['id'] . " AND `plugin_formcreator_questions_id` IN (" . $this->fields['tag_questions'] . ")"; $result = $DB->query($query); while ($line = $DB->fetch_array($result)) { From 89fedc725ebda8aeb62d5921d7c7af669869e57e Mon Sep 17 00:00:00 2001 From: btry Date: Sat, 3 Nov 2018 20:49:32 +0100 Subject: [PATCH 154/192] style: fix code formatting Signed-off-by: btry --- inc/form_answer.class.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index 735c6b778..7372270d5 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -1069,8 +1069,7 @@ public function getFullForm($disableRichText = false) { $eol = "\r\n"; if ($disableRichText === false - && (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text'])) - { + && (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text'])) { $output .= '

' . __('Form data', 'formcreator') . '

'; } else { $output .= __('Form data', 'formcreator') . $eol; @@ -1112,8 +1111,7 @@ public function getFullForm($disableRichText = false) { // Get and display current section if needed if ($last_section != $question_line['section_name']) { if ($disableRichText === false - && (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text'])) - { + && (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text'])) { $output .= '

' . Toolbox::addslashes_deep($question_line['section_name']) . '

'; } else { $output .= $eol . Toolbox::addslashes_deep($question_line['section_name']) . $eol; @@ -1135,8 +1133,7 @@ public function getFullForm($disableRichText = false) { if ($question_line['fieldtype'] != 'description') { $question_no++; if ($disableRichText === false - && (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text'])) - { + && (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text'])) { $output .= '
'; $output .= '' . $question_no . ') ##question_' . $question_line['id'] . '## : '; $output .= '##answer_' . $question_line['id'] . '##'; From cb2d9c1bbf6fd7a82bd6ba35638b1f054f2997e1 Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Tue, 30 Oct 2018 09:18:07 +0100 Subject: [PATCH 155/192] feat(core): add search option to get assign group / tech to ticket --- hook.php | 18 ++++++++++++++++++ inc/issue.class.php | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/hook.php b/hook.php index b7e7647a5..72021a3bb 100644 --- a/hook.php +++ b/hook.php @@ -151,6 +151,24 @@ function plugin_formcreator_addLeftJoin($itemtype, $ref_table, $new_table, $link } $join = " LEFT JOIN `$new_table` AS `$AS` ON (`$ref_table`.`tickets_id` = `$AS`.`tickets_id`) "; } + + if ($new_table == 'glpi_groups') { + foreach ($already_link_tables as $table) { + if (strpos($table, $new_table) === 0) { + $AS = $table; + } + } + $join = " LEFT JOIN `$new_table` AS `$AS` ON (`glpi_groups_tickets_original_id`.`groups_id` = `$AS`.`id`) "; + } + + if ($new_table == 'glpi_users' && $linkfield == 'users_id') { + foreach ($already_link_tables as $table) { + if (strpos($table, $new_table) === 0) { + $AS = $table; + } + } + $join = " LEFT JOIN `$new_table` AS `$AS` ON (`glpi_tickets_users_original_id`.`users_id` = `$AS`.`id`) "; + } break; } diff --git a/inc/issue.class.php b/inc/issue.class.php index 4d6a185d7..8005c91fb 100644 --- a/inc/issue.class.php +++ b/inc/issue.class.php @@ -426,6 +426,46 @@ public function rawSearchOptions() { ] ]; + $tab[] = [ + 'id' => '14', + 'table' => User::getTable(), + 'field' => 'name', + 'linkfield' => 'users_id', + 'name' => __('Technician'), + 'datatype' => 'dropdown', + 'forcegroupby' => false, + 'massiveaction' => false, + 'joinparams' => [ + 'beforejoin' => [ + 'table' => Ticket_User::getTable(), + 'linkfield' => 'original_id', + 'joinparams' => [ + 'jointype' => 'empty', + ] + ] + ] + ]; + + $tab[] = [ + 'id' => '15', + 'table' => Group::getTable(), + 'field' => 'name', + 'linkfield' => 'groups_id', + 'name' => __('Technician group'), + 'datatype' => 'dropdown', + 'forcegroupby' => false, + 'massiveaction' => false, + 'joinparams' => [ + 'beforejoin' => [ + 'table' => Group_Ticket::getTable(), + 'linkfield' => 'original_id', + 'joinparams' => [ + 'jointype' => 'empty', + ] + ] + ] + ]; + return $tab; } From 0643acc2b2e4706d1d7e79fb520ee42fd0f5fc6e Mon Sep 17 00:00:00 2001 From: btry Date: Fri, 2 Nov 2018 16:46:34 +0100 Subject: [PATCH 156/192] refactor(target): factorize entity of target computation Signed-off-by: Thierry Bugier --- inc/fields/actorfield.class.php | 5 + inc/target.class.php | 5 + inc/targetbase.class.php | 91 ++++++++ inc/targetchange.class.php | 109 ++-------- inc/targetticket.class.php | 108 ++-------- tests/src/CommonTestCase.php | 38 ++++ .../PluginFormcreatorTargetChangeDummy.php | 45 ++++ .../PluginFormcreatorTargetTicketDummy.php | 45 ++++ .../PluginFormcreatorActorField.php | 2 +- .../PluginFormcreatorTargetChange.php | 202 ++++++++++++++++++ .../PluginFormcreatorTargetTicket.php | 167 ++++++++++++++- 11 files changed, 630 insertions(+), 187 deletions(-) create mode 100644 tests/src/PluginFormcreatorTargetChangeDummy.php create mode 100644 tests/src/PluginFormcreatorTargetTicketDummy.php create mode 100644 tests/suite-unit/PluginFormcreatorTargetChange.php diff --git a/inc/fields/actorfield.class.php b/inc/fields/actorfield.class.php index 2cffb34f8..1ebc28689 100644 --- a/inc/fields/actorfield.class.php +++ b/inc/fields/actorfield.class.php @@ -248,6 +248,11 @@ public function prepareQuestionInputForSave($input) { public function parseAnswerValues($input) { $key = 'formcreator_field_' . $this->fields['id']; + if (!isset($input[$key])) { + $this->value = []; + return true; + } + if (!is_array($input[$key])) { return false; } diff --git a/inc/target.class.php b/inc/target.class.php index 01cf4ce8e..9113b1e43 100644 --- a/inc/target.class.php +++ b/inc/target.class.php @@ -142,6 +142,7 @@ public function prepareInputForAdd($input) { return []; } // - field type is required + // TODO: remove this if() and use the default case of the switch structure if (isset($input['itemtype'])) { if (empty($input['itemtype'])) { Session::addMessageAfterRedirect(__('The type cannot be empty!', 'formcreator'), false, ERROR); @@ -201,6 +202,10 @@ public function prepareInputForAdd($input) { ]); } break; + + default: + Session::addMessageAfterRedirect(__('Bad type of target', 'formcreator'), false, ERROR); + return []; } } diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index db8fe92da..354705b81 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -202,6 +202,97 @@ public function getForm() { return null; } + /** + * Undocumented function + * + * @param PluginFormcreatorForm_Answer $formanswer + * @param integer $requesters_id ID of the requester of the answers + * @return integer ID of the entity where the target must be generated + */ + protected function getTargetEntity(PluginFormcreatorForm_Answer $formanswer, $requesters_id) { + global $DB; + + $entityId = 0; + switch ($this->fields['destination_entity']) { + // Requester's entity + case 'current' : + $entityId = $formanswer->fields[Entity::getForeignKeyField()]; + break; + + case 'requester' : + $userObj = new User(); + $userObj->getFromDB($requesters_id); + $entityId = $userObj->fields[Entity::getForeignKeyField()]; + break; + + // Requester's first dynamic entity + case 'requester_dynamic_first' : + $order_entities = "`glpi_profiles`.`name` ASC"; + case 'requester_dynamic_last' : + if (!isset($order_entities)) { + $order_entities = "`glpi_profiles`.`name` DESC"; + } + $query_entities = "SELECT `glpi_profiles_users`.`entities_id` + FROM `glpi_profiles_users` + LEFT JOIN `glpi_profiles` + ON `glpi_profiles`.`id` = `glpi_profiles_users`.`profiles_id` + WHERE `glpi_profiles_users`.`users_id` = $requesters_id + ORDER BY `glpi_profiles_users`.`is_dynamic` DESC, $order_entities"; + $res_entities = $DB->query($query_entities); + $data_entities = []; + while ($entity = $DB->fetch_array($res_entities)) { + $data_entities[] = $entity; + } + $first_entity = array_shift($data_entities); + $entityId = $first_entity[Entity::getForeignKeyField()]; + break; + + // Specific entity + case 'specific' : + $entityId = $this->fields['destination_entity_value']; + break; + + // The form entity + case 'form' : + $entityId = $formanswer->getForm()->fields[Entity::getForeignKeyField()]; + break; + + // The validator entity + case 'validator' : + $userObj = new User(); + $userObj->getFromDB($formanswer->fields['users_id_validator']); + $entityId = $userObj->fields[Entity::getForeignKeyField()]; + break; + + // Default entity of a user from the answer of a user's type question + case 'user' : + $answer = new PluginFormcreatorAnswer(); + $found = $answer->find('plugin_formcreator_forms_answers_id = '.$formanswer->fields['id']. + ' AND plugin_formcreator_questions_id = '.$this->fields['destination_entity_value']); + $user = array_shift($found); + $user_id = $user['answer']; + + if ($user_id > 0) { + $userObj = new User(); + $userObj->getFromDB($user_id); + $entityId = $userObj->fields[Entity::getForeignKeyField()]; + } + break; + + // Entity from the answer of an entity's type question + case 'entity' : + $answer = new PluginFormcreatorAnswer(); + $found = $answer->find('plugin_formcreator_forms_answers_id = '.$formanswer->fields['id']. + ' AND plugin_formcreator_questions_id = '.$this->fields['destination_entity_value']); + $entity = array_shift($found); + + $entityId = $entity['answer']; + break; + } + + return $entityId; + } + /** * find all actors and prepare data for the ticket being created */ diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index c547dcbf9..74e18c2a8 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -892,20 +892,23 @@ public function prepareInputForUpdate($input) { } } - $target = new PluginFormcreatorTarget(); - $target->getFromDBByCrit([ - 'itemtype' => self::class, - 'items_id' => $this->getID() - ]); - if (!$target->isNewItem()) { - $target->update([ - 'id' => $target->getID(), - 'name' => $input['name'], + if (isset($input['name'])) { + $target = new PluginFormcreatorTarget(); + $target->getFromDBByCrit([ + 'itemtype' => self::class, + 'items_id' => $this->getID() ]); + if (!$target->isNewItem()) { + $target->update([ + 'id' => $target->getID(), + 'name' => $input['name'], + ]); + } + } + if (isset($input['title'])) { + $input['name'] = $input['title']; + unset($input['title']); } - $input['name'] = $input['title']; - unset($input['title']); - return $input; } @@ -1017,87 +1020,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { } // Computation of the entity - switch ($this->fields['destination_entity']) { - // Requester's entity - case 'current' : - $data['entities_id'] = $_SESSION['glpiactive_entity']; - break; - - case 'requester' : - $userObj = new User(); - $userObj->getFromDB($requesters_id); - $data['entities_id'] = $userObj->fields['entities_id']; - break; - - // Requester's first dynamic entity - case 'requester_dynamic_first' : - $order_entities = "`glpi_profiles`.`name` ASC"; - case 'requester_dynamic_last' : - if (!isset($order_entities)) { - $order_entities = "`glpi_profiles`.`name` DESC"; - } - $query_entities = "SELECT `glpi_profiles_users`.`entities_id` - FROM `glpi_profiles_users` - LEFT JOIN `glpi_profiles` - ON `glpi_profiles`.`id` = `glpi_profiles_users`.`profiles_id` - WHERE `glpi_profiles_users`.`users_id` = $requesters_id - ORDER BY `glpi_profiles_users`.`is_dynamic` DESC, $order_entities"; - $res_entities = $DB->query($query_entities); - $data_entities = []; - while ($entity = $DB->fetch_array($res_entities)) { - $data_entities[] = $entity; - } - $first_entity = array_shift($data_entities); - $data['entities_id'] = $first_entity['entities_id']; - break; - - // Specific entity - case 'specific' : - $data['entities_id'] = $this->fields['destination_entity_value']; - break; - - // The form entity - case 'form' : - $data['entities_id'] = $form->fields['entities_id']; - break; - - // The validator entity - case 'validator' : - $userObj = new User(); - $userObj->getFromDB($formanswer->fields['users_id_validator']); - $data['entities_id'] = $userObj->fields['entities_id']; - break; - - // Default entity of a user from the answer of a user's type question - case 'user' : - $found = $answer->find('plugin_formcreator_forms_answers_id = '.$formanswer->fields['id']. - ' AND plugin_formcreator_questions_id = '.$this->fields['destination_entity_value']); - $user = array_shift($found); - $user_id = $user['answer']; - - if ($user_id > 0) { - $userObj = new User(); - $userObj->getFromDB($user_id); - $data['entities_id'] = $userObj->fields['entities_id']; - } else { - $data['entities_id'] = 0; - } - break; - - // Entity from the answer of an entity's type question - case 'entity' : - $found = $answer->find('plugin_formcreator_forms_answers_id = '.$formanswer->fields['id']. - ' AND plugin_formcreator_questions_id = '.$this->fields['destination_entity_value']); - $entity = array_shift($found); - - $data['entities_id'] = (int) $entity['answer']; - break; - - // Requester current entity - default : - $data['entities_id'] = 0; - break; - } + $data['entities_id'] = $this->getTargetEntity($formanswer, $requesters_id); $data = $this->setTargetDueDate($data, $formanswer); diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index 833f1390f..9e0ad0eed 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -923,19 +923,23 @@ public function prepareInputForUpdate($input) { $input['uuid'] = plugin_formcreator_getUuid(); } - $target = new PluginFormcreatorTarget(); - $target->getFromDBByCrit([ - 'itemtype' => self::class, - 'items_id' => $this->getID() - ]); - if (!$target->isNewItem()) { - $target->update([ - 'id' => $target->getID(), - 'name' => $input['name'], + if (isset($input['name'])) { + $target = new PluginFormcreatorTarget(); + $target->getFromDBByCrit([ + 'itemtype' => self::class, + 'items_id' => $this->getID() ]); + if (!$target->isNewItem()) { + $target->update([ + 'id' => $target->getID(), + 'name' => $input['name'], + ]); + } + } + if (isset($input['title'])) { + $input['name'] = $input['title']; + unset($input['title']); } - $input['name'] = $input['title']; - unset($input['title']); return $input; } @@ -1155,87 +1159,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { } // Computation of the entity - switch ($this->fields['destination_entity']) { - // Requester's entity - case 'current' : - $data['entities_id'] = $formanswer->getField('entities_id'); - break; - - case 'requester' : - $userObj = new User(); - $userObj->getFromDB($requesters_id); - $data['entities_id'] = $userObj->fields['entities_id']; - break; - - // Requester's first dynamic entity - case 'requester_dynamic_first' : - $order_entities = "`glpi_profiles`.`name` ASC"; - case 'requester_dynamic_last' : - if (!isset($order_entities)) { - $order_entities = "`glpi_profiles`.`name` DESC"; - } - $query_entities = "SELECT `glpi_profiles_users`.`entities_id` - FROM `glpi_profiles_users` - LEFT JOIN `glpi_profiles` - ON `glpi_profiles`.`id` = `glpi_profiles_users`.`profiles_id` - WHERE `glpi_profiles_users`.`users_id` = $requesters_id - ORDER BY `glpi_profiles_users`.`is_dynamic` DESC, $order_entities"; - $res_entities = $DB->query($query_entities); - $data_entities = []; - while ($entity = $DB->fetch_array($res_entities)) { - $data_entities[] = $entity; - } - $first_entity = array_shift($data_entities); - $data['entities_id'] = $first_entity['entities_id']; - break; - - // Specific entity - case 'specific' : - $data['entities_id'] = $this->fields['destination_entity_value']; - break; - - // The form entity - case 'form' : - $data['entities_id'] = $form->fields['entities_id']; - break; - - // The validator entity - case 'validator' : - $userObj = new User(); - $userObj->getFromDB($formanswer->fields['users_id_validator']); - $data['entities_id'] = $userObj->fields['entities_id']; - break; - - // Default entity of a user from the answer of a user's type question - case 'user' : - $found = $answer->find('plugin_formcreator_forms_answers_id = '.$formanswer->fields['id']. - ' AND plugin_formcreator_questions_id = '.$this->fields['destination_entity_value']); - $user = array_shift($found); - $user_id = $user['answer']; - - if ($user_id > 0) { - $userObj = new User(); - $userObj->getFromDB($user_id); - $data['entities_id'] = $userObj->fields['entities_id']; - } else { - $data['entities_id'] = 0; - } - break; - - // Entity from the answer of an entity's type question - case 'entity' : - $found = $answer->find('plugin_formcreator_forms_answers_id = '.$formanswer->fields['id']. - ' AND plugin_formcreator_questions_id = '.$this->fields['destination_entity_value']); - $entity = array_shift($found); - - $data['entities_id'] = $entity['answer']; - break; - - // Requester current entity - default : - $data['entities_id'] = 0; - break; - } + $data['entities_id'] = $this->getTargetEntity($formanswer, $requesters_id); $data = $this->setTargetDueDate($data, $formanswer); $data = $this->setTargetUrgency($data, $formanswer); diff --git a/tests/src/CommonTestCase.php b/tests/src/CommonTestCase.php index c14803bc4..701c27f88 100644 --- a/tests/src/CommonTestCase.php +++ b/tests/src/CommonTestCase.php @@ -218,6 +218,44 @@ protected function getQuestion($input = []) { return $question; } + protected function getTargetTicket($input = []) { + if (!isset($input['name'])) { + $input['name'] = $this->getUniqueString(); + } + + $formFk = \PluginFormcreatorForm::getForeignKeyField(); + if (!isset($input[$formFk])) { + $input[$formFk] = $this->getForm(); + } + + $input['itemtype'] = \PluginFormcreatorTargetTicket::class; + $target = new \PluginFormcreatorTarget(); + $target->add($input); + $targetTicket = new \PluginFormcreatorTargetTicket(); + $targetTicket->getFromDB($target->fields['items_id']); + + return $targetTicket; + } + + protected function getTargetChange($input = []) { + if (!isset($input['name'])) { + $input['name'] = $this->getUniqueString(); + } + + $formFk = \PluginFormcreatorForm::getForeignKeyField(); + if (!isset($inoput[$formFk])) { + $inoput[$formFk] = $this->getForm(); + } + + $input['itemtype'] = \PluginFormcreatorTargetChange::class; + $target = new \PluginFormcreatorTarget(); + $target->add($input); + $targetChange = new \PluginFormcreatorTargetChange(); + $targetChange->getFromDB($target->fields['items_id']); + + return $targetChange; + } + protected function _checkForm($form = []) { $this->assertArrayNotHasKey('id', $export); $this->assertArrayNotHasKey('plugin_formcreator_categories_id', $export); diff --git a/tests/src/PluginFormcreatorTargetChangeDummy.php b/tests/src/PluginFormcreatorTargetChangeDummy.php new file mode 100644 index 000000000..2a931e841 --- /dev/null +++ b/tests/src/PluginFormcreatorTargetChangeDummy.php @@ -0,0 +1,45 @@ +. + * --------------------------------------------------------------------- + * @author Thierry Bugier + * @author Jérémy Moreau + * @copyright Copyright © 2011 - 2018 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + +namespace GlpiPlugin\Formcreator\Tests; + +class PluginFormcreatorTargetChangeDummy extends \PluginFormcreatorTargetChange +{ + public static function getTable($classname = null) { + return \PluginFormcreatorTargetChange::getTable(); + } + + public function publicGetTargetEntity(\PluginFormcreatorForm_Answer $formanswer, $requesters_id) { + return $this->getTargetEntity($formanswer, $requesters_id); + } +} diff --git a/tests/src/PluginFormcreatorTargetTicketDummy.php b/tests/src/PluginFormcreatorTargetTicketDummy.php new file mode 100644 index 000000000..56620c66e --- /dev/null +++ b/tests/src/PluginFormcreatorTargetTicketDummy.php @@ -0,0 +1,45 @@ +. + * --------------------------------------------------------------------- + * @author Thierry Bugier + * @author Jérémy Moreau + * @copyright Copyright © 2011 - 2018 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + +namespace GlpiPlugin\Formcreator\Tests; + +class PluginFormcreatorTargetTicketDummy extends \PluginFormcreatorTargetTicket +{ + public static function getTable($classname = null) { + return \PluginFormcreatorTargetTicket::getTable(); + } + + public function publicGetTargetEntity(\PluginFormcreatorForm_Answer $formanswer, $requesters_id) { + return $this->getTargetEntity($formanswer, $requesters_id); + } +} diff --git a/tests/suite-unit/PluginFormcreatorActorField.php b/tests/suite-unit/PluginFormcreatorActorField.php index 4fd30dd10..710afeaab 100644 --- a/tests/suite-unit/PluginFormcreatorActorField.php +++ b/tests/suite-unit/PluginFormcreatorActorField.php @@ -124,7 +124,7 @@ public function providerSerializeValue() { return [ [ 'value' => null, - 'expected' => '', + 'expected' => json_encode([]), ], [ 'value' => [], diff --git a/tests/suite-unit/PluginFormcreatorTargetChange.php b/tests/suite-unit/PluginFormcreatorTargetChange.php new file mode 100644 index 000000000..6b930f166 --- /dev/null +++ b/tests/suite-unit/PluginFormcreatorTargetChange.php @@ -0,0 +1,202 @@ +. + * --------------------------------------------------------------------- + * + * @copyright Copyright © 2011 - 2018 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + +namespace tests\units; +use GlpiPlugin\Formcreator\Tests\CommonTestCase; +use GlpiPlugin\Formcreator\Tests\PluginFormcreatorTargetChangeDummy; + +class PluginFormcreatorTargetChange extends CommonTestCase { + + public function beforeTestMethod($method) { + parent::beforeTestMethod($method); + switch ($method) { + case 'testGetTargetEntity': + $this->boolean($this->login('glpi', 'glpi'))->isTrue(); + break; + } + } + + /** + * @engine inline + * + * @return void + */ + public function testGetTargetEntity() { + $form = $this->getForm(); + $formFk = \PluginFormcreatorForm::getForeignKeyField(); + $targetChange = $this->getTargetChange([ + $formFk => $form->getID(), + ]); + + // Use a dummy class to access protected methods + $instance = new PluginFormcreatorTargetChangeDummy(); + $instance->getFromDB($targetChange->getID()); + + // Test current entity of the requester + $entity = new \Entity(); + $entityId = $entity->import([ + 'entities_id' => '0', + 'name' => $this->getUniqueString() + ]); + $targetChange->update([ + 'id' => $targetChange->getID(), + '_skip_checks' => true, + 'destination_entity' => 'current', + 'destination_entity_value' => '0', + ]); + $instance->getFromDB($targetChange->getID()); + $formAnswer = new \PluginFormcreatorForm_Answer(); + $formAnswer->add([ + 'plugin_formcreator_forms_id' => $form->getID(), + 'entities_id' => $entityId, + ]); + $formAnswer->getFromDB($formAnswer->getID()); + $requesterId = \Session::getLoginUserID(); + $output = $instance->publicGetTargetEntity($formAnswer, $requesterId); + $this->integer((int) $output)->isEqualTo($entityId); + + // Test requester's entity + $targetChange->update([ + 'id' => $targetChange->getID(), + '_skip_checks' => true, + 'destination_entity' => 'requester', + 'destination_entity_value' => '0', + ]); + $instance->getFromDB($targetChange->getID()); + $formAnswer->add([ + 'plugin_formcreator_forms_id' => $form->getID(), + 'entities_id' => $entityId, + ]); + \Session::changeActiveEntities($entityId); + $requesterId = \Session::getLoginUserID(); + $output = $instance->publicGetTargetEntity($formAnswer, $requesterId); + $this->integer((int) $output)->isEqualTo(0); + + // Test requester's first entity (alphanumeric order) + $targetChange->update([ + 'id' => $targetChange->getID(), + '_skip_checks' => true, + 'destination_entity' => 'requester_dynamic_first', + 'destination_entity_value' => '0', + ]); + $instance->getFromDB($targetChange->getID()); + $entityId = $entity->import([ + 'entities_id' => '0', + 'name' => $this->getUniqueString(), + ]); + $user = new \User(); + $user->add([ + 'name' => $this->getUniqueString(), + 'password' => 'passwd', + 'password2' => 'passwd', + '_profiles_id' => '3', // Admin + '_entities_id' => $entityId, + ]); + $entity = new \Entity(); + $profileUser = new \Profile_User(); + $profileUser->add([ + \User::getForeignKeyField() => $user->getID(), + \Profile::getForeignKeyField() => 4, // Super admin + \Entity::getForeignKeyField() => 0, + ]); + $formAnswer->add([ + 'plugin_formcreator_forms_id' => $form->getID(), + 'entities_id' => 0, + ]); + $this->boolean($this->login($user->fields['name'], 'passwd'))->isTrue(); + $requesterId = \Session::getLoginUserID(); + $output = $instance->publicGetTargetEntity($formAnswer, $requesterId); + $this->integer((int) $output)->isEqualTo($entityId); + + // Test requester's last entity (alphanumeric order) + $targetChange->update([ + 'id' => $targetChange->getID(), + '_skip_checks' => true, + 'destination_entity' => 'requester_dynamic_last', + 'destination_entity_value' => '0', + ]); + $instance->getFromDB($targetChange->getID()); + $formAnswer->add([ + 'plugin_formcreator_forms_id' => $form->getID(), + 'entities_id' => $entityId, + ]); + $this->boolean($this->login($user->fields['name'], 'passwd'))->isTrue(); + $requesterId = \Session::getLoginUserID(); + $output = $instance->publicGetTargetEntity($formAnswer, $requesterId); + $this->integer((int) $output)->isEqualTo(0); + + // Test specific entity + $this->boolean($this->login('glpi', 'glpi'))->isTrue(); + $entityId = $entity->import([ + 'entities_id' => '0', + 'name' => $this->getUniqueString(), + ]); + $targetChange->update([ + 'id' => $targetChange->getID(), + '_skip_checks' => true, + 'destination_entity' => 'specific', + 'destination_entity_value' => "$entityId", + ]); + $instance->getFromDB($targetChange->getID()); + $formAnswer->add([ + 'plugin_formcreator_forms_id' => $form->getID(), + 'entities_id' => 0, + ]); + $requesterId = \Session::getLoginUserID(); + $output = $instance->publicGetTargetEntity($formAnswer, $requesterId); + $this->integer((int) $output)->isEqualTo($entityId); + + // Test form's entity + $entityId = $entity->import([ + 'entities_id' => '0', + 'name' => $this->getUniqueString(), + ]); + $targetChange->update([ + 'id' => $targetChange->getID(), + '_skip_checks' => true, + 'destination_entity' => 'form', + 'destination_entity_value' => '0', + ]); + $form->update([ + 'id' => $form->getID(), + 'entities_id' => $entityId, + ]); + $instance->getFromDB($targetChange->getID()); + $formAnswer->add([ + 'plugin_formcreator_forms_id' => $form->getID(), + 'entities_id' => 0, + ]); + $requesterId = \Session::getLoginUserID(); + $output = $instance->publicGetTargetEntity($formAnswer, $requesterId); + $this->integer((int) $output)->isEqualTo($entityId); + } +} diff --git a/tests/suite-unit/PluginFormcreatorTargetTicket.php b/tests/suite-unit/PluginFormcreatorTargetTicket.php index b7bc47213..1499163fc 100644 --- a/tests/suite-unit/PluginFormcreatorTargetTicket.php +++ b/tests/suite-unit/PluginFormcreatorTargetTicket.php @@ -32,9 +32,19 @@ namespace tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; +use GlpiPlugin\Formcreator\Tests\PluginFormcreatorTargetTicketDummy; class PluginFormcreatorTargetTicket extends CommonTestCase { + public function beforeTestMethod($method) { + parent::beforeTestMethod($method); + switch ($method) { + case 'testGetTargetEntity': + $this->boolean($this->login('glpi', 'glpi'))->isTrue(); + break; + } + } + /** * Tests that deleting a target ticket of a form also deletes relations between tickets and generated tickets * @@ -112,4 +122,159 @@ public function testDeleteLinkedTickets() { $this->boolean($item_targetticket_1->getFromDB($item_targetticket_1->getID()))->isFalse(); $this->boolean($item_targetticket_2->getFromDB($item_targetticket_2->getID()))->isFalse(); } -} \ No newline at end of file + + /** + * @engine inline + * + * @return void + */ + public function testGetTargetEntity() { + $form = $this->getForm(); + $formFk = \PluginFormcreatorForm::getForeignKeyField(); + $targetTicket = $this->getTargetTicket([ + $formFk => $form->getID(), + ]); + + // Use a dummy class to access protected methods + $instance = new PluginFormcreatorTargetTicketDummy(); + $instance->getFromDB($targetTicket->getID()); + + // Test current entity of the requester + $entity = new \Entity(); + $entityId = $entity->import([ + 'entities_id' => '0', + 'name' => $this->getUniqueString() + ]); + $targetTicket->update([ + 'id' => $targetTicket->getID(), + '_skip_checks' => true, + 'destination_entity' => 'current', + 'destination_entity_value' => '0', + ]); + $instance->getFromDB($targetTicket->getID()); + $formAnswer = new \PluginFormcreatorForm_Answer(); + $formAnswer->add([ + 'plugin_formcreator_forms_id' => $form->getID(), + 'entities_id' => $entityId, + ]); + $formAnswer->getFromDB($formAnswer->getID()); + $requesterId = \Session::getLoginUserID(); + $output = $instance->publicGetTargetEntity($formAnswer, $requesterId); + $this->integer((int) $output)->isEqualTo($entityId); + + // Test requester's entity + $targetTicket->update([ + 'id' => $targetTicket->getID(), + '_skip_checks' => true, + 'destination_entity' => 'requester', + 'destination_entity_value' => '0', + ]); + $instance->getFromDB($targetTicket->getID()); + $formAnswer->add([ + 'plugin_formcreator_forms_id' => $form->getID(), + 'entities_id' => $entityId, + ]); + \Session::changeActiveEntities($entityId); + $requesterId = \Session::getLoginUserID(); + $output = $instance->publicGetTargetEntity($formAnswer, $requesterId); + $this->integer((int) $output)->isEqualTo(0); + + // Test requester's first entity (alphanumeric order) + $targetTicket->update([ + 'id' => $targetTicket->getID(), + '_skip_checks' => true, + 'destination_entity' => 'requester_dynamic_first', + 'destination_entity_value' => '0', + ]); + $instance->getFromDB($targetTicket->getID()); + $entityId = $entity->import([ + 'entities_id' => '0', + 'name' => $this->getUniqueString(), + ]); + $user = new \User(); + $user->add([ + 'name' => $this->getUniqueString(), + 'password' => 'passwd', + 'password2' => 'passwd', + '_profiles_id' => '3', // Admin + '_entities_id' => $entityId, + ]); + $entity = new \Entity(); + $profileUser = new \Profile_User(); + $profileUser->add([ + \User::getForeignKeyField() => $user->getID(), + \Profile::getForeignKeyField() => 4, // Super admin + \Entity::getForeignKeyField() => 0, + ]); + $formAnswer->add([ + 'plugin_formcreator_forms_id' => $form->getID(), + 'entities_id' => 0, + ]); + $this->boolean($this->login($user->fields['name'], 'passwd'))->isTrue(); + $requesterId = \Session::getLoginUserID(); + $output = $instance->publicGetTargetEntity($formAnswer, $requesterId); + $this->integer((int) $output)->isEqualTo($entityId); + + // Test requester's last entity (alphanumeric order) + $targetTicket->update([ + 'id' => $targetTicket->getID(), + '_skip_checks' => true, + 'destination_entity' => 'requester_dynamic_last', + 'destination_entity_value' => '0', + ]); + $instance->getFromDB($targetTicket->getID()); + $formAnswer->add([ + 'plugin_formcreator_forms_id' => $form->getID(), + 'entities_id' => $entityId, + ]); + $this->boolean($this->login($user->fields['name'], 'passwd'))->isTrue(); + $requesterId = \Session::getLoginUserID(); + $output = $instance->publicGetTargetEntity($formAnswer, $requesterId); + $this->integer((int) $output)->isEqualTo(0); + + // Test specific entity + $this->boolean($this->login('glpi', 'glpi'))->isTrue(); + $entityId = $entity->import([ + 'entities_id' => '0', + 'name' => $this->getUniqueString(), + ]); + $targetTicket->update([ + 'id' => $targetTicket->getID(), + '_skip_checks' => true, + 'destination_entity' => 'specific', + 'destination_entity_value' => "$entityId", + ]); + $instance->getFromDB($targetTicket->getID()); + $formAnswer->add([ + 'plugin_formcreator_forms_id' => $form->getID(), + 'entities_id' => 0, + ]); + $requesterId = \Session::getLoginUserID(); + $output = $instance->publicGetTargetEntity($formAnswer, $requesterId); + $this->integer((int) $output)->isEqualTo($entityId); + + // Test form's entity + $entityId = $entity->import([ + 'entities_id' => '0', + 'name' => $this->getUniqueString(), + ]); + $targetTicket->update([ + 'id' => $targetTicket->getID(), + '_skip_checks' => true, + 'destination_entity' => 'form', + 'destination_entity_value' => '0', + ]); + $form->update([ + 'id' => $form->getID(), + 'entities_id' => $entityId, + ]); + $instance->getFromDB($targetTicket->getID()); + $formAnswer->add([ + 'plugin_formcreator_forms_id' => $form->getID(), + 'entities_id' => 0, + ]); + $requesterId = \Session::getLoginUserID(); + $output = $instance->publicGetTargetEntity($formAnswer, $requesterId); + $this->integer((int) $output)->isEqualTo($entityId); + } +} From 08236c7f94a3d8bb527bdc5e7bb11b25771c7b91 Mon Sep 17 00:00:00 2001 From: btry Date: Sat, 3 Nov 2018 16:36:09 +0100 Subject: [PATCH 157/192] fix(targetchange): changes don't support template Signed-off-by: Thierry Bugier --- install/mysql/plugin_formcreator_empty.sql | 4 +--- install/update_2.6_2.7.php | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/install/mysql/plugin_formcreator_empty.sql b/install/mysql/plugin_formcreator_empty.sql index d77084da5..a78747088 100644 --- a/install/mysql/plugin_formcreator_empty.sql +++ b/install/mysql/plugin_formcreator_empty.sql @@ -143,7 +143,6 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_sections` ( CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targetchanges` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL DEFAULT '', - `changetemplates_id` int(11) DEFAULT NULL, `content` longtext, `impactcontent` longtext, `controlistcontent` longtext, @@ -164,8 +163,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targetchanges` ( `tag_specifics` varchar(255) NOT NULL, `category_rule` enum('none','specific','answer') NOT NULL DEFAULT 'none', `category_question` int(11) NOT NULL DEFAULT '0', - PRIMARY KEY (`id`), - INDEX `changetemplates_id` (`changetemplates_id`) + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targetchanges_actors` ( diff --git a/install/update_2.6_2.7.php b/install/update_2.6_2.7.php index 47cac7168..6a5f3319d 100644 --- a/install/update_2.6_2.7.php +++ b/install/update_2.6_2.7.php @@ -32,6 +32,10 @@ function plugin_formcreator_update_2_7(Migration $migration) { global $DB; + // Changes don't support templates, remove the relation + $table = 'glpi_plugin_formcreator_targetchanges'; + $migration->dropField($table, 'changetemplates_id'); + // Migrate regex question parameters $table = 'glpi_plugin_formcreator_questions'; if ($DB->fieldExists($table, 'regex')) { From d79275d12bd5c5caae8396f1b4fffe624dd67fe0 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 6 Nov 2018 10:48:20 +0100 Subject: [PATCH 158/192] docs: bump version in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 73457a5a3..c734ca6b0 100644 --- a/package.json +++ b/package.json @@ -11,5 +11,5 @@ } }, "dependencies": [], - "version": "2.6.4" + "version": "2.6.5" } From 6ff4533e2b679261cd9d883885bb84eb448afcfa Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 6 Nov 2018 10:48:21 +0100 Subject: [PATCH 159/192] docs(changelog): update changelog --- CHANGELOG.md | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2fe1d32b..e80469cce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,66 @@ + +## [2.6.5](https://github.com-btry/pluginsglpi/formcreator/compare/2.6.3...2.6.5) (2018-11-06) + + +### Bug Fixes + +* **actorfield:** compatibility with GLPI 9.3 ([#1034](https://github.com-btry/pluginsglpi/formcreator/issues/1034)) ([3b2051f](https://github.com-btry/pluginsglpi/formcreator/commit/3b2051f)) +* **actors:** fix broken select tag ([82509e8](https://github.com-btry/pluginsglpi/formcreator/commit/82509e8)) +* **actors:** fix edit of an existing question of type actors ([f1606af](https://github.com-btry/pluginsglpi/formcreator/commit/f1606af)) +* **actors:** use first / last name in generataed tickets ([1455708](https://github.com-btry/pluginsglpi/formcreator/commit/1455708)), closes [#1016](https://github.com-btry/pluginsglpi/formcreator/issues/1016) +* **build:** check consistency of manifest XML file ([fb06543](https://github.com-btry/pluginsglpi/formcreator/commit/fb06543)) +* **checkboxedfield:** single quote rendering ([888b13f](https://github.com-btry/pluginsglpi/formcreator/commit/888b13f)) +* **date:** format dates for target generation ([10c70fc](https://github.com-btry/pluginsglpi/formcreator/commit/10c70fc)), closes [#1050](https://github.com-btry/pluginsglpi/formcreator/issues/1050) +* **description:** cannot apply hide/show condition on descriptions ([8693a6a](https://github.com-btry/pluginsglpi/formcreator/commit/8693a6a)) +* **filefield:** SQL single quote escaping ([e0b9bd6](https://github.com-btry/pluginsglpi/formcreator/commit/e0b9bd6)) +* **form:** access to form not properly checked ([#1047](https://github.com-btry/pluginsglpi/formcreator/issues/1047)) ([1a40790](https://github.com-btry/pluginsglpi/formcreator/commit/1a40790)) +* **form:** check access to form only by entity ([c0973cb](https://github.com-btry/pluginsglpi/formcreator/commit/c0973cb)) +* **form:** duplicate may fail ([a29f806](https://github.com-btry/pluginsglpi/formcreator/commit/a29f806)) +* **form:** duplicate may fail ([b9b2547](https://github.com-btry/pluginsglpi/formcreator/commit/b9b2547)) +* **form:** duplicate with quote ([ec6460f](https://github.com-btry/pluginsglpi/formcreator/commit/ec6460f)) +* **form:** forbid purge of a form when there are answers ([f84b353](https://github.com-btry/pluginsglpi/formcreator/commit/f84b353)) +* **form:** import restrictions by profile was broken ([34ae3bf](https://github.com-btry/pluginsglpi/formcreator/commit/34ae3bf)), closes [#722](https://github.com-btry/pluginsglpi/formcreator/issues/722) +* **form_answer:** allow view of form if the user has update entity right ([7dad4cb](https://github.com-btry/pluginsglpi/formcreator/commit/7dad4cb)) +* **form_answer:** fix compatibility with GLPI 9.4 ([001a82f](https://github.com-btry/pluginsglpi/formcreator/commit/001a82f)) +* **form_answer:** fix fatal error ([c292981](https://github.com-btry/pluginsglpi/formcreator/commit/c292981)) +* **form_profile:** UUID was not generated ([44f231b](https://github.com-btry/pluginsglpi/formcreator/commit/44f231b)) +* **glpiselect:** compatibility with GLPI 9.3 ([a9aea5a](https://github.com-btry/pluginsglpi/formcreator/commit/a9aea5a)) +* **install:** bad logic for upgrade steps ([c324e1c](https://github.com-btry/pluginsglpi/formcreator/commit/c324e1c)) +* **issue:** avoid truncate of comment ([8a98b0d](https://github.com-btry/pluginsglpi/formcreator/commit/8a98b0d)) +* **issue:** more consistent status display for status of issues ([2802a78](https://github.com-btry/pluginsglpi/formcreator/commit/2802a78)) +* **issue:** php warnings in service catalog ([0754b5f](https://github.com-btry/pluginsglpi/formcreator/commit/0754b5f)) +* **plugin:** update compatibility ([57c607f](https://github.com-btry/pluginsglpi/formcreator/commit/57c607f)) +* **question:** description displayed in italic ([e572b43](https://github.com-btry/pluginsglpi/formcreator/commit/e572b43)) +* **question:** fix loss of description ([4b39371](https://github.com-btry/pluginsglpi/formcreator/commit/4b39371)) +* **question_condition:** fix creation of conditions ([135d6c8](https://github.com-btry/pluginsglpi/formcreator/commit/135d6c8)) +* **target:** actors not inserted on tarrgets ([18b5662](https://github.com-btry/pluginsglpi/formcreator/commit/18b5662)) +* **target:** continue keyword in switch ([576c891](https://github.com-btry/pluginsglpi/formcreator/commit/576c891)) +* **target:** loading of instance from DB ([1d314de](https://github.com-btry/pluginsglpi/formcreator/commit/1d314de)) +* **target:** unescaped quote ([6afa05b](https://github.com-btry/pluginsglpi/formcreator/commit/6afa05b)) +* **targetbase:** fix double quote renderiing in targets ([40811d8](https://github.com-btry/pluginsglpi/formcreator/commit/40811d8)) +* **targetchange:** apply fix [#267](https://github.com-btry/pluginsglpi/formcreator/issues/267) to target changes ([3eafa29](https://github.com-btry/pluginsglpi/formcreator/commit/3eafa29)) +* **targetchange:** changes does not supports rich text ([8d7bad0](https://github.com-btry/pluginsglpi/formcreator/commit/8d7bad0)), closes [#1139](https://github.com-btry/pluginsglpi/formcreator/issues/1139) +* **targetchange:** duplication leaves default actors ([854191d](https://github.com-btry/pluginsglpi/formcreator/commit/854191d)) +* **targetchange:** entity from a question ([40cc7eb](https://github.com-btry/pluginsglpi/formcreator/commit/40cc7eb)) +* **targetchange:** fix creation if relation between change and form answer ([8259899](https://github.com-btry/pluginsglpi/formcreator/commit/8259899)) +* compatibility with GLPI 9.4 ([6dfaae9](https://github.com-btry/pluginsglpi/formcreator/commit/6dfaae9)), closes [#1022](https://github.com-btry/pluginsglpi/formcreator/issues/1022) +* **targetchange:** rendering with rich text ([e842b0f](https://github.com-btry/pluginsglpi/formcreator/commit/e842b0f)) +* **targetchange:** rich text does not exists for changes ([e39028b](https://github.com-btry/pluginsglpi/formcreator/commit/e39028b)) +* **targetchange:** time to resolve not populated when required ([b1240d6](https://github.com-btry/pluginsglpi/formcreator/commit/b1240d6)) +* fix plugin manifest xml file ([7608920](https://github.com-btry/pluginsglpi/formcreator/commit/7608920)) +* **targetchange:** title edition fails ([32eb4db](https://github.com-btry/pluginsglpi/formcreator/commit/32eb4db)) +* **targetticket:** fix HTML ([00f81fc](https://github.com-btry/pluginsglpi/formcreator/commit/00f81fc)) +* **textarea:** rendering without rich text mode ([b41a9b2](https://github.com-btry/pluginsglpi/formcreator/commit/b41a9b2)) +* **textareafield:** rendering for rich text ([8735189](https://github.com-btry/pluginsglpi/formcreator/commit/8735189)) +* **wizard:** warnings ([6a355f9](https://github.com-btry/pluginsglpi/formcreator/commit/6a355f9)), closes [#1076](https://github.com-btry/pluginsglpi/formcreator/issues/1076) + + +### Features + +* **core:** add search option to get assign group / tech to ticket ([5f1eb35](https://github.com-btry/pluginsglpi/formcreator/commit/5f1eb35)) + + + ## [2.6.4](https://github.com-btry/pluginsGLPI/formcreator/compare/2.6.3...2.6.4) (2018-08-13) From d577c11bf9b8c62456119b3ad22140fe48487450 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 6 Nov 2018 11:37:22 +0100 Subject: [PATCH 160/192] build: drop support for GLPI 9.2 Signed-off-by: Thierry Bugier --- setup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.php b/setup.php index 1b3b5f74a..d2b74c4d0 100644 --- a/setup.php +++ b/setup.php @@ -40,7 +40,7 @@ define('PLUGIN_FORMCREATOR_IS_OFFICIAL_RELEASE', false); // Minimal GLPI version, inclusive -define ('PLUGIN_FORMCREATOR_GLPI_MIN_VERSION', '9.2.1'); +define ('PLUGIN_FORMCREATOR_GLPI_MIN_VERSION', '9.3'); // Maximum GLPI version, exclusive define ('PLUGIN_FORMCREATOR_GLPI_MAX_VERSION', '9.4'); From f5ad7b82fbb911bef3d3ca99d37328f4b2964bf5 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Thu, 8 Nov 2018 14:40:22 +0100 Subject: [PATCH 161/192] style: single quotes and modern class name expression Signed-off-by: Thierry Bugier --- setup.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/setup.php b/setup.php index d2b74c4d0..8aa0a0bc1 100644 --- a/setup.php +++ b/setup.php @@ -192,8 +192,8 @@ function plugin_init_formcreator() { } // Load JS and CSS files if we are on a page which need them - if (strpos($_SERVER['REQUEST_URI'], "plugins/formcreator") !== false - || strpos($_SERVER['REQUEST_URI'], "central.php") !== false + if (strpos($_SERVER['REQUEST_URI'], 'plugins/formcreator') !== false + || strpos($_SERVER['REQUEST_URI'], 'central.php') !== false || isset($_SESSION['glpiactiveprofile']) && $_SESSION['glpiactiveprofile']['interface'] == 'helpdesk') { @@ -204,32 +204,32 @@ function plugin_init_formcreator() { $PLUGIN_HOOKS['add_javascript']['formcreator'][] = 'js/scripts.js.php'; } - if (strpos($_SERVER['REQUEST_URI'], "plugins/formcreator/front/targetticket.form.php") !== false) { + if (strpos($_SERVER['REQUEST_URI'], 'plugins/formcreator/front/targetticket.form.php') !== false) { if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { Html::requireJs('tinymce'); } } - if (strpos($_SERVER['REQUEST_URI'], "helpdesk") !== false - || strpos($_SERVER['REQUEST_URI'], "central.php") !== false - || strpos($_SERVER['REQUEST_URI'], "formcreator/front/formlist.php") !== false - || strpos($_SERVER['REQUEST_URI'], "formcreator/front/wizard.php") !== false) { + if (strpos($_SERVER['REQUEST_URI'], 'helpdesk') !== false + || strpos($_SERVER['REQUEST_URI'], 'central.php') !== false + || strpos($_SERVER['REQUEST_URI'], 'formcreator/front/formlist.php') !== false + || strpos($_SERVER['REQUEST_URI'], 'formcreator/front/wizard.php') !== false) { $PLUGIN_HOOKS['add_javascript']['formcreator'][] = 'lib/slinky/assets/js/jquery.slinky.js'; $PLUGIN_HOOKS['add_javascript']['formcreator'][] = 'lib/masonry.pkgd.min.js'; } - Plugin::registerClass('PluginFormcreatorForm', ['addtabon' => 'Central']); + Plugin::registerClass(PluginFormcreatorForm::class, ['addtabon' => Central::class]); // Load field class and all its method to manage fields - Plugin::registerClass('PluginFormcreatorFields'); + Plugin::registerClass(PluginFormcreatorFields::class); // Notification - Plugin::registerClass('PluginFormcreatorForm_Answer', [ + Plugin::registerClass(PluginFormcreatorForm_Answer::class, [ 'notificationtemplates_types' => true ]); - Plugin::registerClass('PluginFormcreatorEntityconfig', ['addtabon' => 'Entity']); + Plugin::registerClass(PluginFormcreatorEntityconfig::class, ['addtabon' => Entity::class]); } } } From 6d1a7c18882ca2fd138d14697950f01c2a36b0cb Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 6 Nov 2018 09:51:58 +0100 Subject: [PATCH 162/192] refactor(targetbase): factorization Signed-off-by: Thierry Bugier --- inc/targetbase.class.php | 29 ++++++++++ inc/targetchange.class.php | 19 +------ inc/targetticket.class.php | 108 ++++++++++++++++++++++++++++--------- 3 files changed, 112 insertions(+), 44 deletions(-) diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index 354705b81..377a9fad0 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -1123,4 +1123,33 @@ protected function setTargetDueDate($data, PluginFormcreatorForm_Answer $formans return $data; } + + public function prepareInputForUpdate($input) { + // generate a unique id + if (!isset($input['uuid']) + || empty($input['uuid'])) { + $input['uuid'] = plugin_formcreator_getUuid(); + } + + if (isset($input['name'])) { + $target = new PluginFormcreatorTarget(); + $target->getFromDBByCrit([ + 'itemtype' => self::class, + 'items_id' => $this->getID() + ]); + if (!$target->isNewItem()) { + $target->update([ + 'id' => $target->getID(), + 'name' => $input['name'], + ]); + } + } + + if (isset($input['title'])) { + $input['name'] = $input['title']; + unset($input['title']); + } + + return $input; + } } diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index 74e18c2a8..e705e72d8 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -892,24 +892,7 @@ public function prepareInputForUpdate($input) { } } - if (isset($input['name'])) { - $target = new PluginFormcreatorTarget(); - $target->getFromDBByCrit([ - 'itemtype' => self::class, - 'items_id' => $this->getID() - ]); - if (!$target->isNewItem()) { - $target->update([ - 'id' => $target->getID(), - 'name' => $input['name'], - ]); - } - } - if (isset($input['title'])) { - $input['name'] = $input['title']; - unset($input['title']); - } - return $input; + return parent::prepareInputForUpdate($input); } /** diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index 9e0ad0eed..741b6b732 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -917,31 +917,7 @@ public function prepareInputForUpdate($input) { $input = $this->saveLinkedItem($input); } - // generate a unique id - if (!isset($input['uuid']) - || empty($input['uuid'])) { - $input['uuid'] = plugin_formcreator_getUuid(); - } - - if (isset($input['name'])) { - $target = new PluginFormcreatorTarget(); - $target->getFromDBByCrit([ - 'itemtype' => self::class, - 'items_id' => $this->getID() - ]); - if (!$target->isNewItem()) { - $target->update([ - 'id' => $target->getID(), - 'name' => $input['name'], - ]); - } - } - if (isset($input['title'])) { - $input['name'] = $input['title']; - unset($input['title']); - } - - return $input; + return parent::prepareInputForUpdate($input); } /** @@ -1159,7 +1135,87 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { } // Computation of the entity - $data['entities_id'] = $this->getTargetEntity($formanswer, $requesters_id); + switch ($this->fields['destination_entity']) { + // Requester's entity + case 'current' : + $data['entities_id'] = $formanswer->getField('entities_id'); + break; + + case 'requester' : + $userObj = new User(); + $userObj->getFromDB($requesters_id); + $data['entities_id'] = $userObj->fields['entities_id']; + break; + + // Requester's first dynamic entity + case 'requester_dynamic_first' : + $order_entities = "`glpi_profiles`.`name` ASC"; + case 'requester_dynamic_last' : + if (!isset($order_entities)) { + $order_entities = "`glpi_profiles`.`name` DESC"; + } + $query_entities = "SELECT `glpi_profiles_users`.`entities_id` + FROM `glpi_profiles_users` + LEFT JOIN `glpi_profiles` + ON `glpi_profiles`.`id` = `glpi_profiles_users`.`profiles_id` + WHERE `glpi_profiles_users`.`users_id` = $requesters_id + ORDER BY `glpi_profiles_users`.`is_dynamic` DESC, $order_entities"; + $res_entities = $DB->query($query_entities); + $data_entities = []; + while ($entity = $DB->fetch_array($res_entities)) { + $data_entities[] = $entity; + } + $first_entity = array_shift($data_entities); + $data['entities_id'] = $first_entity['entities_id']; + break; + + // Specific entity + case 'specific' : + $data['entities_id'] = $this->fields['destination_entity_value']; + break; + + // The form entity + case 'form' : + $data['entities_id'] = $form->fields['entities_id']; + break; + + // The validator entity + case 'validator' : + $userObj = new User(); + $userObj->getFromDB($formanswer->fields['users_id_validator']); + $data['entities_id'] = $userObj->fields['entities_id']; + break; + + // Default entity of a user from the answer of a user's type question + case 'user' : + $found = $answer->find('plugin_formcreator_forms_answers_id = '.$formanswer->fields['id']. + ' AND plugin_formcreator_questions_id = '.$this->fields['destination_entity_value']); + $user = array_shift($found); + $user_id = $user['answer']; + + if ($user_id > 0) { + $userObj = new User(); + $userObj->getFromDB($user_id); + $data['entities_id'] = $userObj->fields['entities_id']; + } else { + $data['entities_id'] = 0; + } + break; + + // Entity from the answer of an entity's type question + case 'entity' : + $found = $answer->find('plugin_formcreator_forms_answers_id = '.$formanswer->fields['id']. + ' AND plugin_formcreator_questions_id = '.$this->fields['destination_entity_value']); + $entity = array_shift($found); + + $data['entities_id'] = $entity['answer']; + break; + + // Requester current entity + default : + $data['entities_id'] = 0; + break; + } $data = $this->setTargetDueDate($data, $formanswer); $data = $this->setTargetUrgency($data, $formanswer); From 94ed42b3239e734f0d0375d8757618445427a839 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Wed, 14 Nov 2018 11:33:01 +0100 Subject: [PATCH 163/192] refactor(form_answer): remove raw sql Signed-off-by: Thierry Bugier --- inc/form_answer.class.php | 70 ++++++++++++++++++++++++++++----------- setup.php | 2 +- 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index 7372270d5..93659e979 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -485,25 +485,57 @@ public function showForm($ID, $options = []) { echo '
'; - // Display all fields of the section - $query_questions = "SELECT `sections`.`name` AS `section_name`, - `questions`.*, - `answers`.`answer` - FROM `glpi_plugin_formcreator_questions` AS `questions` - LEFT JOIN `glpi_plugin_formcreator_answers` AS `answers` - ON `answers`.`plugin_formcreator_questions_id` = `questions`.`id` - AND `answers`.`plugin_formcreator_forms_answers_id` = '$ID' - INNER JOIN `glpi_plugin_formcreator_sections` AS `sections` - ON `questions`.`plugin_formcreator_sections_id` = `sections`.`id` - AND `plugin_formcreator_forms_id` = " . $form->getID() . " - GROUP BY `questions`.`id` - ORDER BY `sections`.`order` ASC, - `sections`.`id` ASC, - `questions`.`order` ASC"; - $res_questions = $DB->query($query_questions); - $last_section = ""; - $questionsCount = $DB->numrows($res_questions); - while ($question_line = $DB->fetch_assoc($res_questions)) { + $questionTable = PluginFormcreatorQuestion::getTable(); + $sectionTable = PluginFormcreatorSection::getTable(); + $answerTable = PluginFormcreatorAnswer::getTable(); + $formFk = PluginFormcreatorForm::getForeignKeyField(); + $questionFk = PluginFormcreatorQuestion::getForeignKeyField(); + $sectionFk = PluginFormcreatorSection::getForeignKeyField(); + $formAnswerFk = PluginFormcreatorForm_Answer::getForeignKeyField(); + $request = [ + 'SELECT' => [ + $sectionTable => ['name as section_name'], + $questionTable => ['*'], + $answerTable => ['answer'], + ], + 'FROM' => [ + $questionTable, + ], + 'LEFT JOIN' => [ + $answerTable => [ + 'FKEY' => [ + $answerTable => $questionFk, + $questionTable => 'id', + ['AND' => [ + "$answerTable.$formAnswerFk" => $ID, + ]], + ], + ], + ], + 'INNER JOIN' => [ + $sectionTable => [ + 'FKEY' => [ + $questionTable => $sectionFk, + $sectionTable => 'id', + ['AND' => [ + "$sectionTable.$formFk" => $form->getID(), + ]], + ], + ], + ], + 'GROUPBY' => [ + "$questionTable.id", + ], + 'ORDER' => [ + "$sectionTable.order ASC", + "$sectionTable.id ASC", + "$questionTable.order *ASC", + ], + ]; + $questions = $DB->request($request); + $last_section = ''; + $questionsCount = $questions->count(); + while ($question_line = $questions->next()) { // Get and display current section if needed if ($last_section != $question_line['section_name']) { echo '

'.$question_line['section_name'].'

'; diff --git a/setup.php b/setup.php index 8aa0a0bc1..c188621e9 100644 --- a/setup.php +++ b/setup.php @@ -40,7 +40,7 @@ define('PLUGIN_FORMCREATOR_IS_OFFICIAL_RELEASE', false); // Minimal GLPI version, inclusive -define ('PLUGIN_FORMCREATOR_GLPI_MIN_VERSION', '9.3'); +define ('PLUGIN_FORMCREATOR_GLPI_MIN_VERSION', '9.3.1'); // Maximum GLPI version, exclusive define ('PLUGIN_FORMCREATOR_GLPI_MAX_VERSION', '9.4'); From 993576d94f9cc6210fcd25c7cbc26afd9e649325 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Wed, 14 Nov 2018 12:22:53 +0100 Subject: [PATCH 164/192] fix(target): content generation probably caused by a chery-pick from release 2.6.5 Signed-off-by: Thierry Bugier --- inc/form_answer.class.php | 62 ++++++++++++++++++++++++++------------ inc/targetchange.class.php | 2 +- inc/targetticket.class.php | 1 + setup.php | 2 +- 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index 93659e979..de701efcb 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -485,6 +485,8 @@ public function showForm($ID, $options = []) { echo '
'; + // TODO: code very close to PluginFormcreatorTargetBase::getFullForm() (factorizable ?) + // compute all questions $questionTable = PluginFormcreatorQuestion::getTable(); $sectionTable = PluginFormcreatorSection::getTable(); $answerTable = PluginFormcreatorAnswer::getTable(); @@ -506,9 +508,6 @@ public function showForm($ID, $options = []) { 'FKEY' => [ $answerTable => $questionFk, $questionTable => 'id', - ['AND' => [ - "$answerTable.$formAnswerFk" => $ID, - ]], ], ], ], @@ -517,12 +516,15 @@ public function showForm($ID, $options = []) { 'FKEY' => [ $questionTable => $sectionFk, $sectionTable => 'id', - ['AND' => [ - "$sectionTable.$formFk" => $form->getID(), - ]], ], ], ], + 'WHERE' => [ + 'AND' => [ + "$answerTable.$formAnswerFk" => $ID, + "$sectionTable.$formFk" => $form->getID(), + ], + ], 'GROUPBY' => [ "$questionTable.id", ], @@ -1126,20 +1128,42 @@ public function getFullForm($disableRichText = false) { // TODO: code very close to PluginFormcreatorTargetBase::parseTags() (factorizable ?) // compute all questions - $query_questions = "SELECT sections.`name` as section_name, - questions.* - FROM `glpi_plugin_formcreator_questions` AS questions - INNER JOIN `glpi_plugin_formcreator_sections` as sections - ON questions.`plugin_formcreator_sections_id` = sections.`id` - AND plugin_formcreator_forms_id = ".$this->fields['plugin_formcreator_forms_id']." - GROUP BY questions.`id` - ORDER BY sections.`order` ASC, - sections.`id` ASC, - questions.`order` ASC"; - $res_questions = $DB->query($query_questions); + $questionTable = PluginFormcreatorQuestion::getTable(); + $sectionTable = PluginFormcreatorSection::getTable(); + $formFk = PluginFormcreatorForm::getForeignKeyField(); + $sectionFk = PluginFormcreatorSection::getForeignKeyField(); + $questions = $DB->request([ + 'SELECT' => [ + $sectionTable => ['name as section_name'], + $questionTable => ['*'], + ], + 'FROM' => [ + $questionTable, + ], + 'INNER JOIN' => [ + $sectionTable => [ + 'FKEY' => [ + $questionTable => $sectionFk, + $sectionTable => 'id', + ], + ], + ], + 'WHERE' => [ + 'AND' => [ + "$sectionTable.$formFk" => $this->fields['plugin_formcreator_forms_id'], + ], + ], + 'GROUPBY' => [ + "$questionTable.id", + ], + 'ORDER' => [ + "$sectionTable.order ASC", + "$sectionTable.id ASC", + "$questionTable.order *ASC", + ], + ]); $last_section = ""; - while ($question_line = $DB->fetch_assoc($res_questions)) { - + while ($question_line = $questions->next()) { // Get and display current section if needed if ($last_section != $question_line['section_name']) { if ($disableRichText === false diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index e705e72d8..8962ede41 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -236,7 +236,7 @@ public function showForm($options = []) { echo ''; echo '' . __('Description') . ' *'; echo ''; - echo ''; + echo ''; echo ''; echo ''; diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index 741b6b732..ab3b18e45 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -1097,6 +1097,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { $data['name'] = $this->parseTags($data['name'], $formanswer); $data['name'] = Toolbox::addslashes_deep($data['name']); + $data['content'] = $this->fields['content']; $data['content'] = str_replace("\r\n", '\r\n', $data['content']); if (strpos($data['content'], '##FULLFORM##') !== false) { $data['content'] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data['content']); diff --git a/setup.php b/setup.php index c188621e9..26d77dba6 100644 --- a/setup.php +++ b/setup.php @@ -40,7 +40,7 @@ define('PLUGIN_FORMCREATOR_IS_OFFICIAL_RELEASE', false); // Minimal GLPI version, inclusive -define ('PLUGIN_FORMCREATOR_GLPI_MIN_VERSION', '9.3.1'); +define ('PLUGIN_FORMCREATOR_GLPI_MIN_VERSION', '9.3.0'); // Maximum GLPI version, exclusive define ('PLUGIN_FORMCREATOR_GLPI_MAX_VERSION', '9.4'); From 0bb64c5d802924315ef3f055d4de1a253e00eb37 Mon Sep 17 00:00:00 2001 From: btry Date: Fri, 9 Nov 2018 18:26:01 +0100 Subject: [PATCH 165/192] fix(ticket): redirect to service catalog when viewing ticket Signed-off-by: btry --- setup.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/setup.php b/setup.php index 26d77dba6..93a290b62 100644 --- a/setup.php +++ b/setup.php @@ -153,6 +153,11 @@ function plugin_init_formcreator() { } } } + if (strpos($_SERVER['REQUEST_URI'], "front/ticket.form.php") !== false) { + if (plugin_formcreator_replaceHelpdesk()) { + Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/issue.form.php?id=' . $_GET['id'] . '&sub_itemtype=Ticket'); + } + } // Massive Action definition $PLUGIN_HOOKS['use_massive_action']['formcreator'] = 1; From 5a1bfe735fb17594df07b78f8db6ae8996cd69df Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Mon, 19 Nov 2018 20:27:22 +0100 Subject: [PATCH 166/192] fix(field): remove unused method Signed-off-by: Thierry Bugier --- inc/fieldinterface.class.php | 7 ------- inc/fields/actorfield.class.php | 3 --- inc/fields/checkboxesfield.class.php | 4 ---- inc/fields/datefield.class.php | 4 ---- inc/fields/datetimefield.class.php | 4 ---- inc/fields/descriptionfield.class.php | 4 ---- inc/fields/dropdownfield.class.php | 4 ---- inc/fields/emailfield.class.php | 4 ---- inc/fields/filefield.class.php | 4 ---- inc/fields/floatfield.class.php | 4 ---- inc/fields/hiddenfield.class.php | 4 ---- inc/fields/hostnamefield.class.php | 4 ---- inc/fields/integerfield.class.php | 4 ---- inc/fields/ipfield.class.php | 4 ---- inc/fields/multiselectfield.class.php | 4 ---- inc/fields/radiosfield.class.php | 4 ---- inc/fields/textfield.class.php | 4 ---- inc/fields/urgencyfield.class.php | 4 ---- 18 files changed, 74 deletions(-) diff --git a/inc/fieldinterface.class.php b/inc/fieldinterface.class.php index a0ad74dbc..ef7cfddca 100644 --- a/inc/fieldinterface.class.php +++ b/inc/fieldinterface.class.php @@ -95,13 +95,6 @@ public function getValueForDesign(); */ public function getValueForTargetText(); - /** - * Get the value of the field for use in a field of a target - * - * @return string - */ - public function getValueForTargetField(); - /** * Gets the documents IDs * diff --git a/inc/fields/actorfield.class.php b/inc/fields/actorfield.class.php index 1ebc28689..ead46ebdc 100644 --- a/inc/fields/actorfield.class.php +++ b/inc/fields/actorfield.class.php @@ -150,9 +150,6 @@ public function getValueForTargetText() { return implode(', ', Toolbox::addslashes_deep($value)); } - public function getValueForTargetField() { - return $this->value; - } public function getDocumentsForTarget() { return []; diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index 98632b87c..f17438f9b 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -220,10 +220,6 @@ public function getValueForTargetText() { return $value; } - public function getValueForTargetField() { - return null; - } - public function getDocumentsForTarget() { return [];; } diff --git a/inc/fields/datefield.class.php b/inc/fields/datefield.class.php index e5aca09cd..73cbfa7d1 100644 --- a/inc/fields/datefield.class.php +++ b/inc/fields/datefield.class.php @@ -74,10 +74,6 @@ public function getValueForTargetText() { return Toolbox::addslashes_deep(Html::convDate($this->value)); } - public function getValueForTargetField() { - return $this->value; - } - public function getDocumentsForTarget() { return [];; } diff --git a/inc/fields/datetimefield.class.php b/inc/fields/datetimefield.class.php index 42ff66e3a..d35a613da 100644 --- a/inc/fields/datetimefield.class.php +++ b/inc/fields/datetimefield.class.php @@ -77,10 +77,6 @@ public function getValueForTargetText() { return Toolbox::addslashes_deep(Html::convDateTime($this->value)); } - public function getValueForTargetField() { - return $this->value; - } - public function getDocumentsForTarget() { return [];; } diff --git a/inc/fields/descriptionfield.class.php b/inc/fields/descriptionfield.class.php index 53f607ff4..c831a1ef2 100644 --- a/inc/fields/descriptionfield.class.php +++ b/inc/fields/descriptionfield.class.php @@ -59,10 +59,6 @@ public function getValueForTargetText() { return ''; } - public function getValueForTargetField() { - return ''; - } - public function getDocumentsForTarget() { return [];; } diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index b0b4cb1ce..0e2238068 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -162,10 +162,6 @@ public function getValueForTargetText() { return Toolbox::addslashes_deep($value); } - public function getValueForTargetField() { - return $this->value; - } - public function getDocumentsForTarget() { return [];; } diff --git a/inc/fields/emailfield.class.php b/inc/fields/emailfield.class.php index 525dc8db4..6f784356a 100644 --- a/inc/fields/emailfield.class.php +++ b/inc/fields/emailfield.class.php @@ -84,10 +84,6 @@ public function getValueForTargetText() { return Toolbox::addslashes_deep($this->value); } - public function getValueForTargetField() { - return $this->value; - } - public function getDocumentsForTarget() { return [];; } diff --git a/inc/fields/filefield.class.php b/inc/fields/filefield.class.php index c627ade88..3de1456e2 100644 --- a/inc/fields/filefield.class.php +++ b/inc/fields/filefield.class.php @@ -94,10 +94,6 @@ public function getDocumentsForTarget() { return $this->uploadData; } - public function getValueForTargetField() { - return $this->uploadData; - } - public function isValid() { if (!$this->isRequired()) { return true; diff --git a/inc/fields/floatfield.class.php b/inc/fields/floatfield.class.php index ff0af4319..d14577dec 100644 --- a/inc/fields/floatfield.class.php +++ b/inc/fields/floatfield.class.php @@ -82,10 +82,6 @@ public function getValueForTargetText() { return Toolbox::addslashes_deep($this->value); } - public function getValueForTargetField() { - return $this->value; - } - public function getDocumentsForTarget() { return [];; } diff --git a/inc/fields/hiddenfield.class.php b/inc/fields/hiddenfield.class.php index b9b4fe2e0..465bcd3b8 100644 --- a/inc/fields/hiddenfield.class.php +++ b/inc/fields/hiddenfield.class.php @@ -73,10 +73,6 @@ public function getValueForTargetText() { return str_replace("\n", '\r\n', Toolbox::addslashes_deep($this->value)); } - public function getValueForTargetField() { - return $this->value; - } - public function getDocumentsForTarget() { return [];; } diff --git a/inc/fields/hostnamefield.class.php b/inc/fields/hostnamefield.class.php index 41300e509..9f5af9d14 100644 --- a/inc/fields/hostnamefield.class.php +++ b/inc/fields/hostnamefield.class.php @@ -38,10 +38,6 @@ public function getValueForTargetText() { return Toolbox::addslashes_deep($this->value); } - public function getValueForTargetField() { - return $this->value; - } - public function getDocumentsForTarget() { return [];; } diff --git a/inc/fields/integerfield.class.php b/inc/fields/integerfield.class.php index 2c8682e18..6df8ed8a7 100644 --- a/inc/fields/integerfield.class.php +++ b/inc/fields/integerfield.class.php @@ -82,10 +82,6 @@ public function getValueForTargetText() { return Toolbox::addslashes_deep($this->value); } - public function getValueForTargetField() { - return $this->value; - } - public function getDocumentsForTarget() { return [];; } diff --git a/inc/fields/ipfield.class.php b/inc/fields/ipfield.class.php index 60b68f9b5..f7bc49be8 100644 --- a/inc/fields/ipfield.class.php +++ b/inc/fields/ipfield.class.php @@ -76,10 +76,6 @@ public function getValueForTargetText() { return Toolbox::addslashes_deep($this->value); } - public function getValueForTargetField() { - return $this->value; - } - public function getDocumentsForTarget() { return [];; } diff --git a/inc/fields/multiselectfield.class.php b/inc/fields/multiselectfield.class.php index 93c853e23..bce037f6b 100644 --- a/inc/fields/multiselectfield.class.php +++ b/inc/fields/multiselectfield.class.php @@ -189,10 +189,6 @@ public function getValueForTargetText() { return $value; } - public function getValueForTargetField() { - return $this->value; - } - public function getDocumentsForTarget() { return [];; } diff --git a/inc/fields/radiosfield.class.php b/inc/fields/radiosfield.class.php index 1b46f6c6e..76364abec 100644 --- a/inc/fields/radiosfield.class.php +++ b/inc/fields/radiosfield.class.php @@ -170,10 +170,6 @@ public function getValueForTargetText() { return Toolbox::addslashes_deep($this->value); } - public function getValueForTargetField() { - return $this->value; - } - public function getDocumentsForTarget() { return [];; } diff --git a/inc/fields/textfield.class.php b/inc/fields/textfield.class.php index b78749407..35e51ddc6 100644 --- a/inc/fields/textfield.class.php +++ b/inc/fields/textfield.class.php @@ -82,10 +82,6 @@ public function getValueForTargetText() { return Toolbox::addslashes_deep($this->value); } - public function getValueForTargetField() { - return $this->value; - } - public function getDocumentsForTarget() { return [];; } diff --git a/inc/fields/urgencyfield.class.php b/inc/fields/urgencyfield.class.php index f7c5f32d3..22bfea8cd 100644 --- a/inc/fields/urgencyfield.class.php +++ b/inc/fields/urgencyfield.class.php @@ -128,10 +128,6 @@ public function getValueForTargetText() { return $available[$this->value]; } - public function getValueForTargetField() { - return $this->value; - } - public function getDocumentsForTarget() { return [];; } From 37c19bfae9b98bac97b6e88d59ee45c03060e248 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Mon, 19 Nov 2018 20:43:08 +0100 Subject: [PATCH 167/192] refactor: use Toolbox method remove useless semicolon Signed-off-by: Thierry Bugier --- inc/fields/actorfield.class.php | 12 +++++++++--- inc/fields/checkboxesfield.class.php | 4 ++-- inc/fields/descriptionfield.class.php | 2 +- inc/fields/dropdownfield.class.php | 2 +- inc/fields/emailfield.class.php | 2 +- inc/fields/floatfield.class.php | 2 +- inc/fields/hiddenfield.class.php | 2 +- inc/fields/hostnamefield.class.php | 2 +- inc/fields/integerfield.class.php | 2 +- inc/fields/ipfield.class.php | 2 +- inc/fields/multiselectfield.class.php | 4 ++-- inc/fields/radiosfield.class.php | 2 +- inc/fields/textfield.class.php | 2 +- inc/fields/urgencyfield.class.php | 2 +- inc/targetbase.class.php | 4 ++-- 15 files changed, 26 insertions(+), 20 deletions(-) diff --git a/inc/fields/actorfield.class.php b/inc/fields/actorfield.class.php index ead46ebdc..e6ddc8b10 100644 --- a/inc/fields/actorfield.class.php +++ b/inc/fields/actorfield.class.php @@ -140,14 +140,20 @@ public function getValueForTargetText() { $value = []; foreach ($this->value as $item) { if (filter_var($item, FILTER_VALIDATE_EMAIL) !== false) { - $value[] = $item; + $value[] = Toolbox::addslashes_deep($item); } else { $user = new User(); $user->getFromDB($item); - $value[] = $user->getRawName(); + $value[] = Toolbox::addslashes_deep($user->getRawName()); } } - return implode(', ', Toolbox::addslashes_deep($value)); + + if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { + $value = '
' . implode('
', $value); + } else { + $value = '\r\n' . implode('\r\n', $value); + } + return $value; } diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index f17438f9b..8c20b5d8f 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -208,7 +208,7 @@ public function getValueForTargetText() { foreach ($this->value as $input) { if (in_array($input, $values)) { - $value[] = addslashes($input); + $value[] = Toolbox::addslashes_deep($input); } } @@ -221,7 +221,7 @@ public function getValueForTargetText() { } public function getDocumentsForTarget() { - return [];; + return []; } public static function getPrefs() { diff --git a/inc/fields/descriptionfield.class.php b/inc/fields/descriptionfield.class.php index c831a1ef2..31079b3e8 100644 --- a/inc/fields/descriptionfield.class.php +++ b/inc/fields/descriptionfield.class.php @@ -60,7 +60,7 @@ public function getValueForTargetText() { } public function getDocumentsForTarget() { - return [];; + return []; } public function isValid() { diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index 0e2238068..3ac56f514 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -163,7 +163,7 @@ public function getValueForTargetText() { } public function getDocumentsForTarget() { - return [];; + return []; } public static function getName() { diff --git a/inc/fields/emailfield.class.php b/inc/fields/emailfield.class.php index 6f784356a..e7a94c6c5 100644 --- a/inc/fields/emailfield.class.php +++ b/inc/fields/emailfield.class.php @@ -85,7 +85,7 @@ public function getValueForTargetText() { } public function getDocumentsForTarget() { - return [];; + return []; } public function isValid() { diff --git a/inc/fields/floatfield.class.php b/inc/fields/floatfield.class.php index d14577dec..2d206c32d 100644 --- a/inc/fields/floatfield.class.php +++ b/inc/fields/floatfield.class.php @@ -83,7 +83,7 @@ public function getValueForTargetText() { } public function getDocumentsForTarget() { - return [];; + return []; } public function isValid() { diff --git a/inc/fields/hiddenfield.class.php b/inc/fields/hiddenfield.class.php index 465bcd3b8..4437454b8 100644 --- a/inc/fields/hiddenfield.class.php +++ b/inc/fields/hiddenfield.class.php @@ -74,7 +74,7 @@ public function getValueForTargetText() { } public function getDocumentsForTarget() { - return [];; + return []; } public static function getPrefs() { diff --git a/inc/fields/hostnamefield.class.php b/inc/fields/hostnamefield.class.php index 9f5af9d14..2b382836f 100644 --- a/inc/fields/hostnamefield.class.php +++ b/inc/fields/hostnamefield.class.php @@ -39,7 +39,7 @@ public function getValueForTargetText() { } public function getDocumentsForTarget() { - return [];; + return []; } public function isValid() { diff --git a/inc/fields/integerfield.class.php b/inc/fields/integerfield.class.php index 6df8ed8a7..4538b4730 100644 --- a/inc/fields/integerfield.class.php +++ b/inc/fields/integerfield.class.php @@ -83,7 +83,7 @@ public function getValueForTargetText() { } public function getDocumentsForTarget() { - return [];; + return []; } public function isValid() { diff --git a/inc/fields/ipfield.class.php b/inc/fields/ipfield.class.php index f7bc49be8..d717632ac 100644 --- a/inc/fields/ipfield.class.php +++ b/inc/fields/ipfield.class.php @@ -77,7 +77,7 @@ public function getValueForTargetText() { } public function getDocumentsForTarget() { - return [];; + return []; } public function isValid() { diff --git a/inc/fields/multiselectfield.class.php b/inc/fields/multiselectfield.class.php index bce037f6b..0df4e5b0e 100644 --- a/inc/fields/multiselectfield.class.php +++ b/inc/fields/multiselectfield.class.php @@ -178,7 +178,7 @@ public function getValueForTargetText() { foreach ($tab_values as $input) { if (in_array($input, $values)) { - $value[] = addslashes($input); + $value[] = Toolbox::addslashes_deep($input); } } if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { @@ -190,7 +190,7 @@ public function getValueForTargetText() { } public function getDocumentsForTarget() { - return [];; + return []; } public static function getName() { diff --git a/inc/fields/radiosfield.class.php b/inc/fields/radiosfield.class.php index 76364abec..a953d66a1 100644 --- a/inc/fields/radiosfield.class.php +++ b/inc/fields/radiosfield.class.php @@ -171,7 +171,7 @@ public function getValueForTargetText() { } public function getDocumentsForTarget() { - return [];; + return []; } public function isValid() { diff --git a/inc/fields/textfield.class.php b/inc/fields/textfield.class.php index 35e51ddc6..bee523ead 100644 --- a/inc/fields/textfield.class.php +++ b/inc/fields/textfield.class.php @@ -83,7 +83,7 @@ public function getValueForTargetText() { } public function getDocumentsForTarget() { - return [];; + return []; } public function isValid() { diff --git a/inc/fields/urgencyfield.class.php b/inc/fields/urgencyfield.class.php index 22bfea8cd..36510d1c7 100644 --- a/inc/fields/urgencyfield.class.php +++ b/inc/fields/urgencyfield.class.php @@ -129,7 +129,7 @@ public function getValueForTargetText() { } public function getDocumentsForTarget() { - return [];; + return []; } public function isValid() { diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index 377a9fad0..130e88406 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -972,10 +972,10 @@ protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer, $value = ''; } else { $name = $question->getField('name'); - $value = $fields[$questionId]->getValueForTargetText(); + $value = $fields[$questionId]->getValueForTargetText($disableRichText); } - $content = str_replace('##question_' . $questionId . '##', addslashes($name), $content); + $content = str_replace('##question_' . $questionId . '##', Toolbox::addslashes_deep($name), $content); $content = str_replace('##answer_' . $questionId . '##', $value, $content); foreach ($fields[$questionId]->getDocumentsForTarget() as $documentId) { $this->addAttachedDocument($documentId); From ef73e985cc3a54778408aa745a6d1e0b38f29c68 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Mon, 19 Nov 2018 09:38:49 +0100 Subject: [PATCH 168/192] style(field): fix code style Signed-off-by: Thierry Bugier --- inc/fields/checkboxesfield.class.php | 2 +- inc/question.class.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index 98632b87c..42a4ed18d 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -225,7 +225,7 @@ public function getValueForTargetField() { } public function getDocumentsForTarget() { - return [];; + return []; } public static function getPrefs() { diff --git a/inc/question.class.php b/inc/question.class.php index 3c760561c..858b91f02 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -979,7 +979,7 @@ function plugin_formcreator_hideAllParameters() { $defaultValues = ''; if (!$this->isNewItem()) { $fieldObject = PluginFormcreatorFields::getFieldInstance( - $this->getField('fieldtype'), + $this->fields['fieldtype'], $this ); $fieldObject->deserializeValue($this->fields['default_values']); From a63c04f0d83e664514ffa0b8ba223554b8b5a121 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Mon, 19 Nov 2018 10:20:27 +0100 Subject: [PATCH 169/192] fix(dropdownfield): restrict by entity when needed Signed-off-by: Thierry Bugier --- inc/fields/dropdownfield.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index b0b4cb1ce..dd47955f5 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -57,6 +57,7 @@ public function displayField($canEdit = true) { $dparams = ['name' => $fieldName, 'value' => $this->value, 'comments' => false, + 'entity' => $_SESSION['glpiactive_entity'], 'rand' => $rand]; switch ($itemtype) { @@ -78,13 +79,13 @@ public function displayField($canEdit = true) { $dparams['condition'] .= " AND `is_incident` = '1'"; break; case 'both': - $dparams['condition'] .= " AND `is_incident` = '1' OR `is_request` = '1' "; + $dparams['condition'] .= " AND (`is_incident` = '1' OR `is_request` = '1')"; break; case 'change': $dparams['condition'] .= " AND `is_change` = '1'"; break; case 'all': - $dparams['condition'] .= " AND `is_change` = '1' OR `is_incident` = '1' OR `is_request` = '1'"; + $dparams['condition'] .= " AND (`is_change` = '1' OR `is_incident` = '1' OR `is_request` = '1')"; break; } if (isset($decodedValues['show_ticket_categories_depth']) From 97a12e4803a27e180b89b422fcf0ed89e44107f5 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Thu, 22 Nov 2018 18:19:14 +0100 Subject: [PATCH 170/192] refactor(target): organize rich text handling Signed-off-by: Thierry Bugier --- inc/fieldinterface.class.php | 3 ++- inc/fields/actorfield.class.php | 6 +++--- inc/fields/checkboxesfield.class.php | 6 +++--- inc/fields/datefield.class.php | 2 +- inc/fields/datetimefield.class.php | 6 +++++- inc/fields/descriptionfield.class.php | 2 +- inc/fields/dropdownfield.class.php | 2 +- inc/fields/emailfield.class.php | 2 +- inc/fields/filefield.class.php | 2 +- inc/fields/floatfield.class.php | 2 +- inc/fields/hiddenfield.class.php | 2 +- inc/fields/hostnamefield.class.php | 2 +- inc/fields/integerfield.class.php | 2 +- inc/fields/ipfield.class.php | 2 +- inc/fields/multiselectfield.class.php | 6 +++--- inc/fields/radiosfield.class.php | 2 +- inc/fields/selectfield.class.php | 2 +- inc/fields/textareafield.class.php | 2 +- inc/fields/textfield.class.php | 2 +- inc/fields/urgencyfield.class.php | 2 +- inc/form_answer.class.php | 12 +++++------ inc/targetbase.class.php | 20 ++++++------------ inc/targetchange.class.php | 13 +----------- inc/targetticket.class.php | 11 +++++----- .../PluginFormcreatorActorField.php | 12 +++++------ .../PluginFormcreatorDatetimeField.php | 21 ++++++++----------- 26 files changed, 63 insertions(+), 83 deletions(-) diff --git a/inc/fieldinterface.class.php b/inc/fieldinterface.class.php index ef7cfddca..586d1c21b 100644 --- a/inc/fieldinterface.class.php +++ b/inc/fieldinterface.class.php @@ -91,9 +91,10 @@ public function getValueForDesign(); /** * Get the value of the field for display in a target * + * @param boolean $disableRichText Disable rich text mode for field rendering * @return string */ - public function getValueForTargetText(); + public function getValueForTargetText($disableRichText); /** * Gets the documents IDs diff --git a/inc/fields/actorfield.class.php b/inc/fields/actorfield.class.php index e6ddc8b10..0b845c3dd 100644 --- a/inc/fields/actorfield.class.php +++ b/inc/fields/actorfield.class.php @@ -136,7 +136,7 @@ public function getValueForDesign() { return implode("\r\n", $value); } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { $value = []; foreach ($this->value as $item) { if (filter_var($item, FILTER_VALIDATE_EMAIL) !== false) { @@ -148,10 +148,10 @@ public function getValueForTargetText() { } } - if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { + if ($richText) { $value = '
' . implode('
', $value); } else { - $value = '\r\n' . implode('\r\n', $value); + $value = implode(', ', $value); } return $value; } diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index 8c20b5d8f..f281d2e65 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -196,7 +196,7 @@ public function prepareQuestionInputForSave($input) { return $input; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { global $CFG_GLPI; $value = []; @@ -212,10 +212,10 @@ public function getValueForTargetText() { } } - if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { + if ($richText) { $value = '
' . implode('
', $value); } else { - $value = '\r\n' . implode('\r\n', $value); + $value = implode(', ', $value); } return $value; } diff --git a/inc/fields/datefield.class.php b/inc/fields/datefield.class.php index 73cbfa7d1..d2d4e2a4f 100644 --- a/inc/fields/datefield.class.php +++ b/inc/fields/datefield.class.php @@ -70,7 +70,7 @@ public function getValueForDesign() { return $this->value; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { return Toolbox::addslashes_deep(Html::convDate($this->value)); } diff --git a/inc/fields/datetimefield.class.php b/inc/fields/datetimefield.class.php index d35a613da..d9839fbf8 100644 --- a/inc/fields/datetimefield.class.php +++ b/inc/fields/datetimefield.class.php @@ -73,7 +73,7 @@ public function getValueForDesign() { return $this->value; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { return Toolbox::addslashes_deep(Html::convDateTime($this->value)); } @@ -155,6 +155,10 @@ public function parseAnswerValues($input) { return false; } + if (DateTime::createFromFormat("Y-m-d H:i", $input[$key]) === false) { + return false; + } + $this->value = $input[$key]; return true; } diff --git a/inc/fields/descriptionfield.class.php b/inc/fields/descriptionfield.class.php index 31079b3e8..35b82c049 100644 --- a/inc/fields/descriptionfield.class.php +++ b/inc/fields/descriptionfield.class.php @@ -55,7 +55,7 @@ public function getValueForDesign() { return ''; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { return ''; } diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index 3ac56f514..f4ff6035a 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -150,7 +150,7 @@ public function getValueForDesign() { return $this->value; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { $DbUtil = new DbUtils(); $decodedValues = json_decode($this->fields['values'], JSON_OBJECT_AS_ARRAY); if (!isset($decodedValues['itemtype'])) { diff --git a/inc/fields/emailfield.class.php b/inc/fields/emailfield.class.php index e7a94c6c5..960e35e24 100644 --- a/inc/fields/emailfield.class.php +++ b/inc/fields/emailfield.class.php @@ -80,7 +80,7 @@ public function getValueForDesign() { return $this->value; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { return Toolbox::addslashes_deep($this->value); } diff --git a/inc/fields/filefield.class.php b/inc/fields/filefield.class.php index 3de1456e2..43800293c 100644 --- a/inc/fields/filefield.class.php +++ b/inc/fields/filefield.class.php @@ -86,7 +86,7 @@ public function getValueForDesign() { return ''; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { return $this->value; } diff --git a/inc/fields/floatfield.class.php b/inc/fields/floatfield.class.php index 2d206c32d..e8a89072a 100644 --- a/inc/fields/floatfield.class.php +++ b/inc/fields/floatfield.class.php @@ -78,7 +78,7 @@ public function getValueForDesign() { return $this->value; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { return Toolbox::addslashes_deep($this->value); } diff --git a/inc/fields/hiddenfield.class.php b/inc/fields/hiddenfield.class.php index 4437454b8..f6758b371 100644 --- a/inc/fields/hiddenfield.class.php +++ b/inc/fields/hiddenfield.class.php @@ -69,7 +69,7 @@ public static function getName() { return _n('Hidden field', 'Hidden fields', 1); } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { return str_replace("\n", '\r\n', Toolbox::addslashes_deep($this->value)); } diff --git a/inc/fields/hostnamefield.class.php b/inc/fields/hostnamefield.class.php index 2b382836f..671dc3c02 100644 --- a/inc/fields/hostnamefield.class.php +++ b/inc/fields/hostnamefield.class.php @@ -34,7 +34,7 @@ public function getValueForDesign() { return ''; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { return Toolbox::addslashes_deep($this->value); } diff --git a/inc/fields/integerfield.class.php b/inc/fields/integerfield.class.php index 4538b4730..37ee43a11 100644 --- a/inc/fields/integerfield.class.php +++ b/inc/fields/integerfield.class.php @@ -78,7 +78,7 @@ public function getValueForDesign() { return $this->value; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { return Toolbox::addslashes_deep($this->value); } diff --git a/inc/fields/ipfield.class.php b/inc/fields/ipfield.class.php index d717632ac..132a57474 100644 --- a/inc/fields/ipfield.class.php +++ b/inc/fields/ipfield.class.php @@ -72,7 +72,7 @@ public function getValueForDesign() { return $this->value; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { return Toolbox::addslashes_deep($this->value); } diff --git a/inc/fields/multiselectfield.class.php b/inc/fields/multiselectfield.class.php index 0df4e5b0e..3835ca076 100644 --- a/inc/fields/multiselectfield.class.php +++ b/inc/fields/multiselectfield.class.php @@ -157,7 +157,7 @@ public function prepareQuestionInputForSave($input) { return $input; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { global $CFG_GLPI; $input = $this->value; @@ -181,10 +181,10 @@ public function getValueForTargetText() { $value[] = Toolbox::addslashes_deep($input); } } - if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { + if ($richText) { $value = '
' . implode('
', $value); } else { - $value = '\r\n' . implode('\r\n', $value); + $value = implode(', ', $value); } return $value; } diff --git a/inc/fields/radiosfield.class.php b/inc/fields/radiosfield.class.php index a953d66a1..01bd0c1ac 100644 --- a/inc/fields/radiosfield.class.php +++ b/inc/fields/radiosfield.class.php @@ -166,7 +166,7 @@ public function getValueForDesign() { return $this->value; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { return Toolbox::addslashes_deep($this->value); } diff --git a/inc/fields/selectfield.class.php b/inc/fields/selectfield.class.php index 706b61c8c..7f2219520 100644 --- a/inc/fields/selectfield.class.php +++ b/inc/fields/selectfield.class.php @@ -113,7 +113,7 @@ public function getValueForDesign() { return $this->value; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { return Toolbox::addslashes_deep($this->value); } diff --git a/inc/fields/textareafield.class.php b/inc/fields/textareafield.class.php index ea26814e9..24fe0e086 100644 --- a/inc/fields/textareafield.class.php +++ b/inc/fields/textareafield.class.php @@ -114,7 +114,7 @@ public function prepareQuestionInputForSave($input) { return $input; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { return str_replace("\r\n", '\r\n', Toolbox::addslashes_deep($this->value)); } diff --git a/inc/fields/textfield.class.php b/inc/fields/textfield.class.php index bee523ead..c8c383744 100644 --- a/inc/fields/textfield.class.php +++ b/inc/fields/textfield.class.php @@ -78,7 +78,7 @@ public function getValueForDesign() { return $this->value; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { return Toolbox::addslashes_deep($this->value); } diff --git a/inc/fields/urgencyfield.class.php b/inc/fields/urgencyfield.class.php index 36510d1c7..2df943e9c 100644 --- a/inc/fields/urgencyfield.class.php +++ b/inc/fields/urgencyfield.class.php @@ -123,7 +123,7 @@ public function getValueForDesign() { return $this->value; } - public function getValueForTargetText() { + public function getValueForTargetText($richText) { $available = $this->getAvailableValues(); return $available[$this->value]; } diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index de701efcb..d1bc27fa7 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -1093,17 +1093,17 @@ public function getForm() { /** * Get entire form to be inserted into a target content * + * @param boolean $richText If true, enable rich text output * @return String Full form questions and answers to be print */ - public function getFullForm($disableRichText = false) { + public function getFullForm($richText = false) { global $CFG_GLPI, $DB; $question_no = 0; $output = ''; $eol = "\r\n"; - if ($disableRichText === false - && (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text'])) { + if ($richText) { $output .= '

' . __('Form data', 'formcreator') . '

'; } else { $output .= __('Form data', 'formcreator') . $eol; @@ -1166,8 +1166,7 @@ public function getFullForm($disableRichText = false) { while ($question_line = $questions->next()) { // Get and display current section if needed if ($last_section != $question_line['section_name']) { - if ($disableRichText === false - && (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text'])) { + if ($richText) { $output .= '

' . Toolbox::addslashes_deep($question_line['section_name']) . '

'; } else { $output .= $eol . Toolbox::addslashes_deep($question_line['section_name']) . $eol; @@ -1188,8 +1187,7 @@ public function getFullForm($disableRichText = false) { if ($question_line['fieldtype'] != 'description') { $question_no++; - if ($disableRichText === false - && (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text'])) { + if ($richText) { $output .= '
'; $output .= '' . $question_no . ') ##question_' . $question_line['id'] . '## : '; $output .= '##answer_' . $question_line['id'] . '##'; diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index 130e88406..464cc40c8 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -938,12 +938,12 @@ function change_tag_type() { /** * Parse target content to replace TAGS like ##FULLFORM## by the values * - * @param String $content String to be parsed + * @param string $content String to be parsed * @param PluginFormcreatorForm_Answer $formanswer Formanswer object where answers are stored - * @param String full form - * @return String Parsed string with tags replaced by form values + * @param boolean $richText Disable rich text mode for field rendering + * @return string Parsed string with tags replaced by form values */ - protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer, $fullform = "") { + protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer, $richText = false) { global $DB, $CFG_GLPI; // retrieve answers @@ -972,7 +972,7 @@ protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer, $value = ''; } else { $name = $question->getField('name'); - $value = $fields[$questionId]->getValueForTargetText($disableRichText); + $value = $fields[$questionId]->getValueForTargetText($richText); } $content = str_replace('##question_' . $questionId . '##', Toolbox::addslashes_deep($name), $content); @@ -980,15 +980,7 @@ protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer, foreach ($fields[$questionId]->getDocumentsForTarget() as $documentId) { $this->addAttachedDocument($documentId); } - if ($question->getField('fieldtype') !== 'file') { - if (is_array($value)) { - if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { - $value = '
' . implode('
', $value); - } else { - $value = "\r\n" . implode("\r\n", $value); - } - } - } else { + if ($question->getField('fieldtype') === 'file') { if (strpos($content, '##answer_' . $questionId . '##') !== false) { if (!is_array($value)) { $value = [$value]; diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index 8962ede41..b0e538794 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -969,21 +969,10 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { $data[$changeField] = $this->fields[$changeField]; $data[$changeField] = str_replace("\r\n", '\r\n', $data[$changeField]); if (strpos($data[$changeField], '##FULLFORM##') !== false) { - $data[$changeField] = str_replace('##FULLFORM##', $formanswer->getFullForm(true), $data[$changeField]); - } - if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { - // replace HTML P tags with DIV tags - $data[$changeField] = str_replace('\r\n', "\r\n", $data[$changeField]); + $data[$changeField] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data[$changeField]); } $data[$changeField] = $this->parseTags($data[$changeField], $formanswer); - - // This target does not supports rich text - $data[$changeField] = str_replace('
', '\r\n', $data[$changeField]); - $data[$changeField] = strip_tags($data[$changeField], '

'); - $data[$changeField] = str_replace('

', '', $data[$changeField]); - $data[$changeField] = str_replace('

', '\r\n', $data[$changeField]); - $data[$changeField] = Toolbox::addslashes_deep($data[$changeField]); } $data['_users_id_recipient'] = $_SESSION['glpiID']; diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index ab3b18e45..cc443e4f5 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -1088,11 +1088,12 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { unset($predefined_fields['_groups_id_assign']); } - $data = array_merge($data, $predefined_fields); + $data = array_merge($data, $predefined_fields); // Parse data // TODO: generate instances of all answers of the form and use them for the fullform computation // and the computation from a admin-defined target ticket template + $richText = version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']; $data['name'] = $this->fields['name']; $data['name'] = $this->parseTags($data['name'], $formanswer); $data['name'] = Toolbox::addslashes_deep($data['name']); @@ -1100,15 +1101,15 @@ public function save(PluginFormcreatorForm_Answer $formanswer) { $data['content'] = $this->fields['content']; $data['content'] = str_replace("\r\n", '\r\n', $data['content']); if (strpos($data['content'], '##FULLFORM##') !== false) { - $data['content'] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data['content']); + $data['content'] = str_replace('##FULLFORM##', $formanswer->getFullForm($richText), $data['content']); } - if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { + if ($richText) { // replace HTML P tags with DIV tags $data['content'] = str_replace(['

', '

'], ['
', '
'], $data['content']); } - $data['content'] = $this->parseTags($data['content'], $formanswer); - if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) { + $data['content'] = $this->parseTags($data['content'], $formanswer, $richText); + if ($richText) { $data['content'] = htmlentities($data['content'], ENT_NOQUOTES); } $data['content'] = Toolbox::addslashes_deep($data['content']); diff --git a/tests/suite-unit/PluginFormcreatorActorField.php b/tests/suite-unit/PluginFormcreatorActorField.php index 710afeaab..dba6f9c19 100644 --- a/tests/suite-unit/PluginFormcreatorActorField.php +++ b/tests/suite-unit/PluginFormcreatorActorField.php @@ -176,15 +176,15 @@ public function providerDeserializeValue() { ], [ 'value' => json_encode(["$glpiId"]), - 'expected' => [$glpiId], + 'expected' => ['glpi'], ], [ 'value' => json_encode(["$glpiId","$normalId"]), - 'expected' => [$glpiId, $normalId], + 'expected' => ['glpi', 'normal'], ], [ 'value' => json_encode(["$glpiId","$normalId","user@localhost.local"]), - 'expected' => [$glpiId, $normalId, 'user@localhost.local'], + 'expected' => ['glpi', 'normal', 'user@localhost.local'], ], [ 'value' => json_encode(["user@localhost.local"]), @@ -199,10 +199,8 @@ public function providerDeserializeValue() { public function testDeserializeValue($value, $expected) { $instance = new \PluginFormcreatorActorField([]); $instance->deserializeValue($value); - $output = $instance->getValueForTargetField(); - $this->array($output) - ->hasSize(count($expected)) - ->containsValues($expected); + $output = $instance->getValueForTargetText(false); + $this->string($output)->isEqualTo(implode(', ', $expected)); } public function providerGetValueForDesign() { diff --git a/tests/suite-unit/PluginFormcreatorDatetimeField.php b/tests/suite-unit/PluginFormcreatorDatetimeField.php index 0c87137c9..8fdb839c9 100644 --- a/tests/suite-unit/PluginFormcreatorDatetimeField.php +++ b/tests/suite-unit/PluginFormcreatorDatetimeField.php @@ -149,25 +149,23 @@ public function testGetName() { $this->string($output)->isEqualTo('Date & time'); } - public function providerparseAnswerValue() { + public function providerparseAnswerValues() { return [ [ 'id' => '1', 'input' => [ 'formcreator_field_1' => '' ], - 'expected' => true, + 'expected' => false, 'expectedValue' => null, ], [ 'id' => '1', 'input' => [ - 'formcreator_field_1' => [ - 'glpi' - ] + 'formcreator_field_1' => '2018-12-25 23:00', ], - 'expected' => false, - 'expectedValue' => [2], + 'expected' => true, + 'expectedValue' => '2018-12-25 23:00', ], ]; } @@ -175,7 +173,7 @@ public function providerparseAnswerValue() { /** * Undocumented function * - * @dataProvider providerparseAnswerValue + * @dataProvider providerparseAnswerValues * * @param [type] $id * @param [type] $input @@ -186,10 +184,9 @@ public function providerparseAnswerValue() { public function testParseAnswerValues($id, $input, $expected, $expectedValue) { $instance = $this->newTestedInstance(['id' => $id]); $output = $instance->parseAnswerValues($input); - - $outputValue = $instance->getValueForTargetField(); $this->boolean($output)->isEqualTo($expected); - $outputValue = $instance->getValueForTargetField(); + + $outputValue = $instance->getValueForTargetText(false); if ($expected === false) { $this->variable($outputValue)->isNull(); } else { @@ -217,4 +214,4 @@ public function testIsAnonymousFormCompatible() { $output = $instance->isAnonymousFormCompatible(); $this->boolean($output)->isTrue(); } -} \ No newline at end of file +} From ce7444f47644f48058cc7fdf790cf488cb33d0e7 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 13 Nov 2018 11:31:38 +0100 Subject: [PATCH 171/192] fix(QuestionCondition): inconsistency in selectors Signed-off-by: Thierry Bugier --- inc/field.class.php | 2 +- inc/fields.class.php | 23 +++++++++++------------ js/scripts.js.php | 15 ++++++++------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/inc/field.class.php b/inc/field.class.php index ae6ae4c48..1795fdd86 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -70,7 +70,7 @@ public function getValueForTarget() { public function show($canEdit = true) { $required = ($canEdit && $this->fields['required']) ? ' required' : ''; - echo '
'; + echo '
'; echo '
'; diff --git a/inc/issue.class.php b/inc/issue.class.php index 9186b087d..c684b26de 100644 --- a/inc/issue.class.php +++ b/inc/issue.class.php @@ -69,8 +69,8 @@ public static function cronSyncIssues(CronTask $task) { $volume = 0; // Request which merges tickets and formanswers - // 1 ticket not linked to a form_answer => 1 issue which is the ticket sub_itemtype - // 1 form_answer not linked to a ticket => 1 issue which is the form_answer sub_itemtype + // 1 ticket not linked to a formanswer => 1 issue which is the ticket sub_itemtype + // 1 form_answer not linked to a ticket => 1 issue which is the formanswer sub_itemtype // 1 ticket linked to 1 form_answer => 1 issue which is the ticket sub_itemtype // several tickets linked to the same form_answer => 1 issue which is the form_answer sub_itemtype $query = "SELECT DISTINCT diff --git a/inc/notificationtargetform_answer.class.php b/inc/notificationtargetformanswer.class.php similarity index 96% rename from inc/notificationtargetform_answer.class.php rename to inc/notificationtargetformanswer.class.php index 8c3ddaa4f..8c6001be0 100644 --- a/inc/notificationtargetform_answer.class.php +++ b/inc/notificationtargetformanswer.class.php @@ -35,7 +35,7 @@ die("Sorry. You can't access this file directly"); } -class PluginFormcreatorNotificationTargetForm_answer extends NotificationTarget +class PluginFormcreatorNotificationTargetFormAnswer extends NotificationTarget { const AUTHOR = 101; const APPROVER = 102; @@ -57,7 +57,7 @@ public function addDataForTemplate($event, $options = []) { $form = new PluginFormcreatorForm(); $form->getFromDB($this->obj->fields['plugin_formcreator_forms_id']); $link = $CFG_GLPI['url_base']; - $link .= '/plugins/formcreator/front/form_answer.form.php?id=' . $this->obj->getID(); + $link .= '/plugins/formcreator/front/formanswer.form.php?id=' . $this->obj->getID(); $requester = new User(); $requester->getFromDB($this->obj->fields['requester_id']); diff --git a/install/install.php b/install/install.php index 15e5e8b26..b3491a331 100644 --- a/install/install.php +++ b/install/install.php @@ -292,31 +292,31 @@ protected function createNotifications() { 'name' => __('A form has been created', 'formcreator'), 'subject' => __('Your request has been saved', 'formcreator'), 'content' => __('Hi,\nYour request from GLPI has been successfully saved with number ##formcreator.request_id## and transmitted to the helpdesk team.\nYou can see your answers onto the following link:\n##formcreator.validation_link##', 'formcreator'), - 'notified' => PluginFormcreatorNotificationTargetForm_answer::AUTHOR, + 'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR, ], 'plugin_formcreator_need_validation' => [ 'name' => __('A form need to be validate', 'formcreator'), 'subject' => __('A form from GLPI need to be validate', 'formcreator'), 'content' => __('Hi,\nA form from GLPI need to be validate and you have been choosen as the validator.\nYou can access it by clicking onto this link:\n##formcreator.validation_link##', 'formcreator'), - 'notified' => PluginFormcreatorNotificationTargetForm_answer::APPROVER, + 'notified' => PluginFormcreatorNotificationTargetFormAnswer::APPROVER, ], 'plugin_formcreator_refused' => [ 'name' => __('The form is refused', 'formcreator'), 'subject' => __('Your form has been refused by the validator', 'formcreator'), 'content' => __('Hi,\nWe are sorry to inform you that your form has been refused by the validator for the reason below:\n##formcreator.validation_comment##\n\nYou can still modify and resubmit it by clicking onto this link:\n##formcreator.validation_link##', 'formcreator'), - 'notified' => PluginFormcreatorNotificationTargetForm_answer::AUTHOR, + 'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR, ], 'plugin_formcreator_accepted' => [ 'name' => __('The form is accepted', 'formcreator'), 'subject' => __('Your form has been accepted by the validator', 'formcreator'), 'content' => __('Hi,\nWe are pleased to inform you that your form has been accepted by the validator.\nYour request will be considered soon.', 'formcreator'), - 'notified' => PluginFormcreatorNotificationTargetForm_answer::AUTHOR, + 'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR, ], 'plugin_formcreator_deleted' => [ 'name' => __('The form is deleted', 'formcreator'), 'subject' => __('Your form has been deleted by an administrator', 'formcreator'), 'content' => __('Hi,\nWe are sorry to inform you that your request cannot be considered and has been deleted by an administrator.', 'formcreator'), - 'notified' => PluginFormcreatorNotificationTargetForm_answer::AUTHOR, + 'notified' => PluginFormcreatorNotificationTargetFormAnswer::AUTHOR, ], ]; diff --git a/install/upgrade_to_2.7.php b/install/upgrade_to_2.7.php index 7439f63a3..15d05eb0e 100644 --- a/install/upgrade_to_2.7.php +++ b/install/upgrade_to_2.7.php @@ -40,25 +40,62 @@ public function upgrade(Migration $migration) { $displayPreference = new DisplayPreference(); $DB->update( 'glpi_displaypreferences', [ - 'itemtype' => 'PluginFormcreatorFormAnswer', + 'itemtype' => 'PluginFormcreatorFormAnswer', ], [ 'itemtype' => 'PluginFormcreatorForm_Answer' ] ); $DB->update( 'glpi_items_tickets', [ - 'itemtype' => 'PluginFormcreatorFormAnswer', + 'itemtype' => 'PluginFormcreatorFormAnswer', + ], [ + 'itemtype' => 'PluginFormcreatorForm_Answer' + ] + ); + $DB->update( + 'glpi_notifications', [ + 'itemtype' => 'PluginFormcreatorFormAnswer', + ], [ + 'itemtype' => 'PluginFormcreatorForm_Answer' + ] + ); + $DB->update( + 'glpi_notificationtemplates', [ + 'itemtype' => 'PluginFormcreatorFormAnswer', ], [ 'itemtype' => 'PluginFormcreatorForm_Answer' ] ); $DB->update( 'glpi_queuednotifications', [ - 'itemtype' => 'PluginFormcreatorFormAnswer', + 'itemtype' => 'PluginFormcreatorFormAnswer', ], [ 'itemtype' => 'PluginFormcreatorForm_Answer' ] ); + $DB->update( + 'glpi_plugin_formcreator_issues', [ + 'sub_itemtype' => 'PluginFormcreatorFormAnswer', + ], [ + 'sub_itemtype' => 'PluginFormcreatorForm_Answer' + ] + ); + if (false && isCommandLine()) { + $DB->update( + 'glpi_logs', [ + 'itemtype_link' => 'PluginFormcreatorFormAnswer', + ], [ + 'itemtype_link' => 'PluginFormcreatorForm_Answer' + ] + ); + $DB->update( + 'glpi_logs', [ + 'itemtype' => 'PluginFormcreatorFormAnswer', + ], [ + 'itemtype' => 'PluginFormcreatorForm_Answer' + ] + ); + } $table = 'glpi_plugin_formcreator_formanswers'; $migration->renameTable('glpi_plugin_formcreator_forms_answers', $table); $table = 'glpi_plugin_formcreator_answers'; From 7d7b1701b6089a7d490526e587bbcafac72591dd Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Fri, 23 Nov 2018 22:07:45 +0100 Subject: [PATCH 180/192] style(install): fix code style Signed-off-by: Thierry Bugier --- install/install.php | 10 +++++++++- install/upgrade_to_2.5.php | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/install/install.php b/install/install.php index b3491a331..30dba88de 100644 --- a/install/install.php +++ b/install/install.php @@ -46,9 +46,17 @@ class PluginFormcreatorInstall { * Exemple: an entry '2.0' => '2.1' tells that versions 2.0 * are upgradable to 2.1 * + * When posible avoid schema upgrade between bugfix releases. The schema + * version iscontains major.minor numbers only. If an upgrade of the schema + * occurs between bugfix releases, then the upgrade will start from the + * major.minor.0 version up to the end of the the versions list. + * Exemple: if previous version is 2.6.1 and current code is 2.6.3 then + * the upgrade will start from 2.6.0 to 2.6.3 and replay schema changes + * between 2.6.0 and 2.6.1. This means that upgrade must be _repeatable_. + * * @var array */ - private $upgradeSteps = [ + private $upgradeSteps = [ '0.0' => '2.5', '2.5' => '2.6', '2.6' => '2.6.1', diff --git a/install/upgrade_to_2.5.php b/install/upgrade_to_2.5.php index 731e32d77..375a4adb6 100644 --- a/install/upgrade_to_2.5.php +++ b/install/upgrade_to_2.5.php @@ -39,7 +39,7 @@ class PluginFormcreatorUpgradeTo2_5 { /** * @param Migration $migration */ - public function upgrade(Migration $migration) { + public function upgrade(Migration $migration) { global $DB; $migration->displayMessage("Upgrade to schema version 2.5"); From 0c75a69d5f848c1d4612b1da9ade7531666cf288 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 27 Nov 2018 10:05:16 +0100 Subject: [PATCH 181/192] fix(fields): fields not hidden correctly Signed-off-by: Thierry Bugier --- js/scripts.js.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/js/scripts.js.php b/js/scripts.js.php index 1a21e00af..c063b2c33 100644 --- a/js/scripts.js.php +++ b/js/scripts.js.php @@ -582,8 +582,6 @@ function deleteTarget(items_id, token, target_id) { var formcreatorQuestions = new Object(); function formcreatorShowFields(form) { - //var form = $(field[0].form); - $.ajax({ url: '../ajax/showfields.php', type: "POST", @@ -600,14 +598,14 @@ function formcreatorShowFields(form) { questionId = parseInt(questionKey.replace('formcreator_field_', '')); if (!isNaN(questionId)) { if (questionToShow[questionKey]) { - $('#form-group-field' + questionKey).show(); + $('#form-group-field-' + questionKey).show(); i++; - $('#form-group-field' + questionKey).removeClass('line' + (i+1) % 2); - $('#form-group-field' + questionKey).addClass('line' + i%2); + $('#form-group-field-' + questionKey).removeClass('line' + (i+1) % 2); + $('#form-group-field-' + questionKey).addClass('line' + i%2); } else { - $('#form-group-field' + questionKey).hide(); - $('#form-group-field' + questionKey).removeClass('line0'); - $('#form-group-field' + questionKey).removeClass('line1'); + $('#form-group-field-' + questionKey).hide(); + $('#form-group-field-' + questionKey).removeClass('line0'); + $('#form-group-field-' + questionKey).removeClass('line1'); } } } From 87cc394ab5ded8277483531d6b7fb6f87986ab7d Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 27 Nov 2018 17:46:08 +0100 Subject: [PATCH 182/192] fix(formanswer): show/hide questions in various cases Signed-off-by: Thierry Bugier --- inc/fields.class.php | 2 +- inc/fields/textfield.class.php | 3 +++ inc/form.class.php | 4 ++-- inc/formanswer.class.php | 28 ++++++++++++++++++---------- js/scripts.js.php | 2 +- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/inc/fields.class.php b/inc/fields.class.php index 986465156..aed85072e 100644 --- a/inc/fields.class.php +++ b/inc/fields.class.php @@ -326,7 +326,7 @@ public static function updateVisibility($input) { $fields[$id] = PluginFormcreatorFields::getFieldInstance( $question->fields['fieldtype'], $question - ); + ); $fields[$id]->parseAnswerValues($input); } diff --git a/inc/fields/textfield.class.php b/inc/fields/textfield.class.php index c8c383744..e6d606963 100644 --- a/inc/fields/textfield.class.php +++ b/inc/fields/textfield.class.php @@ -181,6 +181,9 @@ public static function getJSFields() { public function parseAnswerValues($input) { $key = 'formcreator_field_' . $this->fields['id']; + if (!isset($input[$key])) { + return false; + } if (!is_string($input[$key])) { return false; } diff --git a/inc/form.class.php b/inc/form.class.php index f5cd690cc..b808b0596 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -920,7 +920,7 @@ public function displayUserForm() { // Display form $formName = 'formcreator_form' . $this->getID(); - echo "
"; echo "

"; @@ -966,7 +966,7 @@ class='formcreator_form form_horizontal'>"; } } echo Html::scriptBlock('$(function() { - formcreatorShowFields($("form[name=\'' . $formName . '\']")); + formcreatorShowFields($("form[name=\'form\']")); })'); // Show validator selector diff --git a/inc/formanswer.class.php b/inc/formanswer.class.php index 2b587bf6c..433b9d4b2 100644 --- a/inc/formanswer.class.php +++ b/inc/formanswer.class.php @@ -537,7 +537,18 @@ public function showForm($ID, $options = []) { $questions = $DB->request($request); $last_section = ''; $questionsCount = $questions->count(); + $fields = []; while ($question_line = $questions->next()) { + $question = new PluginFormcreatorQuestion(); + $question->getFromDB($question_line['id']); + $fields[$question_line['id']] = PluginFormcreatorFields::getFieldInstance( + $question_line['fieldtype'], + $question + ); + $fields[$question_line['id']]->deserializeValue($question_line['answer']); + } + $questions->rewind(); + while ($question_line = $questions->current()) { // Get and display current section if needed if ($last_section != $question_line['section_name']) { echo '

'.$question_line['section_name'].'

'; @@ -548,19 +559,14 @@ public function showForm($ID, $options = []) { || ($question_line['fieldtype'] != "description" && $question_line['fieldtype'] != "hidden") ) { - $question = new PluginFormcreatorQuestion(); - $question->getFromDB($question_line['id']); - $field = PluginFormcreatorFields::getFieldInstance( - $question_line['fieldtype'], - $question - ); - $field->deserializeValue($question_line['answer']); - $field->show($canEdit); + // if (PluginFormcreatorFields::isVisible($question_line['id'], $fields)) { + // } + $fields[$question_line['id']]->show($canEdit); } + $questions->next(); } - $formName = 'formcreator_form' . $formId; echo Html::scriptBlock('$(function() { - formcreatorShowFields($("form[name=\'' . $formName . '\']")); + formcreatorShowFields($("form[name=\'form\']")); })'); //add requester info @@ -599,6 +605,8 @@ public function showForm($ID, $options = []) { echo ''; echo '
'; echo '
'; + $options['canedit'] = true; + $options['candel'] = false; } } diff --git a/js/scripts.js.php b/js/scripts.js.php index c063b2c33..f79980262 100644 --- a/js/scripts.js.php +++ b/js/scripts.js.php @@ -583,7 +583,7 @@ function deleteTarget(items_id, token, target_id) { function formcreatorShowFields(form) { $.ajax({ - url: '../ajax/showfields.php', + url: rootDoc + '/plugins/formcreator/ajax/showfields.php', type: "POST", data: form.serializeArray() }).done(function(response){ From d3e5bcb7fdda002152ecda3eb236f32d8a4ef1f7 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Wed, 28 Nov 2018 12:07:51 +0100 Subject: [PATCH 183/192] refactor(formanswer): duplicated code and cleanup Signed-off-by: Thierry Bugier --- inc/formanswer.class.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/inc/formanswer.class.php b/inc/formanswer.class.php index 433b9d4b2..c92d8cf09 100644 --- a/inc/formanswer.class.php +++ b/inc/formanswer.class.php @@ -975,14 +975,14 @@ public function refuseAnswers($data) { $form = new PluginFormcreatorForm(); $form->getFromDB((int) $data['formcreator_form']); - $fields = []; // Prepare form fields for validation - $question = new PluginFormcreatorQuestion(); if (!$this->canValidate($form, $this)) { Session::addMessageAfterRedirect(__('You are not the validator of these answers', 'formcreator'), true, ERROR); return false; } + $fields = []; + $question = new PluginFormcreatorQuestion(); $found_questions = $question->getQuestionsFromForm($this->getID()); foreach ($found_questions as $id => $question) { $fields[$id] = PluginFormcreatorFields::getFieldInstance( @@ -1008,19 +1008,14 @@ public function acceptAnswers($data) { $form = new PluginFormcreatorForm(); $form->getFromDB((int) $data['formcreator_form']); + // Prepare form fields for validation if (!$this->canValidate($form, $this)) { Session::addMessageAfterRedirect(__('You are not the validator of these answers', 'formcreator'), true, ERROR); return false; } $fields = []; - // Prepare form fields for validation $question = new PluginFormcreatorQuestion(); - if (!$this->canValidate($form, $this)) { - Session::addMessageAfterRedirect(__('You are not the validator of these answers', 'formcreator'), true, ERROR); - return false; - } - $found_questions = $question->getQuestionsFromForm($this->getID()); foreach ($found_questions as $id => $question) { $fields[$id] = PluginFormcreatorFields::getFieldInstance( From 9649c52b9f44e283a8844adcd7bbce1bc1ced34f Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Wed, 28 Nov 2018 18:29:12 +0100 Subject: [PATCH 184/192] fix(formanwer): various bugs - not loaded from DB - code refactor - update of answers Signed-off-by: Thierry Bugier --- inc/formanswer.class.php | 68 +++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/inc/formanswer.class.php b/inc/formanswer.class.php index c92d8cf09..58f194405 100644 --- a/inc/formanswer.class.php +++ b/inc/formanswer.class.php @@ -685,8 +685,6 @@ public function pre_deleteItem() { * @return boolean */ public function saveAnswers(PluginFormcreatorForm $form, $data, $fields) { - $answer = new PluginFormcreatorAnswer(); - $formanswers_id = isset($data['id']) ? intval($data['id']) : -1; @@ -694,17 +692,6 @@ public function saveAnswers(PluginFormcreatorForm $form, $data, $fields) { $question = new PluginFormcreatorQuestion(); $questions = $question->getQuestionsFromForm($form->getID()); - //Collect answers - $answer_value = []; - foreach ($questions as $questionId => $question) { - if (!isset($data['formcreator_field_' . $questionId])) { - $answer_value[$questionId] = ''; - } else { - $answer_value[$questionId] = $fields[$questionId] - ->serializeValue($data['formcreator_field_' . $questionId]); - } - } - // Update form answers if (isset($data['save_formanswer'])) { $status = $data['status']; @@ -717,9 +704,15 @@ public function saveAnswers(PluginFormcreatorForm $form, $data, $fields) { // Update questions answers if ($status == 'waiting') { foreach ($questions as $questionId => $question) { + $answer = new PluginFormcreatorAnswer(); + $answer->getFromDBByCrit([ + 'plugin_formcreator_formanswers_id' => $formanswers_id, + 'plugin_formcreator_questions_id' => $questionId, + ]); $answer->update([ + 'id' => $answer->getID(), - 'answer' => $answer_value[$questionId], + 'answer' => $fields[$questionId]->serializeValue(), ], 0); } } @@ -767,10 +760,11 @@ public function saveAnswers(PluginFormcreatorForm $form, $data, $fields) { // Save questions answers foreach ($questions as $questionId => $question) { + $answer = new PluginFormcreatorAnswer(); $answer->add([ 'plugin_formcreator_formanswers_id' => $id, - 'plugin_formcreator_questions_id' => $question->getID(), - 'answer' => $answer_value[$questionId], + 'plugin_formcreator_questions_id' => $question->getID(), + 'answer' => $fields[$questionId]->serializeValue(), ], [], 0); foreach ($fields[$questionId]->getDocumentsForTarget() as $documentId) { $docItem = new Document_Item(); @@ -933,7 +927,7 @@ public function saveAnswers(PluginFormcreatorForm $form, $data, $fields) { if ($is_newFormAnswer) { return $id; } else { - return $formAnswerId; + return $this->getID(); } } @@ -945,18 +939,20 @@ public function saveAnswers(PluginFormcreatorForm $form, $data, $fields) { */ public function updateAnswers($input) { $form = new PluginFormcreatorForm(); - $form->getID((int) $_POST['formcreator_form']); + $form->getFromDB((int) $_POST['formcreator_form']); $input['status'] = 'waiting'; - $fields = []; + // Prepare form fields for validation - $question = new PluginFormcreatorQuestion(); - $found_questions = $question->getQuestionsFromForm($this->getID()); + $fields = []; + $question = new PluginFormcreatorQuestion(); + $found_questions = $question->getQuestionsFromForm($form->getID()); foreach ($found_questions as $id => $question) { $fields[$id] = PluginFormcreatorFields::getFieldInstance( $question->fields['fieldtype'], $question ); + $fields[$id]->parseAnswerValues($input); } $this->saveAnswers($form, $input, $fields); } @@ -964,16 +960,16 @@ public function updateAnswers($input) { /** * Mark answers of a form as refused * - * @param array $data + * @param array $input * * @return boolean */ - public function refuseAnswers($data) { - $data['status'] = 'refused'; - $data['save_formanswer'] = true; + public function refuseAnswers($input) { + $input['status'] = 'refused'; + $input['save_formanswer'] = true; $form = new PluginFormcreatorForm(); - $form->getFromDB((int) $data['formcreator_form']); + $form->getFromDB((int) $input['formcreator_form']); // Prepare form fields for validation if (!$this->canValidate($form, $this)) { @@ -983,30 +979,31 @@ public function refuseAnswers($data) { $fields = []; $question = new PluginFormcreatorQuestion(); - $found_questions = $question->getQuestionsFromForm($this->getID()); + $found_questions = $question->getQuestionsFromForm($form->getID()); foreach ($found_questions as $id => $question) { $fields[$id] = PluginFormcreatorFields::getFieldInstance( $question->fields['fieldtype'], $question ); + $fields[$id]->parseAnswerValues($input); } - return $this->saveAnswers($form, $data, $fields); + return $this->saveAnswers($form, $input, $fields); } /** * Mark answers of a form as accepted * - * @param array $data + * @param array $input * * @return boolean */ - public function acceptAnswers($data) { - $data['status'] = 'accepted'; - $data['save_formanswer'] = true; + public function acceptAnswers($input) { + $input['status'] = 'accepted'; + $input['save_formanswer'] = true; $form = new PluginFormcreatorForm(); - $form->getFromDB((int) $data['formcreator_form']); + $form->getFromDB((int) $input['formcreator_form']); // Prepare form fields for validation if (!$this->canValidate($form, $this)) { @@ -1016,15 +1013,16 @@ public function acceptAnswers($data) { $fields = []; $question = new PluginFormcreatorQuestion(); - $found_questions = $question->getQuestionsFromForm($this->getID()); + $found_questions = $question->getQuestionsFromForm($form->getID()); foreach ($found_questions as $id => $question) { $fields[$id] = PluginFormcreatorFields::getFieldInstance( $question->fields['fieldtype'], $question ); + $fields[$id]->parseAnswerValues($input); } - return $this->saveAnswers($form, $data, $fields); + return $this->saveAnswers($form, $input, $fields); } /** From ecaaa3fdd758bb46733e70c1adef0af975af6e02 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Thu, 29 Nov 2018 11:54:56 +0100 Subject: [PATCH 185/192] feat(form_answer): add search option closes: #1220 Signed-off-by: Thierry Bugier --- inc/form_answer.class.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/inc/form_answer.class.php b/inc/form_answer.class.php index eab272915..a508ba165 100644 --- a/inc/form_answer.class.php +++ b/inc/form_answer.class.php @@ -228,6 +228,16 @@ public function rawSearchOptions() { 'massiveaction' => false ]; + $tab[] = [ + 'id' => '9', + 'table' => PluginFormcreatorForm::getTable(), + 'field' => 'id', + 'name' => __('ID'), + 'searchtype' => 'contains', + 'datatype' => 'integer', + 'massiveaction' => false, + ]; + if ($display_for_form) { $optindex = self::SOPTION_ANSWER; $question = new PluginFormcreatorQuestion; From 9a28a61d09c787cee7a7c89c04379d0d998db9e4 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Mon, 3 Dec 2018 17:12:37 +0100 Subject: [PATCH 186/192] feat(dropdown): choose a root ticket category for display Signed-off-by: Thierry Bugier --- inc/fields/dropdownfield.class.php | 12 +++++++ inc/question.class.php | 34 ++++++++++++++++--- .../PluginFormcreatorDropdownField.php | 1 + 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index 281da1f70..beff4e2c9 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -92,6 +92,15 @@ public function displayField($canEdit = true) { && $decodedValues['show_ticket_categories_depth'] > 0) { $dparams['condition'] .= " AND `level` <= '" . $decodedValues['show_ticket_categories_depth'] . "'"; } + if (isset($decodedValues['show_ticket_categories_root']) + && (int) $decodedValues['show_ticket_categories_root'] > 0) { + $sons = (new DBUtils)->getSonsOf( + ItilCategory::getTable(), + $decodedValues['show_ticket_categories_root'] + ); + $sons = "'" . implode("', '", $sons) . "'"; + $dparams['condition'] .= " AND `id` IN ('" . $decodedValues['show_ticket_categories_root'] . "')"; + } break; default: @@ -219,6 +228,9 @@ public function prepareQuestionInputForSave($input) { } else { $input['values']['show_ticket_categories_depth'] = $input['show_ticket_categories_depth']; } + $input['values']['show_ticket_categories_root'] = isset($input['show_ticket_categories_root']) + ? $input['show_ticket_categories_root'] + : ''; } $input['values'] = json_encode($input['values']); unset($input['show_ticket_categories']); diff --git a/inc/question.class.php b/inc/question.class.php index 858b91f02..2a255fdef 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -965,6 +965,29 @@ function plugin_formcreator_hideAllParameters() { echo ''; echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + $decodedValue = json_decode($this->fields['values'], JSON_OBJECT_AS_ARRAY); + $rootValue = isset($decodedValue['show_ticket_categories_root']) + ? $decodedValue['show_ticket_categories_root'] + : Dropdown::EMPTY_VALUE; + Dropdown::show(ITILCategory::class, [ + 'name' => 'show_ticket_categories_root', + 'value' => $rootValue, + 'rand' => $rand, + ]); + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; echo ''; echo '