From 60ba8bf493fbcde6481120c9c90775b61767da6f Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Thu, 1 Apr 2021 10:28:42 +0200 Subject: [PATCH] feat(issue): change status conversion matrix Signed-off-by: Thierry Bugier --- inc/common.class.php | 16 ++++--- inc/issue.class.php | 2 +- tests/3-unit/PluginFormcreatorCommon.php | 59 ++++++++++++++++++++++-- 3 files changed, 65 insertions(+), 12 deletions(-) diff --git a/inc/common.class.php b/inc/common.class.php index a4392d2ea..fb22d205e 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -247,12 +247,12 @@ public static function cancelMyTicket(int $id) : bool { * +-------------+---------+---------+----------+ * |NULL or NONE | WAITING | REFUSED | ACCEPTED | * + ---------+-------------+---------+---------+----------+ - * T S | INCOMING | T V V T - * i t | ASSIGNED | T V V T - * c a | PLANNED | T V V T - * k t | WAITING | T V V T - * e u | SOLVED | T V T T - * t s | CLOSED | T V T T + * T S | INCOMING | T V V T + * i t | ASSIGNED | T V V T + * c a | PLANNED | T V V T + * k t | WAITING | T V V T + * e u | SOLVED | T T T T + * t s | CLOSED | T T T T * * T = status picked from Ticket * V = status picked from Validation @@ -277,7 +277,9 @@ public static function getTicketStatusForIssue(Ticket $item) : array { if ($ticketValidationCount > 0 && !in_array($item->fields['global_validation'], [TicketValidation::ACCEPTED, TicketValidation::NONE])) { switch ($item->fields['global_validation']) { case CommonITILValidation::WAITING: - $status = PluginFormcreatorFormAnswer::STATUS_WAITING; + if (!in_array($item->fields['status'], [Ticket::SOLVED, Ticket::CLOSED])) { + $status = PluginFormcreatorFormAnswer::STATUS_WAITING; + } break; case CommonITILValidation::REFUSED: if (!in_array($item->fields['status'], [Ticket::SOLVED, Ticket::CLOSED])) { diff --git a/inc/issue.class.php b/inc/issue.class.php index 5df8c130b..1c3cbfa77 100644 --- a/inc/issue.class.php +++ b/inc/issue.class.php @@ -142,7 +142,7 @@ public static function getSyncIssuesRequest() : AbstractQuery { `$ticketTable`.`status`, IF(`$ticketTable`.`global_validation` IN ('" . CommonITILValidation::NONE . "', '" . CommonITILValidation::ACCEPTED . "'), `$ticketTable`.`status`, - IF(`$ticketTable`.`status` IN ('" . CommonITILObject::SOLVED . "', '" . CommonITILObject::CLOSED . "') AND `$ticketTable`.`global_validation` = '" . CommonITILValidation::REFUSED . "', + IF(`$ticketTable`.`status` IN ('" . CommonITILObject::SOLVED . "', '" . CommonITILObject::CLOSED . "'), `$ticketTable`.`status`, IF(`$ticketTable`.`global_validation` = '" . CommonITILValidation::WAITING . "', '" . PluginFormcreatorFormAnswer::STATUS_WAITING . "', diff --git a/tests/3-unit/PluginFormcreatorCommon.php b/tests/3-unit/PluginFormcreatorCommon.php index 8f79215ac..877630d69 100644 --- a/tests/3-unit/PluginFormcreatorCommon.php +++ b/tests/3-unit/PluginFormcreatorCommon.php @@ -39,6 +39,7 @@ public function beforeTestMethod($method) { case 'testGetTicketStatusForIssue': $this->login('glpi', 'glpi'); $_SESSION['glpiset_default_tech'] = false; + $this->beforeGetTicketStatusForIssue(); break; } } @@ -164,11 +165,16 @@ public function testCleanOldCaptchas() { } public function beforeGetTicketStatusForIssue() { + global $CFG_GLPI; + $CFG_GLPI['use_notifications'] = '0'; } public function providerGetTicketStatusForIssue() { $data = []; + + // Build test cases for 1st and last columns of tabhe in docblock of + // PluginFormcreatorCommon::getTicketStatusForIssue (total 18 test cases) $expectedStatus = [ \Ticket::INCOMING, \Ticket::ASSIGNED, @@ -240,11 +246,22 @@ public function providerGetTicketStatusForIssue() { 'expected' => ['user' => 4, 'status' => $ticketStatus] ]; $data["validation accepted, " . \Ticket::getStatus($ticketStatus)] = $dataSet; + } + // Build test cases for 2nd column of tabhe in docblock of + // PluginFormcreatorCommon::getTicketStatusForIssue (total 4 test cases) + $expectedStatus = [ + \Ticket::INCOMING, + \Ticket::ASSIGNED, + \Ticket::PLANNED, + \Ticket::WAITING, + ]; + foreach ($expectedStatus as $ticketStatus) { + // generate tickets with a validation $ticket = new \Ticket(); $ticket->add([ 'name' => 'a ticket', - 'content' => "should be " . \Ticket::getStatus($ticketStatus), + 'content' => "should be " . \CommonITILValidation::getStatus(\CommonITILValidation::WAITING), 'status' => \CommonITILObject::INCOMING, '_add_validation' => '0', 'validatortype' => User::class, @@ -264,9 +281,42 @@ public function providerGetTicketStatusForIssue() { 'ticket' => $ticket, 'expected' => ['user' => 4, 'status' => \PluginFormcreatorFormAnswer::STATUS_WAITING] ]; + $data["validation waiting, " . \CommonITILValidation::getStatus(\CommonITILValidation::WAITING)] = $dataSet; + } + + $expectedStatus = [ + \Ticket::SOLVED, + \Ticket::CLOSED, + ]; + foreach ($expectedStatus as $ticketStatus) { + $ticket = new \Ticket(); + $ticket->add([ + 'name' => 'a ticket', + 'content' => "should be " . \Ticket::getStatus($ticketStatus), + 'status' => \CommonITILObject::INCOMING, + '_add_validation' => '0', + 'validatortype' => User::class, + 'users_id_validate' => [4], // Tech + ]); + $this->boolean($ticket->isNewItem())->isFalse(); + // Creating a ticket directly with status solved or closed + // will prevent credation of ticketvalidation item + $ticket->update([ + 'id' => $ticket->getID(), + 'status' => $ticketStatus, + '_users_id_assign' => ($ticketStatus > \CommonITILObject::INCOMING) ? 4 /* Tech */ : 0, + ]); + $this->integer((int) $ticket->fields['status'])->isEqualTo($ticketStatus); + $ticket->fields['global_validation'] = \CommonITILValidation::WAITING; + $dataSet = [ + 'ticket' => $ticket, + 'expected' => ['user' => 4, 'status' => $ticketStatus] + ]; $data["validation waiting, " . \Ticket::getStatus($ticketStatus)] = $dataSet; } + // Build test cases for 3rd column of tabhe in docblock of + // PluginFormcreatorCommon::getTicketStatusForIssue (total 4 test cases) $expectedStatus = [ \Ticket::INCOMING, \Ticket::ASSIGNED, @@ -274,10 +324,11 @@ public function providerGetTicketStatusForIssue() { \Ticket::WAITING, ]; foreach ($expectedStatus as $ticketStatus) { + // generate tickets with a validation $ticket = new \Ticket(); $ticket->add([ 'name' => 'a ticket', - 'content' => "should be " . \Ticket::getStatus($ticketStatus), + 'content' => "should be " . \CommonITILValidation::getStatus(\CommonITILValidation::REFUSED), 'status' => \CommonITILObject::INCOMING, '_add_validation' => '0', 'validatortype' => User::class, @@ -297,7 +348,7 @@ public function providerGetTicketStatusForIssue() { 'ticket' => $ticket, 'expected' => ['user' => 4, 'status' => \PluginFormcreatorFormAnswer::STATUS_REFUSED] ]; - $data["validation waiting, " . \Ticket::getStatus($ticketStatus)] = $dataSet; + $data["validation refused, " . \CommonITILValidation::getStatus(\CommonITILValidation::REFUSED)] = $dataSet; } $expectedStatus = [ @@ -328,7 +379,7 @@ public function providerGetTicketStatusForIssue() { 'ticket' => $ticket, 'expected' => ['user' => 4, 'status' => $ticketStatus] ]; - $data["validation waiting, " . \Ticket::getStatus($ticketStatus)] = $dataSet; + $data["validation refused, " . \Ticket::getStatus($ticketStatus)] = $dataSet; } return $data;