|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Illuminate\Tests\Integration\Mail; |
| 4 | + |
| 5 | +use Illuminate\Mail\Markdown; |
| 6 | +use Illuminate\Support\EncodedHtmlString; |
| 7 | +use Illuminate\Support\HtmlString; |
| 8 | +use Orchestra\Testbench\TestCase; |
| 9 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 10 | + |
| 11 | +class MarkdownParserTest extends TestCase |
| 12 | +{ |
| 13 | + #[DataProvider('markdownDataProvider')] |
| 14 | + public function testItCanParseMarkdownString($given, $expected) |
| 15 | + { |
| 16 | + tap(Markdown::parse($given), function ($html) use ($expected) { |
| 17 | + $this->assertInstanceOf(HtmlString::class, $html); |
| 18 | + |
| 19 | + $this->assertStringEqualsStringIgnoringLineEndings($expected.PHP_EOL, (string) $html); |
| 20 | + $this->assertSame((string) $html, (string) $html->toHtml()); |
| 21 | + }); |
| 22 | + } |
| 23 | + |
| 24 | + #[DataProvider('markdownEncodedDataProvider')] |
| 25 | + public function testItCanParseMarkdownEncodedString($given, $expected) |
| 26 | + { |
| 27 | + tap(Markdown::parse($given), function ($html) use ($expected) { |
| 28 | + $this->assertInstanceOf(HtmlString::class, $html); |
| 29 | + |
| 30 | + $this->assertStringEqualsStringIgnoringLineEndings($expected.PHP_EOL, (string) $html); |
| 31 | + }); |
| 32 | + } |
| 33 | + |
| 34 | + public static function markdownDataProvider() |
| 35 | + { |
| 36 | + yield ['[Laravel](https://laravel.com)', '<p><a href="https://laravel.com">Laravel</a></p>']; |
| 37 | + yield ['\[Laravel](https://laravel.com)', '<p>[Laravel](https://laravel.com)</p>']; |
| 38 | + yield ['', '<p><img src="https://laravel.com/assets/img/welcome/background.svg" alt="Welcome to Laravel" /></p>']; |
| 39 | + yield ['!\[Welcome to Laravel](https://laravel.com/assets/img/welcome/background.svg)', '<p></p>']; |
| 40 | + yield ['Visit https://laravel.com/docs to browse the documentation', '<p>Visit https://laravel.com/docs to browse the documentation</p>']; |
| 41 | + yield ['Visit <https://laravel.com/docs> to browse the documentation', '<p>Visit <a href="https://laravel.com/docs">https://laravel.com/docs</a> to browse the documentation</p>']; |
| 42 | + yield ['Visit <span>https://laravel.com/docs</span> to browse the documentation', '<p>Visit <span>https://laravel.com/docs</span> to browse the documentation</p>']; |
| 43 | + } |
| 44 | + |
| 45 | + public static function markdownEncodedDataProvider() |
| 46 | + { |
| 47 | + yield [new EncodedHtmlString('[Laravel](https://laravel.com)'), '<p>[Laravel](https://laravel.com)</p>']; |
| 48 | + |
| 49 | + yield [ |
| 50 | + new EncodedHtmlString(''), |
| 51 | + '<p></p>', |
| 52 | + ]; |
| 53 | + |
| 54 | + yield [ |
| 55 | + new EncodedHtmlString('Visit https://laravel.com/docs to browse the documentation'), |
| 56 | + '<p>Visit https://laravel.com/docs to browse the documentation</p>', |
| 57 | + ]; |
| 58 | + |
| 59 | + yield [ |
| 60 | + new EncodedHtmlString('Visit <https://laravel.com/docs> to browse the documentation'), |
| 61 | + '<p>Visit <https://laravel.com/docs> to browse the documentation</p>', |
| 62 | + ]; |
| 63 | + |
| 64 | + yield [ |
| 65 | + new EncodedHtmlString('Visit <span>https://laravel.com/docs</span> to browse the documentation'), |
| 66 | + '<p>Visit <span>https://laravel.com/docs</span> to browse the documentation</p>', |
| 67 | + ]; |
| 68 | + |
| 69 | + yield [ |
| 70 | + '<br />'.new EncodedHtmlString('Visit <span>https://laravel.com/docs</span> to browse the documentation'), |
| 71 | + '<p><img src="https://laravel.com/assets/img/welcome/background.svg" alt="Welcome to Laravel" /><br />Visit <span>https://laravel.com/docs</span> to browse the documentation</p>', |
| 72 | + ]; |
| 73 | + } |
| 74 | +} |
0 commit comments