diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-08-15 16:24:56 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-08-15 16:25:34 +0200 |
commit | 8a7a0f328746230dd896ccc53b3ada271a91b930 (patch) | |
tree | aaaaedf7167b74c48a91c90671f705edb71bc541 /apps/theming | |
parent | 75a73a5a7301f203a962a17f6b2b8b90078c1884 (diff) | |
download | nextcloud-server-8a7a0f328746230dd896ccc53b3ada271a91b930.tar.gz nextcloud-server-8a7a0f328746230dd896ccc53b3ada271a91b930.zip |
Add unit tests
Diffstat (limited to 'apps/theming')
-rw-r--r-- | apps/theming/lib/Settings/Admin.php | 9 | ||||
-rw-r--r-- | apps/theming/tests/Controller/ThemingControllerTest.php | 1 | ||||
-rw-r--r-- | apps/theming/tests/Settings/AdminTest.php | 155 | ||||
-rw-r--r-- | apps/theming/tests/Settings/SectionTest.php | 62 |
4 files changed, 222 insertions, 5 deletions
diff --git a/apps/theming/lib/Settings/Admin.php b/apps/theming/lib/Settings/Admin.php index 8aba4696e00..1f79449e658 100644 --- a/apps/theming/lib/Settings/Admin.php +++ b/apps/theming/lib/Settings/Admin.php @@ -31,20 +31,19 @@ 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) { + 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/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index 2662cb16e0f..688e3d62bff 100644 --- a/apps/theming/tests/Controller/ThemingControllerTest.php +++ b/apps/theming/tests/Controller/ThemingControllerTest.php @@ -33,6 +33,7 @@ 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 */ diff --git a/apps/theming/tests/Settings/AdminTest.php b/apps/theming/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..ff42c6997a6 --- /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->createMock('\OCP\IConfig'); + $this->l10n = $this->createMock('\OCP\IL10N'); + $this->themingDefaults = $this->createMock('\OCA\Theming\ThemingDefaults'); + $this->urlGenerator = $this->createMock('\OCP\IURLGenerator'); + + $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..e8a9a217f1f --- /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->createMock('\OCP\IL10N'); + + $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()); + } +} |