Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: root <root@f076b06091fd>
  • Loading branch information
root committed Dec 9, 2018
1 parent 85389b2 commit 84227e2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
12 changes: 7 additions & 5 deletions lib/Controller/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private function getThumbnail($fileId, $square, $scale) {
/** @type File $file */
list($file, $preview, $status) =
$this->getData(
$fileId, $width, $height, $aspect, $animatedPreview, $base64Encode
$fileId, null, $width, $height, $aspect, $animatedPreview, $base64Encode
);
if ($preview === null) {
$preview = $this->prepareEmptyThumbnail($file, $status);
Expand All @@ -107,17 +107,19 @@ private function getThumbnail($fileId, $square, $scale) {
* @throws NotFoundServiceException
*/
private function getData(
$fileId, $width, $height, $keepAspect = true, $animatedPreview = true, $base64Encode = false
$fileId, $etag, $width, $height, $keepAspect = true, $animatedPreview = true, $base64Encode = false
) {
/** @type File $file */
list($file, $status) = $this->getFile($fileId);
try {
if (!is_null($file)) {
if (is_null($file)) {
$data = $this->getErrorData($status);
} else if (!is_null($etag) && $etag === $file->getEtag()) {
$data = [null, Http::STATUS_NOT_MODIFIED];
} else {
$data = $this->getPreviewData(
$file, $animatedPreview, $width, $height, $keepAspect, $base64Encode
);
} else {
$data = $this->getErrorData($status);
}
} catch (ServiceException $exception) {
$data = $this->getExceptionData($exception);
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/PreviewApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function getThumbnails($ids, $square, $scale) {
*/
public function getPreview($fileId, $width, $height, $nativesvg = false) {
/** @type File $file */
list($file, $preview, $status) = $this->getData($fileId, $width, $height);
list($file, $preview, $status) = $this->getData($fileId, null, $width, $height);

if (!$preview) {
return new JSONResponse(
Expand Down
9 changes: 4 additions & 5 deletions lib/Controller/PreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,12 @@ public function getThumbnails($ids, $square, $scale) {
*/
public function getPreview($fileId, $width, $height) {
/** @type File $file */
list($file, $status) = $this->getFile($fileId);
if ($this->request->getHeader('If-None-Match') === $file->getEtag()) {
return new DataResponse([], Http::STATUS_NOT_MODIFIED);
}
list($file, $preview, $status) = $this->getData($fileId, $width, $height);
list($file, $preview, $status) = $this->getData($fileId, $this->request->getHeader('If-None-Match'), $width, $height);

if (!$preview) {
if ($status === Http::STATUS_NOT_MODIFIED) {
return new DataResponse([], Http::STATUS_NOT_MODIFIED);
}
return new JSONResponse(
[
'message' => "I'm truly sorry, but we were unable to generate a preview for this file",
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/Controller/PreviewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCA\Gallery\Service\ThumbnailService;
use OCA\Gallery\Service\PreviewService;
use OCA\Gallery\Service\DownloadService;
use OCA\Gallery\Service\FilePropertiesService;
use OCA\Gallery\Utility\EventSource;
use OCA\Gallery\Service\NotFoundServiceException;
use OCA\Gallery\Service\InternalServerErrorServiceException;
Expand Down Expand Up @@ -58,6 +59,8 @@ class PreviewControllerTest extends \OCA\Gallery\Tests\GalleryUnitTest {
protected $previewService;
/** @var DownloadService */
protected $downloadService;
/** @var FilePropertiesService */
protected $filePropertiesService;
/** @var EventSource */
protected $eventSource;
/** @var ILogger */
Expand Down Expand Up @@ -92,6 +95,9 @@ public function setUp() {
$this->downloadService = $this->getMockBuilder('\OCA\Gallery\Service\DownloadService')
->disableOriginalConstructor()
->getMock();
$this->filePropertiesService = $this->getMockBuilder('\OCA\Gallery\Service\FilePropertiesService')
->disableOriginalConstructor()
->getMock();
$this->eventSource = $this->getMockBuilder('\OCA\Gallery\Utility\EventSource')
->disableOriginalConstructor()
->getMock();
Expand All @@ -106,6 +112,7 @@ public function setUp() {
$this->thumbnailService,
$this->previewService,
$this->downloadService,
$this->filePropertiesService,
$this->eventSource,
$this->logger
);
Expand Down
1 change: 1 addition & 0 deletions tests/unit/Controller/PreviewPublicControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function setUp() {
$this->thumbnailService,
$this->previewService,
$this->downloadService,
$this->filePropertiesService,
$this->eventSource,
$this->logger
);
Expand Down

0 comments on commit 84227e2

Please sign in to comment.