Skip to content

Commit aeb4243

Browse files
committed
Merge remote-tracking branch 'remotes/mainline/2.1.18-develop' into MAGETWO-98738
2 parents 09ef6f4 + f8f2036 commit aeb4243

File tree

9 files changed

+149
-65
lines changed

9 files changed

+149
-65
lines changed

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Catalog\Api\Data\ProductAttributeInterface;
99
use Magento\Catalog\Api\ProductAttributeGroupRepositoryInterface;
1010
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
11+
use Magento\Eav\Model\Entity\Attribute\Source\SourceInterface;
1112
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1213
use Magento\Catalog\Model\ResourceModel\Eav\Attribute as EavAttribute;
1314
use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory as EavAttributeFactory;
@@ -254,7 +255,15 @@ protected function setUp()
254255
$this->searchResultsMock = $this->getMockBuilder(SearchResultsInterface::class)
255256
->getMockForAbstractClass();
256257
$this->eavAttributeMock = $this->getMockBuilder(Attribute::class)
257-
->setMethods(['load', 'getAttributeGroupCode', 'getApplyTo', 'getFrontendInput', 'getAttributeCode'])
258+
->setMethods([
259+
'load',
260+
'getAttributeGroupCode',
261+
'getApplyTo',
262+
'getFrontendInput',
263+
'getAttributeCode',
264+
'usesSource',
265+
'getSource',
266+
])
258267
->disableOriginalConstructor()
259268
->getMock();
260269
$this->productAttributeMock = $this->getMockBuilder(ProductAttributeInterface::class)
@@ -460,6 +469,20 @@ public function testSetupAttributeMetaDefaultAttribute($productId, array $attrib
460469
$configPath = 'arguments/data/config';
461470
$groupCode = 'product-details';
462471
$sortOrder = '0';
472+
$attributeOptions = [
473+
['value' => 1, 'label' => 'Int label'],
474+
['value' => 1.5, 'label' => 'Float label'],
475+
['value' => true, 'label' => 'Boolean label'],
476+
['value' => 'string', 'label' => 'String label'],
477+
['value' => ['test1', 'test2'], 'label' => 'Array label'],
478+
];
479+
$attributeOptionsExpected = [
480+
['value' => '1', 'label' => 'Int label', '__disableTmpl' => true],
481+
['value' => '1.5', 'label' => 'Float label', '__disableTmpl' => true],
482+
['value' => '1', 'label' => 'Boolean label', '__disableTmpl' => true],
483+
['value' => 'string', 'label' => 'String label', '__disableTmpl' => true],
484+
['value' => ['test1', 'test2'], 'label' => 'Array label', '__disableTmpl' => true],
485+
];
463486

464487
$this->productMock->expects($this->any())
465488
->method('getId')
@@ -491,6 +514,11 @@ public function testSetupAttributeMetaDefaultAttribute($productId, array $attrib
491514
->method('getCustomAttribute')
492515
->willReturn($attributeMock);
493516

517+
$this->eavAttributeMock->method('usesSource')->willReturn(true);
518+
$attributeSource = $this->getMockBuilder(SourceInterface::class)->getMockForAbstractClass();
519+
$attributeSource->method('getAllOptions')->willReturn($attributeOptions);
520+
$this->eavAttributeMock->method('getSource')->willReturn($attributeSource);
521+
494522
$this->arrayManagerMock->expects($this->any())
495523
->method('set')
496524
->with(
@@ -502,6 +530,15 @@ public function testSetupAttributeMetaDefaultAttribute($productId, array $attrib
502530

503531
$this->arrayManagerMock->expects($this->any())
504532
->method('merge')
533+
->with(
534+
$this->anything(),
535+
$this->anything(),
536+
$this->callback(
537+
function ($value) use ($attributeOptionsExpected) {
538+
return isset($value['options']) ? $value['options'] === $attributeOptionsExpected : true;
539+
}
540+
)
541+
)
505542
->willReturn($expected);
506543

507544
$this->arrayManagerMock->expects($this->any())

app/code/Magento/Catalog/Ui/Component/ColumnFactory.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
*/
66
namespace Magento\Catalog\Ui\Component;
77

8+
use Magento\Ui\Component\Filters\FilterModifier;
9+
10+
/**
11+
* Product grid columns factory.
12+
*/
813
class ColumnFactory
914
{
1015
/**
@@ -50,19 +55,24 @@ public function __construct(\Magento\Framework\View\Element\UiComponentFactory $
5055
*/
5156
public function create($attribute, $context, array $config = [])
5257
{
58+
$filterModifiers = $context->getRequestParam(FilterModifier::FILTER_MODIFIER, []);
59+
5360
$columnName = $attribute->getAttributeCode();
5461
$config = array_merge([
5562
'label' => __($attribute->getDefaultFrontendLabel()),
5663
'dataType' => $this->getDataType($attribute),
5764
'add_field' => true,
5865
'visible' => $attribute->getIsVisibleInGrid(),
59-
'filter' => ($attribute->getIsFilterableInGrid())
66+
'filter' => ($attribute->getIsFilterableInGrid() || array_key_exists($columnName, $filterModifiers))
6067
? $this->getFilterType($attribute->getFrontendInput())
6168
: null,
6269
], $config);
6370

6471
if ($attribute->usesSource()) {
6572
$config['options'] = $attribute->getSource()->getAllOptions();
73+
foreach ($config['options'] as &$optionData) {
74+
$optionData['__disableTmpl'] = true;
75+
}
6676
}
6777

6878
$config['component'] = $this->getJsComponent($config['dataType']);

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,12 @@ public function setupAttributeMeta(ProductAttributeInterface $attribute, $groupC
568568
// TODO: Refactor to $attribute->getOptions() when MAGETWO-48289 is done
569569
$attributeModel = $this->getAttributeModel($attribute);
570570
if ($attributeModel->usesSource()) {
571+
$options = $attributeModel->getSource()->getAllOptions();
572+
foreach ($options as &$option) {
573+
$option['__disableTmpl'] = true;
574+
}
571575
$meta = $this->arrayManager->merge($configPath, $meta, [
572-
'options' => $attributeModel->getSource()->getAllOptions(),
576+
'options' => $this->convertOptionsValueToString($options),
573577
]);
574578
}
575579

@@ -622,6 +626,23 @@ public function setupAttributeMeta(ProductAttributeInterface $attribute, $groupC
622626
return $meta;
623627
}
624628

629+
/**
630+
* Convert options value to string.
631+
*
632+
* @param array $options
633+
* @return array
634+
*/
635+
private function convertOptionsValueToString(array $options)
636+
{
637+
array_walk($options, function (&$value) {
638+
if (isset($value['value']) && is_scalar($value['value'])) {
639+
$value['value'] = (string)$value['value'];
640+
}
641+
});
642+
643+
return $options;
644+
}
645+
625646
/**
626647
* @param ProductAttributeInterface $attribute
627648
* @param array $meta

app/code/Magento/Cms/Test/Unit/Ui/Component/Listing/Column/BlockActionsTest.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1515

1616
/**
17-
* BlockActionsTest contains unit tests for \Magento\Cms\Ui\Component\Listing\Column\BlockActions class
17+
* BlockActionsTest contains unit tests for \Magento\Cms\Ui\Component\Listing\Column\BlockActions class.
1818
*/
1919
class BlockActionsTest extends \PHPUnit_Framework_TestCase
2020
{
@@ -33,6 +33,9 @@ class BlockActionsTest extends \PHPUnit_Framework_TestCase
3333
*/
3434
private $urlBuilder;
3535

36+
/**
37+
* @inheritdoc
38+
*/
3639
protected function setUp()
3740
{
3841
$objectManager = new ObjectManager($this);
@@ -42,15 +45,15 @@ protected function setUp()
4245
$processor = $this->getMockBuilder(Processor::class)
4346
->disableOriginalConstructor()
4447
->getMock();
45-
$context->expects(static::once())
48+
$context->expects($this->once())
4649
->method('getProcessor')
4750
->willReturn($processor);
4851

4952
$this->urlBuilder = $this->getMock(UrlInterface::class);
5053

5154
$this->escaper = $this->getMockBuilder(Escaper::class)
5255
->disableOriginalConstructor()
53-
->setMethods(['escapeHtml'])
56+
->setMethods(['escapeHtmlAttr'])
5457
->getMock();
5558

5659
$this->blockActions = $objectManager->getObject(BlockActions::class, [
@@ -62,7 +65,10 @@ protected function setUp()
6265
}
6366

6467
/**
68+
* Unit test for prepareDataSource method.
69+
*
6570
* @covers \Magento\Cms\Ui\Component\Listing\Column\BlockActions::prepareDataSource
71+
* @return void
6672
*/
6773
public function testPrepareDataSource()
6874
{
@@ -73,7 +79,7 @@ public function testPrepareDataSource()
7379
'items' => [
7480
[
7581
'block_id' => $blockId,
76-
'title' => $title
82+
'title' => $title,
7783
],
7884
],
7985
],
@@ -93,20 +99,20 @@ public function testPrepareDataSource()
9399
'label' => __('Delete'),
94100
'confirm' => [
95101
'title' => __('Delete %1', $title),
96-
'message' => __('Are you sure you wan\'t to delete a %1 record?', $title)
102+
'message' => __('Are you sure you want to delete a %1 record?', $title),
97103
],
98104
'post' => true,
99105
],
100106
],
101107
],
102108
];
103109

104-
$this->escaper->expects(static::once())
105-
->method('escapeHtml')
110+
$this->escaper->expects($this->once())
111+
->method('escapeHtmlAttr')
106112
->with($title)
107113
->willReturn($title);
108114

109-
$this->urlBuilder->expects(static::exactly(2))
115+
$this->urlBuilder->expects($this->exactly(2))
110116
->method('getUrl')
111117
->willReturnMap(
112118
[
@@ -130,6 +136,6 @@ public function testPrepareDataSource()
130136
$this->blockActions->setData('name', $name);
131137

132138
$actual = $this->blockActions->prepareDataSource($items);
133-
static::assertEquals($expectedItems, $actual['data']['items']);
139+
$this->assertEquals($expectedItems, $actual['data']['items']);
134140
}
135141
}

app/code/Magento/Cms/Ui/Component/Listing/Column/BlockActions.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Magento\Framework\Escaper;
1414

1515
/**
16-
* Class BlockActions
16+
* Class to build edit and delete link for each item.
1717
*/
1818
class BlockActions extends Column
1919
{
@@ -35,8 +35,6 @@ class BlockActions extends Column
3535
private $escaper;
3636

3737
/**
38-
* Constructor
39-
*
4038
* @param ContextInterface $context
4139
* @param UiComponentFactory $uiComponentFactory
4240
* @param UrlInterface $urlBuilder
@@ -55,38 +53,35 @@ public function __construct(
5553
}
5654

5755
/**
58-
* Prepare Data Source.
59-
*
60-
* @param array $dataSource
61-
* @return array
56+
* @inheritdoc
6257
*/
6358
public function prepareDataSource(array $dataSource)
6459
{
6560
if (isset($dataSource['data']['items'])) {
6661
foreach ($dataSource['data']['items'] as & $item) {
6762
if (isset($item['block_id'])) {
68-
$title = $this->getEscaper()->escapeHtml($item['title']);
63+
$title = $this->getEscaper()->escapeHtmlAttr($item['title']);
6964
$item[$this->getData('name')] = [
7065
'edit' => [
7166
'href' => $this->urlBuilder->getUrl(
7267
static::URL_PATH_EDIT,
7368
[
74-
'block_id' => $item['block_id']
69+
'block_id' => $item['block_id'],
7570
]
7671
),
77-
'label' => __('Edit')
72+
'label' => __('Edit'),
7873
],
7974
'delete' => [
8075
'href' => $this->urlBuilder->getUrl(
8176
static::URL_PATH_DELETE,
8277
[
83-
'block_id' => $item['block_id']
78+
'block_id' => $item['block_id'],
8479
]
8580
),
8681
'label' => __('Delete'),
8782
'confirm' => [
8883
'title' => __('Delete %1', $title),
89-
'message' => __('Are you sure you wan\'t to delete a %1 record?', $title),
84+
'message' => __('Are you sure you want to delete a %1 record?', $title),
9085
],
9186
'post' => true,
9287
],

app/code/Magento/Tax/Model/System/Message/Notifications.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Tax\Model\System\Message;
77

8+
use Magento\Framework\App\ObjectManager;
9+
810
/**
911
* Notifications class
1012
*/
@@ -57,22 +59,30 @@ class Notifications implements \Magento\Framework\Notification\MessageInterface
5759
*/
5860
private $notifications = [];
5961

62+
/**
63+
* @var \Magento\Framework\Escaper
64+
*/
65+
private $escaper;
66+
6067
/**
6168
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
6269
* @param \Magento\Framework\UrlInterface $urlBuilder
6370
* @param \Magento\Tax\Model\Config $taxConfig
6471
* @param NotificationInterface[] $notifications
72+
* @param \Magento\Framework\Escaper|null $escaper
6573
*/
6674
public function __construct(
6775
\Magento\Store\Model\StoreManagerInterface $storeManager,
6876
\Magento\Framework\UrlInterface $urlBuilder,
6977
\Magento\Tax\Model\Config $taxConfig,
70-
$notifications = []
78+
$notifications = [],
79+
\Magento\Framework\Escaper $escaper = null
7180
) {
7281
$this->storeManager = $storeManager;
7382
$this->urlBuilder = $urlBuilder;
7483
$this->taxConfig = $taxConfig;
7584
$this->notifications = $notifications;
85+
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(\Magento\Framework\Escaper::class);
7686
}
7787

7888
/**
@@ -134,13 +144,13 @@ public function getSeverity()
134144
}
135145

136146
/**
137-
* Get URL for the tax notification documentation.
147+
* Get URL for the tax notification documentation
138148
*
139149
* @return string
140150
*/
141151
public function getInfoUrl()
142152
{
143-
return $this->taxConfig->getInfoUrl();
153+
return $this->escaper->escapeUrl($this->taxConfig->getInfoUrl());
144154
}
145155

146156
/**

0 commit comments

Comments
 (0)