Skip to content

Commit 90b378d

Browse files
authored
Revert changes to MailMessage (#33816)
1 parent de6b106 commit 90b378d

File tree

5 files changed

+41
-48
lines changed

5 files changed

+41
-48
lines changed

src/Illuminate/Notifications/Channels/MailChannel.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,8 @@ protected function messageBuilder($notifiable, $notification, $message)
8989
*/
9090
protected function buildView($message)
9191
{
92-
if ($message->view || $message->textView) {
93-
return [
94-
'html' => $message->view,
95-
'text' => $message->textView,
96-
];
92+
if ($message->view) {
93+
return $message->view;
9794
}
9895

9996
if (property_exists($message, 'theme') && ! is_null($message->theme)) {

src/Illuminate/Notifications/Messages/MailMessage.php

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ class MailMessage extends SimpleMessage implements Renderable
1717
*/
1818
public $view;
1919

20-
/**
21-
* The plain text view to use for the message.
22-
*
23-
* @var string
24-
*/
25-
public $textView;
26-
2720
/**
2821
* The view data for the message.
2922
*
@@ -111,28 +104,13 @@ class MailMessage extends SimpleMessage implements Renderable
111104
public function view($view, array $data = [])
112105
{
113106
$this->view = $view;
114-
$this->viewData = array_merge($this->viewData, $data);
107+
$this->viewData = $data;
115108

116109
$this->markdown = null;
117110

118111
return $this;
119112
}
120113

121-
/**
122-
* Set the plain text view for the message.
123-
*
124-
* @param string $textView
125-
* @param array $data
126-
* @return $this
127-
*/
128-
public function text($textView, array $data = [])
129-
{
130-
$this->textView = $textView;
131-
$this->viewData = array_merge($this->viewData, $data);
132-
133-
return $this;
134-
}
135-
136114
/**
137115
* Set the Markdown template for the notification.
138116
*
@@ -331,13 +309,9 @@ protected function arrayOfAddresses($address)
331309
*/
332310
public function render()
333311
{
334-
if (isset($this->view) || isset($this->textView)) {
312+
if (isset($this->view)) {
335313
return Container::getInstance()->make('mailer')->render(
336-
[
337-
'html' => $this->view,
338-
'text' => $this->textView,
339-
],
340-
$this->data()
314+
$this->view, $this->data()
341315
);
342316
}
343317

tests/Integration/Notifications/SendingMailNotificationsTest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public function testMailIsSentUsingMailMessageWithHtmlAndPlain()
259259
]);
260260

261261
$this->mailer->shouldReceive('send')->once()->with(
262-
['html' => 'html', 'text' => 'plain'],
262+
['html', 'plain'],
263263
array_merge($notification->toMail($user)->toArray(), [
264264
'__laravel_notification_id' => $notification->id,
265265
'__laravel_notification' => get_class($notification),
@@ -291,7 +291,7 @@ public function testMailIsSentUsingMailMessageWithHtmlOnly()
291291
]);
292292

293293
$this->mailer->shouldReceive('send')->once()->with(
294-
['html' => 'html', 'text' => null],
294+
'html',
295295
array_merge($notification->toMail($user)->toArray(), [
296296
'__laravel_notification_id' => $notification->id,
297297
'__laravel_notification' => get_class($notification),
@@ -323,7 +323,7 @@ public function testMailIsSentUsingMailMessageWithPlainOnly()
323323
]);
324324

325325
$this->mailer->shouldReceive('send')->once()->with(
326-
['html' => null, 'text' => 'plain'],
326+
[null, 'plain'],
327327
array_merge($notification->toMail($user)->toArray(), [
328328
'__laravel_notification_id' => $notification->id,
329329
'__laravel_notification' => get_class($notification),
@@ -438,8 +438,7 @@ public function via($notifiable)
438438
public function toMail($notifiable)
439439
{
440440
return (new MailMessage)
441-
->view('html')
442-
->text('plain');
441+
->view(['html', 'plain']);
443442
}
444443
}
445444

@@ -453,8 +452,7 @@ public function via($notifiable)
453452
public function toMail($notifiable)
454453
{
455454
return (new MailMessage)
456-
->view('html')
457-
->text(null);
455+
->view('html');
458456
}
459457
}
460458

@@ -468,7 +466,6 @@ public function via($notifiable)
468466
public function toMail($notifiable)
469467
{
470468
return (new MailMessage)
471-
->view(null)
472-
->text('plain');
469+
->view([null, 'plain']);
473470
}
474471
}

tests/Notifications/NotificationMailMessageTest.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,27 @@ public function testTemplate()
1818
$this->assertSame('notifications::foo', $message->markdown);
1919
}
2020

21+
public function testHtmlAndPlainView()
22+
{
23+
$message = new MailMessage;
24+
25+
$this->assertNull($message->view);
26+
$this->assertSame([], $message->viewData);
27+
28+
$message->view(['notifications::foo', 'notifications::bar'], [
29+
'foo' => 'bar',
30+
]);
31+
32+
$this->assertSame('notifications::foo', $message->view[0]);
33+
$this->assertSame('notifications::bar', $message->view[1]);
34+
$this->assertSame(['foo' => 'bar'], $message->viewData);
35+
}
36+
2137
public function testHtmlView()
2238
{
2339
$message = new MailMessage;
2440

25-
$this->assertSame(null, $message->view);
41+
$this->assertNull($message->view);
2642
$this->assertSame([], $message->viewData);
2743

2844
$message->view('notifications::foo', [
@@ -37,14 +53,14 @@ public function testPlainView()
3753
{
3854
$message = new MailMessage;
3955

40-
$this->assertSame(null, $message->textView);
56+
$this->assertNull($message->view);
4157
$this->assertSame([], $message->viewData);
4258

43-
$message->text('notifications::foo', [
59+
$message->view([null, 'notifications::foo'], [
4460
'foo' => 'bar',
4561
]);
4662

47-
$this->assertSame('notifications::foo', $message->textView);
63+
$this->assertSame('notifications::foo', $message->view[1]);
4864
$this->assertSame(['foo' => 'bar'], $message->viewData);
4965
}
5066

tests/Notifications/NotificationSendQueuedNotificationTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace Illuminate\Tests\Notifications;
44

55
use Illuminate\Contracts\Database\ModelIdentifier;
6+
use Illuminate\Database\Eloquent\Model;
67
use Illuminate\Notifications\AnonymousNotifiable;
78
use Illuminate\Notifications\ChannelManager;
9+
use Illuminate\Notifications\Notifiable;
810
use Illuminate\Notifications\SendQueuedNotifications;
911
use Illuminate\Support\Collection;
10-
use Illuminate\Tests\Integration\Notifications\NotifiableUser;
1112
use Mockery as m;
1213
use PHPUnit\Framework\TestCase;
1314

@@ -52,3 +53,11 @@ public function testSerializationOfNormalNotifiable()
5253
$this->assertStringContainsString($serializedNotifiable, $serialized);
5354
}
5455
}
56+
57+
class NotifiableUser extends Model
58+
{
59+
use Notifiable;
60+
61+
public $table = 'users';
62+
public $timestamps = false;
63+
}

0 commit comments

Comments
 (0)