Skip to content

Commit 5149235

Browse files
committed
test: update tests
1 parent 27605c0 commit 5149235

File tree

6 files changed

+55
-42
lines changed

6 files changed

+55
-42
lines changed

inc/targetchange.class.php

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -383,49 +383,55 @@ public function prepareInputForUpdate($input) {
383383
|| !$input['_skip_checks']) {
384384

385385
$input['content'] = Html::entity_decode_deep($input['content']);
386-
387-
switch ($input['destination_entity']) {
388-
case self::DESTINATION_ENTITY_SPECIFIC :
389-
$input['destination_entity_value'] = $input['_destination_entity_value_specific'];
390-
unset($input['_destination_entity_value_specific']);
391-
break;
392-
case self::DESTINATION_ENTITY_USER :
393-
$input['destination_entity_value'] = $input['_destination_entity_value_user'];
394-
unset($input['_destination_entity_value_user']);
395-
break;
396-
case self::DESTINATION_ENTITY_ENTITY :
397-
$input['destination_entity_value'] = $input['_destination_entity_value_entity'];
398-
unset($input['_destination_entity_value_entity']);
399-
break;
400-
default :
401-
$input['destination_entity_value'] = 'NULL';
402-
break;
386+
387+
if (isset($input['destination_entity'])) {
388+
switch ($input['destination_entity']) {
389+
case self::DESTINATION_ENTITY_SPECIFIC :
390+
$input['destination_entity_value'] = $input['_destination_entity_value_specific'];
391+
unset($input['_destination_entity_value_specific']);
392+
break;
393+
case self::DESTINATION_ENTITY_USER :
394+
$input['destination_entity_value'] = $input['_destination_entity_value_user'];
395+
unset($input['_destination_entity_value_user']);
396+
break;
397+
case self::DESTINATION_ENTITY_ENTITY :
398+
$input['destination_entity_value'] = $input['_destination_entity_value_entity'];
399+
unset($input['_destination_entity_value_entity']);
400+
break;
401+
default :
402+
$input['destination_entity_value'] = 'NULL';
403+
break;
404+
}
403405
}
404406

405-
switch ($input['urgency_rule']) {
406-
case self::URGENCY_RULE_ANSWER:
407-
$input['urgency_question'] = $input['_urgency_question'];
408-
unset($input['_urgency_question']);
409-
break;
410-
case self::URGENCY_RULE_SPECIFIC:
411-
$input['urgency_question'] = $input['_urgency_specific'];
412-
unset($input['_urgency_specific']);
413-
break;
414-
default:
415-
$input['urgency_question'] = '0';
407+
if (isset($input['urgency_rule'])) {
408+
switch ($input['urgency_rule']) {
409+
case self::URGENCY_RULE_ANSWER:
410+
$input['urgency_question'] = $input['_urgency_question'];
411+
unset($input['_urgency_question']);
412+
break;
413+
case self::URGENCY_RULE_SPECIFIC:
414+
$input['urgency_question'] = $input['_urgency_specific'];
415+
unset($input['_urgency_specific']);
416+
break;
417+
default:
418+
$input['urgency_question'] = '0';
419+
}
416420
}
417421

418-
switch ($input['category_rule']) {
419-
case self::CATEGORY_RULE_ANSWER:
420-
$input['category_question'] = $input['_category_question'];
421-
unset($input['_category_question']);
422-
break;
423-
case self::CATEGORY_RULE_SPECIFIC:
424-
$input['category_question'] = $input['_category_specific'];
425-
unset($input['_category_specific']);
426-
break;
427-
default:
428-
$input['category_question'] = '0';
422+
if (isset($input['category_rule'])) {
423+
switch ($input['category_rule']) {
424+
case self::CATEGORY_RULE_ANSWER:
425+
$input['category_question'] = $input['_category_question'];
426+
unset($input['_category_question']);
427+
break;
428+
case self::CATEGORY_RULE_SPECIFIC:
429+
$input['category_question'] = $input['_category_specific'];
430+
unset($input['_category_specific']);
431+
break;
432+
default:
433+
$input['category_question'] = '0';
434+
}
429435
}
430436

431437
$plugin = new Plugin();

install/mysql/plugin_formcreator_empty.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targetchanges` (
143143
`id` int(11) NOT NULL AUTO_INCREMENT,
144144
`name` varchar(255) NOT NULL DEFAULT '',
145145
`plugin_formcreator_forms_id` int(11) NOT NULL,
146+
`target_name` varchar(255) NOT NULL DEFAULT '',
146147
`content` longtext,
147148
`impactcontent` longtext,
148149
`controlistcontent` longtext,

tests/suite-integration/PluginFormcreatorTargetTicket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function testUrgency() {
152152
$formId = $form->getID();
153153
$targetTicketsData = [
154154
[
155-
'target_name' => 'target 1',
155+
'name' => 'target 1',
156156
'plugin_formcreator_forms_id' => $formId,
157157
'content' => '##FULLFORM##',
158158
'itemtype' => \PluginFormcreatorTargetTicket::class,

tests/suite-unit/PluginFormcreatorForm.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function beforeTestMethod($method) {
4141
case 'testImport':
4242
case 'testCanPurgeItem':
4343
case 'testDuplicate':
44+
case 'testSaveForm':
4445
self::login('glpi', 'glpi');
4546
}
4647
}
@@ -594,8 +595,6 @@ public function testgetFormFromSection($section, $expected) {
594595
public function testSaveForm() {
595596
global $CFG_GLPI;
596597

597-
$this->login('glpi', 'glpi');
598-
599598
// disable notifications as we may fail in some case (not the purpose of this test btw)
600599
$use_notifications = $CFG_GLPI['use_notifications'];
601600
$CFG_GLPI['use_notifications'] = 0;
@@ -760,20 +759,23 @@ public function providerAddTarget() {
760759
],
761760
[
762761
'input' => [
762+
'name' => '',
763763
'itemtype' => \PluginFormcreatorTargetTicket::class,
764764
'plugin_formcreator_forms_id' => $form->getID(),
765765
],
766766
'expected' => false,
767767
],
768768
[
769769
'input' => [
770+
'name' => '',
770771
'itemtype' => \PluginFormcreatorTargetTicket::class,
771772
'plugin_formcreator_forms_id' => $this->getForm()->getID(),
772773
],
773774
'expected' => true,
774775
],
775776
[
776777
'input' => [
778+
'name' => '',
777779
'itemtype' => \PluginFormcreatorTargetChange::class,
778780
'plugin_formcreator_forms_id' => $this->getForm()->getID(),
779781
],
@@ -813,6 +815,7 @@ public function testDeleteTarget() {
813815
$this->boolean($output)->isFalse();
814816

815817
$output = $instance->addTarget([
818+
'name' => '',
816819
'itemtype' => \PluginFormcreatorTargetChange::class,
817820
'plugin_formcreator_forms_id' => $this->getForm()->getID(),
818821
]);

tests/suite-unit/PluginFormcreatorTargetChange.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function providerPrepareInputForUpdate() {
7575
return [
7676
[
7777
'input' => [
78+
'name' => '',
7879
'content' => '',
7980
],
8081
'expected' => [
@@ -393,6 +394,7 @@ public function testExport() {
393394
$fieldsWithoutID = [
394395
'name',
395396
'content',
397+
'target_name',
396398
'impactcontent',
397399
'controlistcontent',
398400
'rolloutplancontent',

tests/suite-unit/PluginFormcreatorTargetTicket.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ public function testSetTargetCategory() {
703703
$form->getByQuestionId($question->getID());
704704
$fields = $form->getFields();
705705
$instance->add([
706+
'name' => 'foo',
706707
'plugin_formcreator_forms_id' => $form->getID(),
707708
'category_rule' => \PluginFormcreatorTargetTicket::CATEGORY_RULE_ANSWER,
708709
'category_question' => $question->getID(),

0 commit comments

Comments
 (0)