diff options
author | Olivier Paroz <github@oparoz.com> | 2015-09-18 22:56:16 +0300 |
---|---|---|
committer | Olivier Paroz <github@oparoz.com> | 2015-09-20 22:22:12 +0300 |
commit | f74f8acc349d9a411978d87940c8434ec7a7e657 (patch) | |
tree | 04b440ea500ba64be1f4efcb3fe2d8ab030680d9 /tests | |
parent | 6703b408601cb983b3b019e55efc7334b1518964 (diff) |
Only serve the media types we support
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/controller/ConfigApiControllerTest.php | 1 | ||||
-rw-r--r-- | tests/unit/controller/ConfigControllerTest.php | 3 | ||||
-rw-r--r-- | tests/unit/controller/ConfigPublicControllerTest.php | 1 | ||||
-rw-r--r-- | tests/unit/controller/PreviewApiControllerTest.php | 1 | ||||
-rw-r--r-- | tests/unit/controller/PreviewControllerTest.php | 10 | ||||
-rw-r--r-- | tests/unit/controller/PreviewPublicControllerTest.php | 1 | ||||
-rw-r--r-- | tests/unit/service/ConfigServiceTest.php | 186 | ||||
-rw-r--r-- | tests/unit/service/PreviewServiceTest.php | 92 |
8 files changed, 199 insertions, 96 deletions
diff --git a/tests/unit/controller/ConfigApiControllerTest.php b/tests/unit/controller/ConfigApiControllerTest.php index 35c65ab8..c6221c14 100644 --- a/tests/unit/controller/ConfigApiControllerTest.php +++ b/tests/unit/controller/ConfigApiControllerTest.php @@ -27,7 +27,6 @@ class ConfigApiControllerTest extends ConfigControllerTest { $this->appName, $this->request, $this->configService, - $this->previewService, $this->logger ); } diff --git a/tests/unit/controller/ConfigControllerTest.php b/tests/unit/controller/ConfigControllerTest.php index 0d5932e6..95ecbbd9 100644 --- a/tests/unit/controller/ConfigControllerTest.php +++ b/tests/unit/controller/ConfigControllerTest.php @@ -77,7 +77,6 @@ class ConfigControllerTest extends \Test\TestCase { $this->appName, $this->request, $this->configService, - $this->previewService, $this->logger ); } @@ -202,7 +201,7 @@ class ConfigControllerTest extends \Test\TestCase { * @param $mimeTypes */ private function mockSupportedMediaTypes($slideshow, $nativeSvgSupport, $mimeTypes) { - $this->previewService->expects($this->any()) + $this->configService->expects($this->any()) ->method('getSupportedMediaTypes') ->with( $this->equalTo($slideshow), diff --git a/tests/unit/controller/ConfigPublicControllerTest.php b/tests/unit/controller/ConfigPublicControllerTest.php index dfd6e271..ea1e4e24 100644 --- a/tests/unit/controller/ConfigPublicControllerTest.php +++ b/tests/unit/controller/ConfigPublicControllerTest.php @@ -27,7 +27,6 @@ class ConfigPublicControllerTest extends ConfigControllerTest { $this->appName, $this->request, $this->configService, - $this->previewService, $this->logger ); } diff --git a/tests/unit/controller/PreviewApiControllerTest.php b/tests/unit/controller/PreviewApiControllerTest.php index 1029fa2f..958020ea 100644 --- a/tests/unit/controller/PreviewApiControllerTest.php +++ b/tests/unit/controller/PreviewApiControllerTest.php @@ -27,6 +27,7 @@ class PreviewApiControllerTest extends PreviewControllerTest { $this->appName, $this->request, $this->urlGenerator, + $this->configService, $this->thumbnailService, $this->previewService, $this->downloadService, diff --git a/tests/unit/controller/PreviewControllerTest.php b/tests/unit/controller/PreviewControllerTest.php index e3b0caca..59b16bd7 100644 --- a/tests/unit/controller/PreviewControllerTest.php +++ b/tests/unit/controller/PreviewControllerTest.php @@ -23,6 +23,7 @@ use OCP\AppFramework\Http\JSONResponse; use OCA\Gallery\AppInfo\Application; use OCA\Gallery\Http\ImageResponse; +use OCA\Gallery\Service\ConfigService; use OCA\Gallery\Service\ThumbnailService; use OCA\Gallery\Service\PreviewService; use OCA\Gallery\Service\DownloadService; @@ -47,6 +48,8 @@ class PreviewControllerTest extends \Test\GalleryUnitTest { protected $controller; /** @var IURLGenerator */ protected $urlGenerator; + /** @var ConfigService */ + protected $configService; /** @var ThumbnailService */ protected $thumbnailService; /** @var PreviewService */ @@ -75,6 +78,9 @@ class PreviewControllerTest extends \Test\GalleryUnitTest { $this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator') ->disableOriginalConstructor() ->getMock(); + $this->configService = $this->getMockBuilder('\OCA\Gallery\Service\ConfigService') + ->disableOriginalConstructor() + ->getMock(); $this->thumbnailService = $this->getMockBuilder('\OCA\Gallery\Service\ThumbnailService') ->disableOriginalConstructor() ->getMock(); @@ -94,6 +100,7 @@ class PreviewControllerTest extends \Test\GalleryUnitTest { $this->appName, $this->request, $this->urlGenerator, + $this->configService, $this->thumbnailService, $this->previewService, $this->downloadService, @@ -110,6 +117,9 @@ class PreviewControllerTest extends \Test\GalleryUnitTest { $scale = 2.5; $thumbnailId = 1234; + $file = $this->mockJpgFile($thumbnailId); + $this->mockGetResourceFromId($this->previewService, $thumbnailId, $file); + $this->controller->getThumbnails($thumbnailId, $square, $scale); } diff --git a/tests/unit/controller/PreviewPublicControllerTest.php b/tests/unit/controller/PreviewPublicControllerTest.php index 17dbd514..70a2ed3b 100644 --- a/tests/unit/controller/PreviewPublicControllerTest.php +++ b/tests/unit/controller/PreviewPublicControllerTest.php @@ -27,6 +27,7 @@ class PreviewPublicControllerTest extends PreviewControllerTest { $this->appName, $this->request, $this->urlGenerator, + $this->configService, $this->thumbnailService, $this->previewService, $this->downloadService, diff --git a/tests/unit/service/ConfigServiceTest.php b/tests/unit/service/ConfigServiceTest.php index a44e275f..1638d6e6 100644 --- a/tests/unit/service/ConfigServiceTest.php +++ b/tests/unit/service/ConfigServiceTest.php @@ -15,6 +15,8 @@ namespace OCA\Gallery\Service; use OCA\Gallery\Config\ConfigParser; use OCA\Gallery\Config\ConfigException; +use OCA\Gallery\Preview\Preview; + /** * Class ConfigServiceTest * @@ -26,6 +28,8 @@ class ConfigServiceTest extends \Test\GalleryUnitTest { protected $service; /** @var ConfigParser */ protected $configParser; + /** @var Preview */ + protected $previewManager; /** * Test set up @@ -36,14 +40,180 @@ class ConfigServiceTest extends \Test\GalleryUnitTest { $this->configParser = $this->getMockBuilder('\OCA\Gallery\Config\ConfigParser') ->disableOriginalConstructor() ->getMock(); + $this->previewManager = $this->getMockBuilder('\OCA\Gallery\Preview\Preview') + ->disableOriginalConstructor() + ->getMock(); $this->service = new ConfigService ( $this->appName, $this->environment, $this->configParser, + $this->previewManager, $this->logger ); } + public function providesGetSupportedMediaTypesData() { + $baseMimeTypes = [ + 'image/jpeg', + ]; + + $slideshowMimes = array_merge( + $baseMimeTypes, + [ + 'application/font-sfnt', + 'application/x-font', + ] + ); + + $baseMimeTypesWithSvg = array_merge( + $baseMimeTypes, + [ + 'image/svg+xml', + ] + ); + + $slideshowMimesWithSvg = array_merge( + $slideshowMimes, + [ + 'image/svg+xml', + ] + ); + + return [ + [$baseMimeTypes, false, false, $baseMimeTypes], + [$baseMimeTypes, false, true, $baseMimeTypesWithSvg], + [$baseMimeTypes, true, true, $slideshowMimesWithSvg], + [$baseMimeTypes, true, false, $slideshowMimes], + ]; + } + + /** + * @dataProvider providesGetSupportedMediaTypesData + * + * @param $baseMimeTypes + * @param $extraMediaTypes + * @param $nativeSvgSupport + * @param $expectedResult + */ + public function testGetSupportedMediaTypes( + $baseMimeTypes, $extraMediaTypes, $nativeSvgSupport, $expectedResult + ) { + + $this->assertSame( + $baseMimeTypes, self::invokePrivate($this->service, 'baseMimeTypes', [$baseMimeTypes]) + ); + + $this->mockIsMimeSupported($nativeSvgSupport); + + $response = $this->service->getSupportedMediaTypes($extraMediaTypes, $nativeSvgSupport); + + $this->assertSame($expectedResult, $response); + } + + public function providesValidateMimeTypeData() { + return [ + ['image/png'], + ['image/jpeg'], + ['image/gif'], + ['application/postscript'], + ['application/x-font'] + ]; + } + + /** + * @dataProvider providesValidateMimeTypeData + * + * @param $mimeType + * + */ + public function testValidateMimeType($mimeType) { + $supportedMimeTypes = [ + 'image/png', + 'image/jpeg', + 'image/gif', + 'application/postscript', + 'application/x-font' + ]; + + $this->assertSame( + $supportedMimeTypes, + self::invokePrivate($this->service, 'baseMimeTypes', [$supportedMimeTypes]) + ); + $this->mockIsMimeSupported($nativeSvgSupport = true); + + $this->service->validateMimeType($mimeType); + } + + public function providesValidateMimeTypeWithForbiddenMimeData() { + return [ + ['text/plain'], + ['application/javascript'], + ['application/json'], + ['text/markdown'], + ['application/yaml'], + ['application/xml'], + ]; + } + + /** + * @dataProvider providesValidateMimeTypeWithForbiddenMimeData + * + * @param $mimeType + * + * @expectedException \OCA\Gallery\Service\ForbiddenServiceException + */ + public function testValidateMimeTypeWithForbiddenMime($mimeType) { + $supportedMimeTypes = [ + 'image/png', + 'image/jpeg', + 'image/gif', + 'image/x-xbitmap', + 'image/bmp', + 'application/postscript', + 'application/x-font' + ]; + + $this->assertSame( + $supportedMimeTypes, + self::invokePrivate($this->service, 'baseMimeTypes', [$supportedMimeTypes]) + ); + $this->mockIsMimeSupported($nativeSvgSupport = true); + + $this->service->validateMimeType($mimeType); + } + + public function providesAddSvgSupportData() { + $supportedMimes = [ + 'image/png', + 'image/jpeg', + 'image/gif' + ]; + + $supportedMimesWithSvg = array_merge($supportedMimes, ['image/svg+xml']); + + return [ + [$supportedMimes, true, $supportedMimesWithSvg], + [$supportedMimes, false, $supportedMimes], + [$supportedMimesWithSvg, true, $supportedMimesWithSvg], + [$supportedMimesWithSvg, false, $supportedMimesWithSvg], + ]; + } + + /** + * @dataProvider providesAddSvgSupportData + * + * @param array $supportedMimes + * @param bool $nativeSvgSupport + * @param array $expectedResult + */ + public function testAddSvgSupport($supportedMimes, $nativeSvgSupport, $expectedResult) { + $response = self::invokePrivate( + $this->service, 'addSvgSupport', [$supportedMimes, $nativeSvgSupport] + ); + + $this->assertSame($expectedResult, $response); + } + public function testBuildFolderConfigWithBrokenSetup() { $nodeId = 65965; $files = []; @@ -94,6 +264,22 @@ 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 * diff --git a/tests/unit/service/PreviewServiceTest.php b/tests/unit/service/PreviewServiceTest.php index c9c28152..fa1c1e31 100644 --- a/tests/unit/service/PreviewServiceTest.php +++ b/tests/unit/service/PreviewServiceTest.php @@ -48,64 +48,6 @@ class PreviewServiceTest extends \Test\GalleryUnitTest { ); } - public function providesGetSupportedMediaTypesData() { - $baseMimeTypes = [ - 'image/jpeg', - ]; - - $slideshowMimes = array_merge( - $baseMimeTypes, - [ - 'application/font-sfnt', - 'application/x-font', - ] - ); - - $baseMimeTypesWithSvg = array_merge( - $baseMimeTypes, - [ - 'image/svg+xml', - ] - ); - - $slideshowMimesWithSvg = array_merge( - $slideshowMimes, - [ - 'image/svg+xml', - ] - ); - - return [ - [$baseMimeTypes, false, false, $baseMimeTypes], - [$baseMimeTypes, false, true, $baseMimeTypesWithSvg], - [$baseMimeTypes, true, true, $slideshowMimesWithSvg], - [$baseMimeTypes, true, false, $slideshowMimes], - ]; - } - - /** - * @dataProvider providesGetSupportedMediaTypesData - * - * @param $baseMimeTypes - * @param $extraMediaTypes - * @param $nativeSvgSupport - * @param $expectedResult - */ - public function testGetSupportedMediaTypes( - $baseMimeTypes, $extraMediaTypes, $nativeSvgSupport, $expectedResult - ) { - - $this->assertSame( - $baseMimeTypes, self::invokePrivate($this->service, 'baseMimeTypes', [$baseMimeTypes]) - ); - - $this->mockIsMimeSupported($nativeSvgSupport); - - $response = $this->service->getSupportedMediaTypes($extraMediaTypes, $nativeSvgSupport); - - $this->assertSame($expectedResult, $response); - } - public function providesIsPreviewRequiredData() { return [ [true], @@ -238,40 +180,6 @@ class PreviewServiceTest extends \Test\GalleryUnitTest { $this->service->previewValidator($square, $base64Encode); } - - public function providesAddSvgSupportData() { - $supportedMimes = [ - 'image/png', - 'image/jpeg', - 'image/gif' - ]; - - $supportedMimesWithSvg = array_merge($supportedMimes, ['image/svg+xml']); - - return [ - [$supportedMimes, true, $supportedMimesWithSvg], - [$supportedMimes, false, $supportedMimes], - [$supportedMimesWithSvg, true, $supportedMimesWithSvg], - [$supportedMimesWithSvg, false, $supportedMimesWithSvg], - ]; - } - - /** - * @dataProvider providesAddSvgSupportData - * - * @param array $supportedMimes - * @param bool $nativeSvgSupport - * @param array $expectedResult - */ - public function testAddSvgSupport($supportedMimes, $nativeSvgSupport, $expectedResult) { - $response = self::invokePrivate( - $this->service, 'addSvgSupport', [$supportedMimes, $nativeSvgSupport] - ); - - $this->assertSame($expectedResult, $response); - } - - private function mockIsMimeSupported($mimeSupported) { $map = [ ['image/jpeg', true], |