Skip to content

Commit d69c242

Browse files
authored
Merge pull request #5542 from magento-tsg/2.4-develop-pr23
[TSG] Fixes for 2.4 (pr23) (2.4-develop)
2 parents 87b7cba + 6278dc9 commit d69c242

File tree

49 files changed

+1996
-1021
lines changed

Some content is hidden

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

49 files changed

+1996
-1021
lines changed

app/code/Magento/Catalog/Model/Layer/FilterList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ protected function getAttributeFilterClass(\Magento\Catalog\Model\ResourceModel\
123123
{
124124
$filterClassName = $this->filterTypes[self::ATTRIBUTE_FILTER];
125125

126-
if ($attribute->getFrontendInput() === 'price') {
126+
if ($attribute->getAttributeCode() == 'price') {
127127
$filterClassName = $this->filterTypes[self::PRICE_FILTER];
128-
} elseif ($attribute->getBackendType() === 'decimal') {
128+
} elseif ($attribute->getBackendType() == 'decimal') {
129129
$filterClassName = $this->filterTypes[self::DECIMAL_FILTER];
130130
}
131131

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
<?php
22
/**
3-
* Depersonalize catalog session data
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
6+
declare(strict_types=1);
7+
88
namespace Magento\Catalog\Model\Layout;
99

10+
use Magento\Catalog\Model\Session as CatalogSession;
11+
use Magento\Framework\View\LayoutInterface;
1012
use Magento\PageCache\Model\DepersonalizeChecker;
1113

1214
/**
13-
* Class DepersonalizePlugin
15+
* Depersonalize customer data.
16+
*
17+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1418
*/
1519
class DepersonalizePlugin
1620
{
1721
/**
1822
* @var DepersonalizeChecker
1923
*/
20-
protected $depersonalizeChecker;
24+
private $depersonalizeChecker;
2125

2226
/**
23-
* Catalog session
24-
*
25-
* @var \Magento\Catalog\Model\Session
27+
* @var CatalogSession
2628
*/
27-
protected $catalogSession;
29+
private $catalogSession;
2830

2931
/**
3032
* @param DepersonalizeChecker $depersonalizeChecker
31-
* @param \Magento\Catalog\Model\Session $catalogSession
33+
* @param CatalogSession $catalogSession
3234
*/
3335
public function __construct(
3436
DepersonalizeChecker $depersonalizeChecker,
35-
\Magento\Catalog\Model\Session $catalogSession
37+
CatalogSession $catalogSession
3638
) {
37-
$this->catalogSession = $catalogSession;
3839
$this->depersonalizeChecker = $depersonalizeChecker;
40+
$this->catalogSession = $catalogSession;
3941
}
4042

4143
/**
42-
* After generate Xml
44+
* Change sensitive customer data if the depersonalization is needed.
4345
*
44-
* @param \Magento\Framework\View\LayoutInterface $subject
45-
* @param \Magento\Framework\View\LayoutInterface $result
46-
* @return \Magento\Framework\View\LayoutInterface
46+
* @param LayoutInterface $subject
47+
* @return void
4748
*/
48-
public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
49+
public function afterGenerateElements(LayoutInterface $subject)
4950
{
5051
if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
5152
$this->catalogSession->clearStorage();
5253
}
53-
return $result;
5454
}
5555
}

app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -282,28 +282,6 @@
282282
<data key="used_for_sort_by">false</data>
283283
<requiredEntity type="FrontendLabel">ProductAttributeFrontendLabel</requiredEntity>
284284
</entity>
285-
<entity name="productAttributeTypeOfPrice" type="ProductAttribute">
286-
<data key="attribute_code" unique="suffix">attribute</data>
287-
<data key="frontend_input">price</data>
288-
<data key="scope">global</data>
289-
<data key="is_required">false</data>
290-
<data key="is_unique">false</data>
291-
<data key="is_searchable">false</data>
292-
<data key="is_visible">true</data>
293-
<data key="is_wysiwyg_enabled">false</data>
294-
<data key="is_visible_in_advanced_search">false</data>
295-
<data key="is_visible_on_front">true</data>
296-
<data key="is_filterable">true</data>
297-
<data key="is_filterable_in_search">false</data>
298-
<data key="used_in_product_listing">false</data>
299-
<data key="is_used_for_promo_rules">false</data>
300-
<data key="is_comparable">true</data>
301-
<data key="is_used_in_grid">false</data>
302-
<data key="is_visible_in_grid">false</data>
303-
<data key="is_filterable_in_grid">false</data>
304-
<data key="used_for_sort_by">false</data>
305-
<requiredEntity type="FrontendLabel">ProductAttributeFrontendLabel</requiredEntity>
306-
</entity>
307285
<entity name="textProductAttribute" extends="productAttributeWysiwyg" type="ProductAttribute">
308286
<data key="frontend_input">text</data>
309287
<data key="default_value" unique="suffix">defaultValue</data>

app/code/Magento/Catalog/Test/Mftf/Section/StorefrontCategoryFilterSection.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@
1111
<section name="StorefrontCategoryFilterSection">
1212
<element name="CategoryFilter" type="button" selector="//main//div[@class='filter-options']//div[contains(text(), 'Category')]"/>
1313
<element name="CategoryByName" type="button" selector="//main//div[@class='filter-options']//li[@class='item']//a[contains(text(), '{{var1}}')]" parameterized="true"/>
14-
<element name="CustomPriceAttribute" type="button" selector="div.filter-options-title"/>
1514
</section>
1615
</sections>

app/code/Magento/Catalog/Test/Unit/Model/Layer/FilterListTest.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,9 @@ public function testGetFilters($method, $value, $expectedClass)
9494

9595
$this->objectManagerMock->expects($this->at(1))
9696
->method('create')
97-
->with(
98-
$expectedClass,
99-
[
100-
'data' => ['attribute_model' => $this->attributeMock],
101-
'layer' => $this->layerMock
102-
]
103-
)
97+
->with($expectedClass, [
98+
'data' => ['attribute_model' => $this->attributeMock],
99+
'layer' => $this->layerMock])
104100
->will($this->returnValue('filter'));
105101

106102
$this->attributeMock->expects($this->once())
@@ -169,8 +165,8 @@ public function getFiltersDataProvider()
169165
{
170166
return [
171167
[
172-
'method' => 'getFrontendInput',
173-
'value' => 'price',
168+
'method' => 'getAttributeCode',
169+
'value' => FilterList::PRICE_FILTER,
174170
'expectedClass' => 'PriceFilterClass',
175171
],
176172
[
@@ -179,8 +175,8 @@ public function getFiltersDataProvider()
179175
'expectedClass' => 'DecimalFilterClass',
180176
],
181177
[
182-
'method' => 'getFrontendInput',
183-
'value' => 'text',
178+
'method' => 'getAttributeCode',
179+
'value' => null,
184180
'expectedClass' => 'AttributeFilterClass',
185181
]
186182
];
@@ -195,8 +191,8 @@ public function getFiltersWithoutCategoryDataProvider(): array
195191
{
196192
return [
197193
'Filters contains only price attribute' => [
198-
'method' => 'getFrontendInput',
199-
'value' => 'price',
194+
'method' => 'getAttributeCode',
195+
'value' => FilterList::PRICE_FILTER,
200196
'expectedClass' => 'PriceFilterClass',
201197
'expectedResult' => [
202198
'filter'

app/code/Magento/Catalog/Test/Unit/Model/Layout/DepersonalizePluginTest.php

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,82 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Catalog\Test\Unit\Model\Layout;
89

9-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\Catalog\Model\Layout\DepersonalizePlugin;
11+
use Magento\Catalog\Model\Session as CatalogSession;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
13+
use Magento\Framework\View\LayoutInterface;
14+
use Magento\PageCache\Model\DepersonalizeChecker;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
1017

11-
class DepersonalizePluginTest extends \PHPUnit\Framework\TestCase
18+
/**
19+
* Unit tests for \Magento\Catalog\Model\Layout\DepersonalizePlugin class.
20+
*/
21+
class DepersonalizePluginTest extends TestCase
1222
{
1323
/**
14-
* @var \Magento\Catalog\Model\Layout\DepersonalizePlugin
24+
* @var DepersonalizePlugin
1525
*/
16-
protected $plugin;
26+
private $plugin;
1727

1828
/**
19-
* @var \Magento\Catalog\Model\Session|\PHPUnit_Framework_MockObject_MockObject
29+
* @var CatalogSession|MockObject
2030
*/
21-
protected $catalogSessionMock;
31+
private $catalogSessionMock;
2232

2333
/**
24-
* @var \Magento\PageCache\Model\DepersonalizeChecker|\PHPUnit_Framework_MockObject_MockObject
34+
* @var DepersonalizeChecker|MockObject
2535
*/
26-
protected $depersonalizeCheckerMock;
36+
private $depersonalizeCheckerMock;
2737

2838
/**
29-
* @var \Magento\Framework\View\Layout|\PHPUnit_Framework_MockObject_MockObject
39+
* @var LayoutInterface|MockObject
3040
*/
31-
protected $resultLayout;
41+
private $layoutMock;
3242

43+
/**
44+
* @inheritdoc
45+
*/
3346
protected function setUp()
3447
{
35-
$this->layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);
36-
$this->catalogSessionMock = $this->createPartialMock(\Magento\Catalog\Model\Session::class, ['clearStorage']);
37-
$this->resultLayout = $this->createMock(\Magento\Framework\View\Layout::class);
38-
$this->depersonalizeCheckerMock = $this->createMock(\Magento\PageCache\Model\DepersonalizeChecker::class);
39-
40-
$this->plugin = (new ObjectManager($this))->getObject(
41-
\Magento\Catalog\Model\Layout\DepersonalizePlugin::class,
42-
['catalogSession' => $this->catalogSessionMock, 'depersonalizeChecker' => $this->depersonalizeCheckerMock]
48+
$this->layoutMock = $this->getMockForAbstractClass(LayoutInterface::class);
49+
$this->catalogSessionMock = $this->createPartialMock(CatalogSession::class, ['clearStorage']);
50+
$this->depersonalizeCheckerMock = $this->createMock(DepersonalizeChecker::class);
51+
52+
$this->plugin = (new ObjectManagerHelper($this))->getObject(
53+
DepersonalizePlugin::class,
54+
[
55+
'catalogSession' => $this->catalogSessionMock,
56+
'depersonalizeChecker' => $this->depersonalizeCheckerMock,
57+
]
4358
);
4459
}
4560

46-
public function testAfterGenerateXml()
61+
/**
62+
* Test afterGenerateElements method when depersonalization is needed.
63+
*
64+
* @return void
65+
*/
66+
public function testAfterGenerateElements(): void
4767
{
4868
$this->catalogSessionMock->expects($this->once())->method('clearStorage');
4969
$this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(true);
50-
$actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $this->resultLayout);
51-
$this->assertEquals($this->resultLayout, $actualResult);
70+
$this->assertEmpty($this->plugin->afterGenerateElements($this->layoutMock));
5271
}
5372

54-
public function testAfterGenerateXmlNoDepersonalize()
73+
/**
74+
* Test afterGenerateElements method when depersonalization is not needed.
75+
*
76+
* @return void
77+
*/
78+
public function testAfterGenerateElementsNoDepersonalize(): void
5579
{
5680
$this->catalogSessionMock->expects($this->never())->method('clearStorage');
5781
$this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false);
58-
$actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $this->resultLayout);
59-
$this->assertEquals($this->resultLayout, $actualResult);
82+
$this->assertEmpty($this->plugin->afterGenerateElements($this->layoutMock));
6083
}
6184
}

0 commit comments

Comments
 (0)