Skip to content

Commit f91049a

Browse files
committed
Notifications: Add test to check notification language
1 parent 4e6b74f commit f91049a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/Activity/WatchTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace Tests\Activity;
44

5+
use BookStack\Activity\ActivityType;
6+
use BookStack\Activity\Models\Comment;
7+
use BookStack\Activity\Notifications\Messages\BaseActivityNotification;
58
use BookStack\Activity\Notifications\Messages\CommentCreationNotification;
69
use BookStack\Activity\Notifications\Messages\PageCreationNotification;
710
use BookStack\Activity\Notifications\Messages\PageUpdateNotification;
11+
use BookStack\Activity\Tools\ActivityLogger;
812
use BookStack\Activity\Tools\UserEntityWatchOptions;
913
use BookStack\Activity\WatchLevels;
1014
use BookStack\Entities\Models\Entity;
@@ -313,6 +317,43 @@ public function test_notify_watch_parent_book_new()
313317
});
314318
}
315319

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+
316357
public function test_notifications_not_sent_if_lacking_view_permission_for_related_item()
317358
{
318359
$notifications = Notification::fake();

0 commit comments

Comments
 (0)