Skip to content

Commit

Permalink
fix(targetticket): undefined type after creation
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Sep 25, 2020
1 parent 8a26b77 commit e3188ef
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
12 changes: 11 additions & 1 deletion inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,17 @@ protected function showCompositeTicketSettings($rand) {

public function prepareInputForAdd($input) {
$input = parent::prepareInputForAdd($input);

if ($input === false) {
return false;
}
if (!isset($input['type_rule'])) {
$input['type_rule'] = self::REQUESTTYPE_SPECIFIC;
}
if ($input['type_rule'] == self::REQUESTTYPE_SPECIFIC) {
if (!isset($input['type_question']) || !in_array($input['type_question'], [Ticket::INCIDENT_TYPE, Ticket::DEMAND_TYPE])) {
$input['type_question'] = Ticket::INCIDENT_TYPE;
}
}
return $input;
}

Expand Down
52 changes: 51 additions & 1 deletion tests/suite-unit/PluginFormcreatorTargetTicket.php
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ public function testIsEntityAssign() {
$this->boolean($instance->isEntityAssign())->isFalse();
}

public function testdeleteObsoleteItems() {
public function testDeleteObsoleteItems() {
$form = $this->getForm();
$targetTicket1 = $this->getTargetTicket([
'plugin_formcreator_forms_id' => $form->getID(),
Expand All @@ -1129,4 +1129,54 @@ public function testdeleteObsoleteItems() {
$checkDeleted = $this->newTestedInstance();
$this->boolean($checkDeleted->getFromDB($targetTicket2->getID()))->isTrue();
}

public function providerPrepareInputForAdd() {
$formFk = \PluginFormcreatorForm::getForeignKeyField();
$form = $this->getForm();
$name = $this->getUniqueString();
return [
[
'input' => [
$formFk => $form->getID(),
'name' => $name,
],
'expected' => [
$formFk => $form->getID(),
'name' => $name,
'target_name' => $name,
'content' => '##FULLFORM##',
'type_rule' => \PluginFormcreatorTargetTicket::REQUESTTYPE_SPECIFIC,
'type_question' => \Ticket::INCIDENT_TYPE
],
],
[
'input' => [
$formFk => $form->getID(),
'name' => $name,
'type_rule' => \PluginFormcreatorTargetTicket::REQUESTTYPE_SPECIFIC,
'type_question' => \Ticket::DEMAND_TYPE
],
'expected' => [
$formFk => $form->getID(),
'name' => $name,
'target_name' => $name,
'content' => '##FULLFORM##',
'type_rule' => \PluginFormcreatorTargetTicket::REQUESTTYPE_SPECIFIC,
'type_question' => \Ticket::DEMAND_TYPE
],
],
];
}

/**
* @dataProvider providerPrepareInputForAdd
*
*/
public function testPrepareInputForAdd($input, $expected) {
$instance = $this->newTestedInstance();
$output = $instance->prepareInputForAdd($input);
$this->array($output)->hasKey('uuid');
unset($output['uuid']);
$this->array($output)->isEqualTo($expected);
}
}

0 comments on commit e3188ef

Please sign in to comment.