Skip to content

Commit

Permalink
Fix multiple notification recipients (#24957)
Browse files Browse the repository at this point in the history
* Fix multiple notification recipients

PR #24606 unfortunately broke on-demand notifications addressed to multiple recipients.
This fixes Issue  #24729 and #24956

* Added test for multiple mail recipients.

* Remove unnecessary spaces.
  • Loading branch information
PaegleK authored and taylorotwell committed Jul 26, 2018
1 parent f1537b9 commit 7bc1103
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Notifications/Channels/MailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ protected function getRecipients($notifiable, $notification, $message)

return collect($recipients)->mapWithKeys(function ($recipient, $email) {
return is_numeric($email)
? [(is_string($recipient) ? $recipient : $recipient->email)]
? [$email => (is_string($recipient) ? $recipient : $recipient->email)]
: [$email => $recipient];
})->all();
}
Expand Down
41 changes: 41 additions & 0 deletions tests/Integration/Notifications/SendingMailNotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,36 @@ public function test_mail_is_sent_with_subject()
$user->notify($notification);
}

public function test_mail_is_sent_to_multiple_adresses()
{
$notification = new TestMailNotificationWithSubject;

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

$this->markdown->shouldReceive('render')->once()->andReturn('htmlContent');
$this->markdown->shouldReceive('renderText')->once()->andReturn('textContent');

$this->mailer->shouldReceive('send')->once()->with(
['html' => 'htmlContent', 'text' => 'textContent'],
$notification->toMail($user)->toArray(),
Mockery::on(function ($closure) {
$message = Mockery::mock(\Illuminate\Mail\Message::class);

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

$message->shouldReceive('subject')->once()->with('mail custom subject');

$closure($message);

return true;
})
);

$user->notify($notification);
}

public function test_mail_is_sent_using_mailable()
{
$notification = new TestMailNotificationWithMailable;
Expand Down Expand Up @@ -205,6 +235,17 @@ public function routeNotificationForMail($notification)
}
}

class NotifiableUserWithMultipleAddreses extends NotifiableUser
{
public function routeNotificationForMail($notification)
{
return [
'foo_'.$this->email,
'bar_'.$this->email,
];
}
}

class TestMailNotification extends Notification
{
public function via($notifiable)
Expand Down

0 comments on commit 7bc1103

Please sign in to comment.