Skip to content

Commit

Permalink
IBX-2814: Returned null instead of empty array when there are no chil…
Browse files Browse the repository at this point in the history
…d nodes
  • Loading branch information
ViniTou committed Apr 27, 2022
1 parent 9ed397f commit 8dcb3d5
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/eZ/RichText/Converter/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ protected function extractConfiguration(DOMElement $embed)
*
* @param \DOMNode $configHash
*
* @return array
* @return array|null
*/
protected function extractHash(DOMNode $configHash)
{
$hash = [];

if ($configHash->childNodes->count() === 0) {
return null;
}

foreach ($configHash->childNodes as $node) {
/** @var \DOMText|\DOMElement $node */
if ($node->nodeType === XML_ELEMENT_NODE) {
Expand Down
50 changes: 50 additions & 0 deletions tests/lib/eZ/RichText/Converter/Render/EmbedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,56 @@ public function providerForTestConvert(): array
['601', '602'],
],
],
[
'<?xml version="1.0" encoding="UTF-8"?>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml">
<paragraph>Here is paragraph with embed with empty config value
<ezembed xlink:href="ezlocation://601">
<ezconfig>
<ezvalue key="non-empty">value1</ezvalue>
<ezvalue key="empty"/>
</ezconfig>
</ezembed>
</paragraph>
</section>',
'<?xml version="1.0" encoding="UTF-8"?>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml">
<paragraph>Here is paragraph with embed with empty config value
<ezembed xlink:href="ezlocation://601">
<ezconfig>
<ezvalue key="non-empty">value1</ezvalue>
<ezvalue key="empty"/>
</ezconfig>
<ezpayload><![CDATA[601]]></ezpayload>
</ezembed>
</paragraph>
</section>',
[],
[
[],
[],
],
[
[
[
'id' => '601',
'viewType' => 'embed',
[
'embedParams' => [
'id' => '601',
'viewType' => 'embed',
'config' => [
'non-empty' => 'value1',
'empty' => null,
],
],
],
'is_inline' => false,
],
],
['601'],
],
],
];
}

Expand Down
1 change: 1 addition & 0 deletions tests/lib/eZ/RichText/Converter/Render/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ protected function getConverterMock()
'content' => '<para>Param: value</para>',
'params' => [
'param' => 'value',
'empty' => null,
],
'align' => 'right',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<ezcontent><para>Param: value</para></ezcontent>
<ezconfig>
<ezvalue key="param">value</ezvalue>
<ezvalue key="empty"/>
</ezconfig>
</eztemplate>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</ezcontent>
<ezconfig>
<ezvalue key="param">value</ezvalue>
<ezvalue key="empty"/>
</ezconfig>
<ezpayload>custom_tag</ezpayload>
</eztemplate>
Expand Down

0 comments on commit 8dcb3d5

Please sign in to comment.