Notifications: Add test to check notification language

This commit is contained in:
Dan Brown 2023-09-01 16:30:37 +01:00
parent 4e6b74f2a1
commit f91049a3f2
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9

View File

@ -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();