Skip to content

Commit

Permalink
[10.x] Fix custom themes not reseting on Markdown renderer (#46200)
Browse files Browse the repository at this point in the history
* test failing

* resets theme to default if Mailable theme is null
  • Loading branch information
AEM5299 authored Feb 21, 2023
1 parent a15d8d3 commit c06dfac
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
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

0 comments on commit c06dfac

Please sign in to comment.