Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Propaganistas committed Jun 15, 2018
1 parent e41bee9 commit d87dedd
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/Integration/Notifications/SendingMailNotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function setUp()
Schema::create('users', function ($table) {
$table->increments('id');
$table->string('email');
$table->string('name')->nullable();
});
}

Expand Down Expand Up @@ -102,6 +103,47 @@ public function test_mail_is_sent()
$user->notify($notification);
}

public function test_mail_is_sent_to_named_address()
{
$notification = new TestMailNotification;

$user = NotifiableUserWithNamedAddress::forceCreate([
'email' => 'taylor@laravel.com',
'name' => 'Taylor Otwell',
]);

$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(['taylor@laravel.com' => 'Taylor Otwell', 'foo_taylor@laravel.com']);

$message->shouldReceive('cc')->once()->with('cc@deepblue.com', 'cc');

$message->shouldReceive('bcc')->once()->with('bcc@deepblue.com', 'bcc');

$message->shouldReceive('from')->once()->with('jack@deepblue.com', 'Jacques Mayol');

$message->shouldReceive('replyTo')->once()->with('jack@deepblue.com', 'Jacques Mayol');

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

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

$closure($message);

return true;
})
);

$user->notify($notification);
}

public function test_mail_is_sent_with_subject()
{
$notification = new TestMailNotificationWithSubject;
Expand Down Expand Up @@ -152,6 +194,17 @@ class NotifiableUser extends Model
public $timestamps = false;
}

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

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

0 comments on commit d87dedd

Please sign in to comment.