+ 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_failed_notifications_dont_block_and_log_errors()
+ {
+ $logger = $this->withTestLogger();
+ $editor = $this->users->editor();
+ $admin = $this->users->admin();
+ $page = $this->entities->page();
+ $book = $page->book;
+ $activityLogger = app()->make(ActivityLogger::class);
+
+ $watches = new UserEntityWatchOptions($editor, $book);
+ $watches->updateLevelByValue(WatchLevels::UPDATES);
+
+ $mockDispatcher = $this->mock(Dispatcher::class);
+ $mockDispatcher->shouldReceive('send')->once()
+ ->andThrow(\Exception::class, 'Failed to connect to mail server');
+
+ $this->actingAs($admin);
+
+ $activityLogger->add(ActivityType::PAGE_UPDATE, $page);
+
+ $this->assertTrue($logger->hasErrorThatContains("Failed to send email notification to user [id:{$editor->id}] with error: Failed to connect to mail server"));
+ }
+