+
+ 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 => Comment::factory()->make([
+ '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()), ENT_QUOTES);
+ $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();
+ $editor = $this->users->editor();
+ $page = $this->entities->page();
+
+ $watches = new UserEntityWatchOptions($editor, $page);
+ $watches->updateLevelByValue(WatchLevels::COMMENTS);
+ $this->permissions->disableEntityInheritedPermissions($page);
+
+ $this->asAdmin()->post("/comment/{$page->id}", [
+ 'html' => '<p>My new comment response</p>',
+ ])->assertOk();
+
+ $notifications->assertNothingSentTo($editor);
+ }
+
+ public function test_watches_deleted_on_user_delete()
+ {
+ $editor = $this->users->editor();
+ $page = $this->entities->page();
+
+ $watches = new UserEntityWatchOptions($editor, $page);
+ $watches->updateLevelByValue(WatchLevels::COMMENTS);
+ $this->assertDatabaseHas('watches', ['user_id' => $editor->id]);
+
+ $this->asAdmin()->delete($editor->getEditUrl());
+
+ $this->assertDatabaseMissing('watches', ['user_id' => $editor->id]);
+ }
+
+ public function test_watches_deleted_on_item_delete()
+ {
+ $editor = $this->users->editor();
+ $page = $this->entities->page();
+
+ $watches = new UserEntityWatchOptions($editor, $page);
+ $watches->updateLevelByValue(WatchLevels::COMMENTS);
+ $this->assertDatabaseHas('watches', ['watchable_type' => 'page', 'watchable_id' => $page->id]);
+
+ $this->entities->destroy($page);
+
+ $this->assertDatabaseMissing('watches', ['watchable_type' => 'page', 'watchable_id' => $page->id]);
+ }
+
+ public function test_page_path_in_notifications_limited_by_permissions()
+ {
+ $chapter = $this->entities->chapterHasPages();
+ $page = $chapter->pages()->first();
+ $book = $chapter->book;
+ $notification = new PageCreationNotification($page, $this->users->editor());
+
+ $viewer = $this->users->viewer();
+ $viewerRole = $viewer->roles()->first();
+
+ $content = html_entity_decode(strip_tags($notification->toMail($viewer)->render()), ENT_QUOTES);
+ $this->assertStringContainsString('Page Path: ' . $book->getShortName(24) . ' > ' . $chapter->getShortName(24), $content);
+
+ $this->permissions->setEntityPermissions($page, ['view'], [$viewerRole]);
+ $this->permissions->setEntityPermissions($chapter, [], [$viewerRole]);
+
+ $content = html_entity_decode(strip_tags($notification->toMail($viewer)->render()), ENT_QUOTES);
+ $this->assertStringContainsString('Page Path: ' . $book->getShortName(24), $content);
+ $this->assertStringNotContainsString(' > ' . $chapter->getShortName(24), $content);
+
+ $this->permissions->setEntityPermissions($book, [], [$viewerRole]);
+
+ $content = html_entity_decode(strip_tags($notification->toMail($viewer)->render()), ENT_QUOTES);
+ $this->assertStringNotContainsString('Page Path:', $content);
+ $this->assertStringNotContainsString($book->getShortName(24), $content);
+ $this->assertStringNotContainsString($chapter->getShortName(24), $content);
+ }