|
31 | 31 | use OCP\Activity\ActivitySettings; |
32 | 32 | use OCP\Activity\IEvent; |
33 | 33 | use OCP\Activity\IManager; |
34 | | -use OCP\Activity\ISetting; |
35 | 34 | use OCP\Config\IUserConfig; |
36 | 35 | use OCP\IDBConnection; |
37 | 36 | use OCP\IL10N; |
@@ -264,213 +263,4 @@ public function testBulkReceiveNotification(string $type, string $author, string |
264 | 263 | $this->consumer->bulkReceive($this->event, $affectedUsers, $settings); |
265 | 264 | } |
266 | 265 |
|
267 | | - public function testBulkReceiveEmail(): void { |
268 | | - $time = time(); |
269 | | - $this->event->setApp('activity') |
270 | | - ->setType('type') |
271 | | - ->setAuthor('author') |
272 | | - ->setTimestamp($time) |
273 | | - ->setSubject('subject', ['subjectParam1']) |
274 | | - ->setMessage('message', ['messageParam1']) |
275 | | - ->setObject('', 0, 'file') |
276 | | - ->setLink('link'); |
277 | | - |
278 | | - $settings = $this->createMock(ActivitySettings::class); |
279 | | - $settings->method('canChangeMail')->willReturn(true); |
280 | | - $settings->method('isDefaultEnabledMail')->willReturn(true); |
281 | | - $settings->method('canChangeNotification')->willReturn(false); |
282 | | - |
283 | | - $this->data->expects($this->once()) |
284 | | - ->method('bulkSend') |
285 | | - ->willReturn([1 => 'affectedUser', 2 => 'affectedUser2']); |
286 | | - |
287 | | - $this->userConfig->method('getValuesByUsers') |
288 | | - ->willReturnCallback(function (string $app, string $key, mixed $type, array $users): array { |
289 | | - if (str_contains($key, 'email')) { |
290 | | - return array_fill_keys($users, true); |
291 | | - } |
292 | | - if (str_contains($key, 'batchtime')) { |
293 | | - return array_fill_keys($users, 10); |
294 | | - } |
295 | | - return []; |
296 | | - }); |
297 | | - |
298 | | - $this->data->expects($this->exactly(2)) |
299 | | - ->method('storeMail'); |
300 | | - |
301 | | - $this->consumer->bulkReceive($this->event, ['affectedUser', 'affectedUser2'], $settings); |
302 | | - } |
303 | | - |
304 | | - public function testBulkReceiveNoMailWhenSettingDisabled(): void { |
305 | | - $this->event->setApp('activity') |
306 | | - ->setType('type') |
307 | | - ->setAuthor('author') |
308 | | - ->setTimestamp(time()) |
309 | | - ->setSubject('subject', ['subjectParam1']) |
310 | | - ->setMessage('message', ['messageParam1']) |
311 | | - ->setObject('', 0, 'file') |
312 | | - ->setLink('link'); |
313 | | - |
314 | | - $settings = $this->createMock(ActivitySettings::class); |
315 | | - $settings->method('canChangeMail')->willReturn(false); |
316 | | - $settings->method('isDefaultEnabledMail')->willReturn(false); |
317 | | - $settings->method('canChangeNotification')->willReturn(false); |
318 | | - |
319 | | - $this->data->expects($this->once()) |
320 | | - ->method('bulkSend') |
321 | | - ->willReturn([1 => 'affectedUser']); |
322 | | - |
323 | | - $this->data->expects($this->never()) |
324 | | - ->method('storeMail'); |
325 | | - // Notification is still sent because $notificationSetting defaults to null |
326 | | - // and null !== false, so the default is to send notifications |
327 | | - $this->notificationGenerator->expects($this->once()) |
328 | | - ->method('sendNotificationForEvent'); |
329 | | - |
330 | | - $this->consumer->bulkReceive($this->event, ['affectedUser'], $settings); |
331 | | - } |
332 | | - |
333 | | - public function testBulkReceiveDeferAndFlushNotifications(): void { |
334 | | - $this->event->setApp('activity') |
335 | | - ->setType('type') |
336 | | - ->setAuthor('author') |
337 | | - ->setTimestamp(time()) |
338 | | - ->setSubject('subject', ['subjectParam1']) |
339 | | - ->setMessage('message', ['messageParam1']) |
340 | | - ->setObject('', 0, 'file') |
341 | | - ->setLink('link'); |
342 | | - |
343 | | - $settings = $this->createMock(ActivitySettings::class); |
344 | | - $settings->method('canChangeMail')->willReturn(false); |
345 | | - $settings->method('isDefaultEnabledMail')->willReturn(false); |
346 | | - $settings->method('canChangeNotification')->willReturn(true); |
347 | | - |
348 | | - $this->data->expects($this->once()) |
349 | | - ->method('bulkSend') |
350 | | - ->willReturn([1 => 'affectedUser']); |
351 | | - |
352 | | - $this->userConfig->method('getValuesByUsers') |
353 | | - ->willReturnCallback(function (string $app, string $key, mixed $type, array $users): array { |
354 | | - return array_fill_keys($users, true); |
355 | | - }); |
356 | | - |
357 | | - $this->notificationGenerator->expects($this->once()) |
358 | | - ->method('deferNotifications') |
359 | | - ->willReturn(true); |
360 | | - $this->notificationGenerator->expects($this->once()) |
361 | | - ->method('flushNotifications'); |
362 | | - $this->notificationGenerator->expects($this->once()) |
363 | | - ->method('sendNotificationForEvent'); |
364 | | - |
365 | | - $this->consumer->bulkReceive($this->event, ['affectedUser'], $settings); |
366 | | - } |
367 | | - |
368 | | - public function testBulkReceiveNoFlushWhenDeferReturnsFalse(): void { |
369 | | - $this->event->setApp('activity') |
370 | | - ->setType('type') |
371 | | - ->setAuthor('author') |
372 | | - ->setTimestamp(time()) |
373 | | - ->setSubject('subject', ['subjectParam1']) |
374 | | - ->setMessage('message', ['messageParam1']) |
375 | | - ->setObject('', 0, 'file') |
376 | | - ->setLink('link'); |
377 | | - |
378 | | - $settings = $this->createMock(ActivitySettings::class); |
379 | | - $settings->method('canChangeMail')->willReturn(false); |
380 | | - $settings->method('isDefaultEnabledMail')->willReturn(false); |
381 | | - $settings->method('canChangeNotification')->willReturn(true); |
382 | | - |
383 | | - $this->data->expects($this->once()) |
384 | | - ->method('bulkSend') |
385 | | - ->willReturn([1 => 'affectedUser']); |
386 | | - |
387 | | - $this->userConfig->method('getValuesByUsers') |
388 | | - ->willReturnCallback(function (string $app, string $key, mixed $type, array $users): array { |
389 | | - return array_fill_keys($users, true); |
390 | | - }); |
391 | | - |
392 | | - $this->notificationGenerator->expects($this->once()) |
393 | | - ->method('deferNotifications') |
394 | | - ->willReturn(false); |
395 | | - $this->notificationGenerator->expects($this->never()) |
396 | | - ->method('flushNotifications'); |
397 | | - |
398 | | - $this->consumer->bulkReceive($this->event, ['affectedUser'], $settings); |
399 | | - } |
400 | | - |
401 | | - public function testBulkReceiveMultipleUsersWithMixedSettings(): void { |
402 | | - $time = time(); |
403 | | - $this->event->setApp('activity') |
404 | | - ->setType('type') |
405 | | - ->setAuthor('author') |
406 | | - ->setTimestamp($time) |
407 | | - ->setSubject('subject', ['subjectParam1']) |
408 | | - ->setMessage('message', ['messageParam1']) |
409 | | - ->setObject('', 0, 'file') |
410 | | - ->setLink('link'); |
411 | | - |
412 | | - $settings = $this->createMock(ActivitySettings::class); |
413 | | - $settings->method('canChangeMail')->willReturn(true); |
414 | | - $settings->method('isDefaultEnabledMail')->willReturn(true); |
415 | | - $settings->method('canChangeNotification')->willReturn(true); |
416 | | - |
417 | | - $this->data->expects($this->once()) |
418 | | - ->method('bulkSend') |
419 | | - ->willReturn([1 => 'user1', 2 => 'user2', 3 => 'author']); |
420 | | - |
421 | | - $this->userConfig->method('getValuesByUsers') |
422 | | - ->willReturnCallback(function (string $app, string $key, mixed $type, array $users): array { |
423 | | - if (str_contains($key, 'notification')) { |
424 | | - // Only user1 has notifications enabled |
425 | | - return ['user1' => true]; |
426 | | - } |
427 | | - if (str_contains($key, 'email')) { |
428 | | - // Only user2 has email enabled |
429 | | - return ['user2' => true]; |
430 | | - } |
431 | | - if (str_contains($key, 'batchtime')) { |
432 | | - return ['user2' => 15]; |
433 | | - } |
434 | | - return []; |
435 | | - }); |
436 | | - |
437 | | - // user1 and user2 get notifications (user2 has null setting which defaults to send), author is skipped |
438 | | - $this->notificationGenerator->expects($this->exactly(2)) |
439 | | - ->method('sendNotificationForEvent'); |
440 | | - // user2 gets email, author is skipped |
441 | | - $this->data->expects($this->once()) |
442 | | - ->method('storeMail') |
443 | | - ->with($this->event, $time + 15); |
444 | | - |
445 | | - $this->consumer->bulkReceive($this->event, ['user1', 'user2', 'author'], $settings); |
446 | | - } |
447 | | - |
448 | | - public function testBulkReceiveWithISetting(): void { |
449 | | - $this->event->setApp('activity') |
450 | | - ->setType('type') |
451 | | - ->setAuthor('author') |
452 | | - ->setTimestamp(time()) |
453 | | - ->setSubject('subject', ['subjectParam1']) |
454 | | - ->setMessage('message', ['messageParam1']) |
455 | | - ->setObject('', 0, 'file') |
456 | | - ->setLink('link'); |
457 | | - |
458 | | - // ISetting (not ActivitySettings) — canChangeNotification is not available |
459 | | - $settings = $this->createMock(ISetting::class); |
460 | | - $settings->method('canChangeMail')->willReturn(false); |
461 | | - |
462 | | - $this->data->expects($this->once()) |
463 | | - ->method('bulkSend') |
464 | | - ->willReturn([1 => 'affectedUser']); |
465 | | - |
466 | | - // Notification is still sent because $notificationSetting defaults to null (not false) |
467 | | - // when ISetting is used (canChangeNotification not available), and null !== false |
468 | | - $this->notificationGenerator->expects($this->once()) |
469 | | - ->method('sendNotificationForEvent'); |
470 | | - $this->data->expects($this->never()) |
471 | | - ->method('storeMail'); |
472 | | - |
473 | | - $this->consumer->bulkReceive($this->event, ['affectedUser'], $settings); |
474 | | - } |
475 | | - |
476 | 266 | } |
0 commit comments