]> source.dussan.org Git - nextcloud-server.git/commitdiff
Theming: Add logo and background to ThemingDefaults
authorJulius Haertl <jus@bitgrid.net>
Tue, 23 Aug 2016 20:02:28 +0000 (22:02 +0200)
committerJulius Haertl <jus@bitgrid.net>
Tue, 23 Aug 2016 22:40:22 +0000 (00:40 +0200)
apps/theming/lib/ThemingDefaults.php
apps/theming/tests/ThemingDefaultsTest.php
lib/private/Server.php

index 7b846919db3583492ce55916258f074a81dc680d..0314b06b8492b0d7444237f645d0fdf313b42025 100644 (file)
@@ -28,6 +28,7 @@ namespace OCA\Theming;
 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 @@ class ThemingDefaults extends \OC_Defaults {
                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
         */
index 6ef7deea152b9663023399c4988b6da28954779d..0aa88c3115e10cbcd0bc13dfd51c79067569c0f4 100644 (file)
@@ -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,11 @@ class ThemingDefaultsTest extends TestCase {
                        $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 @@ 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());
+       }
 }
index 86eee54be7076da8f22a52dc9220dfeeaa84266b..02419e9a5e73d7e474c7096ee88f8f134c052b64 100644 (file)
@@ -650,12 +650,13 @@ class Server extends ServerContainer implements IServerContainer {
                                $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();