]> source.dussan.org Git - nextcloud-server.git/commitdiff
rename "Tenmplate" to "ThemingDefaults" to make the auto loader happy"
authorBjoern Schiessle <bjoern@schiessle.org>
Fri, 12 Aug 2016 13:30:35 +0000 (15:30 +0200)
committerLukas Reschke <lukas@statuscode.ch>
Tue, 16 Aug 2016 19:09:41 +0000 (21:09 +0200)
apps/theming/lib/Settings/Admin.php
apps/theming/lib/Template.php [deleted file]
apps/theming/lib/ThemingDefaults.php [new file with mode: 0644]
apps/theming/tests/TemplateTest.php [deleted file]
apps/theming/tests/ThemingDefaultsTest.php [new file with mode: 0644]
lib/private/Server.php

index 07dfe75ec605b9c280be9f7bf0a6ec11b934213d..03356c113835517ebf10263bdb2a5bba6eea9e91 100644 (file)
@@ -23,7 +23,7 @@
 
 namespace OCA\Theming\Settings;
 
-use OCA\Theming\Template;
+use OCA\Theming\ThemingDefaults;
 use OCP\AppFramework\Http\TemplateResponse;
 use OCP\IConfig;
 use OCP\IL10N;
@@ -44,7 +44,7 @@ class Admin implements ISettings {
        /** @var IURLGenerator */
        private $urlGenerator;
 
-       public function __construct(IConfig $config, IL10N $l, Template $themingDefaults, IURLGenerator $urlGenerator) {
+       public function __construct(IConfig $config, IL10N $l, ThemingDefaults $themingDefaults, IURLGenerator $urlGenerator) {
                $this->config = $config;
                $this->l = $l;
                $this->themingDefaults = $themingDefaults;
diff --git a/apps/theming/lib/Template.php b/apps/theming/lib/Template.php
deleted file mode 100644 (file)
index 25730aa..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\Theming;
-
-use OCP\IConfig;
-use OCP\IL10N;
-use OCP\IURLGenerator;
-
-/**
- * Class Template
- *
- * Handle all the values which can be modified by this app
- *
- * @package OCA\Theming
- */
-class Template extends \OC_Defaults {
-       /** @var IConfig */
-       private $config;
-       /** @var IL10N */
-       private $l;
-       /** @var IURLGenerator */
-       private $urlGenerator;
-       /** @var string */
-       private $name;
-       /** @var string */
-       private $url;
-       /** @var string */
-       private $slogan;
-       /** @var string */
-       private $color;
-
-       /**
-        * Template constructor.
-        *
-        * @param IConfig $config
-        * @param IL10N $l
-        * @param IURLGenerator $urlGenerator
-        * @param \OC_Defaults $defaults
-        */
-       public function __construct(IConfig $config,
-                                                               IL10N $l,
-                                                               IURLGenerator $urlGenerator,
-                                                               \OC_Defaults $defaults
-       ) {
-               parent::__construct();
-               $this->config = $config;
-               $this->l = $l;
-               $this->urlGenerator = $urlGenerator;
-
-               $this->name = $defaults->getName();
-               $this->url = $defaults->getBaseUrl();
-               $this->slogan = $defaults->getSlogan();
-               $this->color = $defaults->getMailHeaderColor();
-       }
-
-       public function getName() {
-               return $this->config->getAppValue('theming', 'name', $this->name);
-       }
-
-       public function getHTMLName() {
-               return $this->config->getAppValue('theming', 'name', $this->name);
-       }
-
-       public function getTitle() {
-               return $this->config->getAppValue('theming', 'name', $this->name);
-       }
-
-       public function getEntity() {
-               return $this->config->getAppValue('theming', 'name', $this->name);
-       }
-       
-       public function getBaseUrl() {
-               return $this->config->getAppValue('theming', 'url', $this->url);
-       }
-
-       public function getSlogan() {
-               return $this->config->getAppValue('theming', 'slogan', $this->slogan);
-       }
-
-       public function getShortFooter() {
-               $slogan = $this->getSlogan();
-               $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
-                       ' rel="noreferrer">' .$this->getEntity() . '</a>'.
-                       ($slogan !== '' ? ' – ' . $slogan : '');
-
-               return $footer;
-       }
-
-       /**
-        * Color that is used for the header as well as for mail headers
-        *
-        * @return string
-        */
-       public function getMailHeaderColor() {
-               return $this->config->getAppValue('theming', 'color', $this->color);
-       }
-
-       /**
-        * Increases the cache buster key
-        */
-       private function increaseCacheBuster() {
-               $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
-               $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
-       }
-
-       /**
-        * Update setting in the database
-        *
-        * @param string $setting
-        * @param string $value
-        */
-       public function set($setting, $value) {
-               $this->config->setAppValue('theming', $setting, $value);
-               $this->increaseCacheBuster();
-       }
-
-       /**
-        * Revert settings to the default value
-        *
-        * @param string $setting setting which should be reverted
-        * @return string default value
-        */
-       public function undo($setting) {
-               $this->config->deleteAppValue('theming', $setting);
-               $this->increaseCacheBuster();
-
-               switch ($setting) {
-                       case 'name':
-                               $returnValue = $this->getEntity();
-                               break;
-                       case 'url':
-                               $returnValue = $this->getBaseUrl();
-                               break;
-                       case 'slogan':
-                               $returnValue = $this->getSlogan();
-                               break;
-                       case 'color':
-                               $returnValue = $this->getMailHeaderColor();
-                               break;
-                       default:
-                               $returnValue = '';
-                               break;
-               }
-
-               return $returnValue;
-       }
-}
diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php
new file mode 100644 (file)
index 0000000..a7af208
--- /dev/null
@@ -0,0 +1,166 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\Theming;
+
+
+
+
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+
+
+class ThemingDefaults extends \OC_Defaults {
+
+       /** @var IConfig */
+       private $config;
+       /** @var IL10N */
+       private $l;
+       /** @var IURLGenerator */
+       private $urlGenerator;
+       /** @var string */
+       private $name;
+       /** @var string */
+       private $url;
+       /** @var string */
+       private $slogan;
+       /** @var string */
+       private $color;
+
+       /**
+        * Template constructor.
+        *
+        * @param IConfig $config
+        * @param IL10N $l
+        * @param IURLGenerator $urlGenerator
+        * @param \OC_Defaults $defaults
+        */
+       public function __construct(IConfig $config,
+                                                               IL10N $l,
+                                                               IURLGenerator $urlGenerator,
+                                                               \OC_Defaults $defaults
+       ) {
+               parent::__construct();
+               $this->config = $config;
+               $this->l = $l;
+               $this->urlGenerator = $urlGenerator;
+
+               $this->name = $defaults->getName();
+               $this->url = $defaults->getBaseUrl();
+               $this->slogan = $defaults->getSlogan();
+               $this->color = $defaults->getMailHeaderColor();
+       }
+
+       public function getName() {
+               return $this->config->getAppValue('theming', 'name', $this->name);
+       }
+
+       public function getHTMLName() {
+               return $this->config->getAppValue('theming', 'name', $this->name);
+       }
+
+       public function getTitle() {
+               return $this->config->getAppValue('theming', 'name', $this->name);
+       }
+
+       public function getEntity() {
+               return $this->config->getAppValue('theming', 'name', $this->name);
+       }
+
+       public function getBaseUrl() {
+               return $this->config->getAppValue('theming', 'url', $this->url);
+       }
+
+       public function getSlogan() {
+               return $this->config->getAppValue('theming', 'slogan', $this->slogan);
+       }
+
+       public function getShortFooter() {
+               $slogan = $this->getSlogan();
+               $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
+                       ' rel="noreferrer">' .$this->getEntity() . '</a>'.
+                       ($slogan !== '' ? ' – ' . $slogan : '');
+
+               return $footer;
+       }
+
+       /**
+        * Color that is used for the header as well as for mail headers
+        *
+        * @return string
+        */
+       public function getMailHeaderColor() {
+               return $this->config->getAppValue('theming', 'color', $this->color);
+       }
+
+       /**
+        * Increases the cache buster key
+        */
+       private function increaseCacheBuster() {
+               $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
+               $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
+       }
+
+       /**
+        * Update setting in the database
+        *
+        * @param string $setting
+        * @param string $value
+        */
+       public function set($setting, $value) {
+               $this->config->setAppValue('theming', $setting, $value);
+               $this->increaseCacheBuster();
+       }
+
+       /**
+        * Revert settings to the default value
+        *
+        * @param string $setting setting which should be reverted
+        * @return string default value
+        */
+       public function undo($setting) {
+               $this->config->deleteAppValue('theming', $setting);
+               $this->increaseCacheBuster();
+
+               switch ($setting) {
+                       case 'name':
+                               $returnValue = $this->getEntity();
+                               break;
+                       case 'url':
+                               $returnValue = $this->getBaseUrl();
+                               break;
+                       case 'slogan':
+                               $returnValue = $this->getSlogan();
+                               break;
+                       case 'color':
+                               $returnValue = $this->getMailHeaderColor();
+                               break;
+                       default:
+                               $returnValue = '';
+                               break;
+               }
+
+               return $returnValue;
+       }
+
+}
diff --git a/apps/theming/tests/TemplateTest.php b/apps/theming/tests/TemplateTest.php
deleted file mode 100644 (file)
index c3c7926..0000000
+++ /dev/null
@@ -1,371 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-namespace OCA\Theming\Tests;
-
-use OCA\Theming\Template;
-use OCP\IConfig;
-use OCP\IL10N;
-use OCP\IURLGenerator;
-use Test\TestCase;
-
-class TemplateTest extends TestCase {
-       /** @var IConfig */
-       private $config;
-       /** @var IL10N */
-       private $l10n;
-       /** @var IURLGenerator */
-       private $urlGenerator;
-       /** @var \OC_Defaults */
-       private $defaults;
-       /** @var Template */
-       private $template;
-
-       public function setUp() {
-               $this->config = $this->getMock('\\OCP\\IConfig');
-               $this->l10n = $this->getMock('\\OCP\\IL10N');
-               $this->urlGenerator = $this->getMock('\\OCP\\IURLGenerator');
-               $this->defaults = $this->getMockBuilder('\\OC_Defaults')
-                       ->disableOriginalConstructor()
-                       ->getMock();
-               $this->defaults
-                       ->expects($this->at(0))
-                       ->method('getName')
-                       ->willReturn('Nextcloud');
-               $this->defaults
-                       ->expects($this->at(1))
-                       ->method('getBaseUrl')
-                       ->willReturn('https://nextcloud.com/');
-               $this->defaults
-                       ->expects($this->at(2))
-                       ->method('getSlogan')
-                       ->willReturn('Safe Data');
-               $this->defaults
-                       ->expects($this->at(3))
-                       ->method('getMailHeaderColor')
-                       ->willReturn('#000');
-               $this->template = new Template(
-                       $this->config,
-                       $this->l10n,
-                       $this->urlGenerator,
-                       $this->defaults
-               );
-
-               return parent::setUp();
-       }
-
-       public function testGetNameWithDefault() {
-               $this->config
-                       ->expects($this->once())
-                       ->method('getAppValue')
-                       ->with('theming', 'name', 'Nextcloud')
-                       ->willReturn('Nextcloud');
-
-               $this->assertEquals('Nextcloud', $this->template->getName());
-       }
-
-       public function testGetNameWithCustom() {
-               $this->config
-                       ->expects($this->once())
-                       ->method('getAppValue')
-                       ->with('theming', 'name', 'Nextcloud')
-                       ->willReturn('MyCustomCloud');
-
-               $this->assertEquals('MyCustomCloud', $this->template->getName());
-       }
-
-       public function testGetHTMLNameWithDefault() {
-               $this->config
-                       ->expects($this->once())
-                       ->method('getAppValue')
-                       ->with('theming', 'name', 'Nextcloud')
-                       ->willReturn('Nextcloud');
-
-               $this->assertEquals('Nextcloud', $this->template->getHTMLName());
-       }
-
-       public function testGetHTMLNameWithCustom() {
-               $this->config
-                       ->expects($this->once())
-                       ->method('getAppValue')
-                       ->with('theming', 'name', 'Nextcloud')
-                       ->willReturn('MyCustomCloud');
-
-               $this->assertEquals('MyCustomCloud', $this->template->getHTMLName());
-       }
-
-       public function testGetTitleWithDefault() {
-               $this->config
-                       ->expects($this->once())
-                       ->method('getAppValue')
-                       ->with('theming', 'name', 'Nextcloud')
-                       ->willReturn('Nextcloud');
-
-               $this->assertEquals('Nextcloud', $this->template->getTitle());
-       }
-
-       public function testGetTitleWithCustom() {
-               $this->config
-                       ->expects($this->once())
-                       ->method('getAppValue')
-                       ->with('theming', 'name', 'Nextcloud')
-                       ->willReturn('MyCustomCloud');
-
-               $this->assertEquals('MyCustomCloud', $this->template->getTitle());
-       }
-
-
-       public function testGetEntityWithDefault() {
-               $this->config
-                       ->expects($this->once())
-                       ->method('getAppValue')
-                       ->with('theming', 'name', 'Nextcloud')
-                       ->willReturn('Nextcloud');
-
-               $this->assertEquals('Nextcloud', $this->template->getEntity());
-       }
-
-       public function testGetEntityWithCustom() {
-               $this->config
-                       ->expects($this->once())
-                       ->method('getAppValue')
-                       ->with('theming', 'name', 'Nextcloud')
-                       ->willReturn('MyCustomCloud');
-
-               $this->assertEquals('MyCustomCloud', $this->template->getEntity());
-       }
-
-       public function testGetBaseUrlWithDefault() {
-               $this->config
-                       ->expects($this->once())
-                       ->method('getAppValue')
-                       ->with('theming', 'url', 'https://nextcloud.com/')
-                       ->willReturn('https://nextcloud.com/');
-
-               $this->assertEquals('https://nextcloud.com/', $this->template->getBaseUrl());
-       }
-
-       public function testGetBaseUrlWithCustom() {
-               $this->config
-                       ->expects($this->once())
-                       ->method('getAppValue')
-                       ->with('theming', 'url', 'https://nextcloud.com/')
-                       ->willReturn('https://example.com/');
-
-               $this->assertEquals('https://example.com/', $this->template->getBaseUrl());
-       }
-
-       public function testGetSloganWithDefault() {
-               $this->config
-                       ->expects($this->once())
-                       ->method('getAppValue')
-                       ->with('theming', 'slogan', 'Safe Data')
-                       ->willReturn('Safe Data');
-
-               $this->assertEquals('Safe Data', $this->template->getSlogan());
-       }
-
-       public function testGetSloganWithCustom() {
-               $this->config
-                       ->expects($this->once())
-                       ->method('getAppValue')
-                       ->with('theming', 'slogan', 'Safe Data')
-                       ->willReturn('My custom Slogan');
-
-               $this->assertEquals('My custom Slogan', $this->template->getSlogan());
-       }
-
-       public function testGetShortFooter() {
-               $this->config
-                       ->expects($this->exactly(3))
-                       ->method('getAppValue')
-                       ->willReturnMap([
-                               ['theming', 'url', 'https://nextcloud.com/', 'url'],
-                               ['theming', 'name', 'Nextcloud', 'Name'],
-                               ['theming', 'slogan', 'Safe Data', 'Slogan'],
-                       ]);
-
-               $this->assertEquals('<a href="url" target="_blank" rel="noreferrer">Name</a> – Slogan', $this->template->getShortFooter());
-       }
-
-       public function testGetShortFooterEmptySlogan() {
-               $this->config
-                       ->expects($this->exactly(3))
-                       ->method('getAppValue')
-                       ->willReturnMap([
-                               ['theming', 'url', 'https://nextcloud.com/', 'url'],
-                               ['theming', 'name', 'Nextcloud', 'Name'],
-                               ['theming', 'slogan', 'Safe Data', ''],
-                       ]);
-
-               $this->assertEquals('<a href="url" target="_blank" rel="noreferrer">Name</a>', $this->template->getShortFooter());
-       }
-
-       public function testGetMailHeaderColorWithDefault() {
-               $this->config
-                       ->expects($this->once())
-                       ->method('getAppValue')
-                       ->with('theming', 'color', '#000')
-                       ->willReturn('#000');
-
-               $this->assertEquals('#000', $this->template->getMailHeaderColor());
-       }
-
-       public function testGetMailHeaderColorWithCustom() {
-               $this->config
-                       ->expects($this->once())
-                       ->method('getAppValue')
-                       ->with('theming', 'color', '#000')
-                       ->willReturn('#fff');
-
-               $this->assertEquals('#fff', $this->template->getMailHeaderColor());
-       }
-
-       public function testSet() {
-               $this->config
-                       ->expects($this->at(0))
-                       ->method('setAppValue')
-                       ->with('theming', 'MySetting', 'MyValue');
-               $this->config
-                       ->expects($this->at(1))
-                       ->method('getAppValue')
-                       ->with('theming', 'cachebuster', '0')
-                       ->willReturn('15');
-               $this->config
-                       ->expects($this->at(2))
-                       ->method('setAppValue')
-                       ->with('theming', 'cachebuster', 16);
-
-               $this->template->set('MySetting', 'MyValue');
-       }
-
-       public function testUndoName() {
-               $this->config
-                       ->expects($this->at(0))
-                       ->method('deleteAppValue')
-                       ->with('theming', 'name');
-               $this->config
-                       ->expects($this->at(1))
-                       ->method('getAppValue')
-                       ->with('theming', 'cachebuster', '0')
-                       ->willReturn('15');
-               $this->config
-                       ->expects($this->at(2))
-                       ->method('setAppValue')
-                       ->with('theming', 'cachebuster', 16);
-               $this->config
-                       ->expects($this->at(3))
-                       ->method('getAppValue')
-                       ->with('theming', 'name', 'Nextcloud')
-                       ->willReturn('Nextcloud');
-
-               $this->assertSame('Nextcloud', $this->template->undo('name'));
-       }
-
-       public function testUndoBaseUrl() {
-               $this->config
-                       ->expects($this->at(0))
-                       ->method('deleteAppValue')
-                       ->with('theming', 'url');
-               $this->config
-                       ->expects($this->at(1))
-                       ->method('getAppValue')
-                       ->with('theming', 'cachebuster', '0')
-                       ->willReturn('15');
-               $this->config
-                       ->expects($this->at(2))
-                       ->method('setAppValue')
-                       ->with('theming', 'cachebuster', 16);
-               $this->config
-                       ->expects($this->at(3))
-                       ->method('getAppValue')
-                       ->with('theming', 'url', 'https://nextcloud.com/')
-                       ->willReturn('https://nextcloud.com/');
-
-               $this->assertSame('https://nextcloud.com/', $this->template->undo('url'));
-       }
-
-       public function testUndoSlogan() {
-               $this->config
-                       ->expects($this->at(0))
-                       ->method('deleteAppValue')
-                       ->with('theming', 'slogan');
-               $this->config
-                       ->expects($this->at(1))
-                       ->method('getAppValue')
-                       ->with('theming', 'cachebuster', '0')
-                       ->willReturn('15');
-               $this->config
-                       ->expects($this->at(2))
-                       ->method('setAppValue')
-                       ->with('theming', 'cachebuster', 16);
-               $this->config
-                       ->expects($this->at(3))
-                       ->method('getAppValue')
-                       ->with('theming', 'slogan', 'Safe Data')
-                       ->willReturn('Safe Data');
-
-               $this->assertSame('Safe Data', $this->template->undo('slogan'));
-       }
-
-       public function testUndoColor() {
-               $this->config
-                       ->expects($this->at(0))
-                       ->method('deleteAppValue')
-                       ->with('theming', 'color');
-               $this->config
-                       ->expects($this->at(1))
-                       ->method('getAppValue')
-                       ->with('theming', 'cachebuster', '0')
-                       ->willReturn('15');
-               $this->config
-                       ->expects($this->at(2))
-                       ->method('setAppValue')
-                       ->with('theming', 'cachebuster', 16);
-               $this->config
-                       ->expects($this->at(3))
-                       ->method('getAppValue')
-                       ->with('theming', 'color', '#000')
-                       ->willReturn('#000');
-
-               $this->assertSame('#000', $this->template->undo('color'));
-       }
-
-       public function testUndoDefaultAction() {
-               $this->config
-                       ->expects($this->at(0))
-                       ->method('deleteAppValue')
-                       ->with('theming', 'defaultitem');
-               $this->config
-                       ->expects($this->at(1))
-                       ->method('getAppValue')
-                       ->with('theming', 'cachebuster', '0')
-                       ->willReturn('15');
-               $this->config
-                       ->expects($this->at(2))
-                       ->method('setAppValue')
-                       ->with('theming', 'cachebuster', 16);
-
-               $this->assertSame('', $this->template->undo('defaultitem'));
-       }
-}
diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php
new file mode 100644 (file)
index 0000000..3440282
--- /dev/null
@@ -0,0 +1,372 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @author Joas Schilling <coding@schilljs.com>
+ * @author Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCA\Theming\Tests;
+
+use OCA\Theming\Template;
+use OCA\Theming\ThemingDefaults;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use Test\TestCase;
+
+class ThemingDefaultsTest extends TestCase {
+       /** @var IConfig */
+       private $config;
+       /** @var IL10N */
+       private $l10n;
+       /** @var IURLGenerator */
+       private $urlGenerator;
+       /** @var \OC_Defaults */
+       private $defaults;
+       /** @var Template */
+       private $template;
+
+       public function setUp() {
+               $this->config = $this->getMock('\\OCP\\IConfig');
+               $this->l10n = $this->getMock('\\OCP\\IL10N');
+               $this->urlGenerator = $this->getMock('\\OCP\\IURLGenerator');
+               $this->defaults = $this->getMockBuilder('\\OC_Defaults')
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $this->defaults
+                       ->expects($this->at(0))
+                       ->method('getName')
+                       ->willReturn('Nextcloud');
+               $this->defaults
+                       ->expects($this->at(1))
+                       ->method('getBaseUrl')
+                       ->willReturn('https://nextcloud.com/');
+               $this->defaults
+                       ->expects($this->at(2))
+                       ->method('getSlogan')
+                       ->willReturn('Safe Data');
+               $this->defaults
+                       ->expects($this->at(3))
+                       ->method('getMailHeaderColor')
+                       ->willReturn('#000');
+               $this->template = new ThemingDefaults(
+                       $this->config,
+                       $this->l10n,
+                       $this->urlGenerator,
+                       $this->defaults
+               );
+
+               return parent::setUp();
+       }
+
+       public function testGetNameWithDefault() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getAppValue')
+                       ->with('theming', 'name', 'Nextcloud')
+                       ->willReturn('Nextcloud');
+
+               $this->assertEquals('Nextcloud', $this->template->getName());
+       }
+
+       public function testGetNameWithCustom() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getAppValue')
+                       ->with('theming', 'name', 'Nextcloud')
+                       ->willReturn('MyCustomCloud');
+
+               $this->assertEquals('MyCustomCloud', $this->template->getName());
+       }
+
+       public function testGetHTMLNameWithDefault() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getAppValue')
+                       ->with('theming', 'name', 'Nextcloud')
+                       ->willReturn('Nextcloud');
+
+               $this->assertEquals('Nextcloud', $this->template->getHTMLName());
+       }
+
+       public function testGetHTMLNameWithCustom() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getAppValue')
+                       ->with('theming', 'name', 'Nextcloud')
+                       ->willReturn('MyCustomCloud');
+
+               $this->assertEquals('MyCustomCloud', $this->template->getHTMLName());
+       }
+
+       public function testGetTitleWithDefault() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getAppValue')
+                       ->with('theming', 'name', 'Nextcloud')
+                       ->willReturn('Nextcloud');
+
+               $this->assertEquals('Nextcloud', $this->template->getTitle());
+       }
+
+       public function testGetTitleWithCustom() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getAppValue')
+                       ->with('theming', 'name', 'Nextcloud')
+                       ->willReturn('MyCustomCloud');
+
+               $this->assertEquals('MyCustomCloud', $this->template->getTitle());
+       }
+
+
+       public function testGetEntityWithDefault() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getAppValue')
+                       ->with('theming', 'name', 'Nextcloud')
+                       ->willReturn('Nextcloud');
+
+               $this->assertEquals('Nextcloud', $this->template->getEntity());
+       }
+
+       public function testGetEntityWithCustom() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getAppValue')
+                       ->with('theming', 'name', 'Nextcloud')
+                       ->willReturn('MyCustomCloud');
+
+               $this->assertEquals('MyCustomCloud', $this->template->getEntity());
+       }
+
+       public function testGetBaseUrlWithDefault() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getAppValue')
+                       ->with('theming', 'url', 'https://nextcloud.com/')
+                       ->willReturn('https://nextcloud.com/');
+
+               $this->assertEquals('https://nextcloud.com/', $this->template->getBaseUrl());
+       }
+
+       public function testGetBaseUrlWithCustom() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getAppValue')
+                       ->with('theming', 'url', 'https://nextcloud.com/')
+                       ->willReturn('https://example.com/');
+
+               $this->assertEquals('https://example.com/', $this->template->getBaseUrl());
+       }
+
+       public function testGetSloganWithDefault() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getAppValue')
+                       ->with('theming', 'slogan', 'Safe Data')
+                       ->willReturn('Safe Data');
+
+               $this->assertEquals('Safe Data', $this->template->getSlogan());
+       }
+
+       public function testGetSloganWithCustom() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getAppValue')
+                       ->with('theming', 'slogan', 'Safe Data')
+                       ->willReturn('My custom Slogan');
+
+               $this->assertEquals('My custom Slogan', $this->template->getSlogan());
+       }
+
+       public function testGetShortFooter() {
+               $this->config
+                       ->expects($this->exactly(3))
+                       ->method('getAppValue')
+                       ->willReturnMap([
+                               ['theming', 'url', 'https://nextcloud.com/', 'url'],
+                               ['theming', 'name', 'Nextcloud', 'Name'],
+                               ['theming', 'slogan', 'Safe Data', 'Slogan'],
+                       ]);
+
+               $this->assertEquals('<a href="url" target="_blank" rel="noreferrer">Name</a> – Slogan', $this->template->getShortFooter());
+       }
+
+       public function testGetShortFooterEmptySlogan() {
+               $this->config
+                       ->expects($this->exactly(3))
+                       ->method('getAppValue')
+                       ->willReturnMap([
+                               ['theming', 'url', 'https://nextcloud.com/', 'url'],
+                               ['theming', 'name', 'Nextcloud', 'Name'],
+                               ['theming', 'slogan', 'Safe Data', ''],
+                       ]);
+
+               $this->assertEquals('<a href="url" target="_blank" rel="noreferrer">Name</a>', $this->template->getShortFooter());
+       }
+
+       public function testGetMailHeaderColorWithDefault() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getAppValue')
+                       ->with('theming', 'color', '#000')
+                       ->willReturn('#000');
+
+               $this->assertEquals('#000', $this->template->getMailHeaderColor());
+       }
+
+       public function testGetMailHeaderColorWithCustom() {
+               $this->config
+                       ->expects($this->once())
+                       ->method('getAppValue')
+                       ->with('theming', 'color', '#000')
+                       ->willReturn('#fff');
+
+               $this->assertEquals('#fff', $this->template->getMailHeaderColor());
+       }
+
+       public function testSet() {
+               $this->config
+                       ->expects($this->at(0))
+                       ->method('setAppValue')
+                       ->with('theming', 'MySetting', 'MyValue');
+               $this->config
+                       ->expects($this->at(1))
+                       ->method('getAppValue')
+                       ->with('theming', 'cachebuster', '0')
+                       ->willReturn('15');
+               $this->config
+                       ->expects($this->at(2))
+                       ->method('setAppValue')
+                       ->with('theming', 'cachebuster', 16);
+
+               $this->template->set('MySetting', 'MyValue');
+       }
+
+       public function testUndoName() {
+               $this->config
+                       ->expects($this->at(0))
+                       ->method('deleteAppValue')
+                       ->with('theming', 'name');
+               $this->config
+                       ->expects($this->at(1))
+                       ->method('getAppValue')
+                       ->with('theming', 'cachebuster', '0')
+                       ->willReturn('15');
+               $this->config
+                       ->expects($this->at(2))
+                       ->method('setAppValue')
+                       ->with('theming', 'cachebuster', 16);
+               $this->config
+                       ->expects($this->at(3))
+                       ->method('getAppValue')
+                       ->with('theming', 'name', 'Nextcloud')
+                       ->willReturn('Nextcloud');
+
+               $this->assertSame('Nextcloud', $this->template->undo('name'));
+       }
+
+       public function testUndoBaseUrl() {
+               $this->config
+                       ->expects($this->at(0))
+                       ->method('deleteAppValue')
+                       ->with('theming', 'url');
+               $this->config
+                       ->expects($this->at(1))
+                       ->method('getAppValue')
+                       ->with('theming', 'cachebuster', '0')
+                       ->willReturn('15');
+               $this->config
+                       ->expects($this->at(2))
+                       ->method('setAppValue')
+                       ->with('theming', 'cachebuster', 16);
+               $this->config
+                       ->expects($this->at(3))
+                       ->method('getAppValue')
+                       ->with('theming', 'url', 'https://nextcloud.com/')
+                       ->willReturn('https://nextcloud.com/');
+
+               $this->assertSame('https://nextcloud.com/', $this->template->undo('url'));
+       }
+
+       public function testUndoSlogan() {
+               $this->config
+                       ->expects($this->at(0))
+                       ->method('deleteAppValue')
+                       ->with('theming', 'slogan');
+               $this->config
+                       ->expects($this->at(1))
+                       ->method('getAppValue')
+                       ->with('theming', 'cachebuster', '0')
+                       ->willReturn('15');
+               $this->config
+                       ->expects($this->at(2))
+                       ->method('setAppValue')
+                       ->with('theming', 'cachebuster', 16);
+               $this->config
+                       ->expects($this->at(3))
+                       ->method('getAppValue')
+                       ->with('theming', 'slogan', 'Safe Data')
+                       ->willReturn('Safe Data');
+
+               $this->assertSame('Safe Data', $this->template->undo('slogan'));
+       }
+
+       public function testUndoColor() {
+               $this->config
+                       ->expects($this->at(0))
+                       ->method('deleteAppValue')
+                       ->with('theming', 'color');
+               $this->config
+                       ->expects($this->at(1))
+                       ->method('getAppValue')
+                       ->with('theming', 'cachebuster', '0')
+                       ->willReturn('15');
+               $this->config
+                       ->expects($this->at(2))
+                       ->method('setAppValue')
+                       ->with('theming', 'cachebuster', 16);
+               $this->config
+                       ->expects($this->at(3))
+                       ->method('getAppValue')
+                       ->with('theming', 'color', '#000')
+                       ->willReturn('#000');
+
+               $this->assertSame('#000', $this->template->undo('color'));
+       }
+
+       public function testUndoDefaultAction() {
+               $this->config
+                       ->expects($this->at(0))
+                       ->method('deleteAppValue')
+                       ->with('theming', 'defaultitem');
+               $this->config
+                       ->expects($this->at(1))
+                       ->method('getAppValue')
+                       ->with('theming', 'cachebuster', '0')
+                       ->willReturn('15');
+               $this->config
+                       ->expects($this->at(2))
+                       ->method('setAppValue')
+                       ->with('theming', 'cachebuster', 16);
+
+               $this->assertSame('', $this->template->undo('defaultitem'));
+       }
+}
index 7de927eb88c466b1491e683f3a9111fabb82259a..69574b975aae65f2715ced7e8d0551572aabf81f 100644 (file)
@@ -82,7 +82,7 @@ use OC\Security\SecureRandom;
 use OC\Security\TrustedDomainHelper;
 use OC\Session\CryptoWrapper;
 use OC\Tagging\TagMapper;
-use OCA\Theming\Template;
+use OCA\Theming\ThemingDefaults;
 use OCP\IL10N;
 use OCP\IServerContainer;
 use OCP\Security\IContentSecurityPolicyManager;
@@ -650,7 +650,7 @@ class Server extends ServerContainer implements IServerContainer {
                        }
 
                        if ($classExists && $this->getConfig()->getSystemValue('installed', false) && $this->getAppManager()->isInstalled('theming')) {
-                               return new Template(
+                               return new ThemingDefaults(
                                        $this->getConfig(),
                                        $this->getL10N('theming'),
                                        $this->getURLGenerator(),