Skip to content

Commit a94b469

Browse files
committed
MAGETWO-53019: [Performance]: Unexpected calls are made if view product on storefront
1 parent fa237ca commit a94b469

File tree

2 files changed

+19
-156
lines changed

2 files changed

+19
-156
lines changed

app/code/Magento/Customer/Test/Unit/Controller/Account/UpdateSessionTest.php

Lines changed: 0 additions & 117 deletions
This file was deleted.

app/code/Magento/Customer/Test/Unit/Model/Plugin/CustomerNotificationTest.php

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ class CustomerNotificationTest extends \PHPUnit_Framework_TestCase
1616
/** @var \Magento\Customer\Model\Customer\NotificationStorage|\PHPUnit_Framework_MockObject_MockObject */
1717
protected $notificationStorage;
1818

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;
19+
/** @var \Magento\Customer\Api\CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
20+
protected $customerRepository;
2421

2522
/** @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject */
2623
protected $appState;
@@ -42,63 +39,46 @@ protected function setUp()
4239
$this->notificationStorage = $this->getMockBuilder('Magento\Customer\Model\Customer\NotificationStorage')
4340
->disableOriginalConstructor()
4441
->getMock();
45-
$this->cookieManager = $this->getMockBuilder('Magento\Framework\Stdlib\CookieManagerInterface')
42+
$this->customerRepository = $this->getMockBuilder('Magento\Customer\Api\CustomerRepositoryInterface')
4643
->getMockForAbstractClass();
47-
$this->cookieMetadataFactory = $this->getMockBuilder('Magento\Framework\Stdlib\Cookie\CookieMetadataFactory')
48-
->disableOriginalConstructor()
49-
->getMock();
5044
$this->abstractAction = $this->getMockBuilder('Magento\Backend\App\AbstractAction')
5145
->disableOriginalConstructor()
5246
->getMockForAbstractClass();
53-
$this->request = $this->getMockBuilder('Magento\Framework\App\RequestInterface')->getMockForAbstractClass();
47+
$this->request = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
48+
->setMethods(['isPost'])
49+
->getMockForAbstractClass();
5450
$this->appState = $this->getMockBuilder('Magento\Framework\App\State')->disableOriginalConstructor()->getMock();
5551
$this->plugin = new CustomerNotification(
5652
$this->session,
5753
$this->notificationStorage,
58-
$this->cookieManager,
59-
$this->cookieMetadataFactory,
60-
$this->appState
54+
$this->appState,
55+
$this->customerRepository
6156
);
6257
}
6358

6459
public function testBeforeDispatch()
6560
{
6661
$customerId = 1;
62+
$customerGroupId =1;
6763
$this->appState->expects($this->any())
6864
->method('getAreaCode')
6965
->willReturn(\Magento\Framework\App\Area::AREA_FRONTEND);
66+
$this->request->expects($this->any())->method('isPost')->willReturn(true);
67+
$customerMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')->getMockForAbstractClass();
68+
$customerMock->expects($this->any())->method('getGroupId')->willReturn($customerGroupId);
69+
$this->customerRepository->expects($this->any())
70+
->method('getById')
71+
->with($customerId)
72+
->willReturn($customerMock);
7073
$this->session->expects($this->any())->method('getCustomerId')->willReturn($customerId);
74+
$this->session->expects($this->any())->method('setCustomerData')->with($customerMock);
75+
$this->session->expects($this->any())->method('setCustomerGroupId')->with($customerGroupId);
76+
$this->session->expects($this->once())->method('regenerateId');
7177
$this->notificationStorage->expects($this->any())
7278
->method('isExists')
7379
->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId)
7480
->willReturn(true);
7581

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-
10282
$this->plugin->beforeDispatch($this->abstractAction, $this->request);
10383
}
10484
}

0 commit comments

Comments
 (0)