@@ -1382,4 +1382,147 @@ public function testHistoryButtonEscalationWithMandatoryTemplateFields()
13821382 $ group1 ->delete (['id ' => $ group1_id ], true );
13831383 $ group2 ->delete (['id ' => $ group2_id ], true );
13841384 }
1385+
1386+ /**
1387+ * Test that using the History button escalation works correctly with mandatory "Assigned Group" field
1388+ */
1389+ public function testHistoryButtonEscalationWithMandatoryAssignedGroupField ()
1390+ {
1391+ $ this ->login ();
1392+
1393+ // Load Escalade plugin configuration
1394+ $ config = new PluginEscaladeConfig ();
1395+ $ conf = $ config ->find ();
1396+ $ conf = reset ($ conf );
1397+ $ config ->getFromDB ($ conf ['id ' ]);
1398+ $ this ->assertGreaterThan (0 , $ conf ['id ' ]);
1399+ PluginEscaladeConfig::loadInSession ();
1400+
1401+ // Create a ticket template with mandatory "Assigned Group" field (field num 8)
1402+ $ template = $ this ->createItem (\TicketTemplate::class, [
1403+ 'name ' => 'Test template with mandatory assigned group ' ,
1404+ 'entities_id ' => 0 ,
1405+ 'is_recursive ' => 1 ,
1406+ ]);
1407+
1408+ // Add mandatory field for "Groupe de techniciens" (Assigned Group)
1409+ $ mandatory_field = $ this ->createItem (\TicketTemplateMandatoryField::class, [
1410+ 'tickettemplates_id ' => $ template ->getID (),
1411+ 'num ' => 8 , // _groups_id_assign field number
1412+ ]);
1413+
1414+ // Also add mandatory requester field to match real-world scenarios
1415+ $ mandatory_field2 = $ this ->createItem (\TicketTemplateMandatoryField::class, [
1416+ 'tickettemplates_id ' => $ template ->getID (),
1417+ 'num ' => 4 , // _users_id_requester field number
1418+ ]);
1419+
1420+ // Create a category linked to this template
1421+ $ category = $ this ->createItem (\ITILCategory::class, [
1422+ 'name ' => 'Test category with mandatory assigned group ' ,
1423+ 'tickettemplates_id_incident ' => $ template ->getID (),
1424+ 'is_incident ' => 1 ,
1425+ 'entities_id ' => 0 ,
1426+ 'is_recursive ' => 1 ,
1427+ ]);
1428+
1429+ // Create a requester user
1430+ $ requester = $ this ->createItem (\User::class, [
1431+ 'name ' => 'requester_assigned_group_test ' ,
1432+ 'realname ' => 'AssignedGroupTest ' ,
1433+ 'firstname ' => 'Requester ' ,
1434+ ]);
1435+
1436+ // Create first escalation group
1437+ $ group1 = $ this ->createItem (\Group::class, [
1438+ 'name ' => 'First assigned group for escalation ' ,
1439+ 'entities_id ' => 0 ,
1440+ 'is_recursive ' => 1 ,
1441+ 'is_assign ' => 1 ,
1442+ ]);
1443+
1444+ // Create second escalation group
1445+ $ group2 = $ this ->createItem (\Group::class, [
1446+ 'name ' => 'Second assigned group for escalation ' ,
1447+ 'entities_id ' => 0 ,
1448+ 'is_recursive ' => 1 ,
1449+ 'is_assign ' => 1 ,
1450+ ]);
1451+
1452+ // Create third group for history button test
1453+ $ group3 = $ this ->createItem (\Group::class, [
1454+ 'name ' => 'Third assigned group for history ' ,
1455+ 'entities_id ' => 0 ,
1456+ 'is_recursive ' => 1 ,
1457+ 'is_assign ' => 1 ,
1458+ ]);
1459+
1460+ // Create a ticket with the template, mandatory requester and mandatory assigned group filled
1461+ $ ticket = $ this ->createItem (\Ticket::class, [
1462+ 'name ' => 'Test ticket with mandatory assigned group ' ,
1463+ 'content ' => 'Content for testing mandatory assigned group in history button ' ,
1464+ 'itilcategories_id ' => $ category ->getID (),
1465+ '_users_id_requester ' => [$ requester ->getID ()],
1466+ '_groups_id_assign ' => [$ group1 ->getID ()],
1467+ ]);
1468+
1469+ // Verify initial group assignment
1470+ $ group_ticket = new \Group_Ticket ();
1471+ $ initial_groups = $ group_ticket ->find ([
1472+ 'tickets_id ' => $ ticket ->getID (),
1473+ 'type ' => CommonITILActor::ASSIGN ,
1474+ ]);
1475+ $ this ->assertEquals (1 , count ($ initial_groups ));
1476+
1477+ // Escalate to second group
1478+ $ this ->createItem (\Group_Ticket::class, [
1479+ 'tickets_id ' => $ ticket ->getID (),
1480+ 'groups_id ' => $ group2 ->getID (),
1481+ 'type ' => CommonITILActor::ASSIGN ,
1482+ ]);
1483+
1484+ // Escalate to third group to create more history
1485+ $ this ->createItem (\Group_Ticket::class, [
1486+ 'tickets_id ' => $ ticket ->getID (),
1487+ 'groups_id ' => $ group3 ->getID (),
1488+ 'type ' => CommonITILActor::ASSIGN ,
1489+ ]);
1490+
1491+ // Now test the history button escalation using climb_group
1492+ // This reproduces issue #381 where mandatory "Groupe de techniciens" field causes an error
1493+ PluginEscaladeTicket::climb_group ($ ticket ->getID (), $ group1 ->getID (), true );
1494+
1495+ // Verify that no error occurred during the climb_group operation
1496+ // by checking that group1 is now assigned
1497+ $ group1_assigned = $ group_ticket ->find ([
1498+ 'tickets_id ' => $ ticket ->getID (),
1499+ 'groups_id ' => $ group1 ->getID (),
1500+ 'type ' => CommonITILActor::ASSIGN ,
1501+ ]);
1502+ $ this ->assertGreaterThan (0 , count ($ group1_assigned ), 'Group 1 should be assigned after climb_group ' );
1503+
1504+ // Test climbing to group2 (another history group)
1505+ PluginEscaladeTicket::climb_group ($ ticket ->getID (), $ group2 ->getID (), true );
1506+
1507+ $ group2_assigned = $ group_ticket ->find ([
1508+ 'tickets_id ' => $ ticket ->getID (),
1509+ 'groups_id ' => $ group2 ->getID (),
1510+ 'type ' => CommonITILActor::ASSIGN ,
1511+ ]);
1512+ $ this ->assertGreaterThan (0 , count ($ group2_assigned ), 'Group 2 should be assigned after second climb_group ' );
1513+
1514+ // Verify that the requester is still properly assigned
1515+ $ ticket_user = new \Ticket_User ();
1516+ $ requesters_after = $ ticket_user ->find ([
1517+ 'tickets_id ' => $ ticket ->getID (),
1518+ 'type ' => CommonITILActor::REQUESTER ,
1519+ ]);
1520+ $ this ->assertEquals (1 , count ($ requesters_after ));
1521+ $ requester_after = reset ($ requesters_after );
1522+ $ this ->assertEquals ($ requester ->getID (), $ requester_after ['users_id ' ]);
1523+
1524+ // Verify that the ticket still has the correct category with template
1525+ $ ticket ->getFromDB ($ ticket ->getID ());
1526+ $ this ->assertEquals ($ category ->getID (), $ ticket ->fields ['itilcategories_id ' ]);
1527+ }
13851528}
0 commit comments