MailMarkdownTest.php 3.6 KB

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