From 38ea5d14b38d86fe09acf0df34857c9eba6e1c6f Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Sun, 2 Sep 2018 14:17:17 +0200 Subject: Disables SVG favicon uploads when imagemagick is missing. Signed-off-by: Michael Weimann --- .../tests/Controller/IconControllerTest.php | 4 +- .../tests/Controller/ThemingControllerTest.php | 55 ++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) (limited to 'apps/theming/tests') diff --git a/apps/theming/tests/Controller/IconControllerTest.php b/apps/theming/tests/Controller/IconControllerTest.php index b4b45a065b0..e749a1dbd44 100644 --- a/apps/theming/tests/Controller/IconControllerTest.php +++ b/apps/theming/tests/Controller/IconControllerTest.php @@ -117,7 +117,7 @@ class IconControllerTest extends TestCase { } $file = $this->iconFileMock('filename', 'filecontent'); $this->imageManager->expects($this->once()) - ->method('getImage') + ->method('getImage', false) ->with('favicon') ->will($this->throwException(new NotFoundException())); $this->imageManager->expects($this->any()) @@ -142,7 +142,7 @@ class IconControllerTest extends TestCase { public function testGetFaviconFail() { $this->imageManager->expects($this->once()) ->method('getImage') - ->with('favicon') + ->with('favicon', false) ->will($this->throwException(new NotFoundException())); $this->imageManager->expects($this->any()) ->method('shouldReplaceIcons') diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index a2105264f10..457e9900b5e 100644 --- a/apps/theming/tests/Controller/ThemingControllerTest.php +++ b/apps/theming/tests/Controller/ThemingControllerTest.php @@ -246,6 +246,61 @@ class ThemingControllerTest extends TestCase { $this->assertEquals($expected, $this->themingController->uploadImage()); } + /** + * Checks that trying to upload an SVG favicon without imagemagick + * results in an unsupported media type response. + * + * @test + * @return void + */ + public function testUploadSVGFaviconWithoutImagemagick() { + $this->imageManager + ->method('shouldReplaceIcons') + ->willReturn(false); + + $this->request + ->expects($this->at(0)) + ->method('getParam') + ->with('key') + ->willReturn('favicon'); + $this->request + ->expects($this->at(1)) + ->method('getUploadedFile') + ->with('image') + ->willReturn([ + 'tmp_name' => __DIR__ . '/../../../../tests/data/testimagelarge.svg', + 'type' => 'image/svg', + 'name' => 'testimagelarge.svg', + 'error' => 0, + ]); + $this->l10n + ->expects($this->any()) + ->method('t') + ->will($this->returnCallback(function($str) { + return $str; + })); + + $folder = $this->createMock(ISimpleFolder::class); + $this->appData + ->expects($this->once()) + ->method('getFolder') + ->with('images') + ->willReturn($folder); + + $expected = new DataResponse( + [ + 'data' => + [ + 'message' => 'Unsupported image type', + ], + 'status' => 'failure' + ], + Http::STATUS_UNPROCESSABLE_ENTITY + ); + + $this->assertEquals($expected, $this->themingController->uploadImage()); + } + public function testUpdateLogoInvalidMimeType() { $this->request ->expects($this->at(0)) -- cgit v1.2.3