Пример #1
0
 public function testLoginPostActionWhenRefererSetBeforeAuthUrl()
 {
     $this->_formKeyValidator->expects($this->once())->method('validate')->will($this->returnValue(true));
     $this->objectManager->expects($this->any())->method('get')->will($this->returnValueMap(array(array('Magento\\Customer\\Helper\\Data', new \Magento\Framework\Object(array('account_url' => 1))), array('Magento\\Framework\\App\\Config\\ScopeConfigInterface', new \Magento\Framework\Object(array('config_flag' => 1))), array('Magento\\Core\\Helper\\Data', $this->getMock('Magento\\Core\\Helper\\Data', array(), array(), '', false)))));
     $this->customerSession->expects($this->at(0))->method('isLoggedIn')->with()->will($this->returnValue(0));
     $this->customerSession->expects($this->at(4))->method('isLoggedIn')->with()->will($this->returnValue(1));
     $this->request->expects($this->once())->method('getParam')->with(\Magento\Customer\Helper\Data::REFERER_QUERY_PARAM_NAME)->will($this->returnValue('referer'));
     $this->url->expects($this->once())->method('isOwnOriginUrl')->with();
     $this->object->execute();
 }
Пример #2
0
 public function testLoginPostActionWhenRefererSetBeforeAuthUrl()
 {
     $this->_formKeyValidator->expects($this->once())->method('validate')->will($this->returnValue(true));
     $this->objectManager->expects($this->any())->method('get')->will($this->returnValueMap([['Magento\\Framework\\App\\Config\\ScopeConfigInterface', new \Magento\Framework\Object(['config_flag' => 1])], ['Magento\\Core\\Helper\\Data', $this->getMock('Magento\\Core\\Helper\\Data', [], [], '', false)]]));
     $this->customerSession->expects($this->at(0))->method('isLoggedIn')->with()->will($this->returnValue(0));
     $this->customerSession->expects($this->at(4))->method('isLoggedIn')->with()->will($this->returnValue(1));
     $this->request->expects($this->once())->method('getParam')->with(Url::REFERER_QUERY_PARAM_NAME)->will($this->returnValue('referer'));
     $this->url->expects($this->once())->method('isOwnOriginUrl')->with();
     $this->redirectFactoryMock->expects($this->once())->method('create')->willReturn($this->redirectResultMock);
     $this->redirectResultMock->expects($this->once())->method('setUrl')->willReturnSelf();
     $this->object->execute();
 }
Пример #3
0
 public function testLoginFailure()
 {
     $jsonRequest = '{"username":"******", "password":"******"}';
     $loginFailureResponse = '{"message":"Invalid login or password."}';
     $this->request->expects($this->any())->method('getRawBody')->willReturn($jsonRequest);
     $this->request->expects($this->any())->method('getMethod')->willReturn('POST');
     $this->request->expects($this->any())->method('isXmlHttpRequest')->willReturn(true);
     $this->resultJsonFactory->expects($this->never())->method('create')->willReturn($this->resultJson);
     $this->dataHelper->expects($this->any())->method('jsonDecode')->with($jsonRequest)->willReturn(['username' => '*****@*****.**', 'password' => 'invalid']);
     $customerMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->customerAccountManagementMock->expects($this->any())->method('authenticate')->with('*****@*****.**', 'invalid')->willThrowException(new InvalidEmailOrPasswordException('Invalid login or password.', []));
     $this->customerSession->expects($this->never())->method('setCustomerDataAsLoggedIn')->with($customerMock);
     $this->customerSession->expects($this->never())->method('regenerateId');
     $this->resultJson->expects($this->never())->method('setData')->with(['message' => 'Invalid login or password.'])->willReturn($loginFailureResponse);
     $this->resultRaw->expects($this->once())->method('setHttpResponseCode')->with(401);
     $this->object->execute();
 }
Пример #4
0
 /**
  * @param $customerId
  * @param $key
  * @param $backUrl
  * @param $successUrl
  * @param $resultUrl
  * @param $isSetFlag
  * @param $successMessage
  *
  * @dataProvider getSuccessRedirectDataProvider
  */
 public function testSuccessRedirect($customerId, $key, $backUrl, $successUrl, $resultUrl, $isSetFlag, $successMessage)
 {
     $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
     $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['id', false, $customerId], ['key', false, $key], ['back_url', false, $backUrl]]);
     $this->customerRepositoryMock->expects($this->any())->method('getById')->with($customerId)->will($this->returnValue($this->customerDataMock));
     $email = '*****@*****.**';
     $this->customerDataMock->expects($this->once())->method('getEmail')->will($this->returnValue($email));
     $this->customerAccountManagementMock->expects($this->once())->method('activate')->with($this->equalTo($email), $this->equalTo($key))->will($this->returnValue($this->customerDataMock));
     $this->customerSessionMock->expects($this->any())->method('setCustomerDataAsLoggedIn')->with($this->equalTo($this->customerDataMock))->willReturnSelf();
     $this->messageManagerMock->expects($this->any())->method('addSuccess')->with($this->stringContains($successMessage))->willReturnSelf();
     $this->storeMock->expects($this->any())->method('getFrontendName')->will($this->returnValue('frontend'));
     $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->storeMock));
     $this->urlMock->expects($this->any())->method('getUrl')->with($this->equalTo('*/*/index'), ['_secure' => true])->will($this->returnValue($successUrl));
     $this->redirectMock->expects($this->once())->method('success')->with($this->equalTo($resultUrl))->will($this->returnValue($resultUrl));
     $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with($this->equalTo(Url::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD), $this->equalTo(ScopeInterface::SCOPE_STORE))->will($this->returnValue($isSetFlag));
     $this->model->execute();
 }