]> BookStack Code Mirror - bookstack/blob - tests/TestEmailTest.php
Update form.blade.php
[bookstack] / tests / TestEmailTest.php
1 <?php namespace Tests;
2
3 use BookStack\Notifications\TestEmail;
4 use Illuminate\Contracts\Notifications\Dispatcher;
5 use Illuminate\Support\Facades\Notification;
6
7 class TestEmailTest extends TestCase
8 {
9
10     public function test_a_send_test_button_shows()
11     {
12         $pageView = $this->asAdmin()->get('/settings/maintenance');
13         $formCssSelector = 'form[action$="/settings/maintenance/send-test-email"]';
14         $pageView->assertElementExists($formCssSelector);
15         $pageView->assertElementContains($formCssSelector . ' button', 'Send Test Email');
16     }
17
18     public function test_send_test_email_endpoint_sends_email_and_redirects_user_and_shows_notification()
19     {
20         Notification::fake();
21         $admin = $this->getAdmin();
22
23         $sendReq = $this->actingAs($admin)->post('/settings/maintenance/send-test-email');
24         $sendReq->assertRedirect('/settings/maintenance#image-cleanup');
25         $this->assertSessionHas('success', 'Email sent to ' . $admin->email);
26
27         Notification::assertSentTo($admin, TestEmail::class);
28     }
29
30     public function test_send_test_email_failure_displays_error_notification()
31     {
32         $mockDispatcher = $this->mock(Dispatcher::class);
33         $this->app[Dispatcher::class] = $mockDispatcher;
34
35         $exception = new \Exception('A random error occurred when testing an email');
36         $mockDispatcher->shouldReceive('send')->andThrow($exception);
37
38         $admin = $this->getAdmin();
39         $sendReq = $this->actingAs($admin)->post('/settings/maintenance/send-test-email');
40         $sendReq->assertRedirect('/settings/maintenance#image-cleanup');
41         $this->assertSessionHas('error');
42
43         $message = session()->get('error');
44         $this->assertStringContainsString('Error thrown when sending a test email:', $message);
45         $this->assertStringContainsString('A random error occurred when testing an email', $message);
46     }
47
48     public function test_send_test_email_requires_settings_manage_permission()
49     {
50         Notification::fake();
51         $user = $this->getViewer();
52
53         $sendReq = $this->actingAs($user)->post('/settings/maintenance/send-test-email');
54         Notification::assertNothingSent();
55
56         $this->giveUserPermissions($user, ['settings-manage']);
57         $sendReq = $this->actingAs($user)->post('/settings/maintenance/send-test-email');
58         Notification::assertSentTo($user, TestEmail::class);
59     }
60
61
62 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.