Completed
Push — master ( ab0d18...cdc6cb )
by Raimund
01:45 queued 12s
created

SettingsServiceTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Nextcloud - Tasks
4
 *
5
 * @author Raimund Schlüßler
6
 * @copyright 2018 Raimund Schlüßler <[email protected]>
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
 * License as published by the Free Software Foundation; either
11
 * version 3 of the License, or any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
namespace OCA\Tasks\Tests\Unit\Service;
24
25
use OCA\Tasks\Service\SettingsService;
26
use OCP\IConfig;
27
28
use PHPUnit\Framework\TestCase;
29
30
31
class SettingsServiceTest extends TestCase {
32
33
	private $settingsService;
34
	private $settings;
35
	private $userId;
36
	private $appName;
37
38
	/**
39
	 * Gets run before each test
40
	 */
41
	protected function setUp(): void {
42
		$this->appName = 'tasks';
43
		$this->userId = 'admin';
44
		$this->settings = $this->getMockBuilder(IConfig::class)
45
			->disableOriginalConstructor()
46
			->getMock();
47
		$this->settingsService = new SettingsService(
48
			$this->userId,
49
			$this->settings,
50
			$this->appName
51
		);
52
	}
53
54
	public function testGet() {
55
		$return = [
56
			'defaultCalendarId' => 'personal',
57
			'showHidden' => 1,
58
			'sortOrder' => 'default',
59
			'sortDirection' => false,
60
			'userID' => $this->userId,
61
			'allDay' => false
62
		];
63
64
		$map = [
65
			[
66
				$this->userId,
67
				$this->appName,
68
				'various_defaultCalendarId',
69
				'',
70
				'personal'
71
			],
72
			[
73
				$this->userId,
74
				$this->appName,
75
				'various_showHidden',
76
				'',
77
				1
78
			],
79
			[
80
				$this->userId,
81
				$this->appName,
82
				'various_sortOrder',
83
				'',
84
				'default'
85
			],
86
			[
87
				$this->userId,
88
				$this->appName,
89
				'various_sortDirection',
90
				'',
91
				false
92
			],
93
			[
94
				$this->userId,
95
				$this->appName,
96
				'various_allDay',
97
				'',
98
				false
99
			]
100
		];
101
102
		$this->settings->expects($this->any())
103
			->method('getUserValue')
104
			->will(
105
				$this->returnValueMap($map)
106
			);
107
108
		$result = $this->settingsService->get();
109
110
		$this->assertEquals($return, $result);
111
	}
112
113
114
	public function testSet() {
115
		$return = true;
116
		
117
		$this->settings->expects($this->once())
118
			->method('setUserValue')
119
			->with(
120
				$this->equalTo($this->userId),
121
				$this->equalTo($this->appName),
122
				'various_defaultCalendarId',
123
				'personal'
124
			);
125
		
126
		$result = $this->settingsService->set('defaultCalendarId', 'personal');
127
128
		$this->assertEquals($return, $result);
129
	}
130
}
131