Completed
Push — master ( dfd9fa...12a57f )
by Raimund
30s queued 10s
created

SettingsServiceTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 92
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 12 1
A testGet() 0 50 1
A testSet() 0 16 1
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
		];
62
63
		$map = [
64
			[
65
				$this->userId,
66
				$this->appName,
67
				'various_defaultCalendarId',
68
				'',
69
				'personal'
70
			],
71
			[
72
				$this->userId,
73
				$this->appName,
74
				'various_showHidden',
75
				'',
76
				1
77
			],
78
			[
79
				$this->userId,
80
				$this->appName,
81
				'various_sortOrder',
82
				'',
83
				'default'
84
			],
85
			[
86
				$this->userId,
87
				$this->appName,
88
				'various_sortDirection',
89
				'',
90
				false
91
			]
92
		];
93
94
		$this->settings->expects($this->any())
95
			->method('getUserValue')
96
			->will(
97
				$this->returnValueMap($map)
98
			);
99
100
		$result = $this->settingsService->get();
101
102
		$this->assertEquals($return, $result);
103
	}
104
105
106
	public function testSet() {
107
		$return = true;
108
		
109
		$this->settings->expects($this->once())
110
			->method('setUserValue')
111
			->with(
112
				$this->equalTo($this->userId),
113
				$this->equalTo($this->appName),
114
				'various_defaultCalendarId',
115
				'personal'
116
			);
117
		
118
		$result = $this->settingsService->set('defaultCalendarId', 'personal');
119
120
		$this->assertEquals($return, $result);
121
	}
122
}
123