Skip to content

Commit 2858976

Browse files
committed
MC-42008: Problem with customer API route
1 parent aec7813 commit 2858976

File tree

1 file changed

+36
-22
lines changed

1 file changed

+36
-22
lines changed

app/code/Magento/Persistent/Test/Unit/Model/Customer/AuthorizationTest.php

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ class AuthorizationTest extends TestCase
4747
protected function setUp(): void
4848
{
4949
$this->persistentSessionMock = $this->getMockBuilder(PersistentSession::class)
50-
->onlyMethods(['isPersistent'])
5150
->disableOriginalConstructor()
5251
->getMock();
5352

5453
$this->customerSessionMock = $this->getMockBuilder(CustomerSession::class)
55-
->onlyMethods(['isLoggedIn'])
5654
->disableOriginalConstructor()
55+
->addMethods(['getIsCustomerEmulated'])
56+
->onlyMethods(['getCustomerId'])
5757
->getMock();
5858

5959
$this->persistentCustomerAuthorization = new PersistentAuthorization(
@@ -71,19 +71,24 @@ protected function setUp(): void
7171
*
7272
* @dataProvider persistentLoggedInCombinations
7373
* @param bool $isPersistent
74-
* @param bool $isLoggedIn
75-
* @param bool $isAllowedExpectation
74+
* @param int|null $customerId
75+
* @param bool|null $isCustomerEmulated
76+
* @param bool $shouldBeAllowed
7677
*/
7778
public function testIsAuthorized(
7879
bool $isPersistent,
79-
bool $isLoggedIn,
80-
bool $isAllowedExpectation
81-
): void {
82-
$this->persistentSessionMock->method('isPersistent')->willReturn($isPersistent);
83-
$this->customerSessionMock->method('isLoggedIn')->willReturn($isLoggedIn);
80+
?int $customerId,
81+
?bool $isCustomerEmulated,
82+
bool $shouldBeAllowed
83+
): void
84+
{
85+
$this->persistentSessionMock->expects($this->any())->method('isPersistent')->willReturn($isPersistent);
86+
$this->customerSessionMock->expects($this->any())->method('getCustomerId')->willReturn($customerId);
87+
$this->customerSessionMock->expects($this->any())->method('getIsCustomerEmulated')->willReturn($isCustomerEmulated);
88+
8489
$isAllowedResult = $this->customerAuthorizationComposite->isAllowed('self');
8590

86-
$this->assertEquals($isAllowedExpectation, $isAllowedResult);
91+
$this->assertEquals($shouldBeAllowed, $isAllowedResult);
8792
}
8893

8994
/**
@@ -92,21 +97,30 @@ public function testIsAuthorized(
9297
public function persistentLoggedInCombinations(): array
9398
{
9499
return [
95-
[
96-
true,
97-
false,
98-
false
100+
'Emulated persistent Customer ID#1 should not be authorized' => [
101+
'isPersistent' => true,
102+
'customerId' => 1,
103+
'isCustomerEmulated' => true,
104+
'shouldBeAllowed' => false
99105
],
100-
[
101-
true,
102-
true,
103-
true
106+
'Logged-in persistent Customer ID#1 should be authorized' => [
107+
'isPersistent' => true,
108+
'customerId' => 1,
109+
'isCustomerEmulated' => false,
110+
'shouldBeAllowed' => true
104111
],
105-
[
106-
false,
107-
false,
108-
true
112+
'Logged-in Customer ID#1 without persistency should be authorized' => [
113+
'isPersistent' => false,
114+
'customerId' => 1,
115+
'isCustomerEmulated' => false,
116+
'shouldBeAllowed' => true
109117
],
118+
'Persistent Customer ID/ isCustomerEmulated = null (API Request) should be authorized' => [
119+
'isPersistent' => true,
120+
'customerId' => null,
121+
'isCustomerEmulated' => null,
122+
'shouldBeAllowed' => true
123+
]
110124
];
111125
}
112126
}

0 commit comments

Comments
 (0)