Ejemplo n.º 1
0
 /**
  * @param AbstractAction $subject
  * @param RequestInterface $request
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function beforeDispatch(AbstractAction $subject, RequestInterface $request)
 {
     if ($this->state->getAreaCode() == Area::AREA_FRONTEND && $request->isPost() && $this->notificationStorage->isExists(NotificationStorage::UPDATE_CUSTOMER_SESSION, $this->session->getCustomerId())) {
         $customer = $this->customerRepository->getById($this->session->getCustomerId());
         $this->session->setCustomerData($customer);
         $this->session->setCustomerGroupId($customer->getGroupId());
         $this->session->regenerateId();
         $this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customer->getId());
     }
 }
 public function testBeforeDispatch()
 {
     $customerId = 1;
     $customerGroupId = 1;
     $this->appState->expects($this->any())->method('getAreaCode')->willReturn(\Magento\Framework\App\Area::AREA_FRONTEND);
     $this->request->expects($this->any())->method('isPost')->willReturn(true);
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMockForAbstractClass();
     $customerMock->expects($this->any())->method('getGroupId')->willReturn($customerGroupId);
     $this->customerRepository->expects($this->any())->method('getById')->with($customerId)->willReturn($customerMock);
     $this->session->expects($this->any())->method('getCustomerId')->willReturn($customerId);
     $this->session->expects($this->any())->method('setCustomerData')->with($customerMock);
     $this->session->expects($this->any())->method('setCustomerGroupId')->with($customerGroupId);
     $this->session->expects($this->once())->method('regenerateId');
     $this->notificationStorage->expects($this->any())->method('isExists')->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId)->willReturn(true);
     $this->plugin->beforeDispatch($this->abstractAction, $this->request);
 }