Skip to content

Commit 2e09c24

Browse files
committed
fix(targetticket): undefined type after creation
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 66203ed commit 2e09c24

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

inc/targetticket.class.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,17 @@ protected function showCompositeTicketSettings($rand) {
370370

371371
public function prepareInputForAdd($input) {
372372
$input = parent::prepareInputForAdd($input);
373-
373+
if ($input === false) {
374+
return false;
375+
}
376+
if (!isset($input['type_rule'])) {
377+
$input['type_rule'] = self::REQUESTTYPE_SPECIFIC;
378+
}
379+
if ($input['type_rule'] == self::REQUESTTYPE_SPECIFIC) {
380+
if (!isset($input['type_question']) || !in_array($input['type_question'], [Ticket::INCIDENT_TYPE, Ticket::DEMAND_TYPE])) {
381+
$input['type_question'] = Ticket::INCIDENT_TYPE;
382+
}
383+
}
374384
return $input;
375385
}
376386

tests/suite-unit/PluginFormcreatorTargetTicket.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ public function testIsEntityAssign() {
10201020
$this->boolean($instance->isEntityAssign())->isFalse();
10211021
}
10221022

1023-
public function testdeleteObsoleteItems() {
1023+
public function testDeleteObsoleteItems() {
10241024
$form = $this->getForm();
10251025
$targetTicket1 = $this->getTargetTicket([
10261026
'plugin_formcreator_forms_id' => $form->getID(),
@@ -1036,4 +1036,54 @@ public function testdeleteObsoleteItems() {
10361036
$checkDeleted = $this->newTestedInstance();
10371037
$this->boolean($checkDeleted->getFromDB($targetTicket2->getID()))->isTrue();
10381038
}
1039+
1040+
public function providerPrepareInputForAdd() {
1041+
$formFk = \PluginFormcreatorForm::getForeignKeyField();
1042+
$form = $this->getForm();
1043+
$name = $this->getUniqueString();
1044+
return [
1045+
[
1046+
'input' => [
1047+
$formFk => $form->getID(),
1048+
'name' => $name,
1049+
],
1050+
'expected' => [
1051+
$formFk => $form->getID(),
1052+
'name' => $name,
1053+
'target_name' => $name,
1054+
'content' => '##FULLFORM##',
1055+
'type_rule' => \PluginFormcreatorTargetTicket::REQUESTTYPE_SPECIFIC,
1056+
'type_question' => \Ticket::INCIDENT_TYPE
1057+
],
1058+
],
1059+
[
1060+
'input' => [
1061+
$formFk => $form->getID(),
1062+
'name' => $name,
1063+
'type_rule' => \PluginFormcreatorTargetTicket::REQUESTTYPE_SPECIFIC,
1064+
'type_question' => \Ticket::DEMAND_TYPE
1065+
],
1066+
'expected' => [
1067+
$formFk => $form->getID(),
1068+
'name' => $name,
1069+
'target_name' => $name,
1070+
'content' => '##FULLFORM##',
1071+
'type_rule' => \PluginFormcreatorTargetTicket::REQUESTTYPE_SPECIFIC,
1072+
'type_question' => \Ticket::DEMAND_TYPE
1073+
],
1074+
],
1075+
];
1076+
}
1077+
1078+
/**
1079+
* @dataProvider providerPrepareInputForAdd
1080+
*
1081+
*/
1082+
public function testPrepareInputForAdd($input, $expected) {
1083+
$instance = $this->newTestedInstance();
1084+
$output = $instance->prepareInputForAdd($input);
1085+
$this->array($output)->hasKey('uuid');
1086+
unset($output['uuid']);
1087+
$this->array($output)->isEqualTo($expected);
1088+
}
10391089
}

0 commit comments

Comments
 (0)