From 8f8362d586d8619906e1f993d69e393c753a1bf3 Mon Sep 17 00:00:00 2001 From: Alex Panshin Date: Tue, 2 Oct 2018 13:41:25 +0300 Subject: [PATCH 1/5] add more CDATA-related tests for `Magento\Framework\Config\Dom::merge` and create a fix for failing ones --- lib/internal/Magento/Framework/Config/Dom.php | 55 ++++++++++++++++++- .../Framework/Config/Test/Unit/DomTest.php | 7 +++ .../Config/Test/Unit/_files/dom/big_cdata.xml | 12 ++++ .../Unit/_files/dom/big_cdata_attribute.xml | 12 ++++ .../_files/dom/big_cdata_attribute_merged.xml | 12 ++++ .../_files/dom/big_cdata_attribute_new.xml | 12 ++++ .../Test/Unit/_files/dom/big_cdata_merged.xml | 12 ++++ .../Test/Unit/_files/dom/big_cdata_new.xml | 12 ++++ .../Test/Unit/_files/dom/big_cdata_text.xml | 12 ++++ .../Unit/_files/dom/big_cdata_text_merged.xml | 10 ++++ .../Unit/_files/dom/big_cdata_text_new.xml | 10 ++++ .../Config/Test/Unit/_files/dom/cdata.xml | 10 ++++ .../Test/Unit/_files/dom/cdata_html.xml | 10 ++++ .../Unit/_files/dom/cdata_html_merged.xml | 10 ++++ .../Test/Unit/_files/dom/cdata_html_new.xml | 10 ++++ .../Test/Unit/_files/dom/cdata_merged.xml | 10 ++++ .../Config/Test/Unit/_files/dom/cdata_new.xml | 10 ++++ .../Test/Unit/_files/dom/cdata_text.xml | 10 ++++ .../Unit/_files/dom/cdata_text_merged.xml | 10 ++++ .../Test/Unit/_files/dom/cdata_text_new.xml | 10 ++++ .../Test/Unit/_files/dom/text_node_cdata.xml | 12 ++++ .../_files/dom/text_node_cdata_merged.xml | 14 +++++ .../Unit/_files/dom/text_node_cdata_new.xml | 14 +++++ 23 files changed, 295 insertions(+), 1 deletion(-) create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_merged.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_new.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_merged.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_new.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_merged.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_new.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_merged.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_new.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_merged.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_new.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_merged.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_new.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/text_node_cdata.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/text_node_cdata_merged.xml create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/text_node_cdata_new.xml diff --git a/lib/internal/Magento/Framework/Config/Dom.php b/lib/internal/Magento/Framework/Config/Dom.php index 1d995bab007e5..2b9722e7cf88d 100644 --- a/lib/internal/Magento/Framework/Config/Dom.php +++ b/lib/internal/Magento/Framework/Config/Dom.php @@ -190,9 +190,15 @@ protected function _mergeNode(\DOMElement $node, $parentPath) /* override node value */ if ($this->_isTextNode($node)) { /* skip the case when the matched node has children, otherwise they get overridden */ - if (!$matchedNode->hasChildNodes() || $this->_isTextNode($matchedNode)) { + if (!$matchedNode->hasChildNodes() || $this->_isTextNode($matchedNode) || $this->_isCdataNode($matchedNode)) { $matchedNode->nodeValue = $node->childNodes->item(0)->nodeValue; } + } elseif ($this->_isCdataNode($node) && $this->_isTextNode($matchedNode) && $this->_findCdataSection($node)) { + /* Replace text node with CDATA section */ + $matchedNode->nodeValue = $this->_findCdataSection($node)->nodeValue; + } elseif ($this->_isCdataNode($node) && $this->_isCdataNode($matchedNode)) { + /* Replace CDATA with new one */ + $this->_replaceCdataNode($matchedNode, $node); } else { /* recursive merge for all child nodes */ foreach ($node->childNodes as $childNode) { @@ -220,6 +226,53 @@ protected function _isTextNode($node) return $node->childNodes->length == 1 && $node->childNodes->item(0) instanceof \DOMText; } + /** + * Check if the node content is CDATA (probably surrounded with text nodes) + * @param $node + * @return bool + */ + protected function _isCdataNode($node) + { + // If every child node of current is NOT \DOMElement + // It is arbitrary combination of text nodes and CDATA sections. + foreach ($node->childNodes as $childNode) { + if ($childNode instanceof \DOMElement) { + return false; + } + } + + return true; + } + + /** + * Finds CDATA section from given node children + * @param $node + * @return \DOMCdataSection|null + */ + protected function _findCdataSection($node) + { + foreach ($node->childNodes as $childNode) { + if ($childNode instanceof \DOMCdataSection) { + return $childNode; + } + } + } + + /** + * Replaces CDATA section in $oldNode with $newNode's + * @param $oldNode + * @param $newNode + */ + protected function _replaceCdataNode($oldNode, $newNode) + { + $oldCdata = $this->_findCdataSection($oldNode); + $newCdata = $this->_findCdataSection($newNode); + + if ($oldCdata && $newCdata) { + $oldCdata->nodeValue = $newCdata->nodeValue; + } + } + /** * Merges attributes of the merge node to the base node * diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php index 5c8f66683877c..a96e123c71d23 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php @@ -62,6 +62,13 @@ public function mergeDataProvider() ['override_node.xml', 'override_node_new.xml', [], null, 'override_node_merged.xml'], ['override_node_new.xml', 'override_node.xml', [], null, 'override_node_merged.xml'], ['text_node.xml', 'text_node_new.xml', [], null, 'text_node_merged.xml'], + 'text node replaced with cdata' => ['text_node_cdata.xml', 'text_node_cdata_new.xml', [], null, 'text_node_cdata_merged.xml'], + 'cdata' => ['cdata.xml', 'cdata_new.xml', [], null, 'cdata_merged.xml'], + 'cdata with html' => ['cdata_html.xml', 'cdata_html_new.xml', [], null, 'cdata_html_merged.xml'], + 'cdata replaced with text node' => ['cdata_text.xml', 'cdata_text_new.xml', [], null, 'cdata_text_merged.xml'], + 'big cdata' => ['big_cdata.xml', 'big_cdata_new.xml', [], null, 'big_cdata_merged.xml'], + 'big cdata with attribute' => ['big_cdata_attribute.xml', 'big_cdata_attribute_new.xml', [], null, 'big_cdata_attribute_merged.xml'], + 'big cdata replaced with text' => ['big_cdata_text.xml', 'big_cdata_text_new.xml', [], null, 'big_cdata_text_merged.xml'], [ 'recursive.xml', 'recursive_new.xml', diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata.xml new file mode 100644 index 0000000000000..6beac814f6e26 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute.xml new file mode 100644 index 0000000000000..4bd6bd7fffbe6 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_merged.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_merged.xml new file mode 100644 index 0000000000000..8bf14adfe6ff3 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_merged.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_new.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_new.xml new file mode 100644 index 0000000000000..79700c8801b78 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_new.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_merged.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_merged.xml new file mode 100644 index 0000000000000..79700c8801b78 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_merged.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_new.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_new.xml new file mode 100644 index 0000000000000..79700c8801b78 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_new.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text.xml new file mode 100644 index 0000000000000..6beac814f6e26 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_merged.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_merged.xml new file mode 100644 index 0000000000000..e1535bf2de982 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_merged.xml @@ -0,0 +1,10 @@ + + + + + Some Other Phrase + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_new.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_new.xml new file mode 100644 index 0000000000000..e1535bf2de982 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_new.xml @@ -0,0 +1,10 @@ + + + + + Some Other Phrase + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata.xml new file mode 100644 index 0000000000000..b08031c6bbd79 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata.xml @@ -0,0 +1,10 @@ + + + + + + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html.xml new file mode 100644 index 0000000000000..e04c47f406461 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html.xml @@ -0,0 +1,10 @@ + + + + + Phrase]]> + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_merged.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_merged.xml new file mode 100644 index 0000000000000..b8dd1a2105946 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_merged.xml @@ -0,0 +1,10 @@ + + + + + Other
Phrase]]>
+
+
diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_new.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_new.xml new file mode 100644 index 0000000000000..b8dd1a2105946 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_new.xml @@ -0,0 +1,10 @@ + + + + + Other
Phrase]]>
+
+
diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_merged.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_merged.xml new file mode 100644 index 0000000000000..a799004ae4775 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_merged.xml @@ -0,0 +1,10 @@ + + + + + + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_new.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_new.xml new file mode 100644 index 0000000000000..a799004ae4775 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_new.xml @@ -0,0 +1,10 @@ + + + + + + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text.xml new file mode 100644 index 0000000000000..b08031c6bbd79 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text.xml @@ -0,0 +1,10 @@ + + + + + + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_merged.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_merged.xml new file mode 100644 index 0000000000000..e1535bf2de982 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_merged.xml @@ -0,0 +1,10 @@ + + + + + Some Other Phrase + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_new.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_new.xml new file mode 100644 index 0000000000000..e1535bf2de982 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_new.xml @@ -0,0 +1,10 @@ + + + + + Some Other Phrase + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/text_node_cdata.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/text_node_cdata.xml new file mode 100644 index 0000000000000..6807872aa3d3a --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/text_node_cdata.xml @@ -0,0 +1,12 @@ + + + + + Some Phrase + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/text_node_cdata_merged.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/text_node_cdata_merged.xml new file mode 100644 index 0000000000000..b905781a9fe50 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/text_node_cdata_merged.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/text_node_cdata_new.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/text_node_cdata_new.xml new file mode 100644 index 0000000000000..b905781a9fe50 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/text_node_cdata_new.xml @@ -0,0 +1,14 @@ + + + + + + + + + From 026a6bc7519119dfab9dc08abae8c8e0b4c0b4b2 Mon Sep 17 00:00:00 2001 From: Alex Panshin Date: Tue, 2 Oct 2018 17:40:21 +0200 Subject: [PATCH 2/5] fix code styling issues --- lib/internal/Magento/Framework/Config/Dom.php | 24 +++++++++----- .../Framework/Config/Test/Unit/DomTest.php | 32 ++++++++++++++++--- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/lib/internal/Magento/Framework/Config/Dom.php b/lib/internal/Magento/Framework/Config/Dom.php index 2b9722e7cf88d..c055cd6fb7dbd 100644 --- a/lib/internal/Magento/Framework/Config/Dom.php +++ b/lib/internal/Magento/Framework/Config/Dom.php @@ -190,12 +190,17 @@ protected function _mergeNode(\DOMElement $node, $parentPath) /* override node value */ if ($this->_isTextNode($node)) { /* skip the case when the matched node has children, otherwise they get overridden */ - if (!$matchedNode->hasChildNodes() || $this->_isTextNode($matchedNode) || $this->_isCdataNode($matchedNode)) { + if (!$matchedNode->hasChildNodes() + || $this->_isTextNode($matchedNode) + || $this->_isCdataNode($matchedNode) + ) { $matchedNode->nodeValue = $node->childNodes->item(0)->nodeValue; } - } elseif ($this->_isCdataNode($node) && $this->_isTextNode($matchedNode) && $this->_findCdataSection($node)) { + } elseif ($this->_isCdataNode($node) && $this->_isTextNode($matchedNode)) { /* Replace text node with CDATA section */ - $matchedNode->nodeValue = $this->_findCdataSection($node)->nodeValue; + if ($this->_findCdataSection($node)) { + $matchedNode->nodeValue = $this->_findCdataSection($node)->nodeValue; + } } elseif ($this->_isCdataNode($node) && $this->_isCdataNode($matchedNode)) { /* Replace CDATA with new one */ $this->_replaceCdataNode($matchedNode, $node); @@ -227,8 +232,9 @@ protected function _isTextNode($node) } /** - * Check if the node content is CDATA (probably surrounded with text nodes) - * @param $node + * Check if the node content is CDATA (probably surrounded with text nodes) or just text node + * + * @param \DOMNode $node * @return bool */ protected function _isCdataNode($node) @@ -246,7 +252,8 @@ protected function _isCdataNode($node) /** * Finds CDATA section from given node children - * @param $node + * + * @param \DOMNode $node * @return \DOMCdataSection|null */ protected function _findCdataSection($node) @@ -260,8 +267,9 @@ protected function _findCdataSection($node) /** * Replaces CDATA section in $oldNode with $newNode's - * @param $oldNode - * @param $newNode + * + * @param \DOMNode $oldNode + * @param \DOMNode $newNode */ protected function _replaceCdataNode($oldNode, $newNode) { diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php index a96e123c71d23..fa58bdb5a5ebb 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php @@ -62,13 +62,37 @@ public function mergeDataProvider() ['override_node.xml', 'override_node_new.xml', [], null, 'override_node_merged.xml'], ['override_node_new.xml', 'override_node.xml', [], null, 'override_node_merged.xml'], ['text_node.xml', 'text_node_new.xml', [], null, 'text_node_merged.xml'], - 'text node replaced with cdata' => ['text_node_cdata.xml', 'text_node_cdata_new.xml', [], null, 'text_node_cdata_merged.xml'], + 'text node replaced with cdata' => [ + 'text_node_cdata.xml', + 'text_node_cdata_new.xml', + [], + null, + 'text_node_cdata_merged.xml' + ], 'cdata' => ['cdata.xml', 'cdata_new.xml', [], null, 'cdata_merged.xml'], 'cdata with html' => ['cdata_html.xml', 'cdata_html_new.xml', [], null, 'cdata_html_merged.xml'], - 'cdata replaced with text node' => ['cdata_text.xml', 'cdata_text_new.xml', [], null, 'cdata_text_merged.xml'], + 'cdata replaced with text node' => [ + 'cdata_text.xml', + 'cdata_text_new.xml', + [], + null, + 'cdata_text_merged.xml' + ], 'big cdata' => ['big_cdata.xml', 'big_cdata_new.xml', [], null, 'big_cdata_merged.xml'], - 'big cdata with attribute' => ['big_cdata_attribute.xml', 'big_cdata_attribute_new.xml', [], null, 'big_cdata_attribute_merged.xml'], - 'big cdata replaced with text' => ['big_cdata_text.xml', 'big_cdata_text_new.xml', [], null, 'big_cdata_text_merged.xml'], + 'big cdata with attribute' => [ + 'big_cdata_attribute.xml', + 'big_cdata_attribute_new.xml', + [], + null, + 'big_cdata_attribute_merged.xml' + ], + 'big cdata replaced with text' => [ + 'big_cdata_text.xml', + 'big_cdata_text_new.xml', + [], + null, + 'big_cdata_text_merged.xml' + ], [ 'recursive.xml', 'recursive_new.xml', From 60d80ec1b3ab40e7cde4749f098b3dd69c28071a Mon Sep 17 00:00:00 2001 From: Alex Panshin Date: Tue, 9 Oct 2018 13:27:31 +0300 Subject: [PATCH 3/5] fix copyright notices according to Magento copyright policy --- .../Framework/Config/Test/Unit/_files/dom/big_cdata.xml | 6 ++++-- .../Config/Test/Unit/_files/dom/big_cdata_attribute.xml | 6 ++++-- .../Test/Unit/_files/dom/big_cdata_attribute_merged.xml | 6 ++++-- .../Config/Test/Unit/_files/dom/big_cdata_attribute_new.xml | 6 ++++-- .../Config/Test/Unit/_files/dom/big_cdata_merged.xml | 6 ++++-- .../Framework/Config/Test/Unit/_files/dom/big_cdata_new.xml | 6 ++++-- .../Config/Test/Unit/_files/dom/big_cdata_text.xml | 6 ++++-- .../Config/Test/Unit/_files/dom/big_cdata_text_merged.xml | 6 ++++-- .../Config/Test/Unit/_files/dom/big_cdata_text_new.xml | 6 ++++-- .../Magento/Framework/Config/Test/Unit/_files/dom/cdata.xml | 6 ++++-- .../Framework/Config/Test/Unit/_files/dom/cdata_html.xml | 6 ++++-- .../Config/Test/Unit/_files/dom/cdata_html_merged.xml | 6 ++++-- .../Config/Test/Unit/_files/dom/cdata_html_new.xml | 6 ++++-- .../Framework/Config/Test/Unit/_files/dom/cdata_merged.xml | 6 ++++-- .../Framework/Config/Test/Unit/_files/dom/cdata_new.xml | 6 ++++-- .../Framework/Config/Test/Unit/_files/dom/cdata_text.xml | 6 ++++-- .../Config/Test/Unit/_files/dom/cdata_text_merged.xml | 6 ++++-- .../Config/Test/Unit/_files/dom/cdata_text_new.xml | 6 ++++-- 18 files changed, 72 insertions(+), 36 deletions(-) diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata.xml index 6beac814f6e26..69eb0035958e6 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute.xml index 4bd6bd7fffbe6..12a9389e3d238 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_merged.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_merged.xml index 8bf14adfe6ff3..6e95d843e34ba 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_merged.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_merged.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_new.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_new.xml index 79700c8801b78..b905781a9fe50 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_new.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_attribute_new.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_merged.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_merged.xml index 79700c8801b78..b905781a9fe50 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_merged.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_merged.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_new.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_new.xml index 79700c8801b78..b905781a9fe50 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_new.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_new.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text.xml index 6beac814f6e26..69eb0035958e6 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_merged.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_merged.xml index e1535bf2de982..3e37e67ffcf35 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_merged.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_merged.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_new.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_new.xml index e1535bf2de982..3e37e67ffcf35 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_new.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/big_cdata_text_new.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata.xml index b08031c6bbd79..f65a21e122394 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html.xml index e04c47f406461..15294f46445ec 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_merged.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_merged.xml index b8dd1a2105946..709d921f737e4 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_merged.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_merged.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_new.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_new.xml index b8dd1a2105946..709d921f737e4 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_new.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_html_new.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_merged.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_merged.xml index a799004ae4775..e6d2d809d7f7f 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_merged.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_merged.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_new.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_new.xml index a799004ae4775..e6d2d809d7f7f 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_new.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_new.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text.xml index b08031c6bbd79..f65a21e122394 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_merged.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_merged.xml index e1535bf2de982..3e37e67ffcf35 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_merged.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_merged.xml @@ -1,7 +1,9 @@ diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_new.xml b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_new.xml index e1535bf2de982..3e37e67ffcf35 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_new.xml +++ b/lib/internal/Magento/Framework/Config/Test/Unit/_files/dom/cdata_text_new.xml @@ -1,7 +1,9 @@ From 5d48710079f750181efc4bbb799dab9d43142789 Mon Sep 17 00:00:00 2001 From: Alex Panshin Date: Fri, 12 Oct 2018 15:02:59 +0300 Subject: [PATCH 4/5] make new methods private according to magento coding standards --- lib/internal/Magento/Framework/Config/Dom.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/internal/Magento/Framework/Config/Dom.php b/lib/internal/Magento/Framework/Config/Dom.php index c055cd6fb7dbd..e36f9615db26b 100644 --- a/lib/internal/Magento/Framework/Config/Dom.php +++ b/lib/internal/Magento/Framework/Config/Dom.php @@ -192,18 +192,18 @@ protected function _mergeNode(\DOMElement $node, $parentPath) /* skip the case when the matched node has children, otherwise they get overridden */ if (!$matchedNode->hasChildNodes() || $this->_isTextNode($matchedNode) - || $this->_isCdataNode($matchedNode) + || $this->isCdataNode($matchedNode) ) { $matchedNode->nodeValue = $node->childNodes->item(0)->nodeValue; } - } elseif ($this->_isCdataNode($node) && $this->_isTextNode($matchedNode)) { + } elseif ($this->isCdataNode($node) && $this->_isTextNode($matchedNode)) { /* Replace text node with CDATA section */ - if ($this->_findCdataSection($node)) { - $matchedNode->nodeValue = $this->_findCdataSection($node)->nodeValue; + if ($this->findCdataSection($node)) { + $matchedNode->nodeValue = $this->findCdataSection($node)->nodeValue; } - } elseif ($this->_isCdataNode($node) && $this->_isCdataNode($matchedNode)) { + } elseif ($this->isCdataNode($node) && $this->isCdataNode($matchedNode)) { /* Replace CDATA with new one */ - $this->_replaceCdataNode($matchedNode, $node); + $this->replaceCdataNode($matchedNode, $node); } else { /* recursive merge for all child nodes */ foreach ($node->childNodes as $childNode) { @@ -237,7 +237,7 @@ protected function _isTextNode($node) * @param \DOMNode $node * @return bool */ - protected function _isCdataNode($node) + private function isCdataNode($node) { // If every child node of current is NOT \DOMElement // It is arbitrary combination of text nodes and CDATA sections. @@ -256,7 +256,7 @@ protected function _isCdataNode($node) * @param \DOMNode $node * @return \DOMCdataSection|null */ - protected function _findCdataSection($node) + private function findCdataSection($node) { foreach ($node->childNodes as $childNode) { if ($childNode instanceof \DOMCdataSection) { @@ -271,10 +271,10 @@ protected function _findCdataSection($node) * @param \DOMNode $oldNode * @param \DOMNode $newNode */ - protected function _replaceCdataNode($oldNode, $newNode) + private function replaceCdataNode($oldNode, $newNode) { - $oldCdata = $this->_findCdataSection($oldNode); - $newCdata = $this->_findCdataSection($newNode); + $oldCdata = $this->findCdataSection($oldNode); + $newCdata = $this->findCdataSection($newNode); if ($oldCdata && $newCdata) { $oldCdata->nodeValue = $newCdata->nodeValue; From 6beb286340905840df531d37f9cc18b71ab9aeb4 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Wed, 17 Apr 2019 12:30:17 +0300 Subject: [PATCH 5/5] magento/magento2#18336: Static test fix. --- lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php index fa58bdb5a5ebb..4d84be1ba4fc1 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php @@ -5,6 +5,9 @@ */ namespace Magento\Framework\Config\Test\Unit; +/** + * Test for \Magento\Framework\Config\Dom class. + */ class DomTest extends \PHPUnit\Framework\TestCase { /**