Skip to content

Commit f7b4b14

Browse files
committed
Merge branch 'ACP2E-2070' of https://github.com/magento-l3/magento2ce into PR-L3-2023-07-14
2 parents b7dfc68 + 3086dae commit f7b4b14

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

app/code/Magento/Customer/Model/App/Action/ContextPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function beforeExecute(ActionInterface $subject)
4848
{
4949
$this->httpContext->setValue(
5050
Context::CONTEXT_GROUP,
51-
$this->customerSession->getCustomerGroupId(),
51+
(string)$this->customerSession->getCustomerGroupId(),
5252
GroupManagement::NOT_LOGGED_IN_ID
5353
);
5454
$this->httpContext->setValue(

app/code/Magento/Customer/Model/Session.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function setCustomerData(CustomerData $customer)
211211
} else {
212212
$this->_httpContext->setValue(
213213
Context::CONTEXT_GROUP,
214-
$customer->getGroupId(),
214+
(string)$customer->getGroupId(),
215215
\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID
216216
);
217217
$this->setCustomerId($customer->getId());
@@ -271,7 +271,7 @@ public function setCustomer(Customer $customerModel)
271271
$this->_customerModel = $customerModel;
272272
$this->_httpContext->setValue(
273273
Context::CONTEXT_GROUP,
274-
$customerModel->getGroupId(),
274+
(string)$customerModel->getGroupId(),
275275
\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID
276276
);
277277
$this->setCustomerId($customerModel->getId());

app/code/Magento/Customer/Test/Unit/Model/App/Action/ContextPluginTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
*/
2121
class ContextPluginTest extends TestCase
2222
{
23-
const STUB_CUSTOMER_GROUP = 'UAH';
24-
const STUB_CUSTOMER_NOT_LOGGED_IN = 0;
23+
public const STUB_CUSTOMER_GROUP = 'UAH';
24+
public const STUB_CUSTOMER_NOT_LOGGED_IN = 0;
2525
/**
2626
* @var ContextPlugin
2727
*/
@@ -66,6 +66,10 @@ public function testBeforeExecute()
6666
->willReturn(true);
6767
$this->httpContextMock->expects($this->atLeastOnce())
6868
->method('setValue')
69+
->withConsecutive(
70+
[Context::CONTEXT_GROUP, self::callback(fn($value): bool => $value === '1'), 0],
71+
[Context::CONTEXT_AUTH, true, self::STUB_CUSTOMER_NOT_LOGGED_IN]
72+
)
6973
->willReturnMap(
7074
[
7175
[Context::CONTEXT_GROUP, self::STUB_CUSTOMER_GROUP, $this->httpContextMock],

app/code/Magento/Customer/Test/Unit/Model/SessionTest.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
<?php declare(strict_types=1);
1+
<?php
22
/**
3-
* Unit test for session \Magento\Customer\Model\Session
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\Customer\Test\Unit\Model;
99

1010
use Magento\Customer\Api\CustomerRepositoryInterface;
1111
use Magento\Customer\Api\Data\CustomerInterface;
12+
use Magento\Customer\Model\Context as CustomerContext;
1213
use Magento\Customer\Model\Customer;
1314
use Magento\Customer\Model\CustomerFactory;
1415
use Magento\Customer\Model\ResourceModel\Customer as ResourceCustomer;
@@ -118,6 +119,9 @@ public function testSetCustomerAsLoggedIn(): void
118119
{
119120
$customer = $this->createMock(Customer::class);
120121
$customerDto = $this->getMockForAbstractClass(CustomerInterface::class);
122+
$customer->expects($this->any())
123+
->method('getGroupId')
124+
->willReturn(1);
121125
$customer->expects($this->any())
122126
->method('getDataModel')
123127
->willReturn($customerDto);
@@ -129,6 +133,10 @@ public function testSetCustomerAsLoggedIn(): void
129133
['customer_data_object_login', ['customer' => $customerDto]]
130134
);
131135

136+
$this->_httpContextMock->expects($this->once())
137+
->method('setValue')
138+
->with(CustomerContext::CONTEXT_GROUP, self::callback(fn($value): bool => $value === '1'), 0);
139+
132140
$_SESSION = [];
133141
$this->_model->setCustomerAsLoggedIn($customer);
134142
$this->assertSame($customer, $this->_model->getCustomer());
@@ -348,4 +356,17 @@ public function testGetCustomerForRegisteredUser(): void
348356

349357
$this->assertSame($customerMock, $this->_model->getCustomer());
350358
}
359+
360+
public function testSetCustomer(): void
361+
{
362+
$customer = $this->createMock(Customer::class);
363+
$customer->expects($this->any())
364+
->method('getGroupId')
365+
->willReturn(1);
366+
$this->_httpContextMock->expects($this->once())
367+
->method('setValue')
368+
->with(CustomerContext::CONTEXT_GROUP, self::callback(fn($value): bool => $value === '1'), 0);
369+
370+
$this->_model->setCustomer($customer);
371+
}
351372
}

0 commit comments

Comments
 (0)