Minor fixes and cleanup
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
d132527aa9
commit
5b0ce806a3
|
@ -125,7 +125,7 @@ class IconController extends Controller {
|
||||||
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
|
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
|
||||||
} catch (NotFoundException $e) {
|
} catch (NotFoundException $e) {
|
||||||
}
|
}
|
||||||
if ($iconFile === null && $this->themingDefaults->shouldReplaceIcons()) {
|
if ($iconFile === null && $this->imageManager->shouldReplaceIcons()) {
|
||||||
try {
|
try {
|
||||||
$iconFile = $this->imageManager->getCachedImage('favIcon-' . $app);
|
$iconFile = $this->imageManager->getCachedImage('favIcon-' . $app);
|
||||||
} catch (NotFoundException $exception) {
|
} catch (NotFoundException $exception) {
|
||||||
|
@ -161,7 +161,7 @@ class IconController extends Controller {
|
||||||
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
|
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
|
||||||
} catch (NotFoundException $e) {
|
} catch (NotFoundException $e) {
|
||||||
}
|
}
|
||||||
if ($this->themingDefaults->shouldReplaceIcons()) {
|
if ($this->imageManager->shouldReplaceIcons()) {
|
||||||
try {
|
try {
|
||||||
$iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app);
|
$iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app);
|
||||||
} catch (NotFoundException $exception) {
|
} catch (NotFoundException $exception) {
|
||||||
|
|
|
@ -35,19 +35,24 @@ class IconBuilder {
|
||||||
private $themingDefaults;
|
private $themingDefaults;
|
||||||
/** @var Util */
|
/** @var Util */
|
||||||
private $util;
|
private $util;
|
||||||
|
/** @var ImageManager */
|
||||||
|
private $imageManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IconBuilder constructor.
|
* IconBuilder constructor.
|
||||||
*
|
*
|
||||||
* @param ThemingDefaults $themingDefaults
|
* @param ThemingDefaults $themingDefaults
|
||||||
* @param Util $util
|
* @param Util $util
|
||||||
|
* @param ImageManager $imageManager
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ThemingDefaults $themingDefaults,
|
ThemingDefaults $themingDefaults,
|
||||||
Util $util
|
Util $util,
|
||||||
|
ImageManager $imageManager
|
||||||
) {
|
) {
|
||||||
$this->themingDefaults = $themingDefaults;
|
$this->themingDefaults = $themingDefaults;
|
||||||
$this->util = $util;
|
$this->util = $util;
|
||||||
|
$this->imageManager = $imageManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +60,7 @@ class IconBuilder {
|
||||||
* @return string|false image blob
|
* @return string|false image blob
|
||||||
*/
|
*/
|
||||||
public function getFavicon($app) {
|
public function getFavicon($app) {
|
||||||
if (!$this->themingDefaults->shouldReplaceIcons()) {
|
if (!$this->imageManager->shouldReplaceIcons()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -181,6 +181,7 @@ class ImageManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete(string $key) {
|
public function delete(string $key) {
|
||||||
|
/* ignore exceptions, since we don't want to fail hard if something goes wrong during cleanup */
|
||||||
try {
|
try {
|
||||||
$file = $this->appData->getFolder('images')->getFile($key);
|
$file = $this->appData->getFolder('images')->getFile($key);
|
||||||
$file->delete();
|
$file->delete();
|
||||||
|
|
|
@ -81,7 +81,7 @@ class Admin implements ISettings {
|
||||||
'slogan' => $this->themingDefaults->getSlogan(),
|
'slogan' => $this->themingDefaults->getSlogan(),
|
||||||
'color' => $this->themingDefaults->getColorPrimary(),
|
'color' => $this->themingDefaults->getColorPrimary(),
|
||||||
'uploadLogoRoute' => $this->urlGenerator->linkToRoute('theming.Theming.uploadImage'),
|
'uploadLogoRoute' => $this->urlGenerator->linkToRoute('theming.Theming.uploadImage'),
|
||||||
'canThemeIcons' => $this->themingDefaults->shouldReplaceIcons(),
|
'canThemeIcons' => $this->imageManager->shouldReplaceIcons(),
|
||||||
'iconDocs' => $this->urlGenerator->linkToDocs('admin-theming-icons'),
|
'iconDocs' => $this->urlGenerator->linkToDocs('admin-theming-icons'),
|
||||||
'images' => $this->imageManager->getCustomImages(),
|
'images' => $this->imageManager->getCustomImages(),
|
||||||
'imprintUrl' => $this->themingDefaults->getImprintUrl(),
|
'imprintUrl' => $this->themingDefaults->getImprintUrl(),
|
||||||
|
|
|
@ -317,10 +317,10 @@ class ThemingDefaults extends \OC_Defaults {
|
||||||
$customFavicon = null;
|
$customFavicon = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($image === 'favicon.ico' && ($customFavicon !== null || $this->shouldReplaceIcons())) {
|
if ($image === 'favicon.ico' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) {
|
||||||
return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue;
|
return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue;
|
||||||
}
|
}
|
||||||
if ($image === 'favicon-touch.png' && ($customFavicon !== null || $this->shouldReplaceIcons())) {
|
if ($image === 'favicon-touch.png' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) {
|
||||||
return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue;
|
return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue;
|
||||||
}
|
}
|
||||||
if ($image === 'manifest.json') {
|
if ($image === 'manifest.json') {
|
||||||
|
@ -334,19 +334,7 @@ class ThemingDefaults extends \OC_Defaults {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if Imagemagick is enabled and if SVG is supported
|
|
||||||
* otherwise we can't render custom icons
|
|
||||||
*
|
|
||||||
* TODO: move to usage of image manager
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function shouldReplaceIcons() {
|
|
||||||
return $this->imageManager->shouldReplaceIcons();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increases the cache buster key
|
* Increases the cache buster key
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -118,7 +118,7 @@ class IconControllerTest extends TestCase {
|
||||||
->method('getImage')
|
->method('getImage')
|
||||||
->with('favicon')
|
->with('favicon')
|
||||||
->will($this->throwException(new NotFoundException()));
|
->will($this->throwException(new NotFoundException()));
|
||||||
$this->themingDefaults->expects($this->any())
|
$this->imageManager->expects($this->any())
|
||||||
->method('shouldReplaceIcons')
|
->method('shouldReplaceIcons')
|
||||||
->willReturn(true);
|
->willReturn(true);
|
||||||
$this->imageManager->expects($this->once())
|
$this->imageManager->expects($this->once())
|
||||||
|
@ -142,7 +142,7 @@ class IconControllerTest extends TestCase {
|
||||||
->method('getImage')
|
->method('getImage')
|
||||||
->with('favicon')
|
->with('favicon')
|
||||||
->will($this->throwException(new NotFoundException()));
|
->will($this->throwException(new NotFoundException()));
|
||||||
$this->themingDefaults->expects($this->any())
|
$this->imageManager->expects($this->any())
|
||||||
->method('shouldReplaceIcons')
|
->method('shouldReplaceIcons')
|
||||||
->willReturn(false);
|
->willReturn(false);
|
||||||
$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png';
|
$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png';
|
||||||
|
@ -163,10 +163,13 @@ class IconControllerTest extends TestCase {
|
||||||
if (count($checkImagick->queryFormats('SVG')) < 1) {
|
if (count($checkImagick->queryFormats('SVG')) < 1) {
|
||||||
$this->markTestSkipped('No SVG provider present.');
|
$this->markTestSkipped('No SVG provider present.');
|
||||||
}
|
}
|
||||||
$this->themingDefaults->expects($this->any())
|
|
||||||
|
$this->imageManager->expects($this->once())
|
||||||
|
->method('getImage')
|
||||||
|
->will($this->throwException(new NotFoundException()));
|
||||||
|
$this->imageManager->expects($this->any())
|
||||||
->method('shouldReplaceIcons')
|
->method('shouldReplaceIcons')
|
||||||
->willReturn(true);
|
->willReturn(true);
|
||||||
|
|
||||||
$this->iconBuilder->expects($this->once())
|
$this->iconBuilder->expects($this->once())
|
||||||
->method('getTouchIcon')
|
->method('getTouchIcon')
|
||||||
->with('core')
|
->with('core')
|
||||||
|
@ -189,7 +192,7 @@ class IconControllerTest extends TestCase {
|
||||||
->method('getImage')
|
->method('getImage')
|
||||||
->with('favicon')
|
->with('favicon')
|
||||||
->will($this->throwException(new NotFoundException()));
|
->will($this->throwException(new NotFoundException()));
|
||||||
$this->themingDefaults->expects($this->any())
|
$this->imageManager->expects($this->any())
|
||||||
->method('shouldReplaceIcons')
|
->method('shouldReplaceIcons')
|
||||||
->willReturn(false);
|
->willReturn(false);
|
||||||
$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png';
|
$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png';
|
||||||
|
|
|
@ -688,7 +688,7 @@ class ThemingControllerTest extends TestCase {
|
||||||
->method('getImage')
|
->method('getImage')
|
||||||
->willReturn($file);
|
->willReturn($file);
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->any())
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('theming', 'logoMime', '')
|
->with('theming', 'logoMime', '')
|
||||||
->willReturn('text/svg');
|
->willReturn('text/svg');
|
||||||
|
@ -716,7 +716,7 @@ class ThemingControllerTest extends TestCase {
|
||||||
->willReturn($file);
|
->willReturn($file);
|
||||||
|
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->any())
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('theming', 'backgroundMime', '')
|
->with('theming', 'backgroundMime', '')
|
||||||
->willReturn('image/png');
|
->willReturn('image/png');
|
||||||
|
|
|
@ -27,6 +27,7 @@ namespace OCA\Theming\Tests;
|
||||||
|
|
||||||
use OC\Files\AppData\AppData;
|
use OC\Files\AppData\AppData;
|
||||||
use OCA\Theming\IconBuilder;
|
use OCA\Theming\IconBuilder;
|
||||||
|
use OCA\Theming\ImageManager;
|
||||||
use OCA\Theming\ThemingDefaults;
|
use OCA\Theming\ThemingDefaults;
|
||||||
use OCA\Theming\Util;
|
use OCA\Theming\Util;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
|
@ -45,6 +46,8 @@ class IconBuilderTest extends TestCase {
|
||||||
protected $themingDefaults;
|
protected $themingDefaults;
|
||||||
/** @var Util */
|
/** @var Util */
|
||||||
protected $util;
|
protected $util;
|
||||||
|
/** @var ImageManager */
|
||||||
|
protected $imageManager;
|
||||||
/** @var IconBuilder */
|
/** @var IconBuilder */
|
||||||
protected $iconBuilder;
|
protected $iconBuilder;
|
||||||
/** @var IAppManager */
|
/** @var IAppManager */
|
||||||
|
@ -53,13 +56,13 @@ class IconBuilderTest extends TestCase {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->config = $this->getMockBuilder(IConfig::class)->getMock();
|
$this->config = $this->createMock(IConfig::class);
|
||||||
$this->appData = $this->createMock(AppData::class);
|
$this->appData = $this->createMock(AppData::class);
|
||||||
$this->themingDefaults = $this->getMockBuilder('OCA\Theming\ThemingDefaults')
|
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
|
||||||
->disableOriginalConstructor()->getMock();
|
$this->appManager = $this->createMock(IAppManager::class);
|
||||||
$this->appManager = $this->getMockBuilder('OCP\App\IAppManager')->getMock();
|
$this->imageManager = $this->createMock(ImageManager::class);
|
||||||
$this->util = new Util($this->config, $this->appManager, $this->appData);
|
$this->util = new Util($this->config, $this->appManager, $this->appData);
|
||||||
$this->iconBuilder = new IconBuilder($this->themingDefaults, $this->util);
|
$this->iconBuilder = new IconBuilder($this->themingDefaults, $this->util, $this->imageManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkImagick() {
|
private function checkImagick() {
|
||||||
|
@ -152,7 +155,7 @@ class IconBuilderTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public function testGetFavicon($app, $color, $file) {
|
public function testGetFavicon($app, $color, $file) {
|
||||||
$this->checkImagick();
|
$this->checkImagick();
|
||||||
$this->themingDefaults->expects($this->once())
|
$this->imageManager->expects($this->once())
|
||||||
->method('shouldReplaceIcons')
|
->method('shouldReplaceIcons')
|
||||||
->willReturn(true);
|
->willReturn(true);
|
||||||
$this->themingDefaults->expects($this->once())
|
$this->themingDefaults->expects($this->once())
|
||||||
|
@ -183,8 +186,8 @@ class IconBuilderTest extends TestCase {
|
||||||
$this->checkImagick();
|
$this->checkImagick();
|
||||||
$this->expectException(Warning::class);
|
$this->expectException(Warning::class);
|
||||||
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
|
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
|
||||||
$iconBuilder = new IconBuilder($this->themingDefaults, $util);
|
$iconBuilder = new IconBuilder($this->themingDefaults, $util, $this->imageManager);
|
||||||
$this->themingDefaults->expects($this->once())
|
$this->imageManager->expects($this->once())
|
||||||
->method('shouldReplaceIcons')
|
->method('shouldReplaceIcons')
|
||||||
->willReturn(true);
|
->willReturn(true);
|
||||||
$util->expects($this->once())
|
$util->expects($this->once())
|
||||||
|
@ -197,7 +200,7 @@ class IconBuilderTest extends TestCase {
|
||||||
$this->checkImagick();
|
$this->checkImagick();
|
||||||
$this->expectException(Warning::class);
|
$this->expectException(Warning::class);
|
||||||
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
|
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
|
||||||
$iconBuilder = new IconBuilder($this->themingDefaults, $util);
|
$iconBuilder = new IconBuilder($this->themingDefaults, $util, $this->imageManager);
|
||||||
$util->expects($this->once())
|
$util->expects($this->once())
|
||||||
->method('getAppIcon')
|
->method('getAppIcon')
|
||||||
->willReturn('notexistingfile');
|
->willReturn('notexistingfile');
|
||||||
|
@ -208,7 +211,7 @@ class IconBuilderTest extends TestCase {
|
||||||
$this->checkImagick();
|
$this->checkImagick();
|
||||||
$this->expectException(Warning::class);
|
$this->expectException(Warning::class);
|
||||||
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
|
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
|
||||||
$iconBuilder = new IconBuilder($this->themingDefaults, $util);
|
$iconBuilder = new IconBuilder($this->themingDefaults, $util, $this->imageManager);
|
||||||
$util->expects($this->once())
|
$util->expects($this->once())
|
||||||
->method('getAppImage')
|
->method('getAppImage')
|
||||||
->willReturn('notexistingfile');
|
->willReturn('notexistingfile');
|
||||||
|
|
|
@ -66,10 +66,10 @@ class ImageManagerTest extends TestCase {
|
||||||
$this->markTestSkipped('Imagemagick is required for dynamic icon generation.');
|
$this->markTestSkipped('Imagemagick is required for dynamic icon generation.');
|
||||||
}
|
}
|
||||||
$checkImagick = new \Imagick();
|
$checkImagick = new \Imagick();
|
||||||
if (count($checkImagick->queryFormats('SVG')) < 1) {
|
if (empty($checkImagick->queryFormats('SVG'))) {
|
||||||
$this->markTestSkipped('No SVG provider present.');
|
$this->markTestSkipped('No SVG provider present.');
|
||||||
}
|
}
|
||||||
if (count($checkImagick->queryFormats('PNG')) < 1) {
|
if (empty($checkImagick->queryFormats('PNG'))) {
|
||||||
$this->markTestSkipped('No PNG provider present.');
|
$this->markTestSkipped('No PNG provider present.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue