Updated email test send to show error on failure
- Added test to cover - Closes #1874
This commit is contained in:
		
							parent
							
								
									33ef1cd4fa
								
							
						
					
					
						commit
						49386b42da
					
				| 
						 | 
					@ -122,8 +122,14 @@ class SettingController extends Controller
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->checkPermission('settings-manage');
 | 
					        $this->checkPermission('settings-manage');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
            user()->notify(new TestEmail());
 | 
					            user()->notify(new TestEmail());
 | 
				
			||||||
            $this->showSuccessNotification(trans('settings.maint_send_test_email_success', ['address' => user()->email]));
 | 
					            $this->showSuccessNotification(trans('settings.maint_send_test_email_success', ['address' => user()->email]));
 | 
				
			||||||
 | 
					        } catch (\Exception $exception) {
 | 
				
			||||||
 | 
					            $errorMessage = trans('errors.maintenance_test_email_failure') . "\n" . $exception->getMessage();
 | 
				
			||||||
 | 
					            $this->showErrorNotification($errorMessage);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return redirect('/settings/maintenance#image-cleanup')->withInput();
 | 
					        return redirect('/settings/maintenance#image-cleanup')->withInput();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -96,4 +96,7 @@ return [
 | 
				
			||||||
    'api_user_no_api_permission' => 'The owner of the used API token does not have permission to make API calls',
 | 
					    'api_user_no_api_permission' => 'The owner of the used API token does not have permission to make API calls',
 | 
				
			||||||
    'api_user_token_expired' => 'The authorization token used has expired',
 | 
					    'api_user_token_expired' => 'The authorization token used has expired',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Settings & Maintenance
 | 
				
			||||||
 | 
					    'maintenance_test_email_failure' => 'Error thrown when sending a test email:',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
<?php namespace Tests;
 | 
					<?php namespace Tests;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use BookStack\Notifications\TestEmail;
 | 
					use BookStack\Notifications\TestEmail;
 | 
				
			||||||
 | 
					use Illuminate\Contracts\Notifications\Dispatcher;
 | 
				
			||||||
use Illuminate\Support\Facades\Notification;
 | 
					use Illuminate\Support\Facades\Notification;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestEmailTest extends TestCase
 | 
					class TestEmailTest extends TestCase
 | 
				
			||||||
| 
						 | 
					@ -26,6 +27,24 @@ class TestEmailTest extends TestCase
 | 
				
			||||||
        Notification::assertSentTo($admin, TestEmail::class);
 | 
					        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()
 | 
					    public function test_send_test_email_requires_settings_manage_permission()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Notification::fake();
 | 
					        Notification::fake();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue