Skip to content

Commit dcaee49

Browse files
committed
Merge remote-tracking branch 'origin/MC-31729' into 2.4-develop-pr23
2 parents def8a07 + 12452e1 commit dcaee49

File tree

20 files changed

+1267
-635
lines changed

20 files changed

+1267
-635
lines changed
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/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
}

app/code/Magento/Checkout/Model/Layout/DepersonalizePlugin.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,54 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Checkout\Model\Layout;
79

10+
use Magento\Checkout\Model\Session as CheckoutSession;
11+
use Magento\Framework\View\LayoutInterface;
812
use Magento\PageCache\Model\DepersonalizeChecker;
913

1014
/**
11-
* Class DepersonalizePlugin
15+
* Depersonalize customer data.
16+
*
17+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1218
*/
1319
class DepersonalizePlugin
1420
{
1521
/**
1622
* @var DepersonalizeChecker
1723
*/
18-
protected $depersonalizeChecker;
24+
private $depersonalizeChecker;
1925

2026
/**
21-
* @var \Magento\Checkout\Model\Session
27+
* @var CheckoutSession
2228
*/
23-
protected $checkoutSession;
29+
private $checkoutSession;
2430

2531
/**
2632
* @param DepersonalizeChecker $depersonalizeChecker
27-
* @param \Magento\Checkout\Model\Session $checkoutSession
33+
* @param CheckoutSession $checkoutSession
2834
* @codeCoverageIgnore
2935
*/
3036
public function __construct(
3137
DepersonalizeChecker $depersonalizeChecker,
32-
\Magento\Checkout\Model\Session $checkoutSession
38+
CheckoutSession $checkoutSession
3339
) {
34-
$this->checkoutSession = $checkoutSession;
3540
$this->depersonalizeChecker = $depersonalizeChecker;
41+
$this->checkoutSession = $checkoutSession;
3642
}
3743

3844
/**
39-
* After generate Xml
45+
* Change sensitive customer data if the depersonalization is needed.
4046
*
41-
* @param \Magento\Framework\View\LayoutInterface $subject
42-
* @param \Magento\Framework\View\LayoutInterface $result
43-
* @return \Magento\Framework\View\LayoutInterface
47+
* @param LayoutInterface $subject
48+
* @return void
4449
*/
45-
public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
50+
public function afterGenerateElements(LayoutInterface $subject)
4651
{
4752
if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
4853
$this->checkoutSession->clearStorage();
4954
}
50-
return $result;
5155
}
5256
}

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

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

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

10+
use Magento\Checkout\Model\Layout\DepersonalizePlugin;
11+
use Magento\Checkout\Model\Session as CheckoutSession;
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;
17+
918
/**
10-
* Class DepersonalizePluginTest
19+
* Unit tests for \Magento\Checkout\Model\Layout\DepersonalizePlugin class.
1120
*/
12-
class DepersonalizePluginTest extends \PHPUnit\Framework\TestCase
21+
class DepersonalizePluginTest extends TestCase
1322
{
1423
/**
15-
* @var \Magento\Customer\Model\Layout\DepersonalizePluginTest
24+
* @var DepersonalizePlugin
1625
*/
17-
protected $plugin;
26+
private $plugin;
1827

1928
/**
20-
* @var \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject
29+
* @var LayoutInterface|MockObject
2130
*/
22-
protected $layoutMock;
31+
private $layoutMock;
2332

2433
/**
25-
* @var \Magento\Checkout\Model\Session|\PHPUnit_Framework_MockObject_MockObject
34+
* @var CheckoutSession|MockObject
2635
*/
27-
protected $checkoutSessionMock;
36+
private $checkoutSessionMock;
2837

2938
/**
30-
* @var \Magento\PageCache\Model\DepersonalizeChecker|\PHPUnit_Framework_MockObject_MockObject
39+
* @var DepersonalizeChecker|MockObject
3140
*/
32-
protected $depersonalizeCheckerMock;
41+
private $depersonalizeCheckerMock;
3342

3443
/**
35-
* SetUp
44+
* @inheritdoc
3645
*/
3746
protected function setUp()
3847
{
39-
$this->layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);
40-
$this->checkoutSessionMock = $this->createPartialMock(
41-
\Magento\Framework\Session\Generic::class,
42-
['clearStorage', 'setData', 'getData']
43-
);
44-
$this->checkoutSessionMock = $this->createPartialMock(\Magento\Checkout\Model\Session::class, ['clearStorage']);
45-
$this->requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
46-
$this->moduleManagerMock = $this->createMock(\Magento\Framework\Module\Manager::class);
47-
$this->cacheConfigMock = $this->createMock(\Magento\PageCache\Model\Config::class);
48-
$this->depersonalizeCheckerMock = $this->createMock(\Magento\PageCache\Model\DepersonalizeChecker::class);
48+
$this->layoutMock = $this->getMockForAbstractClass(LayoutInterface::class);
49+
$this->checkoutSessionMock = $this->createPartialMock(CheckoutSession::class, ['clearStorage']);
50+
$this->depersonalizeCheckerMock = $this->createMock(DepersonalizeChecker::class);
4951

50-
$this->plugin = new \Magento\Checkout\Model\Layout\DepersonalizePlugin(
51-
$this->depersonalizeCheckerMock,
52-
$this->checkoutSessionMock
52+
$this->plugin = (new ObjectManagerHelper($this))->getObject(
53+
DepersonalizePlugin::class,
54+
[
55+
'depersonalizeChecker' => $this->depersonalizeCheckerMock,
56+
'checkoutSession' => $this->checkoutSessionMock,
57+
]
5358
);
5459
}
5560

5661
/**
57-
* Test method afterGenerateXml
62+
* Test afterGenerateElements method when depersonalization is needed.
63+
*
64+
* @return void
5865
*/
59-
public function testAfterGenerateXml()
66+
public function testAfterGenerateElements(): void
6067
{
61-
$expectedResult = $this->createMock(\Magento\Framework\View\Layout::class);
62-
6368
$this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(true);
6469
$this->checkoutSessionMock
6570
->expects($this->once())
6671
->method('clearStorage')
67-
->will($this->returnValue($expectedResult));
72+
->willReturnSelf();
6873

69-
$actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult);
70-
$this->assertEquals($expectedResult, $actualResult);
74+
$this->assertEmpty($this->plugin->afterGenerateElements($this->layoutMock));
7175
}
7276

73-
public function testAfterGenerateXmlNoDepersonalize()
77+
/**
78+
* Test afterGenerateElements method when depersonalization is not needed.
79+
*
80+
* @return void
81+
*/
82+
public function testAfterGenerateElementsNoDepersonalize(): void
7483
{
75-
$expectedResult = $this->createMock(\Magento\Framework\View\Layout::class);
76-
7784
$this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false);
7885
$this->checkoutSessionMock
7986
->expects($this->never())
8087
->method('clearStorage')
81-
->will($this->returnValue($expectedResult));
88+
->willReturnSelf();
8289

83-
$actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult);
84-
$this->assertEquals($expectedResult, $actualResult);
90+
$this->assertEmpty($this->plugin->afterGenerateElements($this->layoutMock));
8591
}
8692
}

0 commit comments

Comments
 (0)