diff --git a/tests/units/UserEscalationTest.php b/tests/units/UserEscalationTest.php new file mode 100644 index 0000000..64f5354 --- /dev/null +++ b/tests/units/UserEscalationTest.php @@ -0,0 +1,98 @@ +. + * ------------------------------------------------------------------------- + * @copyright Copyright (C) 2015-2023 by Escalade plugin team. + * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html + * @link https://github.com/pluginsGLPI/escalade + * ------------------------------------------------------------------------- + */ + +namespace GlpiPlugin\Escalade\Tests\Units; + +use GlpiPlugin\Escalade\Tests\EscaladeTestCase; +use PluginEscaladeConfig; + +final class UserEscalationTest extends EscaladeTestCase +{ + public function testTaskGroupEscalation() + { + $this->login(); + + $config = new PluginEscaladeConfig(); + $conf = reset($config->find()); + $config->getFromDB($conf['id']); + $this->assertGreaterThan(0, $conf['id']); + $this->assertTrue($config->update([ + 'remove_tech' => 1 + ] + $conf)); + + $user1 = $user2 = new \User(); + $user1->getFromDBbyName('glpi'); + $this->assertGreaterThan(0, $user1->getID()); + $user2->getFromDBbyName('tech'); + $this->assertGreaterThan(0, $user2->getID()); + + $ticket = new \Ticket(); + $t_id = $ticket->add([ + 'name' => 'Task User change Escalation Test', + 'content' => '', + '_actors' => [ + 'assign' => [ + [ + 'items_id' => $user1->getID(), + 'itemtype' => 'User' + ] + ], + ] + ]); + + $ticket_user = new \Ticket_User(); + $this->assertEquals(1, count($ticket_user->find(['tickets_id' => $t_id, 'type' => \CommonITILActor::ASSIGN]))); + + // Update ticket with just one group + $this->assertTrue($ticket->update( + [ + 'id' => $t_id, + '_actors' => [ + 'assign' => [ + [ + 'items_id' => $user1->getID(), + 'itemtype' => 'User' + ], + [ + 'items_id' => $user2->getID(), + 'itemtype' => 'User' + ] + ], + ], + ] + )); + + $ticket_user = new \Ticket_User(); + $user_linked = $ticket_user->find(['tickets_id' => $t_id, 'type' => \CommonITILActor::ASSIGN]); + $this->assertEquals(1, count($user_linked)); + reset($user_linked); + $this->assertEquals($user_linked['id'], $user1->getID()); + } +}