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\CollectionsService; |
26
|
|
|
use OCP\IConfig; |
27
|
|
|
use OCP\IL10N; |
28
|
|
|
|
29
|
|
|
use PHPUnit\Framework\TestCase; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
class CollectionsServiceTest extends TestCase { |
33
|
|
|
|
34
|
|
|
private $collectionsService; |
35
|
|
|
private $settings; |
36
|
|
|
private $userId; |
37
|
|
|
private $l10n; |
38
|
|
|
private $appName; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Gets run before each test |
42
|
|
|
*/ |
43
|
|
|
protected function setUp(): void { |
44
|
|
|
$this->appName = 'tasks'; |
45
|
|
|
$this->userId = 'admin'; |
46
|
|
|
$this->settings = $this->getMockBuilder(IConfig::class) |
47
|
|
|
->disableOriginalConstructor() |
48
|
|
|
->getMock(); |
49
|
|
|
$this->l10n = $this->createMock(IL10N::class); |
50
|
|
|
$this->collectionsService = new CollectionsService( |
51
|
|
|
$this->userId, |
52
|
|
|
$this->l10n, |
53
|
|
|
$this->settings, |
54
|
|
|
$this->appName |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testGetAll() { |
59
|
|
|
$return = array( |
60
|
|
|
array( |
61
|
|
|
'id' => "starred", |
62
|
|
|
'displayName' => 'Important', |
63
|
|
|
'show' => 2, |
64
|
|
|
'icon' => 'icon-task-star'), |
65
|
|
|
array( |
66
|
|
|
'id' => "today", |
67
|
|
|
'displayName' => 'Today', |
68
|
|
|
'show' => 2, |
69
|
|
|
'icon' => 'icon-calendar'), |
70
|
|
|
array( |
71
|
|
|
'id' => "week", |
72
|
|
|
'displayName' => 'Week', |
73
|
|
|
'show' => 2, |
74
|
|
|
'icon' => 'icon-calendar'), |
75
|
|
|
array( |
76
|
|
|
'id' => "all", |
77
|
|
|
'displayName' => 'All', |
78
|
|
|
'show' => 2, |
79
|
|
|
'icon' => 'icon-all'), |
80
|
|
|
array( |
81
|
|
|
'id' => "current", |
82
|
|
|
'displayName' => 'Current', |
83
|
|
|
'show' => 2, |
84
|
|
|
'icon' => 'icon-current'), |
85
|
|
|
array( |
86
|
|
|
'id' => "completed", |
87
|
|
|
'displayName' => 'Completed', |
88
|
|
|
'show' => 2, |
89
|
|
|
'icon' => 'icon-checkmark') |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
$map = [ |
93
|
|
|
['Important', [],'Important'], |
94
|
|
|
['Today', [], 'Today'], |
95
|
|
|
['Week', [], 'Week'], |
96
|
|
|
['All', [], 'All'], |
97
|
|
|
['Completed', [], 'Completed'], |
98
|
|
|
['Current', [], 'Current'] |
99
|
|
|
]; |
100
|
|
|
|
101
|
|
|
$this->l10n->expects($this->any()) |
102
|
|
|
->method('t') |
103
|
|
|
->will( |
104
|
|
|
$this->returnValueMap($map) |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
$result = $this->collectionsService->getAll(); |
108
|
|
|
|
109
|
|
|
$this->assertEquals($return, $result); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
public function testSetVisibility() { |
114
|
|
|
$return = true; |
115
|
|
|
|
116
|
|
|
$this->settings->expects($this->once()) |
117
|
|
|
->method('setUserValue') |
118
|
|
|
->with( |
119
|
|
|
$this->equalTo($this->userId), |
120
|
|
|
$this->equalTo($this->appName), |
121
|
|
|
'show_starred', |
122
|
|
|
0 |
123
|
|
|
); |
124
|
|
|
|
125
|
|
|
$result = $this->collectionsService->setVisibility('starred', 0); |
126
|
|
|
// These lines should not lead to a call of '$this->settings->setUserValue' |
127
|
|
|
$this->collectionsService->setVisibility('starred', -1); |
128
|
|
|
$this->collectionsService->setVisibility('starred', '3'); |
129
|
|
|
|
130
|
|
|
$this->assertEquals($return, $result); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|