Skip to content

Commit ad98672

Browse files
committed
Merge branch 'ACP2E-1763' of https://github.com/magento-l3/magento2ce into PR-04202023
2 parents 9bfd091 + 6016f89 commit ad98672

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Persistent\Model\Plugin;
9+
10+
use Magento\LoginAsCustomerApi\Api\AuthenticateCustomerBySecretInterface;
11+
use Magento\Persistent\Helper\Session as PersistentSession;
12+
13+
class LoginAsCustomerCleanUp
14+
{
15+
/**
16+
* @var PersistentSession
17+
*/
18+
private $persistentSession;
19+
20+
/**
21+
* @param PersistentSession $persistentSession
22+
*/
23+
public function __construct(PersistentSession $persistentSession)
24+
{
25+
$this->persistentSession = $persistentSession;
26+
}
27+
28+
/**
29+
* Disable persistence for sales representative login
30+
*
31+
* @param AuthenticateCustomerBySecretInterface $subject
32+
* @return void
33+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
34+
*/
35+
public function afterExecute(AuthenticateCustomerBySecretInterface $subject)
36+
{
37+
if ($this->persistentSession->isPersistent()) {
38+
$this->persistentSession->getSession()->removePersistentCookie();
39+
}
40+
}
41+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Persistent\Test\Unit\Model\Plugin;
9+
10+
use Magento\Persistent\Model\Plugin\LoginAsCustomerCleanUp;
11+
use Magento\Persistent\Helper\Session as PersistentSession;
12+
use Magento\LoginAsCustomerApi\Api\AuthenticateCustomerBySecretInterface;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
class LoginAsCustomerCleanUpTest extends TestCase
17+
{
18+
/**
19+
* @var LoginAsCustomerCleanUp
20+
*/
21+
protected $plugin;
22+
23+
/**
24+
* @var MockObject
25+
*/
26+
protected $subjectMock;
27+
28+
/**
29+
* @var MockObject
30+
*/
31+
protected $persistentSessionMock;
32+
33+
/**
34+
* @var MockObject
35+
*/
36+
protected $persistentSessionModelMock;
37+
38+
protected function setUp(): void
39+
{
40+
$this->persistentSessionMock = $this->createMock(PersistentSession::class);
41+
$this->persistentSessionModelMock = $this->createMock(\Magento\Persistent\Model\Session::class);
42+
$this->persistentSessionMock->method('getSession')->willReturn($this->persistentSessionModelMock);
43+
$this->subjectMock = $this->createMock(AuthenticateCustomerBySecretInterface::class);
44+
$this->plugin = new LoginAsCustomerCleanUp($this->persistentSessionMock);
45+
}
46+
47+
public function testBeforeExecute()
48+
{
49+
$this->persistentSessionMock->expects($this->once())->method('isPersistent')->willReturn(true);
50+
$this->persistentSessionModelMock->expects($this->once())->method('removePersistentCookie');
51+
$result = $this->plugin->afterExecute($this->subjectMock);
52+
$this->assertEquals(null, $result);
53+
}
54+
}

app/code/Magento/Persistent/composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"magento/module-quote": "*",
1515
"magento/module-store": "*"
1616
},
17+
"suggest": {
18+
"magento/module-login-as-customer-api": "*"
19+
},
1720
"type": "magento2-module",
1821
"license": [
1922
"OSL-3.0",

app/code/Magento/Persistent/etc/frontend/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,7 @@
5757
<argument name="shippingAssignmentProcessor" xsi:type="object">Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor\Proxy</argument>
5858
</arguments>
5959
</type>
60+
<type name="Magento\LoginAsCustomerApi\Api\AuthenticateCustomerBySecretInterface">
61+
<plugin name="login_as_customer_cleanup" type="Magento\Persistent\Model\Plugin\LoginAsCustomerCleanUp" />
62+
</type>
6063
</config>

0 commit comments

Comments
 (0)