Skip to content

Commit

Permalink
Fix units tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lainow committed Jan 2, 2025
1 parent 47eb3db commit 7f6c85a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion inc/ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/

use Glpi\Application\View\TemplateRenderer;
use Symfony\Component\VarDumper\VarDumper;

if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
Expand Down Expand Up @@ -589,7 +590,6 @@ public static function removeAssignUsers($item, $keep_users_id = false, $type =

//delete user
$ticket_user->delete(['id' => $id]);

if (isset($item->input['_actors'])) {
foreach ($item->input['_actors'][$types[$type]] as $key => $actor) {
if (
Expand Down
39 changes: 35 additions & 4 deletions tests/units/UserEscalationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,25 @@

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

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

$user1 = $user2 = new \User();
PluginEscaladeConfig::loadInSession();

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

Expand Down Expand Up @@ -91,6 +95,33 @@ 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(1, count($ticket_user->find(['tickets_id' => $t_id, 'type' => \CommonITILActor::ASSIGN, 'users_id' => $user2->getID()])));

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

PluginEscaladeConfig::loadInSession();

$this->assertTrue($ticket->update(
[
'id' => $t_id,
'_actors' => [
'assign' => [
[
'items_id' => $user1->getID(),
'itemtype' => 'User'
],
[
'items_id' => $user2->getID(),
'itemtype' => 'User'
]
],
],
]
));

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

0 comments on commit 7f6c85a

Please sign in to comment.