Skip to content

Commit 9130260

Browse files
Merge pull request #53005 from nextcloud/bugfix/noid/fix-icon-builder-warning
fix(theming): Instead of expecting a warning handle it properly
2 parents 33412e4 + b8fde8b commit 9130260

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

apps/theming/lib/IconBuilder.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,17 @@ public function getTouchIcon($app) {
9090
* Render app icon on themed background color
9191
* fallback to logo
9292
*
93-
* @param $app string app name
94-
* @param $size int size of the icon in px
93+
* @param string $app app name
94+
* @param int $size size of the icon in px
9595
* @return Imagick|false
9696
*/
9797
public function renderAppIcon($app, $size) {
9898
$appIcon = $this->util->getAppIcon($app);
99-
if ($appIcon === false) {
100-
return false;
101-
}
10299
if ($appIcon instanceof ISimpleFile) {
103100
$appIconContent = $appIcon->getContent();
104101
$mime = $appIcon->getMimeType();
102+
} elseif (!file_exists($appIcon)) {
103+
return false;
105104
} else {
106105
$appIconContent = file_get_contents($appIcon);
107106
$mime = mime_content_type($appIcon);
@@ -187,13 +186,13 @@ public function renderAppIcon($app, $size) {
187186
}
188187

189188
/**
190-
* @param $app string app name
191-
* @param $image string relative path to svg file in app directory
189+
* @param string $app app name
190+
* @param string $image relative path to svg file in app directory
192191
* @return string|false content of a colorized svg file
193192
*/
194193
public function colorSvg($app, $image) {
195194
$imageFile = $this->util->getAppImage($app, $image);
196-
if ($imageFile === false || $imageFile === '') {
195+
if ($imageFile === false || $imageFile === '' || !file_exists($imageFile)) {
197196
return false;
198197
}
199198
$svg = file_get_contents($imageFile);

apps/theming/tests/IconBuilderTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use OCP\Files\NotFoundException;
1515
use OCP\IConfig;
1616
use OCP\ServerVersion;
17-
use PHPUnit\Framework\Error\Warning;
1817
use Test\TestCase;
1918

2019
class IconBuilderTest extends TestCase {
@@ -165,8 +164,7 @@ public function testGetFavicon($app, $color, $file): void {
165164

166165
public function testGetFaviconNotFound(): void {
167166
$this->checkImagick();
168-
$this->expectWarning(Warning::class);
169-
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
167+
$util = $this->createMock(Util::class);
170168
$iconBuilder = new IconBuilder($this->themingDefaults, $util, $this->imageManager);
171169
$this->imageManager->expects($this->once())
172170
->method('shouldReplaceIcons')
@@ -179,8 +177,7 @@ public function testGetFaviconNotFound(): void {
179177

180178
public function testGetTouchIconNotFound(): void {
181179
$this->checkImagick();
182-
$this->expectWarning(Warning::class);
183-
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
180+
$util = $this->createMock(Util::class);
184181
$iconBuilder = new IconBuilder($this->themingDefaults, $util, $this->imageManager);
185182
$util->expects($this->once())
186183
->method('getAppIcon')
@@ -190,8 +187,7 @@ public function testGetTouchIconNotFound(): void {
190187

191188
public function testColorSvgNotFound(): void {
192189
$this->checkImagick();
193-
$this->expectWarning(Warning::class);
194-
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
190+
$util = $this->createMock(Util::class);
195191
$iconBuilder = new IconBuilder($this->themingDefaults, $util, $this->imageManager);
196192
$util->expects($this->once())
197193
->method('getAppImage')

0 commit comments

Comments
 (0)