]> BookStack Code Mirror - bookstack/blobdiff - tests/TestEmailTest.php
Fixed failing test after drawio default url change
[bookstack] / tests / TestEmailTest.php
index c06311d84089d6997d06f8b00d9bf1ec7b667eb7..e0350371afe00707ce8eb87f6597018e3f94f424 100644 (file)
@@ -1,11 +1,13 @@
-<?php namespace Tests;
+<?php
+
+namespace Tests;
 
 use BookStack\Notifications\TestEmail;
+use Illuminate\Contracts\Notifications\Dispatcher;
 use Illuminate\Support\Facades\Notification;
 
 class TestEmailTest extends TestCase
 {
-
     public function test_a_send_test_button_shows()
     {
         $pageView = $this->asAdmin()->get('/settings/maintenance');
@@ -26,6 +28,24 @@ class TestEmailTest extends TestCase
         Notification::assertSentTo($admin, TestEmail::class);
     }
 
+    public function test_send_test_email_failure_displays_error_notification()
+    {
+        $mockDispatcher = $this->mock(Dispatcher::class);
+        $this->app[Dispatcher::class] = $mockDispatcher;
+
+        $exception = new \Exception('A random error occurred when testing an email');
+        $mockDispatcher->shouldReceive('sendNow')->andThrow($exception);
+
+        $admin = $this->getAdmin();
+        $sendReq = $this->actingAs($admin)->post('/settings/maintenance/send-test-email');
+        $sendReq->assertRedirect('/settings/maintenance#image-cleanup');
+        $this->assertSessionHas('error');
+
+        $message = session()->get('error');
+        $this->assertStringContainsString('Error thrown when sending a test email:', $message);
+        $this->assertStringContainsString('A random error occurred when testing an email', $message);
+    }
+
     public function test_send_test_email_requires_settings_manage_permission()
     {
         Notification::fake();
@@ -38,6 +58,4 @@ class TestEmailTest extends TestCase
         $sendReq = $this->actingAs($user)->post('/settings/maintenance/send-test-email');
         Notification::assertSentTo($user, TestEmail::class);
     }
-
-
-}
\ No newline at end of file
+}