Skip to content

Commit

Permalink
feat(issue): change status conversion matrix
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Apr 1, 2021
1 parent 4b8b4c1 commit 60ba8bf
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 12 deletions.
16 changes: 9 additions & 7 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])) {
Expand Down
2 changes: 1 addition & 1 deletion inc/issue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . "',
Expand Down
59 changes: 55 additions & 4 deletions tests/3-unit/PluginFormcreatorCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function beforeTestMethod($method) {
case 'testGetTicketStatusForIssue':
$this->login('glpi', 'glpi');
$_SESSION['glpiset_default_tech'] = false;
$this->beforeGetTicketStatusForIssue();
break;
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -264,20 +281,54 @@ 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,
\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::REFUSED),
'status' => \CommonITILObject::INCOMING,
'_add_validation' => '0',
'validatortype' => User::class,
Expand All @@ -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 = [
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 60ba8bf

Please sign in to comment.