Assumes all tables exist, updates tests.
An internal function has now a new signature, it receives a query, and now tests correctly reflect that.
This commit is contained in:
parent
5b16393659
commit
4fd9db8651
|
@ -50,9 +50,6 @@ class SearchController extends Controller {
|
|||
const PATH = '/search';
|
||||
const METHOD = 'POST';
|
||||
private $ignoreDeparmentFilter;
|
||||
private $ticketTableExists;
|
||||
private $tagsTableExists;
|
||||
private $ticketEventTableExists;
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
|
@ -108,9 +105,6 @@ class SearchController extends Controller {
|
|||
|
||||
public function handler() {
|
||||
$this->ignoreDeparmentFilter = (bool)Controller::request('supervisor');
|
||||
$this->ticketTableExists = !empty(RedBean::getAll("SHOW TABLES LIKE 'ticket';"));
|
||||
$this->tagsTableExists = !empty(RedBean::getAll("SHOW TABLES LIKE 'tag_ticket';"));
|
||||
$this->ticketEventTableExists = !empty(RedBean::getAll("SHOW TABLES LIKE 'ticketevent';"));
|
||||
|
||||
$allowedDepartmentsId = [];
|
||||
foreach (Controller::getLoggedUser()->sharedDepartmentList->toArray() as $department) {
|
||||
|
@ -141,20 +135,16 @@ class SearchController extends Controller {
|
|||
$ticket = Ticket::getDataStore($item['id']);
|
||||
array_push($ticketList, $ticket->toArray());
|
||||
}
|
||||
if($this->ticketTableExists){
|
||||
Response::respondSuccess([
|
||||
'tickets' => $ticketList,
|
||||
'pages' => ceil($totalCount / 10),
|
||||
'page' => $inputs['page'] ? ($inputs['page']*1) : 1
|
||||
]);
|
||||
}else{
|
||||
Response::respondSuccess([]);
|
||||
}
|
||||
Response::respondSuccess([
|
||||
'tickets' => $ticketList,
|
||||
'pages' => ceil($totalCount / 10),
|
||||
'page' => $inputs['page'] ? ($inputs['page']*1) : 1
|
||||
]);
|
||||
}
|
||||
|
||||
public function getSQLQuery($inputs) {
|
||||
$taglistQuery = ( $this->tagsTableExists ? " LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id" : '');
|
||||
$ticketeventlistQuery = ( $this->ticketEventTableExists ? " LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id" : '');
|
||||
$taglistQuery = " LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id";
|
||||
$ticketeventlistQuery = " LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id";
|
||||
|
||||
$query = "FROM (ticket" . $taglistQuery . $ticketeventlistQuery .")";
|
||||
$filters = "";
|
||||
|
@ -190,7 +180,7 @@ class SearchController extends Controller {
|
|||
}
|
||||
|
||||
private function setTagFilter($tagList, &$filters){
|
||||
if($tagList && $this->tagsTableExists){
|
||||
if($tagList){
|
||||
$filters != "" ? $filters .= " and " : null;
|
||||
|
||||
foreach($tagList as $key => $tag) {
|
||||
|
@ -333,7 +323,7 @@ class SearchController extends Controller {
|
|||
private function setStringFilter($search, &$filters){
|
||||
if($search !== null){
|
||||
if ($filters != "") $filters .= " and ";
|
||||
$ticketevent = ( $this->ticketEventTableExists ? " or (ticketevent.type = 'COMMENT' and ticketevent.content LIKE :query)" : "");
|
||||
$ticketevent = " or (ticketevent.type = 'COMMENT' and ticketevent.content LIKE :query)";
|
||||
$filters .= " (ticket.title LIKE :query or ticket.content LIKE :query or ticket.ticket_number LIKE :query". $ticketevent ." )";
|
||||
};
|
||||
}
|
||||
|
@ -369,7 +359,7 @@ class SearchController extends Controller {
|
|||
}
|
||||
private function setStringOrder($querysearch, &$order){
|
||||
if($querysearch !== null){
|
||||
$ticketeventOrder = ( $this->ticketEventTableExists ? " WHEN (ticketevent.content LIKE :query) THEN 5 " : "");
|
||||
$ticketeventOrder = " WHEN (ticketevent.content LIKE :query) THEN 5 ";
|
||||
$order .= "CASE WHEN (ticket.ticket_number LIKE :query) THEN 1 WHEN (ticket.title LIKE :queryAtBeginning) THEN 2 WHEN (ticket.title LIKE :query) THEN 3 WHEN ( ticket.content LIKE :query) THEN 4 " . $ticketeventOrder ."END asc, ";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -240,26 +240,29 @@ class SearchControllerTest extends TestCase {
|
|||
);
|
||||
}
|
||||
public function testQueryWithOrder() {
|
||||
$inputs1 = [
|
||||
'page' => 1
|
||||
];
|
||||
$inputs2 = [
|
||||
'page' => 1,
|
||||
'query' => 'stark'
|
||||
];
|
||||
$inputs3 = [
|
||||
'page' => 1,
|
||||
'orderBy' => ['value' => 'closed', 'asc' => 1]
|
||||
];
|
||||
$this->assertEquals(
|
||||
$this->searchController->getSQLQueryWithOrder([
|
||||
'page' => 1
|
||||
]),
|
||||
$this->searchController->getSQLQueryWithOrder($inputs1, $this->searchController->getSQLQuery($inputs1)),
|
||||
"SELECT ticket.id FROM (ticket LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id) GROUP BY ticket.id ORDER BY ticket.closed asc, ticket.owner_id asc, ticket.unread_staff asc, ticket.date desc, ticket.id desc LIMIT 10 OFFSET 0"
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->searchController->getSQLQueryWithOrder([
|
||||
'page' => 1,
|
||||
'query' => 'stark'
|
||||
]),
|
||||
$this->searchController->getSQLQueryWithOrder($inputs2, $this->searchController->getSQLQuery($inputs2)),
|
||||
"SELECT ticket.id FROM (ticket LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id) WHERE (ticket.title LIKE :query or ticket.content LIKE :query or ticket.ticket_number LIKE :query or (ticketevent.type = 'COMMENT' and ticketevent.content LIKE :query) ) GROUP BY ticket.id ORDER BY CASE WHEN (ticket.ticket_number LIKE :query) THEN 1 WHEN (ticket.title LIKE :queryAtBeginning) THEN 2 WHEN (ticket.title LIKE :query) THEN 3 WHEN ( ticket.content LIKE :query) THEN 4 WHEN (ticketevent.content LIKE :query) THEN 5 END asc, ticket.closed asc, ticket.owner_id asc, ticket.unread_staff asc, ticket.date desc, ticket.id desc LIMIT 10 OFFSET 0"
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->searchController->getSQLQueryWithOrder([
|
||||
'page' => 1,
|
||||
'orderBy' => ['value' => 'closed', 'asc' => 1]
|
||||
]),
|
||||
$this->searchController->getSQLQueryWithOrder($inputs3, $this->searchController->getSQLQuery($inputs3)),
|
||||
"SELECT ticket.id FROM (ticket LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id) GROUP BY ticket.id ORDER BY ticket.closed asc,ticket.closed asc, ticket.owner_id asc, ticket.unread_staff asc, ticket.date desc, ticket.id desc LIMIT 10 OFFSET 0"
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue