|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature; |
| 4 | + |
| 5 | +use App\Support\CommonMark\CommonMark; |
| 6 | +use Tests\TestCase; |
| 7 | + |
| 8 | +class AlertBlockQuoteRendererTest extends TestCase |
| 9 | +{ |
| 10 | + public function test_note_alert_renders_with_correct_class_and_title(): void |
| 11 | + { |
| 12 | + $html = CommonMark::convertToHtml("> [!NOTE]\n> This is a note."); |
| 13 | + |
| 14 | + $this->assertStringContainsString('class="markdown-alert markdown-alert-note"', $html); |
| 15 | + $this->assertStringContainsString('class="markdown-alert-title"', $html); |
| 16 | + $this->assertStringContainsString('Note', $html); |
| 17 | + $this->assertStringContainsString('This is a note.', $html); |
| 18 | + $this->assertStringNotContainsString('[!NOTE]', $html); |
| 19 | + } |
| 20 | + |
| 21 | + public function test_tip_alert_renders_with_correct_class_and_title(): void |
| 22 | + { |
| 23 | + $html = CommonMark::convertToHtml("> [!TIP]\n> This is a tip."); |
| 24 | + |
| 25 | + $this->assertStringContainsString('markdown-alert-tip', $html); |
| 26 | + $this->assertStringContainsString('Tip', $html); |
| 27 | + $this->assertStringContainsString('This is a tip.', $html); |
| 28 | + } |
| 29 | + |
| 30 | + public function test_important_alert_renders_with_correct_class_and_title(): void |
| 31 | + { |
| 32 | + $html = CommonMark::convertToHtml("> [!IMPORTANT]\n> This is important."); |
| 33 | + |
| 34 | + $this->assertStringContainsString('markdown-alert-important', $html); |
| 35 | + $this->assertStringContainsString('Important', $html); |
| 36 | + $this->assertStringContainsString('This is important.', $html); |
| 37 | + } |
| 38 | + |
| 39 | + public function test_warning_alert_renders_with_correct_class_and_title(): void |
| 40 | + { |
| 41 | + $html = CommonMark::convertToHtml("> [!WARNING]\n> This is a warning."); |
| 42 | + |
| 43 | + $this->assertStringContainsString('markdown-alert-warning', $html); |
| 44 | + $this->assertStringContainsString('Warning', $html); |
| 45 | + $this->assertStringContainsString('This is a warning.', $html); |
| 46 | + } |
| 47 | + |
| 48 | + public function test_caution_alert_renders_with_correct_class_and_title(): void |
| 49 | + { |
| 50 | + $html = CommonMark::convertToHtml("> [!CAUTION]\n> This is a caution."); |
| 51 | + |
| 52 | + $this->assertStringContainsString('markdown-alert-caution', $html); |
| 53 | + $this->assertStringContainsString('Caution', $html); |
| 54 | + $this->assertStringContainsString('This is a caution.', $html); |
| 55 | + } |
| 56 | + |
| 57 | + public function test_regular_blockquote_still_renders_as_blockquote(): void |
| 58 | + { |
| 59 | + $html = CommonMark::convertToHtml('> This is a regular quote.'); |
| 60 | + |
| 61 | + $this->assertStringContainsString('<blockquote>', $html); |
| 62 | + $this->assertStringNotContainsString('markdown-alert', $html); |
| 63 | + } |
| 64 | + |
| 65 | + public function test_multi_paragraph_alert_content(): void |
| 66 | + { |
| 67 | + $markdown = "> [!NOTE]\n> First paragraph.\n>\n> Second paragraph."; |
| 68 | + $html = CommonMark::convertToHtml($markdown); |
| 69 | + |
| 70 | + $this->assertStringContainsString('markdown-alert-note', $html); |
| 71 | + $this->assertStringContainsString('First paragraph.', $html); |
| 72 | + $this->assertStringContainsString('Second paragraph.', $html); |
| 73 | + } |
| 74 | + |
| 75 | + public function test_inline_formatting_within_alert(): void |
| 76 | + { |
| 77 | + $markdown = "> [!TIP]\n> Use **bold** and `code` and [links](https://example.com)."; |
| 78 | + $html = CommonMark::convertToHtml($markdown); |
| 79 | + |
| 80 | + $this->assertStringContainsString('markdown-alert-tip', $html); |
| 81 | + $this->assertStringContainsString('<strong>bold</strong>', $html); |
| 82 | + $this->assertStringContainsString('<code>code</code>', $html); |
| 83 | + $this->assertStringContainsString('href="https://example.com"', $html); |
| 84 | + } |
| 85 | + |
| 86 | + public function test_lowercase_type_does_not_trigger_alert(): void |
| 87 | + { |
| 88 | + $html = CommonMark::convertToHtml("> [!note]\n> This should not be an alert."); |
| 89 | + |
| 90 | + $this->assertStringContainsString('<blockquote>', $html); |
| 91 | + $this->assertStringNotContainsString('markdown-alert', $html); |
| 92 | + } |
| 93 | + |
| 94 | + public function test_invalid_type_does_not_trigger_alert(): void |
| 95 | + { |
| 96 | + $html = CommonMark::convertToHtml("> [!DANGER]\n> This should not be an alert."); |
| 97 | + |
| 98 | + $this->assertStringContainsString('<blockquote>', $html); |
| 99 | + $this->assertStringNotContainsString('markdown-alert', $html); |
| 100 | + } |
| 101 | + |
| 102 | + public function test_alert_contains_svg_icon(): void |
| 103 | + { |
| 104 | + $html = CommonMark::convertToHtml("> [!NOTE]\n> Content here."); |
| 105 | + |
| 106 | + $this->assertStringContainsString('<svg', $html); |
| 107 | + } |
| 108 | + |
| 109 | + public function test_alert_with_text_on_same_line_as_marker(): void |
| 110 | + { |
| 111 | + $html = CommonMark::convertToHtml('> [!WARNING] Immediate text on same line.'); |
| 112 | + |
| 113 | + $this->assertStringContainsString('markdown-alert-warning', $html); |
| 114 | + $this->assertStringNotContainsString('[!WARNING]', $html); |
| 115 | + } |
| 116 | +} |
0 commit comments