Skip to content

Commit

Permalink
Add support for setting mail notification priority.
Browse files Browse the repository at this point in the history
  • Loading branch information
KKSzymanowski committed Sep 28, 2016
1 parent 5a719af commit 376c0a9
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Notifications/Channels/MailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public function send($notifiable, Notification $notification)
foreach ($message->rawAttachments as $attachment) {
$m->attachData($attachment['data'], $attachment['name'], $attachment['options']);
}

if($message->priority !== null) {
$m->setPriority($message->priority);
}
});
}
}
22 changes: 22 additions & 0 deletions src/Illuminate/Notifications/Messages/MailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class MailMessage extends SimpleMessage
*/
public $rawAttachments = [];

/**
* Priority level of the message.
*
* @var int
*/
public $priority = null;

/**
* Set the view for the mail message.
*
Expand Down Expand Up @@ -129,4 +136,19 @@ public function data()
{
return array_merge($this->toArray(), $this->viewData);
}

/**
* Set the priority of this message.
*
* The value is an integer where 1 is the highest priority and 5 is the lowest.
*
* @param int $level
* @return $this
*/
public function priority($level)
{
$this->priority = $level;

return $this;
}
}
40 changes: 40 additions & 0 deletions tests/Notifications/NotificationMailChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,37 @@ public function testMessageWithToAddress()
$channel->send($notifiable, $notification);
}

public function testMessageWithPriority()
{
$notification = new NotificationMailChannelTestNotificationWithPriority;
$notifiable = new NotificationMailChannelTestNotifiable;

$message = $notification->toMail($notifiable);
$data = $message->toArray();

$channel = new Illuminate\Notifications\Channels\MailChannel(
$mailer = Mockery::mock(Illuminate\Contracts\Mail\Mailer::class)
);

$views = ['notifications::email', 'notifications::email-plain'];

$mailer->shouldReceive('send')->with($views, $data, Mockery::on(function ($closure) {
$mock = Mockery::mock('Illuminate\Mailer\Message');

$mock->shouldReceive('subject')->once();

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

$mock->shouldReceive('setPriority')->once()->with(1);

$closure($mock);

return true;
}));

$channel->send($notifiable, $notification);
}

public function testMessageWithMailableContract()
{
$notification = new NotificationMailChannelTestNotificationWithMailableContract;
Expand Down Expand Up @@ -287,6 +318,15 @@ public function toMail($notifiable)
}
}

class NotificationMailChannelTestNotificationWithPriority extends Notification
{
public function toMail($notifiable)
{
return (new MailMessage)
->priority(1);
}
}

class NotificationMailChannelTestNotificationWithMailableContract extends Notification
{
public function toMail($notifiable)
Expand Down

0 comments on commit 376c0a9

Please sign in to comment.