Completed
Push — master ( 158b3e...c62fa5 )
by Joas
29:53 queued 14s
created
apps/comments/tests/Unit/Notification/NotifierTest.php 1 patch
Indentation   +525 added lines, -525 removed lines patch added patch discarded remove patch
@@ -26,529 +26,529 @@
 block discarded – undo
26 26
 use Test\TestCase;
27 27
 
28 28
 class NotifierTest extends TestCase {
29
-	protected IFactory&MockObject $l10nFactory;
30
-	protected IL10N&MockObject $l;
31
-	protected IRootFolder&MockObject $folder;
32
-	protected ICommentsManager&MockObject $commentsManager;
33
-	protected IURLGenerator&MockObject $url;
34
-	protected IUserManager&MockObject $userManager;
35
-	protected INotification&MockObject $notification;
36
-	protected IComment&MockObject $comment;
37
-	protected Notifier $notifier;
38
-	protected string $lc = 'tlh_KX';
39
-
40
-	protected function setUp(): void {
41
-		parent::setUp();
42
-
43
-		$this->l10nFactory = $this->createMock(IFactory::class);
44
-		$this->folder = $this->createMock(IRootFolder::class);
45
-		$this->commentsManager = $this->createMock(ICommentsManager::class);
46
-		$this->url = $this->createMock(IURLGenerator::class);
47
-		$this->userManager = $this->createMock(IUserManager::class);
48
-
49
-		$this->notifier = new Notifier(
50
-			$this->l10nFactory,
51
-			$this->folder,
52
-			$this->commentsManager,
53
-			$this->url,
54
-			$this->userManager
55
-		);
56
-
57
-		$this->l = $this->createMock(IL10N::class);
58
-		$this->l->expects($this->any())
59
-			->method('t')
60
-			->willReturnCallback(function ($text, $parameters = []) {
61
-				return vsprintf($text, $parameters);
62
-			});
63
-
64
-		$this->notification = $this->createMock(INotification::class);
65
-		$this->comment = $this->createMock(IComment::class);
66
-	}
67
-
68
-	public function testPrepareSuccess(): void {
69
-		$fileName = 'Gre\'thor.odp';
70
-		$displayName = 'Huraga';
71
-
72
-		/** @var Node&MockObject $node */
73
-		$node = $this->createMock(Node::class);
74
-		$node
75
-			->expects($this->atLeastOnce())
76
-			->method('getName')
77
-			->willReturn($fileName);
78
-		$node
79
-			->expects($this->atLeastOnce())
80
-			->method('getPath')
81
-			->willReturn('/you/files/' . $fileName);
82
-
83
-		$userFolder = $this->createMock(Folder::class);
84
-		$this->folder->expects($this->once())
85
-			->method('getUserFolder')
86
-			->with('you')
87
-			->willReturn($userFolder);
88
-		$userFolder->expects($this->once())
89
-			->method('getById')
90
-			->with('678')
91
-			->willReturn([$node]);
92
-
93
-		$this->notification->expects($this->exactly(2))
94
-			->method('getUser')
95
-			->willReturn('you');
96
-		$this->notification
97
-			->expects($this->once())
98
-			->method('getApp')
99
-			->willReturn('comments');
100
-		$this->notification
101
-			->expects($this->once())
102
-			->method('getSubject')
103
-			->willReturn('mention');
104
-		$this->notification
105
-			->expects($this->once())
106
-			->method('getSubjectParameters')
107
-			->willReturn(['files', '678']);
108
-		$this->notification
109
-			->expects($this->never())
110
-			->method('setParsedSubject');
111
-		$this->notification
112
-			->expects($this->once())
113
-			->method('setRichSubject')
114
-			->with('{user} mentioned you in a comment on "{file}"', $this->anything())
115
-			->willReturnSelf();
116
-		$this->notification
117
-			->expects($this->once())
118
-			->method('setRichMessage')
119
-			->with('Hi {mention-user1}!', ['mention-user1' => ['type' => 'user', 'id' => 'you', 'name' => 'Your name']])
120
-			->willReturnSelf();
121
-		$this->notification
122
-			->expects($this->never())
123
-			->method('setParsedMessage');
124
-		$this->notification
125
-			->expects($this->once())
126
-			->method('setIcon')
127
-			->with('absolute-image-path')
128
-			->willReturnSelf();
129
-
130
-		$this->url->expects($this->once())
131
-			->method('imagePath')
132
-			->with('core', 'actions/comment.svg')
133
-			->willReturn('image-path');
134
-		$this->url->expects($this->once())
135
-			->method('getAbsoluteURL')
136
-			->with('image-path')
137
-			->willReturn('absolute-image-path');
138
-
139
-		$this->l10nFactory
140
-			->expects($this->once())
141
-			->method('get')
142
-			->willReturn($this->l);
143
-
144
-		$this->comment
145
-			->expects($this->any())
146
-			->method('getActorId')
147
-			->willReturn('huraga');
148
-		$this->comment
149
-			->expects($this->any())
150
-			->method('getActorType')
151
-			->willReturn('users');
152
-		$this->comment
153
-			->expects($this->any())
154
-			->method('getMessage')
155
-			->willReturn('Hi @you!');
156
-		$this->comment
157
-			->expects($this->any())
158
-			->method('getMentions')
159
-			->willReturn([['type' => 'user', 'id' => 'you']]);
160
-		$this->comment->expects($this->atLeastOnce())
161
-			->method('getId')
162
-			->willReturn('1234');
163
-
164
-		$this->commentsManager
165
-			->expects($this->once())
166
-			->method('get')
167
-			->willReturn($this->comment);
168
-		$this->commentsManager
169
-			->expects($this->once())
170
-			->method('resolveDisplayName')
171
-			->with('user', 'you')
172
-			->willReturn('Your name');
173
-
174
-		$this->userManager
175
-			->expects($this->exactly(2))
176
-			->method('getDisplayName')
177
-			->willReturnMap([
178
-				['huraga', $displayName],
179
-				['you', 'You'],
180
-			]);
181
-
182
-		$this->notifier->prepare($this->notification, $this->lc);
183
-	}
184
-
185
-	public function testPrepareSuccessDeletedUser(): void {
186
-		$fileName = 'Gre\'thor.odp';
187
-
188
-		/** @var Node|MockObject $node */
189
-		$node = $this->createMock(Node::class);
190
-		$node
191
-			->expects($this->atLeastOnce())
192
-			->method('getName')
193
-			->willReturn($fileName);
194
-		$node
195
-			->expects($this->atLeastOnce())
196
-			->method('getPath')
197
-			->willReturn('/you/files/' . $fileName);
198
-
199
-		$userFolder = $this->createMock(Folder::class);
200
-		$this->folder->expects($this->once())
201
-			->method('getUserFolder')
202
-			->with('you')
203
-			->willReturn($userFolder);
204
-		$userFolder->expects($this->once())
205
-			->method('getById')
206
-			->with('678')
207
-			->willReturn([$node]);
208
-
209
-		$this->notification->expects($this->exactly(2))
210
-			->method('getUser')
211
-			->willReturn('you');
212
-		$this->notification
213
-			->expects($this->once())
214
-			->method('getApp')
215
-			->willReturn('comments');
216
-		$this->notification
217
-			->expects($this->once())
218
-			->method('getSubject')
219
-			->willReturn('mention');
220
-		$this->notification
221
-			->expects($this->once())
222
-			->method('getSubjectParameters')
223
-			->willReturn(['files', '678']);
224
-		$this->notification
225
-			->expects($this->never())
226
-			->method('setParsedSubject');
227
-		$this->notification
228
-			->expects($this->once())
229
-			->method('setRichSubject')
230
-			->with('You were mentioned on "{file}", in a comment by an account that has since been deleted', $this->anything())
231
-			->willReturnSelf();
232
-		$this->notification
233
-			->expects($this->once())
234
-			->method('setRichMessage')
235
-			->with('Hi {mention-user1}!', ['mention-user1' => ['type' => 'user', 'id' => 'you', 'name' => 'Your name']])
236
-			->willReturnSelf();
237
-		$this->notification
238
-			->expects($this->never())
239
-			->method('setParsedMessage');
240
-		$this->notification
241
-			->expects($this->once())
242
-			->method('setIcon')
243
-			->with('absolute-image-path')
244
-			->willReturnSelf();
245
-
246
-		$this->url->expects($this->once())
247
-			->method('imagePath')
248
-			->with('core', 'actions/comment.svg')
249
-			->willReturn('image-path');
250
-		$this->url->expects($this->once())
251
-			->method('getAbsoluteURL')
252
-			->with('image-path')
253
-			->willReturn('absolute-image-path');
254
-
255
-		$this->l10nFactory
256
-			->expects($this->once())
257
-			->method('get')
258
-			->willReturn($this->l);
259
-
260
-		$this->comment
261
-			->expects($this->any())
262
-			->method('getActorId')
263
-			->willReturn('huraga');
264
-		$this->comment
265
-			->expects($this->any())
266
-			->method('getActorType')
267
-			->willReturn(ICommentsManager::DELETED_USER);
268
-		$this->comment
269
-			->expects($this->any())
270
-			->method('getMessage')
271
-			->willReturn('Hi @you!');
272
-		$this->comment
273
-			->expects($this->any())
274
-			->method('getMentions')
275
-			->willReturn([['type' => 'user', 'id' => 'you']]);
276
-
277
-		$this->commentsManager
278
-			->expects($this->once())
279
-			->method('get')
280
-			->willReturn($this->comment);
281
-		$this->commentsManager
282
-			->expects($this->once())
283
-			->method('resolveDisplayName')
284
-			->with('user', 'you')
285
-			->willReturn('Your name');
286
-
287
-		$this->userManager
288
-			->expects($this->once())
289
-			->method('getDisplayName')
290
-			->willReturnMap([
291
-				['huraga', null],
292
-				['you', 'You'],
293
-			]);
294
-
295
-		$this->notifier->prepare($this->notification, $this->lc);
296
-	}
297
-
298
-
299
-	public function testPrepareDifferentApp(): void {
300
-		$this->expectException(UnknownNotificationException::class);
301
-
302
-		$this->folder
303
-			->expects($this->never())
304
-			->method('getById');
305
-
306
-		$this->notification
307
-			->expects($this->once())
308
-			->method('getApp')
309
-			->willReturn('constructions');
310
-		$this->notification
311
-			->expects($this->never())
312
-			->method('getSubject');
313
-		$this->notification
314
-			->expects($this->never())
315
-			->method('getSubjectParameters');
316
-		$this->notification
317
-			->expects($this->never())
318
-			->method('setParsedSubject');
319
-
320
-		$this->l10nFactory
321
-			->expects($this->never())
322
-			->method('get');
323
-
324
-		$this->commentsManager
325
-			->expects($this->never())
326
-			->method('get');
327
-
328
-		$this->userManager
329
-			->expects($this->never())
330
-			->method('getDisplayName');
331
-
332
-		$this->notifier->prepare($this->notification, $this->lc);
333
-	}
334
-
335
-
336
-	public function testPrepareNotFound(): void {
337
-		$this->expectException(UnknownNotificationException::class);
338
-
339
-		$this->folder
340
-			->expects($this->never())
341
-			->method('getById');
342
-
343
-		$this->notification
344
-			->expects($this->once())
345
-			->method('getApp')
346
-			->willReturn('comments');
347
-		$this->notification
348
-			->expects($this->never())
349
-			->method('getSubject');
350
-		$this->notification
351
-			->expects($this->never())
352
-			->method('getSubjectParameters');
353
-		$this->notification
354
-			->expects($this->never())
355
-			->method('setParsedSubject');
356
-
357
-		$this->l10nFactory
358
-			->expects($this->never())
359
-			->method('get');
360
-
361
-		$this->commentsManager
362
-			->expects($this->once())
363
-			->method('get')
364
-			->willThrowException(new NotFoundException());
365
-
366
-		$this->userManager
367
-			->expects($this->never())
368
-			->method('getDisplayName');
369
-
370
-		$this->notifier->prepare($this->notification, $this->lc);
371
-	}
372
-
373
-
374
-	public function testPrepareDifferentSubject(): void {
375
-		$this->expectException(UnknownNotificationException::class);
376
-
377
-		$displayName = 'Huraga';
378
-
379
-		$this->folder
380
-			->expects($this->never())
381
-			->method('getById');
382
-
383
-		$this->notification
384
-			->expects($this->once())
385
-			->method('getApp')
386
-			->willReturn('comments');
387
-		$this->notification
388
-			->expects($this->once())
389
-			->method('getSubject')
390
-			->willReturn('unlike');
391
-		$this->notification
392
-			->expects($this->never())
393
-			->method('getSubjectParameters');
394
-		$this->notification
395
-			->expects($this->never())
396
-			->method('setParsedSubject');
397
-
398
-		$this->l
399
-			->expects($this->never())
400
-			->method('t');
401
-
402
-		$this->l10nFactory
403
-			->expects($this->once())
404
-			->method('get')
405
-			->willReturn($this->l);
406
-
407
-		$this->comment
408
-			->expects($this->any())
409
-			->method('getActorId')
410
-			->willReturn('huraga');
411
-		$this->comment
412
-			->expects($this->any())
413
-			->method('getActorType')
414
-			->willReturn('users');
415
-
416
-		$this->commentsManager
417
-			->expects($this->once())
418
-			->method('get')
419
-			->willReturn($this->comment);
420
-
421
-		$this->userManager
422
-			->expects($this->once())
423
-			->method('getDisplayName')
424
-			->with('huraga')
425
-			->willReturn($displayName);
426
-
427
-		$this->notifier->prepare($this->notification, $this->lc);
428
-	}
429
-
430
-
431
-	public function testPrepareNotFiles(): void {
432
-		$this->expectException(UnknownNotificationException::class);
433
-
434
-		$displayName = 'Huraga';
435
-
436
-		$this->folder
437
-			->expects($this->never())
438
-			->method('getById');
439
-
440
-		$this->notification
441
-			->expects($this->once())
442
-			->method('getApp')
443
-			->willReturn('comments');
444
-		$this->notification
445
-			->expects($this->once())
446
-			->method('getSubject')
447
-			->willReturn('mention');
448
-		$this->notification
449
-			->expects($this->once())
450
-			->method('getSubjectParameters')
451
-			->willReturn(['ships', '678']);
452
-		$this->notification
453
-			->expects($this->never())
454
-			->method('setParsedSubject');
455
-
456
-		$this->l
457
-			->expects($this->never())
458
-			->method('t');
459
-
460
-		$this->l10nFactory
461
-			->expects($this->once())
462
-			->method('get')
463
-			->willReturn($this->l);
464
-
465
-		$this->comment
466
-			->expects($this->any())
467
-			->method('getActorId')
468
-			->willReturn('huraga');
469
-		$this->comment
470
-			->expects($this->any())
471
-			->method('getActorType')
472
-			->willReturn('users');
473
-
474
-		$this->commentsManager
475
-			->expects($this->once())
476
-			->method('get')
477
-			->willReturn($this->comment);
478
-
479
-		$this->userManager
480
-			->expects($this->once())
481
-			->method('getDisplayName')
482
-			->with('huraga')
483
-			->willReturn($displayName);
484
-
485
-		$this->notifier->prepare($this->notification, $this->lc);
486
-	}
487
-
488
-
489
-	public function testPrepareUnresolvableFileID(): void {
490
-		$this->expectException(AlreadyProcessedException::class);
491
-
492
-		$displayName = 'Huraga';
493
-
494
-		$userFolder = $this->createMock(Folder::class);
495
-		$this->folder->expects($this->once())
496
-			->method('getUserFolder')
497
-			->with('you')
498
-			->willReturn($userFolder);
499
-		$userFolder->expects($this->once())
500
-			->method('getById')
501
-			->with('678')
502
-			->willReturn([]);
503
-
504
-		$this->notification->expects($this->once())
505
-			->method('getUser')
506
-			->willReturn('you');
507
-		$this->notification
508
-			->expects($this->once())
509
-			->method('getApp')
510
-			->willReturn('comments');
511
-		$this->notification
512
-			->expects($this->once())
513
-			->method('getSubject')
514
-			->willReturn('mention');
515
-		$this->notification
516
-			->expects($this->once())
517
-			->method('getSubjectParameters')
518
-			->willReturn(['files', '678']);
519
-		$this->notification
520
-			->expects($this->never())
521
-			->method('setParsedSubject');
522
-
523
-		$this->l
524
-			->expects($this->never())
525
-			->method('t');
526
-
527
-		$this->l10nFactory
528
-			->expects($this->once())
529
-			->method('get')
530
-			->willReturn($this->l);
531
-
532
-		$this->comment
533
-			->expects($this->any())
534
-			->method('getActorId')
535
-			->willReturn('huraga');
536
-		$this->comment
537
-			->expects($this->any())
538
-			->method('getActorType')
539
-			->willReturn('users');
540
-
541
-		$this->commentsManager
542
-			->expects($this->once())
543
-			->method('get')
544
-			->willReturn($this->comment);
545
-
546
-		$this->userManager
547
-			->expects($this->once())
548
-			->method('getDisplayName')
549
-			->with('huraga')
550
-			->willReturn($displayName);
551
-
552
-		$this->notifier->prepare($this->notification, $this->lc);
553
-	}
29
+    protected IFactory&MockObject $l10nFactory;
30
+    protected IL10N&MockObject $l;
31
+    protected IRootFolder&MockObject $folder;
32
+    protected ICommentsManager&MockObject $commentsManager;
33
+    protected IURLGenerator&MockObject $url;
34
+    protected IUserManager&MockObject $userManager;
35
+    protected INotification&MockObject $notification;
36
+    protected IComment&MockObject $comment;
37
+    protected Notifier $notifier;
38
+    protected string $lc = 'tlh_KX';
39
+
40
+    protected function setUp(): void {
41
+        parent::setUp();
42
+
43
+        $this->l10nFactory = $this->createMock(IFactory::class);
44
+        $this->folder = $this->createMock(IRootFolder::class);
45
+        $this->commentsManager = $this->createMock(ICommentsManager::class);
46
+        $this->url = $this->createMock(IURLGenerator::class);
47
+        $this->userManager = $this->createMock(IUserManager::class);
48
+
49
+        $this->notifier = new Notifier(
50
+            $this->l10nFactory,
51
+            $this->folder,
52
+            $this->commentsManager,
53
+            $this->url,
54
+            $this->userManager
55
+        );
56
+
57
+        $this->l = $this->createMock(IL10N::class);
58
+        $this->l->expects($this->any())
59
+            ->method('t')
60
+            ->willReturnCallback(function ($text, $parameters = []) {
61
+                return vsprintf($text, $parameters);
62
+            });
63
+
64
+        $this->notification = $this->createMock(INotification::class);
65
+        $this->comment = $this->createMock(IComment::class);
66
+    }
67
+
68
+    public function testPrepareSuccess(): void {
69
+        $fileName = 'Gre\'thor.odp';
70
+        $displayName = 'Huraga';
71
+
72
+        /** @var Node&MockObject $node */
73
+        $node = $this->createMock(Node::class);
74
+        $node
75
+            ->expects($this->atLeastOnce())
76
+            ->method('getName')
77
+            ->willReturn($fileName);
78
+        $node
79
+            ->expects($this->atLeastOnce())
80
+            ->method('getPath')
81
+            ->willReturn('/you/files/' . $fileName);
82
+
83
+        $userFolder = $this->createMock(Folder::class);
84
+        $this->folder->expects($this->once())
85
+            ->method('getUserFolder')
86
+            ->with('you')
87
+            ->willReturn($userFolder);
88
+        $userFolder->expects($this->once())
89
+            ->method('getById')
90
+            ->with('678')
91
+            ->willReturn([$node]);
92
+
93
+        $this->notification->expects($this->exactly(2))
94
+            ->method('getUser')
95
+            ->willReturn('you');
96
+        $this->notification
97
+            ->expects($this->once())
98
+            ->method('getApp')
99
+            ->willReturn('comments');
100
+        $this->notification
101
+            ->expects($this->once())
102
+            ->method('getSubject')
103
+            ->willReturn('mention');
104
+        $this->notification
105
+            ->expects($this->once())
106
+            ->method('getSubjectParameters')
107
+            ->willReturn(['files', '678']);
108
+        $this->notification
109
+            ->expects($this->never())
110
+            ->method('setParsedSubject');
111
+        $this->notification
112
+            ->expects($this->once())
113
+            ->method('setRichSubject')
114
+            ->with('{user} mentioned you in a comment on "{file}"', $this->anything())
115
+            ->willReturnSelf();
116
+        $this->notification
117
+            ->expects($this->once())
118
+            ->method('setRichMessage')
119
+            ->with('Hi {mention-user1}!', ['mention-user1' => ['type' => 'user', 'id' => 'you', 'name' => 'Your name']])
120
+            ->willReturnSelf();
121
+        $this->notification
122
+            ->expects($this->never())
123
+            ->method('setParsedMessage');
124
+        $this->notification
125
+            ->expects($this->once())
126
+            ->method('setIcon')
127
+            ->with('absolute-image-path')
128
+            ->willReturnSelf();
129
+
130
+        $this->url->expects($this->once())
131
+            ->method('imagePath')
132
+            ->with('core', 'actions/comment.svg')
133
+            ->willReturn('image-path');
134
+        $this->url->expects($this->once())
135
+            ->method('getAbsoluteURL')
136
+            ->with('image-path')
137
+            ->willReturn('absolute-image-path');
138
+
139
+        $this->l10nFactory
140
+            ->expects($this->once())
141
+            ->method('get')
142
+            ->willReturn($this->l);
143
+
144
+        $this->comment
145
+            ->expects($this->any())
146
+            ->method('getActorId')
147
+            ->willReturn('huraga');
148
+        $this->comment
149
+            ->expects($this->any())
150
+            ->method('getActorType')
151
+            ->willReturn('users');
152
+        $this->comment
153
+            ->expects($this->any())
154
+            ->method('getMessage')
155
+            ->willReturn('Hi @you!');
156
+        $this->comment
157
+            ->expects($this->any())
158
+            ->method('getMentions')
159
+            ->willReturn([['type' => 'user', 'id' => 'you']]);
160
+        $this->comment->expects($this->atLeastOnce())
161
+            ->method('getId')
162
+            ->willReturn('1234');
163
+
164
+        $this->commentsManager
165
+            ->expects($this->once())
166
+            ->method('get')
167
+            ->willReturn($this->comment);
168
+        $this->commentsManager
169
+            ->expects($this->once())
170
+            ->method('resolveDisplayName')
171
+            ->with('user', 'you')
172
+            ->willReturn('Your name');
173
+
174
+        $this->userManager
175
+            ->expects($this->exactly(2))
176
+            ->method('getDisplayName')
177
+            ->willReturnMap([
178
+                ['huraga', $displayName],
179
+                ['you', 'You'],
180
+            ]);
181
+
182
+        $this->notifier->prepare($this->notification, $this->lc);
183
+    }
184
+
185
+    public function testPrepareSuccessDeletedUser(): void {
186
+        $fileName = 'Gre\'thor.odp';
187
+
188
+        /** @var Node|MockObject $node */
189
+        $node = $this->createMock(Node::class);
190
+        $node
191
+            ->expects($this->atLeastOnce())
192
+            ->method('getName')
193
+            ->willReturn($fileName);
194
+        $node
195
+            ->expects($this->atLeastOnce())
196
+            ->method('getPath')
197
+            ->willReturn('/you/files/' . $fileName);
198
+
199
+        $userFolder = $this->createMock(Folder::class);
200
+        $this->folder->expects($this->once())
201
+            ->method('getUserFolder')
202
+            ->with('you')
203
+            ->willReturn($userFolder);
204
+        $userFolder->expects($this->once())
205
+            ->method('getById')
206
+            ->with('678')
207
+            ->willReturn([$node]);
208
+
209
+        $this->notification->expects($this->exactly(2))
210
+            ->method('getUser')
211
+            ->willReturn('you');
212
+        $this->notification
213
+            ->expects($this->once())
214
+            ->method('getApp')
215
+            ->willReturn('comments');
216
+        $this->notification
217
+            ->expects($this->once())
218
+            ->method('getSubject')
219
+            ->willReturn('mention');
220
+        $this->notification
221
+            ->expects($this->once())
222
+            ->method('getSubjectParameters')
223
+            ->willReturn(['files', '678']);
224
+        $this->notification
225
+            ->expects($this->never())
226
+            ->method('setParsedSubject');
227
+        $this->notification
228
+            ->expects($this->once())
229
+            ->method('setRichSubject')
230
+            ->with('You were mentioned on "{file}", in a comment by an account that has since been deleted', $this->anything())
231
+            ->willReturnSelf();
232
+        $this->notification
233
+            ->expects($this->once())
234
+            ->method('setRichMessage')
235
+            ->with('Hi {mention-user1}!', ['mention-user1' => ['type' => 'user', 'id' => 'you', 'name' => 'Your name']])
236
+            ->willReturnSelf();
237
+        $this->notification
238
+            ->expects($this->never())
239
+            ->method('setParsedMessage');
240
+        $this->notification
241
+            ->expects($this->once())
242
+            ->method('setIcon')
243
+            ->with('absolute-image-path')
244
+            ->willReturnSelf();
245
+
246
+        $this->url->expects($this->once())
247
+            ->method('imagePath')
248
+            ->with('core', 'actions/comment.svg')
249
+            ->willReturn('image-path');
250
+        $this->url->expects($this->once())
251
+            ->method('getAbsoluteURL')
252
+            ->with('image-path')
253
+            ->willReturn('absolute-image-path');
254
+
255
+        $this->l10nFactory
256
+            ->expects($this->once())
257
+            ->method('get')
258
+            ->willReturn($this->l);
259
+
260
+        $this->comment
261
+            ->expects($this->any())
262
+            ->method('getActorId')
263
+            ->willReturn('huraga');
264
+        $this->comment
265
+            ->expects($this->any())
266
+            ->method('getActorType')
267
+            ->willReturn(ICommentsManager::DELETED_USER);
268
+        $this->comment
269
+            ->expects($this->any())
270
+            ->method('getMessage')
271
+            ->willReturn('Hi @you!');
272
+        $this->comment
273
+            ->expects($this->any())
274
+            ->method('getMentions')
275
+            ->willReturn([['type' => 'user', 'id' => 'you']]);
276
+
277
+        $this->commentsManager
278
+            ->expects($this->once())
279
+            ->method('get')
280
+            ->willReturn($this->comment);
281
+        $this->commentsManager
282
+            ->expects($this->once())
283
+            ->method('resolveDisplayName')
284
+            ->with('user', 'you')
285
+            ->willReturn('Your name');
286
+
287
+        $this->userManager
288
+            ->expects($this->once())
289
+            ->method('getDisplayName')
290
+            ->willReturnMap([
291
+                ['huraga', null],
292
+                ['you', 'You'],
293
+            ]);
294
+
295
+        $this->notifier->prepare($this->notification, $this->lc);
296
+    }
297
+
298
+
299
+    public function testPrepareDifferentApp(): void {
300
+        $this->expectException(UnknownNotificationException::class);
301
+
302
+        $this->folder
303
+            ->expects($this->never())
304
+            ->method('getById');
305
+
306
+        $this->notification
307
+            ->expects($this->once())
308
+            ->method('getApp')
309
+            ->willReturn('constructions');
310
+        $this->notification
311
+            ->expects($this->never())
312
+            ->method('getSubject');
313
+        $this->notification
314
+            ->expects($this->never())
315
+            ->method('getSubjectParameters');
316
+        $this->notification
317
+            ->expects($this->never())
318
+            ->method('setParsedSubject');
319
+
320
+        $this->l10nFactory
321
+            ->expects($this->never())
322
+            ->method('get');
323
+
324
+        $this->commentsManager
325
+            ->expects($this->never())
326
+            ->method('get');
327
+
328
+        $this->userManager
329
+            ->expects($this->never())
330
+            ->method('getDisplayName');
331
+
332
+        $this->notifier->prepare($this->notification, $this->lc);
333
+    }
334
+
335
+
336
+    public function testPrepareNotFound(): void {
337
+        $this->expectException(UnknownNotificationException::class);
338
+
339
+        $this->folder
340
+            ->expects($this->never())
341
+            ->method('getById');
342
+
343
+        $this->notification
344
+            ->expects($this->once())
345
+            ->method('getApp')
346
+            ->willReturn('comments');
347
+        $this->notification
348
+            ->expects($this->never())
349
+            ->method('getSubject');
350
+        $this->notification
351
+            ->expects($this->never())
352
+            ->method('getSubjectParameters');
353
+        $this->notification
354
+            ->expects($this->never())
355
+            ->method('setParsedSubject');
356
+
357
+        $this->l10nFactory
358
+            ->expects($this->never())
359
+            ->method('get');
360
+
361
+        $this->commentsManager
362
+            ->expects($this->once())
363
+            ->method('get')
364
+            ->willThrowException(new NotFoundException());
365
+
366
+        $this->userManager
367
+            ->expects($this->never())
368
+            ->method('getDisplayName');
369
+
370
+        $this->notifier->prepare($this->notification, $this->lc);
371
+    }
372
+
373
+
374
+    public function testPrepareDifferentSubject(): void {
375
+        $this->expectException(UnknownNotificationException::class);
376
+
377
+        $displayName = 'Huraga';
378
+
379
+        $this->folder
380
+            ->expects($this->never())
381
+            ->method('getById');
382
+
383
+        $this->notification
384
+            ->expects($this->once())
385
+            ->method('getApp')
386
+            ->willReturn('comments');
387
+        $this->notification
388
+            ->expects($this->once())
389
+            ->method('getSubject')
390
+            ->willReturn('unlike');
391
+        $this->notification
392
+            ->expects($this->never())
393
+            ->method('getSubjectParameters');
394
+        $this->notification
395
+            ->expects($this->never())
396
+            ->method('setParsedSubject');
397
+
398
+        $this->l
399
+            ->expects($this->never())
400
+            ->method('t');
401
+
402
+        $this->l10nFactory
403
+            ->expects($this->once())
404
+            ->method('get')
405
+            ->willReturn($this->l);
406
+
407
+        $this->comment
408
+            ->expects($this->any())
409
+            ->method('getActorId')
410
+            ->willReturn('huraga');
411
+        $this->comment
412
+            ->expects($this->any())
413
+            ->method('getActorType')
414
+            ->willReturn('users');
415
+
416
+        $this->commentsManager
417
+            ->expects($this->once())
418
+            ->method('get')
419
+            ->willReturn($this->comment);
420
+
421
+        $this->userManager
422
+            ->expects($this->once())
423
+            ->method('getDisplayName')
424
+            ->with('huraga')
425
+            ->willReturn($displayName);
426
+
427
+        $this->notifier->prepare($this->notification, $this->lc);
428
+    }
429
+
430
+
431
+    public function testPrepareNotFiles(): void {
432
+        $this->expectException(UnknownNotificationException::class);
433
+
434
+        $displayName = 'Huraga';
435
+
436
+        $this->folder
437
+            ->expects($this->never())
438
+            ->method('getById');
439
+
440
+        $this->notification
441
+            ->expects($this->once())
442
+            ->method('getApp')
443
+            ->willReturn('comments');
444
+        $this->notification
445
+            ->expects($this->once())
446
+            ->method('getSubject')
447
+            ->willReturn('mention');
448
+        $this->notification
449
+            ->expects($this->once())
450
+            ->method('getSubjectParameters')
451
+            ->willReturn(['ships', '678']);
452
+        $this->notification
453
+            ->expects($this->never())
454
+            ->method('setParsedSubject');
455
+
456
+        $this->l
457
+            ->expects($this->never())
458
+            ->method('t');
459
+
460
+        $this->l10nFactory
461
+            ->expects($this->once())
462
+            ->method('get')
463
+            ->willReturn($this->l);
464
+
465
+        $this->comment
466
+            ->expects($this->any())
467
+            ->method('getActorId')
468
+            ->willReturn('huraga');
469
+        $this->comment
470
+            ->expects($this->any())
471
+            ->method('getActorType')
472
+            ->willReturn('users');
473
+
474
+        $this->commentsManager
475
+            ->expects($this->once())
476
+            ->method('get')
477
+            ->willReturn($this->comment);
478
+
479
+        $this->userManager
480
+            ->expects($this->once())
481
+            ->method('getDisplayName')
482
+            ->with('huraga')
483
+            ->willReturn($displayName);
484
+
485
+        $this->notifier->prepare($this->notification, $this->lc);
486
+    }
487
+
488
+
489
+    public function testPrepareUnresolvableFileID(): void {
490
+        $this->expectException(AlreadyProcessedException::class);
491
+
492
+        $displayName = 'Huraga';
493
+
494
+        $userFolder = $this->createMock(Folder::class);
495
+        $this->folder->expects($this->once())
496
+            ->method('getUserFolder')
497
+            ->with('you')
498
+            ->willReturn($userFolder);
499
+        $userFolder->expects($this->once())
500
+            ->method('getById')
501
+            ->with('678')
502
+            ->willReturn([]);
503
+
504
+        $this->notification->expects($this->once())
505
+            ->method('getUser')
506
+            ->willReturn('you');
507
+        $this->notification
508
+            ->expects($this->once())
509
+            ->method('getApp')
510
+            ->willReturn('comments');
511
+        $this->notification
512
+            ->expects($this->once())
513
+            ->method('getSubject')
514
+            ->willReturn('mention');
515
+        $this->notification
516
+            ->expects($this->once())
517
+            ->method('getSubjectParameters')
518
+            ->willReturn(['files', '678']);
519
+        $this->notification
520
+            ->expects($this->never())
521
+            ->method('setParsedSubject');
522
+
523
+        $this->l
524
+            ->expects($this->never())
525
+            ->method('t');
526
+
527
+        $this->l10nFactory
528
+            ->expects($this->once())
529
+            ->method('get')
530
+            ->willReturn($this->l);
531
+
532
+        $this->comment
533
+            ->expects($this->any())
534
+            ->method('getActorId')
535
+            ->willReturn('huraga');
536
+        $this->comment
537
+            ->expects($this->any())
538
+            ->method('getActorType')
539
+            ->willReturn('users');
540
+
541
+        $this->commentsManager
542
+            ->expects($this->once())
543
+            ->method('get')
544
+            ->willReturn($this->comment);
545
+
546
+        $this->userManager
547
+            ->expects($this->once())
548
+            ->method('getDisplayName')
549
+            ->with('huraga')
550
+            ->willReturn($displayName);
551
+
552
+        $this->notifier->prepare($this->notification, $this->lc);
553
+    }
554 554
 }
Please login to merge, or discard this patch.
apps/comments/tests/Unit/Activity/ListenerTest.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -27,133 +27,133 @@
 block discarded – undo
27 27
 use Test\TestCase;
28 28
 
29 29
 class ListenerTest extends TestCase {
30
-	protected IManager&MockObject $activityManager;
31
-	protected IUserSession&MockObject $session;
32
-	protected IAppManager&MockObject $appManager;
33
-	protected IMountProviderCollection&MockObject $mountProviderCollection;
34
-	protected IRootFolder&MockObject $rootFolder;
35
-	protected IShareHelper&MockObject $shareHelper;
36
-	protected Listener $listener;
37
-
38
-	protected function setUp(): void {
39
-		parent::setUp();
40
-
41
-		$this->activityManager = $this->createMock(IManager::class);
42
-		$this->session = $this->createMock(IUserSession::class);
43
-		$this->appManager = $this->createMock(IAppManager::class);
44
-		$this->mountProviderCollection = $this->createMock(IMountProviderCollection::class);
45
-		$this->rootFolder = $this->createMock(IRootFolder::class);
46
-		$this->shareHelper = $this->createMock(IShareHelper::class);
47
-
48
-		$this->listener = new Listener(
49
-			$this->activityManager,
50
-			$this->session,
51
-			$this->appManager,
52
-			$this->mountProviderCollection,
53
-			$this->rootFolder,
54
-			$this->shareHelper
55
-		);
56
-	}
57
-
58
-	public function testCommentEvent(): void {
59
-		$this->appManager->expects($this->any())
60
-			->method('isEnabledForAnyone')
61
-			->with('activity')
62
-			->willReturn(true);
63
-
64
-		$comment = $this->createMock(IComment::class);
65
-		$comment->expects($this->any())
66
-			->method('getObjectType')
67
-			->willReturn('files');
68
-
69
-		/** @var CommentsEvent|MockObject $event */
70
-		$event = $this->createMock(CommentsEvent::class);
71
-		$event->expects($this->any())
72
-			->method('getComment')
73
-			->willReturn($comment);
74
-		$event->expects($this->any())
75
-			->method('getEvent')
76
-			->willReturn(CommentsEvent::EVENT_ADD);
77
-
78
-		/** @var IUser|MockObject $ownerUser */
79
-		$ownerUser = $this->createMock(IUser::class);
80
-		$ownerUser->expects($this->any())
81
-			->method('getUID')
82
-			->willReturn('937393');
83
-
84
-		/** @var MockObject $mount */
85
-		$mount = $this->createMock(ICachedMountFileInfo::class);
86
-		$mount->expects($this->any())
87
-			->method('getUser')
88
-			->willReturn($ownerUser); // perhaps not the right user, but does not matter in this scenario
89
-
90
-		$mounts = [ $mount, $mount ]; // to make sure duplicates are dealt with
91
-
92
-		$userMountCache = $this->createMock(IUserMountCache::class);
93
-		$userMountCache->expects($this->any())
94
-			->method('getMountsForFileId')
95
-			->willReturn($mounts);
96
-
97
-		$this->mountProviderCollection->expects($this->any())
98
-			->method('getMountCache')
99
-			->willReturn($userMountCache);
100
-
101
-		$node = $this->createMock(Node::class);
102
-		$nodes = [ $node ];
103
-
104
-		$ownerFolder = $this->createMock(Folder::class);
105
-		$ownerFolder->expects($this->any())
106
-			->method('getById')
107
-			->willReturn($nodes);
108
-
109
-		$this->rootFolder->expects($this->any())
110
-			->method('getUserFolder')
111
-			->willReturn($ownerFolder);
112
-
113
-		$al = [ 'users' => [
114
-			'873304' => 'i/got/it/here',
115
-			'254342' => 'there/i/have/it',
116
-			'sandra' => 'and/here/i/placed/it'
117
-		]];
118
-		$this->shareHelper->expects($this->any())
119
-			->method('getPathsForAccessList')
120
-			->willReturn($al);
121
-
122
-		$this->session->expects($this->any())
123
-			->method('getUser')
124
-			->willReturn($ownerUser);
125
-
126
-		/** @var MockObject $activity */
127
-		$activity = $this->createMock(IEvent::class);
128
-		$activity->expects($this->exactly(count($al['users'])))
129
-			->method('setAffectedUser');
130
-		$activity->expects($this->once())
131
-			->method('setApp')
132
-			->with('comments')
133
-			->willReturnSelf();
134
-		$activity->expects($this->once())
135
-			->method('setType')
136
-			->with('comments')
137
-			->willReturnSelf();
138
-		$activity->expects($this->once())
139
-			->method('setAuthor')
140
-			->with($ownerUser->getUID())
141
-			->willReturnSelf();
142
-		$activity->expects($this->once())
143
-			->method('setObject')
144
-			->with('files', $this->anything())
145
-			->willReturnSelf();
146
-		$activity->expects($this->once())
147
-			->method('setMessage')
148
-			->with('add_comment_message', $this->anything())
149
-			->willReturnSelf();
150
-
151
-		$this->activityManager->expects($this->once())
152
-			->method('generateEvent')
153
-			->willReturn($activity);
154
-		$this->activityManager->expects($this->exactly(count($al['users'])))
155
-			->method('publish');
156
-
157
-		$this->listener->commentEvent($event);
158
-	}
30
+    protected IManager&MockObject $activityManager;
31
+    protected IUserSession&MockObject $session;
32
+    protected IAppManager&MockObject $appManager;
33
+    protected IMountProviderCollection&MockObject $mountProviderCollection;
34
+    protected IRootFolder&MockObject $rootFolder;
35
+    protected IShareHelper&MockObject $shareHelper;
36
+    protected Listener $listener;
37
+
38
+    protected function setUp(): void {
39
+        parent::setUp();
40
+
41
+        $this->activityManager = $this->createMock(IManager::class);
42
+        $this->session = $this->createMock(IUserSession::class);
43
+        $this->appManager = $this->createMock(IAppManager::class);
44
+        $this->mountProviderCollection = $this->createMock(IMountProviderCollection::class);
45
+        $this->rootFolder = $this->createMock(IRootFolder::class);
46
+        $this->shareHelper = $this->createMock(IShareHelper::class);
47
+
48
+        $this->listener = new Listener(
49
+            $this->activityManager,
50
+            $this->session,
51
+            $this->appManager,
52
+            $this->mountProviderCollection,
53
+            $this->rootFolder,
54
+            $this->shareHelper
55
+        );
56
+    }
57
+
58
+    public function testCommentEvent(): void {
59
+        $this->appManager->expects($this->any())
60
+            ->method('isEnabledForAnyone')
61
+            ->with('activity')
62
+            ->willReturn(true);
63
+
64
+        $comment = $this->createMock(IComment::class);
65
+        $comment->expects($this->any())
66
+            ->method('getObjectType')
67
+            ->willReturn('files');
68
+
69
+        /** @var CommentsEvent|MockObject $event */
70
+        $event = $this->createMock(CommentsEvent::class);
71
+        $event->expects($this->any())
72
+            ->method('getComment')
73
+            ->willReturn($comment);
74
+        $event->expects($this->any())
75
+            ->method('getEvent')
76
+            ->willReturn(CommentsEvent::EVENT_ADD);
77
+
78
+        /** @var IUser|MockObject $ownerUser */
79
+        $ownerUser = $this->createMock(IUser::class);
80
+        $ownerUser->expects($this->any())
81
+            ->method('getUID')
82
+            ->willReturn('937393');
83
+
84
+        /** @var MockObject $mount */
85
+        $mount = $this->createMock(ICachedMountFileInfo::class);
86
+        $mount->expects($this->any())
87
+            ->method('getUser')
88
+            ->willReturn($ownerUser); // perhaps not the right user, but does not matter in this scenario
89
+
90
+        $mounts = [ $mount, $mount ]; // to make sure duplicates are dealt with
91
+
92
+        $userMountCache = $this->createMock(IUserMountCache::class);
93
+        $userMountCache->expects($this->any())
94
+            ->method('getMountsForFileId')
95
+            ->willReturn($mounts);
96
+
97
+        $this->mountProviderCollection->expects($this->any())
98
+            ->method('getMountCache')
99
+            ->willReturn($userMountCache);
100
+
101
+        $node = $this->createMock(Node::class);
102
+        $nodes = [ $node ];
103
+
104
+        $ownerFolder = $this->createMock(Folder::class);
105
+        $ownerFolder->expects($this->any())
106
+            ->method('getById')
107
+            ->willReturn($nodes);
108
+
109
+        $this->rootFolder->expects($this->any())
110
+            ->method('getUserFolder')
111
+            ->willReturn($ownerFolder);
112
+
113
+        $al = [ 'users' => [
114
+            '873304' => 'i/got/it/here',
115
+            '254342' => 'there/i/have/it',
116
+            'sandra' => 'and/here/i/placed/it'
117
+        ]];
118
+        $this->shareHelper->expects($this->any())
119
+            ->method('getPathsForAccessList')
120
+            ->willReturn($al);
121
+
122
+        $this->session->expects($this->any())
123
+            ->method('getUser')
124
+            ->willReturn($ownerUser);
125
+
126
+        /** @var MockObject $activity */
127
+        $activity = $this->createMock(IEvent::class);
128
+        $activity->expects($this->exactly(count($al['users'])))
129
+            ->method('setAffectedUser');
130
+        $activity->expects($this->once())
131
+            ->method('setApp')
132
+            ->with('comments')
133
+            ->willReturnSelf();
134
+        $activity->expects($this->once())
135
+            ->method('setType')
136
+            ->with('comments')
137
+            ->willReturnSelf();
138
+        $activity->expects($this->once())
139
+            ->method('setAuthor')
140
+            ->with($ownerUser->getUID())
141
+            ->willReturnSelf();
142
+        $activity->expects($this->once())
143
+            ->method('setObject')
144
+            ->with('files', $this->anything())
145
+            ->willReturnSelf();
146
+        $activity->expects($this->once())
147
+            ->method('setMessage')
148
+            ->with('add_comment_message', $this->anything())
149
+            ->willReturnSelf();
150
+
151
+        $this->activityManager->expects($this->once())
152
+            ->method('generateEvent')
153
+            ->willReturn($activity);
154
+        $this->activityManager->expects($this->exactly(count($al['users'])))
155
+            ->method('publish');
156
+
157
+        $this->listener->commentEvent($event);
158
+    }
159 159
 }
Please login to merge, or discard this patch.
apps/comments/tests/Unit/EventHandlerTest.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -17,73 +17,73 @@
 block discarded – undo
17 17
 use Test\TestCase;
18 18
 
19 19
 class EventHandlerTest extends TestCase {
20
-	protected ActivityListener&MockObject $activityListener;
21
-	protected NotificationListener&MockObject $notificationListener;
22
-	protected CommentsEventListener $eventHandler;
23
-
24
-	protected function setUp(): void {
25
-		parent::setUp();
26
-
27
-		$this->activityListener = $this->createMock(ActivityListener::class);
28
-		$this->notificationListener = $this->createMock(NotificationListener::class);
29
-
30
-		$this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener);
31
-	}
32
-
33
-	public function testNotFiles(): void {
34
-		/** @var IComment|MockObject $comment */
35
-		$comment = $this->createMock(IComment::class);
36
-		$comment->expects($this->once())
37
-			->method('getObjectType')
38
-			->willReturn('smiles');
39
-
40
-		/** @var CommentsEvent|MockObject $event */
41
-		$event = $this->createMock(CommentsEvent::class);
42
-		$event->expects($this->once())
43
-			->method('getComment')
44
-			->willReturn($comment);
45
-		$event->expects($this->never())
46
-			->method('getEvent');
47
-
48
-		$this->eventHandler->handle($event);
49
-	}
50
-
51
-	public static function handledProvider(): array {
52
-		return [
53
-			[CommentsEvent::EVENT_DELETE],
54
-			[CommentsEvent::EVENT_UPDATE],
55
-			[CommentsEvent::EVENT_PRE_UPDATE],
56
-			[CommentsEvent::EVENT_ADD]
57
-		];
58
-	}
59
-
60
-	/**
61
-	 * @dataProvider handledProvider
62
-	 */
63
-	public function testHandled(string $eventType): void {
64
-		/** @var IComment|MockObject $comment */
65
-		$comment = $this->createMock(IComment::class);
66
-		$comment->expects($this->once())
67
-			->method('getObjectType')
68
-			->willReturn('files');
69
-
70
-		/** @var CommentsEvent|MockObject $event */
71
-		$event = $this->createMock(CommentsEvent::class);
72
-		$event->expects($this->atLeastOnce())
73
-			->method('getComment')
74
-			->willReturn($comment);
75
-		$event->expects($this->atLeastOnce())
76
-			->method('getEvent')
77
-			->willReturn($eventType);
78
-
79
-		$this->notificationListener->expects($this->once())
80
-			->method('evaluate')
81
-			->with($event);
82
-
83
-		$this->activityListener->expects($this->any())
84
-			->method('commentEvent')
85
-			->with($event);
86
-
87
-		$this->eventHandler->handle($event);
88
-	}
20
+    protected ActivityListener&MockObject $activityListener;
21
+    protected NotificationListener&MockObject $notificationListener;
22
+    protected CommentsEventListener $eventHandler;
23
+
24
+    protected function setUp(): void {
25
+        parent::setUp();
26
+
27
+        $this->activityListener = $this->createMock(ActivityListener::class);
28
+        $this->notificationListener = $this->createMock(NotificationListener::class);
29
+
30
+        $this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener);
31
+    }
32
+
33
+    public function testNotFiles(): void {
34
+        /** @var IComment|MockObject $comment */
35
+        $comment = $this->createMock(IComment::class);
36
+        $comment->expects($this->once())
37
+            ->method('getObjectType')
38
+            ->willReturn('smiles');
39
+
40
+        /** @var CommentsEvent|MockObject $event */
41
+        $event = $this->createMock(CommentsEvent::class);
42
+        $event->expects($this->once())
43
+            ->method('getComment')
44
+            ->willReturn($comment);
45
+        $event->expects($this->never())
46
+            ->method('getEvent');
47
+
48
+        $this->eventHandler->handle($event);
49
+    }
50
+
51
+    public static function handledProvider(): array {
52
+        return [
53
+            [CommentsEvent::EVENT_DELETE],
54
+            [CommentsEvent::EVENT_UPDATE],
55
+            [CommentsEvent::EVENT_PRE_UPDATE],
56
+            [CommentsEvent::EVENT_ADD]
57
+        ];
58
+    }
59
+
60
+    /**
61
+     * @dataProvider handledProvider
62
+     */
63
+    public function testHandled(string $eventType): void {
64
+        /** @var IComment|MockObject $comment */
65
+        $comment = $this->createMock(IComment::class);
66
+        $comment->expects($this->once())
67
+            ->method('getObjectType')
68
+            ->willReturn('files');
69
+
70
+        /** @var CommentsEvent|MockObject $event */
71
+        $event = $this->createMock(CommentsEvent::class);
72
+        $event->expects($this->atLeastOnce())
73
+            ->method('getComment')
74
+            ->willReturn($comment);
75
+        $event->expects($this->atLeastOnce())
76
+            ->method('getEvent')
77
+            ->willReturn($eventType);
78
+
79
+        $this->notificationListener->expects($this->once())
80
+            ->method('evaluate')
81
+            ->with($event);
82
+
83
+        $this->activityListener->expects($this->any())
84
+            ->method('commentEvent')
85
+            ->with($event);
86
+
87
+        $this->eventHandler->handle($event);
88
+    }
89 89
 }
Please login to merge, or discard this patch.
apps/contactsinteraction/tests/Db/RecentContactMapperTest.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -21,95 +21,95 @@
 block discarded – undo
21 21
  * @group DB
22 22
  */
23 23
 class RecentContactMapperTest extends TestCase {
24
-	private RecentContactMapper $recentContactMapper;
25
-	private ITimeFactory $time;
24
+    private RecentContactMapper $recentContactMapper;
25
+    private ITimeFactory $time;
26 26
 
27
-	protected function setUp(): void {
28
-		parent::setUp();
27
+    protected function setUp(): void {
28
+        parent::setUp();
29 29
 
30
-		$this->recentContactMapper = Server::get(RecentContactMapper::class);
31
-		$this->time = Server::get(ITimeFactory::class);
32
-	}
30
+        $this->recentContactMapper = Server::get(RecentContactMapper::class);
31
+        $this->time = Server::get(ITimeFactory::class);
32
+    }
33 33
 
34
-	protected function tearDown(): void {
35
-		parent::tearDown();
34
+    protected function tearDown(): void {
35
+        parent::tearDown();
36 36
 
37
-		$this->recentContactMapper->cleanUp(time());
38
-	}
37
+        $this->recentContactMapper->cleanUp(time());
38
+    }
39 39
 
40
-	public function testCreateRecentContact(): void {
41
-		$contact = $this->createRecentContact();
42
-		$this->assertNotNull($contact->getId());
43
-	}
40
+    public function testCreateRecentContact(): void {
41
+        $contact = $this->createRecentContact();
42
+        $this->assertNotNull($contact->getId());
43
+    }
44 44
 
45
-	public function testFindAll(): void {
46
-		$this->createRecentContact();
47
-		$this->createRecentContact();
45
+    public function testFindAll(): void {
46
+        $this->createRecentContact();
47
+        $this->createRecentContact();
48 48
 
49
-		$contacts = $this->recentContactMapper->findAll('admin');
50
-		$this->assertCount(2, $contacts);
51
-	}
49
+        $contacts = $this->recentContactMapper->findAll('admin');
50
+        $this->assertCount(2, $contacts);
51
+    }
52 52
 
53
-	public function testFindMatchByEmail(): void {
54
-		$this->createRecentContact();
55
-		$contact = $this->createRecentContact('foo@bar');
53
+    public function testFindMatchByEmail(): void {
54
+        $this->createRecentContact();
55
+        $contact = $this->createRecentContact('foo@bar');
56 56
 
57
-		$user = $this->createMock(IUser::class);
58
-		$user->method('getUID')
59
-			->willReturn('admin');
57
+        $user = $this->createMock(IUser::class);
58
+        $user->method('getUID')
59
+            ->willReturn('admin');
60 60
 
61
-		$result = $this->recentContactMapper->findMatch($user, null, 'foo@bar', null);
61
+        $result = $this->recentContactMapper->findMatch($user, null, 'foo@bar', null);
62 62
 
63
-		$this->assertCount(1, $result);
64
-		$this->assertEquals($contact->getId(), $result[0]->getId());
65
-	}
63
+        $this->assertCount(1, $result);
64
+        $this->assertEquals($contact->getId(), $result[0]->getId());
65
+    }
66 66
 
67
-	public function testFindMatchByFederatedCloudId(): void {
68
-		$this->createRecentContact();
69
-		$contact = $this->createRecentContact(null, 'foo.bar');
67
+    public function testFindMatchByFederatedCloudId(): void {
68
+        $this->createRecentContact();
69
+        $contact = $this->createRecentContact(null, 'foo.bar');
70 70
 
71
-		$user = $this->createMock(IUser::class);
72
-		$user->method('getUID')
73
-			->willReturn('admin');
71
+        $user = $this->createMock(IUser::class);
72
+        $user->method('getUID')
73
+            ->willReturn('admin');
74 74
 
75
-		$result = $this->recentContactMapper->findMatch($user, null, null, 'foo.bar');
75
+        $result = $this->recentContactMapper->findMatch($user, null, null, 'foo.bar');
76 76
 
77
-		$this->assertCount(1, $result);
78
-		$this->assertEquals($contact->getId(), $result[0]->getId());
79
-	}
77
+        $this->assertCount(1, $result);
78
+        $this->assertEquals($contact->getId(), $result[0]->getId());
79
+    }
80 80
 
81
-	public function testCleanUp(): void {
82
-		$this->createRecentContact();
83
-		$this->createRecentContact();
84
-		$this->assertCount(2, $this->recentContactMapper->findAll('admin'));
81
+    public function testCleanUp(): void {
82
+        $this->createRecentContact();
83
+        $this->createRecentContact();
84
+        $this->assertCount(2, $this->recentContactMapper->findAll('admin'));
85 85
 
86
-		$this->recentContactMapper->cleanUp(time());
87
-		$this->assertCount(0, $this->recentContactMapper->findAll('admin'));
88
-	}
86
+        $this->recentContactMapper->cleanUp(time());
87
+        $this->assertCount(0, $this->recentContactMapper->findAll('admin'));
88
+    }
89 89
 
90
-	protected function createRecentContact(?string $email = null, ?string $federatedCloudId = null): RecentContact {
91
-		$props = [
92
-			'URI' => UUIDUtil::getUUID(),
93
-			'FN' => 'Foo Bar',
94
-			'CATEGORIES' => 'Recently contacted',
95
-		];
90
+    protected function createRecentContact(?string $email = null, ?string $federatedCloudId = null): RecentContact {
91
+        $props = [
92
+            'URI' => UUIDUtil::getUUID(),
93
+            'FN' => 'Foo Bar',
94
+            'CATEGORIES' => 'Recently contacted',
95
+        ];
96 96
 
97
-		$time = $this->time->getDateTime();
98
-		$time->modify('-14days');
97
+        $time = $this->time->getDateTime();
98
+        $time->modify('-14days');
99 99
 
100
-		$contact = new RecentContact();
101
-		$contact->setActorUid('admin');
102
-		$contact->setCard((new VCard($props))->serialize());
103
-		$contact->setLastContact($time->getTimestamp());
100
+        $contact = new RecentContact();
101
+        $contact->setActorUid('admin');
102
+        $contact->setCard((new VCard($props))->serialize());
103
+        $contact->setLastContact($time->getTimestamp());
104 104
 
105
-		if ($email !== null) {
106
-			$contact->setEmail($email);
107
-		}
105
+        if ($email !== null) {
106
+            $contact->setEmail($email);
107
+        }
108 108
 
109
-		if ($federatedCloudId !== null) {
110
-			$contact->setFederatedCloudId($federatedCloudId);
111
-		}
109
+        if ($federatedCloudId !== null) {
110
+            $contact->setFederatedCloudId($federatedCloudId);
111
+        }
112 112
 
113
-		return $this->recentContactMapper->insert($contact);
114
-	}
113
+        return $this->recentContactMapper->insert($contact);
114
+    }
115 115
 }
Please login to merge, or discard this patch.
apps/user_status/tests/Unit/Db/UserStatusMapperTest.php 1 patch
Indentation   +318 added lines, -318 removed lines patch added patch discarded remove patch
@@ -15,322 +15,322 @@
 block discarded – undo
15 15
 use Test\TestCase;
16 16
 
17 17
 class UserStatusMapperTest extends TestCase {
18
-	private UserStatusMapper $mapper;
19
-
20
-	protected function setUp(): void {
21
-		parent::setUp();
22
-
23
-		// make sure that DB is empty
24
-		$qb = self::$realDatabase->getQueryBuilder();
25
-		$qb->delete('user_status')->execute();
26
-
27
-		$this->mapper = new UserStatusMapper(self::$realDatabase);
28
-	}
29
-
30
-	public function testGetTableName(): void {
31
-		$this->assertEquals('user_status', $this->mapper->getTableName());
32
-	}
33
-
34
-	public function testGetFindAll(): void {
35
-		$this->insertSampleStatuses();
36
-
37
-		$allResults = $this->mapper->findAll();
38
-		$this->assertCount(3, $allResults);
39
-
40
-		$limitedResults = $this->mapper->findAll(2);
41
-		$this->assertCount(2, $limitedResults);
42
-		$this->assertEquals('admin', $limitedResults[0]->getUserId());
43
-		$this->assertEquals('user1', $limitedResults[1]->getUserId());
44
-
45
-		$offsetResults = $this->mapper->findAll(null, 2);
46
-		$this->assertCount(1, $offsetResults);
47
-		$this->assertEquals('user2', $offsetResults[0]->getUserId());
48
-	}
49
-
50
-	public function testFindAllRecent(): void {
51
-		$this->insertSampleStatuses();
52
-
53
-		$allResults = $this->mapper->findAllRecent(2, 0);
54
-		$this->assertCount(2, $allResults);
55
-		$this->assertEquals('user2', $allResults[0]->getUserId());
56
-		$this->assertEquals('user1', $allResults[1]->getUserId());
57
-	}
58
-
59
-	public function testGetFind(): void {
60
-		$this->insertSampleStatuses();
61
-
62
-		$adminStatus = $this->mapper->findByUserId('admin');
63
-		$this->assertEquals('admin', $adminStatus->getUserId());
64
-		$this->assertEquals('offline', $adminStatus->getStatus());
65
-		$this->assertEquals(0, $adminStatus->getStatusTimestamp());
66
-		$this->assertEquals(false, $adminStatus->getIsUserDefined());
67
-		$this->assertEquals(null, $adminStatus->getCustomIcon());
68
-		$this->assertEquals(null, $adminStatus->getCustomMessage());
69
-		$this->assertEquals(null, $adminStatus->getClearAt());
70
-
71
-		$user1Status = $this->mapper->findByUserId('user1');
72
-		$this->assertEquals('user1', $user1Status->getUserId());
73
-		$this->assertEquals('dnd', $user1Status->getStatus());
74
-		$this->assertEquals(5000, $user1Status->getStatusTimestamp());
75
-		$this->assertEquals(true, $user1Status->getIsUserDefined());
76
-		$this->assertEquals('
Please login to merge, or discard this patch.
apps/user_status/tests/Unit/Connector/UserStatusProviderTest.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -15,59 +15,59 @@
 block discarded – undo
15 15
 use Test\TestCase;
16 16
 
17 17
 class UserStatusProviderTest extends TestCase {
18
-	private StatusService&MockObject $service;
19
-	private UserStatusProvider $provider;
18
+    private StatusService&MockObject $service;
19
+    private UserStatusProvider $provider;
20 20
 
21
-	protected function setUp(): void {
22
-		parent::setUp();
21
+    protected function setUp(): void {
22
+        parent::setUp();
23 23
 
24
-		$this->service = $this->createMock(StatusService::class);
25
-		$this->provider = new UserStatusProvider($this->service);
26
-	}
24
+        $this->service = $this->createMock(StatusService::class);
25
+        $this->provider = new UserStatusProvider($this->service);
26
+    }
27 27
 
28
-	public function testGetUserStatuses(): void {
29
-		$userStatus2 = new UserStatus();
30
-		$userStatus2->setUserId('userId2');
31
-		$userStatus2->setStatus('dnd');
32
-		$userStatus2->setStatusTimestamp(5000);
33
-		$userStatus2->setIsUserDefined(true);
34
-		$userStatus2->setCustomIcon('
Please login to merge, or discard this patch.
apps/user_status/tests/Unit/Controller/StatusesControllerTest.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -18,77 +18,77 @@
 block discarded – undo
18 18
 use Test\TestCase;
19 19
 
20 20
 class StatusesControllerTest extends TestCase {
21
-	private StatusService&MockObject $service;
22
-	private StatusesController $controller;
23
-
24
-	protected function setUp(): void {
25
-		parent::setUp();
26
-
27
-		$request = $this->createMock(IRequest::class);
28
-		$this->service = $this->createMock(StatusService::class);
29
-
30
-		$this->controller = new StatusesController('user_status', $request, $this->service);
31
-	}
32
-
33
-	public function testFindAll(): void {
34
-		$userStatus = $this->getUserStatus();
35
-
36
-		$this->service->expects($this->once())
37
-			->method('findAll')
38
-			->with(20, 40)
39
-			->willReturn([$userStatus]);
40
-
41
-		$response = $this->controller->findAll(20, 40);
42
-		$this->assertEquals([[
43
-			'userId' => 'john.doe',
44
-			'status' => 'offline',
45
-			'icon' => '
Please login to merge, or discard this patch.
apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php 1 patch
Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -27,293 +27,293 @@
 block discarded – undo
27 27
 use Throwable;
28 28
 
29 29
 class UserStatusControllerTest extends TestCase {
30
-	private LoggerInterface&MockObject $logger;
31
-	private StatusService&MockObject $statusService;
32
-	private CalendarStatusService&MockObject $calendarStatusService;
33
-	private UserStatusController $controller;
34
-
35
-	protected function setUp(): void {
36
-		parent::setUp();
37
-
38
-		$request = $this->createMock(IRequest::class);
39
-		$userId = 'john.doe';
40
-		$this->logger = $this->createMock(LoggerInterface::class);
41
-		$this->statusService = $this->createMock(StatusService::class);
42
-		$this->calendarStatusService = $this->createMock(CalendarStatusService::class);
43
-
44
-		$this->controller = new UserStatusController(
45
-			'user_status',
46
-			$request,
47
-			$userId,
48
-			$this->logger,
49
-			$this->statusService,
50
-			$this->calendarStatusService,
51
-		);
52
-	}
53
-
54
-	public function testGetStatus(): void {
55
-		$userStatus = $this->getUserStatus();
56
-
57
-		$this->statusService->expects($this->once())
58
-			->method('findByUserId')
59
-			->with('john.doe')
60
-			->willReturn($userStatus);
61
-
62
-		$response = $this->controller->getStatus();
63
-		$this->assertEquals([
64
-			'userId' => 'john.doe',
65
-			'status' => 'invisible',
66
-			'icon' => '
Please login to merge, or discard this patch.
apps/user_status/tests/Unit/Controller/PredefinedStatusControllerTest.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -15,39 +15,39 @@
 block discarded – undo
15 15
 use Test\TestCase;
16 16
 
17 17
 class PredefinedStatusControllerTest extends TestCase {
18
-	private PredefinedStatusService&MockObject $service;
19
-	private PredefinedStatusController $controller;
20
-
21
-	protected function setUp(): void {
22
-		parent::setUp();
23
-
24
-		$request = $this->createMock(IRequest::class);
25
-		$this->service = $this->createMock(PredefinedStatusService::class);
26
-
27
-		$this->controller = new PredefinedStatusController('user_status', $request, $this->service);
28
-	}
29
-
30
-	public function testFindAll(): void {
31
-		$this->service->expects($this->once())
32
-			->method('getDefaultStatuses')
33
-			->with()
34
-			->willReturn([
35
-				[
36
-					'id' => 'predefined-status-one',
37
-				],
38
-				[
39
-					'id' => 'predefined-status-two',
40
-				],
41
-			]);
42
-
43
-		$actual = $this->controller->findAll();
44
-		$this->assertEquals([
45
-			[
46
-				'id' => 'predefined-status-one',
47
-			],
48
-			[
49
-				'id' => 'predefined-status-two',
50
-			],
51
-		], $actual->getData());
52
-	}
18
+    private PredefinedStatusService&MockObject $service;
19
+    private PredefinedStatusController $controller;
20
+
21
+    protected function setUp(): void {
22
+        parent::setUp();
23
+
24
+        $request = $this->createMock(IRequest::class);
25
+        $this->service = $this->createMock(PredefinedStatusService::class);
26
+
27
+        $this->controller = new PredefinedStatusController('user_status', $request, $this->service);
28
+    }
29
+
30
+    public function testFindAll(): void {
31
+        $this->service->expects($this->once())
32
+            ->method('getDefaultStatuses')
33
+            ->with()
34
+            ->willReturn([
35
+                [
36
+                    'id' => 'predefined-status-one',
37
+                ],
38
+                [
39
+                    'id' => 'predefined-status-two',
40
+                ],
41
+            ]);
42
+
43
+        $actual = $this->controller->findAll();
44
+        $this->assertEquals([
45
+            [
46
+                'id' => 'predefined-status-one',
47
+            ],
48
+            [
49
+                'id' => 'predefined-status-two',
50
+            ],
51
+        ], $actual->getData());
52
+    }
53 53
 }
Please login to merge, or discard this patch.