Skip to content

Commit 1254b32

Browse files
committed
test ticket list for item
1 parent ffd7cd9 commit 1254b32

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

tests/functional/Ticket.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
use Ticket_User;
5555
use TicketValidation;
5656
use User;
57+
use Session;
5758

5859
/* Test for inc/ticket.class.php */
5960

@@ -6984,4 +6985,69 @@ public function testRestrictedDropdownValues()
69846985
$this->array($values['results'])->size->isGreaterThan(1);
69856986
$this->boolean($fn_dropdown_has_id($values['results'], $not_my_tickets_id))->isTrue();
69866987
}
6988+
6989+
public function testGetCommonCriteria() {
6990+
global $DB;
6991+
6992+
$this->login('tech', 'tech');
6993+
6994+
$item = new \Project();
6995+
$item->add([
6996+
'name' => $this->getUniqueString(),
6997+
]);
6998+
$this->boolean($item->isNewItem())->isFalse();
6999+
7000+
// Find tickets already in the entity
7001+
$request = \Ticket::getCommonCriteria();
7002+
$request['WHERE'] = \Ticket::getListForItemRestrict($item);
7003+
$request['WHERE'] = $request['WHERE'] + getEntitiesRestrictCriteria(\Ticket::getTable());
7004+
$result = $DB->request($request);
7005+
$existing_tickets = $result->count();
7006+
7007+
// Create a ticket with no actor and a valdiator
7008+
$ticket = new \Ticket();
7009+
$ticket->add([
7010+
'name' => __FUNCTION__,
7011+
'content' => __FUNCTION__,
7012+
'entities_id' => $this->getTestRootEntity(true),
7013+
'users_id_recipient' => User::getIdByName('tech'),
7014+
]);
7015+
$this->boolean($ticket->isNewItem())->isFalse();
7016+
7017+
$item_ticket= new \Item_Ticket();
7018+
$item_ticket->add([
7019+
'tickets_id' => $ticket->getID(),
7020+
'itemtype' => $item->getType(),
7021+
'items_id' => $item->getID(),
7022+
]);
7023+
$this->boolean($item_ticket->isNewItem())->isFalse();
7024+
7025+
$user = new \Ticket_User();
7026+
$users = $user->find([
7027+
'tickets_id' => $ticket->getID(),
7028+
]);
7029+
$this->integer(count($users))->IsEqualTo(0);
7030+
7031+
$this->login('post-only', 'postonly');
7032+
$_SESSION['glpiactiveprofile'][\TicketValidation::$rightname] = \TicketValidation::VALIDATEINCIDENT + \TicketValidation::VALIDATEREQUEST;
7033+
7034+
// Check the ticket is not found
7035+
$request['WHERE'] = \Ticket::getListForItemRestrict($item);
7036+
$request['WHERE'] = $request['WHERE'] + getEntitiesRestrictCriteria(\Ticket::getTable());
7037+
$result = $DB->request($request);
7038+
$this->integer($result->count())->isEqualTo($existing_tickets);
7039+
7040+
$ticket_valdiation = new TicketValidation();
7041+
$ticket_valdiation->add([
7042+
'tickets_id' => $ticket->getID(),
7043+
'entities_id' => $ticket->fields['entities_id'],
7044+
'users_id_validate' => Session::getLoginUserID(),
7045+
'timeline_position' => 1,
7046+
]);
7047+
$this->boolean($ticket_valdiation->isNewItem())->isFalse();
7048+
7049+
// Check the ticket under valdiation is found
7050+
$result = $DB->request($request);
7051+
$this->integer($result->count())->isEqualTo($existing_tickets + 1);
7052+
}
69877053
}

0 commit comments

Comments
 (0)