Skip to content

Commit f29fe48

Browse files
author
Hwashiang Yu
committed
Merge remote-tracking branch 'origin/MC-19827' into HEAD
2 parents 18f12ee + 0b5a79f commit f29fe48

File tree

11 files changed

+175
-35
lines changed

11 files changed

+175
-35
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
class Widget extends \Magento\Backend\Block\Template
1616
{
1717
/**
18+
* Get ID
19+
*
1820
* @return string
1921
*/
2022
public function getId()
@@ -37,6 +39,8 @@ public function getSuffixId($suffix)
3739
}
3840

3941
/**
42+
* Get HTML ID
43+
*
4044
* @return string
4145
*/
4246
public function getHtmlId()
@@ -59,6 +63,8 @@ public function getCurrentUrl($params = [])
5963
}
6064

6165
/**
66+
* Prepare Breadcrumbs
67+
*
6268
* @param string $label
6369
* @param string|null $title
6470
* @param string|null $link
@@ -84,7 +90,13 @@ public function getButtonHtml($label, $onclick, $class = '', $buttonId = null, $
8490
return $this->getLayout()->createBlock(
8591
\Magento\Backend\Block\Widget\Button::class
8692
)->setData(
87-
['label' => $label, 'onclick' => $onclick, 'class' => $class, 'type' => 'button', 'id' => $buttonId]
93+
[
94+
'label' => $this->escapeHtml($label),
95+
'onclick' => $onclick,
96+
'class' => $class,
97+
'type' => 'button',
98+
'id' => $buttonId
99+
]
88100
)->setDataAttribute(
89101
$dataAttr
90102
)->toHtml();

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function getOptionHtml(Option $option)
227227
{
228228
$optionBlock = $this->getChildBlock($option->getType());
229229
if (!$optionBlock) {
230-
return __('There is no defined renderer for "%1" option type.', $option->getType());
230+
return $this->escapeHtml(__('There is no defined renderer for "%1" option type.', $option->getType()));
231231
}
232232
return $optionBlock->setOption($option)->toHtml();
233233
}
@@ -418,15 +418,18 @@ private function processOptions(string $optionId, array $options, DataObject $pr
418418
{
419419
$preConfiguredQtys = $preConfiguredValues->getData("bundle_option_qty/${optionId}") ?? [];
420420
$selections = $options[$optionId]['selections'];
421-
array_walk($selections, function (&$selection, $selectionId) use ($preConfiguredQtys) {
422-
if (is_array($preConfiguredQtys) && isset($preConfiguredQtys[$selectionId])) {
423-
$selection['qty'] = $preConfiguredQtys[$selectionId];
424-
} else {
425-
if ((int)$preConfiguredQtys > 0) {
426-
$selection['qty'] = $preConfiguredQtys;
421+
array_walk(
422+
$selections,
423+
function (&$selection, $selectionId) use ($preConfiguredQtys) {
424+
if (is_array($preConfiguredQtys) && isset($preConfiguredQtys[$selectionId])) {
425+
$selection['qty'] = $preConfiguredQtys[$selectionId];
426+
} else {
427+
if ((int)$preConfiguredQtys > 0) {
428+
$selection['qty'] = $preConfiguredQtys;
429+
}
427430
}
428431
}
429-
});
432+
);
430433
$options[$optionId]['selections'] = $selections;
431434

432435
return $options;

app/code/Magento/Bundle/Test/Unit/Block/Catalog/Product/View/Type/BundleTest.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\Bundle\Test\Unit\Block\Catalog\Product\View\Type;
77

88
use Magento\Bundle\Block\Catalog\Product\View\Type\Bundle as BundleBlock;
9+
use Magento\Catalog\Block\Product\Context;
10+
use \Magento\Framework\Escaper;
911

1012
/**
1113
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -42,10 +44,18 @@ class BundleTest extends \PHPUnit\Framework\TestCase
4244
*/
4345
private $bundleBlock;
4446

47+
/**
48+
* @var \Magento\Framework\Escaper|\PHPUnit_Framework_MockObject_MockObject
49+
*/
50+
private $escaper;
51+
52+
/** @var \Magento\Catalog\Block\Product\Context|\PHPUnit_Framework_MockObject_MockObject */
53+
protected $context;
54+
4555
protected function setUp()
4656
{
4757
$objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
48-
58+
$this->context = $this->createPartialMock(Context::class, ['getEscaper', 'getRegistry', 'getEventManager']);
4959
$this->bundleProductPriceFactory = $this->getMockBuilder(\Magento\Bundle\Model\Product\PriceFactory::class)
5060
->disableOriginalConstructor()
5161
->setMethods(['create'])
@@ -79,15 +89,23 @@ protected function setUp()
7989
$this->catalogProduct = $this->getMockBuilder(\Magento\Catalog\Helper\Product::class)
8090
->disableOriginalConstructor()
8191
->getMock();
92+
93+
$this->escaper = $objectHelper->getObject(Escaper::class);
94+
95+
$this->context->expects($this->once())->method('getRegistry')->willReturn($registry);
96+
$this->context->expects($this->once())->method('getEscaper')->willReturn($this->escaper);
97+
$this->context->expects($this->once())->method('getEventManager')->willReturn($this->eventManager);
98+
8299
/** @var $bundleBlock BundleBlock */
83100
$this->bundleBlock = $objectHelper->getObject(
84101
\Magento\Bundle\Block\Catalog\Product\View\Type\Bundle::class,
85102
[
103+
'context'=> $this->context,
86104
'registry' => $registry,
87105
'eventManager' => $this->eventManager,
88106
'jsonEncoder' => $this->jsonEncoder,
89107
'productPrice' => $this->bundleProductPriceFactory,
90-
'catalogProduct' => $this->catalogProduct
108+
'catalogProduct' => $this->catalogProduct,
91109
]
92110
);
93111

@@ -108,16 +126,16 @@ public function testGetOptionHtmlNoRenderer()
108126
->disableOriginalConstructor()
109127
->getMock();
110128
$option->expects($this->any())->method('getType')->willReturn('checkbox');
129+
$expected='There is no defined renderer for "checkbox" option type.';
111130

112131
$layout = $this->getMockBuilder(\Magento\Framework\View\Layout::class)
113132
->setMethods(['getChildName', 'getBlock'])
114133
->disableOriginalConstructor()
115134
->getMock();
116135
$layout->expects($this->any())->method('getChildName')->willReturn(false);
117136
$this->bundleBlock->setLayout($layout);
118-
119137
$this->assertEquals(
120-
'There is no defined renderer for "checkbox" option type.',
138+
$expected,
121139
$this->bundleBlock->getOptionHtml($option)
122140
);
123141
}

app/code/Magento/Catalog/Block/Product/View/Options/Type/Date.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function getTimeHtml()
145145
$dayPartHtml = $this->_getHtmlSelect(
146146
'day_part'
147147
)->setOptions(
148-
['am' => __('AM'), 'pm' => __('PM')]
148+
['am' => $this->escapeHtml(__('AM')), 'pm' => $this->escapeHtml(__('PM'))]
149149
)->getHtml();
150150
}
151151
$hoursHtml = $this->_getSelectFromToHtml('hour', $hourStart, $hourEnd);
@@ -158,8 +158,8 @@ public function getTimeHtml()
158158
* Return drop-down html with range of values
159159
*
160160
* @param string $name Id/name of html select element
161-
* @param int $from Start position
162-
* @param int $to End position
161+
* @param int $from Start position
162+
* @param int $to End position
163163
* @param int|null $value Value selected
164164
* @return string Formatted Html
165165
*/

app/code/Magento/Checkout/Block/Cart.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\Checkout\Block;
77

88
use Magento\Customer\Model\Context;
9+
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\Framework\Phrase;
911

1012
/**
1113
* Shopping cart block
@@ -68,7 +70,7 @@ protected function _construct()
6870
}
6971

7072
/**
71-
* prepare cart items URLs
73+
* Prepare cart items URLs
7274
*
7375
* @return void
7476
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
@@ -110,6 +112,8 @@ public function prepareItemUrls()
110112
}
111113

112114
/**
115+
* Check quote for error
116+
*
113117
* @codeCoverageIgnore
114118
* @return bool
115119
*/
@@ -119,6 +123,8 @@ public function hasError()
119123
}
120124

121125
/**
126+
* Get Items Summary Qty
127+
*
122128
* @codeCoverageIgnore
123129
* @return int
124130
*/
@@ -128,6 +134,8 @@ public function getItemsSummaryQty()
128134
}
129135

130136
/**
137+
* Check if Wishlist Active
138+
*
131139
* @codeCoverageIgnore
132140
* @return bool
133141
*/
@@ -147,6 +155,8 @@ public function isWishlistActive()
147155
}
148156

149157
/**
158+
* Get Checkout Url
159+
*
150160
* @codeCoverageIgnore
151161
* @return string
152162
*/
@@ -156,6 +166,8 @@ public function getCheckoutUrl()
156166
}
157167

158168
/**
169+
* Get Continue Shopping Url
170+
*
159171
* @return string
160172
*/
161173
public function getContinueShoppingUrl()
@@ -172,6 +184,8 @@ public function getContinueShoppingUrl()
172184
}
173185

174186
/**
187+
* Check if quote is virtual
188+
*
175189
* @return bool
176190
* @codeCoverageIgnore
177191
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
@@ -207,7 +221,7 @@ public function getMethodHtml($name)
207221
{
208222
$block = $this->getLayout()->getBlock($name);
209223
if (!$block) {
210-
throw new \Magento\Framework\Exception\LocalizedException(__('Invalid method: %1', $name));
224+
throw new LocalizedException(new Phrase($this->escapeHtml(__('Invalid method: %1', $name))));
211225
}
212226
return $block->toHtml();
213227
}
@@ -227,6 +241,8 @@ public function getItems()
227241
}
228242

229243
/**
244+
* Get Items Count
245+
*
230246
* @codeCoverageIgnore
231247
* @return int
232248
*/
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Checkout\Test\Unit\Block;
7+
8+
use Magento\Framework\View\Element\Template\Context;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\Quote\Model\Quote;
11+
use Magento\Checkout\Model\Session;
12+
use Magento\Framework\View\LayoutInterface;
13+
use Magento\Framework\Escaper;
14+
15+
class CartTest extends \PHPUnit\Framework\TestCase
16+
{
17+
18+
/**
19+
* @var \Magento\Checkout\Block\Cart
20+
*/
21+
private $cartBlock;
22+
23+
/**
24+
* @var \Magento\Framework\Escaper|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $escaper;
27+
28+
/** @var \Magento\Checkout\Block\Cart|\PHPUnit_Framework_MockObject_MockObject */
29+
private $context;
30+
31+
/** @var \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject */
32+
private $layoutMock;
33+
34+
protected function setUp()
35+
{
36+
$objectManager = new ObjectManager($this);
37+
$this->context = $this->createPartialMock(Context::class, ['getEscaper', 'getLayout']);
38+
$quoteMock = $this->createMock(Quote::class);
39+
$checkoutSession = $this->createMock(Session::class);
40+
$this->layoutMock = $this->createMock(LayoutInterface::class);
41+
$this->escaper = $objectManager->getObject(Escaper::class);
42+
$quoteMock->expects($this->once())->method('getAllVisibleItems')->willReturn([]);
43+
$checkoutSession->expects($this->any())->method('getQuote')->willReturn($quoteMock);
44+
$this->context->expects($this->once())->method('getEscaper')->willReturn($this->escaper);
45+
$this->context->expects($this->once())->method('getLayout')->willReturn($this->layoutMock);
46+
47+
/** @var $cartBlock CartBlock */
48+
$this->cartBlock = $objectManager->getObject(
49+
\Magento\Checkout\Block\Cart::class,
50+
[
51+
'context'=> $this->context,
52+
'checkoutSession'=>$checkoutSession,
53+
54+
]
55+
);
56+
}
57+
58+
public function testGetMethodHtmlWithException()
59+
{
60+
$this->layoutMock->expects($this->any())->method('getBlock')->willReturn(false);
61+
$name='blockMethod';
62+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
63+
$this->expectExceptionMessage(
64+
(string)__('Invalid method: %1', $name)
65+
);
66+
$this->cartBlock->getMethodHtml($name);
67+
}
68+
}

app/code/Magento/Directory/Block/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function getCountryHtmlSelect($defValue = null, $name = 'country_id', $id
142142
)->setId(
143143
$id
144144
)->setTitle(
145-
__($title)
145+
$this->escapeHtml(__($title))
146146
)->setValue(
147147
$defValue
148148
)->setOptions(

0 commit comments

Comments
 (0)