Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/juliushaertl/theming_customcss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2017-04-29 11:48:50 +0300
committerJulius Härtl <jus@bitgrid.net>2017-04-29 11:48:50 +0300
commite8339da3614f7248a59b055101d85086c99f1aaa (patch)
treee4cab36d9f7d69ac02339238c760f1d271ad4f22
Initial commit
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r--appinfo/app.php38
-rw-r--r--appinfo/info.xml20
-rw-r--r--appinfo/routes.php31
-rw-r--r--css/settings-admin.css5
-rw-r--r--img/app-dark.svg1
-rw-r--r--img/app.svg1
-rw-r--r--js/settings-admin.js40
-rw-r--r--l10n/.gitkeep0
-rw-r--r--lib/Controller/ThemingController.php96
-rw-r--r--lib/Settings/Admin.php84
-rw-r--r--phpunit.xml12
-rw-r--r--templates/settings-admin.php34
-rw-r--r--tests/Controller/ThemingControllerTest.php97
-rw-r--r--tests/Settings/AdminTest.php81
-rw-r--r--tests/bootstrap.php35
15 files changed, 575 insertions, 0 deletions
diff --git a/appinfo/app.php b/appinfo/app.php
new file mode 100644
index 0000000..873bc31
--- /dev/null
+++ b/appinfo/app.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @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/>.
+ *
+ */
+
+$linkToCSS = \OC::$server->getURLGenerator()->linkToRoute(
+ 'theming_customcss.Theming.getStylesheet',
+ [
+ 'v' => \OC::$server->getConfig()->getAppValue('theming_customcss', 'cachebuster', '0'),
+ ]
+);
+\OCP\Util::addHeader(
+ 'link',
+ [
+ 'rel' => 'stylesheet',
+ 'href' => $linkToCSS,
+ ]
+);
+
+$app = new \OCP\AppFramework\App('theming_customcss');
diff --git a/appinfo/info.xml b/appinfo/info.xml
new file mode 100644
index 0000000..1a77982
--- /dev/null
+++ b/appinfo/info.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<info>
+ <id>theming_customcss</id>
+ <name>Theming custom CSS</name>
+ <description>Adjust the Nextcloud theme with custom CSS</description>
+ <licence>AGPL</licence>
+ <author>Nextcloud</author>
+ <version>1.0.0</version>
+ <namespace>ThemingCustomCss</namespace>
+ <category>other</category>
+
+ <dependencies>
+ <nextcloud min-version="12" max-version="12" />
+ </dependencies>
+
+ <settings>
+ <admin>OCA\ThemingCustomCss\Settings\Admin</admin>
+ </settings>
+
+</info>
diff --git a/appinfo/routes.php b/appinfo/routes.php
new file mode 100644
index 0000000..eb3717e
--- /dev/null
+++ b/appinfo/routes.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @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/>.
+ *
+ */
+
+return ['routes' => [
+ [
+ 'name' => 'Theming#getStylesheet',
+ 'url' => '/styles',
+ 'verb' => 'GET',
+ ]
+]];
+
diff --git a/css/settings-admin.css b/css/settings-admin.css
new file mode 100644
index 0000000..eed726f
--- /dev/null
+++ b/css/settings-admin.css
@@ -0,0 +1,5 @@
+#theming-customcss textarea {
+ width:100%;
+ height:200px;
+ font-family: monospace;
+} \ No newline at end of file
diff --git a/img/app-dark.svg b/img/app-dark.svg
new file mode 100644
index 0000000..adf9796
--- /dev/null
+++ b/img/app-dark.svg
@@ -0,0 +1 @@
+<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M10.707 11.412l-.587-.587-.03-.03a.513.513 0 0 1-.074-.526L13.07 3.4l-1.5-1.498-.15.15-.708-.706.505-.505a.538.538 0 0 1 .224-.128c.04-.01.05-.01.087-.016h.087c.04.006.05.006.086.016.072.02.134.055.192.1.74.676 1.42 1.415 2.127 2.124a.503.503 0 0 1 .103.556l-3.053 6.87.344.343.49-.49 3.01 3.01a1.192 1.192 0 0 1-1.685 1.686l-3.012-3.01.49-.488zm-.533-10.217a.986.986 0 0 0-1.396 0l-7.582 7.58a.99.99 0 0 0 0 1.398l1.397 1.396a.986.986 0 0 0 1.396 0l7.58-7.583a.988.988 0 0 0 0-1.396l-1.396-1.395z" fill="#000"/></svg>
diff --git a/img/app.svg b/img/app.svg
new file mode 100644
index 0000000..cbca87d
--- /dev/null
+++ b/img/app.svg
@@ -0,0 +1 @@
+<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M10.707 11.412l-.587-.587-.03-.03a.513.513 0 0 1-.074-.526L13.07 3.4l-1.5-1.498-.15.15-.708-.706.505-.505a.538.538 0 0 1 .224-.128c.04-.01.05-.01.087-.016h.087c.04.006.05.006.086.016.072.02.134.055.192.1.74.676 1.42 1.415 2.127 2.124a.503.503 0 0 1 .103.556l-3.053 6.87.344.343.49-.49 3.01 3.01a1.192 1.192 0 0 1-1.685 1.686l-3.012-3.01.49-.488zm-.533-10.217a.986.986 0 0 0-1.396 0l-7.582 7.58a.99.99 0 0 0 0 1.398l1.397 1.396a.986.986 0 0 0 1.396 0l7.58-7.583a.988.988 0 0 0 0-1.396l-1.396-1.395z" fill="#fff"/></svg> \ No newline at end of file
diff --git a/js/settings-admin.js b/js/settings-admin.js
new file mode 100644
index 0000000..15f152d
--- /dev/null
+++ b/js/settings-admin.js
@@ -0,0 +1,40 @@
+
+/*
+ * @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @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/>.
+ *
+ */
+$(document).ready(function () {
+ $('html > head').append($('<style type="text/css" id="previewStylesCustom"></style>'));
+ $('#theming-customcss button').click(function (e) {
+ var content = $('#theming-customcss-input').val();
+ OCP.AppConfig.setValue('theming_customcss', 'customcss', content, {
+ success: function () {
+ OC.msg.finishedSuccess('#theming-customcss_settings_msg', t('theming_customcss', 'Saved'));
+ $('link[href*="theming_customcss/styles"]').remove();
+ $('#previewStylesCustom').replaceWith($('<style type="text/css" id="previewStylesCustom">'+content+'</style>'));
+ OCP.AppConfig.setValue('theming_customcss', 'cachebuster', Date.now);
+ },
+ error: function () {
+ OC.msg.finishedError('#theming-customcss_settings_msg', t('theming_customcss', 'Error'));
+ }
+ });
+ OC.msg.startSaving('#theming-customcss_settings_msg');
+ });
+});
diff --git a/l10n/.gitkeep b/l10n/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/l10n/.gitkeep
diff --git a/lib/Controller/ThemingController.php b/lib/Controller/ThemingController.php
new file mode 100644
index 0000000..b62bd5d
--- /dev/null
+++ b/lib/Controller/ThemingController.php
@@ -0,0 +1,96 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @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\ThemingCustomCss\Controller;
+
+use OC\Template\SCSSCacher;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\DataDisplayResponse;
+use OCP\AppFramework\Http\NotFoundResponse;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Files\IAppData;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IRequest;
+
+class ThemingController extends Controller {
+ /** @var ITimeFactory */
+ private $timeFactory;
+ /** @var IL10N */
+ private $l10n;
+ /** @var IConfig */
+ private $config;
+ /** @var IAppData */
+ private $appData;
+ /** @var SCSSCacher */
+ private $scssCacher;
+
+ /**
+ * ThemingController constructor.
+ *
+ * @param string $appName
+ * @param IRequest $request
+ * @param IConfig $config
+ * @param ITimeFactory $timeFactory
+ * @param IL10N $l
+ * @param IAppData $appData
+ * @param SCSSCacher $scssCacher
+ */
+ public function __construct(
+ $appName,
+ IRequest $request,
+ IConfig $config,
+ ITimeFactory $timeFactory,
+ IL10N $l,
+ IAppData $appData,
+ SCSSCacher $scssCacher
+ ) {
+ parent::__construct($appName, $request);
+
+ $this->timeFactory = $timeFactory;
+ $this->l10n = $l;
+ $this->config = $config;
+ $this->appData = $appData;
+ $this->scssCacher = $scssCacher;
+ }
+
+ /**
+ * @NoCSRFRequired
+ * @PublicPage
+ *
+ * @return DataDisplayResponse|NotFoundResponse
+ */
+ public function getStylesheet() {
+ // TODO: compile SCSS and cache that as a file
+ $customCss = $this->config->getAppValue('theming_customcss', 'customcss', '');
+ $response = new DataDisplayResponse($customCss, Http::STATUS_OK, ['Content-Type' => 'text/css']);
+ $response->cacheFor(86400);
+ $expires = new \DateTime();
+ $expires->setTimestamp($this->timeFactory->getTime());
+ $expires->add(new \DateInterval('PT24H'));
+ $response->addHeader('Expires', $expires->format(\DateTime::RFC1123));
+ $response->addHeader('Pragma', 'cache');
+ return $response;
+ }
+}
diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php
new file mode 100644
index 0000000..21d2c24
--- /dev/null
+++ b/lib/Settings/Admin.php
@@ -0,0 +1,84 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @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\ThemingCustomCss\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() {
+ $customcss = $this->config->getAppValue('theming_customcss', 'customcss', '');
+
+ $parameters = [
+ 'customcss' => $customcss
+ ];
+
+ return new TemplateResponse('theming_customcss', '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 10;
+ }
+
+}
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
index 0000000..e5fd49c
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,12 @@
+<phpunit bootstrap="tests/bootstrap.php" colors="true">
+<testsuites>
+ <testsuite name="unit">
+ <directory>./tests/unit</directory>
+ </testsuite>
+</testsuites>
+<filter>
+<whitelist>
+ <directory suffix=".php">./</directory>
+</whitelist>
+</filter>
+</phpunit>
diff --git a/templates/settings-admin.php b/templates/settings-admin.php
new file mode 100644
index 0000000..f451588
--- /dev/null
+++ b/templates/settings-admin.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @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/>.
+ *
+ */
+script('theming_customcss', 'settings-admin');
+style('theming_customcss', 'settings-admin');
+?>
+<div id="theming-customcss" class="section">
+ <h2 class="inlineblock"><?php p($l->t('Theming')); ?></h2>
+ <p class="settings-hint"><?php p($l->t('You can specify your own CSS here. Be aware that this might break something after upgrade.')); ?></p>
+ <div id="theming-customcss_settings_msg" class="msg success inlineblock" style="display: none;">Saved</div>
+ <div>
+ <textarea id="theming-customcss-input" placeholder="<?php p($l->t('Insert your custom CSS here…')); ?>"><?php p($_['customcss']) ?></textarea>
+ <button class="primary">Save</button>
+ </div>
+</div>
diff --git a/tests/Controller/ThemingControllerTest.php b/tests/Controller/ThemingControllerTest.php
new file mode 100644
index 0000000..2453ada
--- /dev/null
+++ b/tests/Controller/ThemingControllerTest.php
@@ -0,0 +1,97 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @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\ThemingCustomCss\Tests\Controller;
+
+use OC\L10N\L10N;
+use OC\Template\SCSSCacher;
+use OCA\ThemingCustomCss\Controller\ThemingController;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Files\IAppData;
+use OCP\Files\NotFoundException;
+use OCP\Files\SimpleFS\ISimpleFile;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IRequest;
+use Test\TestCase;
+
+class ThemingControllerTest extends TestCase {
+ /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
+ private $request;
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
+ private $config;
+ /** @var \OCP\AppFramework\Utility\ITimeFactory */
+ private $timeFactory;
+ /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
+ private $l10n;
+ /** @var ThemingController */
+ private $themingController;
+ /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
+ private $appData;
+ /** @var SCSSCacher */
+ private $scssCacher;
+
+ public function setUp() {
+ $this->request = $this->createMock(IRequest::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
+ $this->l10n = $this->createMock(L10N::class);
+ $this->appData = $this->createMock(IAppData::class);
+ $this->scssCacher = $this->createMock(SCSSCacher::class);
+
+ $this->timeFactory->expects($this->any())
+ ->method('getTime')
+ ->willReturn(123);
+
+ $this->themingController = new ThemingController(
+ 'theming',
+ $this->request,
+ $this->config,
+ $this->timeFactory,
+ $this->l10n,
+ $this->appData,
+ $this->scssCacher
+ );
+
+ return parent::setUp();
+ }
+
+ public function testGetStylesheet() {
+
+ $this->config->expects($this->at(0))
+ ->method('getAppValue')
+ ->with('theming_customcss', 'customcss', '')
+ ->willReturn('* { background-color: black; }');
+
+ $response = new DataDisplayResponse('* { background-color: black; }', Http::STATUS_OK, ['Content-Type' => 'text/css']);
+ $response->cacheFor(86400);
+ $expires = new \DateTime();
+ $expires->setTimestamp($this->timeFactory->getTime());
+ $expires->add(new \DateInterval('PT24H'));
+ $response->addHeader('Expires', $expires->format(\DateTime::RFC1123));
+ $response->addHeader('Pragma', 'cache');
+ $actual = $this->themingController->getStylesheet();
+ $this->assertEquals($response, $actual);
+ }
+
+}
diff --git a/tests/Settings/AdminTest.php b/tests/Settings/AdminTest.php
new file mode 100644
index 0000000..e913442
--- /dev/null
+++ b/tests/Settings/AdminTest.php
@@ -0,0 +1,81 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @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->at(0))
+ ->method('getAppValue')
+ ->with('theming_customcss', 'customcss', '')
+ ->willReturn('* { background-color: black; }');
+ $params = [
+ 'customcss' => '* { background-color: black; }',
+ ];
+
+ $expected = new TemplateResponse('theming_customcss', 'settings-admin', $params, '');
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ public function testGetSection() {
+ $this->assertSame('theming', $this->admin->getSection());
+ }
+
+ public function testGetPriority() {
+ $this->assertSame(10, $this->admin->getPriority());
+ }
+}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
new file mode 100644
index 0000000..45855bf
--- /dev/null
+++ b/tests/bootstrap.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @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/>.
+ *
+ */
+
+require_once __DIR__.'/../../../tests/bootstrap.php';
+
+
+require_once __DIR__.'/../../../lib/base.php';
+if (!class_exists('PHPUnit_Framework_TestCase')) {
+ require_once('PHPUnit/Autoload.php');
+}
+
+\OC_App::loadApp('theming_customcss');
+
+OC_Hook::clear();
+