diff --git a/inc/abstractitiltarget.class.php b/inc/abstractitiltarget.class.php
index b4ea4327d..ed6e8639e 100644
--- a/inc/abstractitiltarget.class.php
+++ b/inc/abstractitiltarget.class.php
@@ -161,6 +161,11 @@ abstract protected function getTargetTemplate(array $data): int;
const LOCATION_RULE_ANSWER = 3;
const LOCATION_RULE_LAST_ANSWER = 4;
+ const CONTRACT_RULE_NONE = 1;
+ const CONTRACT_RULE_SPECIFIC = 2;
+ const CONTRACT_RULE_ANSWER = 3;
+ const CONTRACT_RULE_LAST_ANSWER = 4;
+
const COMMONITIL_VALIDATION_RULE_NONE = 1;
const COMMONITIL_VALIDATION_RULE_SPECIFIC_USER_OR_GROUP = 2;
const COMMONITIL_VALIDATION_RULE_ANSWER_USER = 3;
@@ -235,6 +240,15 @@ public static function getEnumLocationRule() {
];
}
+ public static function getEnumContractRule() {
+ return [
+ self::CONTRACT_RULE_NONE => __('Contract from template or none', 'formcreator'),
+ self::CONTRACT_RULE_SPECIFIC => __('Specific contract', 'formcreator'),
+ self::CONTRACT_RULE_ANSWER => __('Equals to the answer to the question', 'formcreator'),
+ self::CONTRACT_RULE_LAST_ANSWER => __('Last valid answer', 'formcreator'),
+ ];
+ }
+
public static function getEnumValidationRule() {
return [
self::COMMONITIL_VALIDATION_RULE_NONE => __('No validation', 'formcreator'),
@@ -1263,6 +1277,48 @@ protected function showLocationSettings($rand) {
echo '';
}
+ protected function showContractSettings($rand) {
+ global $DB;
+
+ echo '
';
+ echo '| ' . __('Contract') . ' | ';
+ echo '';
+ Dropdown::showFromArray('contract_rule', static::getEnumContractRule(), [
+ 'value' => $this->fields['contract_rule'],
+ 'on_change' => "plugin_formcreator_change_contract($rand)",
+ 'rand' => $rand
+ ]);
+
+ echo Html::scriptBlock("plugin_formcreator_change_contract($rand)");
+ echo ' | ';
+ echo '';
+ echo '' . __('Question', 'formcreator') . '';
+ echo '' . __('Contract ', 'formcreator') . '';
+ echo ' | ';
+ echo '';
+
+ echo ' ';
+ Contract::dropdown([
+ 'name' => '_contract_specific',
+ 'value' => $this->fields["contract_question"],
+ ]);
+ echo ' ';
+ echo '';
+ PluginFormcreatorQuestion::dropdownForForm(
+ $this->getForm(),
+ [
+ 'fieldtype' => ['glpiselect'],
+ 'itemtype' => Contract::class
+ ],
+ 'contract_question',
+ $this->fields['contract_question']
+ );
+
+ echo ' ';
+ echo ' | ';
+ echo '
';
+ }
+
protected function showValidationSettings($rand) {
echo '';
diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php
index b9de80c20..0af68f10e 100644
--- a/inc/targetticket.class.php
+++ b/inc/targetticket.class.php
@@ -270,6 +270,11 @@ public static function showProperties(self $item) {
// -------------------------------------------------------------------------------------------
$item->showLocationSettings($rand);
+ // -------------------------------------------------------------------------------------------
+ // Contracts
+ // -------------------------------------------------------------------------------------------
+ $item->showContractSettings($rand);
+
// -------------------------------------------------------------------------------------------
// Validation selection
// -------------------------------------------------------------------------------------------
@@ -669,6 +674,20 @@ public function prepareInputForUpdate($input) {
}
}
+ if (isset($input['contract_rule'])) {
+ switch ($input['contract_rule']) {
+ case self::CONTRACT_RULE_ANSWER:
+ $input['contract_question'] = $input['_contract_question'];
+ break;
+ case self::CONTRACT_RULE_SPECIFIC:
+ $input['contract_question'] = $input['_contract_specific'];
+ break;
+ case self::CONTRACT_RULE_LAST_ANSWER:
+ default:
+ $input['contract_question'] = '0';
+ }
+ }
+
$plugin = new Plugin();
if ($plugin->isActivated('tag')) {
if (isset($input['tag_questions'])) {
@@ -888,6 +907,7 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM {
$data = $this->setOLA($data, $formanswer);
$data = $this->setTargetUrgency($data, $formanswer);
$data = $this->setTargetLocation($data, $formanswer);
+ $data = $this->setTargetContract($data, $formanswer);
$data = $this->setTargetAssociatedItem($data, $formanswer);
$data = $this->setTargetValidation($data, $formanswer);
@@ -1069,6 +1089,82 @@ protected function setTargetLocation($data, $formanswer) {
return $data;
}
+ protected function setTargetContract($data, $formanswer) {
+ global $DB;
+
+ $contract = null;
+ switch ($this->fields['contract_rule']) {
+ case self::CONTRACT_RULE_ANSWER:
+ $contract = $DB->request([
+ 'SELECT' => ['answer'],
+ 'FROM' => PluginFormcreatorAnswer::getTable(),
+ 'WHERE' => [
+ 'plugin_formcreator_formanswers_id' => $formanswer->fields['id'],
+ 'plugin_formcreator_questions_id' => $this->fields['contract_question']
+ ]
+ ])->current();
+ if (isset($contract['answer']) && ctype_digit($contract['answer'])) {
+ $contract = $contract['answer'];
+ }
+ break;
+ case self::CONTRACT_RULE_SPECIFIC:
+ $contract = $this->fields['contract_question'];
+ break;
+ case self::CONTRACT_RULE_LAST_ANSWER:
+ $form_answer_id = $formanswer->fields['id'];
+
+ // Get all answers for dropdown questions of this form, ordered
+ // from last to first displayed
+ $answers = $DB->request([
+ 'SELECT' => ['answer.plugin_formcreator_questions_id', 'answer.answer', 'question.values'],
+ 'FROM' => PluginFormcreatorAnswer::getTable() . ' AS answer',
+ 'JOIN' => [
+ PluginFormcreatorQuestion::getTable() . ' AS question' => [
+ 'ON' => [
+ 'answer' => 'plugin_formcreator_questions_id',
+ 'question' => 'id',
+ ]
+ ]
+ ],
+ 'WHERE' => [
+ 'answer.plugin_formcreator_formanswers_id' => $form_answer_id,
+ 'question.fieldtype' => "glpiselect",
+ 'question.itemtype' => Contract::class,
+ ],
+ 'ORDER' => [
+ 'row DESC',
+ 'col DESC',
+ ]
+ ]);
+
+ foreach ($answers as $answer) {
+ // Decode dropdown settings
+ $question = PluginFormcreatorQuestion::getById($answer[PluginFormcreatorQuestion::getForeignKeyField()]);
+ $itemtype = $question->fields['itemtype'];
+
+ // Skip if question was not answered
+ if (empty($answer['answer'])) {
+ continue;
+ }
+
+ // Skip if question is not visible
+ if (!$formanswer->isFieldVisible($answer['plugin_formcreator_questions_id'])) {
+ continue;
+ }
+
+ // Found a valid answer, stop here
+ $contract = $answer['answer'];
+ break;
+ }
+ break;
+ }
+ if (!is_null($contract)) {
+ $data['_contracts_id'] = $contract;
+ }
+
+ return $data;
+ }
+
protected function setTargetSource(array $data, PluginFormcreatorFormAnswer $formanswer): array {
switch ($this->fields['source_rule']) {
case self::REQUESTSOURCE_SPECIFIC:
@@ -1515,6 +1611,7 @@ public function export(bool $remove_uuid = false) : array {
'category_rule' => ['values' => self::CATEGORY_RULE_ANSWER, 'field' => 'category_question'],
'associate_rule' => ['values' => self::ASSOCIATE_RULE_ANSWER, 'field' => 'associate_question'],
'location_rule' => ['values' => self::LOCATION_RULE_ANSWER, 'field' => 'location_question'],
+ 'contract_rule' => ['values' => self::CONTRACT_RULE_ANSWER, 'field' => 'contract_question'],
'destination_entity' => [
'values' => [
self::DESTINATION_ENTITY_ENTITY,
diff --git a/install/mysql/plugin_formcreator_2.14.0_empty.sql b/install/mysql/plugin_formcreator_2.14.0_empty.sql
index 66c64c843..27e44fdb7 100644
--- a/install/mysql/plugin_formcreator_2.14.0_empty.sql
+++ b/install/mysql/plugin_formcreator_2.14.0_empty.sql
@@ -247,6 +247,8 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targettickets` (
`associate_question` int unsigned NOT NULL DEFAULT '0',
`location_rule` int(11) NOT NULL DEFAULT '1',
`location_question` int unsigned NOT NULL DEFAULT '0',
+ `contract_rule` int(11) NOT NULL DEFAULT '1',
+ `contract_question` int unsigned NOT NULL DEFAULT '0',
`commonitil_validation_rule` int(11) NOT NULL DEFAULT '1',
`commonitil_validation_question` varchar(255) DEFAULT NULL,
`show_rule` int(11) NOT NULL DEFAULT '1',
diff --git a/install/upgrade_to_2.14.php b/install/upgrade_to_2.14.php
index 68c3c2d19..2f101db3c 100644
--- a/install/upgrade_to_2.14.php
+++ b/install/upgrade_to_2.14.php
@@ -42,6 +42,7 @@ public function upgrade(Migration $migration) {
$this->addRights();
$this->addPropertiesToCategories();
$this->addTargetActorUnicity();
+ $this->addTargetContract();
}
public function addTtoToIssues() {
@@ -131,4 +132,12 @@ public function addTargetActorUnicity() {
// Set unicity
$this->migration->addKey($table, $unicity, 'unicity', 'UNIQUE');
}
+
+ public function addTargetContract() {
+ $table = 'glpi_plugin_formcreator_targettickets';
+ $unsignedIntType = "INT UNSIGNED NOT NULL DEFAULT '0'";
+
+ $this->migration->addField($table, 'contract_rule', 'integer', ['after' => 'location_question', 'value' => '1']);
+ $this->migration->addField($table, 'contract_question', $unsignedIntType, ['after' => 'contract_rule']);
+ }
}
diff --git a/js/scripts.js b/js/scripts.js
index b56e939ad..ce48ab871 100644
--- a/js/scripts.js
+++ b/js/scripts.js
@@ -1930,6 +1930,24 @@ function plugin_formcreator_change_location(rand) {
}
}
+function plugin_formcreator_change_contract(rand) {
+ $('#contract_specific_title').hide();
+ $('#contract_specific_value').hide();
+ $('#contract_question_title').hide();
+ $('#contract_question_value').hide();
+
+ switch($('#dropdown_contract_rule' + rand).val()) {
+ case '3' : // PluginFormcreatorAbstractTarget::CONTRACT_RULE_ANSWER
+ $('#contract_question_title').show();
+ $('#contract_question_value').show();
+ break;
+ case '2' : // PluginFormcreatorAbstractTarget::CONTRACT_RULE_SPECIFIC
+ $('#contract_specific_title').show();
+ $('#contract_specific_value').show();
+ break;
+ }
+}
+
function plugin_formcreator_change_validation(rand) {
switch($('#dropdown_commonitil_validation_rule' + rand).val()) {
case '1' : // PluginFormcreatorAbstractTarget::COMMONITIL_VALIDATION_RULE_NONE
diff --git a/tests/3-unit/PluginFormcreatorTargetTicket.php b/tests/3-unit/PluginFormcreatorTargetTicket.php
index bbce1e707..7cd6d5917 100644
--- a/tests/3-unit/PluginFormcreatorTargetTicket.php
+++ b/tests/3-unit/PluginFormcreatorTargetTicket.php
@@ -41,6 +41,7 @@ public function beforeTestMethod($method) {
case 'testSetTargetEntity':
case 'testSetTargetCategory':
case 'testSetTargetLocation':
+ case 'testSetTargetContract':
case 'testSetTargetType':
case 'testPrepareTemplate':
case 'testDeleteLinkedTickets':
@@ -141,6 +142,16 @@ public function testGetEnumLocationType() {
]);
}
+ public function testGetEnumContractType() {
+ $output = \PluginFormcreatorTargetTicket::getEnumContractRule();
+ $this->array($output)->isEqualTo([
+ \PluginFormcreatorTargetTicket::CONTRACT_RULE_NONE => __('Contract from template or none', 'formcreator'),
+ \PluginFormcreatorTargetTicket::CONTRACT_RULE_SPECIFIC => __('Specific contract', 'formcreator'),
+ \PluginFormcreatorTargetTicket::CONTRACT_RULE_ANSWER => __('Equals to the answer to the question', 'formcreator'),
+ \PluginFormcreatorTargetTicket::CONTRACT_RULE_LAST_ANSWER => __('Last valid answer', 'formcreator'),
+ ]);
+ }
+
public function testGetEnumUrgencyRule() {
$output = \PluginFormcreatorTargetTicket::getEnumUrgencyRule();
$this->array($output)->isEqualTo([
@@ -680,6 +691,8 @@ public function testExport() {
'associate_question',
'location_rule',
'location_question',
+ 'contract_rule',
+ 'contract_question',
'commonitil_validation_rule',
'commonitil_validation_question',
'show_rule',
@@ -1713,4 +1726,291 @@ public function testSetTargetLocation($instance, $formanswer, $expected) {
$this->integer((int) $output['locations_id'])->isEqualTo($expected);
}
+
+ public function providerSetTargetContract_notSet() {
+ // Prepare form
+
+ $form1 = $this->getForm();
+
+ $instance1 = new PluginFormcreatorTargetTicketDummy();
+ $instance1->add([
+ 'name' => 'foo',
+ 'target_name' => '',
+ \PluginFormcreatorForm::getForeignKeyField() => $form1->getID(),
+ 'content' => '##FULLFORM',
+ 'contract_rule' => \PluginFormcreatorTargetTicket::CONTRACT_RULE_NONE,
+ 'contract_question' => '0',
+ ]);
+ $this->boolean($instance1->isNewItem())->isFalse();
+ $formAnswer1 = new \PluginFormcreatorFormAnswer();
+ $formAnswer1->add([
+ 'plugin_formcreator_forms_id' => $form1->getID(),
+ ]);
+ $this->boolean($formAnswer1->isNewItem())->isFalse();
+
+ return [
+ [
+ 'instance' => $instance1,
+ 'formanswer' => $formAnswer1,
+ 'expected' => null,
+ ],
+ ];
+ }
+
+ public function providerSetTargetContract_lastItem() {
+ // Prepare form
+ $validItemtype = \Contract::class;
+ $invalidItemtype = \Monitor::getType();
+
+ $item1 = new $validItemtype();
+ $item1->add([
+ 'name' => $this->getUniqueString(),
+ 'entities_id' => \Session::getActiveEntity(),
+ ]);
+ $this->boolean($item1->isNewItem())->isFalse();
+ $item2 = new $validItemtype();
+ $item2->add([
+ 'name' => $this->getUniqueString(),
+ 'entities_id' => \Session::getActiveEntity(),
+ ]);
+ $this->boolean($item2->isNewItem())->isFalse();
+
+ $question1 = $this->getQuestion([
+ 'fieldtype' => 'glpiselect',
+ 'itemtype' => $validItemtype,
+ ]);
+ $form1 = \PluginFormcreatorForm::getByItem($question1);
+ $sectionId = $question1->fields['plugin_formcreator_sections_id'];
+ $question2 = $this->getQuestion([
+ 'plugin_formcreator_sections_id' => $sectionId,
+ 'fieldtype' => 'glpiselect',
+ 'itemtype' => $validItemtype
+ ]);
+ $instance1 = new PluginFormcreatorTargetTicketDummy();
+ $instance1->add([
+ 'name' => 'foo',
+ 'target_name' => '',
+ \PluginFormcreatorForm::getForeignKeyField() => $form1->getID(),
+ 'content' => '##FULLFORM',
+ 'contract_rule' => \PluginFormcreatorTargetTicket::CONTRACT_RULE_LAST_ANSWER,
+ 'contract_question' => '0',
+ ]);
+ $this->boolean($instance1->isNewItem())->isFalse();
+ $formAnswer1 = new \PluginFormcreatorFormAnswer();
+ $formAnswer1->add([
+ 'plugin_formcreator_forms_id' => $form1->getID(),
+ 'formcreator_field_' . $question1->getID() => (string) $item1->getID(),
+ 'formcreator_field_' . $question2->getID() => (string) $item2->getID(),
+ ]);
+ $this->boolean($formAnswer1->isNewItem())->isFalse();
+
+ return [
+ [
+ 'instance' => $instance1,
+ 'formanswer' => $formAnswer1,
+ 'expected' => $item2->getID(),
+ ],
+ ];
+ }
+
+ public function providerSetTargetContract_nothing() {
+ $form = $this->getForm();
+ $formanswer = new \PluginFormcreatorFormanswer();
+ $formanswer->add([
+ 'plugin_formcreator_forms_id' => $form->getID(),
+ ]);
+ $this->boolean($formanswer->isNewItem())->isFalse();
+ $targetTicket = new \PluginFormcreatorTargetTicket();
+ $targetTicket->add([
+ 'name' => 'target ticket no contract',
+ 'target_name' => 'target ticket',
+ 'plugin_formcreator_forms_id' => $form->getID(),
+ 'contract_rule' => \PluginFormcreatorTargetTicket::CONTRACT_RULE_NONE,
+ ]);
+ $this->boolean($targetTicket->isNewItem())->isFalse();
+
+ return [
+ [
+ 'instance' => $targetTicket,
+ 'formanswer' => $formanswer,
+ 'expected' => 0
+ ],
+ ];
+ }
+
+ public function providerSetTargetContract_noTemplate() {
+ $contract1 = new \Contract();
+ $contract1Id = $contract1->add([
+ 'name' => 'contract 1',
+ 'entities_id' => 0,
+ ]);
+ $contract2 = new \Contract();
+ $contract2Id = $contract2->add([
+ 'name' => 'contract 2',
+ 'entities_id' => 0,
+ ]);
+
+ $question1 = $this->getQuestion([
+ 'name' => 'request type',
+ 'fieldtype' => 'requesttype',
+ ]);
+ $this->boolean($question1->isNewItem())->isFalse();
+ $section = new \PluginFormcreatorSection();
+ $section->getFromDB($question1->fields['plugin_formcreator_sections_id']);
+ $this->boolean($section->isNewItem())->isFalse();
+ $question2 = $this->getQuestion([
+ 'plugin_formcreator_sections_id' => $section->getID(),
+ 'name' => 'contract',
+ 'fieldtype' => 'glpiselect',
+ 'itemtype' => \Contract::class,
+ 'show_rule' => \PluginFormcreatorCondition::SHOW_RULE_HIDDEN,
+ '_conditions' => [
+ 'show_logic' => [\PluginFormcreatorCondition::SHOW_LOGIC_AND],
+ 'plugin_formcreator_questions_id' => [$question1->getID()],
+ 'show_condition' => [\PluginFormcreatorCondition::SHOW_CONDITION_EQ],
+ 'show_value' => ['Incident'],
+ ]
+ ]);
+ $question3 = $this->getQuestion([
+ 'plugin_formcreator_sections_id' => $section->getID(),
+ 'name' => 'other contract',
+ 'fieldtype' => 'glpiselect',
+ 'itemtype' => \Contract::class,
+ 'show_rule' => \PluginFormcreatorCondition::SHOW_RULE_HIDDEN,
+ '_conditions' => [
+ 'show_logic' => [\PluginFormcreatorCondition::SHOW_LOGIC_AND],
+ 'plugin_formcreator_questions_id' => [$question1->getID()],
+ 'show_condition' => [\PluginFormcreatorCondition::SHOW_CONDITION_EQ],
+ 'show_value' => ['Request'],
+ ]
+ ]);
+
+ $formanswer1 = new \PluginFormcreatorFormAnswer();
+ $formanswer1->add([
+ 'plugin_formcreator_forms_id' => $section->fields['plugin_formcreator_forms_id'],
+ 'formcreator_field_' . $question1->getID() => (string) \Ticket::INCIDENT_TYPE,
+ 'formcreator_field_' . $question2->getID() => (string) $contract1Id,
+ 'formcreator_field_' . $question3->getID() => (string) $contract2Id,
+ ]);
+
+ $formanswer2 = new \PluginFormcreatorFormAnswer();
+ $formanswer2->add([
+ 'plugin_formcreator_forms_id' => $section->fields['plugin_formcreator_forms_id'],
+ 'formcreator_field_' . $question1->getID() => (string) \Ticket::DEMAND_TYPE,
+ 'formcreator_field_' . $question2->getID() => (string) $contract1Id,
+ 'formcreator_field_' . $question3->getID() => (string) $contract2Id,
+ ]);
+
+ $formanswer3 = new \PluginFormcreatorFormAnswer();
+ $formanswer3->add([
+ 'plugin_formcreator_forms_id' => $section->fields['plugin_formcreator_forms_id'],
+ 'formcreator_field_' . $question1->getID() => (string) \Ticket::INCIDENT_TYPE,
+ 'formcreator_field_' . $question2->getID() => (string) $contract1Id,
+ 'formcreator_field_' . $question3->getID() => (string) 0,
+ ]);
+
+ $instance1 = $this->newTestedInstance();
+ $instance1->add([
+ 'name' => 'target ticket no template',
+ 'target_name' => 'target ticket',
+ 'plugin_formcreator_forms_id' => $formanswer1->getForm()->getID(),
+ 'contract_rule' => \PluginFormcreatorTargetTicket::CONTRACT_RULE_LAST_ANSWER,
+ ]);
+
+ return [
+ // Check visibility is taken into account
+ 'visibility taken into account' => [
+ 'instance' => $instance1,
+ 'formanswer' => $formanswer1,
+ 'expected' => $contract1Id,
+ ],
+ // Check contract dropdown is ignored
+ '1st ticket contract question is ignored' => [
+ 'instance' => $instance1,
+ 'formanswer' => $formanswer2,
+ 'expected' => $contract2Id,
+ ],
+ // Check zero value is ignored
+ 'zero value is ignored' => [
+ 'instance' => $instance1,
+ 'formanswer' => $formanswer3,
+ 'expected' => $contract1Id,
+ ]
+ ];
+ }
+
+ public function providerSetTargetContract_fromTemplate() {
+ // When the target ticket uses a ticket template and does not specify a contract
+ $contract1 = new \Contract();
+ $contract1Id = $contract1->add([
+ 'name' => 'contract 1',
+ 'entities_id' => 0,
+ ]);
+
+ $ticketTemplate = $this->getGlpiCoreItem(
+ \TicketTemplate::getType(), [
+ 'name' => 'template with predefined contract',
+ ]
+ );
+ $this->getGlpiCoreItem(\TicketTemplatePredefinedField::getType(), [
+ 'tickettemplates_id' => $ticketTemplate->getID(),
+ 'num' => 193, // Contract
+ 'value' => $contract1Id
+ ]);
+
+ $form = $this->getForm();
+
+ $formanswer1 = new \PluginFormcreatorFormAnswer();
+ $formanswer1->add([
+ 'plugin_formcreator_forms_id' => $form->getID(),
+ ]);
+ $this->boolean($formanswer1->isNewItem())->isFalse();
+
+ $instance1 = $this->newTestedInstance();
+ $instance1->add([
+ 'name' => 'target ticket with template',
+ 'target_name' => 'target ticket',
+ 'plugin_formcreator_forms_id' => $form->getID(),
+ 'tickettemplates_id' => $ticketTemplate->getID(),
+ 'contract_rule' => \PluginFormcreatorTargetTicket::CONTRACT_RULE_NONE,
+ ]);
+ $this->boolean($instance1->isNewItem())->isFalse();
+
+ return [
+ [
+ 'instance' => $instance1,
+ 'formanswer' => $formanswer1,
+ 'expected' => $contract1Id,
+ ],
+ ];
+ }
+
+ public function providerSetTargetContract() {
+ return array_merge(
+ $this->providerSetTargetContract_notSet(),
+ $this->providerSetTargetContract_lastItem(),
+ $this->providerSetTargetContract_nothing(),
+ $this->providerSetTargetContract_noTemplate(),
+ $this->providerSetTargetContract_fromTemplate(),
+ );
+ }
+
+ /**
+ * @dataProvider providerSetTargetContract
+ *
+ */
+ public function testSetTargetContract($instance, $formanswer, $expected) {
+ // Substitute a dummy class to access protected / private methods
+ $dummyItemtype = 'GlpiPlugin\Formcreator\Tests\\' . $this->getTestedClassName() . 'Dummy';
+ $dummyInstance = new $dummyItemtype();
+ /**@var \GlpiPlugin\Formcreator\Tests\PluginFormcreatorTargetTicketDummy */
+ $instance->getFromDB($instance->getID());
+ $dummyInstance->fields = $instance->fields;
+
+ \PluginFormcreatorFields::resetVisibilityCache();
+ $data = $dummyInstance->publicGetDefaultData($formanswer);
+ $output = $dummyInstance->publicSetTargetContract($data, $formanswer);
+
+ $this->integer((int) $output['_contracts_id'])->isEqualTo($expected);
+ }
}
diff --git a/tests/src/PluginFormcreatorTargetTicketDummy.php b/tests/src/PluginFormcreatorTargetTicketDummy.php
index 7b6f4c35c..fe5009f68 100644
--- a/tests/src/PluginFormcreatorTargetTicketDummy.php
+++ b/tests/src/PluginFormcreatorTargetTicketDummy.php
@@ -97,6 +97,10 @@ public function publicSetTargetLocation($data, $formanswer) {
return $this->setTargetLocation($data, $formanswer);
}
+ public function publicSetTargetContract($data, $formanswer) {
+ return $this->setTargetContract($data, $formanswer);
+ }
+
public function publicSetTargetSource($data, $formanswer): array {
return $this->setTargetSource($data, $formanswer);
}