66 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace BusinessLogic\Attachments;
use BusinessLogic\Security\UserContext;
use BusinessLogic\Security\UserToTicketChecker;
use DataAccess\Attachments\AttachmentGateway;
use DataAccess\Files\FileReader;
use DataAccess\Tickets\TicketGateway;
use PHPUnit\Framework\TestCase;
class AttachmentRetrieverTest extends TestCase {
/* @var $attachmentGateway \PHPUnit_Framework_MockObject_MockObject */
private $attachmentGateway;
/* @var $fileReader \PHPUnit_Framework_MockObject_MockObject */
private $fileReader;
/* @var $ticketGateway \PHPUnit_Framework_MockObject_MockObject */
private $ticketGateway;
/* @var $userToTicketChecker \PHPUnit_Framework_MockObject_MockObject */
private $userToTicketChecker;
/* @var $attachmentRetriever AttachmentRetriever */
private $attachmentRetriever;
2017-04-05 21:56:13 -04:00
/* @var $heskSettings array */
private $heskSettings;
protected function setUp() {
$this->attachmentGateway = $this->createMock(AttachmentGateway::class);
$this->fileReader = $this->createMock(FileReader::class);
$this->ticketGateway = $this->createMock(TicketGateway::class);
$this->userToTicketChecker = $this->createMock(UserToTicketChecker::class);
2017-04-05 21:56:13 -04:00
$this->heskSettings = array('attach_dir' => 'attachments');
$this->attachmentRetriever = new AttachmentRetriever($this->attachmentGateway, $this->fileReader,
$this->ticketGateway, $this->userToTicketChecker);
$this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true);
}
2017-04-05 21:56:13 -04:00
function testItGetsTheMetadataFromTheGateway() {
//-- Arrange
$attachmentMeta = new Attachment();
$attachmentMeta->savedName = '5';
$attachmentContents = 'string';
$expectedContents = base64_encode($attachmentContents);
$this->attachmentGateway->method('getAttachmentById')
->with(4, $this->heskSettings)
->willReturn($attachmentMeta);
$this->fileReader->method('readFromFile')
->with('5', $this->heskSettings['attach_dir'])
->willReturn($attachmentContents);
//-- Act
$actualContents = $this->attachmentRetriever->getAttachmentContentsForTicket(0, 4, new UserContext(), $this->heskSettings);
2017-04-05 21:56:13 -04:00
//-- Assert
self::assertThat($actualContents, self::equalTo($expectedContents));
}
}