@@ -105,6 +105,25 @@ public function testInvalidIdToName(string $id)
105
105
Icon::idToName ($ id );
106
106
}
107
107
108
+ /**
109
+ * @dataProvider provideRenderAttributesTestCases
110
+ */
111
+ public function testRenderAttributes (array $ attributes , string $ expected ): void
112
+ {
113
+ $ icon = new Icon ('' , $ attributes );
114
+ $ this ->assertStringStartsWith ($ expected , $ icon ->toHtml ());
115
+ }
116
+
117
+ /**
118
+ * @dataProvider provideWithAttributesTestCases
119
+ */
120
+ public function testWithAttributes (array $ attributes , array $ withAttributes , array $ expected ): void
121
+ {
122
+ $ icon = new Icon ('foo ' , $ attributes );
123
+ $ icon = $ icon ->withAttributes ($ withAttributes );
124
+ $ this ->assertSame ($ expected , $ icon ->getAttributes ());
125
+ }
126
+
108
127
public static function provideIdToName (): iterable
109
128
{
110
129
yield from [
@@ -203,4 +222,57 @@ private static function provideInvalidIdentifiers(): iterable
203
222
['🙂 ' ],
204
223
];
205
224
}
225
+
226
+ public static function provideRenderAttributesTestCases (): iterable
227
+ {
228
+ yield 'it_renders_empty_attributes ' => [
229
+ [],
230
+ '<svg> ' ,
231
+ ];
232
+ yield 'it_renders_one_attribute ' => [
233
+ ['foo ' => 'bar ' ],
234
+ '<svg foo="bar"> ' ,
235
+ ];
236
+ yield 'it_renders_multiple_attributes ' => [
237
+ ['foo ' => 'bar ' , 'baz ' => 'qux ' ],
238
+ '<svg foo="bar" baz="qux"> ' ,
239
+ ];
240
+ yield 'it_renders_true_attribute_with_no_value ' => [
241
+ ['foo ' => true ],
242
+ '<svg foo> ' ,
243
+ ];
244
+ yield 'it_does_not_render_attribute_with_false_value ' => [
245
+ ['foo ' => false ],
246
+ '<svg> ' ,
247
+ ];
248
+ }
249
+
250
+ public static function provideWithAttributesTestCases (): iterable
251
+ {
252
+ yield 'it_does_nothing_with_empty_attributes ' => [
253
+ ['foo ' => 'bar ' ],
254
+ [],
255
+ ['foo ' => 'bar ' ],
256
+ ];
257
+ yield 'it_does_nothing_with_same_attributes ' => [
258
+ ['foo ' => 'bar ' ],
259
+ ['foo ' => 'bar ' ],
260
+ ['foo ' => 'bar ' ],
261
+ ];
262
+ yield 'it_does_nothing_with_same_attributes_incomplete ' => [
263
+ ['foo ' => 'bar ' , 'baz ' => 'qux ' ],
264
+ ['foo ' => 'bar ' ],
265
+ ['foo ' => 'bar ' , 'baz ' => 'qux ' ],
266
+ ];
267
+ yield 'it_replaces_value_with_same_key ' => [
268
+ ['foo ' => 'bar ' ],
269
+ ['foo ' => 'foobar ' ],
270
+ ['foo ' => 'foobar ' ],
271
+ ];
272
+ yield 'it_replaces_value_with_same_key_and_keep_others ' => [
273
+ ['foo ' => 'bar ' , 'baz ' => 'qux ' ],
274
+ ['foo ' => 'foobar ' ],
275
+ ['foo ' => 'foobar ' , 'baz ' => 'qux ' ],
276
+ ];
277
+ }
206
278
}
0 commit comments