X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/e108808a32b865668076b7b032ee620229d44d1f..refs/pull/3593/head:/tests/TestEmailTest.php diff --git a/tests/TestEmailTest.php b/tests/TestEmailTest.php index c06311d84..97f98225d 100644 --- a/tests/TestEmailTest.php +++ b/tests/TestEmailTest.php @@ -1,17 +1,19 @@ -asAdmin()->get('/settings/maintenance'); $formCssSelector = 'form[action$="/settings/maintenance/send-test-email"]'; - $pageView->assertElementExists($formCssSelector); - $pageView->assertElementContains($formCssSelector . ' button', 'Send Test Email'); + $this->withHtml($pageView)->assertElementExists($formCssSelector); + $this->withHtml($pageView)->assertElementContains($formCssSelector . ' button', 'Send Test Email'); } public function test_send_test_email_endpoint_sends_email_and_redirects_user_and_shows_notification() @@ -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 +}