From 9b764d356a29f30901016fa8f1a0c509c0ab9e63 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Wed, 15 Nov 2023 19:55:35 +0100 Subject: [PATCH] Add test to cover cdata --- src/Renderer/Block/HtmlBlockRenderer.php | 2 ++ .../Renderer/Block/HtmlBlockRendererTest.php | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Renderer/Block/HtmlBlockRenderer.php b/src/Renderer/Block/HtmlBlockRenderer.php index 1d1d99c..e5d2b01 100644 --- a/src/Renderer/Block/HtmlBlockRenderer.php +++ b/src/Renderer/Block/HtmlBlockRenderer.php @@ -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); diff --git a/tests/Renderer/Block/HtmlBlockRendererTest.php b/tests/Renderer/Block/HtmlBlockRendererTest.php index 0f44eb8..087a1e7 100644 --- a/tests/Renderer/Block/HtmlBlockRendererTest.php +++ b/tests/Renderer/Block/HtmlBlockRendererTest.php @@ -37,6 +37,28 @@ public function it_renders_paragraph(): void $this->assertEquals('', $result); } + #[Test] + public function it_renders_cdata_html(): void + { + $block = new HtmlBlock(HtmlBlock::TYPE_5_CDATA); + $block->setLiteral(<<Hello World + ]]> + HTML); + $fakeRenderer = new FakeChildNodeRenderer(); + $fakeRenderer->pretendChildrenExist(); + + $result = $this->renderer->render($block, $fakeRenderer); + + $this->assertIsString($result); + $this->assertEquals(<<Hello World + ]]> + HTML, $result); + } + /** * @param array $values */