Skip to content

Commit ecb32fd

Browse files
committed
Add helper methods on EmbedBlock and ListBlock
1 parent a7a715b commit ecb32fd

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

src/Block/EmbedBlock.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@ public function __construct(
1717
) {
1818
parent::__construct($id);
1919
}
20+
21+
/**
22+
* A helper method for the CSS attribute 'aspect-ratio'
23+
*/
24+
public function getAspectRatio(): string
25+
{
26+
return sprintf('%d / %d', $this->width, $this->height);
27+
}
2028
}

src/Block/ListBlock.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,16 @@ public function __construct(
2323
) {
2424
parent::__construct($id);
2525
}
26+
27+
/**
28+
* This is a helper method to get the HTML tag for the list
29+
*/
30+
public function getTag(): string
31+
{
32+
return match ($this->style) {
33+
self::STYLE_ORDERED => 'ol',
34+
self::STYLE_UNORDERED => 'ul',
35+
default => throw new \LogicException(sprintf('The defined style "%s" is not valid', $this->style)),
36+
};
37+
}
2638
}

tests/Block/EmbedBlockTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@
66

77
final class EmbedBlockTest extends BlockTestCase
88
{
9-
protected function getBlock(): Block
9+
protected function getBlock(): EmbedBlock
1010
{
1111
return new EmbedBlock('id', 'youtube', 'https://youtube.com/sadfas', 'https://youtube.com/embed/sadfas', 200, 150);
1212
}
13+
14+
/**
15+
* @test
16+
*/
17+
public function it_returns_aspect_ratio(): void
18+
{
19+
self::assertSame('200 / 150', $this->getBlock()->getAspectRatio());
20+
}
1321
}

tests/Block/ListBlockTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,16 @@ protected function getBlock(): Block
1010
{
1111
return new ListBlock('id', ListBlock::STYLE_ORDERED, ['Item 1', 'Item 2']);
1212
}
13+
14+
/**
15+
* @test
16+
*/
17+
public function it_returns_tag(): void
18+
{
19+
$block = new ListBlock('id', ListBlock::STYLE_UNORDERED, ['Item 1']);
20+
self::assertSame('ul', $block->getTag());
21+
22+
$block = new ListBlock('id', ListBlock::STYLE_ORDERED, ['Item 1']);
23+
self::assertSame('ol', $block->getTag());
24+
}
1325
}

0 commit comments

Comments
 (0)