From 80fe499707b280424fd032c33dcb3ff956e3a282 Mon Sep 17 00:00:00 2001 From: Julius Haertl Date: Tue, 23 Aug 2016 22:02:28 +0200 Subject: [PATCH 1/2] Theming: Add logo and background to ThemingDefaults --- apps/theming/lib/ThemingDefaults.php | 35 ++++++++++++++- apps/theming/tests/ThemingDefaultsTest.php | 52 +++++++++++++++++++++- lib/private/Server.php | 11 ++--- 3 files changed, 90 insertions(+), 8 deletions(-) diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 7b846919db358..0314b06b8492b 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -28,6 +28,7 @@ use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; +use OCP\Files\IRootFolder; class ThemingDefaults extends \OC_Defaults { @@ -38,6 +39,8 @@ class ThemingDefaults extends \OC_Defaults { private $l; /** @var IURLGenerator */ private $urlGenerator; + /** @var IRootFolder */ + private $rootFolder; /** @var string */ private $name; /** @var string */ @@ -58,12 +61,14 @@ class ThemingDefaults extends \OC_Defaults { public function __construct(IConfig $config, IL10N $l, IURLGenerator $urlGenerator, - \OC_Defaults $defaults + \OC_Defaults $defaults, + IRootFolder $rootFolder ) { parent::__construct(); $this->config = $config; $this->l = $l; $this->urlGenerator = $urlGenerator; + $this->rootFolder = $rootFolder; $this->name = $defaults->getName(); $this->url = $defaults->getBaseUrl(); @@ -113,6 +118,34 @@ public function getMailHeaderColor() { return $this->config->getAppValue('theming', 'color', $this->color); } + /** + * Themed logo url + * + * @return string + */ + public function getLogo() { + $logo = $this->config->getAppValue('theming', 'logoMime'); + if(!$logo || !$this->rootFolder->nodeExists('/themedinstancelogo')) { + return $this->urlGenerator->imagePath('core','logo.svg'); + } else { + return $this->urlGenerator->linkToRoute('theming.Theming.getLogo'); + } + } + + /** + * Themed background image url + * + * @return string + */ + public function getBackground() { + $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime'); + if(!$backgroundLogo || !$this->rootFolder->nodeExists('/themedbackgroundlogo')) { + return $this->urlGenerator->imagePath('core','background.jpg'); + } else { + return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground'); + } + } + /** * Increases the cache buster key */ diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php index 6ef7deea152b9..0aa88c3115e10 100644 --- a/apps/theming/tests/ThemingDefaultsTest.php +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -27,6 +27,7 @@ use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; +use OCP\Files\IRootFolder; use Test\TestCase; class ThemingDefaultsTest extends TestCase { @@ -40,11 +41,17 @@ class ThemingDefaultsTest extends TestCase { private $defaults; /** @var ThemingDefaults */ private $template; + /** @var IRootFolder */ + private $rootFolder; public function setUp() { + parent::setUp(); $this->config = $this->getMock('\\OCP\\IConfig'); $this->l10n = $this->getMock('\\OCP\\IL10N'); $this->urlGenerator = $this->getMock('\\OCP\\IURLGenerator'); + $this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder') + ->disableOriginalConstructor() + ->getMock(); $this->defaults = $this->getMockBuilder('\\OC_Defaults') ->disableOriginalConstructor() ->getMock(); @@ -68,10 +75,11 @@ public function setUp() { $this->config, $this->l10n, $this->urlGenerator, - $this->defaults + $this->defaults, + $this->rootFolder ); - return parent::setUp(); + //return parent::setUp(); } public function testGetNameWithDefault() { @@ -368,4 +376,44 @@ public function testUndoDefaultAction() { $this->assertSame('', $this->template->undo('defaultitem')); } + + public function testGetBackgroundDefault() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'backgroundMime') + ->willReturn(''); + $expected = $this->urlGenerator->imagePath('core','background.jpg'); + $this->assertEquals($expected, $this->template->getBackground()); + } + + public function testGetBackgroundCustom() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'backgroundMime') + ->willReturn('image/svg+xml'); + $expected = $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground'); + $this->assertEquals($expected, $this->template->getBackground()); + } + + public function testGetLogoDefault() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'logoMime') + ->willReturn(''); + $expected = $this->urlGenerator->imagePath('core','logo.svg'); + $this->assertEquals($expected, $this->template->getLogo()); + } + + public function testGetLogoCustom() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'logoMime') + ->willReturn('image/svg+xml'); + $expected = $this->urlGenerator->linkToRoute('theming.Theming.getLogo'); + $this->assertEquals($expected, $this->template->getLogo()); + } } diff --git a/lib/private/Server.php b/lib/private/Server.php index 86eee54be7076..02419e9a5e73d 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -650,12 +650,13 @@ public function __construct($webRoot, \OC\Config $config) { $classExists = false; } - if ($classExists && $this->getConfig()->getSystemValue('installed', false) && $this->getAppManager()->isInstalled('theming')) { + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) { return new ThemingDefaults( - $this->getConfig(), - $this->getL10N('theming'), - $this->getURLGenerator(), - new \OC_Defaults() + $c->getConfig(), + $c->getL10N('theming'), + $c->getURLGenerator(), + new \OC_Defaults(), + $c->getRootFolder() ); } return new \OC_Defaults(); From c7c53aefb2cefde1dabcf38534950e7a95cad542 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 24 Aug 2016 09:52:05 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Use=20the=20lazy=20root=20to=20make=20tests?= =?UTF-8?q?=20pass=20=F0=9F=99=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/theming/lib/ThemingDefaults.php | 4 +--- apps/theming/tests/ThemingDefaultsTest.php | 2 -- lib/private/Server.php | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 0314b06b8492b..9139dd56247e7 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -23,14 +23,11 @@ namespace OCA\Theming; - - use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; use OCP\Files\IRootFolder; - class ThemingDefaults extends \OC_Defaults { /** @var IConfig */ @@ -57,6 +54,7 @@ class ThemingDefaults extends \OC_Defaults { * @param IL10N $l * @param IURLGenerator $urlGenerator * @param \OC_Defaults $defaults + * @param IRootFolder $rootFolder */ public function __construct(IConfig $config, IL10N $l, diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php index 0aa88c3115e10..ffa6810ffdee8 100644 --- a/apps/theming/tests/ThemingDefaultsTest.php +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -78,8 +78,6 @@ public function setUp() { $this->defaults, $this->rootFolder ); - - //return parent::setUp(); } public function testGetNameWithDefault() { diff --git a/lib/private/Server.php b/lib/private/Server.php index 02419e9a5e73d..e99c6e8c56af9 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -656,7 +656,7 @@ public function __construct($webRoot, \OC\Config $config) { $c->getL10N('theming'), $c->getURLGenerator(), new \OC_Defaults(), - $c->getRootFolder() + $c->getLazyRootFolder() ); } return new \OC_Defaults();