forked from BookStackApp/BookStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestEmailTest.php
More file actions
61 lines (48 loc) · 2.36 KB
/
TestEmailTest.php
File metadata and controls
61 lines (48 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Tests;
use BookStack\Notifications\TestEmail;
use Illuminate\Contracts\Notifications\Dispatcher;
use Illuminate\Support\Facades\Notification;
class TestEmailTest extends TestCase
{
public function test_a_send_test_button_shows()
{
$pageView = $this->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_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();
$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);
}
}