Skip to content

Commit 88a2f11

Browse files
authored
Add parameter $attributes to ListTag::strings()
1 parent a2977f4 commit 88a2f11

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/Tag/Base/ListTag.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ public function items(Li ...$items): self
2727

2828
/**
2929
* @param string[] $strings Array of list items as strings.
30+
* @param array $attributes The tag attributes in terms of name-value pairs.
3031
* @param bool $encode Whether to encode strings passed.
3132
*
3233
* @return static
3334
*/
34-
public function strings(array $strings, bool $encode = true): self
35+
public function strings(array $strings, array $attributes = [], bool $encode = true): self
3536
{
36-
$items = array_map(static function (string $string) use ($encode) {
37+
$items = array_map(static function (string $string) use ($attributes, $encode) {
3738
return Li::tag()
3839
->content($string)
40+
->attributes($attributes)
3941
->encode($encode);
4042
}, $strings);
4143
return $this->items(...$items);

tests/Tag/Base/ListTagTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ public function testStrings(): void
2727
$this->assertSame("<test>\n<li>A</li>\n<li>B</li>\n</test>", (string)$tag);
2828
}
2929

30+
public function testStringsAttributes(): void
31+
{
32+
$tag = TestListTag::tag()->strings(['A', 'B'], ['class' => 'red']);
33+
34+
self::assertSame(
35+
"<test>\n<li class=\"red\">A</li>\n<li class=\"red\">B</li>\n</test>",
36+
(string)$tag
37+
);
38+
}
39+
3040
public function testStringsEncode(): void
3141
{
3242
$tag = TestListTag::tag()->strings(['<b>A</b>', '<b>B</b>']);
@@ -39,9 +49,9 @@ public function testStringsEncode(): void
3949

4050
public function testStringsWithoutEncode(): void
4151
{
42-
$tag = TestListTag::tag()->strings(['<b>A</b>', '<b>B</b>'], false);
52+
$tag = TestListTag::tag()->strings(['<b>A</b>', '<b>B</b>'], [], false);
4353

44-
$this->assertSame("<test>\n<li><b>A</b></li>\n<li><b>B</b></li>\n</test>", (string)$tag);
54+
self::assertSame("<test>\n<li><b>A</b></li>\n<li><b>B</b></li>\n</test>", (string)$tag);
4555
}
4656

4757
public function testImmutability(): void

0 commit comments

Comments
 (0)