123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?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->assertNotFalse(strpos($result, '<html></html>'));
- }
- 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->assertNotFalse(strpos($result, '<html></html>'));
- }
- 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->assertNotFalse(strpos($result, '<html></html>'));
- }
- 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);
- }
- }
|