Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/gallery.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorOlivier Paroz <github@oparoz.com>2015-09-20 22:58:42 +0300
committerOlivier Paroz <github@oparoz.com>2015-09-20 22:58:42 +0300
commit6ee8b3c62c0543832ff3ba4ef90e9413dd4bf279 (patch)
treed511c19e680773d6cf116158f837396412770deb /tests
parent7bf0b3545372b0af0e9f8fb13b4924cf03303921 (diff)
Updated tests for FilesController and ConfigService
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/controller/FilesControllerTest.php32
-rw-r--r--tests/unit/service/ConfigServiceTest.php52
2 files changed, 60 insertions, 24 deletions
diff --git a/tests/unit/controller/FilesControllerTest.php b/tests/unit/controller/FilesControllerTest.php
index 00b45734..a9e45860 100644
--- a/tests/unit/controller/FilesControllerTest.php
+++ b/tests/unit/controller/FilesControllerTest.php
@@ -15,6 +15,7 @@ namespace OCA\Gallery\Controller;
use OCA\Gallery\Service\ServiceException;
use OCP\IRequest;
use OCP\IURLGenerator;
+use OCP\Files\File;
use OCP\ILogger;
use OCP\AppFramework\IAppContainer;
@@ -105,18 +106,35 @@ class FilesControllerTest extends \Test\GalleryUnitTest {
);
}
- public function testDownload() {
- $fileId = 1234;
- $filename = null;
+ /**
+ * @return array
+ */
+ public function providesTestDownloadData() {
+ return [
+ [1234, $this->mockJpgFile(1234), 'image/jpeg'],
+ [4567, $this->mockSvgFile(4567), 'text/plain']
+ ];
+ }
- $download = $this->mockGetDownload($fileId, $filename);
+ /**
+ * @dataProvider providesTestDownloadData
+ *
+ * @param int $fileId
+ * @param File $file
+ * @param string $expectedMimeType
+ *
+ * @internal param string $type
+ */
+ public function testDownload($fileId, $file, $expectedMimeType) {
+ $filename = null;
+ $download = $this->mockGetDownload($fileId, $file, $filename);
/** @type ImageResponse $response */
$response = $this->controller->download($fileId, $filename);
$this->assertEquals(Http::STATUS_OK, $response->getStatus());
$this->assertEquals(
- $download['mimetype'] . '; charset=utf-8', $response->getHeaders()['Content-type']
+ $expectedMimeType . '; charset=utf-8', $response->getHeaders()['Content-type']
);
$this->assertEquals($download['preview'], $response->render());
}
@@ -262,9 +280,7 @@ class FilesControllerTest extends \Test\GalleryUnitTest {
*
* @return array
*/
- private function mockGetDownload($fileId, $filename) {
- $file = $this->mockFile($fileId);
-
+ private function mockGetDownload($fileId, $file, $filename) {
$this->mockGetResourceFromId($this->downloadService, $fileId, $file);
$download = $this->mockDownloadData($file, $filename);
diff --git a/tests/unit/service/ConfigServiceTest.php b/tests/unit/service/ConfigServiceTest.php
index 1638d6e6..f39ef84e 100644
--- a/tests/unit/service/ConfigServiceTest.php
+++ b/tests/unit/service/ConfigServiceTest.php
@@ -110,6 +110,19 @@ class ConfigServiceTest extends \Test\GalleryUnitTest {
$this->assertSame($expectedResult, $response);
}
+ public function testGetSupportedMediaTypesWithBrokenPreviewSystem() {
+ // We only support 1 media type: GIF
+ self::invokePrivate($this->service, 'baseMimeTypes', [['image/gif']]);
+
+ // Unfortunately, the GIF preview is broken
+ $this->mockIsMimeSupportedWithBrokenSystem('image/gif');
+
+ $response = $this->service->getSupportedMediaTypes(false, false);
+
+ // 1-1 = 0
+ $this->assertEmpty($response);
+ }
+
public function providesValidateMimeTypeData() {
return [
['image/png'],
@@ -264,22 +277,6 @@ class ConfigServiceTest extends \Test\GalleryUnitTest {
];
}
- private function mockIsMimeSupported($mimeSupported) {
- $map = [
- ['image/png', true],
- ['image/jpeg', true],
- ['application/postscript', true],
- ['application/font-sfnt', true],
- ['application/x-font', true],
- ['image/svg+xml', $mimeSupported],
- ['image/gif', $mimeSupported]
- ];
- $this->previewManager->method('isMimeSupported')
- ->will(
- $this->returnValueMap($map)
- );
- }
-
/**
* @dataProvider providesValidatesInfoConfigData
*
@@ -301,6 +298,29 @@ class ConfigServiceTest extends \Test\GalleryUnitTest {
$this->assertSame($modifiedAlbumConfig, $response);
}
+ private function mockIsMimeSupported($mimeSupported) {
+ $map = [
+ ['image/png', true],
+ ['image/jpeg', true],
+ ['application/postscript', true],
+ ['application/font-sfnt', true],
+ ['application/x-font', true],
+ ['image/svg+xml', $mimeSupported],
+ ['image/gif', $mimeSupported]
+ ];
+ $this->previewManager->method('isMimeSupported')
+ ->will(
+ $this->returnValueMap($map)
+ );
+ }
+
+ private function mockIsMimeSupportedWithBrokenSystem($mimeType) {
+ $this->previewManager->expects($this->once())
+ ->method('isMimeSupported')
+ ->with($mimeType)
+ ->willThrowException(new \Exception('Boom'));
+ }
+
private function mockGetFolderConfigWithBrokenSetup(
$folder, $configName, $config, $configItems, $level, $exception
) {