Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.4-develop' into MC-32430
Browse files Browse the repository at this point in the history
  • Loading branch information
yelahin-serhiy committed Apr 6, 2020
2 parents 32b92d7 + d69c242 commit a16450d
Show file tree
Hide file tree
Showing 49 changed files with 1,996 additions and 1,021 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/Model/Layer/FilterList.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ protected function getAttributeFilterClass(\Magento\Catalog\Model\ResourceModel\
{
$filterClassName = $this->filterTypes[self::ATTRIBUTE_FILTER];

if ($attribute->getFrontendInput() === 'price') {
if ($attribute->getAttributeCode() == 'price') {
$filterClassName = $this->filterTypes[self::PRICE_FILTER];
} elseif ($attribute->getBackendType() === 'decimal') {
} elseif ($attribute->getBackendType() == 'decimal') {
$filterClassName = $this->filterTypes[self::DECIMAL_FILTER];
}

Expand Down
34 changes: 17 additions & 17 deletions app/code/Magento/Catalog/Model/Layout/DepersonalizePlugin.php
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
<?php
/**
* Depersonalize catalog session data
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Layout;

use Magento\Catalog\Model\Session as CatalogSession;
use Magento\Framework\View\LayoutInterface;
use Magento\PageCache\Model\DepersonalizeChecker;

/**
* Class DepersonalizePlugin
* Depersonalize customer data.
*
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class DepersonalizePlugin
{
/**
* @var DepersonalizeChecker
*/
protected $depersonalizeChecker;
private $depersonalizeChecker;

/**
* Catalog session
*
* @var \Magento\Catalog\Model\Session
* @var CatalogSession
*/
protected $catalogSession;
private $catalogSession;

/**
* @param DepersonalizeChecker $depersonalizeChecker
* @param \Magento\Catalog\Model\Session $catalogSession
* @param CatalogSession $catalogSession
*/
public function __construct(
DepersonalizeChecker $depersonalizeChecker,
\Magento\Catalog\Model\Session $catalogSession
CatalogSession $catalogSession
) {
$this->catalogSession = $catalogSession;
$this->depersonalizeChecker = $depersonalizeChecker;
$this->catalogSession = $catalogSession;
}

/**
* After generate Xml
* Change sensitive customer data if the depersonalization is needed.
*
* @param \Magento\Framework\View\LayoutInterface $subject
* @param \Magento\Framework\View\LayoutInterface $result
* @return \Magento\Framework\View\LayoutInterface
* @param LayoutInterface $subject
* @return void
*/
public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
public function afterGenerateElements(LayoutInterface $subject)
{
if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
$this->catalogSession->clearStorage();
}
return $result;
}
}
22 changes: 0 additions & 22 deletions app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,28 +282,6 @@
<data key="used_for_sort_by">false</data>
<requiredEntity type="FrontendLabel">ProductAttributeFrontendLabel</requiredEntity>
</entity>
<entity name="productAttributeTypeOfPrice" type="ProductAttribute">
<data key="attribute_code" unique="suffix">attribute</data>
<data key="frontend_input">price</data>
<data key="scope">global</data>
<data key="is_required">false</data>
<data key="is_unique">false</data>
<data key="is_searchable">false</data>
<data key="is_visible">true</data>
<data key="is_wysiwyg_enabled">false</data>
<data key="is_visible_in_advanced_search">false</data>
<data key="is_visible_on_front">true</data>
<data key="is_filterable">true</data>
<data key="is_filterable_in_search">false</data>
<data key="used_in_product_listing">false</data>
<data key="is_used_for_promo_rules">false</data>
<data key="is_comparable">true</data>
<data key="is_used_in_grid">false</data>
<data key="is_visible_in_grid">false</data>
<data key="is_filterable_in_grid">false</data>
<data key="used_for_sort_by">false</data>
<requiredEntity type="FrontendLabel">ProductAttributeFrontendLabel</requiredEntity>
</entity>
<entity name="textProductAttribute" extends="productAttributeWysiwyg" type="ProductAttribute">
<data key="frontend_input">text</data>
<data key="default_value" unique="suffix">defaultValue</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
<section name="StorefrontCategoryFilterSection">
<element name="CategoryFilter" type="button" selector="//main//div[@class='filter-options']//div[contains(text(), 'Category')]"/>
<element name="CategoryByName" type="button" selector="//main//div[@class='filter-options']//li[@class='item']//a[contains(text(), '{{var1}}')]" parameterized="true"/>
<element name="CustomPriceAttribute" type="button" selector="div.filter-options-title"/>
</section>
</sections>
22 changes: 9 additions & 13 deletions app/code/Magento/Catalog/Test/Unit/Model/Layer/FilterListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,9 @@ public function testGetFilters($method, $value, $expectedClass)

$this->objectManagerMock->expects($this->at(1))
->method('create')
->with(
$expectedClass,
[
'data' => ['attribute_model' => $this->attributeMock],
'layer' => $this->layerMock
]
)
->with($expectedClass, [
'data' => ['attribute_model' => $this->attributeMock],
'layer' => $this->layerMock])
->will($this->returnValue('filter'));

$this->attributeMock->expects($this->once())
Expand Down Expand Up @@ -169,8 +165,8 @@ public function getFiltersDataProvider()
{
return [
[
'method' => 'getFrontendInput',
'value' => 'price',
'method' => 'getAttributeCode',
'value' => FilterList::PRICE_FILTER,
'expectedClass' => 'PriceFilterClass',
],
[
Expand All @@ -179,8 +175,8 @@ public function getFiltersDataProvider()
'expectedClass' => 'DecimalFilterClass',
],
[
'method' => 'getFrontendInput',
'value' => 'text',
'method' => 'getAttributeCode',
'value' => null,
'expectedClass' => 'AttributeFilterClass',
]
];
Expand All @@ -195,8 +191,8 @@ public function getFiltersWithoutCategoryDataProvider(): array
{
return [
'Filters contains only price attribute' => [
'method' => 'getFrontendInput',
'value' => 'price',
'method' => 'getAttributeCode',
'value' => FilterList::PRICE_FILTER,
'expectedClass' => 'PriceFilterClass',
'expectedResult' => [
'filter'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,82 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

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

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Catalog\Model\Layout\DepersonalizePlugin;
use Magento\Catalog\Model\Session as CatalogSession;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Framework\View\LayoutInterface;
use Magento\PageCache\Model\DepersonalizeChecker;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class DepersonalizePluginTest extends \PHPUnit\Framework\TestCase
/**
* Unit tests for \Magento\Catalog\Model\Layout\DepersonalizePlugin class.
*/
class DepersonalizePluginTest extends TestCase
{
/**
* @var \Magento\Catalog\Model\Layout\DepersonalizePlugin
* @var DepersonalizePlugin
*/
protected $plugin;
private $plugin;

/**
* @var \Magento\Catalog\Model\Session|\PHPUnit_Framework_MockObject_MockObject
* @var CatalogSession|MockObject
*/
protected $catalogSessionMock;
private $catalogSessionMock;

/**
* @var \Magento\PageCache\Model\DepersonalizeChecker|\PHPUnit_Framework_MockObject_MockObject
* @var DepersonalizeChecker|MockObject
*/
protected $depersonalizeCheckerMock;
private $depersonalizeCheckerMock;

/**
* @var \Magento\Framework\View\Layout|\PHPUnit_Framework_MockObject_MockObject
* @var LayoutInterface|MockObject
*/
protected $resultLayout;
private $layoutMock;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);
$this->catalogSessionMock = $this->createPartialMock(\Magento\Catalog\Model\Session::class, ['clearStorage']);
$this->resultLayout = $this->createMock(\Magento\Framework\View\Layout::class);
$this->depersonalizeCheckerMock = $this->createMock(\Magento\PageCache\Model\DepersonalizeChecker::class);

$this->plugin = (new ObjectManager($this))->getObject(
\Magento\Catalog\Model\Layout\DepersonalizePlugin::class,
['catalogSession' => $this->catalogSessionMock, 'depersonalizeChecker' => $this->depersonalizeCheckerMock]
$this->layoutMock = $this->getMockForAbstractClass(LayoutInterface::class);
$this->catalogSessionMock = $this->createPartialMock(CatalogSession::class, ['clearStorage']);
$this->depersonalizeCheckerMock = $this->createMock(DepersonalizeChecker::class);

$this->plugin = (new ObjectManagerHelper($this))->getObject(
DepersonalizePlugin::class,
[
'catalogSession' => $this->catalogSessionMock,
'depersonalizeChecker' => $this->depersonalizeCheckerMock,
]
);
}

public function testAfterGenerateXml()
/**
* Test afterGenerateElements method when depersonalization is needed.
*
* @return void
*/
public function testAfterGenerateElements(): void
{
$this->catalogSessionMock->expects($this->once())->method('clearStorage');
$this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(true);
$actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $this->resultLayout);
$this->assertEquals($this->resultLayout, $actualResult);
$this->assertEmpty($this->plugin->afterGenerateElements($this->layoutMock));
}

public function testAfterGenerateXmlNoDepersonalize()
/**
* Test afterGenerateElements method when depersonalization is not needed.
*
* @return void
*/
public function testAfterGenerateElementsNoDepersonalize(): void
{
$this->catalogSessionMock->expects($this->never())->method('clearStorage');
$this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false);
$actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $this->resultLayout);
$this->assertEquals($this->resultLayout, $actualResult);
$this->assertEmpty($this->plugin->afterGenerateElements($this->layoutMock));
}
}
Loading

0 comments on commit a16450d

Please sign in to comment.