Skip to content

Commit c06dfac

Browse files
authored
[10.x] Fix custom themes not reseting on Markdown renderer (#46200)
* test failing * resets theme to default if Mailable theme is null
1 parent a15d8d3 commit c06dfac

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

src/Illuminate/Mail/Mailable.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,7 @@ protected function buildMarkdownView()
324324
{
325325
$markdown = Container::getInstance()->make(Markdown::class);
326326

327-
if (isset($this->theme)) {
328-
$markdown->theme($this->theme);
329-
}
327+
$markdown->theme($this->theme ?? 'default');
330328

331329
$data = $this->buildViewData();
332330

tests/Mail/MailMailableTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
use Illuminate\Contracts\View\Factory;
88
use Illuminate\Mail\Attachment;
99
use Illuminate\Mail\Mailable;
10+
use Illuminate\Mail\Mailables\Content;
1011
use Illuminate\Mail\Mailables\Envelope;
1112
use Illuminate\Mail\Mailer;
13+
use Illuminate\Mail\Markdown;
1214
use Illuminate\Mail\Transport\ArrayTransport;
1315
use Mockery as m;
1416
use PHPUnit\Framework\AssertionFailedError;
@@ -437,6 +439,52 @@ public function testMailableSetsFromCorrectly()
437439
}
438440
}
439441

442+
public function testMailableSetsMarkdownThemeCorrectly()
443+
{
444+
$viewFactory = m::mock(Factory::class);
445+
$viewFactory->shouldReceive('flushFinderCache');
446+
$viewFactory->shouldReceive('replaceNamespace')->andReturnSelf();
447+
$viewFactory->shouldReceive('make')->andReturnSelf();
448+
$viewFactory->shouldReceive('render')->andReturn('<html></html>', 'body {}');
449+
$viewFactory->shouldReceive('exists')->andReturn(true);
450+
451+
Container::getInstance()->instance(Factory::class, $viewFactory);
452+
Container::getInstance()->singleton(Markdown::class);
453+
Container::getInstance()->instance('mailer', new class
454+
{
455+
public function render()
456+
{
457+
//
458+
}
459+
});
460+
461+
(new class() extends Mailable
462+
{
463+
public $theme = 'custom-theme';
464+
465+
public function content()
466+
{
467+
return new Content(
468+
markdown: 'mail.markdown',
469+
);
470+
}
471+
})->render();
472+
473+
$this->assertEquals('custom-theme', Container::getInstance()->make(Markdown::class)->getTheme());
474+
475+
(new class() extends Mailable
476+
{
477+
public function content()
478+
{
479+
return new Content(
480+
markdown: 'mail.markdown',
481+
);
482+
}
483+
})->render();
484+
485+
$this->assertEquals('default', Container::getInstance()->make(Markdown::class)->getTheme());
486+
}
487+
440488
public function testMailableSetsSubjectCorrectly()
441489
{
442490
$mailable = new WelcomeMailableStub;

0 commit comments

Comments
 (0)