Skip to content

Commit b1a47eb

Browse files
Merge pull request #53008 from nextcloud/backport/53005/stable30
[stable30] fix(theming): Instead of expecting a warning handle it properly
2 parents 091e779 + c75dd57 commit b1a47eb

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
@@ -101,18 +101,17 @@ public function getTouchIcon($app) {
101101
* Render app icon on themed background color
102102
* fallback to logo
103103
*
104-
* @param $app string app name
105-
* @param $size int size of the icon in px
104+
* @param string $app app name
105+
* @param int $size size of the icon in px
106106
* @return Imagick|false
107107
*/
108108
public function renderAppIcon($app, $size) {
109109
$appIcon = $this->util->getAppIcon($app);
110-
if ($appIcon === false) {
111-
return false;
112-
}
113110
if ($appIcon instanceof ISimpleFile) {
114111
$appIconContent = $appIcon->getContent();
115112
$mime = $appIcon->getMimeType();
113+
} elseif (!file_exists($appIcon)) {
114+
return false;
116115
} else {
117116
$appIconContent = file_get_contents($appIcon);
118117
$mime = mime_content_type($appIcon);
@@ -198,13 +197,13 @@ public function renderAppIcon($app, $size) {
198197
}
199198

200199
/**
201-
* @param $app string app name
202-
* @param $image string relative path to svg file in app directory
200+
* @param string $app app name
201+
* @param string $image relative path to svg file in app directory
203202
* @return string|false content of a colorized svg file
204203
*/
205204
public function colorSvg($app, $image) {
206205
$imageFile = $this->util->getAppImage($app, $image);
207-
if ($imageFile === false || $imageFile === '') {
206+
if ($imageFile === false || $imageFile === '' || !file_exists($imageFile)) {
208207
return false;
209208
}
210209
$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\App\IAppManager;
1515
use OCP\Files\NotFoundException;
1616
use OCP\IConfig;
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) {
165164

166165
public function testGetFaviconNotFound() {
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() {
179177

180178
public function testGetTouchIconNotFound() {
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() {
190187

191188
public function testColorSvgNotFound() {
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)