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

[10.x] Fix custom themes not reseting on Markdown renderer #46200

Merged
merged 2 commits into from
Feb 21, 2023
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
4 changes: 1 addition & 3 deletions src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,7 @@ protected function buildMarkdownView()
{
$markdown = Container::getInstance()->make(Markdown::class);

if (isset($this->theme)) {
$markdown->theme($this->theme);
}
$markdown->theme($this->theme ?? 'default');

$data = $this->buildViewData();

Expand Down
48 changes: 48 additions & 0 deletions tests/Mail/MailMailableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use Illuminate\Contracts\View\Factory;
use Illuminate\Mail\Attachment;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Mail\Mailer;
use Illuminate\Mail\Markdown;
use Illuminate\Mail\Transport\ArrayTransport;
use Mockery as m;
use PHPUnit\Framework\AssertionFailedError;
Expand Down Expand Up @@ -437,6 +439,52 @@ public function testMailableSetsFromCorrectly()
}
}

public function testMailableSetsMarkdownThemeCorrectly()
{
$viewFactory = m::mock(Factory::class);
$viewFactory->shouldReceive('flushFinderCache');
$viewFactory->shouldReceive('replaceNamespace')->andReturnSelf();
$viewFactory->shouldReceive('make')->andReturnSelf();
$viewFactory->shouldReceive('render')->andReturn('<html></html>', 'body {}');
$viewFactory->shouldReceive('exists')->andReturn(true);

Container::getInstance()->instance(Factory::class, $viewFactory);
Container::getInstance()->singleton(Markdown::class);
Container::getInstance()->instance('mailer', new class
{
public function render()
{
//
}
});

(new class() extends Mailable
{
public $theme = 'custom-theme';

public function content()
{
return new Content(
markdown: 'mail.markdown',
);
}
})->render();

$this->assertEquals('custom-theme', Container::getInstance()->make(Markdown::class)->getTheme());

(new class() extends Mailable
{
public function content()
{
return new Content(
markdown: 'mail.markdown',
);
}
})->render();

$this->assertEquals('default', Container::getInstance()->make(Markdown::class)->getTheme());
}

public function testMailableSetsSubjectCorrectly()
{
$mailable = new WelcomeMailableStub;
Expand Down