|
17 | 17 | use OCP\AppFramework\Http; |
18 | 18 | use OCP\AppFramework\Http\DataDisplayResponse; |
19 | 19 | use OCP\AppFramework\Http\FileDisplayResponse; |
| 20 | +use OCP\AppFramework\Http\NotFoundResponse; |
20 | 21 | use OCP\AppFramework\Utility\ITimeFactory; |
21 | 22 | use OCP\Files\File; |
22 | 23 | use OCP\Files\NotFoundException; |
@@ -73,15 +74,52 @@ private function iconFileMock($filename, $data): SimpleFile { |
73 | 74 | return new SimpleFile($icon); |
74 | 75 | } |
75 | 76 |
|
76 | | - public function testGetThemedIcon(): void { |
77 | | - $file = $this->iconFileMock('icon-core-filetypes_folder.svg', 'filecontent'); |
| 77 | + public static function dataGetThemedIcon(): array { |
| 78 | + return [ |
| 79 | + ['filetypes/folder.svg', 'icon-core-filetypes_folder.svg'], |
| 80 | + ['filetypes/x-office-document.svg', 'icon-core-filetypes_x-office-document.svg'], |
| 81 | + ['actions/add.svg', 'icon-core-actions_add.svg'], |
| 82 | + ['app_dark.svg', 'icon-core-app_dark.svg'], |
| 83 | + ['logo/logo.v2.svg', 'icon-core-logo_logo.v2.svg'], |
| 84 | + ]; |
| 85 | + } |
| 86 | + |
| 87 | + #[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataGetThemedIcon')] |
| 88 | + public function testGetThemedIcon(string $image, string $cacheKey): void { |
| 89 | + $file = $this->iconFileMock($cacheKey, 'filecontent'); |
78 | 90 | $this->imageManager->expects($this->once()) |
79 | 91 | ->method('getCachedImage') |
80 | | - ->with('icon-core-filetypes_folder.svg') |
| 92 | + ->with($cacheKey) |
81 | 93 | ->willReturn($file); |
82 | 94 | $expected = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); |
83 | 95 | $expected->cacheFor(86400, false, true); |
84 | | - $this->assertEquals($expected, $this->iconController->getThemedIcon('core', 'filetypes/folder.svg')); |
| 96 | + $this->assertEquals($expected, $this->iconController->getThemedIcon('core', $image)); |
| 97 | + } |
| 98 | + |
| 99 | + public static function dataGetThemedIconInvalidImage(): array { |
| 100 | + return [ |
| 101 | + 'not an svg' => ['background/eduardo-neves-pedra-azul.jpg'], |
| 102 | + 'png' => ['favicon.png'], |
| 103 | + 'missing extension' => ['filetypes/folder'], |
| 104 | + 'double dot' => ['filetypes/fol..der.svg'], |
| 105 | + 'dot segment' => ['filetypes/./folder.svg'], |
| 106 | + 'parent segment' => ['filetypes/../filetypes/folder.svg'], |
| 107 | + 'leading slash' => ['/filetypes/folder.svg'], |
| 108 | + 'double slash' => ['filetypes//folder.svg'], |
| 109 | + 'trailing newline' => ["filetypes/folder.svg\n"], |
| 110 | + 'extension only' => ['.svg'], |
| 111 | + ]; |
| 112 | + } |
| 113 | + |
| 114 | + #[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataGetThemedIconInvalidImage')] |
| 115 | + public function testGetThemedIconInvalidImage(string $image): void { |
| 116 | + $this->imageManager->expects($this->never()) |
| 117 | + ->method('getCachedImage'); |
| 118 | + $this->imageManager->expects($this->never()) |
| 119 | + ->method('setCachedImage'); |
| 120 | + $this->iconBuilder->expects($this->never()) |
| 121 | + ->method('colorSvg'); |
| 122 | + $this->assertInstanceOf(NotFoundResponse::class, $this->iconController->getThemedIcon('core', $image)); |
85 | 123 | } |
86 | 124 |
|
87 | 125 | public function testGetFaviconDefault(): void { |
|
0 commit comments