1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
<?php
namespace Illuminate\Tests\Mail;
use Illuminate\Mail\Markdown;
use Illuminate\View\Factory;
use Mockery as m;
use PHPUnit\Framework\TestCase;
class MailMarkdownTest extends TestCase
{
protected function tearDown(): void
{
m::close();
}
public function testRenderFunctionReturnsHtml()
{
$viewFactory = m::mock(Factory::class);
$markdown = new Markdown($viewFactory);
$viewFactory->shouldReceive('flushFinderCache')->once();
$viewFactory->shouldReceive('replaceNamespace')->once()->with('mail', $markdown->htmlComponentPaths())->andReturnSelf();
$viewFactory->shouldReceive('exists')->with('mail.default')->andReturn(false);
$viewFactory->shouldReceive('make')->with('view', [])->andReturnSelf();
$viewFactory->shouldReceive('make')->with('mail::themes.default', [])->andReturnSelf();
$viewFactory->shouldReceive('render')->twice()->andReturn('<html></html>', 'body {}');
$result = $markdown->render('view', []);
$this->assertStringContainsString('<html></html>', $result);
}
public function testRenderFunctionReturnsHtmlWithCustomTheme()
{
$viewFactory = m::mock(Factory::class);
$markdown = new Markdown($viewFactory);
$markdown->theme('yaz');
$viewFactory->shouldReceive('flushFinderCache')->once();
$viewFactory->shouldReceive('replaceNamespace')->once()->with('mail', $markdown->htmlComponentPaths())->andReturnSelf();
$viewFactory->shouldReceive('exists')->with('mail.yaz')->andReturn(true);
$viewFactory->shouldReceive('make')->with('view', [])->andReturnSelf();
$viewFactory->shouldReceive('make')->with('mail.yaz', [])->andReturnSelf();
$viewFactory->shouldReceive('render')->twice()->andReturn('<html></html>', 'body {}');
$result = $markdown->render('view', []);
$this->assertStringContainsString('<html></html>', $result);
}
public function testRenderFunctionReturnsHtmlWithCustomThemeWithMailPrefix()
{
$viewFactory = m::mock(Factory::class);
$markdown = new Markdown($viewFactory);
$markdown->theme('mail.yaz');
$viewFactory->shouldReceive('flushFinderCache')->once();
$viewFactory->shouldReceive('replaceNamespace')->once()->with('mail', $markdown->htmlComponentPaths())->andReturnSelf();
$viewFactory->shouldReceive('exists')->with('mail.yaz')->andReturn(true);
$viewFactory->shouldReceive('make')->with('view', [])->andReturnSelf();
$viewFactory->shouldReceive('make')->with('mail.yaz', [])->andReturnSelf();
$viewFactory->shouldReceive('render')->twice()->andReturn('<html></html>', 'body {}');
$result = $markdown->render('view', []);
$this->assertStringContainsString('<html></html>', $result);
}
public function testRenderTextReturnsText()
{
$viewFactory = m::mock(Factory::class);
$markdown = new Markdown($viewFactory);
$viewFactory->shouldReceive('flushFinderCache')->once();
$viewFactory->shouldReceive('replaceNamespace')->once()->with('mail', $markdown->textComponentPaths())->andReturnSelf();
$viewFactory->shouldReceive('make')->with('view', [])->andReturnSelf();
$viewFactory->shouldReceive('render')->andReturn('text');
$result = $markdown->renderText('view', [])->toHtml();
$this->assertSame('text', $result);
}
public function testParseReturnsParsedMarkdown()
{
$viewFactory = m::mock(Factory::class);
$markdown = new Markdown($viewFactory);
$result = $markdown->parse('# Something')->toHtml();
$this->assertSame("<h1>Something</h1>\n", $result);
}
}
|