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
|
|
|
class CollectionsServiceTest extends TestCase { |
32
|
|
|
private $collectionsService; |
33
|
|
|
private $settings; |
34
|
|
|
private $userId; |
35
|
|
|
private $l10n; |
36
|
|
|
private $appName; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Gets run before each test |
40
|
|
|
*/ |
41
|
|
View Code Duplication |
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->l10n = $this->createMock(IL10N::class); |
48
|
|
|
$this->collectionsService = new CollectionsService( |
49
|
|
|
$this->userId, |
50
|
|
|
$this->l10n, |
|
|
|
|
51
|
|
|
$this->settings, |
52
|
|
|
$this->appName |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testGetAll() { |
57
|
|
|
$return = [ |
58
|
|
|
[ |
59
|
|
|
'id' => "starred", |
60
|
|
|
'displayName' => 'Important', |
61
|
|
|
'show' => 2, |
62
|
|
|
'icon' => 'Star'], |
63
|
|
|
[ |
64
|
|
|
'id' => "today", |
65
|
|
|
'displayName' => 'Today', |
66
|
|
|
'show' => 2, |
67
|
|
|
'icon' => 'CalendarToday'], |
68
|
|
|
[ |
69
|
|
|
'id' => "week", |
70
|
|
|
'displayName' => 'Week', |
71
|
|
|
'show' => 2, |
72
|
|
|
'icon' => 'CalendarWeek'], |
73
|
|
|
[ |
74
|
|
|
'id' => "all", |
75
|
|
|
'displayName' => 'All', |
76
|
|
|
'show' => 2, |
77
|
|
|
'icon' => 'CircleOutline'], |
78
|
|
|
[ |
79
|
|
|
'id' => "current", |
80
|
|
|
'displayName' => 'Current', |
81
|
|
|
'show' => 2, |
82
|
|
|
'icon' => 'TrendingUp'], |
83
|
|
|
[ |
84
|
|
|
'id' => "completed", |
85
|
|
|
'displayName' => 'Completed', |
86
|
|
|
'show' => 2, |
87
|
|
|
'icon' => 'Check'] |
88
|
|
|
]; |
89
|
|
|
|
90
|
|
|
$map = [ |
91
|
|
|
['Important', [],'Important'], |
92
|
|
|
['Today', [], 'Today'], |
93
|
|
|
['Week', [], 'Week'], |
94
|
|
|
['All', [], 'All'], |
95
|
|
|
['Completed', [], 'Completed'], |
96
|
|
|
['Current', [], 'Current'] |
97
|
|
|
]; |
98
|
|
|
|
99
|
|
|
$this->l10n->expects($this->any()) |
100
|
|
|
->method('t') |
101
|
|
|
->will( |
102
|
|
|
$this->returnValueMap($map) |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$result = $this->collectionsService->getAll(); |
106
|
|
|
|
107
|
|
|
$this->assertEquals($return, $result); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
public function testSetVisibility() { |
112
|
|
|
$return = true; |
113
|
|
|
|
114
|
|
|
$this->settings->expects($this->once()) |
115
|
|
|
->method('setUserValue') |
116
|
|
|
->with( |
117
|
|
|
$this->equalTo($this->userId), |
118
|
|
|
$this->equalTo($this->appName), |
119
|
|
|
'show_starred', |
120
|
|
|
0 |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
$result = $this->collectionsService->setVisibility('starred', 0); |
124
|
|
|
// These lines should not lead to a call of '$this->settings->setUserValue' |
125
|
|
|
$this->collectionsService->setVisibility('starred', -1); |
126
|
|
|
$this->collectionsService->setVisibility('starred', '3'); |
127
|
|
|
|
128
|
|
|
$this->assertEquals($return, $result); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.