]> BookStack Code Mirror - bookstack/blob - tests/TestEmailTest.php
Merge pull request #1734 from ististudio/master
[bookstack] / tests / TestEmailTest.php
1 <?php namespace Tests;
2
3 use BookStack\Notifications\TestEmail;
4 use Illuminate\Support\Facades\Notification;
5
6 class TestEmailTest extends TestCase
7 {
8
9     public function test_a_send_test_button_shows()
10     {
11         $pageView = $this->asAdmin()->get('/settings/maintenance');
12         $formCssSelector = 'form[action$="/settings/maintenance/send-test-email"]';
13         $pageView->assertElementExists($formCssSelector);
14         $pageView->assertElementContains($formCssSelector . ' button', 'Send Test Email');
15     }
16
17     public function test_send_test_email_endpoint_sends_email_and_redirects_user_and_shows_notification()
18     {
19         Notification::fake();
20         $admin = $this->getAdmin();
21
22         $sendReq = $this->actingAs($admin)->post('/settings/maintenance/send-test-email');
23         $sendReq->assertRedirect('/settings/maintenance#image-cleanup');
24         $this->assertSessionHas('success', 'Email sent to ' . $admin->email);
25
26         Notification::assertSentTo($admin, TestEmail::class);
27     }
28
29     public function test_send_test_email_requires_settings_manage_permission()
30     {
31         Notification::fake();
32         $user = $this->getViewer();
33
34         $sendReq = $this->actingAs($user)->post('/settings/maintenance/send-test-email');
35         Notification::assertNothingSent();
36
37         $this->giveUserPermissions($user, ['settings-manage']);
38         $sendReq = $this->actingAs($user)->post('/settings/maintenance/send-test-email');
39         Notification::assertSentTo($user, TestEmail::class);
40     }
41
42
43 }