-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate invalidity of captured HTML in notification-sent Mails
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Laravel\Telescope\Tests\Watchers; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use Illuminate\Notifications\Notification as BaseNotification; | ||
use Illuminate\Support\Facades\Notification; | ||
use Laravel\Telescope\EntryType; | ||
use Laravel\Telescope\Tests\FeatureTestCase; | ||
use Laravel\Telescope\Watchers\MailWatcher; | ||
use Laravel\Telescope\Watchers\NotificationWatcher; | ||
|
||
class MailNotificationTest extends FeatureTestCase | ||
{ | ||
protected function getEnvironmentSetUp($app) | ||
{ | ||
parent::getEnvironmentSetUp($app); | ||
|
||
$app->get('config')->set('telescope.watchers', [ | ||
MailWatcher::class => true, | ||
NotificationWatcher::class => true, | ||
]); | ||
|
||
$app->get('config')->set('mail.driver', 'array'); | ||
} | ||
|
||
/** @test */ | ||
public function test_mail_watcher_registers_valid_html() | ||
{ | ||
Notification::route('mail', 'to@laravel.com') | ||
->notify(new TestMailNotification()); | ||
|
||
$entry = $this->loadTelescopeEntries()->firstWhere('type', EntryType::MAIL); | ||
|
||
$this->assertSame(EntryType::MAIL, $entry->type); | ||
|
||
$doc = new \DOMDocument(); | ||
$doc->loadHTML($entry->content['html']); | ||
} | ||
} | ||
|
||
class TestMailNotification extends BaseNotification | ||
{ | ||
use Queueable; | ||
|
||
public function via($notifiable) | ||
{ | ||
return ['mail']; | ||
} | ||
|
||
public function toMail($notifiable) | ||
{ | ||
return (new MailMessage()) | ||
->subject('Check out this awesome HTML and raw email!') | ||
->line('The introduction to the notification.') | ||
->action('Notification Action', url('/')) | ||
->line('Thank you for using our application!'); | ||
} | ||
} |