X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/1366fc45ce7849b744ea0f84b9b4587e7d0e61ba..refs/pull/3039/head:/tests/TestEmailTest.php diff --git a/tests/TestEmailTest.php b/tests/TestEmailTest.php index c06311d84..0a2091fe3 100644 --- a/tests/TestEmailTest.php +++ b/tests/TestEmailTest.php @@ -1,11 +1,13 @@ -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('send')->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 +}