@@ -249,9 +249,9 @@ public function testMailIsSentUsingMailable()
249
249
$ user ->notify ($ notification );
250
250
}
251
251
252
- public function testMailIsSentUsingMailMessageWithPlain ()
252
+ public function testMailIsSentUsingMailMessageWithHtmlAndPlain ()
253
253
{
254
- $ notification = new TestMailNotificationWithPlain ;
254
+ $ notification = new TestMailNotificationWithHtmlAndPlain ;
255
255
$ notification ->id = Str::uuid ()->toString ();
256
256
257
257
$ user = NotifiableUser::forceCreate ([
@@ -270,7 +270,71 @@ public function testMailIsSentUsingMailMessageWithPlain()
270
270
271
271
$ message->
shouldReceive (
'to ' )->
once ()->
with ([
'[email protected] ' ]);
272
272
273
- $ message ->shouldReceive ('subject ' )->once ()->with ('Test Mail Notification With Plain ' );
273
+ $ message ->shouldReceive ('subject ' )->once ()->with ('Test Mail Notification With Html And Plain ' );
274
+
275
+ $ closure ($ message );
276
+
277
+ return true ;
278
+ })
279
+ );
280
+
281
+ $ user ->notify ($ notification );
282
+ }
283
+
284
+ public function testMailIsSentUsingMailMessageWithHtmlOnly ()
285
+ {
286
+ $ notification = new TestMailNotificationWithHtmlOnly ;
287
+ $ notification ->id = Str::uuid ()->toString ();
288
+
289
+ $ user = NotifiableUser::forceCreate ([
290
+
291
+ ]);
292
+
293
+ $ this ->mailer ->shouldReceive ('send ' )->once ()->with (
294
+ ['html ' => 'html ' , 'text ' => null ],
295
+ array_merge ($ notification ->toMail ($ user )->toArray (), [
296
+ '__laravel_notification_id ' => $ notification ->id ,
297
+ '__laravel_notification ' => get_class ($ notification ),
298
+ '__laravel_notification_queued ' => false ,
299
+ ]),
300
+ m::on (function ($ closure ) {
301
+ $ message = m::mock (Message::class);
302
+
303
+ $ message->
shouldReceive (
'to ' )->
once ()->
with ([
'[email protected] ' ]);
304
+
305
+ $ message ->shouldReceive ('subject ' )->once ()->with ('Test Mail Notification With Html Only ' );
306
+
307
+ $ closure ($ message );
308
+
309
+ return true ;
310
+ })
311
+ );
312
+
313
+ $ user ->notify ($ notification );
314
+ }
315
+
316
+ public function testMailIsSentUsingMailMessageWithPlainOnly ()
317
+ {
318
+ $ notification = new TestMailNotificationWithPlainOnly ;
319
+ $ notification ->id = Str::uuid ()->toString ();
320
+
321
+ $ user = NotifiableUser::forceCreate ([
322
+
323
+ ]);
324
+
325
+ $ this ->mailer ->shouldReceive ('send ' )->once ()->with (
326
+ ['html ' => null , 'text ' => 'plain ' ],
327
+ array_merge ($ notification ->toMail ($ user )->toArray (), [
328
+ '__laravel_notification_id ' => $ notification ->id ,
329
+ '__laravel_notification ' => get_class ($ notification ),
330
+ '__laravel_notification_queued ' => false ,
331
+ ]),
332
+ m::on (function ($ closure ) {
333
+ $ message = m::mock (Message::class);
334
+
335
+ $ message->
shouldReceive (
'to ' )->
once ()->
with ([
'[email protected] ' ]);
336
+
337
+ $ message ->shouldReceive ('subject ' )->once ()->with ('Test Mail Notification With Plain Only ' );
274
338
275
339
$ closure ($ message );
276
340
@@ -364,7 +428,7 @@ public function toMail($notifiable)
364
428
}
365
429
}
366
430
367
- class TestMailNotificationWithPlain extends Notification
431
+ class TestMailNotificationWithHtmlAndPlain extends Notification
368
432
{
369
433
public function via ($ notifiable )
370
434
{
@@ -378,3 +442,33 @@ public function toMail($notifiable)
378
442
->text ('plain ' );
379
443
}
380
444
}
445
+
446
+ class TestMailNotificationWithHtmlOnly extends Notification
447
+ {
448
+ public function via ($ notifiable )
449
+ {
450
+ return [MailChannel::class];
451
+ }
452
+
453
+ public function toMail ($ notifiable )
454
+ {
455
+ return (new MailMessage )
456
+ ->view ('html ' )
457
+ ->text (null );
458
+ }
459
+ }
460
+
461
+ class TestMailNotificationWithPlainOnly extends Notification
462
+ {
463
+ public function via ($ notifiable )
464
+ {
465
+ return [MailChannel::class];
466
+ }
467
+
468
+ public function toMail ($ notifiable )
469
+ {
470
+ return (new MailMessage )
471
+ ->view (null )
472
+ ->text ('plain ' );
473
+ }
474
+ }
0 commit comments