Skip to content

Commit

Permalink
Add test to cover cdata
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanzweifel committed Nov 15, 2023
1 parent 2b31b87 commit 9b764d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Renderer/Block/HtmlBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s
{
HtmlBlock::assertInstanceOf($node);

// We ignore $node->getType() here, as we want to render all HTML blocks the same way.

$htmlInput = $this->config->get('html_input');

return HtmlFilter::filter($node->getLiteral(), $htmlInput);
Expand Down
22 changes: 22 additions & 0 deletions tests/Renderer/Block/HtmlBlockRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ public function it_renders_paragraph(): void
$this->assertEquals('<!-- This is a comment -->', $result);
}

#[Test]
public function it_renders_cdata_html(): void
{
$block = new HtmlBlock(HtmlBlock::TYPE_5_CDATA);
$block->setLiteral(<<<HTML
<![CDATA[
<h1>Hello World</h1>
]]>
HTML);
$fakeRenderer = new FakeChildNodeRenderer();
$fakeRenderer->pretendChildrenExist();

$result = $this->renderer->render($block, $fakeRenderer);

$this->assertIsString($result);
$this->assertEquals(<<<HTML
<![CDATA[
<h1>Hello World</h1>
]]>
HTML, $result);
}

/**
* @param array<string, mixed> $values
*/
Expand Down

0 comments on commit 9b764d3

Please sign in to comment.