|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ipl\Tests\Web\Widget; |
| 4 | + |
| 5 | +use ipl\Html\Html; |
| 6 | +use ipl\Html\Test\TestCase; |
| 7 | +use ipl\Web\Common\CalloutType; |
| 8 | +use ipl\Web\Widget\Callout; |
| 9 | + |
| 10 | +class CalloutTest extends TestCase |
| 11 | +{ |
| 12 | + public function testCalloutWithoutTitle(): void |
| 13 | + { |
| 14 | + $callout = new Callout(CalloutType::Info, 'Content'); |
| 15 | + |
| 16 | + $html = <<<'HTML' |
| 17 | +<div class="callout callout-type-info"> |
| 18 | + <i class="icon fa-circle-info fa"></i> |
| 19 | + <div class="callout-text"> |
| 20 | + Content |
| 21 | + </div> |
| 22 | +</div> |
| 23 | +HTML; |
| 24 | + |
| 25 | + $this->assertHtml($html, $callout); |
| 26 | + } |
| 27 | + |
| 28 | + public function testCalloutWithTitle(): void |
| 29 | + { |
| 30 | + $callout = new Callout(CalloutType::Info, 'Content', 'Title'); |
| 31 | + |
| 32 | + $html = <<<'HTML' |
| 33 | +<div class="callout callout-type-info"> |
| 34 | + <i class="icon fa-circle-info fa"></i> |
| 35 | + <div class="callout-text"> |
| 36 | + <strong class="callout-title">Title</strong> |
| 37 | + Content |
| 38 | + </div> |
| 39 | +</div> |
| 40 | +HTML; |
| 41 | + |
| 42 | + $this->assertHtml($html, $callout); |
| 43 | + } |
| 44 | + |
| 45 | + public function testCalloutFalsyTitle(): void |
| 46 | + { |
| 47 | + $callout = new Callout(CalloutType::Warning, 'Content', '0'); |
| 48 | + |
| 49 | + $html = <<<'HTML' |
| 50 | +<div class="callout callout-type-warning"> |
| 51 | + <i class="icon fa-warning fa"></i> |
| 52 | + <div class="callout-text"> |
| 53 | + <strong class="callout-title">0</strong> |
| 54 | + Content |
| 55 | + </div> |
| 56 | +</div> |
| 57 | +HTML; |
| 58 | + $this->assertHtml($html, $callout); |
| 59 | + } |
| 60 | + |
| 61 | + public function testCalloutEmptyTitle(): void |
| 62 | + { |
| 63 | + $callout = new Callout(CalloutType::Error, 'Content', ''); |
| 64 | + |
| 65 | + $html = <<<'HTML' |
| 66 | +<div class="callout callout-type-error"> |
| 67 | + <i class="icon fa-circle-xmark fa"></i> |
| 68 | + <div class="callout-text"> |
| 69 | + Content |
| 70 | + </div> |
| 71 | +</div> |
| 72 | +HTML; |
| 73 | + $this->assertHtml($html, $callout); |
| 74 | + } |
| 75 | + |
| 76 | + public function testCalloutValidHtmlContent(): void |
| 77 | + { |
| 78 | + $callout = new Callout( |
| 79 | + CalloutType::Success, |
| 80 | + Html::tag('p', ['class' => 'test-class'], 'This is a Test'), |
| 81 | + 'Test Title', |
| 82 | + ); |
| 83 | + |
| 84 | + $html = <<<'HTML' |
| 85 | +<div class="callout callout-type-success"> |
| 86 | + <i class="icon fa-circle-check fa"></i> |
| 87 | + <div class="callout-text"> |
| 88 | + <strong class="callout-title">Test Title</strong> |
| 89 | + <p class="test-class">This is a Test</p> |
| 90 | + </div> |
| 91 | +</div> |
| 92 | +HTML; |
| 93 | + |
| 94 | + $this->assertHtml($html, $callout); |
| 95 | + } |
| 96 | + |
| 97 | + public function testCalloutFitContent(): void |
| 98 | + { |
| 99 | + $callout = (new Callout(CalloutType::Error, 'Content')) |
| 100 | + ->setFitContent(true); |
| 101 | + |
| 102 | + $html = <<<'HTML' |
| 103 | +<div class="callout callout-type-error callout-fit-content"> |
| 104 | + <i class="icon fa-circle-xmark fa"></i> |
| 105 | + <div class="callout-text"> |
| 106 | + Content |
| 107 | + </div> |
| 108 | +</div> |
| 109 | +HTML; |
| 110 | + $this->assertHtml($html, $callout); |
| 111 | + |
| 112 | + $callout->setFitContent(false); |
| 113 | + |
| 114 | + $html2 = <<<'HTML' |
| 115 | +<div class="callout callout-type-error"> |
| 116 | + <i class="icon fa-circle-xmark fa"></i> |
| 117 | + <div class="callout-text"> |
| 118 | + Content |
| 119 | + </div> |
| 120 | +</div> |
| 121 | +HTML; |
| 122 | + $this->assertHtml($html2, $callout); |
| 123 | + } |
| 124 | +} |
0 commit comments