Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 7c52f85

Browse files
committed
tests: add more tests
1 parent d9a4ba9 commit 7c52f85

File tree

15 files changed

+512
-102
lines changed

15 files changed

+512
-102
lines changed

composer.lock

Lines changed: 76 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Blocks/Code.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ protected function __construct(string $id, string $type, array $data, ?array $tu
3636
{
3737
Assert::eq($type, self::NAME);
3838
Assert::keyExists($data, 'code');
39+
Assert::string($data['code']);
3940

4041
parent::__construct($id, $type, $data, $tunes, $allowedTags);
4142
}

src/Blocks/Delimiter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function __construct(string $id, string $type, array $data, ?array $tu
4343
public function toHtml(): string
4444
{
4545
return <<<HTML
46-
<hr id="{$this->id}">
46+
<hr id="{$this->id}" />
4747
HTML;
4848
}
4949
}

src/Blocks/Embed.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
{
3131
public const string NAME = 'embed';
3232

33-
public const array ALLOWED_TAGS = [];
33+
public const array ALLOWED_TAGS = [
34+
'iframe' => ['src', 'width', 'height'],
35+
'figcaption' => [],
36+
'figure' => ['id', 'class'],
37+
];
3438

3539
protected function __construct(string $id, string $type, array $data, ?array $tunes = [], ?array $allowedTags = null)
3640
{

src/Blocks/Header.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ protected function __construct(string $id, string $type, array $data, ?array $tu
5252
#[\Override]
5353
public function toHtml(): string
5454
{
55+
$tag = "h{$this->data['level']}";
56+
5557
return <<<HTML
56-
<h{$this->data['level']} id="{$this->id}">
57-
{$this->data['text']}
58-
</h{$this->data['level']}>
58+
<{$tag} id="{$this->id}">{$this->data['text']}</{$tag}>
5959
HTML;
6060
}
6161
}

src/Blocks/Listing.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
public const string NAME = 'list';
3232

3333
public const array ALLOWED_TAGS = [
34-
'ol' => '*',
35-
'ul' => '*',
36-
'li' => '*',
34+
'ol' => ['id', 'class'],
35+
'ul' => ['id', 'class'],
36+
'li' => [],
3737
];
3838

3939
protected function __construct(string $id, string $type, array $data, ?array $tunes = [], ?array $allowedTags = null)

src/Blocks/Quote.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
public const string NAME = 'quote';
3232

3333
public const array ALLOWED_TAGS = [
34-
'blockquote' => ['id', 'class', 'style'],
34+
'blockquote' => ['id', 'class', 'data-align'],
3535
'footer' => [],
3636
];
3737

@@ -49,8 +49,16 @@ protected function __construct(string $id, string $type, array $data, ?array $tu
4949
#[\Override]
5050
public function toHtml(): string
5151
{
52+
if ($this->data['caption'] == '<br>') {
53+
return <<<HTML
54+
<blockquote id="{$this->id}" data-align="{$this->data['alignment']}">
55+
<p>{$this->data['text']}</p>
56+
</blockquote>
57+
HTML;
58+
}
59+
5260
return <<<HTML
53-
<blockquote id="{$this->id}" style="text-align: {$this->data['alignment']}">
61+
<blockquote id="{$this->id}" data-align="{$this->data['alignment']}">
5462
<p>{$this->data['text']}</p>
5563
<footer>{$this->data['caption']}</footer>
5664
</blockquote>

src/Definition/AbstractBlock.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public static function create(array $data, array $allowedTags = []): static
7272
Assert::notEmpty($data['id']);
7373
Assert::notEmpty($data['type']);
7474
Assert::isArray($data['data']);
75-
Assert::notEmpty($data['data']);
7675

7776
return new static(
7877
id: $data['id'],

src/Definition/BlockFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ private static function decode(string $data): void
6969
Assert::keyExists($input, 'blocks');
7070
Assert::keyExists($input, 'time');
7171
Assert::keyExists($input, 'version');
72+
Assert::allKeyExists($input['blocks'], 'type');
7273

7374
self::$data = $input;
7475
}

tests/Blocks/AbstractBlockTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ abstract public static function getInvalidSchemasProvider(): Generator;
2525
public function testBlockParsingWithInvalidSchema(string $data, string $message): void
2626
{
2727
$this->expectException(EditorException::class);
28-
$editor = new Editor($data);
29-
$editor->getHtml();
28+
(new Editor($data))->getHtml();
3029
}
3130

3231
#[DataProvider('getValidSchemasProvider')]

0 commit comments

Comments
 (0)