userToTicketChecker = $this->createMock(UserToTicketChecker::class); $this->ticketGateway = $this->createMock(TicketGateway::class); $this->attachmentHandler = $this->createMock(AttachmentHandler::class); $this->ticketDeleter = new TicketDeleter($this->ticketGateway, $this->userToTicketChecker, $this->attachmentHandler); } function testItThrowsAnExceptionWhenTheUserDoesNotHavePermissionToDeleteTheTicket() { //-- Arrange $this->ticketGateway->method('getTicketById')->willReturn(new Ticket()); $this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(false); //-- Assert $this->expectException(\Exception::class); $this->expectExceptionMessage("User does not have access to ticket 1"); //-- Act $this->ticketDeleter->deleteTicket(1, $this->userContext, $this->heskSettings); } function testItDeletesAllAttachmentsForTheTicket() { //-- Arrange $ticket = new Ticket(); $attachmentOne = new Attachment(); $attachmentOne->id = 1; $attachmentTwo = new Attachment(); $attachmentTwo->id = 2; $attachments = array($attachmentOne, $attachmentTwo); $ticket->attachments = $attachments; $ticket->replies = array(); $this->ticketGateway->method('getTicketById')->willReturn($ticket); $this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true); //-- Assert $this->attachmentHandler->expects($this->exactly(2))->method('deleteAttachmentFromTicket'); //-- Act $this->ticketDeleter->deleteTicket(1, $this->userContext, $this->heskSettings); } function testItDeletesAllRepliesForTheTicket() { //-- Arrange $ticket = new Ticket(); $ticket->attachments = array(); $ticket->replies = array(); $ticket->id = 1; $this->ticketGateway->method('getTicketById')->willReturn($ticket); $this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true); //-- Assert $this->ticketGateway->expects($this->once())->method('deleteRepliesForTicket')->with(1, $this->heskSettings); //-- Act $this->ticketDeleter->deleteTicket(1, $this->userContext, $this->heskSettings); } function testItDeleteAllReplyDrafts() { //-- Arrange $ticket = new Ticket(); $ticket->attachments = array(); $ticket->replies = array(); $ticket->id = 1; $this->ticketGateway->method('getTicketById')->willReturn($ticket); $this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true); //-- Assert $this->ticketGateway->expects($this->once())->method('deleteReplyDraftsForTicket')->with(1, $this->heskSettings); //-- Act $this->ticketDeleter->deleteTicket(1, $this->userContext, $this->heskSettings); } function testItDeletesTheTicketNotes() { //-- Arrange $ticket = new Ticket(); $ticket->attachments = array(); $ticket->replies = array(); $ticket->id = 1; $this->ticketGateway->method('getTicketById')->willReturn($ticket); $this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true); //-- Assert $this->ticketGateway->expects($this->once())->method('deleteNotesForTicket')->with(1, $this->heskSettings); //-- Act $this->ticketDeleter->deleteTicket(1, $this->userContext, $this->heskSettings); } function testItDeletesTheTicket() { //-- Arrange $ticket = new Ticket(); $ticket->attachments = array(); $ticket->replies = array(); $ticket->id = 1; $this->ticketGateway->method('getTicketById')->willReturn($ticket); $this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true); //-- Assert $this->ticketGateway->expects($this->once())->method('deleteTicket')->with(1, $this->heskSettings); //-- Act $this->ticketDeleter->deleteTicket(1, $this->userContext, $this->heskSettings); } }