Skip to content

Commit fbe4093

Browse files
committed
[Icons] Test Icon attributes
1 parent 500d3f9 commit fbe4093

File tree

2 files changed

+72
-5
lines changed

2 files changed

+72
-5
lines changed

src/Icons/src/Svg/Icon.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,6 @@ public function withAttributes(array $attributes): self
188188
return new self($this->innerSvg, [...$this->attributes, ...$attributes]);
189189
}
190190

191-
public function withInnerSvg(string $innerSvg): self
192-
{
193-
return new self($innerSvg, $this->attributes);
194-
}
195-
196191
public function __toString(): string
197192
{
198193
return $this->toHtml();

src/Icons/tests/Unit/Svg/IconTest.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,25 @@ public function testInvalidIdToName(string $id)
105105
Icon::idToName($id);
106106
}
107107

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+
108127
public static function provideIdToName(): iterable
109128
{
110129
yield from [
@@ -203,4 +222,57 @@ private static function provideInvalidIdentifiers(): iterable
203222
['🙂'],
204223
];
205224
}
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+
}
206278
}

0 commit comments

Comments
 (0)