diff --git a/apps/theming/lib/ImageManager.php b/apps/theming/lib/ImageManager.php index 87123a6f7c9c0..f609e5ef9d4f2 100644 --- a/apps/theming/lib/ImageManager.php +++ b/apps/theming/lib/ImageManager.php @@ -240,7 +240,7 @@ public function updateImage(string $key, string $tmpFile): string { $supportedFormats = $this->getSupportedUploadImageFormats($key); $detectedMimeType = mime_content_type($tmpFile); if (!in_array($detectedMimeType, $supportedFormats, true)) { - throw new \Exception('Unsupported image type'); + throw new \Exception('Unsupported image type: ' . $detectedMimeType); } if ($key === 'background' && $this->shouldOptimizeBackgroundImage($detectedMimeType, filesize($tmpFile))) { diff --git a/apps/theming/tests/ImageManagerTest.php b/apps/theming/tests/ImageManagerTest.php index 22432a00103f3..e0e00615edbe4 100644 --- a/apps/theming/tests/ImageManagerTest.php +++ b/apps/theming/tests/ImageManagerTest.php @@ -390,4 +390,30 @@ public function testUpdateImage($key, $tmpFile, $folderExists, $shouldConvert) { $this->imageManager->updateImage($key, $tmpFile); } + + public function testUnsupportedImageType(): void { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Unsupported image type: text/plain'); + + $file = $this->createMock(ISimpleFile::class); + $folder = $this->createMock(ISimpleFolder::class); + $oldFile = $this->createMock(ISimpleFile::class); + + $folder->expects($this->any()) + ->method('getFile') + ->willReturn($oldFile); + + $this->rootFolder + ->expects($this->any()) + ->method('getFolder') + ->with('images') + ->willReturn($folder); + + $folder->expects($this->once()) + ->method('newFile') + ->with('favicon') + ->willReturn($file); + + $this->imageManager->updateImage('favicon', __DIR__ . '/../../../tests/data/lorem.txt'); + } }