Skip to content

Commit 1552780

Browse files
Merge pull request #417 from magento-frontend/public-prs
Bug MAGETWO-58373 Set return code for SetModeCommand [GITHUB PR#4845] MAGETWO-58372 Added 'target' attribute to the allowed attributes array for link block [GITHUB PR#1935] MAGETWO-56552 [GITHUB PR#4733] Escape Js Quote for layout updates MAGETWO-58369 [GITHUB PR#4733] Update Container.php [GITHUB PR#4565]
2 parents 4bb5467 + 5839e18 commit 1552780

File tree

7 files changed

+204
-32
lines changed

7 files changed

+204
-32
lines changed

app/code/Magento/Backend/Block/Widget/Form/Container.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ class Container extends \Magento\Backend\Block\Widget\Container
3737
* @var string
3838
*/
3939
protected $_blockGroup = 'Magento_Backend';
40+
41+
/**
42+
* @var string
43+
*/
44+
const PARAM_BLOCK_GROUP = 'block_group';
45+
46+
/**
47+
* @var string
48+
*/
49+
const PARAM_MODE = 'mode';
4050

4151
/**
4252
* @var string
@@ -49,6 +59,12 @@ class Container extends \Magento\Backend\Block\Widget\Container
4959
protected function _construct()
5060
{
5161
parent::_construct();
62+
if ($this->hasData(self::PARAM_BLOCK_GROUP)) {
63+
$this->_blockGroup = $this->_getData(self::PARAM_BLOCK_GROUP);
64+
}
65+
if ($this->hasData(self::PARAM_MODE)) {
66+
$this->_mode = $this->_getData(self::PARAM_MODE);
67+
}
5268

5369
$this->addButton(
5470
'back',

app/code/Magento/Deploy/Console/Command/SetModeCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
104104
throw new LocalizedException(__('Cannot switch into given mode "%1"', $toMode));
105105
}
106106
$output->writeln('Enabled ' . $toMode . ' mode.');
107+
108+
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
107109
} catch (\Exception $e) {
108110
$output->writeln('<error>' . $e->getMessage() . '</error>');
109111
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {

app/code/Magento/Widget/Test/Unit/Block/Adminhtml/Widget/Instance/Edit/Chooser/AbstractContainerTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,14 @@ protected function setUp()
103103
->disableOriginalConstructor()
104104
->getMock();
105105

106-
$this->escaperMock = $this->getMock(\Magento\Framework\Escaper::class, ['escapeHtml'], [], '', false);
106+
$this->escaperMock = $this->getMock(
107+
\Magento\Framework\Escaper::class,
108+
['escapeHtml', 'escapeHtmlAttr'],
109+
[],
110+
'',
111+
false
112+
);
113+
$this->escaperMock->expects($this->any())->method('escapeHtmlAttr')->willReturnArgument(0);
107114

108115
$this->contextMock = $this->getMockBuilder(\Magento\Backend\Block\Context::class)
109116
->setMethods(['getEventManager', 'getScopeConfig', 'getEscaper'])

dev/tests/integration/testsuite/Magento/Backend/Block/Widget/Form/ContainerTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,23 @@ public function testGetFormHtml()
3333
$form->setText($expectedHtml);
3434
$this->assertEquals($expectedHtml, $block->getFormHtml());
3535
}
36+
37+
public function testPseudoConstruct()
38+
{
39+
/** @var $block \Magento\Backend\Block\Widget\Form\Container */
40+
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
41+
\Magento\Framework\View\LayoutInterface::class
42+
)->createBlock(
43+
\Magento\Backend\Block\Widget\Form\Container::class,
44+
'',
45+
[
46+
'data' => [
47+
\Magento\Backend\Block\Widget\Container::PARAM_CONTROLLER => 'user',
48+
\Magento\Backend\Block\Widget\Form\Container::PARAM_MODE => 'edit',
49+
\Magento\Backend\Block\Widget\Form\Container::PARAM_BLOCK_GROUP => 'Magento_User'
50+
]
51+
]
52+
);
53+
$this->assertInstanceOf(\Magento\User\Block\User\Edit\Form::class, $block->getChildBlock('form'));
54+
}
3655
}

lib/internal/Magento/Framework/View/Element/Html/Link.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Link extends \Magento\Framework\View\Element\Template
2222
'title',
2323
'charset',
2424
'name',
25+
'target',
2526
'hreflang',
2627
'rel',
2728
'rev',

lib/internal/Magento/Framework/View/Element/Html/Select.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ protected function _toHtml()
140140
'" class="' .
141141
$this->getClass() .
142142
'" title="' .
143-
$this->getTitle() .
143+
$this->escapeHtml($this->getTitle()) .
144144
'" ' .
145145
$this->getExtraParams() .
146146
'>';
@@ -166,7 +166,8 @@ protected function _toHtml()
166166
}
167167

168168
if (is_array($value)) {
169-
$html .= '<optgroup label="' . $label . '" data-optgroup-name="' . $optgroupName . '">';
169+
$html .= '<optgroup label="' . $this->escapeHtml($label)
170+
. '" data-optgroup-name="' . $this->escapeHtml($optgroupName) . '">';
170171
foreach ($value as $keyGroup => $optionGroup) {
171172
if (!is_array($optionGroup)) {
172173
$optionGroup = ['value' => $keyGroup, 'label' => $optionGroup];
@@ -204,10 +205,10 @@ protected function _optionToHtml($option, $selected = false)
204205
foreach ($option['params'] as $key => $value) {
205206
if (is_array($value)) {
206207
foreach ($value as $keyMulti => $valueMulti) {
207-
$params .= sprintf(' %s="%s" ', $keyMulti, $valueMulti);
208+
$params .= sprintf(' %s="%s" ', $keyMulti, $this->escapeHtml($valueMulti));
208209
}
209210
} else {
210-
$params .= sprintf(' %s="%s" ', $key, $value);
211+
$params .= sprintf(' %s="%s" ', $key, $this->escapeHtml($value));
211212
}
212213
}
213214
}

lib/internal/Magento/Framework/View/Test/Unit/Element/Html/SelectTest.php

Lines changed: 153 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Framework\View\Test\Unit\Element\Html;
77

88
use \Magento\Framework\View\Element\Html\Select;
9+
use Magento\Framework\Escaper;
910

1011
class SelectTest extends \PHPUnit_Framework_TestCase
1112
{
@@ -14,25 +15,27 @@ class SelectTest extends \PHPUnit_Framework_TestCase
1415
*/
1516
protected $select;
1617

18+
/**
19+
* @var Escaper|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
protected $escaper;
22+
1723
protected function setUp()
1824
{
1925
$eventManager = $this->getMock(\Magento\Framework\Event\ManagerInterface::class);
2026

2127
$scopeConfig = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
2228

23-
$escaper = $this->getMockBuilder(\Magento\Framework\Escaper::class)
29+
$this->escaper = $this->getMockBuilder(\Magento\Framework\Escaper::class)
2430
->disableOriginalConstructor()
2531
->getMock();
26-
$escaper->expects($this->any())
27-
->method('escapeHtml')
28-
->will($this->returnArgument(0));
2932

3033
$context = $this->getMockBuilder(\Magento\Framework\View\Element\Context::class)
3134
->disableOriginalConstructor()
3235
->getMock();
3336
$context->expects($this->once())
3437
->method('getEscaper')
35-
->will($this->returnValue($escaper));
38+
->will($this->returnValue($this->escaper));
3639
$context->expects($this->once())
3740
->method('getEventManager')
3841
->will($this->returnValue($eventManager));
@@ -92,8 +95,52 @@ public function testGetSetTitle()
9295
$this->assertEquals($selectTitle, $this->select->getTitle());
9396
}
9497

98+
public function testGetHtmlJs()
99+
{
100+
$this->escaper->expects($this->any())
101+
->method('escapeHtml')
102+
->will($this->returnArgument(0));
103+
$this->escaper->expects($this->any())
104+
->method('escapeHtmlAttr')
105+
->will($this->returnArgument(0));
106+
107+
$selectId = 'testId';
108+
$selectClass = 'testClass';
109+
$selectTitle = 'testTitle';
110+
$selectName = 'testName';
111+
112+
$options = [
113+
'testValue' => 'testLabel',
114+
'selectedValue' => 'selectedLabel',
115+
];
116+
$selectedValue = 'selectedValue';
117+
118+
$this->select->setId($selectId);
119+
$this->select->setClass($selectClass);
120+
$this->select->setTitle($selectTitle);
121+
$this->select->setName($selectName);
122+
$this->select->setOptions($options);
123+
$this->select->setValue($selectedValue);
124+
125+
$result = '<select name="testName" id="testId" class="testClass" title="testTitle" >'
126+
. '<option value="testValue" <%= option_extra_attrs.option_4016862802 %> >testLabel</option>'
127+
. '<option value="selectedValue" selected="selected" <%= option_extra_attrs.option_662265145 %> >'
128+
. 'selectedLabel</option>'
129+
. '</select>';
130+
131+
$this->select->setIsRenderToJsTemplate(true);
132+
$this->assertEquals($result, $this->select->getHtml());
133+
}
134+
95135
public function testGetHtml()
96136
{
137+
$this->escaper->expects($this->any())
138+
->method('escapeHtml')
139+
->will($this->returnArgument(0));
140+
$this->escaper->expects($this->any())
141+
->method('escapeHtmlAttr')
142+
->will($this->returnArgument(0));
143+
97144
$selectId = 'testId';
98145
$selectClass = 'testClass';
99146
$selectTitle = 'testTitle';
@@ -137,33 +184,112 @@ public function testGetHtml()
137184
$this->assertEquals($result, $this->select->getHtml());
138185
}
139186

140-
public function testGetHtmlJs()
187+
public function testGetHtmlEscapes()
141188
{
142-
$selectId = 'testId';
143-
$selectClass = 'testClass';
144-
$selectTitle = 'testTitle';
145-
$selectName = 'testName';
189+
$this->escaper->expects($this->any())
190+
->method('escapeHtml')
191+
->will($this->returnValue('ESCAPED'));
192+
$this->escaper->expects($this->any())
193+
->method('escapeHtmlAttr')
194+
->will($this->returnValue('ESCAPED_ATTR'));
146195

147-
$options = [
148-
'testValue' => 'testLabel',
149-
'selectedValue' => 'selectedLabel',
196+
$optionsSets = [
197+
$this->getOptionsWithSingleQuotes(),
198+
$this->getOptionsWithDoubleQuotes()
150199
];
151-
$selectedValue = 'selectedValue';
152-
153-
$this->select->setId($selectId);
154-
$this->select->setClass($selectClass);
155-
$this->select->setTitle($selectTitle);
156-
$this->select->setName($selectName);
157-
$this->select->setOptions($options);
158-
$this->select->setValue($selectedValue);
159200

160-
$result = '<select name="testName" id="testId" class="testClass" title="testTitle" >'
161-
. '<option value="testValue" <%= option_extra_attrs.option_4016862802 %> >testLabel</option>'
162-
. '<option value="selectedValue" selected="selected" <%= option_extra_attrs.option_662265145 %> >'
163-
. 'selectedLabel</option>'
201+
$expectedResult = '<select name="test[name]" id="testId" class="test class" title="ESCAPED" >'
202+
. '<option value="ESCAPED" paramKey="ESCAPED" >ESCAPED</option>'
203+
. '<option value="ESCAPED" selected="selected" >ESCAPED</option>'
204+
. '<optgroup label="ESCAPED" data-optgroup-name="ESCAPED">'
205+
. '<option value="ESCAPED" >ESCAPED</option>'
206+
. '<option value="ESCAPED" selected="selected" >ESCAPED</option>'
207+
. '</optgroup>'
164208
. '</select>';
165209

166-
$this->select->setIsRenderToJsTemplate(true);
167-
$this->assertEquals($result, $this->select->getHtml());
210+
foreach ($optionsSets as $inOptions) {
211+
$this->select->setId($inOptions['id']);
212+
$this->select->setClass($inOptions['class']);
213+
$this->select->setTitle($inOptions['title']);
214+
$this->select->setName($inOptions['name']);
215+
216+
foreach ($inOptions['options'] as $option) {
217+
$this->select->addOption($option['value'], $option['label'], $option['params']);
218+
}
219+
$this->select->setValue($inOptions['values']);
220+
221+
$this->assertEquals($expectedResult, $this->select->getHtml());
222+
223+
// reset
224+
$this->select->setOptions([]);
225+
}
226+
}
227+
228+
/**
229+
* @return array
230+
*/
231+
private function getOptionsWithSingleQuotes()
232+
{
233+
return [
234+
'id' => "testId",
235+
'name' => "test[name]",
236+
'class' => "test class",
237+
'title' => "test'Title",
238+
'options' => [
239+
'regular' => [
240+
'value' => 'testValue',
241+
'label' => "test'Label",
242+
'params' => ['paramKey' => "param'Value"]
243+
],
244+
'selected' => [
245+
'value' => 'selectedValue',
246+
'label' => "selected'Label",
247+
'params' => []
248+
],
249+
'optgroup' => [
250+
'value' => [
251+
'groupElementValue' => "GroupElement'Label",
252+
'selectedGroupElementValue' => "SelectedGroupElement'Label"
253+
],
254+
'label' => "group'Label",
255+
'params' => []
256+
]
257+
],
258+
'values' => ['selectedValue', 'selectedGroupElementValue']
259+
];
260+
}
261+
262+
/**
263+
* @return array
264+
*/
265+
private function getOptionsWithDoubleQuotes()
266+
{
267+
return [
268+
'id' => 'testId',
269+
'name' => 'test[name]',
270+
'class' => 'test class',
271+
'title' => 'test"Title',
272+
'options' => [
273+
'regular' => [
274+
'value' => 'testValue',
275+
'label' => 'test"Label',
276+
'params' => ['paramKey' => 'param"Value']
277+
],
278+
'selected' => [
279+
'value' => 'selectedValue',
280+
'label' => 'selected"Label',
281+
'params' => []
282+
],
283+
'optgroup' => [
284+
'value' => [
285+
'groupElementValue' => 'GroupElement"Label',
286+
'selectedGroupElementValue' => 'SelectedGroupElement"Label'
287+
],
288+
'label' => 'group"Label',
289+
'params' => []
290+
]
291+
],
292+
'values' => ['selectedValue', 'selectedGroupElementValue']
293+
];
168294
}
169295
}

0 commit comments

Comments
 (0)