|
2 | 2 |
|
3 | 3 | namespace Tests\Activity; |
4 | 4 |
|
| 5 | +use BookStack\Activity\ActivityType; |
| 6 | +use BookStack\Activity\Models\Comment; |
| 7 | +use BookStack\Activity\Notifications\Messages\BaseActivityNotification; |
5 | 8 | use BookStack\Activity\Notifications\Messages\CommentCreationNotification; |
6 | 9 | use BookStack\Activity\Notifications\Messages\PageCreationNotification; |
7 | 10 | use BookStack\Activity\Notifications\Messages\PageUpdateNotification; |
| 11 | +use BookStack\Activity\Tools\ActivityLogger; |
8 | 12 | use BookStack\Activity\Tools\UserEntityWatchOptions; |
9 | 13 | use BookStack\Activity\WatchLevels; |
10 | 14 | use BookStack\Entities\Models\Entity; |
@@ -313,6 +317,43 @@ public function test_notify_watch_parent_book_new() |
313 | 317 | }); |
314 | 318 | } |
315 | 319 |
|
| 320 | + public function test_notifications_sent_in_right_language() |
| 321 | + { |
| 322 | + $editor = $this->users->editor(); |
| 323 | + $admin = $this->users->admin(); |
| 324 | + setting()->putUser($editor, 'language', 'de'); |
| 325 | + $entities = $this->entities->createChainBelongingToUser($editor); |
| 326 | + $watches = new UserEntityWatchOptions($editor, $entities['book']); |
| 327 | + $watches->updateLevelByValue(WatchLevels::COMMENTS); |
| 328 | + |
| 329 | + $activities = [ |
| 330 | + ActivityType::PAGE_CREATE => $entities['page'], |
| 331 | + ActivityType::PAGE_UPDATE => $entities['page'], |
| 332 | + ActivityType::COMMENT_CREATE => (new Comment([]))->forceFill(['entity_id' => $entities['page']->id, 'entity_type' => $entities['page']->getMorphClass()]), |
| 333 | + ]; |
| 334 | + |
| 335 | + $notifications = Notification::fake(); |
| 336 | + $logger = app()->make(ActivityLogger::class); |
| 337 | + $this->actingAs($admin); |
| 338 | + |
| 339 | + foreach ($activities as $activityType => $detail) { |
| 340 | + $logger->add($activityType, $detail); |
| 341 | + } |
| 342 | + |
| 343 | + $sent = $notifications->sentNotifications()[get_class($editor)][$editor->id]; |
| 344 | + $this->assertCount(3, $sent); |
| 345 | + |
| 346 | + foreach ($sent as $notificationInfo) { |
| 347 | + $notification = $notificationInfo[0]['notification']; |
| 348 | + $this->assertInstanceOf(BaseActivityNotification::class, $notification); |
| 349 | + $mail = $notification->toMail($editor); |
| 350 | + $mailContent = html_entity_decode(strip_tags($mail->render())); |
| 351 | + $this->assertStringContainsString('Name der Seite:', $mailContent); |
| 352 | + $this->assertStringContainsString('Diese Benachrichtigung wurde', $mailContent); |
| 353 | + $this->assertStringContainsString('Sollte es beim Anklicken der Schaltfläche', $mailContent); |
| 354 | + } |
| 355 | + } |
| 356 | + |
316 | 357 | public function test_notifications_not_sent_if_lacking_view_permission_for_related_item() |
317 | 358 | { |
318 | 359 | $notifications = Notification::fake(); |
|
0 commit comments