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 6
6
namespace Magento \Framework \View \TemplateEngine \Xhtml ;
7
7
8
8
/**
9
- * Class Template
9
+ * XML Template Engine
10
10
*/
11
11
class Template
12
12
{
@@ -34,7 +34,7 @@ public function __construct(
34
34
) {
35
35
$ this ->logger = $ logger ;
36
36
$ document = new \DOMDocument (static ::XML_VERSION , static ::XML_ENCODING );
37
- $ document ->loadXML ($ content );
37
+ $ document ->loadXML ($ content, LIBXML_PARSEHUGE );
38
38
$ this ->templateNode = $ document ->documentElement ;
39
39
}
40
40
@@ -56,9 +56,12 @@ public function getDocumentElement()
56
56
*/
57
57
public function append ($ content )
58
58
{
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
+ );
62
65
}
63
66
64
67
/**
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