1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Yiisoft\Yii\Widgets\Tests\Alert; |
||
6 | |||
7 | use PHPUnit\Framework\TestCase; |
||
8 | use Yiisoft\Definitions\Exception\CircularReferenceException; |
||
9 | use Yiisoft\Definitions\Exception\InvalidConfigException; |
||
10 | use Yiisoft\Definitions\Exception\NotInstantiableException; |
||
11 | use Yiisoft\Factory\NotFoundException; |
||
12 | use Yiisoft\Yii\Widgets\Alert; |
||
13 | use Yiisoft\Yii\Widgets\Tests\Support\Assert; |
||
14 | use Yiisoft\Yii\Widgets\Tests\Support\TestTrait; |
||
15 | |||
16 | /** |
||
17 | * @psalm-suppress PropertyNotSetInConstructor |
||
18 | */ |
||
19 | final class Bootstrap5Test extends TestCase |
||
20 | { |
||
21 | use TestTrait; |
||
22 | |||
23 | /** |
||
24 | * @link https://getbootstrap.com/docs/5.0/components/alerts/#additional-content |
||
25 | * |
||
26 | * @throws CircularReferenceException |
||
27 | * @throws InvalidConfigException |
||
28 | * @throws NotFoundException |
||
29 | * @throws NotInstantiableException |
||
30 | */ |
||
31 | public function testAdditionalContent(): void |
||
32 | { |
||
33 | Assert::equalsWithoutLE( |
||
34 | <<<HTML |
||
35 | <div id="w0-alert" class="alert alert-success alert-dismissible fade show" role="alert"> |
||
36 | <h4 class="alert-heading">Well done!</h4> |
||
37 | <span><p>Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.</p> |
||
38 | <hr> |
||
39 | <p class="mb-0">Whenever you need to, be sure to use margin utilities to keep things nice and tidy</p></span> |
||
40 | <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> |
||
41 | </div> |
||
42 | HTML, |
||
43 | Alert::widget() |
||
44 | ->body( |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
45 | '<p>Aww yeah, you successfully read this important alert message. This example text is going to run ' . |
||
46 | 'a bit longer so that you can see how spacing within an alert works with this kind of content.</p>' . |
||
47 | PHP_EOL . '<hr>' . PHP_EOL . |
||
48 | '<p class="mb-0">Whenever you need to, be sure to use margin utilities to keep things nice and tidy</p>' |
||
49 | ) |
||
50 | ->buttonAttributes(['data-bs-dismiss' => 'alert', 'aria-label' => 'Close']) |
||
51 | ->buttonClass('btn-close') |
||
52 | ->buttonLabel() |
||
53 | ->class('alert alert-success alert-dismissible fade show') |
||
54 | ->id('w0-alert') |
||
55 | ->header('Well done!') |
||
56 | ->headerClass('alert-heading') |
||
57 | ->headerTag('h4') |
||
58 | ->layoutHeader('{header}') |
||
59 | ->render(), |
||
60 | ); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @link https://getbootstrap.com/docs/5.0/components/alerts/#dismissing |
||
65 | * |
||
66 | * @throws CircularReferenceException |
||
67 | * @throws InvalidConfigException |
||
68 | * @throws NotFoundException |
||
69 | * @throws NotInstantiableException |
||
70 | */ |
||
71 | public function testDismissing(): void |
||
72 | { |
||
73 | Assert::equalsWithoutLE( |
||
74 | <<<HTML |
||
75 | <div id="w0-alert" class="alert alert-warning alert-dismissible fade show" role="alert"> |
||
76 | <span><strong>Holy guacamole!</strong> You should check in on some of those fields below.</span> |
||
77 | <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> |
||
78 | </div> |
||
79 | HTML, |
||
80 | Alert::widget() |
||
81 | ->body('<strong>Holy guacamole!</strong> You should check in on some of those fields below.') |
||
82 | ->buttonAttributes(['data-bs-dismiss' => 'alert', 'aria-label' => 'Close']) |
||
83 | ->buttonClass('btn-close') |
||
84 | ->buttonLabel() |
||
85 | ->class('alert alert-warning alert-dismissible fade show') |
||
86 | ->id('w0-alert') |
||
87 | ->render(), |
||
88 | ); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @link https://getbootstrap.com/docs/5.0/components/alerts/#icons |
||
93 | * |
||
94 | * @throws CircularReferenceException |
||
95 | * @throws InvalidConfigException |
||
96 | * @throws NotFoundException |
||
97 | * @throws NotInstantiableException |
||
98 | */ |
||
99 | public function testIcon(): void |
||
100 | { |
||
101 | Assert::equalsWithoutLE( |
||
102 | <<<HTML |
||
103 | <div id="w0-alert" class="alert alert-primary alert-dismissible fade show" role="alert"> |
||
104 | <div class="align-items-center d-flex"> |
||
105 | <div><i class="bi bi-exclamation-triangle-fill flex-shrink-0 me-2"></i></div> |
||
106 | <span>An example alert with an icon</span> |
||
107 | <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> |
||
108 | </div> |
||
109 | </div> |
||
110 | HTML, |
||
111 | Alert::widget() |
||
112 | ->body('An example alert with an icon') |
||
113 | ->bodyContainerClass('align-items-center d-flex') |
||
114 | ->buttonAttributes(['data-bs-dismiss' => 'alert', 'aria-label' => 'Close']) |
||
115 | ->bodyContainer(true) |
||
116 | ->buttonClass('btn-close') |
||
117 | ->buttonLabel() |
||
118 | ->class('alert alert-primary alert-dismissible fade show') |
||
119 | ->iconClass('bi bi-exclamation-triangle-fill flex-shrink-0 me-2') |
||
120 | ->id('w0-alert') |
||
121 | ->layoutBody('{icon}{body}{button}') |
||
122 | ->render(), |
||
123 | ); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * @link https://getbootstrap.com/docs/5.0/components/alerts/#link-color |
||
128 | * |
||
129 | * @throws CircularReferenceException |
||
130 | * @throws InvalidConfigException |
||
131 | * @throws NotFoundException |
||
132 | * @throws NotInstantiableException |
||
133 | */ |
||
134 | public function testLinkColor(): void |
||
135 | { |
||
136 | Assert::equalsWithoutLE( |
||
137 | <<<HTML |
||
138 | <div id="w0-alert" class="alert alert-primary" role="alert"> |
||
139 | <span>A simple primary alert with <a href="#" class="alert-link">an example link</a>.Give it a click if you like.</span> |
||
140 | <button type="button" class="float-right" data-bs-dismiss="alert" aria-label="Close"></button> |
||
141 | </div> |
||
142 | HTML, |
||
143 | Alert::widget() |
||
144 | ->body( |
||
145 | 'A simple primary alert with <a href="#" class="alert-link">an example link</a>.' . |
||
146 | 'Give it a click if you like.' |
||
147 | ) |
||
148 | ->buttonAttributes(['data-bs-dismiss' => 'alert', 'aria-label' => 'Close']) |
||
149 | ->buttonClass('float-right') |
||
150 | ->buttonLabel() |
||
151 | ->class('alert alert-primary') |
||
152 | ->id('w0-alert') |
||
153 | ->render(), |
||
154 | ); |
||
155 | } |
||
156 | } |
||
157 |