From 1366fc45ce7849b744ea0f84b9b4587e7d0e61ba Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Wed, 23 Oct 2019 20:25:51 +0100 Subject: [PATCH] Added tests to cover test email sends - Also tweaked wording of 'E-mail' to 'Email' to remain consistent with the rest of the app. Related to #1696 and #1719 --- resources/lang/en/settings.php | 14 +++++------ tests/TestEmailTest.php | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 tests/TestEmailTest.php diff --git a/resources/lang/en/settings.php b/resources/lang/en/settings.php index ac3be1f3f..56e0868e4 100755 --- a/resources/lang/en/settings.php +++ b/resources/lang/en/settings.php @@ -63,13 +63,13 @@ return [ 'maint_image_cleanup_warning' => ':count potentially unused images were found. Are you sure you want to delete these images?', 'maint_image_cleanup_success' => ':count potentially unused images found and deleted!', 'maint_image_cleanup_nothing_found' => 'No unused images found, Nothing deleted!', - 'maint_send_test_email' => 'Send a Test E-Mail', - 'maint_send_test_email_desc' => 'This sends a test e-mail to your e-mail address specified in your profile.', - 'maint_send_test_email_run' => 'Send test e-mail', - 'maint_send_test_email_success' => 'E-Mail sent to :address', - 'maint_send_test_email_mail_subject' => 'Test E-Mail', - 'maint_send_test_email_mail_greeting' => 'E-Mail delivery seems to work!', - 'maint_send_test_email_mail_text' => 'Congratulations! As you received this e-mail notification, your e-mail settings seem to be configured properly.', + 'maint_send_test_email' => 'Send a Test Email', + 'maint_send_test_email_desc' => 'This sends a test email to your email address specified in your profile.', + 'maint_send_test_email_run' => 'Send test email', + 'maint_send_test_email_success' => 'Email sent to :address', + 'maint_send_test_email_mail_subject' => 'Test Email', + 'maint_send_test_email_mail_greeting' => 'Email delivery seems to work!', + 'maint_send_test_email_mail_text' => 'Congratulations! As you received this email notification, your email settings seem to be configured properly.', // Role Settings 'roles' => 'Roles', diff --git a/tests/TestEmailTest.php b/tests/TestEmailTest.php new file mode 100644 index 000000000..c06311d84 --- /dev/null +++ b/tests/TestEmailTest.php @@ -0,0 +1,43 @@ +asAdmin()->get('/settings/maintenance'); + $formCssSelector = 'form[action$="/settings/maintenance/send-test-email"]'; + $pageView->assertElementExists($formCssSelector); + $pageView->assertElementContains($formCssSelector . ' button', 'Send Test Email'); + } + + public function test_send_test_email_endpoint_sends_email_and_redirects_user_and_shows_notification() + { + Notification::fake(); + $admin = $this->getAdmin(); + + $sendReq = $this->actingAs($admin)->post('/settings/maintenance/send-test-email'); + $sendReq->assertRedirect('/settings/maintenance#image-cleanup'); + $this->assertSessionHas('success', 'Email sent to ' . $admin->email); + + Notification::assertSentTo($admin, TestEmail::class); + } + + public function test_send_test_email_requires_settings_manage_permission() + { + Notification::fake(); + $user = $this->getViewer(); + + $sendReq = $this->actingAs($user)->post('/settings/maintenance/send-test-email'); + Notification::assertNothingSent(); + + $this->giveUserPermissions($user, ['settings-manage']); + $sendReq = $this->actingAs($user)->post('/settings/maintenance/send-test-email'); + Notification::assertSentTo($user, TestEmail::class); + } + + +} \ No newline at end of file