Skip to content

Commit 4fd4dd2

Browse files
author
Roman Lytvynenko
committed
MC-36647: Order can be placed as a customer after session cookie expiration with Persistent Cart enabled
1 parent 00ae238 commit 4fd4dd2

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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\Customer;
9+
10+
use Magento\Customer\Model\Session as CustomerSession;
11+
use Magento\Persistent\Helper\Session as PersistentSession;
12+
use Magento\Persistent\Model\Customer\Authorization;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* A test class for the persistent customers authorization
18+
*
19+
* Unit tests for \Magento\Persistent\Model\Customer\Authorization class.
20+
*/
21+
class AuthorizationTest extends TestCase
22+
{
23+
/**
24+
* @var PersistentSession|MockObject
25+
*/
26+
private $persistentSessionMock;
27+
28+
/**
29+
* @var Authorization
30+
*/
31+
private $authorization;
32+
33+
/**
34+
* @var CustomerSession|MockObject
35+
*/
36+
private $customerSessionMock;
37+
38+
/**
39+
* @inheritdoc
40+
*/
41+
protected function setUp(): void
42+
{
43+
$this->persistentSessionMock = $this->getMockBuilder(PersistentSession::class)
44+
->onlyMethods(['isPersistent'])
45+
->disableOriginalConstructor()
46+
->getMock();
47+
48+
$this->customerSessionMock = $this->getMockBuilder(CustomerSession::class)
49+
->onlyMethods(['isLoggedIn'])
50+
->disableOriginalConstructor()
51+
->getMock();
52+
53+
$this->authorization = new Authorization(
54+
$this->customerSessionMock,
55+
$this->persistentSessionMock
56+
);
57+
}
58+
59+
/**
60+
* Validate if isAuthorized() will return proper permission value for logged in/ out persistent customers
61+
*
62+
* @dataProvider persistentLoggedInCombinations
63+
* @param bool $isPersistent
64+
* @param bool $isLoggedIn
65+
* @param bool $isAllowedExpectation
66+
*/
67+
public function testIsAuthorized(
68+
bool $isPersistent,
69+
bool $isLoggedIn,
70+
bool $isAllowedExpectation
71+
): void {
72+
$this->persistentSessionMock->method('isPersistent')->willReturn($isPersistent);
73+
$this->customerSessionMock->method('isLoggedIn')->willReturn($isLoggedIn);
74+
$isAllowedResult = $this->authorization->isAllowed('self');
75+
76+
$this->assertEquals($isAllowedExpectation, $isAllowedResult);
77+
}
78+
79+
/**
80+
* @return array
81+
*/
82+
public function persistentLoggedInCombinations(): array
83+
{
84+
return [
85+
[
86+
true,
87+
false,
88+
false
89+
],
90+
[
91+
true,
92+
true,
93+
true
94+
],
95+
[
96+
false,
97+
false,
98+
true
99+
],
100+
];
101+
}
102+
}

0 commit comments

Comments
 (0)