File tree Expand file tree Collapse file tree 3 files changed +87
-5
lines changed
lib/internal/Magento/Framework/View Expand file tree Collapse file tree 3 files changed +87
-5
lines changed Original file line number Diff line number Diff line change 66namespace Magento \Framework \View \TemplateEngine \Xhtml ;
77
88/**
9- * Class Template
9+ * XML Template Engine
1010 */
1111class Template
1212{
@@ -34,7 +34,7 @@ public function __construct(
3434 ) {
3535 $ this ->logger = $ logger ;
3636 $ document = new \DOMDocument (static ::XML_VERSION , static ::XML_ENCODING );
37- $ document ->loadXML ($ content );
37+ $ document ->loadXML ($ content, LIBXML_PARSEHUGE );
3838 $ this ->templateNode = $ document ->documentElement ;
3939 }
4040
@@ -56,9 +56,12 @@ public function getDocumentElement()
5656 */
5757 public function append ($ content )
5858 {
59- $ newFragment = $ this ->templateNode ->ownerDocument ->createDocumentFragment ();
60- $ newFragment ->appendXML ($ content );
61- $ this ->templateNode ->appendChild ($ newFragment );
59+ $ ownerDocument = $ this ->templateNode ->ownerDocument ;
60+ $ document = new \DOMDocument ();
61+ $ document ->loadXml ($ content , LIBXML_PARSEHUGE );
62+ $ this ->templateNode ->appendChild (
63+ $ ownerDocument ->importNode ($ document ->documentElement , true )
64+ );
6265 }
6366
6467 /**
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Copyright © Magento, Inc. All rights reserved.
4+ * See COPYING.txt for license details.
5+ */
6+ declare (strict_types=1 );
7+
8+ namespace Magento \Framework \View \Test \Unit \TemplateEngine \Xhtml ;
9+
10+ use Magento \Framework \View \TemplateEngine \Xhtml \Template ;
11+ use PHPUnit \Framework \TestCase ;
12+ use Psr \Log \LoggerInterface ;
13+
14+ /**
15+ * Test XML template engine
16+ */
17+ class TemplateTest extends TestCase
18+ {
19+ /**
20+ * @var Template
21+ */
22+ private $ model ;
23+
24+ /**
25+ * @inheritDoc
26+ */
27+ protected function setUp ()
28+ {
29+ parent ::setUp ();
30+ $ this ->model = new Template (
31+ $ this ->getMockForAbstractClass (LoggerInterface::class),
32+ file_get_contents (__DIR__ . '/../_files/simple.xml ' )
33+ );
34+ }
35+
36+ /**
37+ * Test that xml content is correctly appended to the current element
38+ */
39+ public function testAppend ()
40+ {
41+ $ body = <<<HTML
42+ <body>
43+ <h1>Home Page</h1>
44+ <p>CMS homepage content goes here.</p>
45+ </body>
46+ HTML ;
47+ $ expected = <<<HTML
48+ <!--
49+ /**
50+ * Copyright © Magento, Inc. All rights reserved.
51+ * See COPYING.txt for license details.
52+ */
53+ --><html xmlns="http://www.w3.org/1999/xhtml">
54+ <head>
55+ <title>Home Page</title>
56+ </head>
57+ <body>
58+ <h1>Home Page</h1>
59+ <p>CMS homepage content goes here.</p>
60+ </body></html>
61+
62+ HTML ;
63+
64+ $ this ->model ->append ($ body );
65+ $ this ->assertEquals ($ expected , (string ) $ this ->model );
66+ }
67+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" ?>
2+ <!--
3+ /**
4+ * Copyright © Magento, Inc. All rights reserved.
5+ * See COPYING.txt for license details.
6+ */
7+ -->
8+ <html xmlns =" http://www.w3.org/1999/xhtml" >
9+ <head >
10+ <title >Home Page</title >
11+ </head >
12+ </html >
You can’t perform that action at this time.
0 commit comments