1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Calendar App |
4
|
|
|
* |
5
|
|
|
* @author Georg Ehrke |
6
|
|
|
* @copyright 2016 Georg Ehrke <[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
|
|
|
namespace OCA\Calendar\Controller; |
23
|
|
|
|
24
|
|
|
function scandir($directory) { |
25
|
|
|
$dir = substr(__DIR__, 0, -strlen('tests/php/controller')) . 'controller/../timezones/'; |
26
|
|
|
return $dir === $directory ? [ |
27
|
|
|
'..', |
28
|
|
|
'.', |
29
|
|
|
'TIMEZONE1.ics', |
30
|
|
|
'TIMEZONE2.ics', |
31
|
|
|
'REG-CIT.ics', |
32
|
|
|
'INFO.md', |
33
|
|
|
] : []; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function file_get_contents($file) { |
37
|
|
|
$file_parts = explode('/', $file); |
38
|
|
|
end($file_parts); |
39
|
|
|
$file = current($file_parts); |
40
|
|
|
switch($file) { |
41
|
|
|
case 'TIMEZONE1.ics': |
42
|
|
|
return 'TIMEZONE1-data'; |
43
|
|
|
|
44
|
|
|
case 'TIMEZONE2.ics': |
45
|
|
|
return 'ANOTHER TIMEZONE DATA'; |
46
|
|
|
|
47
|
|
|
case 'REG-CIT.ics': |
48
|
|
|
return 'TIMEZONE DATA WITH REGION AND CITY'; |
49
|
|
|
|
50
|
|
|
default: |
51
|
|
|
return null; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
class ViewControllerTest extends \PHPUnit_Framework_TestCase { |
56
|
|
|
|
57
|
|
|
private $appName; |
58
|
|
|
private $request; |
59
|
|
|
private $config; |
60
|
|
|
private $userSession; |
61
|
|
|
private $mailer; |
62
|
|
|
private $l10n; |
63
|
|
|
private $defaults; |
64
|
|
|
private $urlGenerator; |
65
|
|
|
|
66
|
|
|
private $dummyUser; |
67
|
|
|
|
68
|
|
|
private $controller; |
69
|
|
|
|
70
|
|
|
public function setUp() { |
71
|
|
|
$this->appName = 'calendar'; |
72
|
|
|
$this->request = $this->getMockBuilder('\OCP\IRequest') |
73
|
|
|
->disableOriginalConstructor() |
74
|
|
|
->getMock(); |
75
|
|
|
$this->config = $this->getMockBuilder('\OCP\IConfig') |
76
|
|
|
->disableOriginalConstructor() |
77
|
|
|
->getMock(); |
78
|
|
|
$this->userSession = $this->getMockBuilder('\OCP\IUserSession') |
79
|
|
|
->disableOriginalConstructor() |
80
|
|
|
->getMock(); |
81
|
|
|
|
82
|
|
|
$this->dummyUser = $this->getMockBuilder('OCP\IUser') |
83
|
|
|
->disableOriginalConstructor() |
84
|
|
|
->getMock(); |
85
|
|
|
|
86
|
|
|
$this->mailer = $this->getMockBuilder('\OCP\Mail\IMailer') |
87
|
|
|
->disableOriginalConstructor() |
88
|
|
|
->getMock(); |
89
|
|
|
|
90
|
|
|
$this->l10n = $this->getMockBuilder('OC\L10N\L10N') |
91
|
|
|
->disableOriginalConstructor() |
92
|
|
|
->getMock(); |
93
|
|
|
|
94
|
|
|
$this->defaults = $this->getMockBuilder('OCP\Defaults') |
95
|
|
|
->disableOriginalConstructor() |
96
|
|
|
->getMock(); |
97
|
|
|
|
98
|
|
|
$this->urlGenerator = $this->getMockBuilder('OCP\IURLGenerator') |
99
|
|
|
->disableOriginalConstructor() |
100
|
|
|
->getMock(); |
101
|
|
|
|
102
|
|
|
$this->controller = new ViewController($this->appName, $this->request, |
103
|
|
|
$this->userSession, $this->config, $this->mailer, $this->l10n, $this->defaults, $this->urlGenerator); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @dataProvider indexDataProvider |
108
|
|
|
*/ |
109
|
|
|
public function testIndex($isAssetPipelineEnabled, $showAssetPipelineError, $serverVersion, $expectsSupportsClass, $expectsWebcalWorkaround) { |
110
|
|
|
$this->config->expects($this->at(0)) |
111
|
|
|
->method('getSystemValue') |
112
|
|
|
->with('version') |
113
|
|
|
->will($this->returnValue($serverVersion)); |
114
|
|
|
|
115
|
|
|
$this->config->expects($this->at(1)) |
116
|
|
|
->method('getSystemValue') |
117
|
|
|
->with('asset-pipeline.enabled', false) |
118
|
|
|
->will($this->returnValue($isAssetPipelineEnabled)); |
119
|
|
|
|
120
|
|
|
if ($showAssetPipelineError) { |
121
|
|
|
$actual = $this->controller->index(); |
122
|
|
|
|
123
|
|
|
$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $actual); |
124
|
|
|
$this->assertEquals([], $actual->getParams()); |
125
|
|
|
$this->assertEquals('main-asset-pipeline-unsupported', $actual->getTemplateName()); |
126
|
|
|
} else { |
127
|
|
|
$this->userSession->expects($this->once()) |
128
|
|
|
->method('getUser') |
129
|
|
|
->will($this->returnValue($this->dummyUser)); |
130
|
|
|
|
131
|
|
|
$this->dummyUser->expects($this->once()) |
132
|
|
|
->method('getUID') |
133
|
|
|
->will($this->returnValue('user123')); |
134
|
|
|
|
135
|
|
|
$this->dummyUser->expects($this->once()) |
136
|
|
|
->method('getEMailAddress') |
137
|
|
|
->will($this->returnValue('[email protected]')); |
138
|
|
|
|
139
|
|
|
$this->config->expects($this->at(2)) |
140
|
|
|
->method('getAppValue') |
141
|
|
|
->with($this->appName, 'installed_version') |
142
|
|
|
->will($this->returnValue('42.13.37')); |
143
|
|
|
|
144
|
|
|
$this->config->expects($this->at(3)) |
145
|
|
|
->method('getUserValue') |
146
|
|
|
->with('user123', $this->appName, 'currentView', 'month') |
147
|
|
|
->will($this->returnValue('someView')); |
148
|
|
|
|
149
|
|
|
$this->config->expects($this->at(4)) |
150
|
|
|
->method('getUserValue') |
151
|
|
|
->with('user123', $this->appName, 'skipPopover', 'no') |
152
|
|
|
->will($this->returnValue('someSkipPopoverValue')); |
153
|
|
|
|
154
|
|
|
$this->config->expects($this->at(5)) |
155
|
|
|
->method('getUserValue') |
156
|
|
|
->with('user123', $this->appName, 'showWeekNr', 'no') |
157
|
|
|
->will($this->returnValue('someShowWeekNrValue')); |
158
|
|
|
|
159
|
|
|
$this->config->expects($this->at(6)) |
160
|
|
|
->method('getAppValue') |
161
|
|
|
->with('theming', 'color', '#0082C9') |
162
|
|
|
->will($this->returnValue('#ff00ff')); |
163
|
|
|
|
164
|
|
|
$actual = $this->controller->index(); |
165
|
|
|
|
166
|
|
|
$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $actual); |
167
|
|
|
$this->assertEquals([ |
168
|
|
|
'appVersion' => '42.13.37', |
169
|
|
|
'defaultView' => 'someView', |
170
|
|
|
'emailAddress' => '[email protected]', |
171
|
|
|
'skipPopover' => 'someSkipPopoverValue', |
172
|
|
|
'weekNumbers' => 'someShowWeekNrValue', |
173
|
|
|
'supportsClass' => $expectsSupportsClass, |
174
|
|
|
'defaultColor' => '#ff00ff', |
175
|
|
|
'webCalWorkaround' => $expectsWebcalWorkaround, |
176
|
|
|
'isPublic' => false, |
177
|
|
|
], $actual->getParams()); |
178
|
|
|
$this->assertEquals('main', $actual->getTemplateName()); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function indexDataProvider() { |
184
|
|
|
return [ |
185
|
|
|
[true, true, '9.0.5.2', false, 'yes'], |
186
|
|
|
[true, false, '9.1.0.0', true, 'no'], |
187
|
|
|
[false, false, '9.0.5.2', false, 'yes'], |
188
|
|
|
[false, false, '9.1.0.0', true, 'no'] |
189
|
|
|
]; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @dataProvider indexPublicDataProvider |
194
|
|
|
*/ |
195
|
|
|
public function testPublicIndex($isAssetPipelineEnabled, $showAssetPipelineError, $serverVersion, $expectsSupportsClass) { |
196
|
|
|
$this->config->expects($this->at(0)) |
197
|
|
|
->method('getSystemValue') |
198
|
|
|
->with('version') |
199
|
|
|
->will($this->returnValue($serverVersion)); |
200
|
|
|
|
201
|
|
|
$this->config->expects($this->at(1)) |
202
|
|
|
->method('getSystemValue') |
203
|
|
|
->with('asset-pipeline.enabled', false) |
204
|
|
|
->will($this->returnValue($isAssetPipelineEnabled)); |
205
|
|
|
|
206
|
|
|
if ($showAssetPipelineError) { |
207
|
|
|
$actual = $this->controller->index(); |
208
|
|
|
|
209
|
|
|
$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $actual); |
210
|
|
|
$this->assertEquals([], $actual->getParams()); |
211
|
|
|
$this->assertEquals('main-asset-pipeline-unsupported', $actual->getTemplateName()); |
212
|
|
|
} else { |
213
|
|
|
$this->config->expects($this->once()) |
214
|
|
|
->method('getAppValue') |
215
|
|
|
->with($this->appName, 'installed_version') |
216
|
|
|
->will($this->returnValue('42.13.37')); |
217
|
|
|
|
218
|
|
|
$actual = $this->controller->publicIndex(); |
219
|
|
|
|
220
|
|
|
$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $actual); |
221
|
|
|
$this->assertEquals([ |
222
|
|
|
'appVersion' => '42.13.37', |
223
|
|
|
'defaultView' => 'month', |
224
|
|
|
'emailAddress' => '', |
225
|
|
|
'supportsClass' => $expectsSupportsClass, |
226
|
|
|
'isPublic' => true, |
227
|
|
|
'shareURL' => '://', |
228
|
|
|
'previewImage' => null, |
229
|
|
|
], $actual->getParams()); |
230
|
|
|
$this->assertEquals('main', $actual->getTemplateName()); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
public function indexPublicDataProvider() { |
236
|
|
|
return [ |
237
|
|
|
[true, true, '9.0.5.2', false], |
238
|
|
|
[true, false, '9.1.0.0', true], |
239
|
|
|
[false, false, '9.0.5.2', false], |
240
|
|
|
[false, false, '9.1.0.0', true] |
241
|
|
|
]; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
public function testGetTimezone() { |
245
|
|
|
$actual = $this->controller->getTimezone('TIMEZONE1.ics'); |
246
|
|
|
|
247
|
|
|
$this->assertInstanceOf('OCP\AppFramework\Http\DataDisplayResponse', $actual); |
248
|
|
|
$this->assertEquals('TIMEZONE1-data', $actual->getData()); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
public function testGetTimezoneWithFakeTz() { |
252
|
|
|
$actual = $this->controller->getTimezone('TIMEZONE42.ics'); |
253
|
|
|
|
254
|
|
|
$this->assertInstanceOf('OCP\AppFramework\Http\NotFoundResponse', $actual); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
public function testGetTimezoneWithRegion() { |
258
|
|
|
$actual = $this->controller->getTimezoneWithRegion('REG', 'CIT.ics'); |
259
|
|
|
|
260
|
|
|
$this->assertInstanceOf('OCP\AppFramework\Http\DataDisplayResponse', $actual); |
261
|
|
|
$this->assertEquals('TIMEZONE DATA WITH REGION AND CITY', $actual->getData()); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
public function testGetTimezoneWithRegionWithFakeTz() { |
265
|
|
|
$actual = $this->controller->getTimezoneWithRegion('EUROPE', 'BERLIN.ics'); |
266
|
|
|
|
267
|
|
|
$this->assertInstanceOf('OCP\AppFramework\Http\NotFoundResponse', $actual); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @dataProvider indexEmailPublicLink |
272
|
|
|
*/ |
273
|
|
|
public function testEmailPublicLink($to, $url, $name) { |
274
|
|
|
|
275
|
|
|
$this->userSession->expects($this->exactly(1)) |
276
|
|
|
->method('getUser') |
277
|
|
|
->will($this->returnValue($this->dummyUser)); |
278
|
|
|
|
279
|
|
|
$actual = $this->controller->sendEmailPublicLink($to, $url, $name); |
280
|
|
|
|
281
|
|
|
$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual); |
282
|
|
|
|
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
public function indexEmailPublicLink() { |
286
|
|
|
return [ |
287
|
|
|
['[email protected]', 'myurl.tld', 'user123'], |
288
|
|
|
['testtesttld', 'myurl.tld', 'user123'], |
289
|
|
|
]; |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
|