diff options
author | brantje <brantje@gmail.com> | 2016-12-30 18:56:57 +0300 |
---|---|---|
committer | brantje <brantje@gmail.com> | 2016-12-30 18:59:48 +0300 |
commit | 863d7c49859fe7bcf049b86c73b00795e97439ca (patch) | |
tree | 49f57b18e839fe810a2cd09c12c0a9087ca800c1 /tests | |
parent | 3bbaa6296b4f8f9b8d78db45fd8469825f72ac99 (diff) |
Add test for Settings, improve SettingsService
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/controller/SettingsControllerTest.php | 93 | ||||
-rw-r--r-- | tests/unit/lib/Service/SettingsServiceTest.php | 86 |
2 files changed, 179 insertions, 0 deletions
diff --git a/tests/unit/controller/SettingsControllerTest.php b/tests/unit/controller/SettingsControllerTest.php new file mode 100644 index 00000000..808e7b89 --- /dev/null +++ b/tests/unit/controller/SettingsControllerTest.php @@ -0,0 +1,93 @@ +<?php +/** + * Nextcloud - passman + * + * @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com) + * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es) + * @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\Passman\Controller; + +use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use PHPUnit_Framework_TestCase; +use OCA\Passman\Service\SettingsService; + +/** + * Class PageControllerTest + * + * @package OCA\Passman\Controller + * @coversDefaultClass \OCA\Passman\Controller\SettingsController + */ +class SettingsControllerTest extends PHPUnit_Framework_TestCase { + + private $controller; + + public function setUp() { + $request = $this->getMockBuilder('OCP\IRequest')->getMock(); + $IL10N = $this->getMockBuilder('OCP\IL10N')->getMock(); + $config = $this->getMockBuilder('OCP\IConfig')->getMock(); + $userId = 'admin'; + $settings = new SettingsService($userId, $config, 'passman'); + + $this->controller = new SettingsController( + 'passman', $request, $userId, $settings, $IL10N + ); + } + + /** + * @covers ::getForm + */ + public function testGetForm() { + $result = $this->controller->getForm(); + $this->assertTrue($result instanceof TemplateResponse); + } + + /** + * @covers ::getPriority + */ + public function testGetPriority() { + $result = $this->controller->getPriority(); + $this->assertTrue($result === 0); + } + + /** + * @covers ::getSettings + */ + public function testGetSettings() { + $result = $this->controller->getsettings(); + $this->assertTrue($result instanceof JSONResponse); + } + + /** + * @covers ::saveUserSetting + */ + public function testSaveUserSetting() { + $result = $this->controller->saveUserSetting('test','value'); + $this->assertTrue($result instanceof JSONResponse); + } + + /** + * @covers ::saveAdminSetting + */ + public function testSaveAdminSetting() { + $result = $this->controller->saveAdminSetting('admin', 'value'); + $this->assertTrue($result instanceof JSONResponse); + } +}
\ No newline at end of file diff --git a/tests/unit/lib/Service/SettingsServiceTest.php b/tests/unit/lib/Service/SettingsServiceTest.php new file mode 100644 index 00000000..1444263e --- /dev/null +++ b/tests/unit/lib/Service/SettingsServiceTest.php @@ -0,0 +1,86 @@ +<?php +/** + * Nextcloud - passman + * + * @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com) + * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es) + * @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\Passman\Controller; + +use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use PHPUnit_Framework_TestCase; +use OCA\Passman\Service\SettingsService; + +/** + * Class PageControllerTest + * + * @package OCA\Passman\Controller + * @coversDefaultClass \OCA\Passman\Service\SettingsServiceTest + */ +class SettingsServiceTest extends PHPUnit_Framework_TestCase { + + private $service; + + public function setUp() { + $config = $this->getMockBuilder('OCP\IConfig')->getMock(); + $userId = 'admin'; + $this->service = new SettingsService($userId, $config, 'passman'); + } + + /** + * @covers ::getAppSettings + */ + public function testGetAppSettings() { + $result = $this->service->getAppSettings(); + $this->assertTrue(is_array($result)); + } + + /** + * @covers ::getAppSetting + */ + public function testGetAppSetting() { + $result = $this->service->getAppSetting('settings_loaded', 1); + $this->assertTrue($result === 1); + } + + /** + * @covers ::setAppSetting + */ + public function testSetAppSetting() { + $this->service->setAppSetting('settings_loaded', 0); + $this->assertTrue( $this->service->getAppSetting('settings_loaded') === 0); + } + /** + * @covers ::setUserSetting + */ + public function testSetUserSetting() { + $this->service->setUserSetting('test','value'); + } + + /** + * On tests link_sharing is disabled + * @covers ::isEnabled + */ + public function testIsEnabled() { + $result = $this->service->isEnabled('link_sharing_enabled'); + $this->assertFalse($result); + } +}
\ No newline at end of file |