Spaces:
Sleeping
Sleeping
File size: 2,153 Bytes
6773345 | 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 | <?php
namespace Tests\Unit;
use App\Domain\Communications\EmailLayoutRenderer;
use Tests\TestCase;
class EmailLayoutRendererTest extends TestCase
{
public function test_email_layout_wraps_plain_text_body(): void
{
$html = app(EmailLayoutRenderer::class)->bodyToHtml("Thank you.\n\nPay here: https://example.com/pay?token=abc");
$this->assertStringContainsString('<p>Thank you.</p>', $html);
$this->assertStringContainsString('href="https://example.com/pay?token=abc"', $html);
$this->assertStringNotContainsString('<script', strtolower($html));
}
public function test_email_layout_escapes_body_html(): void
{
$html = app(EmailLayoutRenderer::class)->bodyToHtml('<strong>Code</strong>');
$this->assertStringContainsString('<strong>Code</strong>', $html);
$this->assertStringNotContainsString('<strong>Code</strong>', $html);
}
public function test_email_layout_renders_safe_bold_markers_after_escaping_body(): void
{
$html = app(EmailLayoutRenderer::class)->bodyToHtml('Your code is **123456**. Do not trust **<script>bad</script>**.');
$this->assertStringContainsString('Your code is <strong>123456</strong>.', $html);
$this->assertStringContainsString('<strong><script>bad</script></strong>', $html);
$this->assertStringNotContainsString('<script>bad</script>', $html);
}
public function test_email_layout_has_black_header_and_footer_fallbacks_without_script(): void
{
$template = file_get_contents(resource_path('views/emails/mdn-layout.blade.php'));
$this->assertStringContainsString('background-color: #0b0b0b', $template);
$this->assertStringContainsString('bgcolor="#0b0b0b"', $template);
$this->assertStringContainsString('<header class="email-header" bgcolor="#0b0b0b" style="background-color: #0b0b0b;">', $template);
$this->assertStringContainsString('<footer class="email-footer" bgcolor="#0b0b0b" style="background-color: #0b0b0b;">', $template);
$this->assertStringNotContainsString('<script', strtolower($template));
}
}
|