From 7300b5bd5fd3794fe4162a0f56c352c47b19af08 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Thu, 22 Jun 2017 22:06:00 -0400 Subject: [PATCH] Fix tests, remove ls from ci config --- .gitlab-ci.yml | 1 - api/BusinessLogic/Attachments/AttachmentRetriever.php | 2 +- .../BusinessLogic/Attachments/AttachmentRetrieverTest.php | 5 +++++ api/Tests/BusinessLogic/Tickets/TicketDeleterTest.php | 1 + api/Tests/BusinessLogic/Tickets/TicketRetrieverTest.php | 7 ++++++- .../BusinessLogic/Tickets/TrackingIdGeneratorTest.php | 4 ++-- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3a7c2f0f..cca1e560 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,5 +6,4 @@ before_script: test:app: script: - cd api/Tests - - ls - phpunit \ No newline at end of file diff --git a/api/BusinessLogic/Attachments/AttachmentRetriever.php b/api/BusinessLogic/Attachments/AttachmentRetriever.php index 59fdcc54..eb5b57c5 100644 --- a/api/BusinessLogic/Attachments/AttachmentRetriever.php +++ b/api/BusinessLogic/Attachments/AttachmentRetriever.php @@ -37,7 +37,7 @@ class AttachmentRetriever { throw new ApiFriendlyException("Ticket {$ticketId} not found!", "Ticket Not Found", 404); } - if ($this->userToTicketChecker->isTicketAccessibleToUser($userContext, $ticket, $heskSettings)) { + if (!$this->userToTicketChecker->isTicketAccessibleToUser($userContext, $ticket, $heskSettings)) { throw new AccessViolationException("User does not have access to attachment {$attachmentId}!"); } diff --git a/api/Tests/BusinessLogic/Attachments/AttachmentRetrieverTest.php b/api/Tests/BusinessLogic/Attachments/AttachmentRetrieverTest.php index 5017ea91..776fe1eb 100644 --- a/api/Tests/BusinessLogic/Attachments/AttachmentRetrieverTest.php +++ b/api/Tests/BusinessLogic/Attachments/AttachmentRetrieverTest.php @@ -6,6 +6,7 @@ namespace BusinessLogic\Attachments; use BusinessLogic\Security\UserContext; use BusinessLogic\Security\UserToTicketChecker; +use BusinessLogic\Tickets\Ticket; use DataAccess\Attachments\AttachmentGateway; use DataAccess\Files\FileReader; use DataAccess\Tickets\TicketGateway; @@ -55,6 +56,10 @@ class AttachmentRetrieverTest extends TestCase { $this->fileReader->method('readFromFile') ->with('5', $this->heskSettings['attach_dir']) ->willReturn($attachmentContents); + $this->ticketGateway->method('getTicketById') + ->willReturn(new Ticket()); + $this->userToTicketChecker->method('isTicketAccessibleToUser') + ->willReturn(true); //-- Act $actualContents = $this->attachmentRetriever->getAttachmentContentsForTicket(0, 4, new UserContext(), $this->heskSettings); diff --git a/api/Tests/BusinessLogic/Tickets/TicketDeleterTest.php b/api/Tests/BusinessLogic/Tickets/TicketDeleterTest.php index 4ac994a8..bce86231 100644 --- a/api/Tests/BusinessLogic/Tickets/TicketDeleterTest.php +++ b/api/Tests/BusinessLogic/Tickets/TicketDeleterTest.php @@ -39,6 +39,7 @@ class TicketDeleterTest extends TestCase { function testItThrowsAnExceptionWhenTheUserDoesNotHavePermissionToDeleteTheTicket() { //-- Arrange + $this->ticketGateway->method('getTicketById')->willReturn(new Ticket()); $this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(false); //-- Assert diff --git a/api/Tests/BusinessLogic/Tickets/TicketRetrieverTest.php b/api/Tests/BusinessLogic/Tickets/TicketRetrieverTest.php index 6fd6b168..8065c5a7 100644 --- a/api/Tests/BusinessLogic/Tickets/TicketRetrieverTest.php +++ b/api/Tests/BusinessLogic/Tickets/TicketRetrieverTest.php @@ -3,6 +3,7 @@ namespace BusinessLogic\Tickets; +use BusinessLogic\Security\UserToTicketChecker; use DataAccess\Tickets\TicketGateway; use PHPUnit\Framework\TestCase; @@ -13,14 +14,18 @@ class TicketRetrieverTest extends TestCase { /* @var $ticketGateway \PHPUnit_Framework_MockObject_MockObject */ private $ticketGateway; + /* @var $userToTicketChecker \PHPUnit_Framework_MockObject_MockObject */ + private $userToTicketChecker; + /* @var $heskSettings array */ private $heskSettings; protected function setUp() { $this->ticketGateway = $this->createMock(TicketGateway::class); + $this->userToTicketChecker = $this->createMock(UserToTicketChecker::class); $this->heskSettings = array('email_view_ticket' => 0); - $this->ticketRetriever = new TicketRetriever($this->ticketGateway); + $this->ticketRetriever = new TicketRetriever($this->ticketGateway, $this->userToTicketChecker); } function testItGetsTheTicketByTrackingId() { diff --git a/api/Tests/BusinessLogic/Tickets/TrackingIdGeneratorTest.php b/api/Tests/BusinessLogic/Tickets/TrackingIdGeneratorTest.php index 0ef20b1f..f879e579 100644 --- a/api/Tests/BusinessLogic/Tickets/TrackingIdGeneratorTest.php +++ b/api/Tests/BusinessLogic/Tickets/TrackingIdGeneratorTest.php @@ -41,8 +41,8 @@ class TrackingIdGeneratorTest extends TestCase { function testItThrowsAnExceptionWhenItWasUnableToGenerateAValidTrackingId() { //-- Arrange $exceptionThrown = false; - $this->ticketGateway->method('getTicketByTrackingId') - ->willReturn(new Ticket()); + $this->ticketGateway->method('doesTicketExist') + ->willReturn(true); //-- Act try {