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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
<?php
namespace Illuminate\Tests\Integration\Mail;
use Illuminate\Foundation\Auth\User;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Markdown;
use Orchestra\Testbench\Attributes\WithMigration;
use Orchestra\Testbench\Factories\UserFactory;
use PHPUnit\Framework\Attributes\DataProvider;
class MailableWithoutSecuredEncodingTest extends MailableTestCase
{
use LazilyRefreshDatabase;
/** {@inheritdoc} */
#[\Override]
protected function defineEnvironment($app)
{
parent::defineEnvironment($app);
Markdown::withoutSecuredEncoding();
}
#[WithMigration]
#[DataProvider('markdownEncodedTemplateDataProvider')]
public function testItCanAssertMarkdownEncodedStringUsingTemplate($given, $expected)
{
$user = UserFactory::new()->create([
'name' => $given,
]);
$mailable = new class($user) extends Mailable
{
public $theme = 'taylor';
public function __construct(public User $user)
{
//
}
public function build()
{
return $this->markdown('message-with-template');
}
};
$mailable->assertSeeInHtml($expected, false);
}
#[WithMigration]
#[DataProvider('markdownEncodedTemplateDataProvider')]
public function testItCanAssertMarkdownEncodedStringUsingTemplateWithTable($given, $expected)
{
$user = UserFactory::new()->create([
'name' => $given,
]);
$mailable = new class($user) extends Mailable
{
public $theme = 'taylor';
public function __construct(public User $user)
{
//
}
public function build()
{
return $this->markdown('table-with-template');
}
};
$mailable->assertSeeInHtml($expected, false);
$mailable->assertSeeInHtml('<p>This is a subcopy</p>', false);
$mailable->assertSeeInHtml(<<<'TABLE'
<table>
<thead>
<tr>
<th>Laravel</th>
<th align="center">Table</th>
<th align="right">Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>Col 2 is</td>
<td align="center">Centered</td>
<td align="right">$10</td>
</tr>
<tr>
<td>Col 3 is</td>
<td align="center">Right-Aligned</td>
<td align="right">$20</td>
</tr>
</tbody>
</table>
TABLE, false);
}
public static function markdownEncodedTemplateDataProvider()
{
yield ['[Laravel](https://laravel.com)', '<p><em>Hi</em> <a href="https://laravel.com">Laravel</a></p>'];
yield [
'',
'<p><em>Hi</em> <img src="https://laravel.com/assets/img/welcome/background.svg" alt="Welcome to Laravel"></p>',
];
yield [
'Visit https://laravel.com/docs to browse the documentation',
'<em>Hi</em> Visit https://laravel.com/docs to browse the documentation',
];
yield [
'Visit <https://laravel.com/docs> to browse the documentation',
'<em>Hi</em> Visit <https://laravel.com/docs> to browse the documentation',
];
yield [
'Visit <span>https://laravel.com/docs</span> to browse the documentation',
'<em>Hi</em> Visit <span>https://laravel.com/docs</span> to browse the documentation',
];
}
}
|