Skip to content

Commit

Permalink
fix(SO): Add a search option to retrieve the latest follow-up, tasks,…
Browse files Browse the repository at this point in the history
… and solution
  • Loading branch information
MyvTsv authored Nov 26, 2024
1 parent ec80b07 commit 7fbbb96
Show file tree
Hide file tree
Showing 6 changed files with 392 additions and 0 deletions.
113 changes: 113 additions & 0 deletions phpunit/functional/ChangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,117 @@ public function testStatusWhenSolutionIsRefused()
$item = $change->getById($changes_id);
$this->assertSame(\CommonITILObject::INCOMING, $item->fields['status']);
}

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

$last_followup_date = '2016-01-01 00:00:00';
$last_task_date = '2017-01-01 00:00:00';
$last_solution_date = '2018-01-01 00:00:00';

$change = new \Change();
$change_id = $change->add(
[
'name' => 'ticket title',
'content' => 'a description',
'entities_id' => getItemByTypeName('Entity', '_test_root_entity', true),
]
);

$followup = new \ITILFollowup();
$followup->add([
'itemtype' => $change::getType(),
'items_id' => $change_id,
'content' => 'followup content',
'date' => '2015-01-01 00:00:00',
]);

$followup->add([
'itemtype' => $change::getType(),
'items_id' => $change_id,
'content' => 'followup content',
'date' => '2015-02-01 00:00:00',
]);

$task = new \ChangeTask();
$this->assertGreaterThan(
0,
(int)$task->add([
'changes_id' => $change_id,
'content' => 'A simple Task',
'date' => '2015-01-01 00:00:00',
])
);

$this->assertGreaterThan(
0,
(int)$task->add([
'changes_id' => $change_id,
'content' => 'A simple Task',
'date' => $last_task_date,
])
);

$this->assertGreaterThan(
0,
(int)$task->add([
'changes_id' => $change_id,
'content' => 'A simple Task',
'date' => '2016-01-01 00:00:00',
])
);

$solution = new \ITILSolution();
$this->assertGreaterThan(
0,
(int)$solution->add([
'itemtype' => $change::getType(),
'items_id' => $change_id,
'content' => 'solution content',
'date_creation' => '2017-01-01 00:00:00',
'status' => 2,
])
);

$this->assertGreaterThan(
0,
(int)$followup->add([
'itemtype' => $change::getType(),
'items_id' => $change_id,
'add_reopen' => '1',
'content' => 'This is required',
'date' => $last_followup_date,
])
);

$this->assertGreaterThan(
0,
(int)$solution->add([
'itemtype' => $change::getType(),
'items_id' => $change_id,
'content' => 'solution content',
'date_creation' => $last_solution_date,
])
);

$criteria = [
[
'link' => 'AND',
'field' => 2,
'searchtype' => 'contains',
'value' => $change_id,
]
];
$data = \Search::getDatas($change->getType(), ["criteria" => $criteria], [72,73,74]);
$this->assertSame(1, $data['data']['totalcount']);
$change_with_so = $data['data']['rows'][0]['raw'];
$this->assertEquals($change_id, $change_with_so['id']);
$this->assertTrue(array_key_exists('ITEM_Change_72', $change_with_so));
$this->assertEquals($last_followup_date, $change_with_so['ITEM_Change_72']);
$this->assertTrue(array_key_exists('ITEM_Change_73', $change_with_so));
$this->assertEquals($last_task_date, $change_with_so['ITEM_Change_73']);
$this->assertTrue(array_key_exists('ITEM_Change_74', $change_with_so));
$this->assertEquals($last_solution_date, $change_with_so['ITEM_Change_74']);
}
}
113 changes: 113 additions & 0 deletions phpunit/functional/ProblemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,117 @@ public function testGetTeamRoleName(): void
$this->assertNotEmpty(\Problem::getTeamRoleName($role));
}
}

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

$last_followup_date = '2016-01-01 00:00:00';
$last_task_date = '2017-01-01 00:00:00';
$last_solution_date = '2018-01-01 00:00:00';

$problem = new \Problem();
$problem_id = $problem->add(
[
'name' => 'ticket title',
'content' => 'a description',
'entities_id' => getItemByTypeName('Entity', '_test_root_entity', true),
]
);

$followup = new \ITILFollowup();
$followup->add([
'itemtype' => $problem::getType(),
'items_id' => $problem_id,
'content' => 'followup content',
'date' => '2015-01-01 00:00:00',
]);

$followup->add([
'itemtype' => $problem::getType(),
'items_id' => $problem_id,
'content' => 'followup content',
'date' => '2015-02-01 00:00:00',
]);

$task = new \ProblemTask();
$this->assertGreaterThan(
0,
(int)$task->add([
'problems_id' => $problem_id,
'content' => 'A simple Task',
'date' => '2015-01-01 00:00:00',
])
);

$this->assertGreaterThan(
0,
(int)$task->add([
'problems_id' => $problem_id,
'content' => 'A simple Task',
'date' => $last_task_date,
])
);

$this->assertGreaterThan(
0,
(int)$task->add([
'problems_id' => $problem_id,
'content' => 'A simple Task',
'date' => '2016-01-01 00:00:00',
])
);

$solution = new \ITILSolution();
$this->assertGreaterThan(
0,
(int)$solution->add([
'itemtype' => $problem::getType(),
'items_id' => $problem_id,
'content' => 'solution content',
'date_creation' => '2017-01-01 00:00:00',
'status' => 2,
])
);

$this->assertGreaterThan(
0,
(int)$followup->add([
'itemtype' => $problem::getType(),
'items_id' => $problem_id,
'add_reopen' => '1',
'content' => 'This is required',
'date' => $last_followup_date,
])
);

$this->assertGreaterThan(
0,
(int)$solution->add([
'itemtype' => $problem::getType(),
'items_id' => $problem_id,
'content' => 'solution content',
'date_creation' => $last_solution_date,
])
);

$criteria = [
[
'link' => 'AND',
'field' => 2,
'searchtype' => 'contains',
'value' => $problem_id,
]
];
$data = \Search::getDatas($problem->getType(), ["criteria" => $criteria], [72,73,74]);
$this->assertSame(1, $data['data']['totalcount']);
$problem_with_so = $data['data']['rows'][0]['raw'];
$this->assertEquals($problem_id, $problem_with_so['id']);
$this->assertTrue(array_key_exists('ITEM_Problem_72', $problem_with_so));
$this->assertEquals($last_followup_date, $problem_with_so['ITEM_Problem_72']);
$this->assertTrue(array_key_exists('ITEM_Problem_73', $problem_with_so));
$this->assertEquals($last_task_date, $problem_with_so['ITEM_Problem_73']);
$this->assertTrue(array_key_exists('ITEM_Problem_74', $problem_with_so));
$this->assertEquals($last_solution_date, $problem_with_so['ITEM_Problem_74']);
}
}
113 changes: 113 additions & 0 deletions phpunit/functional/TicketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,119 @@ public function testCreateTicketWithActors(array $actors_input, array $expected_
$this->checkActors($ticket, $expected_actors);
}

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

$last_followup_date = '2016-01-01 00:00:00';
$last_task_date = '2017-01-01 00:00:00';
$last_solution_date = '2018-01-01 00:00:00';

$ticket = new \Ticket();
$ticket_id = $ticket->add(
[
'name' => 'ticket title',
'content' => 'a description',
'entities_id' => getItemByTypeName('Entity', '_test_root_entity', true),
]
);

$followup = new \ITILFollowup();
$followup->add([
'itemtype' => $ticket::getType(),
'items_id' => $ticket_id,
'content' => 'followup content',
'date' => '2015-01-01 00:00:00',
]);

$followup->add([
'itemtype' => $ticket::getType(),
'items_id' => $ticket_id,
'content' => 'followup content',
'date' => '2015-02-01 00:00:00',
]);

$task = new \TicketTask();
$this->assertGreaterThan(
0,
(int)$task->add([
'tickets_id' => $ticket_id,
'content' => 'A simple Task',
'date' => '2015-01-01 00:00:00',
])
);

$this->assertGreaterThan(
0,
(int)$task->add([
'tickets_id' => $ticket_id,
'content' => 'A simple Task',
'date' => $last_task_date,
])
);

$this->assertGreaterThan(
0,
(int)$task->add([
'tickets_id' => $ticket_id,
'content' => 'A simple Task',
'date' => '2016-01-01 00:00:00',
])
);

$solution = new \ITILSolution();
$this->assertGreaterThan(
0,
(int)$solution->add([
'itemtype' => $ticket::getType(),
'items_id' => $ticket_id,
'content' => 'solution content',
'date_creation' => '2017-01-01 00:00:00',
'status' => 2,
])
);

$this->assertGreaterThan(
0,
(int)$followup->add([
'itemtype' => $ticket::getType(),
'items_id' => $ticket_id,
'add_reopen' => '1',
'content' => 'This is required',
'date' => $last_followup_date,
])
);

$this->assertGreaterThan(
0,
(int)$solution->add([
'itemtype' => $ticket::getType(),
'items_id' => $ticket_id,
'content' => 'solution content',
'date_creation' => $last_solution_date,
])
);

$criteria = [
[
'link' => 'AND',
'field' => 2,
'searchtype' => 'contains',
'value' => $ticket_id,
]
];
$data = \Search::getDatas($ticket->getType(), ["criteria" => $criteria], [72,73,74]);
$this->assertSame(1, $data['data']['totalcount']);
$ticket_with_so = $data['data']['rows'][0]['raw'];
$this->assertEquals($ticket_id, $ticket_with_so['id']);
$this->assertTrue(array_key_exists('ITEM_Ticket_72', $ticket_with_so));
$this->assertEquals($last_followup_date, $ticket_with_so['ITEM_Ticket_72']);
$this->assertTrue(array_key_exists('ITEM_Ticket_73', $ticket_with_so));
$this->assertEquals($last_task_date, $ticket_with_so['ITEM_Ticket_73']);
$this->assertTrue(array_key_exists('ITEM_Ticket_74', $ticket_with_so));
$this->assertEquals($last_solution_date, $ticket_with_so['ITEM_Ticket_74']);
}


public static function updateActorsProvider(): iterable
{
Expand Down
15 changes: 15 additions & 0 deletions src/CommonITILObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4365,6 +4365,21 @@ public function getSearchOptionsSolution()
]
];

$tab[] = [
'id' => '74',
'table' => ITILSolution::getTable(),
'field' => 'date_creation',
'name' => _n('Latest date', 'Latest dates', 1),
'datatype' => 'datetime',
'massiveaction' => false,
'forcegroupby' => true,
'joinparams' => [
'jointype' => 'itemtype_item',
],
'computation' => 'MAX( ' . $DB->quoteName('TABLE.date_creation') . ')',
'nometa' => true // cannot GROUP_CONCAT a MAX
];

return $tab;
}

Expand Down
Loading

0 comments on commit 7fbbb96

Please sign in to comment.