Skip to content

Commit f1f4ea2

Browse files
committed
test ticket list for item
1 parent 72427ee commit f1f4ea2

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/functional/Ticket.php

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

0 commit comments

Comments
 (0)