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 eee05ab
Showing 1 changed file with 72 additions and 4 deletions.
76 changes: 72 additions & 4 deletions tests/units/UserEscalationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,22 @@

final class UserEscalationTest extends EscaladeTestCase
{
public function testTaskGroupEscalation()
public function testTaskGroupEscalationWithRemoveTech()
{
$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));
foreach ($conf as $key => $value) {
if ($key === 'remove_tech') {
$conf[$key] = 1;
} else if ($value === 1) {
$conf[$key] = 0;
}
}
$this->assertTrue($config->update($conf));

$user1 = $user2 = new \User();
$user1->getFromDBbyName('glpi');
Expand Down Expand Up @@ -93,4 +98,67 @@ public function testTaskGroupEscalation()
$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()])));
}

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

$config = new PluginEscaladeConfig();
$conf = reset($config->find());
$config->getFromDB($conf['id']);
$this->assertGreaterThan(0, $conf['id']);
foreach ($conf as $key => $value) {
if ($value === 1) {
$conf[$key] = 0;
}
}

PluginEscaladeConfig::loadInSession();

$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();
$this->assertEquals(2, count($ticket_user->find(['tickets_id' => $t_id, 'type' => \CommonITILActor::ASSIGN])));
$this->assertEquals(2, count($ticket_user->find(['tickets_id' => $t_id, 'type' => \CommonITILActor::ASSIGN, 'users_id' => $user1->getID()])));
}
}

0 comments on commit eee05ab

Please sign in to comment.