Skip to content

Commit

Permalink
Wrong status when adding a planned task (#15416)
Browse files Browse the repository at this point in the history
* fix: Wrong status when adding a planned task

fix: Wrong status when adding a planned task with deactivation of waiting status

fix: Wrong status when adding a planned task with pending

test: Add unit tests to encompass the ParentStatus trait

* fix: Test modification
  • Loading branch information
ccailly authored Sep 1, 2023
1 parent 057c200 commit 517eeed
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Features/ParentStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ public function updateParentStatus(CommonITILObject $parentitem, array $input):
|| $parentitem::isAllowedStatus($parentitem->fields["status"], CommonITILObject::ASSIGNED)
) {
$needupdateparent = true;
$update['status'] = CommonITILObject::ASSIGNED;
// If begin date is defined, the status must be planned if it exists, rather than assigned.
if (!empty($this->fields['begin']) && $parentitem->isStatusExists(CommonITILObject::PLANNED)) {
$update['status'] = CommonITILObject::PLANNED;
} else {
$update['status'] = CommonITILObject::ASSIGNED;
}
}
} else {
//check if lifecycle allowed new status
Expand All @@ -159,7 +164,8 @@ public function updateParentStatus(CommonITILObject $parentitem, array $input):
}

if (
!empty($this->fields['begin'])
!$is_set_pending
&& !empty($this->fields['begin'])
&& $parentitem->isStatusExists(CommonITILObject::PLANNED)
&& (($parentitem->fields["status"] == CommonITILObject::INCOMING)
|| ($parentitem->fields["status"] == CommonITILObject::ASSIGNED)
Expand Down
64 changes: 64 additions & 0 deletions tests/functional/TicketTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,68 @@ public function testAddFromTemplate()
$this->integer($task->fields['state'])->isEqualTo(\Planning::TODO);
$this->integer($task->fields['is_private'])->isEqualTo(0);
}

public function testUpdateParentStatus()
{
$this->login();
$ticket_id = $this->getNewTicket();
$task = new \TicketTask();

$uid = getItemByTypeName('User', TU_USER, true);
$date_begin = new \DateTime(); // ==> now
$date_begin_string = $date_begin->format('Y-m-d H:i:s');
$date_end = new \DateTime(); // ==> +2days
$date_end->add(new \DateInterval('P2D'));
$date_end_string = $date_end->format('Y-m-d H:i:s');

$this->integer($task->add([
'pending' => 1,
'tickets_id' => $ticket_id,
'content' => "Task with schedule",
'state' => \Planning::TODO,
'users_id_tech' => $uid,
'begin' => $date_begin_string,
'end' => $date_end_string,
]))->isGreaterThan(0);

$this->integer(\Ticket::getById($ticket_id)->fields['status'])->isEqualTo(\Ticket::WAITING);

$date_begin = new \DateTime(); // ==> +3days
$date_begin->add(new \DateInterval('P3D'));
$date_begin_string = $date_begin->format('Y-m-d H:i:s');
$date_end = new \DateTime(); // ==> +4days
$date_end->add(new \DateInterval('P4D'));
$date_end_string = $date_end->format('Y-m-d H:i:s');

$this->integer($task->add([
'pending' => 0,
'tickets_id' => $ticket_id,
'content' => "Task with schedule",
'state' => \Planning::TODO,
'users_id_tech' => $uid,
'begin' => $date_begin_string,
'end' => $date_end_string,
]))->isGreaterThan(0);

$this->integer(\Ticket::getById($ticket_id)->fields['status'])->isEqualTo(\Ticket::PLANNED);

$date_begin = new \DateTime(); // ==> +5days
$date_begin->add(new \DateInterval('P5D'));
$date_begin_string = $date_begin->format('Y-m-d H:i:s');
$date_end = new \DateTime(); // ==> +6days
$date_end->add(new \DateInterval('P6D'));
$date_end_string = $date_end->format('Y-m-d H:i:s');

$this->integer($task->add([
'pending' => 1,
'tickets_id' => $ticket_id,
'content' => "Task with schedule",
'state' => \Planning::TODO,
'users_id_tech' => $uid,
'begin' => $date_begin_string,
'end' => $date_end_string,
]))->isGreaterThan(0);

$this->integer(\Ticket::getById($ticket_id)->fields['status'])->isEqualTo(\Ticket::WAITING);
}
}

0 comments on commit 517eeed

Please sign in to comment.