@@ -74,42 +74,108 @@ public function testMailIsSent()
74
74
75
75
]);
76
76
77
+ $ this ->markdown ->shouldReceive ('theme ' )->twice ()->with ('default ' )->andReturn ($ this ->markdown );
77
78
$ this ->markdown ->shouldReceive ('render ' )->once ()->andReturn ('htmlContent ' );
78
79
$ this ->markdown ->shouldReceive ('renderText ' )->once ()->andReturn ('textContent ' );
79
80
80
- $ this ->mailer ->shouldReceive ('send ' )->once ()->with (
81
- ['html ' => 'htmlContent ' , 'text ' => 'textContent ' ],
82
- array_merge ($ notification ->toMail ($ user )->toArray (), [
83
- '__laravel_notification_id ' => $ notification ->id ,
84
- '__laravel_notification ' => get_class ($ notification ),
85
- '__laravel_notification_queued ' => false ,
86
- ]),
87
- m::on (function ($ closure ) {
88
- $ message = m::mock (Message::class);
81
+ $ this ->setMailerSendAssertions ($ notification , $ user , function ($ closure ) {
82
+ $ message = m::mock (Message::class);
89
83
90
- $ message->
shouldReceive (
'to ' )->
once ()->
with ([
'[email protected] ' ]);
84
+ $ message->
shouldReceive (
'to ' )->
once ()->
with ([
'[email protected] ' ]);
91
85
92
- $ message->
shouldReceive (
'cc ' )->
once ()->
with (
'[email protected] ' ,
'cc ' );
86
+ $ message->
shouldReceive (
'cc ' )->
once ()->
with (
'[email protected] ' ,
'cc ' );
93
87
94
- $ message->
shouldReceive (
'bcc ' )->
once ()->
with (
'[email protected] ' ,
'bcc ' );
88
+ $ message->
shouldReceive (
'bcc ' )->
once ()->
with (
'[email protected] ' ,
'bcc ' );
95
89
96
- $ message->
shouldReceive (
'from ' )->
once ()->
with (
'[email protected] ' ,
'Jacques Mayol ' );
90
+ $ message->
shouldReceive (
'from ' )->
once ()->
with (
'[email protected] ' ,
'Jacques Mayol ' );
97
91
98
- $ message->
shouldReceive (
'replyTo ' )->
once ()->
with (
'[email protected] ' ,
'Jacques Mayol ' );
92
+ $ message->
shouldReceive (
'replyTo ' )->
once ()->
with (
'[email protected] ' ,
'Jacques Mayol ' );
99
93
100
- $ message ->shouldReceive ('subject ' )->once ()->with ('Test Mail Notification ' );
94
+ $ message ->shouldReceive ('subject ' )->once ()->with ('Test Mail Notification ' );
101
95
102
- $ message ->shouldReceive ('priority ' )->once ()->with (1 );
96
+ $ message ->shouldReceive ('priority ' )->once ()->with (1 );
103
97
104
- $ closure ($ message );
98
+ $ closure ($ message );
105
99
106
- return true ;
107
- })
108
- );
100
+ return true ;
101
+ });
109
102
110
103
$ user ->notify ($ notification );
111
104
}
112
105
106
+ public function testMailIsSentWithCustomTheme ()
107
+ {
108
+ $ notification = new TestMailNotificationWithCustomTheme ;
109
+ $ notification ->id = Str::uuid ()->toString ();
110
+
111
+ $ user = NotifiableUser::forceCreate ([
112
+
113
+ ]);
114
+
115
+ $ this ->markdown ->shouldReceive ('theme ' )->twice ()->with ('my-custom-theme ' )->andReturn ($ this ->markdown );
116
+ $ this ->markdown ->shouldReceive ('render ' )->once ()->andReturn ('htmlContent ' );
117
+ $ this ->markdown ->shouldReceive ('renderText ' )->once ()->andReturn ('textContent ' );
118
+
119
+ $ this ->setMailerSendAssertions ($ notification , $ user , function ($ closure ) {
120
+ $ message = m::mock (Message::class);
121
+
122
+ $ message->
shouldReceive (
'to ' )->
once ()->
with ([
'[email protected] ' ]);
123
+
124
+ $ message->
shouldReceive (
'cc ' )->
once ()->
with (
'[email protected] ' ,
'cc ' );
125
+
126
+ $ message->
shouldReceive (
'bcc ' )->
once ()->
with (
'[email protected] ' ,
'bcc ' );
127
+
128
+ $ message->
shouldReceive (
'from ' )->
once ()->
with (
'[email protected] ' ,
'Jacques Mayol ' );
129
+
130
+ $ message->
shouldReceive (
'replyTo ' )->
once ()->
with (
'[email protected] ' ,
'Jacques Mayol ' );
131
+
132
+ $ message ->shouldReceive ('subject ' )->once ()->with ('Test Mail Notification With Custom Theme ' );
133
+
134
+ $ message ->shouldReceive ('priority ' )->once ()->with (1 );
135
+
136
+ $ closure ($ message );
137
+
138
+ return true ;
139
+ });
140
+
141
+ $ user ->notify ($ notification );
142
+ }
143
+
144
+ private function setMailerSendAssertions (
145
+ Notification $ notification ,
146
+ NotifiableUser $ user ,
147
+ callable $ callbackExpectationClosure
148
+ ) {
149
+ $ this ->mailer ->shouldReceive ('send ' )->once ()->withArgs (function (...$ args ) use ($ notification , $ user , $ callbackExpectationClosure ) {
150
+ $ viewArray = $ args [0 ];
151
+
152
+ if (! m::on (fn ($ closure ) => $ closure ([]) === 'htmlContent ' )->match ($ viewArray ['html ' ])) {
153
+ return false ;
154
+ }
155
+
156
+ if (! m::on (fn ($ closure ) => $ closure ([]) === 'textContent ' )->match ($ viewArray ['text ' ])) {
157
+ return false ;
158
+ }
159
+
160
+ $ data = $ args [1 ];
161
+
162
+ $ expected = array_merge ($ notification ->toMail ($ user )->toArray (), [
163
+ '__laravel_notification_id ' => $ notification ->id ,
164
+ '__laravel_notification ' => get_class ($ notification ),
165
+ '__laravel_notification_queued ' => false ,
166
+ ]);
167
+
168
+ if (array_keys ($ data ) !== array_keys ($ expected )) {
169
+ return false ;
170
+ }
171
+ if (array_values ($ data ) !== array_values ($ expected )) {
172
+ return false ;
173
+ }
174
+
175
+ return m::on ($ callbackExpectationClosure )->match ($ args [2 ]);
176
+ });
177
+ }
178
+
113
179
public function testMailIsSentToNamedAddress ()
114
180
{
115
181
$ notification = new TestMailNotification ;
@@ -120,38 +186,31 @@ public function testMailIsSentToNamedAddress()
120
186
'name ' => 'Taylor Otwell ' ,
121
187
]);
122
188
189
+ $ this ->markdown ->shouldReceive ('theme ' )->twice ()->with ('default ' )->andReturn ($ this ->markdown );
123
190
$ this ->markdown ->shouldReceive ('render ' )->once ()->andReturn ('htmlContent ' );
124
191
$ this ->markdown ->shouldReceive ('renderText ' )->once ()->andReturn ('textContent ' );
125
192
126
- $ this ->mailer ->shouldReceive ('send ' )->once ()->with (
127
- ['html ' => 'htmlContent ' , 'text ' => 'textContent ' ],
128
- array_merge ($ notification ->toMail ($ user )->toArray (), [
129
- '__laravel_notification_id ' => $ notification ->id ,
130
- '__laravel_notification ' => get_class ($ notification ),
131
- '__laravel_notification_queued ' => false ,
132
- ]),
133
- m::on (function ($ closure ) {
134
- $ message = m::mock (Message::class);
193
+ $ this ->setMailerSendAssertions ($ notification , $ user , function ($ closure ) {
194
+ $ message = m::mock (Message::class);
135
195
136
- $ message->
shouldReceive (
'to ' )->
once ()->
with ([
'[email protected] ' =>
'Taylor Otwell ' ,
'[email protected] ' ]);
196
+ $ message->
shouldReceive (
'to ' )->
once ()->
with ([
'[email protected] ' =>
'Taylor Otwell ' ,
'[email protected] ' ]);
137
197
138
- $ message->
shouldReceive (
'cc ' )->
once ()->
with (
'[email protected] ' ,
'cc ' );
198
+ $ message->
shouldReceive (
'cc ' )->
once ()->
with (
'[email protected] ' ,
'cc ' );
139
199
140
- $ message->
shouldReceive (
'bcc ' )->
once ()->
with (
'[email protected] ' ,
'bcc ' );
200
+ $ message->
shouldReceive (
'bcc ' )->
once ()->
with (
'[email protected] ' ,
'bcc ' );
141
201
142
- $ message->
shouldReceive (
'from ' )->
once ()->
with (
'[email protected] ' ,
'Jacques Mayol ' );
202
+ $ message->
shouldReceive (
'from ' )->
once ()->
with (
'[email protected] ' ,
'Jacques Mayol ' );
143
203
144
- $ message->
shouldReceive (
'replyTo ' )->
once ()->
with (
'[email protected] ' ,
'Jacques Mayol ' );
204
+ $ message->
shouldReceive (
'replyTo ' )->
once ()->
with (
'[email protected] ' ,
'Jacques Mayol ' );
145
205
146
- $ message ->shouldReceive ('subject ' )->once ()->with ('Test Mail Notification ' );
206
+ $ message ->shouldReceive ('subject ' )->once ()->with ('Test Mail Notification ' );
147
207
148
- $ message ->shouldReceive ('priority ' )->once ()->with (1 );
208
+ $ message ->shouldReceive ('priority ' )->once ()->with (1 );
149
209
150
- $ closure ($ message );
210
+ $ closure ($ message );
151
211
152
- return true ;
153
- })
154
- );
212
+ return true ;
213
+ });
155
214
156
215
$ user ->notify ($ notification );
157
216
}
@@ -165,28 +224,21 @@ public function testMailIsSentWithSubject()
165
224
166
225
]);
167
226
227
+ $ this ->markdown ->shouldReceive ('theme ' )->with ('default ' )->twice ()->andReturn ($ this ->markdown );
168
228
$ this ->markdown ->shouldReceive ('render ' )->once ()->andReturn ('htmlContent ' );
169
229
$ this ->markdown ->shouldReceive ('renderText ' )->once ()->andReturn ('textContent ' );
170
230
171
- $ this ->mailer ->shouldReceive ('send ' )->once ()->with (
172
- ['html ' => 'htmlContent ' , 'text ' => 'textContent ' ],
173
- array_merge ($ notification ->toMail ($ user )->toArray (), [
174
- '__laravel_notification_id ' => $ notification ->id ,
175
- '__laravel_notification ' => get_class ($ notification ),
176
- '__laravel_notification_queued ' => false ,
177
- ]),
178
- m::on (function ($ closure ) {
179
- $ message = m::mock (Message::class);
231
+ $ this ->setMailerSendAssertions ($ notification , $ user , function ($ closure ) {
232
+ $ message = m::mock (Message::class);
180
233
181
- $ message->
shouldReceive (
'to ' )->
once ()->
with ([
'[email protected] ' ]);
234
+ $ message->
shouldReceive (
'to ' )->
once ()->
with ([
'[email protected] ' ]);
182
235
183
- $ message ->shouldReceive ('subject ' )->once ()->with ('mail custom subject ' );
236
+ $ message ->shouldReceive ('subject ' )->once ()->with ('mail custom subject ' );
184
237
185
- $ closure ($ message );
238
+ $ closure ($ message );
186
239
187
- return true ;
188
- })
189
- );
240
+ return true ;
241
+ });
190
242
191
243
$ user ->notify ($ notification );
192
244
}
@@ -200,28 +252,21 @@ public function testMailIsSentToMultipleAddresses()
200
252
201
253
]);
202
254
255
+ $ this ->markdown ->shouldReceive ('theme ' )->with ('default ' )->twice ()->andReturn ($ this ->markdown );
203
256
$ this ->markdown ->shouldReceive ('render ' )->once ()->andReturn ('htmlContent ' );
204
257
$ this ->markdown ->shouldReceive ('renderText ' )->once ()->andReturn ('textContent ' );
205
258
206
- $ this ->mailer ->shouldReceive ('send ' )->once ()->with (
207
- ['html ' => 'htmlContent ' , 'text ' => 'textContent ' ],
208
- array_merge ($ notification ->toMail ($ user )->toArray (), [
209
- '__laravel_notification_id ' => $ notification ->id ,
210
- '__laravel_notification ' => get_class ($ notification ),
211
- '__laravel_notification_queued ' => false ,
212
- ]),
213
- m::on (function ($ closure ) {
214
- $ message = m::mock (Message::class);
259
+ $ this ->setMailerSendAssertions ($ notification , $ user , function ($ closure ) {
260
+ $ message = m::mock (Message::class);
215
261
216
- $ message->
shouldReceive (
'to ' )->
once ()->
with ([
'[email protected] ' ,
'[email protected] ' ]);
262
+ $ message->
shouldReceive (
'to ' )->
once ()->
with ([
'[email protected] ' ,
'[email protected] ' ]);
217
263
218
- $ message ->shouldReceive ('subject ' )->once ()->with ('mail custom subject ' );
264
+ $ message ->shouldReceive ('subject ' )->once ()->with ('mail custom subject ' );
219
265
220
- $ closure ($ message );
266
+ $ closure ($ message );
221
267
222
- return true ;
223
- })
224
- );
268
+ return true ;
269
+ });
225
270
226
271
$ user ->notify ($ notification );
227
272
}
@@ -457,3 +502,24 @@ public function toMail($notifiable)
457
502
->view ([null , 'plain ' ]);
458
503
}
459
504
}
505
+
506
+ class TestMailNotificationWithCustomTheme extends Notification
507
+ {
508
+ public function via ($ notifiable )
509
+ {
510
+ return [MailChannel::class];
511
+ }
512
+
513
+ public function toMail ($ notifiable )
514
+ {
515
+ return (new MailMessage )
516
+ ->priority (1 )
517
+
518
+
519
+ ->
from (
'[email protected] ' ,
'Jacques Mayol ' )
520
+ ->
replyTo (
'[email protected] ' ,
'Jacques Mayol ' )
521
+ ->line ('The introduction to the notification. ' )
522
+ ->theme ('my-custom-theme ' )
523
+ ->mailer ('foo ' );
524
+ }
525
+ }
0 commit comments