diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2016-08-26 11:53:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-26 11:53:24 +0200 |
commit | 044d7c3bb71b24a140bdf6581779a16474b0e490 (patch) | |
tree | 316762615950daaae3b1fc7adf7f2fb2ec2a29de /apps | |
parent | ad4cab130eda568cdd1e5344796140d853655740 (diff) | |
parent | c7c53aefb2cefde1dabcf38534950e7a95cad542 (diff) | |
download | nextcloud-server-044d7c3bb71b24a140bdf6581779a16474b0e490.tar.gz nextcloud-server-044d7c3bb71b24a140bdf6581779a16474b0e490.zip |
Merge pull request #1026 from nextcloud/theming-extend-defaults
Theming: Add logo and background to ThemingDefaults
Diffstat (limited to 'apps')
-rw-r--r-- | apps/theming/lib/ThemingDefaults.php | 39 | ||||
-rw-r--r-- | apps/theming/tests/ThemingDefaultsTest.php | 52 |
2 files changed, 84 insertions, 7 deletions
diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 7b846919db3..9139dd56247 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -23,12 +23,10 @@ namespace OCA\Theming; - - use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; - +use OCP\Files\IRootFolder; class ThemingDefaults extends \OC_Defaults { @@ -38,6 +36,8 @@ class ThemingDefaults extends \OC_Defaults { private $l; /** @var IURLGenerator */ private $urlGenerator; + /** @var IRootFolder */ + private $rootFolder; /** @var string */ private $name; /** @var string */ @@ -54,16 +54,19 @@ 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, 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(); @@ -114,6 +117,34 @@ class ThemingDefaults extends \OC_Defaults { } /** + * 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 */ private function increaseCacheBuster() { diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php index 6ef7deea152..ffa6810ffde 100644 --- a/apps/theming/tests/ThemingDefaultsTest.php +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -27,6 +27,7 @@ use OCA\Theming\ThemingDefaults; 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,9 @@ class ThemingDefaultsTest extends TestCase { $this->config, $this->l10n, $this->urlGenerator, - $this->defaults + $this->defaults, + $this->rootFolder ); - - return parent::setUp(); } public function testGetNameWithDefault() { @@ -368,4 +374,44 @@ class ThemingDefaultsTest extends TestCase { $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()); + } } |