|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Illuminate\Tests\Integration\Mail; |
| 4 | + |
| 5 | +use Illuminate\Foundation\Auth\User; |
| 6 | +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; |
| 7 | +use Illuminate\Mail\Mailable; |
| 8 | +use Illuminate\Mail\Mailables\Content; |
| 9 | +use Illuminate\Mail\Mailables\Envelope; |
| 10 | +use Illuminate\Mail\Markdown; |
| 11 | +use Illuminate\Support\EncodedHtmlString; |
| 12 | +use Orchestra\Testbench\Attributes\WithMigration; |
| 13 | +use Orchestra\Testbench\Factories\UserFactory; |
| 14 | +use Orchestra\Testbench\TestCase; |
| 15 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 16 | + |
| 17 | +class MailableWithoutSecuredEncodingTest extends TestCase |
| 18 | +{ |
| 19 | + use LazilyRefreshDatabase; |
| 20 | + |
| 21 | + /** {@inheritdoc} */ |
| 22 | + #[\Override] |
| 23 | + protected function tearDown(): void |
| 24 | + { |
| 25 | + Markdown::flushState(); |
| 26 | + EncodedHtmlString::flushState(); |
| 27 | + |
| 28 | + parent::tearDown(); |
| 29 | + } |
| 30 | + |
| 31 | + /** {@inheritdoc} */ |
| 32 | + #[\Override] |
| 33 | + protected function defineEnvironment($app) |
| 34 | + { |
| 35 | + $app['view']->addLocation(__DIR__.'/Fixtures'); |
| 36 | + |
| 37 | + Markdown::withoutSecuredEncoding(); |
| 38 | + } |
| 39 | + |
| 40 | + #[DataProvider('markdownEncodedDataProvider')] |
| 41 | + public function testItCanAssertMarkdownEncodedString($given, $expected) |
| 42 | + { |
| 43 | + $mailable = new class($given) extends Mailable |
| 44 | + { |
| 45 | + public function __construct(public string $message) |
| 46 | + { |
| 47 | + // |
| 48 | + } |
| 49 | + |
| 50 | + public function envelope() |
| 51 | + { |
| 52 | + return new Envelope( |
| 53 | + subject: 'My basic title', |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + public function content() |
| 58 | + { |
| 59 | + return new Content( |
| 60 | + markdown: 'message', |
| 61 | + ); |
| 62 | + } |
| 63 | + }; |
| 64 | + |
| 65 | + $mailable->assertSeeInHtml($expected, false); |
| 66 | + } |
| 67 | + |
| 68 | + public static function markdownEncodedDataProvider() |
| 69 | + { |
| 70 | + yield ['[Laravel](https://laravel.com)', 'My message is: [Laravel](https://laravel.com)']; |
| 71 | + |
| 72 | + yield [ |
| 73 | + '', |
| 74 | + 'My message is: ', |
| 75 | + ]; |
| 76 | + |
| 77 | + yield [ |
| 78 | + 'Visit https://laravel.com/docs to browse the documentation', |
| 79 | + 'My message is: Visit https://laravel.com/docs to browse the documentation', |
| 80 | + ]; |
| 81 | + |
| 82 | + yield [ |
| 83 | + 'Visit <https://laravel.com/docs> to browse the documentation', |
| 84 | + 'My message is: Visit <https://laravel.com/docs> to browse the documentation', |
| 85 | + ]; |
| 86 | + |
| 87 | + yield [ |
| 88 | + 'Visit <span>https://laravel.com/docs</span> to browse the documentation', |
| 89 | + 'My message is: Visit <span>https://laravel.com/docs</span> to browse the documentation', |
| 90 | + ]; |
| 91 | + } |
| 92 | + |
| 93 | + #[WithMigration] |
| 94 | + #[DataProvider('markdownEncodedTemplateDataProvider')] |
| 95 | + public function testItCanAssertMarkdownEncodedStringUsingTemplate($given, $expected) |
| 96 | + { |
| 97 | + $user = UserFactory::new()->create([ |
| 98 | + 'name' => $given, |
| 99 | + ]); |
| 100 | + |
| 101 | + $mailable = new class($user) extends Mailable |
| 102 | + { |
| 103 | + public $theme = 'taylor'; |
| 104 | + |
| 105 | + public function __construct(public User $user) |
| 106 | + { |
| 107 | + // |
| 108 | + } |
| 109 | + |
| 110 | + public function build() |
| 111 | + { |
| 112 | + return $this->markdown('message-with-template'); |
| 113 | + } |
| 114 | + }; |
| 115 | + |
| 116 | + $mailable->assertSeeInHtml($expected, false); |
| 117 | + } |
| 118 | + |
| 119 | + public static function markdownEncodedTemplateDataProvider() |
| 120 | + { |
| 121 | + yield ['[Laravel](https://laravel.com)', '<p><em>Hi</em> <a href="https://laravel.com">Laravel</a></p>']; |
| 122 | + |
| 123 | + yield [ |
| 124 | + '', |
| 125 | + '<p><em>Hi</em> <img src="https://laravel.com/assets/img/welcome/background.svg" alt="Welcome to Laravel"></p>', |
| 126 | + ]; |
| 127 | + |
| 128 | + yield [ |
| 129 | + 'Visit https://laravel.com/docs to browse the documentation', |
| 130 | + '<em>Hi</em> Visit https://laravel.com/docs to browse the documentation', |
| 131 | + ]; |
| 132 | + |
| 133 | + yield [ |
| 134 | + 'Visit <https://laravel.com/docs> to browse the documentation', |
| 135 | + '<em>Hi</em> Visit <https://laravel.com/docs> to browse the documentation', |
| 136 | + ]; |
| 137 | + |
| 138 | + yield [ |
| 139 | + 'Visit <span>https://laravel.com/docs</span> to browse the documentation', |
| 140 | + '<em>Hi</em> Visit <span>https://laravel.com/docs</span> to browse the documentation', |
| 141 | + ]; |
| 142 | + } |
| 143 | +} |
0 commit comments