/** * Makes sure we return previews of the asked dimensions and fix the cache * if necessary * * @param bool $square * @param bool $base64Encode * * @return \OC_Image|string * @throws InternalServerErrorServiceException */ public function previewValidator($square, $base64Encode) { try { $preview = $this->previewManager->previewValidator($square); if ($base64Encode) { $preview = $this->encode($preview); } return $preview; } catch (\Exception $exception) { throw new InternalServerErrorServiceException('There was an error while trying to fix the preview'); } }
/** * Without a defined datadirectory, the thumbnail can't be saved and the original preview will * be used * * Ideally, Image->save should be mocked, but the mock is never called */ public function testPreviewValidatorWhenCannotSaveThumbnail() { $maxWidth = $width = 400; $maxHeight = $height = 200; $width = 500; $height = 100; $square = false; $fileId = 12345; $file = $this->mockFile($fileId); self::invokePrivate($this->previewManager, 'file', [$file]); self::invokePrivate($this->previewManager, 'dims', [[$maxWidth, $maxHeight]]); $preview = $this->mockGetPreview($fileId, $width, $height); self::invokePrivate($this->previewManager, 'preview', [$preview]); $response = $this->previewManager->previewValidator($square); $this->assertEquals([$width, $height], [$response->width(), $response->height()]); }