From b2c35ca9eb769d1a4752a64e936defd7f7099043 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 15 Mar 2017 15:55:36 -0500 Subject: [PATCH] Allow for per-mailable theme configuration. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A “theme” property on the mailable will be used to determine the theme on a per-mailable level if necessary. --- src/Illuminate/Mail/Mailable.php | 4 ++++ src/Illuminate/Mail/Markdown.php | 13 +++++++++++++ tests/Mail/MailMarkdownTest.php | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/Illuminate/Mail/Mailable.php b/src/Illuminate/Mail/Mailable.php index 0b72d25dc296..0d22517f9d46 100644 --- a/src/Illuminate/Mail/Mailable.php +++ b/src/Illuminate/Mail/Mailable.php @@ -188,6 +188,10 @@ protected function buildMarkdownView() { $markdown = Container::getInstance()->make(Markdown::class); + if (isset($this->theme)) { + $markdown->theme($this->theme); + } + $data = $this->buildViewData(); return [ diff --git a/src/Illuminate/Mail/Markdown.php b/src/Illuminate/Mail/Markdown.php index 06938627666c..caa68617f3d4 100644 --- a/src/Illuminate/Mail/Markdown.php +++ b/src/Illuminate/Mail/Markdown.php @@ -141,4 +141,17 @@ public function loadComponentsFrom(array $paths = []) { $this->componentPaths = $paths; } + + /** + * Set the default theme to be used. + * + * @param string $theme + * @return $this + */ + public function theme($theme) + { + $this->theme = $theme; + + return $this; + } } diff --git a/tests/Mail/MailMarkdownTest.php b/tests/Mail/MailMarkdownTest.php index 834105c20c10..bb7100bb64bf 100644 --- a/tests/Mail/MailMarkdownTest.php +++ b/tests/Mail/MailMarkdownTest.php @@ -26,6 +26,22 @@ public function testRenderFunctionReturnsHtml() $this->assertTrue(strpos($result, '') !== false); } + public function testRenderFunctionReturnsHtmlWithCustomTheme() + { + $viewFactory = \Mockery::mock('Illuminate\View\Factory'); + $markdown = new \Illuminate\Mail\Markdown($viewFactory); + $markdown->theme('yaz'); + $viewFactory->shouldReceive('flushFinderCache')->once(); + $viewFactory->shouldReceive('replaceNamespace')->once()->with('mail', $markdown->htmlComponentPaths())->andReturnSelf(); + $viewFactory->shouldReceive('make')->with('view', [])->andReturnSelf(); + $viewFactory->shouldReceive('make')->with('mail::themes.yaz')->andReturnSelf(); + $viewFactory->shouldReceive('render')->twice()->andReturn('', 'body {}'); + + $result = $markdown->render('view', []); + + $this->assertTrue(strpos($result, '') !== false); + } + public function testRenderTextReturnsText() { $viewFactory = \Mockery::mock('Illuminate\View\Factory');