@@ -19,491 +19,491 @@ |
||
19 | 19 | use Sabre\VObject\Component\VCalendar; |
20 | 20 | |
21 | 21 | class EmailProviderTest extends AbstractNotificationProviderTestCase { |
22 | - public const USER_EMAIL = '[email protected]'; |
|
23 | - private IMailer&MockObject $mailer; |
|
24 | - |
|
25 | - protected function setUp(): void { |
|
26 | - parent::setUp(); |
|
27 | - |
|
28 | - $this->mailer = $this->createMock(IMailer::class); |
|
29 | - |
|
30 | - $this->provider = new EmailProvider( |
|
31 | - $this->config, |
|
32 | - $this->mailer, |
|
33 | - $this->logger, |
|
34 | - $this->l10nFactory, |
|
35 | - $this->urlGenerator |
|
36 | - ); |
|
37 | - } |
|
38 | - |
|
39 | - public function testSendWithoutAttendees():void { |
|
40 | - [$user1, $user2, $user3, , $user5] = $users = $this->getUsers(); |
|
41 | - $principalEmailAddresses = [$user1->getEmailAddress()]; |
|
42 | - |
|
43 | - $enL10N = $this->createMock(IL10N::class); |
|
44 | - $enL10N->method('t') |
|
45 | - ->willReturnArgument(0); |
|
46 | - $enL10N->method('l') |
|
47 | - ->willReturnArgument(0); |
|
48 | - |
|
49 | - $deL10N = $this->createMock(IL10N::class); |
|
50 | - $deL10N->method('t') |
|
51 | - ->willReturnArgument(0); |
|
52 | - $deL10N->method('l') |
|
53 | - ->willReturnArgument(0); |
|
54 | - |
|
55 | - $this->l10nFactory |
|
56 | - ->method('getUserLanguage') |
|
57 | - ->willReturnMap([ |
|
58 | - [$user1, 'en'], |
|
59 | - [$user2, 'de'], |
|
60 | - [$user3, 'de'], |
|
61 | - [$user5, 'de'], |
|
62 | - ]); |
|
63 | - |
|
64 | - $this->l10nFactory |
|
65 | - ->method('findGenericLanguage') |
|
66 | - ->willReturn('en'); |
|
67 | - |
|
68 | - $this->l10nFactory |
|
69 | - ->method('languageExists') |
|
70 | - ->willReturnMap([ |
|
71 | - ['dav', 'en', true], |
|
72 | - ['dav', 'de', true], |
|
73 | - ]); |
|
74 | - |
|
75 | - $this->l10nFactory |
|
76 | - ->method('get') |
|
77 | - ->willReturnMap([ |
|
78 | - ['dav', 'en', null, $enL10N], |
|
79 | - ['dav', 'de', null, $deL10N], |
|
80 | - ]); |
|
81 | - |
|
82 | - $template1 = $this->getTemplateMock(); |
|
83 | - $message11 = $this->getMessageMock('[email protected]', $template1); |
|
84 | - $template2 = $this->getTemplateMock(); |
|
85 | - $message21 = $this->getMessageMock('[email protected]', $template2); |
|
86 | - $message22 = $this->getMessageMock('[email protected]', $template2); |
|
87 | - |
|
88 | - $this->mailer->expects($this->exactly(2)) |
|
89 | - ->method('createEMailTemplate') |
|
90 | - ->with('dav.calendarReminder') |
|
91 | - ->willReturnOnConsecutiveCalls( |
|
92 | - $template1, |
|
93 | - $template2 |
|
94 | - ); |
|
95 | - |
|
96 | - $this->mailer->expects($this->exactly(4)) |
|
97 | - ->method('validateMailAddress') |
|
98 | - ->willReturnMap([ |
|
99 | - ['[email protected]', true], |
|
100 | - ['[email protected]', true], |
|
101 | - ['[email protected]', true], |
|
102 | - ['invalid', false], |
|
103 | - ]); |
|
104 | - |
|
105 | - $this->mailer->expects($this->exactly(3)) |
|
106 | - ->method('createMessage') |
|
107 | - ->with() |
|
108 | - ->willReturnOnConsecutiveCalls( |
|
109 | - $message11, |
|
110 | - $message21, |
|
111 | - $message22 |
|
112 | - ); |
|
113 | - |
|
114 | - $calls = [ |
|
115 | - [$message11], |
|
116 | - [$message21], |
|
117 | - [$message22], |
|
118 | - ]; |
|
119 | - $this->mailer->expects($this->exactly(count($calls))) |
|
120 | - ->method('send') |
|
121 | - ->willReturnCallback(function () use (&$calls) { |
|
122 | - $expected = array_shift($calls); |
|
123 | - $this->assertEquals($expected, func_get_args()); |
|
124 | - return []; |
|
125 | - }); |
|
126 | - |
|
127 | - $this->setupURLGeneratorMock(2); |
|
128 | - |
|
129 | - $vcalendar = $this->getNoAttendeeVCalendar(); |
|
130 | - $this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $principalEmailAddresses, $users); |
|
131 | - } |
|
132 | - |
|
133 | - public function testSendWithAttendeesWhenOwnerIsOrganizer(): void { |
|
134 | - [$user1, $user2, $user3, , $user5] = $users = $this->getUsers(); |
|
135 | - $principalEmailAddresses = [$user1->getEmailAddress()]; |
|
136 | - |
|
137 | - $enL10N = $this->createMock(IL10N::class); |
|
138 | - $enL10N->method('t') |
|
139 | - ->willReturnArgument(0); |
|
140 | - $enL10N->method('l') |
|
141 | - ->willReturnArgument(0); |
|
142 | - |
|
143 | - $deL10N = $this->createMock(IL10N::class); |
|
144 | - $deL10N->method('t') |
|
145 | - ->willReturnArgument(0); |
|
146 | - $deL10N->method('l') |
|
147 | - ->willReturnArgument(0); |
|
148 | - |
|
149 | - $this->l10nFactory |
|
150 | - ->method('getUserLanguage') |
|
151 | - ->willReturnMap([ |
|
152 | - [$user1, 'en'], |
|
153 | - [$user2, 'de'], |
|
154 | - [$user3, 'de'], |
|
155 | - [$user5, 'de'], |
|
156 | - ]); |
|
157 | - |
|
158 | - $this->l10nFactory |
|
159 | - ->method('findGenericLanguage') |
|
160 | - ->willReturn('en'); |
|
161 | - |
|
162 | - $this->l10nFactory |
|
163 | - ->method('languageExists') |
|
164 | - ->willReturnMap([ |
|
165 | - ['dav', 'en', true], |
|
166 | - ['dav', 'de', true], |
|
167 | - ]); |
|
168 | - |
|
169 | - $this->l10nFactory |
|
170 | - ->method('get') |
|
171 | - ->willReturnMap([ |
|
172 | - ['dav', 'en', null, $enL10N], |
|
173 | - ['dav', 'de', null, $deL10N], |
|
174 | - ]); |
|
175 | - |
|
176 | - $template1 = $this->getTemplateMock(); |
|
177 | - $message11 = $this->getMessageMock('[email protected]', $template1); |
|
178 | - $message12 = $this->getMessageMock('[email protected]', $template1); |
|
179 | - $message13 = $this->getMessageMock('[email protected]', $template1); |
|
180 | - $template2 = $this->getTemplateMock(); |
|
181 | - $message21 = $this->getMessageMock('[email protected]', $template2); |
|
182 | - $message22 = $this->getMessageMock('[email protected]', $template2); |
|
183 | - $message23 = $this->getMessageMock('[email protected]', $template2); |
|
184 | - |
|
185 | - $this->mailer->expects(self::exactly(2)) |
|
186 | - ->method('createEMailTemplate') |
|
187 | - ->with('dav.calendarReminder') |
|
188 | - ->willReturnOnConsecutiveCalls( |
|
189 | - $template1, |
|
190 | - $template2, |
|
191 | - ); |
|
192 | - $this->mailer->expects($this->atLeastOnce()) |
|
193 | - ->method('validateMailAddress') |
|
194 | - ->willReturnMap([ |
|
195 | - ['[email protected]', true], |
|
196 | - ['[email protected]', true], |
|
197 | - ['[email protected]', true], |
|
198 | - ['[email protected]', true], |
|
199 | - ['[email protected]', true], |
|
200 | - ['[email protected]', true], |
|
201 | - ['invalid', false], |
|
202 | - ]); |
|
203 | - $this->mailer->expects($this->exactly(6)) |
|
204 | - ->method('createMessage') |
|
205 | - ->with() |
|
206 | - ->willReturnOnConsecutiveCalls( |
|
207 | - $message11, |
|
208 | - $message12, |
|
209 | - $message13, |
|
210 | - $message21, |
|
211 | - $message22, |
|
212 | - $message23, |
|
213 | - ); |
|
214 | - |
|
215 | - $calls = [ |
|
216 | - [$message11], |
|
217 | - [$message12], |
|
218 | - [$message13], |
|
219 | - [$message21], |
|
220 | - [$message22], |
|
221 | - [$message23], |
|
222 | - ]; |
|
223 | - $this->mailer->expects($this->exactly(count($calls))) |
|
224 | - ->method('send') |
|
225 | - ->willReturnCallback(function () use (&$calls) { |
|
226 | - $expected = array_shift($calls); |
|
227 | - $this->assertEquals($expected, func_get_args()); |
|
228 | - return []; |
|
229 | - }); |
|
230 | - $this->setupURLGeneratorMock(2); |
|
231 | - |
|
232 | - $vcalendar = $this->getAttendeeVCalendar(); |
|
233 | - $this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $principalEmailAddresses, $users); |
|
234 | - } |
|
235 | - |
|
236 | - public function testSendWithAttendeesWhenOwnerIsAttendee(): void { |
|
237 | - [$user1, $user2, $user3] = $this->getUsers(); |
|
238 | - $users = [$user2, $user3]; |
|
239 | - $principalEmailAddresses = [$user2->getEmailAddress()]; |
|
240 | - |
|
241 | - $deL10N = $this->createMock(IL10N::class); |
|
242 | - $deL10N->method('t') |
|
243 | - ->willReturnArgument(0); |
|
244 | - $deL10N->method('l') |
|
245 | - ->willReturnArgument(0); |
|
246 | - |
|
247 | - $this->l10nFactory |
|
248 | - ->method('getUserLanguage') |
|
249 | - ->willReturnMap([ |
|
250 | - [$user2, 'de'], |
|
251 | - [$user3, 'de'], |
|
252 | - ]); |
|
253 | - |
|
254 | - $this->l10nFactory |
|
255 | - ->method('findGenericLanguage') |
|
256 | - ->willReturn('en'); |
|
257 | - |
|
258 | - $this->l10nFactory |
|
259 | - ->method('languageExists') |
|
260 | - ->willReturnMap([ |
|
261 | - ['dav', 'de', true], |
|
262 | - ]); |
|
263 | - |
|
264 | - $this->l10nFactory |
|
265 | - ->method('get') |
|
266 | - ->willReturnMap([ |
|
267 | - ['dav', 'de', null, $deL10N], |
|
268 | - ]); |
|
269 | - |
|
270 | - $template1 = $this->getTemplateMock(); |
|
271 | - $message12 = $this->getMessageMock('[email protected]', $template1); |
|
272 | - $message13 = $this->getMessageMock('[email protected]', $template1); |
|
273 | - |
|
274 | - $this->mailer->expects(self::once()) |
|
275 | - ->method('createEMailTemplate') |
|
276 | - ->with('dav.calendarReminder') |
|
277 | - ->willReturnOnConsecutiveCalls( |
|
278 | - $template1, |
|
279 | - ); |
|
280 | - $this->mailer->expects($this->atLeastOnce()) |
|
281 | - ->method('validateMailAddress') |
|
282 | - ->willReturnMap([ |
|
283 | - ['[email protected]', true], |
|
284 | - ['[email protected]', true], |
|
285 | - ['[email protected]', true], |
|
286 | - ['[email protected]', true], |
|
287 | - ['[email protected]', true], |
|
288 | - ['[email protected]', true], |
|
289 | - ['invalid', false], |
|
290 | - ]); |
|
291 | - $this->mailer->expects($this->exactly(2)) |
|
292 | - ->method('createMessage') |
|
293 | - ->with() |
|
294 | - ->willReturnOnConsecutiveCalls( |
|
295 | - $message12, |
|
296 | - $message13, |
|
297 | - ); |
|
298 | - |
|
299 | - $calls = [ |
|
300 | - [$message12], |
|
301 | - [$message13], |
|
302 | - ]; |
|
303 | - $this->mailer->expects($this->exactly(count($calls))) |
|
304 | - ->method('send') |
|
305 | - ->willReturnCallback(function () use (&$calls) { |
|
306 | - $expected = array_shift($calls); |
|
307 | - $this->assertEquals($expected, func_get_args()); |
|
308 | - return []; |
|
309 | - }); |
|
310 | - $this->setupURLGeneratorMock(1); |
|
311 | - |
|
312 | - $vcalendar = $this->getAttendeeVCalendar(); |
|
313 | - $this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $principalEmailAddresses, $users); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * @return IEMailTemplate |
|
318 | - */ |
|
319 | - private function getTemplateMock():IEMailTemplate { |
|
320 | - $template = $this->createMock(IEMailTemplate::class); |
|
321 | - |
|
322 | - $template->expects($this->once()) |
|
323 | - ->method('addHeader') |
|
324 | - ->with() |
|
325 | - ->willReturn($template); |
|
326 | - |
|
327 | - $template->expects($this->once()) |
|
328 | - ->method('setSubject') |
|
329 | - ->with() |
|
330 | - ->willReturn($template); |
|
331 | - |
|
332 | - $template->expects($this->once()) |
|
333 | - ->method('addHeading') |
|
334 | - ->with() |
|
335 | - ->willReturn($template); |
|
336 | - |
|
337 | - $template->expects($this->exactly(4)) |
|
338 | - ->method('addBodyListItem') |
|
339 | - ->with() |
|
340 | - ->willReturn($template); |
|
341 | - |
|
342 | - $template->expects($this->once()) |
|
343 | - ->method('addFooter') |
|
344 | - ->with() |
|
345 | - ->willReturn($template); |
|
346 | - |
|
347 | - return $template; |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * @param string $toMail |
|
352 | - * @param IEMailTemplate $templateMock |
|
353 | - * @param array|null $replyTo |
|
354 | - * @return IMessage |
|
355 | - */ |
|
356 | - private function getMessageMock(string $toMail, IEMailTemplate $templateMock, ?array $replyTo = null):IMessage { |
|
357 | - $message = $this->createMock(IMessage::class); |
|
358 | - $i = 0; |
|
359 | - |
|
360 | - $message->expects($this->once()) |
|
361 | - ->method('setFrom') |
|
362 | - ->with([Util::getDefaultEmailAddress('reminders-noreply')]) |
|
363 | - ->willReturn($message); |
|
364 | - |
|
365 | - if ($replyTo) { |
|
366 | - $message->expects($this->once()) |
|
367 | - ->method('setReplyTo') |
|
368 | - ->with($replyTo) |
|
369 | - ->willReturn($message); |
|
370 | - } else { |
|
371 | - $message->expects($this->never()) |
|
372 | - ->method('setReplyTo'); |
|
373 | - } |
|
374 | - |
|
375 | - $message->expects($this->once()) |
|
376 | - ->method('setTo') |
|
377 | - ->with([$toMail]) |
|
378 | - ->willReturn($message); |
|
379 | - |
|
380 | - $message->expects($this->once()) |
|
381 | - ->method('useTemplate') |
|
382 | - ->with($templateMock) |
|
383 | - ->willReturn($message); |
|
384 | - |
|
385 | - return $message; |
|
386 | - } |
|
387 | - |
|
388 | - private function getNoAttendeeVCalendar():VCalendar { |
|
389 | - $vcalendar = new VCalendar(); |
|
390 | - $vcalendar->add('VEVENT', [ |
|
391 | - 'SUMMARY' => 'Fellowship meeting', |
|
392 | - 'DTSTART' => new \DateTime('2017-01-01 00:00:00+00:00'), // 1483228800, |
|
393 | - 'UID' => 'uid1234', |
|
394 | - 'LOCATION' => 'Location 123', |
|
395 | - 'DESCRIPTION' => 'DESCRIPTION 456', |
|
396 | - ]); |
|
397 | - |
|
398 | - return $vcalendar; |
|
399 | - } |
|
400 | - |
|
401 | - private function getAttendeeVCalendar():VCalendar { |
|
402 | - $vcalendar = new VCalendar(); |
|
403 | - $vcalendar->add('VEVENT', [ |
|
404 | - 'SUMMARY' => 'Fellowship meeting', |
|
405 | - 'DTSTART' => new \DateTime('2017-01-01 00:00:00+00:00'), // 1483228800, |
|
406 | - 'UID' => 'uid1234', |
|
407 | - 'LOCATION' => 'Location 123', |
|
408 | - 'DESCRIPTION' => 'DESCRIPTION 456', |
|
409 | - ]); |
|
410 | - |
|
411 | - $vcalendar->VEVENT->add( |
|
412 | - 'ORGANIZER', |
|
413 | - 'mailto:[email protected]', |
|
414 | - [ |
|
415 | - 'LANG' => 'en' |
|
416 | - ] |
|
417 | - ); |
|
418 | - |
|
419 | - $vcalendar->VEVENT->add( |
|
420 | - 'ATTENDEE', |
|
421 | - 'mailto:[email protected]', |
|
422 | - [ |
|
423 | - 'LANG' => 'de', |
|
424 | - 'PARTSTAT' => 'NEEDS-ACTION', |
|
425 | - ] |
|
426 | - ); |
|
427 | - |
|
428 | - $vcalendar->VEVENT->add( |
|
429 | - 'ATTENDEE', |
|
430 | - 'mailto:[email protected]', |
|
431 | - [ |
|
432 | - 'LANG' => 'de', |
|
433 | - 'PARTSTAT' => 'DECLINED', |
|
434 | - ] |
|
435 | - ); |
|
436 | - |
|
437 | - $vcalendar->VEVENT->add( |
|
438 | - 'ATTENDEE', |
|
439 | - 'mailto:[email protected]', |
|
440 | - [ |
|
441 | - 'LANG' => 'en', |
|
442 | - 'PARTSTAT' => 'CONFIRMED', |
|
443 | - ] |
|
444 | - ); |
|
445 | - |
|
446 | - $vcalendar->VEVENT->add( |
|
447 | - 'ATTENDEE', |
|
448 | - 'mailto:[email protected]' |
|
449 | - ); |
|
450 | - |
|
451 | - $vcalendar->VEVENT->add( |
|
452 | - 'ATTENDEE', |
|
453 | - 'tomail:[email protected]' |
|
454 | - ); |
|
455 | - |
|
456 | - return $vcalendar; |
|
457 | - } |
|
458 | - |
|
459 | - private function setupURLGeneratorMock(int $times = 1): void { |
|
460 | - $this->urlGenerator |
|
461 | - ->expects($this->exactly($times * 4)) |
|
462 | - ->method('imagePath') |
|
463 | - ->willReturnMap([ |
|
464 | - ['core', 'actions/info.png', 'imagePath1'], |
|
465 | - ['core', 'places/calendar.png', 'imagePath2'], |
|
466 | - ['core', 'actions/address.png', 'imagePath3'], |
|
467 | - ['core', 'actions/more.png', 'imagePath4'], |
|
468 | - ]); |
|
469 | - $this->urlGenerator |
|
470 | - ->expects($this->exactly($times * 4)) |
|
471 | - ->method('getAbsoluteURL') |
|
472 | - ->willReturnMap([ |
|
473 | - ['imagePath1', 'AbsURL1'], |
|
474 | - ['imagePath2', 'AbsURL2'], |
|
475 | - ['imagePath3', 'AbsURL3'], |
|
476 | - ['imagePath4', 'AbsURL4'], |
|
477 | - ]); |
|
478 | - } |
|
479 | - |
|
480 | - private function getUsers(): array { |
|
481 | - $user1 = $this->createMock(IUser::class); |
|
482 | - $user1->method('getUID') |
|
483 | - ->willReturn('uid1'); |
|
484 | - $user1->method('getEMailAddress') |
|
485 | - ->willReturn('[email protected]'); |
|
486 | - $user2 = $this->createMock(IUser::class); |
|
487 | - $user2->method('getUID') |
|
488 | - ->willReturn('uid2'); |
|
489 | - $user2->method('getEMailAddress') |
|
490 | - ->willReturn('[email protected]'); |
|
491 | - $user3 = $this->createMock(IUser::class); |
|
492 | - $user3->method('getUID') |
|
493 | - ->willReturn('uid3'); |
|
494 | - $user3->method('getEMailAddress') |
|
495 | - ->willReturn('[email protected]'); |
|
496 | - $user4 = $this->createMock(IUser::class); |
|
497 | - $user4->method('getUID') |
|
498 | - ->willReturn('uid4'); |
|
499 | - $user4->method('getEMailAddress') |
|
500 | - ->willReturn(null); |
|
501 | - $user5 = $this->createMock(IUser::class); |
|
502 | - $user5->method('getUID') |
|
503 | - ->willReturn('uid5'); |
|
504 | - $user5->method('getEMailAddress') |
|
505 | - ->willReturn('invalid'); |
|
506 | - |
|
507 | - return [$user1, $user2, $user3, $user4, $user5]; |
|
508 | - } |
|
22 | + public const USER_EMAIL = '[email protected]'; |
|
23 | + private IMailer&MockObject $mailer; |
|
24 | + |
|
25 | + protected function setUp(): void { |
|
26 | + parent::setUp(); |
|
27 | + |
|
28 | + $this->mailer = $this->createMock(IMailer::class); |
|
29 | + |
|
30 | + $this->provider = new EmailProvider( |
|
31 | + $this->config, |
|
32 | + $this->mailer, |
|
33 | + $this->logger, |
|
34 | + $this->l10nFactory, |
|
35 | + $this->urlGenerator |
|
36 | + ); |
|
37 | + } |
|
38 | + |
|
39 | + public function testSendWithoutAttendees():void { |
|
40 | + [$user1, $user2, $user3, , $user5] = $users = $this->getUsers(); |
|
41 | + $principalEmailAddresses = [$user1->getEmailAddress()]; |
|
42 | + |
|
43 | + $enL10N = $this->createMock(IL10N::class); |
|
44 | + $enL10N->method('t') |
|
45 | + ->willReturnArgument(0); |
|
46 | + $enL10N->method('l') |
|
47 | + ->willReturnArgument(0); |
|
48 | + |
|
49 | + $deL10N = $this->createMock(IL10N::class); |
|
50 | + $deL10N->method('t') |
|
51 | + ->willReturnArgument(0); |
|
52 | + $deL10N->method('l') |
|
53 | + ->willReturnArgument(0); |
|
54 | + |
|
55 | + $this->l10nFactory |
|
56 | + ->method('getUserLanguage') |
|
57 | + ->willReturnMap([ |
|
58 | + [$user1, 'en'], |
|
59 | + [$user2, 'de'], |
|
60 | + [$user3, 'de'], |
|
61 | + [$user5, 'de'], |
|
62 | + ]); |
|
63 | + |
|
64 | + $this->l10nFactory |
|
65 | + ->method('findGenericLanguage') |
|
66 | + ->willReturn('en'); |
|
67 | + |
|
68 | + $this->l10nFactory |
|
69 | + ->method('languageExists') |
|
70 | + ->willReturnMap([ |
|
71 | + ['dav', 'en', true], |
|
72 | + ['dav', 'de', true], |
|
73 | + ]); |
|
74 | + |
|
75 | + $this->l10nFactory |
|
76 | + ->method('get') |
|
77 | + ->willReturnMap([ |
|
78 | + ['dav', 'en', null, $enL10N], |
|
79 | + ['dav', 'de', null, $deL10N], |
|
80 | + ]); |
|
81 | + |
|
82 | + $template1 = $this->getTemplateMock(); |
|
83 | + $message11 = $this->getMessageMock('[email protected]', $template1); |
|
84 | + $template2 = $this->getTemplateMock(); |
|
85 | + $message21 = $this->getMessageMock('[email protected]', $template2); |
|
86 | + $message22 = $this->getMessageMock('[email protected]', $template2); |
|
87 | + |
|
88 | + $this->mailer->expects($this->exactly(2)) |
|
89 | + ->method('createEMailTemplate') |
|
90 | + ->with('dav.calendarReminder') |
|
91 | + ->willReturnOnConsecutiveCalls( |
|
92 | + $template1, |
|
93 | + $template2 |
|
94 | + ); |
|
95 | + |
|
96 | + $this->mailer->expects($this->exactly(4)) |
|
97 | + ->method('validateMailAddress') |
|
98 | + ->willReturnMap([ |
|
99 | + ['[email protected]', true], |
|
100 | + ['[email protected]', true], |
|
101 | + ['[email protected]', true], |
|
102 | + ['invalid', false], |
|
103 | + ]); |
|
104 | + |
|
105 | + $this->mailer->expects($this->exactly(3)) |
|
106 | + ->method('createMessage') |
|
107 | + ->with() |
|
108 | + ->willReturnOnConsecutiveCalls( |
|
109 | + $message11, |
|
110 | + $message21, |
|
111 | + $message22 |
|
112 | + ); |
|
113 | + |
|
114 | + $calls = [ |
|
115 | + [$message11], |
|
116 | + [$message21], |
|
117 | + [$message22], |
|
118 | + ]; |
|
119 | + $this->mailer->expects($this->exactly(count($calls))) |
|
120 | + ->method('send') |
|
121 | + ->willReturnCallback(function () use (&$calls) { |
|
122 | + $expected = array_shift($calls); |
|
123 | + $this->assertEquals($expected, func_get_args()); |
|
124 | + return []; |
|
125 | + }); |
|
126 | + |
|
127 | + $this->setupURLGeneratorMock(2); |
|
128 | + |
|
129 | + $vcalendar = $this->getNoAttendeeVCalendar(); |
|
130 | + $this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $principalEmailAddresses, $users); |
|
131 | + } |
|
132 | + |
|
133 | + public function testSendWithAttendeesWhenOwnerIsOrganizer(): void { |
|
134 | + [$user1, $user2, $user3, , $user5] = $users = $this->getUsers(); |
|
135 | + $principalEmailAddresses = [$user1->getEmailAddress()]; |
|
136 | + |
|
137 | + $enL10N = $this->createMock(IL10N::class); |
|
138 | + $enL10N->method('t') |
|
139 | + ->willReturnArgument(0); |
|
140 | + $enL10N->method('l') |
|
141 | + ->willReturnArgument(0); |
|
142 | + |
|
143 | + $deL10N = $this->createMock(IL10N::class); |
|
144 | + $deL10N->method('t') |
|
145 | + ->willReturnArgument(0); |
|
146 | + $deL10N->method('l') |
|
147 | + ->willReturnArgument(0); |
|
148 | + |
|
149 | + $this->l10nFactory |
|
150 | + ->method('getUserLanguage') |
|
151 | + ->willReturnMap([ |
|
152 | + [$user1, 'en'], |
|
153 | + [$user2, 'de'], |
|
154 | + [$user3, 'de'], |
|
155 | + [$user5, 'de'], |
|
156 | + ]); |
|
157 | + |
|
158 | + $this->l10nFactory |
|
159 | + ->method('findGenericLanguage') |
|
160 | + ->willReturn('en'); |
|
161 | + |
|
162 | + $this->l10nFactory |
|
163 | + ->method('languageExists') |
|
164 | + ->willReturnMap([ |
|
165 | + ['dav', 'en', true], |
|
166 | + ['dav', 'de', true], |
|
167 | + ]); |
|
168 | + |
|
169 | + $this->l10nFactory |
|
170 | + ->method('get') |
|
171 | + ->willReturnMap([ |
|
172 | + ['dav', 'en', null, $enL10N], |
|
173 | + ['dav', 'de', null, $deL10N], |
|
174 | + ]); |
|
175 | + |
|
176 | + $template1 = $this->getTemplateMock(); |
|
177 | + $message11 = $this->getMessageMock('[email protected]', $template1); |
|
178 | + $message12 = $this->getMessageMock('[email protected]', $template1); |
|
179 | + $message13 = $this->getMessageMock('[email protected]', $template1); |
|
180 | + $template2 = $this->getTemplateMock(); |
|
181 | + $message21 = $this->getMessageMock('[email protected]', $template2); |
|
182 | + $message22 = $this->getMessageMock('[email protected]', $template2); |
|
183 | + $message23 = $this->getMessageMock('[email protected]', $template2); |
|
184 | + |
|
185 | + $this->mailer->expects(self::exactly(2)) |
|
186 | + ->method('createEMailTemplate') |
|
187 | + ->with('dav.calendarReminder') |
|
188 | + ->willReturnOnConsecutiveCalls( |
|
189 | + $template1, |
|
190 | + $template2, |
|
191 | + ); |
|
192 | + $this->mailer->expects($this->atLeastOnce()) |
|
193 | + ->method('validateMailAddress') |
|
194 | + ->willReturnMap([ |
|
195 | + ['[email protected]', true], |
|
196 | + ['[email protected]', true], |
|
197 | + ['[email protected]', true], |
|
198 | + ['[email protected]', true], |
|
199 | + ['[email protected]', true], |
|
200 | + ['[email protected]', true], |
|
201 | + ['invalid', false], |
|
202 | + ]); |
|
203 | + $this->mailer->expects($this->exactly(6)) |
|
204 | + ->method('createMessage') |
|
205 | + ->with() |
|
206 | + ->willReturnOnConsecutiveCalls( |
|
207 | + $message11, |
|
208 | + $message12, |
|
209 | + $message13, |
|
210 | + $message21, |
|
211 | + $message22, |
|
212 | + $message23, |
|
213 | + ); |
|
214 | + |
|
215 | + $calls = [ |
|
216 | + [$message11], |
|
217 | + [$message12], |
|
218 | + [$message13], |
|
219 | + [$message21], |
|
220 | + [$message22], |
|
221 | + [$message23], |
|
222 | + ]; |
|
223 | + $this->mailer->expects($this->exactly(count($calls))) |
|
224 | + ->method('send') |
|
225 | + ->willReturnCallback(function () use (&$calls) { |
|
226 | + $expected = array_shift($calls); |
|
227 | + $this->assertEquals($expected, func_get_args()); |
|
228 | + return []; |
|
229 | + }); |
|
230 | + $this->setupURLGeneratorMock(2); |
|
231 | + |
|
232 | + $vcalendar = $this->getAttendeeVCalendar(); |
|
233 | + $this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $principalEmailAddresses, $users); |
|
234 | + } |
|
235 | + |
|
236 | + public function testSendWithAttendeesWhenOwnerIsAttendee(): void { |
|
237 | + [$user1, $user2, $user3] = $this->getUsers(); |
|
238 | + $users = [$user2, $user3]; |
|
239 | + $principalEmailAddresses = [$user2->getEmailAddress()]; |
|
240 | + |
|
241 | + $deL10N = $this->createMock(IL10N::class); |
|
242 | + $deL10N->method('t') |
|
243 | + ->willReturnArgument(0); |
|
244 | + $deL10N->method('l') |
|
245 | + ->willReturnArgument(0); |
|
246 | + |
|
247 | + $this->l10nFactory |
|
248 | + ->method('getUserLanguage') |
|
249 | + ->willReturnMap([ |
|
250 | + [$user2, 'de'], |
|
251 | + [$user3, 'de'], |
|
252 | + ]); |
|
253 | + |
|
254 | + $this->l10nFactory |
|
255 | + ->method('findGenericLanguage') |
|
256 | + ->willReturn('en'); |
|
257 | + |
|
258 | + $this->l10nFactory |
|
259 | + ->method('languageExists') |
|
260 | + ->willReturnMap([ |
|
261 | + ['dav', 'de', true], |
|
262 | + ]); |
|
263 | + |
|
264 | + $this->l10nFactory |
|
265 | + ->method('get') |
|
266 | + ->willReturnMap([ |
|
267 | + ['dav', 'de', null, $deL10N], |
|
268 | + ]); |
|
269 | + |
|
270 | + $template1 = $this->getTemplateMock(); |
|
271 | + $message12 = $this->getMessageMock('[email protected]', $template1); |
|
272 | + $message13 = $this->getMessageMock('[email protected]', $template1); |
|
273 | + |
|
274 | + $this->mailer->expects(self::once()) |
|
275 | + ->method('createEMailTemplate') |
|
276 | + ->with('dav.calendarReminder') |
|
277 | + ->willReturnOnConsecutiveCalls( |
|
278 | + $template1, |
|
279 | + ); |
|
280 | + $this->mailer->expects($this->atLeastOnce()) |
|
281 | + ->method('validateMailAddress') |
|
282 | + ->willReturnMap([ |
|
283 | + ['[email protected]', true], |
|
284 | + ['[email protected]', true], |
|
285 | + ['[email protected]', true], |
|
286 | + ['[email protected]', true], |
|
287 | + ['[email protected]', true], |
|
288 | + ['[email protected]', true], |
|
289 | + ['invalid', false], |
|
290 | + ]); |
|
291 | + $this->mailer->expects($this->exactly(2)) |
|
292 | + ->method('createMessage') |
|
293 | + ->with() |
|
294 | + ->willReturnOnConsecutiveCalls( |
|
295 | + $message12, |
|
296 | + $message13, |
|
297 | + ); |
|
298 | + |
|
299 | + $calls = [ |
|
300 | + [$message12], |
|
301 | + [$message13], |
|
302 | + ]; |
|
303 | + $this->mailer->expects($this->exactly(count($calls))) |
|
304 | + ->method('send') |
|
305 | + ->willReturnCallback(function () use (&$calls) { |
|
306 | + $expected = array_shift($calls); |
|
307 | + $this->assertEquals($expected, func_get_args()); |
|
308 | + return []; |
|
309 | + }); |
|
310 | + $this->setupURLGeneratorMock(1); |
|
311 | + |
|
312 | + $vcalendar = $this->getAttendeeVCalendar(); |
|
313 | + $this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $principalEmailAddresses, $users); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * @return IEMailTemplate |
|
318 | + */ |
|
319 | + private function getTemplateMock():IEMailTemplate { |
|
320 | + $template = $this->createMock(IEMailTemplate::class); |
|
321 | + |
|
322 | + $template->expects($this->once()) |
|
323 | + ->method('addHeader') |
|
324 | + ->with() |
|
325 | + ->willReturn($template); |
|
326 | + |
|
327 | + $template->expects($this->once()) |
|
328 | + ->method('setSubject') |
|
329 | + ->with() |
|
330 | + ->willReturn($template); |
|
331 | + |
|
332 | + $template->expects($this->once()) |
|
333 | + ->method('addHeading') |
|
334 | + ->with() |
|
335 | + ->willReturn($template); |
|
336 | + |
|
337 | + $template->expects($this->exactly(4)) |
|
338 | + ->method('addBodyListItem') |
|
339 | + ->with() |
|
340 | + ->willReturn($template); |
|
341 | + |
|
342 | + $template->expects($this->once()) |
|
343 | + ->method('addFooter') |
|
344 | + ->with() |
|
345 | + ->willReturn($template); |
|
346 | + |
|
347 | + return $template; |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * @param string $toMail |
|
352 | + * @param IEMailTemplate $templateMock |
|
353 | + * @param array|null $replyTo |
|
354 | + * @return IMessage |
|
355 | + */ |
|
356 | + private function getMessageMock(string $toMail, IEMailTemplate $templateMock, ?array $replyTo = null):IMessage { |
|
357 | + $message = $this->createMock(IMessage::class); |
|
358 | + $i = 0; |
|
359 | + |
|
360 | + $message->expects($this->once()) |
|
361 | + ->method('setFrom') |
|
362 | + ->with([Util::getDefaultEmailAddress('reminders-noreply')]) |
|
363 | + ->willReturn($message); |
|
364 | + |
|
365 | + if ($replyTo) { |
|
366 | + $message->expects($this->once()) |
|
367 | + ->method('setReplyTo') |
|
368 | + ->with($replyTo) |
|
369 | + ->willReturn($message); |
|
370 | + } else { |
|
371 | + $message->expects($this->never()) |
|
372 | + ->method('setReplyTo'); |
|
373 | + } |
|
374 | + |
|
375 | + $message->expects($this->once()) |
|
376 | + ->method('setTo') |
|
377 | + ->with([$toMail]) |
|
378 | + ->willReturn($message); |
|
379 | + |
|
380 | + $message->expects($this->once()) |
|
381 | + ->method('useTemplate') |
|
382 | + ->with($templateMock) |
|
383 | + ->willReturn($message); |
|
384 | + |
|
385 | + return $message; |
|
386 | + } |
|
387 | + |
|
388 | + private function getNoAttendeeVCalendar():VCalendar { |
|
389 | + $vcalendar = new VCalendar(); |
|
390 | + $vcalendar->add('VEVENT', [ |
|
391 | + 'SUMMARY' => 'Fellowship meeting', |
|
392 | + 'DTSTART' => new \DateTime('2017-01-01 00:00:00+00:00'), // 1483228800, |
|
393 | + 'UID' => 'uid1234', |
|
394 | + 'LOCATION' => 'Location 123', |
|
395 | + 'DESCRIPTION' => 'DESCRIPTION 456', |
|
396 | + ]); |
|
397 | + |
|
398 | + return $vcalendar; |
|
399 | + } |
|
400 | + |
|
401 | + private function getAttendeeVCalendar():VCalendar { |
|
402 | + $vcalendar = new VCalendar(); |
|
403 | + $vcalendar->add('VEVENT', [ |
|
404 | + 'SUMMARY' => 'Fellowship meeting', |
|
405 | + 'DTSTART' => new \DateTime('2017-01-01 00:00:00+00:00'), // 1483228800, |
|
406 | + 'UID' => 'uid1234', |
|
407 | + 'LOCATION' => 'Location 123', |
|
408 | + 'DESCRIPTION' => 'DESCRIPTION 456', |
|
409 | + ]); |
|
410 | + |
|
411 | + $vcalendar->VEVENT->add( |
|
412 | + 'ORGANIZER', |
|
413 | + 'mailto:[email protected]', |
|
414 | + [ |
|
415 | + 'LANG' => 'en' |
|
416 | + ] |
|
417 | + ); |
|
418 | + |
|
419 | + $vcalendar->VEVENT->add( |
|
420 | + 'ATTENDEE', |
|
421 | + 'mailto:[email protected]', |
|
422 | + [ |
|
423 | + 'LANG' => 'de', |
|
424 | + 'PARTSTAT' => 'NEEDS-ACTION', |
|
425 | + ] |
|
426 | + ); |
|
427 | + |
|
428 | + $vcalendar->VEVENT->add( |
|
429 | + 'ATTENDEE', |
|
430 | + 'mailto:[email protected]', |
|
431 | + [ |
|
432 | + 'LANG' => 'de', |
|
433 | + 'PARTSTAT' => 'DECLINED', |
|
434 | + ] |
|
435 | + ); |
|
436 | + |
|
437 | + $vcalendar->VEVENT->add( |
|
438 | + 'ATTENDEE', |
|
439 | + 'mailto:[email protected]', |
|
440 | + [ |
|
441 | + 'LANG' => 'en', |
|
442 | + 'PARTSTAT' => 'CONFIRMED', |
|
443 | + ] |
|
444 | + ); |
|
445 | + |
|
446 | + $vcalendar->VEVENT->add( |
|
447 | + 'ATTENDEE', |
|
448 | + 'mailto:[email protected]' |
|
449 | + ); |
|
450 | + |
|
451 | + $vcalendar->VEVENT->add( |
|
452 | + 'ATTENDEE', |
|
453 | + 'tomail:[email protected]' |
|
454 | + ); |
|
455 | + |
|
456 | + return $vcalendar; |
|
457 | + } |
|
458 | + |
|
459 | + private function setupURLGeneratorMock(int $times = 1): void { |
|
460 | + $this->urlGenerator |
|
461 | + ->expects($this->exactly($times * 4)) |
|
462 | + ->method('imagePath') |
|
463 | + ->willReturnMap([ |
|
464 | + ['core', 'actions/info.png', 'imagePath1'], |
|
465 | + ['core', 'places/calendar.png', 'imagePath2'], |
|
466 | + ['core', 'actions/address.png', 'imagePath3'], |
|
467 | + ['core', 'actions/more.png', 'imagePath4'], |
|
468 | + ]); |
|
469 | + $this->urlGenerator |
|
470 | + ->expects($this->exactly($times * 4)) |
|
471 | + ->method('getAbsoluteURL') |
|
472 | + ->willReturnMap([ |
|
473 | + ['imagePath1', 'AbsURL1'], |
|
474 | + ['imagePath2', 'AbsURL2'], |
|
475 | + ['imagePath3', 'AbsURL3'], |
|
476 | + ['imagePath4', 'AbsURL4'], |
|
477 | + ]); |
|
478 | + } |
|
479 | + |
|
480 | + private function getUsers(): array { |
|
481 | + $user1 = $this->createMock(IUser::class); |
|
482 | + $user1->method('getUID') |
|
483 | + ->willReturn('uid1'); |
|
484 | + $user1->method('getEMailAddress') |
|
485 | + ->willReturn('[email protected]'); |
|
486 | + $user2 = $this->createMock(IUser::class); |
|
487 | + $user2->method('getUID') |
|
488 | + ->willReturn('uid2'); |
|
489 | + $user2->method('getEMailAddress') |
|
490 | + ->willReturn('[email protected]'); |
|
491 | + $user3 = $this->createMock(IUser::class); |
|
492 | + $user3->method('getUID') |
|
493 | + ->willReturn('uid3'); |
|
494 | + $user3->method('getEMailAddress') |
|
495 | + ->willReturn('[email protected]'); |
|
496 | + $user4 = $this->createMock(IUser::class); |
|
497 | + $user4->method('getUID') |
|
498 | + ->willReturn('uid4'); |
|
499 | + $user4->method('getEMailAddress') |
|
500 | + ->willReturn(null); |
|
501 | + $user5 = $this->createMock(IUser::class); |
|
502 | + $user5->method('getUID') |
|
503 | + ->willReturn('uid5'); |
|
504 | + $user5->method('getEMailAddress') |
|
505 | + ->willReturn('invalid'); |
|
506 | + |
|
507 | + return [$user1, $user2, $user3, $user4, $user5]; |
|
508 | + } |
|
509 | 509 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | } |
38 | 38 | |
39 | 39 | public function testSendWithoutAttendees():void { |
40 | - [$user1, $user2, $user3, , $user5] = $users = $this->getUsers(); |
|
40 | + [$user1, $user2, $user3,, $user5] = $users = $this->getUsers(); |
|
41 | 41 | $principalEmailAddresses = [$user1->getEmailAddress()]; |
42 | 42 | |
43 | 43 | $enL10N = $this->createMock(IL10N::class); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | ]; |
119 | 119 | $this->mailer->expects($this->exactly(count($calls))) |
120 | 120 | ->method('send') |
121 | - ->willReturnCallback(function () use (&$calls) { |
|
121 | + ->willReturnCallback(function() use (&$calls) { |
|
122 | 122 | $expected = array_shift($calls); |
123 | 123 | $this->assertEquals($expected, func_get_args()); |
124 | 124 | return []; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | public function testSendWithAttendeesWhenOwnerIsOrganizer(): void { |
134 | - [$user1, $user2, $user3, , $user5] = $users = $this->getUsers(); |
|
134 | + [$user1, $user2, $user3,, $user5] = $users = $this->getUsers(); |
|
135 | 135 | $principalEmailAddresses = [$user1->getEmailAddress()]; |
136 | 136 | |
137 | 137 | $enL10N = $this->createMock(IL10N::class); |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | ]; |
223 | 223 | $this->mailer->expects($this->exactly(count($calls))) |
224 | 224 | ->method('send') |
225 | - ->willReturnCallback(function () use (&$calls) { |
|
225 | + ->willReturnCallback(function() use (&$calls) { |
|
226 | 226 | $expected = array_shift($calls); |
227 | 227 | $this->assertEquals($expected, func_get_args()); |
228 | 228 | return []; |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | ]; |
303 | 303 | $this->mailer->expects($this->exactly(count($calls))) |
304 | 304 | ->method('send') |
305 | - ->willReturnCallback(function () use (&$calls) { |
|
305 | + ->willReturnCallback(function() use (&$calls) { |
|
306 | 306 | $expected = array_shift($calls); |
307 | 307 | $this->assertEquals($expected, func_get_args()); |
308 | 308 | return []; |
@@ -21,63 +21,63 @@ |
||
21 | 21 | * @group DB |
22 | 22 | */ |
23 | 23 | class NotificationProviderManagerTest extends TestCase { |
24 | - private NotificationProviderManager $providerManager; |
|
24 | + private NotificationProviderManager $providerManager; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @throws QueryException |
|
28 | - */ |
|
29 | - protected function setUp(): void { |
|
30 | - parent::setUp(); |
|
26 | + /** |
|
27 | + * @throws QueryException |
|
28 | + */ |
|
29 | + protected function setUp(): void { |
|
30 | + parent::setUp(); |
|
31 | 31 | |
32 | - $this->providerManager = new NotificationProviderManager(); |
|
33 | - $this->providerManager->registerProvider(EmailProvider::class); |
|
34 | - } |
|
32 | + $this->providerManager = new NotificationProviderManager(); |
|
33 | + $this->providerManager->registerProvider(EmailProvider::class); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @throws ProviderNotAvailableException |
|
38 | - * @throws NotificationTypeDoesNotExistException |
|
39 | - */ |
|
40 | - public function testGetProviderForUnknownType(): void { |
|
41 | - $this->expectException(NotificationTypeDoesNotExistException::class); |
|
42 | - $this->expectExceptionMessage('Type NOT EXISTENT is not an accepted type of notification'); |
|
36 | + /** |
|
37 | + * @throws ProviderNotAvailableException |
|
38 | + * @throws NotificationTypeDoesNotExistException |
|
39 | + */ |
|
40 | + public function testGetProviderForUnknownType(): void { |
|
41 | + $this->expectException(NotificationTypeDoesNotExistException::class); |
|
42 | + $this->expectExceptionMessage('Type NOT EXISTENT is not an accepted type of notification'); |
|
43 | 43 | |
44 | - $this->providerManager->getProvider('NOT EXISTENT'); |
|
45 | - } |
|
44 | + $this->providerManager->getProvider('NOT EXISTENT'); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @throws NotificationTypeDoesNotExistException |
|
49 | - * @throws ProviderNotAvailableException |
|
50 | - */ |
|
51 | - public function testGetProviderForUnRegisteredType(): void { |
|
52 | - $this->expectException(ProviderNotAvailableException::class); |
|
53 | - $this->expectExceptionMessage('No notification provider for type AUDIO available'); |
|
47 | + /** |
|
48 | + * @throws NotificationTypeDoesNotExistException |
|
49 | + * @throws ProviderNotAvailableException |
|
50 | + */ |
|
51 | + public function testGetProviderForUnRegisteredType(): void { |
|
52 | + $this->expectException(ProviderNotAvailableException::class); |
|
53 | + $this->expectExceptionMessage('No notification provider for type AUDIO available'); |
|
54 | 54 | |
55 | - $this->providerManager->getProvider('AUDIO'); |
|
56 | - } |
|
55 | + $this->providerManager->getProvider('AUDIO'); |
|
56 | + } |
|
57 | 57 | |
58 | - public function testGetProvider(): void { |
|
59 | - $provider = $this->providerManager->getProvider('EMAIL'); |
|
60 | - $this->assertInstanceOf(EmailProvider::class, $provider); |
|
61 | - } |
|
58 | + public function testGetProvider(): void { |
|
59 | + $provider = $this->providerManager->getProvider('EMAIL'); |
|
60 | + $this->assertInstanceOf(EmailProvider::class, $provider); |
|
61 | + } |
|
62 | 62 | |
63 | - public function testRegisterProvider(): void { |
|
64 | - $this->providerManager->registerProvider(PushProvider::class); |
|
65 | - $provider = $this->providerManager->getProvider('DISPLAY'); |
|
66 | - $this->assertInstanceOf(PushProvider::class, $provider); |
|
67 | - } |
|
63 | + public function testRegisterProvider(): void { |
|
64 | + $this->providerManager->registerProvider(PushProvider::class); |
|
65 | + $provider = $this->providerManager->getProvider('DISPLAY'); |
|
66 | + $this->assertInstanceOf(PushProvider::class, $provider); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @throws QueryException |
|
71 | - */ |
|
72 | - public function testRegisterBadProvider(): void { |
|
73 | - $this->expectException(\InvalidArgumentException::class); |
|
74 | - $this->expectExceptionMessage('Invalid notification provider registered'); |
|
69 | + /** |
|
70 | + * @throws QueryException |
|
71 | + */ |
|
72 | + public function testRegisterBadProvider(): void { |
|
73 | + $this->expectException(\InvalidArgumentException::class); |
|
74 | + $this->expectExceptionMessage('Invalid notification provider registered'); |
|
75 | 75 | |
76 | - $this->providerManager->registerProvider(Capabilities::class); |
|
77 | - } |
|
76 | + $this->providerManager->registerProvider(Capabilities::class); |
|
77 | + } |
|
78 | 78 | |
79 | - public function testHasProvider(): void { |
|
80 | - $this->assertTrue($this->providerManager->hasProvider('EMAIL')); |
|
81 | - $this->assertFalse($this->providerManager->hasProvider('EMAIL123')); |
|
82 | - } |
|
79 | + public function testHasProvider(): void { |
|
80 | + $this->assertTrue($this->providerManager->hasProvider('EMAIL')); |
|
81 | + $this->assertFalse($this->providerManager->hasProvider('EMAIL123')); |
|
82 | + } |
|
83 | 83 | } |
@@ -29,95 +29,95 @@ discard block |
||
29 | 29 | * @group DB |
30 | 30 | */ |
31 | 31 | class UserStatusAutomationTest extends TestCase { |
32 | - protected ITimeFactory&MockObject $time; |
|
33 | - protected IJobList&MockObject $jobList; |
|
34 | - protected LoggerInterface&MockObject $logger; |
|
35 | - protected IManager&MockObject $statusManager; |
|
36 | - protected IConfig&MockObject $config; |
|
37 | - private IAvailabilityCoordinator&MockObject $coordinator; |
|
38 | - private IUserManager&MockObject $userManager; |
|
39 | - |
|
40 | - protected function setUp(): void { |
|
41 | - parent::setUp(); |
|
42 | - |
|
43 | - $this->time = $this->createMock(ITimeFactory::class); |
|
44 | - $this->jobList = $this->createMock(IJobList::class); |
|
45 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
46 | - $this->statusManager = $this->createMock(IManager::class); |
|
47 | - $this->config = $this->createMock(IConfig::class); |
|
48 | - $this->coordinator = $this->createMock(IAvailabilityCoordinator::class); |
|
49 | - $this->userManager = $this->createMock(IUserManager::class); |
|
50 | - |
|
51 | - } |
|
52 | - |
|
53 | - protected function getAutomationMock(array $methods): MockObject|UserStatusAutomation { |
|
54 | - if (empty($methods)) { |
|
55 | - return new UserStatusAutomation( |
|
56 | - $this->time, |
|
57 | - Server::get(IDBConnection::class), |
|
58 | - $this->jobList, |
|
59 | - $this->logger, |
|
60 | - $this->statusManager, |
|
61 | - $this->config, |
|
62 | - $this->coordinator, |
|
63 | - $this->userManager, |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - return $this->getMockBuilder(UserStatusAutomation::class) |
|
68 | - ->setConstructorArgs([ |
|
69 | - $this->time, |
|
70 | - Server::get(IDBConnection::class), |
|
71 | - $this->jobList, |
|
72 | - $this->logger, |
|
73 | - $this->statusManager, |
|
74 | - $this->config, |
|
75 | - $this->coordinator, |
|
76 | - $this->userManager, |
|
77 | - ]) |
|
78 | - ->onlyMethods($methods) |
|
79 | - ->getMock(); |
|
80 | - } |
|
81 | - |
|
82 | - public static function dataRun(): array { |
|
83 | - return [ |
|
84 | - ['20230217', '2023-02-24 10:49:36.613834', true], |
|
85 | - ['20230224', '2023-02-24 10:49:36.613834', true], |
|
86 | - ['20230217', '2023-02-24 13:58:24.479357', false], |
|
87 | - ['20230224', '2023-02-24 13:58:24.479357', false], |
|
88 | - ]; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @dataProvider dataRun |
|
93 | - */ |
|
94 | - public function testRunNoOOO(string $ruleDay, string $currentTime, bool $isAvailable): void { |
|
95 | - $user = $this->createConfiguredMock(IUser::class, [ |
|
96 | - 'getUID' => 'user' |
|
97 | - ]); |
|
98 | - |
|
99 | - $this->userManager->expects(self::once()) |
|
100 | - ->method('get') |
|
101 | - ->willReturn($user); |
|
102 | - $this->coordinator->expects(self::once()) |
|
103 | - ->method('getCurrentOutOfOfficeData') |
|
104 | - ->willReturn(null); |
|
105 | - $this->config->method('getUserValue') |
|
106 | - ->with('user', 'dav', 'user_status_automation', 'no') |
|
107 | - ->willReturn('yes'); |
|
108 | - $this->time->method('getDateTime') |
|
109 | - ->willReturn(new \DateTime($currentTime, new \DateTimeZone('UTC'))); |
|
110 | - $this->logger->expects(self::exactly(4)) |
|
111 | - ->method('debug'); |
|
112 | - if (!$isAvailable) { |
|
113 | - $this->statusManager->expects(self::once()) |
|
114 | - ->method('setUserStatus') |
|
115 | - ->with('user', IUserStatus::MESSAGE_AVAILABILITY, IUserStatus::DND, true); |
|
116 | - } |
|
117 | - $automation = $this->getAutomationMock(['getAvailabilityFromPropertiesTable']); |
|
118 | - $automation->method('getAvailabilityFromPropertiesTable') |
|
119 | - ->with('user') |
|
120 | - ->willReturn('BEGIN:VCALENDAR |
|
32 | + protected ITimeFactory&MockObject $time; |
|
33 | + protected IJobList&MockObject $jobList; |
|
34 | + protected LoggerInterface&MockObject $logger; |
|
35 | + protected IManager&MockObject $statusManager; |
|
36 | + protected IConfig&MockObject $config; |
|
37 | + private IAvailabilityCoordinator&MockObject $coordinator; |
|
38 | + private IUserManager&MockObject $userManager; |
|
39 | + |
|
40 | + protected function setUp(): void { |
|
41 | + parent::setUp(); |
|
42 | + |
|
43 | + $this->time = $this->createMock(ITimeFactory::class); |
|
44 | + $this->jobList = $this->createMock(IJobList::class); |
|
45 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
46 | + $this->statusManager = $this->createMock(IManager::class); |
|
47 | + $this->config = $this->createMock(IConfig::class); |
|
48 | + $this->coordinator = $this->createMock(IAvailabilityCoordinator::class); |
|
49 | + $this->userManager = $this->createMock(IUserManager::class); |
|
50 | + |
|
51 | + } |
|
52 | + |
|
53 | + protected function getAutomationMock(array $methods): MockObject|UserStatusAutomation { |
|
54 | + if (empty($methods)) { |
|
55 | + return new UserStatusAutomation( |
|
56 | + $this->time, |
|
57 | + Server::get(IDBConnection::class), |
|
58 | + $this->jobList, |
|
59 | + $this->logger, |
|
60 | + $this->statusManager, |
|
61 | + $this->config, |
|
62 | + $this->coordinator, |
|
63 | + $this->userManager, |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + return $this->getMockBuilder(UserStatusAutomation::class) |
|
68 | + ->setConstructorArgs([ |
|
69 | + $this->time, |
|
70 | + Server::get(IDBConnection::class), |
|
71 | + $this->jobList, |
|
72 | + $this->logger, |
|
73 | + $this->statusManager, |
|
74 | + $this->config, |
|
75 | + $this->coordinator, |
|
76 | + $this->userManager, |
|
77 | + ]) |
|
78 | + ->onlyMethods($methods) |
|
79 | + ->getMock(); |
|
80 | + } |
|
81 | + |
|
82 | + public static function dataRun(): array { |
|
83 | + return [ |
|
84 | + ['20230217', '2023-02-24 10:49:36.613834', true], |
|
85 | + ['20230224', '2023-02-24 10:49:36.613834', true], |
|
86 | + ['20230217', '2023-02-24 13:58:24.479357', false], |
|
87 | + ['20230224', '2023-02-24 13:58:24.479357', false], |
|
88 | + ]; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @dataProvider dataRun |
|
93 | + */ |
|
94 | + public function testRunNoOOO(string $ruleDay, string $currentTime, bool $isAvailable): void { |
|
95 | + $user = $this->createConfiguredMock(IUser::class, [ |
|
96 | + 'getUID' => 'user' |
|
97 | + ]); |
|
98 | + |
|
99 | + $this->userManager->expects(self::once()) |
|
100 | + ->method('get') |
|
101 | + ->willReturn($user); |
|
102 | + $this->coordinator->expects(self::once()) |
|
103 | + ->method('getCurrentOutOfOfficeData') |
|
104 | + ->willReturn(null); |
|
105 | + $this->config->method('getUserValue') |
|
106 | + ->with('user', 'dav', 'user_status_automation', 'no') |
|
107 | + ->willReturn('yes'); |
|
108 | + $this->time->method('getDateTime') |
|
109 | + ->willReturn(new \DateTime($currentTime, new \DateTimeZone('UTC'))); |
|
110 | + $this->logger->expects(self::exactly(4)) |
|
111 | + ->method('debug'); |
|
112 | + if (!$isAvailable) { |
|
113 | + $this->statusManager->expects(self::once()) |
|
114 | + ->method('setUserStatus') |
|
115 | + ->with('user', IUserStatus::MESSAGE_AVAILABILITY, IUserStatus::DND, true); |
|
116 | + } |
|
117 | + $automation = $this->getAutomationMock(['getAvailabilityFromPropertiesTable']); |
|
118 | + $automation->method('getAvailabilityFromPropertiesTable') |
|
119 | + ->with('user') |
|
120 | + ->willReturn('BEGIN:VCALENDAR |
|
121 | 121 | PRODID:Nextcloud DAV app |
122 | 122 | BEGIN:VTIMEZONE |
123 | 123 | TZID:Europe/Berlin |
@@ -152,71 +152,71 @@ discard block |
||
152 | 152 | END:VAVAILABILITY |
153 | 153 | END:VCALENDAR'); |
154 | 154 | |
155 | - self::invokePrivate($automation, 'run', [['userId' => 'user']]); |
|
156 | - } |
|
157 | - |
|
158 | - public function testRunNoAvailabilityNoOOO(): void { |
|
159 | - $user = $this->createConfiguredMock(IUser::class, [ |
|
160 | - 'getUID' => 'user' |
|
161 | - ]); |
|
162 | - |
|
163 | - $this->userManager->expects(self::once()) |
|
164 | - ->method('get') |
|
165 | - ->willReturn($user); |
|
166 | - $this->coordinator->expects(self::once()) |
|
167 | - ->method('getCurrentOutOfOfficeData') |
|
168 | - ->willReturn(null); |
|
169 | - $this->config->method('getUserValue') |
|
170 | - ->with('user', 'dav', 'user_status_automation', 'no') |
|
171 | - ->willReturn('yes'); |
|
172 | - $this->time->method('getDateTime') |
|
173 | - ->willReturn(new \DateTime('2023-02-24 13:58:24.479357', new \DateTimeZone('UTC'))); |
|
174 | - $this->jobList->expects($this->once()) |
|
175 | - ->method('remove') |
|
176 | - ->with(UserStatusAutomation::class, ['userId' => 'user']); |
|
177 | - $this->logger->expects(self::once()) |
|
178 | - ->method('debug'); |
|
179 | - $this->logger->expects(self::once()) |
|
180 | - ->method('info'); |
|
181 | - $automation = $this->getAutomationMock(['getAvailabilityFromPropertiesTable']); |
|
182 | - $automation->method('getAvailabilityFromPropertiesTable') |
|
183 | - ->with('user') |
|
184 | - ->willReturn(false); |
|
185 | - |
|
186 | - self::invokePrivate($automation, 'run', [['userId' => 'user']]); |
|
187 | - } |
|
188 | - |
|
189 | - public function testRunNoAvailabilityWithOOO(): void { |
|
190 | - $user = $this->createConfiguredMock(IUser::class, [ |
|
191 | - 'getUID' => 'user' |
|
192 | - ]); |
|
193 | - $ooo = $this->createConfiguredMock(OutOfOfficeData::class, [ |
|
194 | - 'getShortMessage' => 'On Vacation', |
|
195 | - 'getEndDate' => 123456, |
|
196 | - ]); |
|
197 | - |
|
198 | - $this->userManager->expects(self::once()) |
|
199 | - ->method('get') |
|
200 | - ->willReturn($user); |
|
201 | - $this->coordinator->expects(self::once()) |
|
202 | - ->method('getCurrentOutOfOfficeData') |
|
203 | - ->willReturn($ooo); |
|
204 | - $this->coordinator->expects(self::once()) |
|
205 | - ->method('isInEffect') |
|
206 | - ->willReturn(true); |
|
207 | - $this->statusManager->expects(self::once()) |
|
208 | - ->method('setUserStatus') |
|
209 | - ->with('user', IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::DND, true, $ooo->getShortMessage()); |
|
210 | - $this->config->expects(self::never()) |
|
211 | - ->method('getUserValue'); |
|
212 | - $this->time->method('getDateTime') |
|
213 | - ->willReturn(new \DateTime('2023-02-24 13:58:24.479357', new \DateTimeZone('UTC'))); |
|
214 | - $this->jobList->expects($this->never()) |
|
215 | - ->method('remove'); |
|
216 | - $this->logger->expects(self::exactly(2)) |
|
217 | - ->method('debug'); |
|
218 | - $automation = $this->getAutomationMock([]); |
|
219 | - |
|
220 | - self::invokePrivate($automation, 'run', [['userId' => 'user']]); |
|
221 | - } |
|
155 | + self::invokePrivate($automation, 'run', [['userId' => 'user']]); |
|
156 | + } |
|
157 | + |
|
158 | + public function testRunNoAvailabilityNoOOO(): void { |
|
159 | + $user = $this->createConfiguredMock(IUser::class, [ |
|
160 | + 'getUID' => 'user' |
|
161 | + ]); |
|
162 | + |
|
163 | + $this->userManager->expects(self::once()) |
|
164 | + ->method('get') |
|
165 | + ->willReturn($user); |
|
166 | + $this->coordinator->expects(self::once()) |
|
167 | + ->method('getCurrentOutOfOfficeData') |
|
168 | + ->willReturn(null); |
|
169 | + $this->config->method('getUserValue') |
|
170 | + ->with('user', 'dav', 'user_status_automation', 'no') |
|
171 | + ->willReturn('yes'); |
|
172 | + $this->time->method('getDateTime') |
|
173 | + ->willReturn(new \DateTime('2023-02-24 13:58:24.479357', new \DateTimeZone('UTC'))); |
|
174 | + $this->jobList->expects($this->once()) |
|
175 | + ->method('remove') |
|
176 | + ->with(UserStatusAutomation::class, ['userId' => 'user']); |
|
177 | + $this->logger->expects(self::once()) |
|
178 | + ->method('debug'); |
|
179 | + $this->logger->expects(self::once()) |
|
180 | + ->method('info'); |
|
181 | + $automation = $this->getAutomationMock(['getAvailabilityFromPropertiesTable']); |
|
182 | + $automation->method('getAvailabilityFromPropertiesTable') |
|
183 | + ->with('user') |
|
184 | + ->willReturn(false); |
|
185 | + |
|
186 | + self::invokePrivate($automation, 'run', [['userId' => 'user']]); |
|
187 | + } |
|
188 | + |
|
189 | + public function testRunNoAvailabilityWithOOO(): void { |
|
190 | + $user = $this->createConfiguredMock(IUser::class, [ |
|
191 | + 'getUID' => 'user' |
|
192 | + ]); |
|
193 | + $ooo = $this->createConfiguredMock(OutOfOfficeData::class, [ |
|
194 | + 'getShortMessage' => 'On Vacation', |
|
195 | + 'getEndDate' => 123456, |
|
196 | + ]); |
|
197 | + |
|
198 | + $this->userManager->expects(self::once()) |
|
199 | + ->method('get') |
|
200 | + ->willReturn($user); |
|
201 | + $this->coordinator->expects(self::once()) |
|
202 | + ->method('getCurrentOutOfOfficeData') |
|
203 | + ->willReturn($ooo); |
|
204 | + $this->coordinator->expects(self::once()) |
|
205 | + ->method('isInEffect') |
|
206 | + ->willReturn(true); |
|
207 | + $this->statusManager->expects(self::once()) |
|
208 | + ->method('setUserStatus') |
|
209 | + ->with('user', IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::DND, true, $ooo->getShortMessage()); |
|
210 | + $this->config->expects(self::never()) |
|
211 | + ->method('getUserValue'); |
|
212 | + $this->time->method('getDateTime') |
|
213 | + ->willReturn(new \DateTime('2023-02-24 13:58:24.479357', new \DateTimeZone('UTC'))); |
|
214 | + $this->jobList->expects($this->never()) |
|
215 | + ->method('remove'); |
|
216 | + $this->logger->expects(self::exactly(2)) |
|
217 | + ->method('debug'); |
|
218 | + $automation = $this->getAutomationMock([]); |
|
219 | + |
|
220 | + self::invokePrivate($automation, 'run', [['userId' => 'user']]); |
|
221 | + } |
|
222 | 222 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | } |
52 | 52 | |
53 | - protected function getAutomationMock(array $methods): MockObject|UserStatusAutomation { |
|
53 | + protected function getAutomationMock(array $methods): MockObject | UserStatusAutomation { |
|
54 | 54 | if (empty($methods)) { |
55 | 55 | return new UserStatusAutomation( |
56 | 56 | $this->time, |
@@ -138,14 +138,14 @@ discard block |
||
138 | 138 | END:VTIMEZONE |
139 | 139 | BEGIN:VAVAILABILITY |
140 | 140 | BEGIN:AVAILABLE |
141 | -DTSTART;TZID=Europe/Berlin:' . $ruleDay . 'T090000 |
|
142 | -DTEND;TZID=Europe/Berlin:' . $ruleDay . 'T170000 |
|
141 | +DTSTART;TZID=Europe/Berlin:' . $ruleDay.'T090000 |
|
142 | +DTEND;TZID=Europe/Berlin:' . $ruleDay.'T170000 |
|
143 | 143 | UID:3e6feeec-8e00-4265-b822-b73174e8b39f |
144 | 144 | RRULE:FREQ=WEEKLY;BYDAY=TH |
145 | 145 | END:AVAILABLE |
146 | 146 | BEGIN:AVAILABLE |
147 | -DTSTART;TZID=Europe/Berlin:' . $ruleDay . 'T090000 |
|
148 | -DTEND;TZID=Europe/Berlin:' . $ruleDay . 'T120000 |
|
147 | +DTSTART;TZID=Europe/Berlin:' . $ruleDay.'T090000 |
|
148 | +DTEND;TZID=Europe/Berlin:' . $ruleDay.'T120000 |
|
149 | 149 | UID:8a634e99-07cf-443b-b480-005a0e1db323 |
150 | 150 | RRULE:FREQ=WEEKLY;BYDAY=FR |
151 | 151 | END:AVAILABLE |
@@ -20,65 +20,65 @@ |
||
20 | 20 | use Test\TestCase; |
21 | 21 | |
22 | 22 | class PruneOutdatedSyncTokensJobTest extends TestCase { |
23 | - private ITimeFactory&MockObject $timeFactory; |
|
24 | - private CalDavBackend&MockObject $calDavBackend; |
|
25 | - private CardDavBackend&MockObject $cardDavBackend; |
|
26 | - private IConfig&MockObject $config; |
|
27 | - private LoggerInterface&MockObject $logger; |
|
28 | - private PruneOutdatedSyncTokensJob $backgroundJob; |
|
23 | + private ITimeFactory&MockObject $timeFactory; |
|
24 | + private CalDavBackend&MockObject $calDavBackend; |
|
25 | + private CardDavBackend&MockObject $cardDavBackend; |
|
26 | + private IConfig&MockObject $config; |
|
27 | + private LoggerInterface&MockObject $logger; |
|
28 | + private PruneOutdatedSyncTokensJob $backgroundJob; |
|
29 | 29 | |
30 | - protected function setUp(): void { |
|
31 | - parent::setUp(); |
|
30 | + protected function setUp(): void { |
|
31 | + parent::setUp(); |
|
32 | 32 | |
33 | - $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
34 | - $this->calDavBackend = $this->createMock(CalDavBackend::class); |
|
35 | - $this->cardDavBackend = $this->createMock(CardDavBackend::class); |
|
36 | - $this->config = $this->createMock(IConfig::class); |
|
37 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
33 | + $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
34 | + $this->calDavBackend = $this->createMock(CalDavBackend::class); |
|
35 | + $this->cardDavBackend = $this->createMock(CardDavBackend::class); |
|
36 | + $this->config = $this->createMock(IConfig::class); |
|
37 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
38 | 38 | |
39 | - $this->backgroundJob = new PruneOutdatedSyncTokensJob($this->timeFactory, $this->calDavBackend, $this->cardDavBackend, $this->config, $this->logger); |
|
40 | - } |
|
39 | + $this->backgroundJob = new PruneOutdatedSyncTokensJob($this->timeFactory, $this->calDavBackend, $this->cardDavBackend, $this->config, $this->logger); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @dataProvider dataForTestRun |
|
44 | - */ |
|
45 | - public function testRun(string $configToKeep, string $configRetentionDays, int $actualLimit, int $retentionDays, int $deletedCalendarSyncTokens, int $deletedAddressBookSyncTokens): void { |
|
46 | - $this->config->expects($this->exactly(2)) |
|
47 | - ->method('getAppValue') |
|
48 | - ->with(Application::APP_ID, self::anything(), self::anything()) |
|
49 | - ->willReturnCallback(function ($app, $key) use ($configToKeep, $configRetentionDays) { |
|
50 | - switch ($key) { |
|
51 | - case 'totalNumberOfSyncTokensToKeep': |
|
52 | - return $configToKeep; |
|
53 | - case 'syncTokensRetentionDays': |
|
54 | - return $configRetentionDays; |
|
55 | - default: |
|
56 | - throw new InvalidArgumentException(); |
|
57 | - } |
|
58 | - }); |
|
59 | - $this->calDavBackend->expects($this->once()) |
|
60 | - ->method('pruneOutdatedSyncTokens') |
|
61 | - ->with($actualLimit) |
|
62 | - ->willReturn($deletedCalendarSyncTokens); |
|
63 | - $this->cardDavBackend->expects($this->once()) |
|
64 | - ->method('pruneOutdatedSyncTokens') |
|
65 | - ->with($actualLimit, $retentionDays) |
|
66 | - ->willReturn($deletedAddressBookSyncTokens); |
|
67 | - $this->logger->expects($this->once()) |
|
68 | - ->method('info') |
|
69 | - ->with('Pruned {calendarSyncTokensNumber} calendar sync tokens and {addressBooksSyncTokensNumber} address book sync tokens', [ |
|
70 | - 'calendarSyncTokensNumber' => $deletedCalendarSyncTokens, |
|
71 | - 'addressBooksSyncTokensNumber' => $deletedAddressBookSyncTokens |
|
72 | - ]); |
|
42 | + /** |
|
43 | + * @dataProvider dataForTestRun |
|
44 | + */ |
|
45 | + public function testRun(string $configToKeep, string $configRetentionDays, int $actualLimit, int $retentionDays, int $deletedCalendarSyncTokens, int $deletedAddressBookSyncTokens): void { |
|
46 | + $this->config->expects($this->exactly(2)) |
|
47 | + ->method('getAppValue') |
|
48 | + ->with(Application::APP_ID, self::anything(), self::anything()) |
|
49 | + ->willReturnCallback(function ($app, $key) use ($configToKeep, $configRetentionDays) { |
|
50 | + switch ($key) { |
|
51 | + case 'totalNumberOfSyncTokensToKeep': |
|
52 | + return $configToKeep; |
|
53 | + case 'syncTokensRetentionDays': |
|
54 | + return $configRetentionDays; |
|
55 | + default: |
|
56 | + throw new InvalidArgumentException(); |
|
57 | + } |
|
58 | + }); |
|
59 | + $this->calDavBackend->expects($this->once()) |
|
60 | + ->method('pruneOutdatedSyncTokens') |
|
61 | + ->with($actualLimit) |
|
62 | + ->willReturn($deletedCalendarSyncTokens); |
|
63 | + $this->cardDavBackend->expects($this->once()) |
|
64 | + ->method('pruneOutdatedSyncTokens') |
|
65 | + ->with($actualLimit, $retentionDays) |
|
66 | + ->willReturn($deletedAddressBookSyncTokens); |
|
67 | + $this->logger->expects($this->once()) |
|
68 | + ->method('info') |
|
69 | + ->with('Pruned {calendarSyncTokensNumber} calendar sync tokens and {addressBooksSyncTokensNumber} address book sync tokens', [ |
|
70 | + 'calendarSyncTokensNumber' => $deletedCalendarSyncTokens, |
|
71 | + 'addressBooksSyncTokensNumber' => $deletedAddressBookSyncTokens |
|
72 | + ]); |
|
73 | 73 | |
74 | - $this->backgroundJob->run(null); |
|
75 | - } |
|
74 | + $this->backgroundJob->run(null); |
|
75 | + } |
|
76 | 76 | |
77 | - public static function dataForTestRun(): array { |
|
78 | - return [ |
|
79 | - ['100', '2', 100, 7 * 24 * 3600, 2, 3], |
|
80 | - ['100', '14', 100, 14 * 24 * 3600, 2, 3], |
|
81 | - ['0', '60', 1, 60 * 24 * 3600, 0, 0] |
|
82 | - ]; |
|
83 | - } |
|
77 | + public static function dataForTestRun(): array { |
|
78 | + return [ |
|
79 | + ['100', '2', 100, 7 * 24 * 3600, 2, 3], |
|
80 | + ['100', '14', 100, 14 * 24 * 3600, 2, 3], |
|
81 | + ['0', '60', 1, 60 * 24 * 3600, 0, 0] |
|
82 | + ]; |
|
83 | + } |
|
84 | 84 | } |
@@ -16,98 +16,98 @@ |
||
16 | 16 | use Test\TestCase; |
17 | 17 | |
18 | 18 | class GenerateBirthdayCalendarBackgroundJobTest extends TestCase { |
19 | - private ITimeFactory&MockObject $time; |
|
20 | - private BirthdayService&MockObject $birthdayService; |
|
21 | - private IConfig&MockObject $config; |
|
22 | - private GenerateBirthdayCalendarBackgroundJob $backgroundJob; |
|
23 | - |
|
24 | - protected function setUp(): void { |
|
25 | - parent::setUp(); |
|
26 | - |
|
27 | - $this->time = $this->createMock(ITimeFactory::class); |
|
28 | - $this->birthdayService = $this->createMock(BirthdayService::class); |
|
29 | - $this->config = $this->createMock(IConfig::class); |
|
30 | - |
|
31 | - $this->backgroundJob = new GenerateBirthdayCalendarBackgroundJob( |
|
32 | - $this->time, |
|
33 | - $this->birthdayService, |
|
34 | - $this->config, |
|
35 | - ); |
|
36 | - } |
|
37 | - |
|
38 | - public function testRun(): void { |
|
39 | - $this->config->expects($this->once()) |
|
40 | - ->method('getAppValue') |
|
41 | - ->with('dav', 'generateBirthdayCalendar', 'yes') |
|
42 | - ->willReturn('yes'); |
|
43 | - |
|
44 | - $this->config->expects($this->once()) |
|
45 | - ->method('getUserValue') |
|
46 | - ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes') |
|
47 | - ->willReturn('yes'); |
|
48 | - |
|
49 | - $this->birthdayService->expects($this->never()) |
|
50 | - ->method('resetForUser') |
|
51 | - ->with('user123'); |
|
52 | - |
|
53 | - $this->birthdayService->expects($this->once()) |
|
54 | - ->method('syncUser') |
|
55 | - ->with('user123'); |
|
56 | - |
|
57 | - $this->backgroundJob->run(['userId' => 'user123']); |
|
58 | - } |
|
59 | - |
|
60 | - public function testRunAndReset(): void { |
|
61 | - $this->config->expects($this->once()) |
|
62 | - ->method('getAppValue') |
|
63 | - ->with('dav', 'generateBirthdayCalendar', 'yes') |
|
64 | - ->willReturn('yes'); |
|
65 | - |
|
66 | - $this->config->expects($this->once()) |
|
67 | - ->method('getUserValue') |
|
68 | - ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes') |
|
69 | - ->willReturn('yes'); |
|
70 | - |
|
71 | - $this->birthdayService->expects($this->once()) |
|
72 | - ->method('resetForUser') |
|
73 | - ->with('user123'); |
|
74 | - |
|
75 | - $this->birthdayService->expects($this->once()) |
|
76 | - ->method('syncUser') |
|
77 | - ->with('user123'); |
|
78 | - |
|
79 | - $this->backgroundJob->run(['userId' => 'user123', 'purgeBeforeGenerating' => true]); |
|
80 | - } |
|
81 | - |
|
82 | - public function testRunGloballyDisabled(): void { |
|
83 | - $this->config->expects($this->once()) |
|
84 | - ->method('getAppValue') |
|
85 | - ->with('dav', 'generateBirthdayCalendar', 'yes') |
|
86 | - ->willReturn('no'); |
|
87 | - |
|
88 | - $this->config->expects($this->never()) |
|
89 | - ->method('getUserValue'); |
|
90 | - |
|
91 | - $this->birthdayService->expects($this->never()) |
|
92 | - ->method('syncUser'); |
|
93 | - |
|
94 | - $this->backgroundJob->run(['userId' => 'user123']); |
|
95 | - } |
|
96 | - |
|
97 | - public function testRunUserDisabled(): void { |
|
98 | - $this->config->expects($this->once()) |
|
99 | - ->method('getAppValue') |
|
100 | - ->with('dav', 'generateBirthdayCalendar', 'yes') |
|
101 | - ->willReturn('yes'); |
|
102 | - |
|
103 | - $this->config->expects($this->once()) |
|
104 | - ->method('getUserValue') |
|
105 | - ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes') |
|
106 | - ->willReturn('no'); |
|
107 | - |
|
108 | - $this->birthdayService->expects($this->never()) |
|
109 | - ->method('syncUser'); |
|
110 | - |
|
111 | - $this->backgroundJob->run(['userId' => 'user123']); |
|
112 | - } |
|
19 | + private ITimeFactory&MockObject $time; |
|
20 | + private BirthdayService&MockObject $birthdayService; |
|
21 | + private IConfig&MockObject $config; |
|
22 | + private GenerateBirthdayCalendarBackgroundJob $backgroundJob; |
|
23 | + |
|
24 | + protected function setUp(): void { |
|
25 | + parent::setUp(); |
|
26 | + |
|
27 | + $this->time = $this->createMock(ITimeFactory::class); |
|
28 | + $this->birthdayService = $this->createMock(BirthdayService::class); |
|
29 | + $this->config = $this->createMock(IConfig::class); |
|
30 | + |
|
31 | + $this->backgroundJob = new GenerateBirthdayCalendarBackgroundJob( |
|
32 | + $this->time, |
|
33 | + $this->birthdayService, |
|
34 | + $this->config, |
|
35 | + ); |
|
36 | + } |
|
37 | + |
|
38 | + public function testRun(): void { |
|
39 | + $this->config->expects($this->once()) |
|
40 | + ->method('getAppValue') |
|
41 | + ->with('dav', 'generateBirthdayCalendar', 'yes') |
|
42 | + ->willReturn('yes'); |
|
43 | + |
|
44 | + $this->config->expects($this->once()) |
|
45 | + ->method('getUserValue') |
|
46 | + ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes') |
|
47 | + ->willReturn('yes'); |
|
48 | + |
|
49 | + $this->birthdayService->expects($this->never()) |
|
50 | + ->method('resetForUser') |
|
51 | + ->with('user123'); |
|
52 | + |
|
53 | + $this->birthdayService->expects($this->once()) |
|
54 | + ->method('syncUser') |
|
55 | + ->with('user123'); |
|
56 | + |
|
57 | + $this->backgroundJob->run(['userId' => 'user123']); |
|
58 | + } |
|
59 | + |
|
60 | + public function testRunAndReset(): void { |
|
61 | + $this->config->expects($this->once()) |
|
62 | + ->method('getAppValue') |
|
63 | + ->with('dav', 'generateBirthdayCalendar', 'yes') |
|
64 | + ->willReturn('yes'); |
|
65 | + |
|
66 | + $this->config->expects($this->once()) |
|
67 | + ->method('getUserValue') |
|
68 | + ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes') |
|
69 | + ->willReturn('yes'); |
|
70 | + |
|
71 | + $this->birthdayService->expects($this->once()) |
|
72 | + ->method('resetForUser') |
|
73 | + ->with('user123'); |
|
74 | + |
|
75 | + $this->birthdayService->expects($this->once()) |
|
76 | + ->method('syncUser') |
|
77 | + ->with('user123'); |
|
78 | + |
|
79 | + $this->backgroundJob->run(['userId' => 'user123', 'purgeBeforeGenerating' => true]); |
|
80 | + } |
|
81 | + |
|
82 | + public function testRunGloballyDisabled(): void { |
|
83 | + $this->config->expects($this->once()) |
|
84 | + ->method('getAppValue') |
|
85 | + ->with('dav', 'generateBirthdayCalendar', 'yes') |
|
86 | + ->willReturn('no'); |
|
87 | + |
|
88 | + $this->config->expects($this->never()) |
|
89 | + ->method('getUserValue'); |
|
90 | + |
|
91 | + $this->birthdayService->expects($this->never()) |
|
92 | + ->method('syncUser'); |
|
93 | + |
|
94 | + $this->backgroundJob->run(['userId' => 'user123']); |
|
95 | + } |
|
96 | + |
|
97 | + public function testRunUserDisabled(): void { |
|
98 | + $this->config->expects($this->once()) |
|
99 | + ->method('getAppValue') |
|
100 | + ->with('dav', 'generateBirthdayCalendar', 'yes') |
|
101 | + ->willReturn('yes'); |
|
102 | + |
|
103 | + $this->config->expects($this->once()) |
|
104 | + ->method('getUserValue') |
|
105 | + ->with('user123', 'dav', 'generateBirthdayCalendar', 'yes') |
|
106 | + ->willReturn('no'); |
|
107 | + |
|
108 | + $this->birthdayService->expects($this->never()) |
|
109 | + ->method('syncUser'); |
|
110 | + |
|
111 | + $this->backgroundJob->run(['userId' => 'user123']); |
|
112 | + } |
|
113 | 113 | } |
@@ -16,57 +16,57 @@ |
||
16 | 16 | use Test\TestCase; |
17 | 17 | |
18 | 18 | class EventReminderJobTest extends TestCase { |
19 | - private ITimeFactory&MockObject $time; |
|
20 | - private ReminderService&MockObject $reminderService; |
|
21 | - private IConfig&MockObject $config; |
|
22 | - private EventReminderJob $backgroundJob; |
|
19 | + private ITimeFactory&MockObject $time; |
|
20 | + private ReminderService&MockObject $reminderService; |
|
21 | + private IConfig&MockObject $config; |
|
22 | + private EventReminderJob $backgroundJob; |
|
23 | 23 | |
24 | - protected function setUp(): void { |
|
25 | - parent::setUp(); |
|
24 | + protected function setUp(): void { |
|
25 | + parent::setUp(); |
|
26 | 26 | |
27 | - $this->time = $this->createMock(ITimeFactory::class); |
|
28 | - $this->reminderService = $this->createMock(ReminderService::class); |
|
29 | - $this->config = $this->createMock(IConfig::class); |
|
27 | + $this->time = $this->createMock(ITimeFactory::class); |
|
28 | + $this->reminderService = $this->createMock(ReminderService::class); |
|
29 | + $this->config = $this->createMock(IConfig::class); |
|
30 | 30 | |
31 | - $this->backgroundJob = new EventReminderJob( |
|
32 | - $this->time, |
|
33 | - $this->reminderService, |
|
34 | - $this->config, |
|
35 | - ); |
|
36 | - } |
|
31 | + $this->backgroundJob = new EventReminderJob( |
|
32 | + $this->time, |
|
33 | + $this->reminderService, |
|
34 | + $this->config, |
|
35 | + ); |
|
36 | + } |
|
37 | 37 | |
38 | - public static function data(): array { |
|
39 | - return [ |
|
40 | - [true, true, true], |
|
41 | - [true, false, false], |
|
42 | - [false, true, false], |
|
43 | - [false, false, false], |
|
44 | - ]; |
|
45 | - } |
|
38 | + public static function data(): array { |
|
39 | + return [ |
|
40 | + [true, true, true], |
|
41 | + [true, false, false], |
|
42 | + [false, true, false], |
|
43 | + [false, false, false], |
|
44 | + ]; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @dataProvider data |
|
49 | - * |
|
50 | - * @param bool $sendEventReminders |
|
51 | - * @param bool $sendEventRemindersMode |
|
52 | - * @param bool $expectCall |
|
53 | - */ |
|
54 | - public function testRun(bool $sendEventReminders, bool $sendEventRemindersMode, bool $expectCall): void { |
|
55 | - $this->config->expects($this->exactly($sendEventReminders ? 2 : 1)) |
|
56 | - ->method('getAppValue') |
|
57 | - ->willReturnMap([ |
|
58 | - ['dav', 'sendEventReminders', 'yes', ($sendEventReminders ? 'yes' : 'no')], |
|
59 | - ['dav', 'sendEventRemindersMode', 'backgroundjob', ($sendEventRemindersMode ? 'backgroundjob' : 'cron')], |
|
60 | - ]); |
|
47 | + /** |
|
48 | + * @dataProvider data |
|
49 | + * |
|
50 | + * @param bool $sendEventReminders |
|
51 | + * @param bool $sendEventRemindersMode |
|
52 | + * @param bool $expectCall |
|
53 | + */ |
|
54 | + public function testRun(bool $sendEventReminders, bool $sendEventRemindersMode, bool $expectCall): void { |
|
55 | + $this->config->expects($this->exactly($sendEventReminders ? 2 : 1)) |
|
56 | + ->method('getAppValue') |
|
57 | + ->willReturnMap([ |
|
58 | + ['dav', 'sendEventReminders', 'yes', ($sendEventReminders ? 'yes' : 'no')], |
|
59 | + ['dav', 'sendEventRemindersMode', 'backgroundjob', ($sendEventRemindersMode ? 'backgroundjob' : 'cron')], |
|
60 | + ]); |
|
61 | 61 | |
62 | - if ($expectCall) { |
|
63 | - $this->reminderService->expects($this->once()) |
|
64 | - ->method('processReminders'); |
|
65 | - } else { |
|
66 | - $this->reminderService->expects($this->never()) |
|
67 | - ->method('processReminders'); |
|
68 | - } |
|
62 | + if ($expectCall) { |
|
63 | + $this->reminderService->expects($this->once()) |
|
64 | + ->method('processReminders'); |
|
65 | + } else { |
|
66 | + $this->reminderService->expects($this->never()) |
|
67 | + ->method('processReminders'); |
|
68 | + } |
|
69 | 69 | |
70 | - $this->backgroundJob->run([]); |
|
71 | - } |
|
70 | + $this->backgroundJob->run([]); |
|
71 | + } |
|
72 | 72 | } |
@@ -18,62 +18,62 @@ |
||
18 | 18 | use Test\TestCase; |
19 | 19 | |
20 | 20 | class RegisterRegenerateBirthdayCalendarsTest extends TestCase { |
21 | - private ITimeFactory&MockObject $time; |
|
22 | - private IUserManager&MockObject $userManager; |
|
23 | - private IJobList&MockObject $jobList; |
|
24 | - private RegisterRegenerateBirthdayCalendars $backgroundJob; |
|
21 | + private ITimeFactory&MockObject $time; |
|
22 | + private IUserManager&MockObject $userManager; |
|
23 | + private IJobList&MockObject $jobList; |
|
24 | + private RegisterRegenerateBirthdayCalendars $backgroundJob; |
|
25 | 25 | |
26 | - protected function setUp(): void { |
|
27 | - parent::setUp(); |
|
26 | + protected function setUp(): void { |
|
27 | + parent::setUp(); |
|
28 | 28 | |
29 | - $this->time = $this->createMock(ITimeFactory::class); |
|
30 | - $this->userManager = $this->createMock(IUserManager::class); |
|
31 | - $this->jobList = $this->createMock(IJobList::class); |
|
29 | + $this->time = $this->createMock(ITimeFactory::class); |
|
30 | + $this->userManager = $this->createMock(IUserManager::class); |
|
31 | + $this->jobList = $this->createMock(IJobList::class); |
|
32 | 32 | |
33 | - $this->backgroundJob = new RegisterRegenerateBirthdayCalendars( |
|
34 | - $this->time, |
|
35 | - $this->userManager, |
|
36 | - $this->jobList |
|
37 | - ); |
|
38 | - } |
|
33 | + $this->backgroundJob = new RegisterRegenerateBirthdayCalendars( |
|
34 | + $this->time, |
|
35 | + $this->userManager, |
|
36 | + $this->jobList |
|
37 | + ); |
|
38 | + } |
|
39 | 39 | |
40 | - public function testRun(): void { |
|
41 | - $this->userManager->expects($this->once()) |
|
42 | - ->method('callForSeenUsers') |
|
43 | - ->willReturnCallback(function ($closure): void { |
|
44 | - $user1 = $this->createMock(IUser::class); |
|
45 | - $user1->method('getUID')->willReturn('uid1'); |
|
46 | - $user2 = $this->createMock(IUser::class); |
|
47 | - $user2->method('getUID')->willReturn('uid2'); |
|
48 | - $user3 = $this->createMock(IUser::class); |
|
49 | - $user3->method('getUID')->willReturn('uid3'); |
|
40 | + public function testRun(): void { |
|
41 | + $this->userManager->expects($this->once()) |
|
42 | + ->method('callForSeenUsers') |
|
43 | + ->willReturnCallback(function ($closure): void { |
|
44 | + $user1 = $this->createMock(IUser::class); |
|
45 | + $user1->method('getUID')->willReturn('uid1'); |
|
46 | + $user2 = $this->createMock(IUser::class); |
|
47 | + $user2->method('getUID')->willReturn('uid2'); |
|
48 | + $user3 = $this->createMock(IUser::class); |
|
49 | + $user3->method('getUID')->willReturn('uid3'); |
|
50 | 50 | |
51 | - $closure($user1); |
|
52 | - $closure($user2); |
|
53 | - $closure($user3); |
|
54 | - }); |
|
51 | + $closure($user1); |
|
52 | + $closure($user2); |
|
53 | + $closure($user3); |
|
54 | + }); |
|
55 | 55 | |
56 | - $calls = [ |
|
57 | - 'uid1', |
|
58 | - 'uid2', |
|
59 | - 'uid3', |
|
60 | - ]; |
|
61 | - $this->jobList->expects($this->exactly(3)) |
|
62 | - ->method('add') |
|
63 | - ->willReturnCallback(function () use (&$calls): void { |
|
64 | - $expected = array_shift($calls); |
|
65 | - $this->assertEquals( |
|
66 | - [ |
|
67 | - GenerateBirthdayCalendarBackgroundJob::class, |
|
68 | - [ |
|
69 | - 'userId' => $expected, |
|
70 | - 'purgeBeforeGenerating' => true |
|
71 | - ] |
|
72 | - ], |
|
73 | - func_get_args() |
|
74 | - ); |
|
75 | - }); |
|
56 | + $calls = [ |
|
57 | + 'uid1', |
|
58 | + 'uid2', |
|
59 | + 'uid3', |
|
60 | + ]; |
|
61 | + $this->jobList->expects($this->exactly(3)) |
|
62 | + ->method('add') |
|
63 | + ->willReturnCallback(function () use (&$calls): void { |
|
64 | + $expected = array_shift($calls); |
|
65 | + $this->assertEquals( |
|
66 | + [ |
|
67 | + GenerateBirthdayCalendarBackgroundJob::class, |
|
68 | + [ |
|
69 | + 'userId' => $expected, |
|
70 | + 'purgeBeforeGenerating' => true |
|
71 | + ] |
|
72 | + ], |
|
73 | + func_get_args() |
|
74 | + ); |
|
75 | + }); |
|
76 | 76 | |
77 | - $this->backgroundJob->run([]); |
|
78 | - } |
|
77 | + $this->backgroundJob->run([]); |
|
78 | + } |
|
79 | 79 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public function testRun(): void { |
41 | 41 | $this->userManager->expects($this->once()) |
42 | 42 | ->method('callForSeenUsers') |
43 | - ->willReturnCallback(function ($closure): void { |
|
43 | + ->willReturnCallback(function($closure): void { |
|
44 | 44 | $user1 = $this->createMock(IUser::class); |
45 | 45 | $user1->method('getUID')->willReturn('uid1'); |
46 | 46 | $user2 = $this->createMock(IUser::class); |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | ]; |
61 | 61 | $this->jobList->expects($this->exactly(3)) |
62 | 62 | ->method('add') |
63 | - ->willReturnCallback(function () use (&$calls): void { |
|
63 | + ->willReturnCallback(function() use (&$calls): void { |
|
64 | 64 | $expected = array_shift($calls); |
65 | 65 | $this->assertEquals( |
66 | 66 | [ |
@@ -17,31 +17,31 @@ |
||
17 | 17 | use Test\TestCase; |
18 | 18 | |
19 | 19 | class UpdateCalendarResourcesRoomsBackgroundJobTest extends TestCase { |
20 | - private UpdateCalendarResourcesRoomsBackgroundJob $backgroundJob; |
|
21 | - private ITimeFactory&MockObject $time; |
|
22 | - private IResourceManager&MockObject $resourceManager; |
|
23 | - private IRoomManager&MockObject $roomManager; |
|
24 | - |
|
25 | - protected function setUp(): void { |
|
26 | - parent::setUp(); |
|
27 | - |
|
28 | - $this->time = $this->createMock(ITimeFactory::class); |
|
29 | - $this->resourceManager = $this->createMock(IResourceManager::class); |
|
30 | - $this->roomManager = $this->createMock(IRoomManager::class); |
|
31 | - |
|
32 | - $this->backgroundJob = new UpdateCalendarResourcesRoomsBackgroundJob( |
|
33 | - $this->time, |
|
34 | - $this->resourceManager, |
|
35 | - $this->roomManager, |
|
36 | - ); |
|
37 | - } |
|
38 | - |
|
39 | - public function testRun(): void { |
|
40 | - $this->resourceManager->expects(self::once()) |
|
41 | - ->method('update'); |
|
42 | - $this->roomManager->expects(self::once()) |
|
43 | - ->method('update'); |
|
44 | - |
|
45 | - $this->backgroundJob->run([]); |
|
46 | - } |
|
20 | + private UpdateCalendarResourcesRoomsBackgroundJob $backgroundJob; |
|
21 | + private ITimeFactory&MockObject $time; |
|
22 | + private IResourceManager&MockObject $resourceManager; |
|
23 | + private IRoomManager&MockObject $roomManager; |
|
24 | + |
|
25 | + protected function setUp(): void { |
|
26 | + parent::setUp(); |
|
27 | + |
|
28 | + $this->time = $this->createMock(ITimeFactory::class); |
|
29 | + $this->resourceManager = $this->createMock(IResourceManager::class); |
|
30 | + $this->roomManager = $this->createMock(IRoomManager::class); |
|
31 | + |
|
32 | + $this->backgroundJob = new UpdateCalendarResourcesRoomsBackgroundJob( |
|
33 | + $this->time, |
|
34 | + $this->resourceManager, |
|
35 | + $this->roomManager, |
|
36 | + ); |
|
37 | + } |
|
38 | + |
|
39 | + public function testRun(): void { |
|
40 | + $this->resourceManager->expects(self::once()) |
|
41 | + ->method('update'); |
|
42 | + $this->roomManager->expects(self::once()) |
|
43 | + ->method('update'); |
|
44 | + |
|
45 | + $this->backgroundJob->run([]); |
|
46 | + } |
|
47 | 47 | } |
@@ -24,125 +24,125 @@ |
||
24 | 24 | use Test\TestCase; |
25 | 25 | |
26 | 26 | class OutOfOfficeEventDispatcherJobTest extends TestCase { |
27 | - private OutOfOfficeEventDispatcherJob $job; |
|
28 | - private ITimeFactory&MockObject $timeFactory; |
|
29 | - private AbsenceMapper&MockObject $absenceMapper; |
|
30 | - private LoggerInterface&MockObject $logger; |
|
31 | - private IEventDispatcher&MockObject $eventDispatcher; |
|
32 | - private IUserManager&MockObject $userManager; |
|
33 | - private MockObject|TimezoneService $timezoneService; |
|
34 | - |
|
35 | - protected function setUp(): void { |
|
36 | - parent::setUp(); |
|
37 | - |
|
38 | - $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
39 | - $this->absenceMapper = $this->createMock(AbsenceMapper::class); |
|
40 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
41 | - $this->eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
42 | - $this->userManager = $this->createMock(IUserManager::class); |
|
43 | - $this->timezoneService = $this->createMock(TimezoneService::class); |
|
44 | - |
|
45 | - $this->job = new OutOfOfficeEventDispatcherJob( |
|
46 | - $this->timeFactory, |
|
47 | - $this->absenceMapper, |
|
48 | - $this->logger, |
|
49 | - $this->eventDispatcher, |
|
50 | - $this->userManager, |
|
51 | - $this->timezoneService, |
|
52 | - ); |
|
53 | - } |
|
54 | - |
|
55 | - public function testDispatchStartEvent(): void { |
|
56 | - $this->timezoneService->method('getUserTimezone')->with('user')->willReturn('Europe/Berlin'); |
|
57 | - |
|
58 | - $absence = new Absence(); |
|
59 | - $absence->setId(200); |
|
60 | - $absence->setUserId('user'); |
|
61 | - |
|
62 | - $user = $this->createMock(IUser::class); |
|
63 | - $user->method('getUID') |
|
64 | - ->willReturn('user'); |
|
65 | - |
|
66 | - $this->absenceMapper->expects(self::once()) |
|
67 | - ->method('findById') |
|
68 | - ->with(1) |
|
69 | - ->willReturn($absence); |
|
70 | - $this->userManager->expects(self::once()) |
|
71 | - ->method('get') |
|
72 | - ->with('user') |
|
73 | - ->willReturn($user); |
|
74 | - $this->eventDispatcher->expects(self::once()) |
|
75 | - ->method('dispatchTyped') |
|
76 | - ->with(self::callback(static function ($event): bool { |
|
77 | - self::assertInstanceOf(OutOfOfficeStartedEvent::class, $event); |
|
78 | - return true; |
|
79 | - })); |
|
80 | - |
|
81 | - $this->job->run([ |
|
82 | - 'id' => 1, |
|
83 | - 'event' => OutOfOfficeEventDispatcherJob::EVENT_START, |
|
84 | - ]); |
|
85 | - } |
|
86 | - |
|
87 | - public function testDispatchStopEvent(): void { |
|
88 | - $this->timezoneService->method('getUserTimezone')->with('user')->willReturn('Europe/Berlin'); |
|
89 | - |
|
90 | - $absence = new Absence(); |
|
91 | - $absence->setId(200); |
|
92 | - $absence->setUserId('user'); |
|
93 | - |
|
94 | - $user = $this->createMock(IUser::class); |
|
95 | - $user->method('getUID') |
|
96 | - ->willReturn('user'); |
|
97 | - |
|
98 | - $this->absenceMapper->expects(self::once()) |
|
99 | - ->method('findById') |
|
100 | - ->with(1) |
|
101 | - ->willReturn($absence); |
|
102 | - $this->userManager->expects(self::once()) |
|
103 | - ->method('get') |
|
104 | - ->with('user') |
|
105 | - ->willReturn($user); |
|
106 | - $this->eventDispatcher->expects(self::once()) |
|
107 | - ->method('dispatchTyped') |
|
108 | - ->with(self::callback(static function ($event): bool { |
|
109 | - self::assertInstanceOf(OutOfOfficeEndedEvent::class, $event); |
|
110 | - return true; |
|
111 | - })); |
|
112 | - |
|
113 | - $this->job->run([ |
|
114 | - 'id' => 1, |
|
115 | - 'event' => OutOfOfficeEventDispatcherJob::EVENT_END, |
|
116 | - ]); |
|
117 | - } |
|
118 | - |
|
119 | - public function testDoesntDispatchUnknownEvent(): void { |
|
120 | - $this->timezoneService->method('getUserTimezone')->with('user')->willReturn('Europe/Berlin'); |
|
121 | - |
|
122 | - $absence = new Absence(); |
|
123 | - $absence->setId(100); |
|
124 | - $absence->setUserId('user'); |
|
125 | - |
|
126 | - $user = $this->createMock(IUser::class); |
|
127 | - $user->method('getUID') |
|
128 | - ->willReturn('user'); |
|
129 | - |
|
130 | - $this->absenceMapper->expects(self::once()) |
|
131 | - ->method('findById') |
|
132 | - ->with(1) |
|
133 | - ->willReturn($absence); |
|
134 | - $this->userManager->expects(self::once()) |
|
135 | - ->method('get') |
|
136 | - ->with('user') |
|
137 | - ->willReturn($user); |
|
138 | - $this->eventDispatcher->expects(self::never()) |
|
139 | - ->method('dispatchTyped'); |
|
140 | - $this->logger->expects(self::once()) |
|
141 | - ->method('error'); |
|
142 | - |
|
143 | - $this->job->run([ |
|
144 | - 'id' => 1, |
|
145 | - 'event' => 'foobar', |
|
146 | - ]); |
|
147 | - } |
|
27 | + private OutOfOfficeEventDispatcherJob $job; |
|
28 | + private ITimeFactory&MockObject $timeFactory; |
|
29 | + private AbsenceMapper&MockObject $absenceMapper; |
|
30 | + private LoggerInterface&MockObject $logger; |
|
31 | + private IEventDispatcher&MockObject $eventDispatcher; |
|
32 | + private IUserManager&MockObject $userManager; |
|
33 | + private MockObject|TimezoneService $timezoneService; |
|
34 | + |
|
35 | + protected function setUp(): void { |
|
36 | + parent::setUp(); |
|
37 | + |
|
38 | + $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
39 | + $this->absenceMapper = $this->createMock(AbsenceMapper::class); |
|
40 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
41 | + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
42 | + $this->userManager = $this->createMock(IUserManager::class); |
|
43 | + $this->timezoneService = $this->createMock(TimezoneService::class); |
|
44 | + |
|
45 | + $this->job = new OutOfOfficeEventDispatcherJob( |
|
46 | + $this->timeFactory, |
|
47 | + $this->absenceMapper, |
|
48 | + $this->logger, |
|
49 | + $this->eventDispatcher, |
|
50 | + $this->userManager, |
|
51 | + $this->timezoneService, |
|
52 | + ); |
|
53 | + } |
|
54 | + |
|
55 | + public function testDispatchStartEvent(): void { |
|
56 | + $this->timezoneService->method('getUserTimezone')->with('user')->willReturn('Europe/Berlin'); |
|
57 | + |
|
58 | + $absence = new Absence(); |
|
59 | + $absence->setId(200); |
|
60 | + $absence->setUserId('user'); |
|
61 | + |
|
62 | + $user = $this->createMock(IUser::class); |
|
63 | + $user->method('getUID') |
|
64 | + ->willReturn('user'); |
|
65 | + |
|
66 | + $this->absenceMapper->expects(self::once()) |
|
67 | + ->method('findById') |
|
68 | + ->with(1) |
|
69 | + ->willReturn($absence); |
|
70 | + $this->userManager->expects(self::once()) |
|
71 | + ->method('get') |
|
72 | + ->with('user') |
|
73 | + ->willReturn($user); |
|
74 | + $this->eventDispatcher->expects(self::once()) |
|
75 | + ->method('dispatchTyped') |
|
76 | + ->with(self::callback(static function ($event): bool { |
|
77 | + self::assertInstanceOf(OutOfOfficeStartedEvent::class, $event); |
|
78 | + return true; |
|
79 | + })); |
|
80 | + |
|
81 | + $this->job->run([ |
|
82 | + 'id' => 1, |
|
83 | + 'event' => OutOfOfficeEventDispatcherJob::EVENT_START, |
|
84 | + ]); |
|
85 | + } |
|
86 | + |
|
87 | + public function testDispatchStopEvent(): void { |
|
88 | + $this->timezoneService->method('getUserTimezone')->with('user')->willReturn('Europe/Berlin'); |
|
89 | + |
|
90 | + $absence = new Absence(); |
|
91 | + $absence->setId(200); |
|
92 | + $absence->setUserId('user'); |
|
93 | + |
|
94 | + $user = $this->createMock(IUser::class); |
|
95 | + $user->method('getUID') |
|
96 | + ->willReturn('user'); |
|
97 | + |
|
98 | + $this->absenceMapper->expects(self::once()) |
|
99 | + ->method('findById') |
|
100 | + ->with(1) |
|
101 | + ->willReturn($absence); |
|
102 | + $this->userManager->expects(self::once()) |
|
103 | + ->method('get') |
|
104 | + ->with('user') |
|
105 | + ->willReturn($user); |
|
106 | + $this->eventDispatcher->expects(self::once()) |
|
107 | + ->method('dispatchTyped') |
|
108 | + ->with(self::callback(static function ($event): bool { |
|
109 | + self::assertInstanceOf(OutOfOfficeEndedEvent::class, $event); |
|
110 | + return true; |
|
111 | + })); |
|
112 | + |
|
113 | + $this->job->run([ |
|
114 | + 'id' => 1, |
|
115 | + 'event' => OutOfOfficeEventDispatcherJob::EVENT_END, |
|
116 | + ]); |
|
117 | + } |
|
118 | + |
|
119 | + public function testDoesntDispatchUnknownEvent(): void { |
|
120 | + $this->timezoneService->method('getUserTimezone')->with('user')->willReturn('Europe/Berlin'); |
|
121 | + |
|
122 | + $absence = new Absence(); |
|
123 | + $absence->setId(100); |
|
124 | + $absence->setUserId('user'); |
|
125 | + |
|
126 | + $user = $this->createMock(IUser::class); |
|
127 | + $user->method('getUID') |
|
128 | + ->willReturn('user'); |
|
129 | + |
|
130 | + $this->absenceMapper->expects(self::once()) |
|
131 | + ->method('findById') |
|
132 | + ->with(1) |
|
133 | + ->willReturn($absence); |
|
134 | + $this->userManager->expects(self::once()) |
|
135 | + ->method('get') |
|
136 | + ->with('user') |
|
137 | + ->willReturn($user); |
|
138 | + $this->eventDispatcher->expects(self::never()) |
|
139 | + ->method('dispatchTyped'); |
|
140 | + $this->logger->expects(self::once()) |
|
141 | + ->method('error'); |
|
142 | + |
|
143 | + $this->job->run([ |
|
144 | + 'id' => 1, |
|
145 | + 'event' => 'foobar', |
|
146 | + ]); |
|
147 | + } |
|
148 | 148 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | private LoggerInterface&MockObject $logger; |
31 | 31 | private IEventDispatcher&MockObject $eventDispatcher; |
32 | 32 | private IUserManager&MockObject $userManager; |
33 | - private MockObject|TimezoneService $timezoneService; |
|
33 | + private MockObject | TimezoneService $timezoneService; |
|
34 | 34 | |
35 | 35 | protected function setUp(): void { |
36 | 36 | parent::setUp(); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | ->willReturn($user); |
74 | 74 | $this->eventDispatcher->expects(self::once()) |
75 | 75 | ->method('dispatchTyped') |
76 | - ->with(self::callback(static function ($event): bool { |
|
76 | + ->with(self::callback(static function($event): bool { |
|
77 | 77 | self::assertInstanceOf(OutOfOfficeStartedEvent::class, $event); |
78 | 78 | return true; |
79 | 79 | })); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | ->willReturn($user); |
106 | 106 | $this->eventDispatcher->expects(self::once()) |
107 | 107 | ->method('dispatchTyped') |
108 | - ->with(self::callback(static function ($event): bool { |
|
108 | + ->with(self::callback(static function($event): bool { |
|
109 | 109 | self::assertInstanceOf(OutOfOfficeEndedEvent::class, $event); |
110 | 110 | return true; |
111 | 111 | })); |