Skip to content

Commit 3ab9936

Browse files
committed
Merge remote-tracking branch 'origin/2.2.8-develop' into MAGETWO-97960
2 parents 522f5f8 + a9d1215 commit 3ab9936

File tree

43 files changed

+989
-141
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+989
-141
lines changed

.htaccess

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
############################################
3131
## default index file
32+
## Specifies option, to use methods arguments in backtrace or not
33+
SetEnv MAGE_DEBUG_SHOW_ARGS 1
3234

3335
DirectoryIndex index.php
3436

app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/AdditionalCommentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class AdditionalCommentTest extends \PHPUnit\Framework\TestCase
3636
protected function setUp()
3737
{
3838
$this->abstractElementMock = $this->getMockBuilder(AbstractElement::class)
39-
->setMethods(['getComment', 'getLabel'])
39+
->setMethods(['getComment', 'getLabel', 'getHtmlId', 'getName'])
4040
->disableOriginalConstructor()
4141
->getMock();
4242
$this->contextMock = $this->getMockBuilder(Context::class)

app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/CollectionTimeLabelTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CollectionTimeLabelTest extends \PHPUnit\Framework\TestCase
3737
protected function setUp()
3838
{
3939
$this->abstractElementMock = $this->getMockBuilder(AbstractElement::class)
40-
->setMethods(['getComment'])
40+
->setMethods(['getComment', 'getHtmlId', 'getName'])
4141
->disableOriginalConstructor()
4242
->getMock();
4343
$this->contextMock = $this->getMockBuilder(Context::class)

app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/SubscriptionStatusLabelTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected function setUp()
5151
->disableOriginalConstructor()
5252
->getMock();
5353
$this->abstractElementMock = $this->getMockBuilder(AbstractElement::class)
54-
->setMethods(['getComment'])
54+
->setMethods(['getComment', 'getHtmlId', 'getName'])
5555
->disableOriginalConstructor()
5656
->getMock();
5757
$this->formMock = $this->getMockBuilder(Form::class)

app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/VerticalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class VerticalTest extends \PHPUnit\Framework\TestCase
3636
protected function setUp()
3737
{
3838
$this->abstractElementMock = $this->getMockBuilder(AbstractElement::class)
39-
->setMethods(['getComment', 'getLabel', 'getHint'])
39+
->setMethods(['getComment', 'getLabel', 'getHint', 'getHtmlId', 'getName'])
4040
->disableOriginalConstructor()
4141
->getMock();
4242
$this->contextMock = $this->getMockBuilder(Context::class)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function _construct()
8383
-1
8484
);
8585

86-
$objId = $this->getRequest()->getParam($this->_objectId);
86+
$objId = (int)$this->getRequest()->getParam($this->_objectId);
8787

8888
if (!empty($objId)) {
8989
$this->addButton(
@@ -155,7 +155,7 @@ public function getBackUrl()
155155
*/
156156
public function getDeleteUrl()
157157
{
158-
return $this->getUrl('*/*/delete', [$this->_objectId => $this->getRequest()->getParam($this->_objectId)]);
158+
return $this->getUrl('*/*/delete', [$this->_objectId => (int)$this->getRequest()->getParam($this->_objectId)]);
159159
}
160160

161161
/**

app/code/Magento/Catalog/Model/Config/CatalogClone/Media/Image.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
*/
66
namespace Magento\Catalog\Model\Config\CatalogClone\Media;
77

8+
use Magento\Framework\Escaper;
9+
use Magento\Framework\App\ObjectManager;
10+
811
/**
912
* Clone model for media images related config fields
1013
*
1114
* @SuppressWarnings(PHPMD.LongVariable)
15+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1216
*/
1317
class Image extends \Magento\Framework\App\Config\Value
1418
{
@@ -26,6 +30,11 @@ class Image extends \Magento\Framework\App\Config\Value
2630
*/
2731
protected $_attributeCollectionFactory;
2832

33+
/**
34+
* @var Escaper
35+
*/
36+
private $escaper;
37+
2938
/**
3039
* @param \Magento\Framework\Model\Context $context
3140
* @param \Magento\Framework\Registry $registry
@@ -36,6 +45,9 @@ class Image extends \Magento\Framework\App\Config\Value
3645
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
3746
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
3847
* @param array $data
48+
* @param Escaper|null $escaper
49+
*
50+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
3951
*/
4052
public function __construct(
4153
\Magento\Framework\Model\Context $context,
@@ -46,8 +58,10 @@ public function __construct(
4658
\Magento\Eav\Model\Config $eavConfig,
4759
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
4860
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
49-
array $data = []
61+
array $data = [],
62+
Escaper $escaper = null
5063
) {
64+
$this->escaper = $escaper ?? ObjectManager::getInstance()->get(Escaper::class);
5165
$this->_attributeCollectionFactory = $attributeCollectionFactory;
5266
$this->_eavConfig = $eavConfig;
5367
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
@@ -74,7 +88,7 @@ public function getPrefixes()
7488
/* @var $attribute \Magento\Eav\Model\Entity\Attribute */
7589
$prefixes[] = [
7690
'field' => $attribute->getAttributeCode() . '_',
77-
'label' => $attribute->getFrontend()->getLabel(),
91+
'label' => $this->escaper->escapeHtml($attribute->getFrontend()->getLabel()),
7892
];
7993
}
8094

app/code/Magento/Catalog/Test/Unit/Model/Config/CatalogClone/Media/ImageTest.php

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ class ImageTest extends \PHPUnit\Framework\TestCase
3636
*/
3737
private $attribute;
3838

39+
/**
40+
* @var \Magento\Framework\Escaper|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
private $escaperMock;
43+
44+
/**
45+
* @inheritdoc
46+
*/
3947
protected function setUp()
4048
{
4149
$this->eavConfig = $this->getMockBuilder(\Magento\Eav\Model\Config::class)
@@ -62,54 +70,78 @@ protected function setUp()
6270
->disableOriginalConstructor()
6371
->getMock();
6472

73+
$this->escaperMock = $this->getMockBuilder(
74+
\Magento\Framework\Escaper::class
75+
)
76+
->disableOriginalConstructor()
77+
->setMethods(['escapeHtml'])
78+
->getMock();
79+
6580
$helper = new ObjectManager($this);
6681
$this->model = $helper->getObject(
6782
\Magento\Catalog\Model\Config\CatalogClone\Media\Image::class,
6883
[
6984
'eavConfig' => $this->eavConfig,
70-
'attributeCollectionFactory' => $this->attributeCollectionFactory
85+
'attributeCollectionFactory' => $this->attributeCollectionFactory,
86+
'escaper' => $this->escaperMock,
7187
]
7288
);
7389
}
7490

75-
public function testGetPrefixes()
91+
/**
92+
* @param string $actualLabel
93+
* @param string $expectedLabel
94+
* @return void
95+
* @dataProvider getPrefixesDataProvider
96+
*/
97+
public function testGetPrefixes(string $actualLabel, string $expectedLabel)
7698
{
7799
$entityTypeId = 3;
78100
/** @var \Magento\Eav\Model\Entity\Type|\PHPUnit_Framework_MockObject_MockObject $entityType */
79101
$entityType = $this->getMockBuilder(\Magento\Eav\Model\Entity\Type::class)
80102
->disableOriginalConstructor()
81103
->getMock();
82-
$entityType->expects($this->once())->method('getId')->will($this->returnValue($entityTypeId));
104+
$entityType->expects($this->once())->method('getId')->willReturn($entityTypeId);
83105

84106
/** @var AbstractFrontend|\PHPUnit_Framework_MockObject_MockObject $frontend */
85107
$frontend = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend::class)
86108
->setMethods(['getLabel'])
87109
->disableOriginalConstructor()
88110
->getMockForAbstractClass();
89-
$frontend->expects($this->once())->method('getLabel')->will($this->returnValue('testLabel'));
111+
$frontend->expects($this->once())->method('getLabel')->willReturn($actualLabel);
90112

91-
$this->attributeCollection->expects($this->once())->method('setEntityTypeFilter')->with(
92-
$this->equalTo($entityTypeId)
93-
);
94-
$this->attributeCollection->expects($this->once())->method('setFrontendInputTypeFilter')->with(
95-
$this->equalTo('media_image')
96-
);
113+
$this->attributeCollection->expects($this->once())->method('setEntityTypeFilter')->with($entityTypeId);
114+
$this->attributeCollection->expects($this->once())->method('setFrontendInputTypeFilter')->with('media_image');
97115

98-
$this->attribute->expects($this->once())->method('getAttributeCode')->will(
99-
$this->returnValue('attributeCode')
100-
);
101-
$this->attribute->expects($this->once())->method('getFrontend')->will(
102-
$this->returnValue($frontend)
103-
);
116+
$this->attribute->expects($this->once())->method('getAttributeCode')->willReturn('attributeCode');
117+
$this->attribute->expects($this->once())->method('getFrontend')->willReturn($frontend);
104118

105-
$this->attributeCollection->expects($this->any())->method('getIterator')->will(
106-
$this->returnValue(new \ArrayIterator([$this->attribute]))
107-
);
119+
$this->attributeCollection->expects($this->any())->method('getIterator')
120+
->willReturn(new \ArrayIterator([$this->attribute]));
121+
122+
$this->eavConfig->expects($this->any())->method('getEntityType')->with(Product::ENTITY)
123+
->willReturn($entityType);
124+
125+
$this->escaperMock->expects($this->once())->method('escapeHtml')->with($actualLabel)
126+
->willReturn($expectedLabel);
108127

109-
$this->eavConfig->expects($this->any())->method('getEntityType')->with(
110-
$this->equalTo(Product::ENTITY)
111-
)->will($this->returnValue($entityType));
128+
$this->assertEquals([['field' => 'attributeCode_', 'label' => $expectedLabel]], $this->model->getPrefixes());
129+
}
112130

113-
$this->assertEquals([['field' => 'attributeCode_', 'label' => 'testLabel']], $this->model->getPrefixes());
131+
/**
132+
* @return array
133+
*/
134+
public function getPrefixesDataProvider(): array
135+
{
136+
return [
137+
[
138+
'actual_label' => 'testLabel',
139+
'expected_label' => 'testLabel',
140+
],
141+
[
142+
'actual_label' => '<media-image-attributelabel',
143+
'expected_label' => '&lt;media-image-attributelabel',
144+
],
145+
];
114146
}
115147
}

app/code/Magento/CheckoutAgreements/Model/AgreementsConfigProvider.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,18 @@ public function __construct(
4545
}
4646

4747
/**
48-
* {@inheritdoc}
48+
* @inheritdoc
4949
*/
5050
public function getConfig()
5151
{
5252
$agreements = [];
5353
$agreements['checkoutAgreements'] = $this->getAgreementsConfig();
54+
5455
return $agreements;
5556
}
5657

5758
/**
58-
* Returns agreements config
59+
* Returns agreements config.
5960
*
6061
* @return array
6162
*/
@@ -75,7 +76,7 @@ protected function getAgreementsConfig()
7576
'content' => $agreement->getIsHtml()
7677
? $agreement->getContent()
7778
: nl2br($this->escaper->escapeHtml($agreement->getContent())),
78-
'checkboxText' => $agreement->getCheckboxText(),
79+
'checkboxText' => $this->escaper->escapeHtml($agreement->getCheckboxText()),
7980
'mode' => $agreement->getMode(),
8081
'agreementId' => $agreement->getAgreementId()
8182
];

app/code/Magento/CheckoutAgreements/Test/Unit/Model/AgreementsConfigProviderTest.php

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Magento\CheckoutAgreements\Model\AgreementsProvider;
99
use Magento\Store\Model\ScopeInterface;
1010

11+
/**
12+
* Tests for AgreementsConfigProvider.
13+
*/
1114
class AgreementsConfigProviderTest extends \PHPUnit\Framework\TestCase
1215
{
1316
/**
@@ -30,6 +33,9 @@ class AgreementsConfigProviderTest extends \PHPUnit\Framework\TestCase
3033
*/
3134
protected $escaperMock;
3235

36+
/**
37+
* @inheritdoc
38+
*/
3339
protected function setUp()
3440
{
3541
$this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
@@ -45,10 +51,16 @@ protected function setUp()
4551
);
4652
}
4753

54+
/**
55+
* Test for getConfig if content is HTML.
56+
*
57+
* @return void
58+
*/
4859
public function testGetConfigIfContentIsHtml()
4960
{
5061
$content = 'content';
5162
$checkboxText = 'checkbox_text';
63+
$escapedCheckboxText = 'escaped_checkbox_text';
5264
$mode = \Magento\CheckoutAgreements\Model\AgreementModeOptions::MODE_AUTO;
5365
$agreementId = 100;
5466
$expectedResult = [
@@ -57,12 +69,12 @@ public function testGetConfigIfContentIsHtml()
5769
'agreements' => [
5870
[
5971
'content' => $content,
60-
'checkboxText' => $checkboxText,
72+
'checkboxText' => $escapedCheckboxText,
6173
'mode' => $mode,
62-
'agreementId' => $agreementId
63-
]
64-
]
65-
]
74+
'agreementId' => $agreementId,
75+
],
76+
],
77+
],
6678
];
6779

6880
$this->scopeConfigMock->expects($this->once())
@@ -71,8 +83,12 @@ public function testGetConfigIfContentIsHtml()
7183
->willReturn(true);
7284

7385
$agreement = $this->createMock(\Magento\CheckoutAgreements\Api\Data\AgreementInterface::class);
74-
$this->agreementsRepositoryMock->expects($this->any())->method('getList')->willReturn([$agreement]);
86+
$this->agreementsRepositoryMock->expects($this->once())->method('getList')->willReturn([$agreement]);
7587

88+
$this->escaperMock->expects($this->once())
89+
->method('escapeHtml')
90+
->with($checkboxText)
91+
->willReturn($escapedCheckboxText);
7692
$agreement->expects($this->once())->method('getIsHtml')->willReturn(true);
7793
$agreement->expects($this->once())->method('getContent')->willReturn($content);
7894
$agreement->expects($this->once())->method('getCheckboxText')->willReturn($checkboxText);
@@ -82,11 +98,17 @@ public function testGetConfigIfContentIsHtml()
8298
$this->assertEquals($expectedResult, $this->model->getConfig());
8399
}
84100

101+
/**
102+
* Test for getConfig if content is not HTML.
103+
*
104+
* @return void
105+
*/
85106
public function testGetConfigIfContentIsNotHtml()
86107
{
87108
$content = 'content';
88109
$escapedContent = 'escaped_content';
89110
$checkboxText = 'checkbox_text';
111+
$escapedCheckboxText = 'escaped_checkbox_text';
90112
$mode = \Magento\CheckoutAgreements\Model\AgreementModeOptions::MODE_AUTO;
91113
$agreementId = 100;
92114
$expectedResult = [
@@ -95,12 +117,12 @@ public function testGetConfigIfContentIsNotHtml()
95117
'agreements' => [
96118
[
97119
'content' => $escapedContent,
98-
'checkboxText' => $checkboxText,
120+
'checkboxText' => $escapedCheckboxText,
99121
'mode' => $mode,
100-
'agreementId' => $agreementId
101-
]
102-
]
103-
]
122+
'agreementId' => $agreementId,
123+
],
124+
],
125+
],
104126
];
105127

106128
$this->scopeConfigMock->expects($this->once())
@@ -109,9 +131,13 @@ public function testGetConfigIfContentIsNotHtml()
109131
->willReturn(true);
110132

111133
$agreement = $this->createMock(\Magento\CheckoutAgreements\Api\Data\AgreementInterface::class);
112-
$this->agreementsRepositoryMock->expects($this->any())->method('getList')->willReturn([$agreement]);
113-
$this->escaperMock->expects($this->once())->method('escapeHtml')->with($content)->willReturn($escapedContent);
134+
$this->agreementsRepositoryMock->expects($this->once())->method('getList')->willReturn([$agreement]);
114135

136+
$this->escaperMock->expects($this->at(0))->method('escapeHtml')->with($content)->willReturn($escapedContent);
137+
$this->escaperMock->expects($this->at(1))
138+
->method('escapeHtml')
139+
->with($checkboxText)
140+
->willReturn($escapedCheckboxText);
115141
$agreement->expects($this->once())->method('getIsHtml')->willReturn(false);
116142
$agreement->expects($this->once())->method('getContent')->willReturn($content);
117143
$agreement->expects($this->once())->method('getCheckboxText')->willReturn($checkboxText);

0 commit comments

Comments
 (0)