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 AlertTest extends TestCase |
||
20 | { |
||
21 | use TestTrait; |
||
22 | |||
23 | /** |
||
24 | * @throws CircularReferenceException |
||
25 | * @throws InvalidConfigException |
||
26 | * @throws NotFoundException |
||
27 | * @throws NotInstantiableException |
||
28 | */ |
||
29 | public function testBodyAttributes(): void |
||
30 | { |
||
31 | Assert::equalsWithoutLE( |
||
32 | <<<HTML |
||
33 | <div id="w0-alert" role="alert"> |
||
34 | <span class="test-class">This is a test.</span> |
||
35 | <button type="button">×</button> |
||
36 | </div> |
||
37 | HTML, |
||
38 | Alert::widget() |
||
39 | ->body('This is a test.') |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
40 | ->bodyAttributes(['class' => 'test-class']) |
||
41 | ->id('w0-alert') |
||
42 | ->render(), |
||
43 | ); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @throws CircularReferenceException |
||
48 | * @throws InvalidConfigException |
||
49 | * @throws NotFoundException |
||
50 | * @throws NotInstantiableException |
||
51 | */ |
||
52 | public function testBodyContainerAttributes(): void |
||
53 | { |
||
54 | Assert::equalsWithoutLE( |
||
55 | <<<HTML |
||
56 | <div id="w0-alert" role="alert"> |
||
57 | <div class="test-class"> |
||
58 | <span>This is a test.</span> |
||
59 | <button type="button">×</button> |
||
60 | </div> |
||
61 | </div> |
||
62 | HTML, |
||
63 | Alert::widget() |
||
64 | ->body('This is a test.') |
||
65 | ->bodyContainer(true) |
||
66 | ->bodyContainerAttributes(['class' => 'test-class']) |
||
67 | ->id('w0-alert') |
||
68 | ->render(), |
||
69 | ); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @throws CircularReferenceException |
||
74 | * @throws InvalidConfigException |
||
75 | * @throws NotFoundException |
||
76 | * @throws NotInstantiableException |
||
77 | */ |
||
78 | public function testBodyWithoutTag(): void |
||
79 | { |
||
80 | Assert::equalsWithoutLE( |
||
81 | <<<HTML |
||
82 | <div id="w0-alert" role="alert"> |
||
83 | This is a test. |
||
84 | <button type="button">×</button> |
||
85 | </div> |
||
86 | HTML, |
||
87 | Alert::widget() |
||
88 | ->body('This is a test.') |
||
89 | ->bodyTag() |
||
90 | ->id('w0-alert') |
||
91 | ->render(), |
||
92 | ); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @throws CircularReferenceException |
||
97 | * @throws InvalidConfigException |
||
98 | * @throws NotFoundException |
||
99 | * @throws NotInstantiableException |
||
100 | */ |
||
101 | public function testGenerateId(): void |
||
102 | { |
||
103 | Assert::equalsWithoutLE( |
||
104 | <<<HTML |
||
105 | <div id="alert-1" role="alert"> |
||
106 | <span>This is a test.</span> |
||
107 | <button type="button">×</button> |
||
108 | </div> |
||
109 | HTML, |
||
110 | Alert::widget()->body('This is a test.')->render(), |
||
111 | ); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @throws CircularReferenceException |
||
116 | * @throws InvalidConfigException |
||
117 | * @throws NotFoundException |
||
118 | * @throws NotInstantiableException |
||
119 | */ |
||
120 | public function testHeaderAttributes(): void |
||
121 | { |
||
122 | Assert::equalsWithoutLE( |
||
123 | <<<HTML |
||
124 | <div id="w0-alert" role="alert"> |
||
125 | <span class="tests-class">Header title</span> |
||
126 | <span>This is a test.</span> |
||
127 | <button type="button">×</button> |
||
128 | </div> |
||
129 | HTML, |
||
130 | Alert::widget() |
||
131 | ->body('This is a test.') |
||
132 | ->header('Header title') |
||
133 | ->headerAttributes(['class' => 'tests-class']) |
||
134 | ->id('w0-alert') |
||
135 | ->layoutHeader('{header}') |
||
136 | ->render(), |
||
137 | ); |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * @throws CircularReferenceException |
||
142 | * @throws InvalidConfigException |
||
143 | * @throws NotFoundException |
||
144 | * @throws NotInstantiableException |
||
145 | */ |
||
146 | public function testHeaderContainerAttributes(): void |
||
147 | { |
||
148 | Assert::equalsWithoutLE( |
||
149 | <<<HTML |
||
150 | <div id="w0-alert" role="alert"> |
||
151 | <div class="test-class"> |
||
152 | <span>Header title</span> |
||
153 | </div> |
||
154 | <span>This is a test.</span> |
||
155 | <button type="button">×</button> |
||
156 | </div> |
||
157 | HTML, |
||
158 | Alert::widget() |
||
159 | ->body('This is a test.') |
||
160 | ->header('Header title') |
||
161 | ->headerContainer() |
||
162 | ->headerContainerAttributes(['class' => 'test-class']) |
||
163 | ->id('w0-alert') |
||
164 | ->layoutHeader('{header}') |
||
165 | ->render(), |
||
166 | ); |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * @throws CircularReferenceException |
||
171 | * @throws InvalidConfigException |
||
172 | * @throws NotFoundException |
||
173 | * @throws NotInstantiableException |
||
174 | */ |
||
175 | public function testIconAttributes(): void |
||
176 | { |
||
177 | Assert::equalsWithoutLE( |
||
178 | <<<HTML |
||
179 | <div id="w0-alert" role="alert"> |
||
180 | <div><i class="tests-class"></i></div> |
||
181 | <span>This is a test.</span> |
||
182 | </div> |
||
183 | HTML, |
||
184 | Alert::widget() |
||
185 | ->body('This is a test.') |
||
186 | ->iconAttributes(['class' => 'tests-class']) |
||
187 | ->id('w0-alert') |
||
188 | ->layoutBody('{icon}{body}') |
||
189 | ->render() |
||
190 | ); |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * @throws CircularReferenceException |
||
195 | * @throws InvalidConfigException |
||
196 | * @throws NotFoundException |
||
197 | * @throws NotInstantiableException |
||
198 | */ |
||
199 | public function testIconContainerAttributes(): void |
||
200 | { |
||
201 | Assert::equalsWithoutLE( |
||
202 | <<<HTML |
||
203 | <div id="w0-alert" role="alert"> |
||
204 | <div class="test-container-class"><i class="tests-class"></i></div> |
||
205 | <span>This is a test.</span> |
||
206 | </div> |
||
207 | HTML, |
||
208 | Alert::widget() |
||
209 | ->body('This is a test.') |
||
210 | ->iconAttributes(['class' => 'tests-class']) |
||
211 | ->iconContainerAttributes(['class' => 'test-container-class']) |
||
212 | ->id('w0-alert') |
||
213 | ->layoutBody('{icon}{body}') |
||
214 | ->render(), |
||
215 | ); |
||
216 | } |
||
217 | } |
||
218 |