summaryrefslogtreecommitdiffstats
path: root/apps/theming
diff options
context:
space:
mode:
Diffstat (limited to 'apps/theming')
-rw-r--r--apps/theming/appinfo/app.php2
-rw-r--r--apps/theming/appinfo/info.xml7
-rw-r--r--apps/theming/lib/Controller/ThemingController.php8
-rw-r--r--apps/theming/lib/Settings/Admin.php98
-rw-r--r--apps/theming/lib/Settings/Section.php67
-rw-r--r--apps/theming/lib/ThemingDefaults.php (renamed from apps/theming/lib/Template.php)25
-rw-r--r--apps/theming/settings/settings-admin.php52
-rw-r--r--apps/theming/tests/Controller/ThemingControllerTest.php6
-rw-r--r--apps/theming/tests/Settings/AdminTest.php155
-rw-r--r--apps/theming/tests/Settings/SectionTest.php62
-rw-r--r--apps/theming/tests/ThemingDefaultsTest.php (renamed from apps/theming/tests/TemplateTest.php)8
11 files changed, 409 insertions, 81 deletions
diff --git a/apps/theming/appinfo/app.php b/apps/theming/appinfo/app.php
index 051a2e279e5..f558c35e61f 100644
--- a/apps/theming/appinfo/app.php
+++ b/apps/theming/appinfo/app.php
@@ -23,8 +23,6 @@
*
*/
-\OCP\App::registerAdmin('theming', 'settings/settings-admin');
-
$linkToCSS = \OC::$server->getURLGenerator()->linkToRoute(
'theming.Theming.getStylesheet',
[
diff --git a/apps/theming/appinfo/info.xml b/apps/theming/appinfo/info.xml
index 8ae1d3eb73a..423d11d2aef 100644
--- a/apps/theming/appinfo/info.xml
+++ b/apps/theming/appinfo/info.xml
@@ -5,7 +5,7 @@
<description>Adjust the Nextcloud theme</description>
<licence>AGPL</licence>
<author>Nextcloud</author>
- <version>1.1.0</version>
+ <version>1.1.1</version>
<namespace>Theming</namespace>
<category>other</category>
@@ -18,4 +18,9 @@
</types>
<default_enable/>
+
+ <settings>
+ <admin>OCA\Theming\Settings\Admin</admin>
+ <admin-section>OCA\Theming\Settings\Section</admin-section>
+ </settings>
</info>
diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php
index 0db4dfe0627..8d3e2a5f2e2 100644
--- a/apps/theming/lib/Controller/ThemingController.php
+++ b/apps/theming/lib/Controller/ThemingController.php
@@ -27,7 +27,7 @@
namespace OCA\Theming\Controller;
-use OCA\Theming\Template;
+use OCA\Theming\ThemingDefaults;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataDownloadResponse;
@@ -48,7 +48,7 @@ use OCA\Theming\Util;
* @package OCA\Theming\Controller
*/
class ThemingController extends Controller {
- /** @var Template */
+ /** @var ThemingDefaults */
private $template;
/** @var Util */
private $util;
@@ -67,7 +67,7 @@ class ThemingController extends Controller {
* @param string $appName
* @param IRequest $request
* @param IConfig $config
- * @param Template $template
+ * @param ThemingDefaults $template
* @param Util $util
* @param ITimeFactory $timeFactory
* @param IL10N $l
@@ -77,7 +77,7 @@ class ThemingController extends Controller {
$appName,
IRequest $request,
IConfig $config,
- Template $template,
+ ThemingDefaults $template,
Util $util,
ITimeFactory $timeFactory,
IL10N $l,
diff --git a/apps/theming/lib/Settings/Admin.php b/apps/theming/lib/Settings/Admin.php
new file mode 100644
index 00000000000..1f79449e658
--- /dev/null
+++ b/apps/theming/lib/Settings/Admin.php
@@ -0,0 +1,98 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @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\Settings;
+
+use OCA\Theming\ThemingDefaults;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\Settings\ISettings;
+
+class Admin implements ISettings {
+ /** @var IConfig */
+ private $config;
+ /** @var IL10N */
+ private $l;
+ /** @var ThemingDefaults */
+ private $themingDefaults;
+ /** @var IURLGenerator */
+ private $urlGenerator;
+
+ public function __construct(IConfig $config,
+ IL10N $l,
+ ThemingDefaults $themingDefaults,
+ IURLGenerator $urlGenerator) {
+ $this->config = $config;
+ $this->l = $l;
+ $this->themingDefaults = $themingDefaults;
+ $this->urlGenerator = $urlGenerator;
+ }
+
+ /**
+ * @return TemplateResponse
+ */
+ public function getForm() {
+ $path = $this->urlGenerator->linkToRoute('theming.Theming.updateLogo');
+
+ $themable = true;
+ $errorMessage = '';
+ $theme = $this->config->getSystemValue('theme', '');
+ if ($theme !== '') {
+ $themable = false;
+ $errorMessage = $this->l->t('You already use a custom theme');
+ }
+
+ $parameters = [
+ 'themable' => $themable,
+ 'errorMessage' => $errorMessage,
+ 'name' => $this->themingDefaults->getEntity(),
+ 'url' => $this->themingDefaults->getBaseUrl(),
+ 'slogan' => $this->themingDefaults->getSlogan(),
+ 'color' => $this->themingDefaults->getMailHeaderColor(),
+ 'uploadLogoRoute' => $path,
+ ];
+
+ return new TemplateResponse('theming', 'settings-admin', $parameters, '');
+ }
+
+ /**
+ * @return string the section ID, e.g. 'sharing'
+ */
+ public function getSection() {
+ return 'theming';
+ }
+
+ /**
+ * @return int whether the form should be rather on the top or bottom of
+ * the admin section. The forms are arranged in ascending order of the
+ * priority values. It is required to return a value between 0 and 100.
+ *
+ * E.g.: 70
+ */
+ public function getPriority() {
+ return 5;
+ }
+
+}
diff --git a/apps/theming/lib/Settings/Section.php b/apps/theming/lib/Settings/Section.php
new file mode 100644
index 00000000000..cffbb8901c8
--- /dev/null
+++ b/apps/theming/lib/Settings/Section.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @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\Settings;
+
+use OCP\IL10N;
+use OCP\Settings\ISection;
+
+class Section implements ISection {
+ /** @var IL10N */
+ private $l;
+
+ public function __construct(IL10N $l) {
+ $this->l = $l;
+ }
+
+ /**
+ * returns the ID of the section. It is supposed to be a lower case string,
+ * e.g. 'ldap'
+ *
+ * @returns string
+ */
+ public function getID() {
+ return 'theming';
+ }
+
+ /**
+ * returns the translated name as it should be displayed, e.g. 'LDAP / AD
+ * integration'. Use the L10N service to translate it.
+ *
+ * @return string
+ */
+ public function getName() {
+ return $this->l->t('Theming');
+ }
+
+ /**
+ * @return int whether the form should be rather on the top or bottom of
+ * the settings navigation. The sections are arranged in ascending order of
+ * the priority values. It is required to return a value between 0 and 99.
+ *
+ * E.g.: 70
+ */
+ public function getPriority() {
+ return 30;
+ }
+}
diff --git a/apps/theming/lib/Template.php b/apps/theming/lib/ThemingDefaults.php
index 25730aad95b..7b846919db3 100644
--- a/apps/theming/lib/Template.php
+++ b/apps/theming/lib/ThemingDefaults.php
@@ -1,11 +1,6 @@
<?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
*
@@ -24,20 +19,19 @@
*
*/
+
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 {
+
+class ThemingDefaults extends \OC_Defaults {
+
/** @var IConfig */
private $config;
/** @var IL10N */
@@ -54,7 +48,7 @@ class Template extends \OC_Defaults {
private $color;
/**
- * Template constructor.
+ * ThemingDefaults constructor.
*
* @param IConfig $config
* @param IL10N $l
@@ -92,7 +86,7 @@ class Template extends \OC_Defaults {
public function getEntity() {
return $this->config->getAppValue('theming', 'name', $this->name);
}
-
+
public function getBaseUrl() {
return $this->config->getAppValue('theming', 'url', $this->url);
}
@@ -168,4 +162,5 @@ class Template extends \OC_Defaults {
return $returnValue;
}
+
}
diff --git a/apps/theming/settings/settings-admin.php b/apps/theming/settings/settings-admin.php
deleted file mode 100644
index 8ef499789e8..00000000000
--- a/apps/theming/settings/settings-admin.php
+++ /dev/null
@@ -1,52 +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 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/>.
- *
- */
-
-$config = \OC::$server->getConfig();
-$l = \OC::$server->getL10N('theming');
-$urlGenerator = \OC::$server->getURLGenerator();
-
-$theming = \OC::$server->getThemingDefaults();
-
-$themable = true;
-$errorMessage = '';
-$theme = $config->getSystemValue('theme', '');
-
-if ($theme !== '') {
- $themable = false;
- $errorMessage = $l->t('You already use a custom theme');
-}
-
-$template = new \OCP\Template('theming', 'settings-admin');
-
-$template->assign('themable', $themable);
-$template->assign('errorMessage', $errorMessage);
-$template->assign('name', $theming->getEntity());
-$template->assign('url', $theming->getBaseUrl());
-$template->assign('slogan', $theming->getSlogan());
-$template->assign('color', $theming->getMailHeaderColor());
-$path = $urlGenerator->linkToRoute('theming.Theming.updateLogo');
-$template->assign('uploadLogoRoute', $path);
-
-return $template->fetchPage();
diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php
index 81b6b886c9f..688e3d62bff 100644
--- a/apps/theming/tests/Controller/ThemingControllerTest.php
+++ b/apps/theming/tests/Controller/ThemingControllerTest.php
@@ -25,7 +25,6 @@
namespace OCA\Theming\Tests\Controller;
use OCA\Theming\Controller\ThemingController;
-use OCA\Theming\Template;
use OCA\Theming\Util;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
@@ -34,13 +33,14 @@ use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use Test\TestCase;
+use OCA\Theming\ThemingDefaults;
class ThemingControllerTest extends TestCase {
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
private $request;
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
private $config;
- /** @var Template|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var ThemingDefaults|\PHPUnit_Framework_MockObject_MockObject */
private $template;
/** @var Util */
private $util;
@@ -56,7 +56,7 @@ class ThemingControllerTest extends TestCase {
public function setUp() {
$this->request = $this->getMockBuilder('OCP\IRequest')->getMock();
$this->config = $this->getMockBuilder('OCP\IConfig')->getMock();
- $this->template = $this->getMockBuilder('OCA\Theming\Template')
+ $this->template = $this->getMockBuilder('OCA\Theming\ThemingDefaults')
->disableOriginalConstructor()->getMock();
$this->util = new Util();
$this->timeFactory = $this->getMockBuilder('OCP\AppFramework\Utility\ITimeFactory')
diff --git a/apps/theming/tests/Settings/AdminTest.php b/apps/theming/tests/Settings/AdminTest.php
new file mode 100644
index 00000000000..18c2064e8ce
--- /dev/null
+++ b/apps/theming/tests/Settings/AdminTest.php
@@ -0,0 +1,155 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @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\Settings;
+
+use OCA\Theming\Settings\Admin;
+use OCA\Theming\ThemingDefaults;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use Test\TestCase;
+
+class AdminTest extends TestCase {
+ /** @var Admin */
+ private $admin;
+ /** @var IConfig */
+ private $config;
+ /** @var ThemingDefaults */
+ private $themingDefaults;
+ /** @var IURLGenerator */
+ private $urlGenerator;
+ /** @var IL10N */
+ private $l10n;
+
+ public function setUp() {
+ parent::setUp();
+ $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock();
+ $this->l10n = $this->getMockBuilder('\OCP\IL10N')->getMock();
+ $this->themingDefaults = $this->getMockBuilder('\OCA\Theming\ThemingDefaults')->disableOriginalConstructor()->getMock();
+ $this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')->getMock();
+
+ $this->admin = new Admin(
+ $this->config,
+ $this->l10n,
+ $this->themingDefaults,
+ $this->urlGenerator
+ );
+ }
+
+ public function testGetFormNoErrors() {
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValue')
+ ->with('theme', '')
+ ->willReturn('');
+ $this->themingDefaults
+ ->expects($this->once())
+ ->method('getEntity')
+ ->willReturn('MyEntity');
+ $this->themingDefaults
+ ->expects($this->once())
+ ->method('getBaseUrl')
+ ->willReturn('https://example.com');
+ $this->themingDefaults
+ ->expects($this->once())
+ ->method('getSlogan')
+ ->willReturn('MySlogan');
+ $this->themingDefaults
+ ->expects($this->once())
+ ->method('getMailHeaderColor')
+ ->willReturn('#fff');
+ $this->urlGenerator
+ ->expects($this->once())
+ ->method('linkToRoute')
+ ->with('theming.Theming.updateLogo')
+ ->willReturn('/my/route');
+ $params = [
+ 'themable' => true,
+ 'errorMessage' => '',
+ 'name' => 'MyEntity',
+ 'url' => 'https://example.com',
+ 'slogan' => 'MySlogan',
+ 'color' => '#fff',
+ 'uploadLogoRoute' => '/my/route',
+ ];
+
+ $expected = new TemplateResponse('theming', 'settings-admin', $params, '');
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ public function testGetFormWithErrors() {
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValue')
+ ->with('theme', '')
+ ->willReturn('MyCustomTheme');
+ $this->l10n
+ ->expects($this->once())
+ ->method('t')
+ ->with('You already use a custom theme')
+ ->willReturn('You already use a custom theme');
+ $this->themingDefaults
+ ->expects($this->once())
+ ->method('getEntity')
+ ->willReturn('MyEntity');
+ $this->themingDefaults
+ ->expects($this->once())
+ ->method('getBaseUrl')
+ ->willReturn('https://example.com');
+ $this->themingDefaults
+ ->expects($this->once())
+ ->method('getSlogan')
+ ->willReturn('MySlogan');
+ $this->themingDefaults
+ ->expects($this->once())
+ ->method('getMailHeaderColor')
+ ->willReturn('#fff');
+ $this->urlGenerator
+ ->expects($this->once())
+ ->method('linkToRoute')
+ ->with('theming.Theming.updateLogo')
+ ->willReturn('/my/route');
+ $params = [
+ 'themable' => false,
+ 'errorMessage' => 'You already use a custom theme',
+ 'name' => 'MyEntity',
+ 'url' => 'https://example.com',
+ 'slogan' => 'MySlogan',
+ 'color' => '#fff',
+ 'uploadLogoRoute' => '/my/route',
+ ];
+
+ $expected = new TemplateResponse('theming', 'settings-admin', $params, '');
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ public function testGetSection() {
+ $this->assertSame('theming', $this->admin->getSection());
+ }
+
+ public function testGetPriority() {
+ $this->assertSame(5, $this->admin->getPriority());
+ }
+}
diff --git a/apps/theming/tests/Settings/SectionTest.php b/apps/theming/tests/Settings/SectionTest.php
new file mode 100644
index 00000000000..3a3a4375236
--- /dev/null
+++ b/apps/theming/tests/Settings/SectionTest.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @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\Settings;
+
+use OCA\Theming\Settings\Section;
+use OCP\IL10N;
+use Test\TestCase;
+
+class SectionTest extends TestCase {
+ /** @var IL10N */
+ private $l;
+ /** @var Section */
+ private $section;
+
+ public function setUp() {
+ parent::setUp();
+ $this->l = $this->getMockBuilder('\OCP\IL10N')->getMock();
+
+ $this->section = new Section(
+ $this->l
+ );
+ }
+
+ public function testGetID() {
+ $this->assertSame('theming', $this->section->getID());
+ }
+
+ public function testGetName() {
+ $this->l
+ ->expects($this->once())
+ ->method('t')
+ ->with('Theming')
+ ->willReturn('Theming');
+
+ $this->assertSame('Theming', $this->section->getName());
+ }
+
+ public function testGetPriority() {
+ $this->assertSame(30, $this->section->getPriority());
+ }
+}
diff --git a/apps/theming/tests/TemplateTest.php b/apps/theming/tests/ThemingDefaultsTest.php
index c3c792657ec..6ef7deea152 100644
--- a/apps/theming/tests/TemplateTest.php
+++ b/apps/theming/tests/ThemingDefaultsTest.php
@@ -23,13 +23,13 @@
*/
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 TemplateTest extends TestCase {
+class ThemingDefaultsTest extends TestCase {
/** @var IConfig */
private $config;
/** @var IL10N */
@@ -38,7 +38,7 @@ class TemplateTest extends TestCase {
private $urlGenerator;
/** @var \OC_Defaults */
private $defaults;
- /** @var Template */
+ /** @var ThemingDefaults */
private $template;
public function setUp() {
@@ -64,7 +64,7 @@ class TemplateTest extends TestCase {
->expects($this->at(3))
->method('getMailHeaderColor')
->willReturn('#000');
- $this->template = new Template(
+ $this->template = new ThemingDefaults(
$this->config,
$this->l10n,
$this->urlGenerator,