Attachments should be retrievable

remotes/upstream/api-rewrite
Mike Koch 7 years ago
parent 3cec244e15
commit c58867577f

@ -19,6 +19,10 @@ class AttachmentRetriever {
}
function getAttachmentContentsForTicket($id, $heskSettings) {
$attachment = $this->attachmentGateway->getAttachmentById($id, $heskSettings);
$contents = base64_encode($this->fileReader->readFromFile(
$attachment->savedName, $heskSettings['attach_dir']));
return $contents;
}
}

@ -7,11 +7,10 @@ class FileReader {
/**
* @param $name string - The file name (including extension)
* @param $folder - The folder name (relative to the ROOT of the helpdesk)
* @param $contents string - The contents of the file to write
* @return int The file size, in bytes
* @returns string - The contents of the file to write
* @throws \Exception When the file fails to save
*/
function readFromFile($name, $folder, $contents) {
function readFromFile($name, $folder) {
// __DIR__ === '/{ROOT}/api/DataAccess/Files
$location = __DIR__ . "/../../../{$folder}/{$name}";
$fileContents = file_get_contents($location);

@ -18,14 +18,34 @@ class AttachmentRetrieverTest extends TestCase {
/* @var $attachmentRetriever AttachmentRetriever */
private $attachmentRetriever;
/* @var $heskSettings array */
private $heskSettings;
protected function setUp() {
$this->attachmentGateway = $this->createMock(AttachmentGateway::class);
$this->fileReader = $this->createMock(FileReader::class);
$this->heskSettings = array('attach_dir' => 'attachments');
$this->attachmentRetriever = new AttachmentRetriever($this->attachmentGateway, $this->fileReader);
}
function testItGetsTheAttachmentFromTheFilesystem() {
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(4, $this->heskSettings);
//-- Assert
self::assertThat($actualContents, self::equalTo($expectedContents));
}
}

Loading…
Cancel
Save