@@ -82,81 +82,196 @@ public function testRenderIconWithDefaultAttributes(): void
82
82
}
83
83
84
84
/**
85
- * @dataProvider provideAttributesWithDefaultAttributesCases
85
+ * @dataProvider provideRenderIconWithAttributeCascadeCases
86
86
*/
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 {
89
94
$ registry = $ this ->createRegistry ([
90
- 'foo ' => ['' , $ iconAttrs ],
95
+ 'ux:icon ' => ['' , $ iconAttributes ],
91
96
]);
92
- $ iconRenderer = new IconRenderer ($ registry , $ defaultAttrs );
97
+ $ iconRenderer = new IconRenderer ($ registry , $ defaultAttributes , [], [ ' ux ' => $ iconSetAttributes ] );
93
98
94
- $ svg = $ iconRenderer ->renderIcon ('foo ' , $ renderAttr );
99
+ $ svg = $ iconRenderer ->renderIcon ('ux:icon ' , $ renderAttributes );
95
100
$ svg = str_replace (' aria-hidden="true" ' , '' , $ svg );
96
101
$ this ->assertStringStartsWith ($ expectedTag , $ svg );
97
102
}
98
103
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
100
114
{
101
115
yield 'no_attributes ' => [
102
116
[],
103
117
[],
104
118
[],
119
+ [],
105
120
'<svg> ' ,
106
121
];
107
122
yield 'icon_attributes_are_used ' => [
108
- ['id ' => 'icon ' ],
123
+ ['ico ' => 'ICO ' ],
109
124
[],
110
125
[],
111
- '<svg id="icon"> ' ,
126
+ [],
127
+ '<svg ico="ICO"> ' ,
112
128
];
113
129
yield 'default_attributes_are_used ' => [
114
130
[],
115
- ['id ' => 'default ' ],
131
+ ['def ' => 'DEF ' ],
132
+ [],
116
133
[],
117
- '<svg id="default "> ' ,
134
+ '<svg def="DEF "> ' ,
118
135
];
119
- yield 'render_attributes_are_used ' => [
136
+ yield 'default_attributes_overwrite_icon_attributes ' => [
137
+ ['ico ' => 'ICO ' ],
138
+ ['ico ' => 'DEF ' ],
120
139
[],
121
140
[],
122
- ['id ' => 'render ' ],
123
- '<svg id="render"> ' ,
141
+ '<svg ico="DEF"> ' ,
124
142
];
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 ],
128
146
[],
129
- '<svg id="default"> ' ,
147
+ [],
148
+ '<svg> ' ,
130
149
];
131
150
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
+ [],
134
154
[],
135
- '<svg id="default " foo="bar" baz="qux "> ' ,
155
+ '<svg ico="DEF " foo="ICO" bar="DEF "> ' ,
136
156
];
137
- yield 'render_attributes_take_precedence_on_default ' => [
157
+ yield 'icon_set_attributes_are_used ' => [
138
158
[],
139
- ['id ' => 'default ' ],
140
- ['id ' => 'render ' ],
141
- '<svg id="render"> ' ,
159
+ [],
160
+ ['ico ' => 'SET ' ],
161
+ [],
162
+ '<svg ico="SET"> ' ,
142
163
];
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
+ [],
144
202
[],
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"> ' ,
148
205
];
149
- yield 'render_attributes_take_precedence_on_icon ' => [
150
- ['id ' => 'icon ' ],
206
+ yield 'render_attributes_overwrite_icon_attributes ' => [
207
+ ['ico ' => 'ICO ' ],
151
208
[],
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"> ' ,
154
226
];
155
227
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 ' => [
157
235
[],
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"> ' ,
160
275
];
161
276
}
162
277
0 commit comments