diff --git a/tests/Activity/WatchTest.php b/tests/Activity/WatchTest.php index fd86029d3..d3c9387bb 100644 --- a/tests/Activity/WatchTest.php +++ b/tests/Activity/WatchTest.php @@ -2,9 +2,13 @@ namespace Tests\Activity; +use BookStack\Activity\ActivityType; +use BookStack\Activity\Models\Comment; +use BookStack\Activity\Notifications\Messages\BaseActivityNotification; use BookStack\Activity\Notifications\Messages\CommentCreationNotification; use BookStack\Activity\Notifications\Messages\PageCreationNotification; use BookStack\Activity\Notifications\Messages\PageUpdateNotification; +use BookStack\Activity\Tools\ActivityLogger; use BookStack\Activity\Tools\UserEntityWatchOptions; use BookStack\Activity\WatchLevels; use BookStack\Entities\Models\Entity; @@ -313,6 +317,43 @@ class WatchTest extends TestCase }); } + public function test_notifications_sent_in_right_language() + { + $editor = $this->users->editor(); + $admin = $this->users->admin(); + setting()->putUser($editor, 'language', 'de'); + $entities = $this->entities->createChainBelongingToUser($editor); + $watches = new UserEntityWatchOptions($editor, $entities['book']); + $watches->updateLevelByValue(WatchLevels::COMMENTS); + + $activities = [ + ActivityType::PAGE_CREATE => $entities['page'], + ActivityType::PAGE_UPDATE => $entities['page'], + ActivityType::COMMENT_CREATE => (new Comment([]))->forceFill(['entity_id' => $entities['page']->id, 'entity_type' => $entities['page']->getMorphClass()]), + ]; + + $notifications = Notification::fake(); + $logger = app()->make(ActivityLogger::class); + $this->actingAs($admin); + + foreach ($activities as $activityType => $detail) { + $logger->add($activityType, $detail); + } + + $sent = $notifications->sentNotifications()[get_class($editor)][$editor->id]; + $this->assertCount(3, $sent); + + foreach ($sent as $notificationInfo) { + $notification = $notificationInfo[0]['notification']; + $this->assertInstanceOf(BaseActivityNotification::class, $notification); + $mail = $notification->toMail($editor); + $mailContent = html_entity_decode(strip_tags($mail->render())); + $this->assertStringContainsString('Name der Seite:', $mailContent); + $this->assertStringContainsString('Diese Benachrichtigung wurde', $mailContent); + $this->assertStringContainsString('Sollte es beim Anklicken der Schaltfläche', $mailContent); + } + } + public function test_notifications_not_sent_if_lacking_view_permission_for_related_item() { $notifications = Notification::fake();