/**
  * @dataProvider redirectLoginDataProvider
  * @param array $actionFlagList
  * @param string|null $customerBeforeAuthUrl
  * @param string|null $customerBeforeAuthUrlDefault
  */
 public function testRedirectLogin($actionFlagList, $customerBeforeAuthUrl, $customerBeforeAuthUrlDefault)
 {
     $expressRedirectMock = $this->getMockBuilder('Magento\\Checkout\\Controller\\Express\\RedirectLoginInterface')->disableOriginalConstructor()->setMethods(['getActionFlagList', 'getResponse', 'getCustomerBeforeAuthUrl', 'getLoginUrl', 'getRedirectActionName'])->getMock();
     $expressRedirectMock->expects($this->any())->method('getActionFlagList')->will($this->returnValue($actionFlagList));
     $atIndex = 0;
     $actionFlagList = array_merge(['no-dispatch' => true], $actionFlagList);
     foreach ($actionFlagList as $actionKey => $actionFlag) {
         $this->_actionFlag->expects($this->at($atIndex))->method('set')->with('', $actionKey, $actionFlag);
         $atIndex++;
     }
     $expectedLoginUrl = 'loginURL';
     $expressRedirectMock->expects($this->once())->method('getLoginUrl')->will($this->returnValue($expectedLoginUrl));
     $urlMock = $this->getMockBuilder('Magento\\Framework\\Url\\Helper\\Data')->disableOriginalConstructor()->setMethods(['addRequestParam'])->getMock();
     $urlMock->expects($this->once())->method('addRequestParam')->with($expectedLoginUrl, ['context' => 'checkout'])->will($this->returnValue($expectedLoginUrl));
     $this->_objectManager->expects($this->once())->method('get')->with('Magento\\Framework\\Url\\Helper\\Data')->will($this->returnValue($urlMock));
     $responseMock = $this->getMockBuilder('Magento\\Framework\\App\\Response\\Http')->disableOriginalConstructor()->setMethods(['setRedirect', '__wakeup'])->getMock();
     $responseMock->expects($this->once())->method('setRedirect')->with($expectedLoginUrl);
     $expressRedirectMock->expects($this->once())->method('getResponse')->will($this->returnValue($responseMock));
     $expressRedirectMock->expects($this->any())->method('getCustomerBeforeAuthUrl')->will($this->returnValue($customerBeforeAuthUrl));
     $expectedCustomerBeforeAuthUrl = $customerBeforeAuthUrl !== null ? $customerBeforeAuthUrl : $customerBeforeAuthUrlDefault;
     if ($expectedCustomerBeforeAuthUrl) {
         $this->_customerSession->expects($this->once())->method('setBeforeAuthUrl')->with($expectedCustomerBeforeAuthUrl);
     }
     $this->_helper->redirectLogin($expressRedirectMock, $customerBeforeAuthUrlDefault);
 }
 /**
  * Prevent express checkout
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn())) {
         return;
     }
     /** @var $controllerAction \Magento\Checkout\Controller\Express\RedirectLoginInterface*/
     $controllerAction = $observer->getEvent()->getControllerAction();
     if (!$controllerAction || !$controllerAction instanceof \Magento\Checkout\Controller\Express\RedirectLoginInterface || $controllerAction->getRedirectActionName() != $controllerAction->getRequest()->getActionName()) {
         return;
     }
     $this->messageManager->addNotice(__('To check out, please sign in using your email address.'));
     $customerBeforeAuthUrl = $this->_url->getUrl('persistent/index/expressCheckout');
     $this->_expressRedirectHelper->redirectLogin($controllerAction, $customerBeforeAuthUrl);
 }