diff options
author | Raimund Schlüßler <raimund.schluessler@mailbox.org> | 2019-07-20 09:10:32 +0300 |
---|---|---|
committer | Raimund Schlüßler <raimund.schluessler@mailbox.org> | 2019-07-20 09:10:32 +0300 |
commit | 73ad10f887bee2669cdf8141c50fbf775a47a8d0 (patch) | |
tree | 6bac8ed659d5c9e8b21d96a5bbb4b2b4c6c9734b /tests | |
parent | b3fef47f20b56e3fc038f05667b0f21aa3a2972a (diff) |
Add SettingsService Test
Signed-off-by: Raimund Schlüßler <raimund.schluessler@mailbox.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/Service/SettingsServiceTest.php | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/tests/unit/Service/SettingsServiceTest.php b/tests/unit/Service/SettingsServiceTest.php new file mode 100644 index 00000000..d8897ae6 --- /dev/null +++ b/tests/unit/Service/SettingsServiceTest.php @@ -0,0 +1,121 @@ +<?php +/** + * Nextcloud - Tasks + * + * @author Raimund Schlüßler + * @copyright 2018 Raimund Schlüßler <raimund.schluessler@mailbox.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library 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 library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Tasks\Tests\Unit\Service; + +use OCA\Tasks\Service\SettingsService; +use OCP\IConfig; + +use PHPUnit\Framework\TestCase; + + +class SettingsServiceTest extends TestCase { + + private $settingsService; + private $settings; + private $userId; + private $appName; + + /** + * Gets run before each test + */ + protected function setUp(): void { + $this->appName = 'tasks'; + $this->userId = 'admin'; + $this->settings = $this->getMockBuilder(IConfig::class) + ->disableOriginalConstructor() + ->getMock(); + $this->settingsService = new SettingsService( + $this->userId, + $this->settings, + $this->appName + ); + } + + public function testGet() { + $return = [ + 'defaultCalendarId' => 'personal', + 'showHidden' => 0, + 'sortOrder' => 'default', + 'sortDirection' => false, + 'userID' => $this->userId + ]; + + $this->settings->expects($this->at(0)) + ->method('getUserValue') + ->with( + $this->equalTo($this->userId), + $this->equalTo($this->appName), + 'various_defaultCalendarId' + ) + ->will($this->returnValue('personal')); + + $this->settings->expects($this->at(1)) + ->method('getUserValue') + ->with( + $this->equalTo($this->userId), + $this->equalTo($this->appName), + 'various_showHidden' + ) + ->will($this->returnValue(0)); + + $this->settings->expects($this->at(2)) + ->method('getUserValue') + ->with( + $this->equalTo($this->userId), + $this->equalTo($this->appName), + 'various_sortOrder' + ) + ->will($this->returnValue('default')); + + $this->settings->expects($this->at(3)) + ->method('getUserValue') + ->with( + $this->equalTo($this->userId), + $this->equalTo($this->appName), + 'various_sortDirection' + ) + ->will($this->returnValue(false)); + + $result = $this->settingsService->get(); + + $this->assertEquals($return, $result); + } + + + public function testSet() { + $return = true; + + $this->settings->expects($this->once()) + ->method('setUserValue') + ->with( + $this->equalTo($this->userId), + $this->equalTo($this->appName), + 'various_defaultCalendarId', + 'personal' + ); + + $result = $this->settingsService->set('defaultCalendarId', 'personal'); + + $this->assertEquals($return, $result); + } +} |