@@ -45,6 +45,7 @@ public function beforeTestMethod($method) {
45
45
case 'testDeleteLinkedTickets ' :
46
46
case 'testSetTargetAssociatedItem ' :
47
47
case 'testSetTargetLocation ' :
48
+ case 'testSetRequestSource ' :
48
49
$ this ->boolean ($ this ->login ('glpi ' , 'glpi ' ))->isTrue ();
49
50
break ;
50
51
}
@@ -77,6 +78,23 @@ public function testGetTypeName($number, $expected) {
77
78
$ this ->string ($ output )->isEqualTo ($ expected );
78
79
}
79
80
81
+ public function testGetEnumRequestTypeRule (): void {
82
+ $ output = \PluginFormcreatorTargetTicket::getEnumRequestTypeRule ();
83
+ $ this ->array ($ output )->isEqualTo ([
84
+ \PluginFormcreatorTargetTicket::REQUESTTYPE_NONE => 'Default or from a template ' ,
85
+ \PluginFormcreatorTargetTicket::REQUESTTYPE_SPECIFIC => "Specific type " ,
86
+ \PluginFormcreatorTargetTicket::REQUESTTYPE_ANSWER => "Equals to the answer to the question " ,
87
+ ]);
88
+ }
89
+
90
+ public function testGetEnumRequestSourceRule (): void {
91
+ $ output = \PluginFormcreatorTargetTicket::getEnumRequestSourceRule ();
92
+ $ this ->array ($ output )->isEqualTo ([
93
+ \PluginFormcreatorTargetTicket::REQUESTTYPE_NONE => 'Source from template or user default or GLPI default ' ,
94
+ \PluginFormcreatorTargetTicket::REQUESTTYPE_SPECIFIC => "Formcreator " ,
95
+ ]);
96
+ }
97
+
80
98
public function testGetEnumDestinationEntity () {
81
99
$ output = \PluginFormcreatorTargetTicket::getEnumDestinationEntity ();
82
100
$ this ->array ($ output )->isEqualTo ([
@@ -638,6 +656,8 @@ public function testExport() {
638
656
$ fieldsWithoutID = [
639
657
'name ' ,
640
658
'target_name ' ,
659
+ 'source_rule ' ,
660
+ 'source_question ' ,
641
661
'type_rule ' ,
642
662
'type_question ' ,
643
663
'content ' ,
@@ -712,6 +732,8 @@ public function testImport() {
712
732
'category_question ' => '0 ' ,
713
733
'associate_rule ' => \PluginFormcreatorTargetTicket::ASSOCIATE_RULE_NONE ,
714
734
'associate_question ' => '0 ' ,
735
+ 'source_rule ' => 0 ,
736
+ 'source_question ' => 0 ,
715
737
'type_rule ' => 1 ,
716
738
'type_question ' => 0 ,
717
739
'uuid ' => $ uuid ,
@@ -1266,6 +1288,7 @@ public function providerPrepareInputForAdd() {
1266
1288
$ formFk = \PluginFormcreatorForm::getForeignKeyField ();
1267
1289
$ form = $ this ->getForm ();
1268
1290
$ name = $ this ->getUniqueString ();
1291
+ $ sourceId = \PluginFormcreatorCommon::getFormcreatorRequestTypeId ();
1269
1292
return [
1270
1293
'name is mandatory ' => [
1271
1294
'input ' => [
@@ -1287,6 +1310,8 @@ public function providerPrepareInputForAdd() {
1287
1310
'type_rule ' => \PluginFormcreatorTargetTicket::REQUESTTYPE_SPECIFIC ,
1288
1311
'type_question ' => \Ticket::INCIDENT_TYPE ,
1289
1312
'show_rule ' => \PluginFormcreatorCondition::SHOW_RULE_ALWAYS ,
1313
+ 'source_rule ' => \PluginFormcreatorTargetTicket::REQUESTSOURCE_SPECIFIC ,
1314
+ 'source_question ' => $ sourceId ,
1290
1315
],
1291
1316
'message ' => null ,
1292
1317
],
@@ -1296,6 +1321,7 @@ public function providerPrepareInputForAdd() {
1296
1321
'name ' => $ name ,
1297
1322
'type_rule ' => \PluginFormcreatorTargetTicket::REQUESTTYPE_SPECIFIC ,
1298
1323
'type_question ' => \Ticket::DEMAND_TYPE ,
1324
+ 'source_rule ' => \PluginFormcreatorTargetTicket::REQUESTSOURCE_NONE ,
1299
1325
],
1300
1326
'expected ' => [
1301
1327
$ formFk => $ form ->getID (),
@@ -1305,6 +1331,8 @@ public function providerPrepareInputForAdd() {
1305
1331
'type_rule ' => \PluginFormcreatorTargetTicket::REQUESTTYPE_SPECIFIC ,
1306
1332
'type_question ' => \Ticket::DEMAND_TYPE ,
1307
1333
'show_rule ' => \PluginFormcreatorCondition::SHOW_RULE_ALWAYS ,
1334
+ 'source_rule ' => \PluginFormcreatorTargetTicket::REQUESTSOURCE_NONE ,
1335
+ 'source_question ' => 0 ,
1308
1336
],
1309
1337
'message ' => null ,
1310
1338
],
@@ -1437,4 +1465,78 @@ public function testSetTargetLocation($instance, $formanswer, $expected) {
1437
1465
$ this ->array ($ output )->notHasKey ('locations_id ' );
1438
1466
}
1439
1467
}
1468
+
1469
+ public function providerSetRequestSource_none (): array {
1470
+ $ form = $ this ->getForm ();
1471
+ $ formanswer = new \PluginFormcreatorFormanswer ();
1472
+ $ formanswer ->add ([
1473
+ 'plugin_formcreator_forms_id ' => $ form ->getID (),
1474
+ ]);
1475
+ $ this ->boolean ($ formanswer ->isNewItem ())->isFalse ();
1476
+ $ targetTicket = new \PluginFormcreatorTargetTicket ();
1477
+ $ targetTicket ->add ([
1478
+ 'name ' => 'target ticket ' ,
1479
+ 'target_name ' => 'target ticket ' ,
1480
+ 'plugin_formcreator_forms_id ' => $ form ->getID (),
1481
+ 'source_rule ' => \PluginFormcreatorTargetTicket::REQUESTSOURCE_NONE ,
1482
+ ]);
1483
+ $ this ->boolean ($ targetTicket ->isNewItem ())->isFalse ();
1484
+
1485
+ return [
1486
+ [
1487
+ 'instance ' => $ targetTicket ,
1488
+ 'formanswer ' => $ formanswer ,
1489
+ 'expected ' => 0
1490
+ ],
1491
+ ];
1492
+ }
1493
+
1494
+ public function providerSetRequestSource_specific (): array {
1495
+ $ form = $ this ->getForm ();
1496
+ $ formanswer = new \PluginFormcreatorFormanswer ();
1497
+ $ formanswer ->add ([
1498
+ 'plugin_formcreator_forms_id ' => $ form ->getID (),
1499
+ ]);
1500
+ $ this ->boolean ($ formanswer ->isNewItem ())->isFalse ();
1501
+ $ targetTicket = new \PluginFormcreatorTargetTicket ();
1502
+ $ targetTicket ->add ([
1503
+ 'name ' => 'target ticket ' ,
1504
+ 'target_name ' => 'target ticket ' ,
1505
+ 'plugin_formcreator_forms_id ' => $ form ->getID (),
1506
+ 'source_rule ' => \PluginFormcreatorTargetTicket::REQUESTSOURCE_SPECIFIC ,
1507
+ 'source_question ' => \PluginFormcreatorCommon::getFormcreatorRequestTypeId (),
1508
+ ]);
1509
+ $ this ->boolean ($ targetTicket ->isNewItem ())->isFalse ();
1510
+
1511
+ return [
1512
+ [
1513
+ 'instance ' => $ targetTicket ,
1514
+ 'formanswer ' => $ formanswer ,
1515
+ 'expected ' => 0
1516
+ ],
1517
+ ];
1518
+ }
1519
+
1520
+ public function providerSetRequestSource (): array {
1521
+ return array_merge (
1522
+ $ this ->providerSetRequestSource_none (),
1523
+ $ this ->providerSetRequestSource_specific ()
1524
+ );
1525
+ }
1526
+
1527
+ /**
1528
+ * @dataProvider providerSetRequestSource
1529
+ */
1530
+ public function testSetRequestSource ($ instance , $ formanswer , $ expected ): void {
1531
+ // Substitute a dummy class to access protected / private methods
1532
+ $ dummyItemtype = 'GlpiPlugin\Formcreator\Tests \\' . $ this ->getTestedClassName () . 'Dummy ' ;
1533
+ $ dummyInstance = new $ dummyItemtype ();
1534
+ /**@var \GlpiPlugin\Formcreator\Tests\PluginFormcreatorTargetTicketDummy */
1535
+ $ instance ->getFromDB ($ instance ->getID ());
1536
+ $ dummyInstance ->fields = $ instance ->fields ;
1537
+
1538
+ $ data = $ dummyInstance ->publicGetDefaultData ($ formanswer );
1539
+ $ output = $ dummyInstance ->publicSetTargetCategory ($ data , $ formanswer );
1540
+ $ this ->integer ((int ) $ output ['itilcategories_id ' ])->isEqualTo ($ expected );
1541
+ }
1440
1542
}
0 commit comments