Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Add plain text only notifications #33781

Merged
merged 3 commits into from
Aug 7, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add test for html only notifications
  • Loading branch information
pawelmysior committed Aug 7, 2020
commit f9731a1dc09a2402ac2ba469a9012708d0d179b6
49 changes: 48 additions & 1 deletion tests/Integration/Notifications/SendingMailNotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public function testMailIsSentUsingMailable()
$user->notify($notification);
}

public function testMailIsSentUsingMailMessageWithPlain()
public function testMailIsSentUsingMailMessageWithHtmlAndPlain()
{
$notification = new TestMailNotificationWithPlain;
$notification->id = Str::uuid()->toString();
Expand Down Expand Up @@ -280,6 +280,38 @@ public function testMailIsSentUsingMailMessageWithPlain()

$user->notify($notification);
}

public function testMailIsSentUsingMailMessageWithHtmlOnly()
{
$notification = new TestMailNotificationWithHtmlOnly;
$notification->id = Str::uuid()->toString();

$user = NotifiableUser::forceCreate([
'email' => 'taylor@laravel.com',
]);

$this->mailer->shouldReceive('send')->once()->with(
['html' => 'html', 'text' => null],
array_merge($notification->toMail($user)->toArray(), [
'__laravel_notification_id' => $notification->id,
'__laravel_notification' => get_class($notification),
'__laravel_notification_queued' => false,
]),
m::on(function ($closure) {
$message = m::mock(Message::class);

$message->shouldReceive('to')->once()->with(['taylor@laravel.com']);

$message->shouldReceive('subject')->once()->with('Test Mail Notification With Html Only');

$closure($message);

return true;
})
);

$user->notify($notification);
}
}

class NotifiableUser extends Model
Expand Down Expand Up @@ -378,3 +410,18 @@ public function toMail($notifiable)
->text('plain');
}
}

class TestMailNotificationWithHtmlOnly extends Notification
{
public function via($notifiable)
{
return [MailChannel::class];
}

public function toMail($notifiable)
{
return (new MailMessage)
->view('html')
->text(null);
}
}