Skip to content

Commit 525af29

Browse files
committed
MAGETWO-52117: Customer group is not changed for logged in customer
1 parent 12f8ff4 commit 525af29

File tree

2 files changed

+108
-4
lines changed

2 files changed

+108
-4
lines changed

app/code/Magento/Customer/Model/Plugin/CustomerNotification.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ public function beforeDispatch(AbstractAction $subject, RequestInterface $reques
8181
$this->session->getCustomerId()
8282
)
8383
) {
84-
$publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()
85-
->setDurationOneYear()
86-
->setPath('/')
87-
->setHttpOnly(false);
84+
$publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata();
85+
$publicCookieMetadata->setDurationOneYear();
86+
$publicCookieMetadata->setPath('/');
87+
$publicCookieMetadata->setHttpOnly(false);
8888
$this->cookieManager->setPublicCookie(
8989
NotificationStorage::UPDATE_CUSTOMER_SESSION,
9090
$this->session->getCustomerId(),
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Test\Unit\Model\Plugin;
7+
8+
use Magento\Customer\Model\Customer\NotificationStorage;
9+
use Magento\Customer\Model\Plugin\CustomerNotification;
10+
11+
class CustomerNotificationTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/** @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject */
14+
protected $session;
15+
16+
/** @var \Magento\Customer\Model\Customer\NotificationStorage|\PHPUnit_Framework_MockObject_MockObject */
17+
protected $notificationStorage;
18+
19+
/** @var \Magento\Framework\Stdlib\CookieManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
20+
protected $cookieManager;
21+
22+
/** @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory|\PHPUnit_Framework_MockObject_MockObject */
23+
protected $cookieMetadataFactory;
24+
25+
/** @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject */
26+
protected $appState;
27+
28+
/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
29+
protected $request;
30+
31+
/** @var \Magento\Backend\App\AbstractAction|\PHPUnit_Framework_MockObject_MockObject */
32+
protected $abstractAction;
33+
34+
/** @var CustomerNotification */
35+
protected $plugin;
36+
37+
protected function setUp()
38+
{
39+
$this->session = $this->getMockBuilder('Magento\Customer\Model\Session')
40+
->disableOriginalConstructor()
41+
->getMock();
42+
$this->notificationStorage = $this->getMockBuilder('Magento\Customer\Model\Customer\NotificationStorage')
43+
->disableOriginalConstructor()
44+
->getMock();
45+
$this->cookieManager = $this->getMockBuilder('Magento\Framework\Stdlib\CookieManagerInterface')
46+
->getMockForAbstractClass();
47+
$this->cookieMetadataFactory = $this->getMockBuilder('Magento\Framework\Stdlib\Cookie\CookieMetadataFactory')
48+
->disableOriginalConstructor()
49+
->getMock();
50+
$this->abstractAction = $this->getMockBuilder('Magento\Backend\App\AbstractAction')
51+
->disableOriginalConstructor()
52+
->getMockForAbstractClass();
53+
$this->request = $this->getMockBuilder('Magento\Framework\App\RequestInterface')->getMockForAbstractClass();
54+
$this->appState = $this->getMockBuilder('Magento\Framework\App\State')->disableOriginalConstructor()->getMock();
55+
$this->plugin = new CustomerNotification(
56+
$this->session,
57+
$this->notificationStorage,
58+
$this->cookieManager,
59+
$this->cookieMetadataFactory,
60+
$this->appState
61+
);
62+
}
63+
64+
public function testBeforeDispatch()
65+
{
66+
$customerId = 1;
67+
$this->appState->expects($this->any())
68+
->method('getAreaCode')
69+
->willReturn(\Magento\Framework\App\Area::AREA_FRONTEND);
70+
$this->session->expects($this->any())->method('getCustomerId')->willReturn($customerId);
71+
$this->notificationStorage->expects($this->any())
72+
->method('isExists')
73+
->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId)
74+
->willReturn(true);
75+
76+
$publicCookieMetadata = $this->getMockBuilder('Magento\Framework\Stdlib\Cookie\PublicCookieMetadata')
77+
->disableOriginalConstructor()
78+
->getMock();
79+
$publicCookieMetadata->expects($this->once())->method('setPath')->with('/');
80+
$publicCookieMetadata->expects($this->once())->method('setDurationOneYear');
81+
$publicCookieMetadata->expects($this->once())->method('setHttpOnly')->with(false);
82+
83+
$sensitiveCookieMetadata = $this->getMockBuilder('Magento\Framework\Stdlib\Cookie\SensitiveCookieMetadata')
84+
->disableOriginalConstructor()
85+
->getMock();
86+
$sensitiveCookieMetadata->expects($this->once())->method('setPath')->with('/')->willReturnSelf();
87+
88+
$this->cookieMetadataFactory->expects($this->any())
89+
->method('createPublicCookieMetadata')
90+
->willReturn($publicCookieMetadata);
91+
$this->cookieMetadataFactory->expects($this->any())
92+
->method('createSensitiveCookieMetadata')
93+
->willReturn($sensitiveCookieMetadata);
94+
95+
$this->cookieManager->expects($this->once())
96+
->method('setPublicCookie')
97+
->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId, $publicCookieMetadata);
98+
$this->cookieManager->expects($this->once())
99+
->method('deleteCookie')
100+
->with(\Magento\Framework\App\Response\Http::COOKIE_VARY_STRING, $sensitiveCookieMetadata);
101+
102+
$this->plugin->beforeDispatch($this->abstractAction, $this->request);
103+
}
104+
}

0 commit comments

Comments
 (0)