本文整理汇总了PHP中Magento\Framework\App\Response\RedirectInterface类的典型用法代码示例。如果您正苦于以下问题:PHP RedirectInterface类的具体用法?PHP RedirectInterface怎么用?PHP RedirectInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RedirectInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testExecute
/**
* @return void
*/
public function testExecute()
{
$customerId = 7;
$captchaValue = 'some-value';
$email = 'test@example.com';
$redirectUrl = 'http://magento.com/customer/account/edit/';
$captcha = $this->getMock('Magento\\Captcha\\Model\\DefaultModel', [], [], '', false);
$captcha->expects($this->once())->method('isRequired')->willReturn(true);
$captcha->expects($this->once())->method('isCorrect')->with($captchaValue)->willReturn(false);
$this->helperMock->expects($this->once())->method('getCaptcha')->with(\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)->willReturn($captcha);
$response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
$request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
$request->expects($this->any())->method('getPost')->with(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE, null)->willReturn([\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID => $captchaValue]);
$controller = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
$controller->expects($this->any())->method('getRequest')->will($this->returnValue($request));
$controller->expects($this->any())->method('getResponse')->will($this->returnValue($response));
$this->captchaStringResolverMock->expects($this->once())->method('resolve')->with($request, \Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)->willReturn($captchaValue);
$customerDataMock = $this->getMock('\\Magento\\Customer\\Model\\Data\\Customer', [], [], '', false);
$this->customerSessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
$this->customerSessionMock->expects($this->atLeastOnce())->method('getCustomer')->willReturn($customerDataMock);
$this->authenticationMock->expects($this->once())->method('processAuthenticationFailure')->with($customerId);
$this->authenticationMock->expects($this->once())->method('isLocked')->with($customerId)->willReturn(true);
$this->customerSessionMock->expects($this->once())->method('logout');
$this->customerSessionMock->expects($this->once())->method('start');
$this->scopeConfigMock->expects($this->once())->method('getValue')->with('contact/email/recipient_email')->willReturn($email);
$message = __('The account is locked. Please wait and try again or contact %1.', $email);
$this->messageManagerMock->expects($this->exactly(2))->method('addError')->withConsecutive([$message], [__('Incorrect CAPTCHA')]);
$this->actionFlagMock->expects($this->once())->method('set')->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirectMock->expects($this->once())->method('redirect')->with($response, '*/*/edit')->willReturn($redirectUrl);
$this->observer->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller]));
}
示例2: testSaveActionWithException
public function testSaveActionWithException()
{
$this->formKeyValidatorMock->expects($this->once())->method('validate')->will($this->returnValue(true));
$this->customerSessionMock->expects($this->any())->method('getCustomerId')->will($this->returnValue(1));
$this->customerRepositoryMock->expects($this->any())->method('getById')->will($this->throwException(new NoSuchEntityException(__(NoSuchEntityException::MESSAGE_SINGLE_FIELD, ['fieldName' => 'customerId', 'value' => 'value']))));
$this->redirectMock->expects($this->once())->method('redirect')->with($this->responseMock, 'customer/account/', []);
$this->messageManagerMock->expects($this->never())->method('addSuccess');
$this->messageManagerMock->expects($this->once())->method('addError')->with('Something went wrong while saving your subscription.');
$this->action->execute();
}
示例3: setUp
public function setUp()
{
$this->request = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->getMock();
$this->response = $this->getMock('Magento\\Framework\\App\\ResponseInterface', [], [], '', false);
$this->redirect = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->setMethods(['setRefererOrBaseUrl'])->disableOriginalConstructor()->getMock();
$this->redirectFactory = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\RedirectFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
$this->redirectFactory->expects($this->any())->method('create')->willReturn($this->redirect);
$this->context = $this->getMockBuilder('Magento\\Framework\\App\\Action\\Context')->disableOriginalConstructor()->getMock();
$this->context->expects($this->any())->method('getResultRedirectFactory')->willReturn($this->redirectFactory);
$this->action = $this->getMockForAbstractClass('Magento\\Framework\\App\\Action\\AbstractAction', [$this->context]);
}
示例4: beforeDispatch
/**
* Perform customer authentication and wishlist feature state checks
*
* @param \Magento\Framework\App\ActionInterface $subject
* @param RequestInterface $request
* @return void
* @throws \Magento\Framework\Exception\NotFoundException
*/
public function beforeDispatch(\Magento\Framework\App\ActionInterface $subject, RequestInterface $request)
{
if ($this->authenticationState->isEnabled() && !$this->customerSession->authenticate($subject)) {
$subject->getActionFlag()->set('', 'no-dispatch', true);
if (!$this->customerSession->getBeforeWishlistUrl()) {
$this->customerSession->setBeforeWishlistUrl($this->redirector->getRefererUrl());
}
$this->customerSession->setBeforeWishlistRequest($request->getParams());
}
if (!$this->config->isSetFlag('wishlist/general/active')) {
throw new NotFoundException(__('Page not found.'));
}
}
示例5: execute
/**
* Check CAPTCHA on Contact Us page
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$formId = 'contact_us';
$captcha = $this->_helper->getCaptcha($formId);
if ($captcha->isRequired()) {
/** @var \Magento\Framework\App\Action\Action $controller */
$controller = $observer->getControllerAction();
if (!$captcha->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
$this->messageManager->addError(__('Incorrect CAPTCHA.'));
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirect->redirect($controller->getResponse(), 'contact/index/index');
}
}
}
示例6: testExecute
public function testExecute()
{
$firstElement = 'firstElement';
$symbolsDataArray = [$firstElement];
$redirectUrl = 'redirectUrl';
$this->requestMock->expects($this->once())->method('getParam')->with('custom_currency_symbol')->willReturn($symbolsDataArray);
$this->helperMock->expects($this->once())->method('getUrl')->with('*');
$this->redirectMock->expects($this->once())->method('getRedirectUrl')->willReturn($redirectUrl);
$this->currencySymbolMock->expects($this->once())->method('setCurrencySymbolsData')->with($symbolsDataArray);
$this->responseMock->expects($this->once())->method('setRedirect');
$this->filterManagerMock->expects($this->once())->method('stripTags')->with($firstElement)->willReturn($firstElement);
$this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\CurrencySymbol\\Model\\System\\Currencysymbol')->willReturn($this->currencySymbolMock);
$this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Framework\\Filter\\FilterManager')->willReturn($this->filterManagerMock);
$this->messageManagerMock->expects($this->once())->method('addSuccess')->with(__('You applied the custom currency symbols.'));
$this->action->execute();
}
示例7: execute
/**
* Check Captcha On Forgot Password Page
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$captchaModel = $this->helper->getCaptcha(self::FORM_ID);
if ($captchaModel->isRequired()) {
/** @var \Magento\Framework\App\Action\Action $controller */
$controller = $observer->getControllerAction();
if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), self::FORM_ID))) {
try {
$customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
$this->accountManagementHelper->processCustomerLockoutData($customer->getId());
$this->customerRepository->save($customer);
} catch (NoSuchEntityException $e) {
//do nothing as customer existance is validated later in authenticate method
}
$this->workWithLock();
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirect->redirect($controller->getResponse(), '*/*/edit');
}
}
$customer = $this->customerSession->getCustomer();
$login = $customer->getEmail();
$captchaModel->logAttempt($login);
return $this;
}
示例8: execute
/**
* Check Captcha On Forgot Password Page
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$captchaModel = $this->helper->getCaptcha(self::FORM_ID);
if ($captchaModel->isRequired()) {
/** @var \Magento\Framework\App\Action\Action $controller */
$controller = $observer->getControllerAction();
if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), self::FORM_ID))) {
$customerId = $this->customerSession->getCustomerId();
$this->authentication->processAuthenticationFailure($customerId);
if ($this->authentication->isLocked($customerId)) {
$this->customerSession->logout();
$this->customerSession->start();
$message = __('The account is locked. Please wait and try again or contact %1.', $this->scopeConfig->getValue('contact/email/recipient_email'));
$this->messageManager->addError($message);
}
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirect->redirect($controller->getResponse(), '*/*/edit');
}
}
$customer = $this->customerSession->getCustomer();
$login = $customer->getEmail();
$captchaModel->logAttempt($login);
return $this;
}
示例9: testCheckContactUsFormRedirectsCustomerWithWarningMessageWhenCaptchaIsRequiredAndInvalid
public function testCheckContactUsFormRedirectsCustomerWithWarningMessageWhenCaptchaIsRequiredAndInvalid()
{
$formId = 'contact_us';
$captchaValue = 'some-value';
$warningMessage = 'Incorrect CAPTCHA.';
$redirectRoutePath = 'contact/index/index';
$redirectUrl = 'http://magento.com/contacts/';
$postData = ['name' => 'Some Name'];
$request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
$response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
$request->expects($this->any())->method('getPost')->with(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE, null)->willReturn([$formId => $captchaValue]);
$request->expects($this->once())->method('getPostValue')->willReturn($postData);
$this->redirectMock->expects($this->once())->method('redirect')->with($response, $redirectRoutePath, [])->willReturn($redirectUrl);
$controller = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
$controller->expects($this->any())->method('getRequest')->willReturn($request);
$controller->expects($this->any())->method('getResponse')->willReturn($response);
$this->captchaMock->expects($this->any())->method('isRequired')->willReturn(true);
$this->captchaMock->expects($this->once())->method('isCorrect')->with($captchaValue)->willReturn(false);
$this->captchaStringResolverMock->expects($this->once())->method('resolve')->with($request, $formId)->willReturn($captchaValue);
$this->helperMock->expects($this->any())->method('getCaptcha')->with($formId)->willReturn($this->captchaMock);
$this->messageManagerMock->expects($this->once())->method('addError')->with($warningMessage);
$this->actionFlagMock->expects($this->once())->method('set')->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->dataPersistorMock->expects($this->once())->method('set')->with($formId, $postData);
$this->checkContactUsFormObserver->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller]));
}
示例10: testBeforeDispatch
/**
* @expectedException \Magento\Framework\Exception\NotFoundException
*/
public function testBeforeDispatch()
{
$actionFlag = $this->getMock('Magento\\Framework\\App\\ActionFlag', [], [], '', false);
$indexController = $this->getMock('Magento\\Wishlist\\Controller\\Index\\Index', [], [], '', false);
$actionFlag->expects($this->once())->method('set')->with('', 'no-dispatch', true)->willReturn(true);
$indexController->expects($this->once())->method('getActionFlag')->willReturn($actionFlag);
$this->authenticationState->expects($this->once())->method('isEnabled')->willReturn(true);
$this->customerSession->expects($this->once())->method('authenticate')->willReturn(false);
$this->redirector->expects($this->once())->method('getRefererUrl')->willReturn('http://referer-url.com');
$this->request->expects($this->once())->method('getParams')->willReturn(['product' => 1]);
$this->customerSession->expects($this->at(1))->method('__call')->with('getBeforeWishlistUrl', [])->willReturn(false);
$this->customerSession->expects($this->at(2))->method('__call')->with('setBeforeWishlistUrl', ['http://referer-url.com'])->willReturn(false);
$this->customerSession->expects($this->at(3))->method('__call')->with('setBeforeWishlistRequest', [['product' => 1]])->willReturn(true);
$this->config->expects($this->once())->method('isSetFlag')->with('wishlist/general/active')->willReturn(false);
$this->getPlugin()->beforeDispatch($indexController, $this->request);
}
示例11: testExecuteWithException
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testExecuteWithException()
{
$productId = 11;
$categoryId = 5;
$sender = 'sender';
$recipients = 'recipients';
$formData = ['sender' => $sender, 'recipients' => $recipients];
$redirectUrl = 'redirect_url';
/** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
$redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
$this->resultFactoryMock->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [])->willReturn($redirectMock);
$this->validatorMock->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true);
$this->requestMock->expects($this->exactly(2))->method('getParam')->willReturnMap([['id', null, $productId], ['cat_id', null, $categoryId]]);
/** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
$productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['isVisibleInCatalog', 'setCategory', 'getProductUrl'])->getMockForAbstractClass();
$this->productRepositoryMock->expects($this->once())->method('getById')->with($productId, false, null, false)->willReturn($productMock);
$productMock->expects($this->once())->method('isVisibleInCatalog')->willReturn(true);
$this->categoryRepositoryMock->expects($this->once())->method('get')->with($categoryId, null)->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException(__('No Category Exception.')));
$productMock->expects($this->never())->method('setCategory');
$this->registryMock->expects($this->once())->method('register')->willReturnMap([['product', $productMock, false, null]]);
$this->requestMock->expects($this->once())->method('getPostValue')->willReturn($formData);
$this->requestMock->expects($this->exactly(2))->method('getPost')->willReturnMap([['sender', $sender], ['recipients', $recipients]]);
$this->sendFriendMock->expects($this->once())->method('setSender')->with($sender)->willReturnSelf();
$this->sendFriendMock->expects($this->once())->method('setRecipients')->with($recipients)->willReturnSelf();
$this->sendFriendMock->expects($this->once())->method('setProduct')->with($productMock)->willReturnSelf();
$exception = new \Exception(__('Exception.'));
$this->sendFriendMock->expects($this->once())->method('validate')->willThrowException($exception);
$this->sendFriendMock->expects($this->never())->method('send');
$this->messageManagerMock->expects($this->once())->method('addException')->with($exception, __('Some emails were not sent.'))->willReturnSelf();
$this->catalogSessionMock->expects($this->once())->method('setSendfriendFormData')->with($formData);
$this->urlBuilderMock->expects($this->once())->method('getUrl')->with('sendfriend/product/send', ['_current' => true])->willReturn($redirectUrl);
$this->redirectMock->expects($this->once())->method('error')->with($redirectUrl)->willReturnArgument(0);
$redirectMock->expects($this->once())->method('setUrl')->with($redirectUrl)->willReturnSelf();
$this->assertEquals($redirectMock, $this->model->execute());
}
示例12: testDispatchPostDispatch
public function testDispatchPostDispatch()
{
$this->_requestMock->expects($this->exactly(3))->method('getFullActionName')->will($this->returnValue(self::FULL_ACTION_NAME));
$this->_requestMock->expects($this->exactly(2))->method('getRouteName')->will($this->returnValue(self::ROUTE_NAME));
$expectedEventParameters = ['controller_action' => $this->action, 'request' => $this->_requestMock];
$this->_eventManagerMock->expects($this->at(0))->method('dispatch')->with('controller_action_predispatch', $expectedEventParameters);
$this->_eventManagerMock->expects($this->at(1))->method('dispatch')->with('controller_action_predispatch_' . self::ROUTE_NAME, $expectedEventParameters);
$this->_eventManagerMock->expects($this->at(2))->method('dispatch')->with('controller_action_predispatch_' . self::FULL_ACTION_NAME, $expectedEventParameters);
$this->_requestMock->expects($this->once())->method('isDispatched')->will($this->returnValue(true));
$this->_actionFlagMock->expects($this->at(0))->method('get')->with('', Action::FLAG_NO_DISPATCH)->will($this->returnValue(false));
// _forward expectations
$this->_requestMock->expects($this->once())->method('initForward');
$this->_requestMock->expects($this->once())->method('setParams')->with(self::$actionParams);
$this->_requestMock->expects($this->once())->method('setControllerName')->with(self::CONTROLLER_NAME);
$this->_requestMock->expects($this->once())->method('setModuleName')->with(self::MODULE_NAME);
$this->_requestMock->expects($this->once())->method('setActionName')->with(self::ACTION_NAME);
$this->_requestMock->expects($this->once())->method('setDispatched')->with(false);
// _redirect expectations
$this->_redirectMock->expects($this->once())->method('redirect')->with($this->_responseMock, self::FULL_ACTION_NAME, self::$actionParams);
$this->_actionFlagMock->expects($this->at(1))->method('get')->with('', Action::FLAG_NO_POST_DISPATCH)->will($this->returnValue(false));
$this->_eventManagerMock->expects($this->at(3))->method('dispatch')->with('controller_action_postdispatch_' . self::FULL_ACTION_NAME, $expectedEventParameters);
$this->_eventManagerMock->expects($this->at(4))->method('dispatch')->with('controller_action_postdispatch_' . self::ROUTE_NAME, $expectedEventParameters);
$this->_eventManagerMock->expects($this->at(5))->method('dispatch')->with('controller_action_postdispatch', $expectedEventParameters);
$this->assertEquals($this->_responseMock, $this->action->dispatch($this->_requestMock));
}
示例13: execute
/**
* Check Captcha On User Login Page
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$formId = 'user_create';
$captchaModel = $this->_helper->getCaptcha($formId);
if ($captchaModel->isRequired()) {
/** @var \Magento\Framework\App\Action\Action $controller */
$controller = $observer->getControllerAction();
if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->_session->setCustomerFormData($controller->getRequest()->getPostValue());
$url = $this->_urlManager->getUrl('*/*/create', ['_nosecret' => true]);
$controller->getResponse()->setRedirect($this->redirect->error($url));
}
}
return $this;
}
示例14: testExecute
public function testExecute()
{
$customerId = 1;
$refererUrl = 'http://referer.url';
$this->sessionMock->expects($this->once())->method('getId')->willReturn($customerId);
$this->sessionMock->expects($this->once())->method('logout')->willReturnSelf();
$this->redirect->expects($this->once())->method('getRefererUrl')->willReturn($refererUrl);
$this->sessionMock->expects($this->once())->method('setBeforeAuthUrl')->with($refererUrl)->willReturnSelf();
$this->sessionMock->expects($this->once())->method('setLastCustomerId')->with($customerId);
$this->cookieManager->expects($this->once())->method('getCookie')->with('mage-cache-sessid')->willReturn(true);
$this->cookieMetadataFactory->expects($this->once())->method('createCookieMetadata')->willReturn($this->cookieMetadata);
$this->cookieMetadata->expects($this->once())->method('setPath')->with('/');
$this->cookieManager->expects($this->once())->method('deleteCookie')->with('mage-cache-sessid', $this->cookieMetadata);
$this->redirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
$this->resultRedirect->expects($this->once())->method('setPath')->with('*/*/logoutSuccess');
$this->assertSame($this->resultRedirect, $this->controller->execute());
}
示例15: testExecuteInvalidArgument
public function testExecuteInvalidArgument()
{
$themeId = 1;
$fileParam = '/path/to/file.ext';
$fileId = 'fileId';
$refererUrl = 'referer/url';
$this->request->expects($this->any())
->method('getParam')
->willReturnMap(
[
['theme_id', null, $themeId],
['file', null, $fileParam],
]
);
$theme = $this->getMockBuilder('Magento\Framework\View\Design\ThemeInterface')
->setMethods(['getId', 'load'])
->getMockForAbstractClass();
$urlDecoder = $this->getMockBuilder('Magento\Framework\Url\DecoderInterface')->getMock();
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$this->objectManager->expects($this->any())
->method('get')
->willReturnMap(
[
['Magento\Framework\Url\DecoderInterface', $urlDecoder],
['Psr\Log\LoggerInterface', $logger],
]
);
$this->objectManager->expects($this->any())
->method('create')
->with('Magento\Framework\View\Design\ThemeInterface')
->willReturn($theme);
$urlDecoder->expects($this->once())
->method('decode')
->with($fileParam)
->willReturn($fileId);
$theme->expects($this->once())
->method('load')
->with($themeId)
->willReturnSelf();
$theme->expects($this->once())
->method('getId')
->willReturn(null);
$this->messageManager->expects($this->once())
->method('addException');
$logger->expects($this->once())
->method('critical');
$this->redirect->expects($this->once())
->method('getRefererUrl')
->willReturn($refererUrl);
$this->response->expects($this->once())
->method('setRedirect')
->with($refererUrl);
$this->controller->executeInternal();
}