Skip to content

Commit

Permalink
Fix units tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lainow committed Dec 30, 2024
1 parent 47eb3db commit 4c27346
Showing 1 changed file with 78 additions and 5 deletions.
83 changes: 78 additions & 5 deletions tests/units/UserEscalationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,91 @@

final class UserEscalationTest extends EscaladeTestCase
{
public function testTaskGroupEscalation()
public function testUserGroupEscalationWithoutRemove_Tech()
{
$this->login();

$plugins = new \Plugin();
$plugins->getFromDBbyDir('escalade');
$this->assertTrue(\Plugin::isPluginActive('escalade'));

PluginEscaladeConfig::loadInSession();

$config = new PluginEscaladeConfig();
$conf = reset($config->find());
$config->getFromDB($conf['id']);
$this->assertGreaterThan(0, $conf['id']);
$this->assertTrue($config->update([
'remove_tech' => 0
] + $conf));

PluginEscaladeConfig::loadInSession();

$this->assertEquals($_SESSION['plugins']['escalade']['config']['remove_tech'], 0);

$user1 = $user2 = new \User();
$user1->getFromDBbyName('glpi');
$this->assertGreaterThan(0, $user1->getID());
$user2->getFromDBbyName('tech');
$this->assertGreaterThan(0, $user2->getID());

$this->assertTrue($config->update([
'remove_tech' => 1
] + $conf));

PluginEscaladeConfig::loadInSession();

$this->assertEquals($_SESSION['plugins']['escalade']['config']['remove_tech'], 1);

$ticket = new \Ticket();
$t_id = $ticket->add([
'name' => 'Task User change Escalation Test',
'content' => 'A comment',
'_actors' => [
'assign' => [
[
'items_id' => $user2->getID(),
'itemtype' => 'User'
]
],
]
]);

$ticket_user = new \Ticket_User();
$this->assertEquals(1, count($ticket_user->find(['tickets_id' => $t_id, 'type' => \CommonITILActor::ASSIGN])));

// Update with two user (only one added)
$this->assertTrue($ticket->update(
[
'id' => $t_id,
'content' => 'A new comment',
'_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])));
}

public function testUserGroupEscalationWithRemove_Tech()
{
$this->login();

$plugins = new \Plugin();
$plugins->getFromDBbyDir('escalade');
$this->assertTrue(\Plugin::isPluginActive('escalade'));

PluginEscaladeConfig::loadInSession();

$this->assertEquals($_SESSION['plugins']['escalade']['config']['remove_tech'], 0);

$user1 = $user2 = new \User();
$user1->getFromDBbyName('glpi');
$this->assertGreaterThan(0, $user1->getID());
Expand All @@ -56,7 +129,7 @@ public function testTaskGroupEscalation()
$ticket = new \Ticket();
$t_id = $ticket->add([
'name' => 'Task User change Escalation Test',
'content' => '',
'content' => 'A comment',
'_actors' => [
'assign' => [
[
Expand All @@ -70,10 +143,11 @@ public function testTaskGroupEscalation()
$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
// Update ticket with two user
$this->assertTrue($ticket->update(
[
'id' => $t_id,
'content' => 'A new comment 2',
'_actors' => [
'assign' => [
[
Expand All @@ -90,7 +164,6 @@ public function testTaskGroupEscalation()
));

$ticket_user = new \Ticket_User();
$this->assertEquals(1, count($ticket_user->find(['tickets_id' => $t_id, 'type' => \CommonITILActor::ASSIGN])));
$this->assertEquals(1, count($ticket_user->find(['tickets_id' => $t_id, 'type' => \CommonITILActor::ASSIGN, 'users_id' => $user1->getID()])));
$this->assertEquals(2, count($ticket_user->find(['tickets_id' => $t_id, 'type' => \CommonITILActor::ASSIGN])));
}
}

0 comments on commit 4c27346

Please sign in to comment.