Skip to content

Commit 20c31f7

Browse files
committed
Better attribute cascade tests
1 parent 7eeda48 commit 20c31f7

File tree

1 file changed

+151
-36
lines changed

1 file changed

+151
-36
lines changed

src/Icons/tests/Unit/IconRendererTest.php

Lines changed: 151 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -82,81 +82,196 @@ public function testRenderIconWithDefaultAttributes(): void
8282
}
8383

8484
/**
85-
* @dataProvider provideAttributesWithDefaultAttributesCases
85+
* @dataProvider provideRenderIconWithAttributeCascadeCases
8686
*/
87-
public function testRenderIconWithAttributesAndDefaultAttributes($iconAttrs, $defaultAttrs, $renderAttr, $expectedTag): void
88-
{
87+
public function testRenderIconWithAttributeCascade(
88+
array $iconAttributes,
89+
array $defaultAttributes = [],
90+
array $iconSetAttributes = [],
91+
array $renderAttributes = [],
92+
string $expectedTag = '',
93+
): void {
8994
$registry = $this->createRegistry([
90-
'foo' => ['', $iconAttrs],
95+
'ux:icon' => ['', $iconAttributes],
9196
]);
92-
$iconRenderer = new IconRenderer($registry, $defaultAttrs);
97+
$iconRenderer = new IconRenderer($registry, $defaultAttributes, [], ['ux' => $iconSetAttributes]);
9398

94-
$svg = $iconRenderer->renderIcon('foo', $renderAttr);
99+
$svg = $iconRenderer->renderIcon('ux:icon', $renderAttributes);
95100
$svg = str_replace(' aria-hidden="true"', '', $svg);
96101
$this->assertStringStartsWith($expectedTag, $svg);
97102
}
98103

99-
public static function provideAttributesWithDefaultAttributesCases()
104+
/**
105+
* @return iterable<array{
106+
* array<string, string|bool>,
107+
* array<string, string|bool>,
108+
* array<string, string|bool>,
109+
* array<string, string|bool>,
110+
* string,
111+
* }>
112+
*/
113+
public static function provideRenderIconWithAttributeCascadeCases(): iterable
100114
{
101115
yield 'no_attributes' => [
102116
[],
103117
[],
104118
[],
119+
[],
105120
'<svg>',
106121
];
107122
yield 'icon_attributes_are_used' => [
108-
['id' => 'icon'],
123+
['ico' => 'ICO'],
109124
[],
110125
[],
111-
'<svg id="icon">',
126+
[],
127+
'<svg ico="ICO">',
112128
];
113129
yield 'default_attributes_are_used' => [
114130
[],
115-
['id' => 'default'],
131+
['def' => 'DEF'],
132+
[],
116133
[],
117-
'<svg id="default">',
134+
'<svg def="DEF">',
118135
];
119-
yield 'render_attributes_are_used' => [
136+
yield 'default_attributes_overwrite_icon_attributes' => [
137+
['ico' => 'ICO'],
138+
['ico' => 'DEF'],
120139
[],
121140
[],
122-
['id' => 'render'],
123-
'<svg id="render">',
141+
'<svg ico="DEF">',
124142
];
125-
yield 'default_attributes_take_precedence_on_icon' => [
126-
['id' => 'icon'],
127-
['id' => 'default'],
143+
yield 'default_attributes_removes_icon_attributes' => [
144+
['ico' => 'ICO'],
145+
['ico' => false],
128146
[],
129-
'<svg id="default">',
147+
[],
148+
'<svg>',
130149
];
131150
yield 'default_attributes_are_merged_with_icon_attributes' => [
132-
['id' => 'icon', 'foo' => 'bar'],
133-
['id' => 'default', 'baz' => 'qux'],
151+
['ico' => 'ICO', 'foo' => 'ICO'],
152+
['ico' => 'DEF', 'bar' => 'DEF'],
153+
[],
134154
[],
135-
'<svg id="default" foo="bar" baz="qux">',
155+
'<svg ico="DEF" foo="ICO" bar="DEF">',
136156
];
137-
yield 'render_attributes_take_precedence_on_default' => [
157+
yield 'icon_set_attributes_are_used' => [
138158
[],
139-
['id' => 'default'],
140-
['id' => 'render'],
141-
'<svg id="render">',
159+
[],
160+
['ico' => 'SET'],
161+
[],
162+
'<svg ico="SET">',
142163
];
143-
yield 'render_attributes_are_merged_with_default_attributes' => [
164+
yield 'icon_set_attributes_overwrite_icon_attributes' => [
165+
['ico' => 'ICO'],
166+
[],
167+
['ico' => 'SET'],
168+
[],
169+
'<svg ico="SET">',
170+
];
171+
yield 'icon_set_attributes_overwrite_default_attributes' => [
172+
[],
173+
['ico' => 'DEF'],
174+
['ico' => 'SET'],
175+
[],
176+
'<svg ico="SET">',
177+
];
178+
yield 'icon_set_attributes_are_merged_with_icon_attributes' => [
179+
['ico' => 'ICO', 'foo' => 'ICO'],
180+
[],
181+
['ico' => 'SET', 'bar' => 'SET'],
182+
[],
183+
'<svg ico="SET" foo="ICO" bar="SET">',
184+
];
185+
yield 'icon_set_attributes_are_merged_with_default_attributes' => [
186+
[],
187+
['ico' => 'DEF', 'foo' => 'DEF'],
188+
['ico' => 'SET', 'bar' => 'SET'],
189+
[],
190+
'<svg ico="SET" foo="DEF" bar="SET">',
191+
];
192+
yield 'icon_set_attributes_are_merged_with_default_attributes_and_icon_attributes' => [
193+
['ico' => 'ICO', 'foo' => 'ICO'],
194+
['ico' => 'DEF', 'bar' => 'DEF'],
195+
['ico' => 'SET', 'baz' => 'SET'],
196+
[],
197+
'<svg ico="SET" foo="ICO" bar="DEF" baz="SET">',
198+
];
199+
yield 'render_attributes_are_used' => [
200+
[],
201+
[],
144202
[],
145-
['id' => 'default', 'foo' => 'bar'],
146-
['id' => 'render', 'baz' => 'qux'],
147-
'<svg id="render" foo="bar" baz="qux">',
203+
['ren' => 'REN'],
204+
'<svg ren="REN">',
148205
];
149-
yield 'render_attributes_take_precedence_on_icon' => [
150-
['id' => 'icon'],
206+
yield 'render_attributes_overwrite_icon_attributes' => [
207+
['ico' => 'ICO'],
151208
[],
152-
['id' => 'render'],
153-
'<svg id="render">',
209+
[],
210+
['ico' => 'REN'],
211+
'<svg ico="REN">',
212+
];
213+
yield 'render_attributes_overwrite_default_attributes' => [
214+
[],
215+
['ico' => 'DEF'],
216+
[],
217+
['ico' => 'REN'],
218+
'<svg ico="REN">',
219+
];
220+
yield 'render_attributes_overwrite_icon_set_attributes' => [
221+
[],
222+
[],
223+
['ico' => 'SET'],
224+
['ico' => 'REN'],
225+
'<svg ico="REN">',
154226
];
155227
yield 'render_attributes_are_merged_with_icon_attributes' => [
156-
['id' => 'icon', 'foo' => 'bar'],
228+
['ico' => 'ICO', 'foo' => 'ICO'],
229+
[],
230+
[],
231+
['ico' => 'REN', 'bar' => 'REN'],
232+
'<svg ico="REN" foo="ICO" bar="REN">',
233+
];
234+
yield 'render_attributes_are_merged_with_default_attributes' => [
157235
[],
158-
['id' => 'render', 'baz' => 'qux'],
159-
'<svg id="render" foo="bar" baz="qux">',
236+
['ico' => 'DEF', 'foo' => 'DEF'],
237+
[],
238+
['ico' => 'REN', 'bar' => 'REN'],
239+
'<svg ico="REN" foo="DEF" bar="REN">',
240+
];
241+
yield 'render_attributes_are_merged_with_icon_set_attributes' => [
242+
[],
243+
[],
244+
['ico' => 'SET', 'foo' => 'SET'],
245+
['ico' => 'REN', 'bar' => 'REN'],
246+
'<svg ico="REN" foo="SET" bar="REN">',
247+
];
248+
yield 'render_attributes_are_merged_with_default_attributes_and_icon_attributes' => [
249+
['ico' => 'ICO', 'foo' => 'ICO'],
250+
['ico' => 'DEF', 'bar' => 'DEF'],
251+
[],
252+
['ico' => 'REN', 'baz' => 'REN'],
253+
'<svg ico="REN" foo="ICO" bar="DEF" baz="REN">',
254+
];
255+
yield 'render_attributes_are_merged_with_icon_set_attributes_and_default_attributes' => [
256+
[],
257+
['ico' => 'DEF', 'foo' => 'DEF'],
258+
['ico' => 'SET', 'bar' => 'SET'],
259+
['ico' => 'REN', 'baz' => 'REN'],
260+
'<svg ico="REN" foo="DEF" bar="SET" baz="REN">',
261+
];
262+
yield 'render_attributes_are_merged_with_icon_set_attributes_and_icon_attributes' => [
263+
['ico' => 'ICO', 'foo' => 'ICO'],
264+
[],
265+
['ico' => 'SET', 'bar' => 'SET'],
266+
['ico' => 'REN', 'baz' => 'REN'],
267+
'<svg ico="REN" foo="ICO" bar="SET" baz="REN">',
268+
];
269+
yield 'render_attributes_are_merged_with_icon_set_attributes_and_default_attributes_and_icon_attributes' => [
270+
['ico' => 'ICO', 'foo' => 'ICO'],
271+
['ico' => 'DEF', 'bar' => 'DEF'],
272+
['ico' => 'SET', 'baz' => 'SET'],
273+
['ico' => 'REN', 'qux' => 'REN'],
274+
'<svg ico="REN" foo="ICO" bar="DEF" baz="SET" qux="REN">',
160275
];
161276
}
162277

0 commit comments

Comments
 (0)