diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index d5f7ba2ed..ba48288d3 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -1189,7 +1189,7 @@ protected function showAssociateSettings($rand) { * @return array */ protected function setTargetAssociatedItem(array $data, PluginFormcreatorFormAnswer $formanswer) : array { - global $DB, $CFG_GLPI; + global $DB; switch ($this->fields['associate_rule']) { case self::ASSOCIATE_RULE_ANSWER: @@ -1265,6 +1265,7 @@ protected function setTargetAssociatedItem(array $data, PluginFormcreatorFormAns ] ]); + $valid_associated_itemtypes = $_SESSION["glpiactiveprofile"]["helpdesk_item_type"]; foreach ($answers as $answer) { // Skip if the object type is not valid asset type $question = new PluginFormcreatorQuestion(); @@ -1273,7 +1274,7 @@ protected function setTargetAssociatedItem(array $data, PluginFormcreatorFormAns $field = $question->getSubField(); $field->deserializeValue($answer['answer']); $itemtype = $field->getSubItemtype(); - if (!in_array($itemtype, $CFG_GLPI['asset_types'])) { + if (!in_array($itemtype, $valid_associated_itemtypes)) { continue; } diff --git a/tests/3-unit/PluginFormcreatorTargetTicket.php b/tests/3-unit/PluginFormcreatorTargetTicket.php index f2e2c1773..9e8dbfdfe 100644 --- a/tests/3-unit/PluginFormcreatorTargetTicket.php +++ b/tests/3-unit/PluginFormcreatorTargetTicket.php @@ -1064,17 +1064,15 @@ public function providerSetTargetAssociatedItem_1() { } public function providerSetTargetAssociatedItem_LastItem() { - global $CFG_GLPI; - // Prepare form - $validItemtype = $CFG_GLPI["asset_types"][0]; - if (array_search(Computer::getType(), $CFG_GLPI['asset_types']) === false) { - $CFG_GLPI['asset_types'][] = Computer::getType(); + $validItemtype = $_SESSION["glpiactiveprofile"]["helpdesk_item_type"][0]; + if (array_search(Computer::getType(), $_SESSION["glpiactiveprofile"]["helpdesk_item_type"]) === false) { + $_SESSION["glpiactiveprofile"]["helpdesk_item_type"][] = Computer::getType(); } $invalidItemtype = Monitor::getType(); // Ensure an itemtype is not in the asset types - $CFG_GLPI['asset_types'] = array_filter($CFG_GLPI['asset_types'], function ($itemtype) use ($invalidItemtype) { + $_SESSION["glpiactiveprofile"]["helpdesk_item_type"] = array_filter($_SESSION["glpiactiveprofile"]["helpdesk_item_type"], function ($itemtype) use ($invalidItemtype) { return ($itemtype != $invalidItemtype); }); @@ -1384,7 +1382,7 @@ public function providerSetTargetLocation_NotSet() { $form1 = $this->getForm(); - $instance1 = new PluginFormcreatorTargetTicket(); + $instance1 = $this->newTestedInstance(); $instance1->add([ 'name' => 'foo', 'target_name' => '', @@ -1438,7 +1436,7 @@ public function providerSetTargetLocation_LastItem() { 'fieldtype' => 'dropdown', 'itemtype' => $validItemtype ]); - $instance1 = new PluginFormcreatorTargetTicket(); + $instance1 = $this->newTestedInstance(); $instance1->add([ 'name' => 'foo', 'target_name' => '',