Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Ensure Mailable view data is not overridden by order of operations #18322

Merged
merged 2 commits into from
Mar 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ public function subject($subject)
public function markdown($view, array $data = [])
{
$this->markdown = $view;
$this->viewData = $data;
$this->viewData = array_merge($this->viewData, $data);

return $this;
}
Expand All @@ -535,7 +535,7 @@ public function markdown($view, array $data = [])
public function view($view, array $data = [])
{
$this->view = $view;
$this->viewData = $data;
$this->viewData = array_merge($this->viewData, $data);

return $this;
}
Expand All @@ -550,7 +550,7 @@ public function view($view, array $data = [])
public function text($textView, array $data = [])
{
$this->textView = $textView;
$this->viewData = $data;
$this->viewData = array_merge($this->viewData, $data);

return $this;
}
Expand Down
40 changes: 40 additions & 0 deletions tests/Mail/MailMailableDataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Illuminate\Tests\Mail;

use Illuminate\Mail\Mailable;
use PHPUnit\Framework\TestCase;

class MailMailableDataTest extends TestCase
{
public function testMailableDataIsNotLost()
{
$testData = ['first_name' => 'James'];

$mailable = new MailableStub;
$mailable->build(function($m) use ($testData) {
$m->view('view', $testData);
});
$this->assertSame($testData, $mailable->buildViewData());

$mailable = new MailableStub;
$mailable->build(function($m) use ($testData) {
$m->view('view', $testData)
->text('text-view');
});
$this->assertSame($testData, $mailable->buildViewData());
}
}

class MailableStub extends Mailable
{
/**
* Build the message.
*
* @return $this
*/
public function build($builder)
{
$builder($this);
}
}
2 changes: 1 addition & 1 deletion tests/Mail/MailMailableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class WelcomeMailableStub extends Mailable
public function build()
{
$this->with('first_name', 'Taylor')
->withLastName('Otwell');
->withLastName('Otwell');
}
}

Expand Down