Skip to content

Commit 2e19f33

Browse files
MAGETWO-86840: GitHub 12322: Bug with CDATA in XML layout update #1163
2 parents 6a48b85 + ad951b0 commit 2e19f33

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function __toString()
119119
protected function wrapContent($content)
120120
{
121121
return '<script type="text/x-magento-init"><![CDATA['
122-
. '{"*": {"Magento_Ui/js/core/app": ' . str_replace(['<![CDATA[', ']]>'], '', $content) . '}}'
122+
. '{"*": {"Magento_Ui/js/core/app": ' . str_replace(']]>', ']]]]><![CDATA[>', $content) . '}}'
123123
. ']]></script>';
124124
}
125125
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Ui\Test\Unit\TemplateEngine\Xhtml;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\Framework\View\Layout\Generator\Structure;
11+
use Magento\Framework\View\Element\UiComponentInterface;
12+
use Magento\Framework\View\TemplateEngine\Xhtml\CompilerInterface;
13+
use Magento\Framework\View\TemplateEngine\Xhtml\Template;
14+
use Magento\Ui\TemplateEngine\Xhtml\Result;
15+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
16+
use Psr\Log\LoggerInterface;
17+
18+
/**
19+
* Test Class for Class Result.
20+
* @see \Magento\Ui\TemplateEngine\Xhtml\Result
21+
*
22+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
23+
*/
24+
class ResultTest extends \PHPUnit\Framework\TestCase
25+
{
26+
/**
27+
* @var Template|MockObject
28+
*/
29+
private $template;
30+
31+
/**
32+
* @var CompilerInterface|MockObject
33+
*/
34+
private $compiler;
35+
36+
/**
37+
* @var UiComponentInterface|MockObject
38+
*/
39+
private $component;
40+
41+
/**
42+
* @var Structure|MockObject
43+
*/
44+
private $structure;
45+
46+
/**
47+
* @var LoggerInterface|MockObject
48+
*/
49+
private $logger;
50+
51+
/**
52+
* @var Result
53+
*/
54+
private $testModel;
55+
56+
/**
57+
* @var ObjectManager
58+
*/
59+
private $objectManager;
60+
61+
protected function setUp()
62+
{
63+
$this->template = $this->createPartialMock(Template::class, ['append']);
64+
$this->compiler = $this->createMock(CompilerInterface::class);
65+
$this->component = $this->createMock(UiComponentInterface::class);
66+
$this->structure = $this->createPartialMock(Structure::class, ['generate']);
67+
$this->logger = $this->createMock(LoggerInterface::class);
68+
69+
$this->objectManager = new ObjectManager($this);
70+
$this->testModel = $this->objectManager->getObject(Result::class, [
71+
'template' => $this->template,
72+
'compiler' => $this->compiler,
73+
'component' => $this->component,
74+
'structure' => $this->structure,
75+
'logger' => $this->logger,
76+
]);
77+
}
78+
79+
/**
80+
* Test Append layout configuration method
81+
*/
82+
public function testAppendLayoutConfiguration()
83+
{
84+
$configWithCdata = 'text before <![CDATA[cdata text]]>';
85+
$this->structure->expects($this->once())
86+
->method('generate')
87+
->with($this->component)
88+
->willReturn([$configWithCdata]);
89+
$this->template->expects($this->once())
90+
->method('append')
91+
->with('<script type="text/x-magento-init"><![CDATA[{"*": {"Magento_Ui/js/core/app": '
92+
. '["text before <![CDATA[cdata text]]]]><![CDATA[>"]'
93+
. '}}]]></script>');
94+
95+
$this->testModel->appendLayoutConfiguration();
96+
}
97+
}

0 commit comments

Comments
 (0)