Browse Source

Fix tests, remove ls from ci config

tags/3.1.0
Mike Koch 2 years ago
parent
commit
7300b5bd5f

+ 0
- 1
.gitlab-ci.yml View File

@@ -6,5 +6,4 @@ before_script:
test:app:
script:
- cd api/Tests
- ls
- phpunit

+ 1
- 1
api/BusinessLogic/Attachments/AttachmentRetriever.php View File

@@ -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}!");
}


+ 5
- 0
api/Tests/BusinessLogic/Attachments/AttachmentRetrieverTest.php View File

@@ -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);

+ 1
- 0
api/Tests/BusinessLogic/Tickets/TicketDeleterTest.php View File

@@ -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

+ 6
- 1
api/Tests/BusinessLogic/Tickets/TicketRetrieverTest.php View File

@@ -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() {

+ 2
- 2
api/Tests/BusinessLogic/Tickets/TrackingIdGeneratorTest.php View File

@@ -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 {

Loading…
Cancel
Save