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
|
<?php
namespace Illuminate\Tests\Integration\Mail;
use Illuminate\Mail\Markdown;
use Illuminate\Support\EncodedHtmlString;
use Illuminate\Support\HtmlString;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
class MarkdownParserTest extends TestCase
{
/** {@inheritdoc} */
#[\Override]
protected function tearDown(): void
{
Markdown::flushState();
EncodedHtmlString::flushState();
parent::tearDown();
}
#[DataProvider('markdownDataProvider')]
public function testItCanParseMarkdownString($given, $expected)
{
tap(Markdown::parse($given), function ($html) use ($expected) {
$this->assertInstanceOf(HtmlString::class, $html);
$this->assertStringEqualsStringIgnoringLineEndings($expected.PHP_EOL, (string) $html);
$this->assertSame((string) $html, (string) $html->toHtml());
});
}
#[DataProvider('markdownEncodedDataProvider')]
public function testItCanParseMarkdownEncodedString($given, $expected)
{
tap(Markdown::parse($given, encoded: true), function ($html) use ($expected) {
$this->assertInstanceOf(HtmlString::class, $html);
$this->assertStringEqualsStringIgnoringLineEndings($expected.PHP_EOL, (string) $html);
});
}
public static function markdownDataProvider()
{
yield ['[Laravel](https://laravel.com)', '<p><a href="https://laravel.com">Laravel</a></p>'];
yield ['\[Laravel](https://laravel.com)', '<p>[Laravel](https://laravel.com)</p>'];
yield ['', '<p><img src="https://laravel.com/assets/img/welcome/background.svg" alt="Welcome to Laravel" /></p>'];
yield ['!\[Welcome to Laravel](https://laravel.com/assets/img/welcome/background.svg)', '<p></p>'];
yield ['Visit https://laravel.com/docs to browse the documentation', '<p>Visit https://laravel.com/docs to browse the documentation</p>'];
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>'];
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>'];
}
public static function markdownEncodedDataProvider()
{
yield [new EncodedHtmlString('[Laravel](https://laravel.com)'), '<p>[Laravel](https://laravel.com)</p>'];
yield [
new EncodedHtmlString(''),
'<p></p>',
];
yield [
new EncodedHtmlString('Visit https://laravel.com/docs to browse the documentation'),
'<p>Visit https://laravel.com/docs to browse the documentation</p>',
];
yield [
new EncodedHtmlString('Visit <https://laravel.com/docs> to browse the documentation'),
'<p>Visit <https://laravel.com/docs> to browse the documentation</p>',
];
yield [
new EncodedHtmlString('Visit <span>https://laravel.com/docs</span> to browse the documentation'),
'<p>Visit <span>https://laravel.com/docs</span> to browse the documentation</p>',
];
yield [
new EncodedHtmlString(new HtmlString('Visit <span>https://laravel.com/docs</span> to browse the documentation')),
'<p>Visit <span>https://laravel.com/docs</span> to browse the documentation</p>',
];
yield [
'<br />'.new EncodedHtmlString('Visit <span>https://laravel.com/docs</span> to browse the documentation'),
'<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>',
];
}
}
|