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

github.com/nextcloud/theming_customcss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
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 /tests
Initial commit
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'tests')
-rw-r--r--tests/Controller/ThemingControllerTest.php97
-rw-r--r--tests/Settings/AdminTest.php81
-rw-r--r--tests/bootstrap.php35
3 files changed, 213 insertions, 0 deletions
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();
+