コード例 #1
0
 public function testGetDefaultRedirect()
 {
     $expectedResult = '/index';
     $this->redirect->expects($this->once())->method('setRefererOrBaseUrl')->willReturn('/index');
     $result = $this->action->getDefaultResult();
     $this->assertSame($expectedResult, $result);
 }
コード例 #2
0
 /**
  * Get resolved back url, rewritten to return checkout URL instead of cart url
  *
  * @param \Magento\Checkout\Controller\Cart\Add $subject
  * @return string
  */
 public function afterExecute(\Magento\Checkout\Controller\Cart\Add $subject, \Magento\Framework\Controller\Result\Redirect $redirect)
 {
     $shouldRedirectToCart = $this->_config->getValue('checkout/cart/redirect_to_cart', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     if ($shouldRedirectToCart && !$subject->getRequest()->getParam('in_cart')) {
         $redirect->setUrl($this->_url->getUrl('checkout/index/index'));
     }
     return $redirect;
 }
コード例 #3
0
 /**
  * @return void
  */
 public function testCreateActionRegistrationDisabled()
 {
     $this->customerSession->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
     $this->registrationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(false));
     $this->redirectFactoryMock->expects($this->once())->method('create')->willReturn($this->redirectResultMock);
     $this->redirectResultMock->expects($this->once())->method('setPath')->with('*/*')->willReturnSelf();
     $this->resultPageMock->expects($this->never())->method('getLayout');
     $this->object->execute();
 }
コード例 #4
0
 public function testExecuteWithWishlist()
 {
     $url = 'http://redirect-url.com';
     $quantity = 2;
     $this->wishlistProviderMock->expects($this->once())->method('getWishlist')->willReturn($this->wishlistMock);
     $this->requestMock->expects($this->any())->method('getParam')->with('qty')->willReturn($quantity);
     $this->itemCarrierMock->expects($this->once())->method('moveAllToCart')->with($this->wishlistMock, 2)->willReturn($url);
     $this->resultRedirectMock->expects($this->once())->method('setUrl')->with($url)->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->allcartController->execute());
 }
コード例 #5
0
ファイル: MyCreditCardsTest.php プロジェクト: nja78/magento2
 /**
  * Executes the dispatch override
  */
 public function testDispatchNotLoggedIn()
 {
     $objectManager = new ObjectManagerHelper($this);
     $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
     $this->resultRedirect->expects($this->any())->method('setPath')->willReturnSelf();
     $this->customerSession->expects($this->any())->method('authenticate')->willReturn(false);
     $this->config->expects($this->any())->method('useVault')->willReturn(true);
     /**
      * @var \Magento\Framework\App\RequestInterface $requestInterface
      */
     $requestInterface = $this->getMockBuilder('\\Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock();
     $notification = $objectManager->getObject('Magento\\Braintree\\Controller\\MyCreditCards', ['customerSession' => $this->customerSession, 'resultRedirectFactory' => $this->resultRedirectFactory, 'config' => $this->config, 'customerUrl' => $this->customerUrl, 'response' => $this->_response]);
     $this->assertSame($this->_response, $notification->dispatch($requestInterface));
 }
コード例 #6
0
ファイル: Banner.php プロジェクト: Doability/magento2dev
 /**
  * Get back result redirect after add/edit.
  *
  * @param \Magento\Framework\Controller\Result\Redirect $resultRedirect
  * @param null                                          $paramCrudId
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 protected function _getBackResultRedirect(\Magento\Framework\Controller\Result\Redirect $resultRedirect, $paramCrudId = null)
 {
     switch ($this->getRequest()->getParam('back')) {
         case 'edit':
             $resultRedirect->setPath('*/*/edit', [static::PARAM_CRUD_ID => $paramCrudId, '_current' => true, 'store' => $this->getRequest()->getParam('store'), 'current_slider_id' => $this->getRequest()->getParam('current_slider_id'), 'saveandclose' => $this->getRequest()->getParam('saveandclose')]);
             break;
         case 'new':
             $resultRedirect->setPath('*/*/new', ['_current' => true]);
             break;
         default:
             $resultRedirect->setPath('*/*/');
     }
     return $resultRedirect;
 }
コード例 #7
0
ファイル: SaveTest.php プロジェクト: pradeep-wagento/magento2
 /**
  * Executes the controller action
  */
 public function testExecute()
 {
     $objectManager = new ObjectManagerHelper($this);
     $phrase = new \Magento\Framework\Phrase('There was error during saving card data');
     $this->request->expects($this->any())->method('getParam')->willReturn('token');
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
     $this->resultRedirect->expects($this->once())->method('setPath')->willReturnSelf();
     /**
      * @var \Magento\Framework\Message\ManagerInterface $messageManager
      */
     $messageManager = $this->getMockBuilder('\\Magento\\Framework\\Message\\ManagerInterface')->getMock();
     $messageManager->expects($this->once())->method('addError')->with($phrase);
     $notification = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\Save', ['request' => $this->request, 'resultRedirectFactory' => $this->resultRedirectFactory, 'messageManager' => $messageManager]);
     $this->assertSame($this->resultRedirect, $notification->execute());
 }
コード例 #8
0
ファイル: Gallery.php プロジェクト: shabbirvividads/magento2
 /**
  * View product gallery action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $result = null;
     if (!$this->_initProduct()) {
         $store = $this->getRequest()->getQuery('store');
         if (isset($store) && !$this->getResponse()->isRedirect()) {
             $result = $this->resultRedirectFactory->create();
             $result->setPath('');
         } elseif (!$this->getResponse()->isRedirect()) {
             $result = $this->resultForwardFactory->create();
             $result->forward('noroute');
         }
     }
     return $result ?: $this->resultPageFactory->create();
 }
コード例 #9
0
 /**
  * Executes the controller action and asserts with redirects for can't delete card logic
  */
 public function testExecuteNonExistingTokenRedirect()
 {
     $objectManager = new ObjectManagerHelper($this);
     $phrase = new \Magento\Framework\Phrase('a,b,c');
     $this->vault->expects($this->once())->method('deleteCard')->willReturn(json_decode(json_encode(['success' => false, 'message' => 'a,b,c'])));
     $this->request->expects($this->any())->method('getParam')->willReturn('token');
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
     $this->resultRedirect->expects($this->once())->method('setPath')->willReturnSelf();
     /**
      * @var \Magento\Framework\Message\ManagerInterface $messageManager
      */
     $messageManager = $this->getMockBuilder('\\Magento\\Framework\\Message\\ManagerInterface')->getMock();
     $messageManager->expects($this->once())->method('addError')->with($phrase);
     $notification = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\DeleteConfirm', ['request' => $this->request, 'resultRedirectFactory' => $this->resultRedirectFactory, 'vault' => $this->vault, 'messageManager' => $messageManager]);
     $this->assertSame($this->resultRedirect, $notification->execute());
 }
コード例 #10
0
ファイル: DeleteTest.php プロジェクト: Doability/magento2dev
 public function testExecuteWithException()
 {
     $addressId = 1;
     $customerId = 2;
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
     $this->request->expects($this->once())->method('getParam')->with('id', false)->willReturn($addressId);
     $this->validatorMock->expects($this->once())->method('validate')->with($this->request)->willReturn(true);
     $this->addressRepositoryMock->expects($this->once())->method('getById')->with($addressId)->willReturn($this->address);
     $this->sessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $this->address->expects($this->once())->method('getCustomerId')->willReturn(34);
     $exception = new \Exception('Exception');
     $this->messageManager->expects($this->once())->method('addError')->with(__('We can\'t delete the address right now.'))->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addException')->with($exception, __('We can\'t delete the address right now.'));
     $this->resultRedirect->expects($this->once())->method('setPath')->with('*/*/index')->willReturnSelf();
     $this->assertSame($this->resultRedirect, $this->model->execute());
 }
コード例 #11
0
ファイル: IndexTest.php プロジェクト: kid17/magento2
 public function testInvalidQuote()
 {
     $this->basicStub($this->quoteMock, 'hasError')->willReturn(true);
     $expectedPath = 'checkout/cart';
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with($expectedPath)->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->model->execute());
 }
コード例 #12
0
 /**
  * Test execute add success critical exception
  *
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteAddSuccessCriticalException()
 {
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false);
     $helper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false);
     $logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', [], [], '', false);
     $exception = new \Exception();
     $logger->expects($this->once())->method('critical')->with($exception)->willReturn(true);
     $helper->expects($this->exactly(2))->method('calculate')->willReturn(true);
     $wishlist->expects($this->once())->method('getItem')->with(3)->willReturn($item);
     $wishlist->expects($this->once())->method('updateItem')->with(3, new \Magento\Framework\DataObject([]))->willReturnSelf();
     $wishlist->expects($this->once())->method('save')->willReturn(null);
     $wishlist->expects($this->once())->method('getId')->willReturn(56);
     $product->expects($this->once())->method('isVisibleInCatalog')->willReturn(true);
     $product->expects($this->once())->method('getName')->willReturn('Test name');
     $this->request->expects($this->at(0))->method('getParam')->with('product', null)->willReturn(2);
     $this->request->expects($this->at(1))->method('getParam')->with('id', null)->willReturn(3);
     $this->productRepository->expects($this->once())->method('getById')->with(2)->willReturn($product);
     $item->expects($this->once())->method('load')->with(3)->willReturnSelf();
     $item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(12);
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->with(12)->willReturn($wishlist);
     $this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item);
     $this->request->expects($this->once())->method('getParams')->willReturn([]);
     $this->om->expects($this->at(1))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
     $this->om->expects($this->at(2))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
     $this->om->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->willReturn($logger);
     $this->eventManager->expects($this->once())->method('dispatch')->with('wishlist_update_item', ['wishlist' => $wishlist, 'product' => $product, 'item' => $item])->willReturn(true);
     $this->messageManager->expects($this->once())->method('addSuccess')->with('Test name has been updated in your Wish List.', null)->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addError')->with('We can\'t update your Wish List right now.', null)->willReturn(true);
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*', ['wishlist_id' => 56])->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->getController()->execute());
 }
コード例 #13
0
ファイル: EditPostTest.php プロジェクト: nja78/magento2
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testEditPostActionWithoutErrors()
 {
     $customerId = 24;
     $address = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false);
     $loadedCustomer = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], 'loadedCustomer', false);
     $loadedCustomer->expects($this->once())->method('getAddresses')->willReturn([$address, $address]);
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->redirectResultMock);
     $this->formKeyValidator->expects($this->once())->method('validate')->willReturn(true);
     $this->request->expects($this->once())->method('isPost')->willReturn(true);
     $this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $this->customerExtractor->expects($this->once())->method('extract')->willReturn($this->customer);
     $this->customer->expects($this->once())->method('setId')->with($customerId);
     $this->customer->expects($this->once())->method('getAddresses')->willReturn(null);
     $this->customerRepository->expects($this->exactly(2))->method('getById')->with($customerId)->willReturn($loadedCustomer);
     $this->customer->expects($this->once())->method('setAddresses')->with([$address, $address]);
     $this->request->expects($this->once())->method('getParam')->with('change_password')->willReturn(true);
     $this->request->expects($this->at(2))->method('getPost')->with('current_password', null)->willReturn(123);
     $this->request->expects($this->at(3))->method('getPost')->with('password', null)->willReturn(321);
     $this->request->expects($this->at(4))->method('getPost')->with('password_confirmation', null)->willReturn(321);
     $this->customerAccountManagement->expects($this->once())->method('changePassword');
     $this->customerRepository->expects($this->once())->method('save');
     $messageCollection = $this->getMock('Magento\\Framework\\Message\\Collection', [], [], '', false);
     $messageCollection->expects($this->once())->method('getCount')->willReturn(0);
     $this->messageManager->expects($this->once())->method('getMessages')->willReturn($messageCollection);
     $this->messageManager->expects($this->once())->method('addSuccess')->with('You saved the account information.');
     $this->redirectResultMock->expects($this->once())->method('setPath')->with('customer/account')->willReturn('http://test.com/customer/account/edit');
     $this->assertSame($this->redirectResultMock, $this->getController()->execute());
 }
コード例 #14
0
ファイル: AllcartTest.php プロジェクト: nblair/magescotch
    public function testExecutePassed()
    {
        $url = 'http://redirect-url.com';
        $wishlist = $this->getMock('Magento\Wishlist\Model\Wishlist', [], [], '', false);
        
        $this->formKeyValidator->expects($this->once())
            ->method('validate')
            ->with($this->request)
            ->will($this->returnValue(true));
        $this->request->expects($this->once())
            ->method('getParam')
            ->with('qty')
            ->will($this->returnValue(2));
        $this->wishlistProvider->expects($this->once())
            ->method('getWishlist')
            ->will($this->returnValue($wishlist));
        $this->itemCarrier->expects($this->once())
            ->method('moveAllToCart')
            ->with($wishlist, 2)
            ->willReturn($url);
        $this->resultRedirectMock->expects($this->once())
            ->method('setUrl')
            ->with($url)
            ->willReturnSelf();

        $this->assertSame($this->resultRedirectMock, $this->getController()->executeInternal());
    }
コード例 #15
0
ファイル: ConfirmTest.php プロジェクト: opexsw/magento2
 public function testGetDefaultRedirect()
 {
     $testUrl = 'http://example.com';
     $this->urlMock->expects($this->once())->method('getUrl')->with('*/*/index', ['_secure' => true])->willReturn($testUrl);
     $this->redirectMock->expects($this->once())->method('error')->with($testUrl)->willReturn($testUrl);
     $this->redirectResultMock->expects($this->once())->method('setUrl')->with($testUrl)->willReturnSelf();
     $this->model->getDefaultResult();
 }
コード例 #16
0
ファイル: LogoutTest.php プロジェクト: Doability/magento2dev
 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());
 }
コード例 #17
0
 public function testScopeRedirect()
 {
     $scope = 'test';
     $scopeId = 1;
     $this->request->expects($this->exactly(2))->method('getParam')->willReturnMap([['scope', null, $scope], ['scope_id', null, $scopeId]]);
     $this->scopeValidator->expects($this->once())->method('isValidScope')->with($scope, $scopeId)->willReturn(false);
     $this->resultRedirect->expects($this->once())->method('setPath')->with('theme/design_config/')->willReturnSelf();
     $this->assertSame($this->resultRedirect, $this->controller->execute());
 }
コード例 #18
0
 /**
  * {@inheritdoc}
  */
 public function renderResult(\Magento\Framework\App\ResponseInterface $response)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'renderResult');
     if (!$pluginInfo) {
         return parent::renderResult($response);
     } else {
         return $this->___callPlugins('renderResult', func_get_args(), $pluginInfo);
     }
 }
コード例 #19
0
 /**
  * @param string $currentPassword
  * @param string $newPassword
  * @param [] $errors
  * @param string $customerEmail
  * @return void
  */
 protected function mockChangePasswordErrors($currentPassword, $newPassword, $errors, $customerEmail)
 {
     if (!empty($errors['exception'])) {
         $exception = new $errors['exception'](__($errors['message']));
         $this->customerAccountManagement->expects($this->once())->method('changePassword')->with($customerEmail, $currentPassword, $newPassword)->willThrowException($exception);
         $this->messageManager->expects($this->any())->method('addException')->with($exception, __('We can\'t save the customer.'))->willReturnSelf();
     }
     $this->customerSession->expects($this->once())->method('setCustomerFormData')->with(true)->willReturnSelf();
     $this->messageManager->expects($this->any())->method('addError')->with($errors['message'])->willReturnSelf();
     $this->resultRedirect->expects($this->any())->method('setPath')->with('*/*/edit')->willReturnSelf();
 }
コード例 #20
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();
 }
コード例 #21
0
ファイル: AddTest.php プロジェクト: opexsw/magento2
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteProductAddedToWishlistAfterObjectManagerThrowException()
 {
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['isVisibleInCatalog', 'getName'], [], '', false);
     $product->expects($this->once())->method('isVisibleInCatalog')->will($this->returnValue(true));
     $product->expects($this->once())->method('getName')->will($this->returnValue('Product test name'));
     $this->productRepository->expects($this->once())->method('getById')->with(2)->will($this->returnValue($product));
     $exception = new \Exception('Exception');
     $wishListItem = new \stdClass();
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', ['addNewItem', 'save', 'getId'], [], '', false);
     $wishlist->expects($this->once())->method('addNewItem')->will($this->returnValue($wishListItem));
     $wishlist->expects($this->once())->method('getId')->will($this->returnValue(2));
     $wishlist->expects($this->once())->method('save')->will($this->returnValue(true));
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->will($this->returnValue($wishlist));
     $request = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParams'], [], '', false);
     $request->expects($this->once())->method('getParams')->will($this->returnValue(['product' => 2]));
     $wishlistHelper = $this->getMock('Magento\\Wishlist\\Helper\\Data', ['calculate'], [], '', false);
     $wishlistHelper->expects($this->once())->method('calculate')->will($this->returnSelf());
     $escaper = $this->getMock('Magento\\Framework\\Escaper', ['escapeHtml', 'escapeUrl'], [], '', false);
     $escaper->expects($this->once())->method('escapeHtml')->with('Product test name')->will($this->returnValue('Product test name'));
     $escaper->expects($this->once())->method('escapeUrl')->with('http://test-url.com')->will($this->returnValue('http://test-url.com'));
     $logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', ['critical'], [], '', false);
     $logger->expects($this->once())->method('critical')->with($exception)->will($this->returnValue(true));
     $om = $this->getMock('Magento\\Framework\\App\\ObjectManager', ['get'], [], '', false);
     $om->expects($this->at(0))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->will($this->returnValue($wishlistHelper));
     $om->expects($this->at(1))->method('get')->with('Magento\\Framework\\Escaper')->will($this->returnValue($escaper));
     $om->expects($this->at(2))->method('get')->with('Magento\\Framework\\Escaper')->will($this->returnValue($escaper));
     $om->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->will($this->returnValue($logger));
     $response = $this->getMock('Magento\\Framework\\App\\Response\\Http', null, [], '', false);
     $eventManager = $this->getMock('Magento\\Framework\\Event\\Manager', ['dispatch'], [], '', false);
     $eventManager->expects($this->once())->method('dispatch')->with('wishlist_add_product', ['wishlist' => $wishlist, 'product' => $product, 'item' => $wishListItem])->will($this->returnValue(true));
     $url = $this->getMock('Magento\\Framework\\Url', null, [], '', false);
     $actionFlag = $this->getMock('Magento\\Framework\\App\\ActionFlag', null, [], '', false);
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*', ['wishlist_id' => 2])->willReturnSelf();
     $view = $this->getMock('Magento\\Framework\\App\\View', null, [], '', false);
     $messageManager = $this->getMock('Magento\\Framework\\Message\\Manager', ['addError', 'addSuccess'], [], '', false);
     $messageManager->expects($this->once())->method('addError')->with('An error occurred while adding item to wish list.')->will($this->returnValue(null));
     $messageManager->expects($this->once())->method('addSuccess')->will($this->throwException($exception));
     $this->context->expects($this->any())->method('getObjectManager')->will($this->returnValue($om));
     $this->context->expects($this->any())->method('getRequest')->will($this->returnValue($request));
     $this->context->expects($this->any())->method('getResponse')->will($this->returnValue($response));
     $this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager));
     $this->context->expects($this->any())->method('getUrl')->will($this->returnValue($url));
     $this->context->expects($this->any())->method('getActionFlag')->will($this->returnValue($actionFlag));
     $this->context->expects($this->any())->method('getView')->will($this->returnValue($view));
     $this->context->expects($this->any())->method('getMessageManager')->will($this->returnValue($messageManager));
     $this->context->expects($this->any())->method('getResultFactory')->willReturn($this->resultFactoryMock);
     $this->customerSession->expects($this->exactly(1))->method('getBeforeWishlistRequest')->will($this->returnValue(false));
     $this->customerSession->expects($this->never())->method('unsBeforeWishlistRequest')->will($this->returnValue(null));
     $this->customerSession->expects($this->once())->method('getBeforeWishlistUrl')->will($this->returnValue('http://test-url.com'));
     $this->customerSession->expects($this->once())->method('setBeforeWishlistUrl')->with(null)->will($this->returnValue(null));
     $this->createController();
     $this->assertSame($this->resultRedirectMock, $this->controller->execute());
 }
コード例 #22
0
ファイル: ConfirmTest.php プロジェクト: kid17/magento2
 /**
  * @dataProvider getParametersDataProvider
  */
 public function testNoCustomerIdInRequest($customerId, $key)
 {
     $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
     $this->requestMock->expects($this->at(0))->method('getParam')->with($this->equalTo('id'), false)->will($this->returnValue($customerId));
     $this->requestMock->expects($this->at(1))->method('getParam')->with($this->equalTo('key'), false)->will($this->returnValue($key));
     $exception = new \Exception('Bad request.');
     $this->messageManagerMock->expects($this->once())->method('addException')->with($this->equalTo($exception), $this->equalTo('There was an error confirming the account'));
     $testUrl = 'http://example.com';
     $this->urlMock->expects($this->once())->method('getUrl')->with($this->equalTo('*/*/index'), ['_secure' => true])->will($this->returnValue($testUrl));
     $this->redirectMock->expects($this->once())->method('error')->with($this->equalTo($testUrl))->will($this->returnValue($testUrl));
     $this->redirectResultMock->expects($this->once())->method('setUrl')->with($this->equalTo($testUrl))->willReturnSelf();
     $this->assertInstanceOf('Magento\\Framework\\Controller\\Result\\Redirect', $this->model->execute());
 }
コード例 #23
0
ファイル: DeleteTest.php プロジェクト: nblair/magescotch
 /**
  * Executes the controller action and asserts with redirects for non existing logic
  */
 public function testExecuteInternalNonExistingTokenRedirect()
 {
     $objectManager = new ObjectManagerHelper($this);
     $phrase = new \Magento\Framework\Phrase('Credit card does not exist');
     $this->vault->expects($this->once())->method('storedCard')->willReturn(false);
     $this->request->expects($this->any())->method('getParam')->willReturn('token');
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
     $this->resultPageFactory->expects($this->never())->method('create')->willReturn($this->resultPage);
     $this->resultRedirect->expects($this->once())->method('setPath')->willReturnSelf();
     /**
      * @var \Magento\Framework\Message\ManagerInterface $messageManager
      */
     $messageManager = $this->getMockBuilder('\\Magento\\Framework\\Message\\ManagerInterface')->getMock();
     $messageManager->expects($this->once())->method('addError')->with($phrase);
     /** @var \Magento\Braintree\Controller\Creditcard\Delete $controller */
     $controller = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\Delete', ['request' => $this->request, 'resultPageFactory' => $this->resultPageFactory, 'resultRedirectFactory' => $this->resultRedirectFactory, 'vault' => $this->vault, 'messageManager' => $messageManager]);
     $this->assertSame($this->resultRedirect, $controller->executeInternal());
 }
コード例 #24
0
ファイル: SaveTest.php プロジェクト: tingyeeh/magento2
 /**
  * @param bool $formKeyIsValid
  * @param bool $isPost
  * @dataProvider executeDataProvider
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecute($formKeyIsValid, $isPost)
 {
     $this->formKeyValidator->expects($this->any())->method('validate')->willReturn($formKeyIsValid);
     $this->request->expects($this->any())->method('isPost')->willReturn($isPost);
     if (!$formKeyIsValid || !$isPost) {
         $this->messageManager->expects($this->once())->method('addError');
         $this->resultRedirect->expects($this->once())->method('setPath')->with('sales/order/index');
         $this->shipmentLoader->expects($this->never())->method('load');
         $this->assertEquals($this->resultRedirect, $this->saveAction->execute());
     } else {
         $shipmentId = 1000012;
         $orderId = 10003;
         $tracking = [];
         $shipmentData = ['items' => [], 'send_email' => ''];
         $shipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['load', 'save', 'register', 'getOrder', 'getOrderId', '__wakeup'], [], '', false);
         $order = $this->getMock('Magento\\Sales\\Model\\Order', ['setCustomerNoteNotify', '__wakeup'], [], '', false);
         $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipmentData], ['tracking', null, $tracking]]));
         $this->shipmentLoader->expects($this->any())->method('setShipmentId')->with($shipmentId);
         $this->shipmentLoader->expects($this->any())->method('setOrderId')->with($orderId);
         $this->shipmentLoader->expects($this->any())->method('setShipment')->with($shipmentData);
         $this->shipmentLoader->expects($this->any())->method('setTracking')->with($tracking);
         $this->shipmentLoader->expects($this->once())->method('load')->will($this->returnValue($shipment));
         $shipment->expects($this->once())->method('register')->will($this->returnSelf());
         $shipment->expects($this->any())->method('getOrder')->will($this->returnValue($order));
         $order->expects($this->once())->method('setCustomerNoteNotify')->with(false);
         $this->labelGenerator->expects($this->any())->method('create')->with($shipment, $this->request)->will($this->returnValue(true));
         $saveTransaction = $this->getMockBuilder('Magento\\Framework\\DB\\Transaction')->disableOriginalConstructor()->setMethods([])->getMock();
         $saveTransaction->expects($this->at(0))->method('addObject')->with($shipment)->will($this->returnSelf());
         $saveTransaction->expects($this->at(1))->method('addObject')->with($order)->will($this->returnSelf());
         $saveTransaction->expects($this->at(2))->method('save');
         $this->session->expects($this->once())->method('getCommentText')->with(true);
         $this->objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\DB\\Transaction')->will($this->returnValue($saveTransaction));
         $this->objectManager->expects($this->once())->method('get')->with('Magento\\Backend\\Model\\Session')->will($this->returnValue($this->session));
         $path = 'sales/order/view';
         $arguments = ['order_id' => $orderId];
         $shipment->expects($this->once())->method('getOrderId')->will($this->returnValue($orderId));
         $this->prepareRedirect($path, $arguments);
         $this->saveAction->execute();
         $this->assertEquals($this->response, $this->saveAction->getResponse());
     }
 }
コード例 #25
0
ファイル: SaveTest.php プロジェクト: Doability/magento2dev
 public function testExecuteWithTaxClassAndException()
 {
     $taxClass = '3';
     $groupId = 0;
     $code = 'NOT LOGGED IN';
     $this->request->expects($this->exactly(3))->method('getParam')->withConsecutive(['tax_class'], ['id'], ['code'])->willReturnOnConsecutiveCalls($taxClass, $groupId, null);
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
     $this->groupRepositoryMock->expects($this->once())->method('getById')->with($groupId)->willReturn($this->group);
     $this->group->expects($this->once())->method('getCode')->willReturn($code);
     $this->group->expects($this->once())->method('setCode')->with($code);
     $this->group->expects($this->once())->method('setTaxClassId')->with($taxClass);
     $this->groupRepositoryMock->expects($this->once())->method('save')->with($this->group);
     $this->messageManager->expects($this->once())->method('addSuccess')->with(__('You saved the customer group.'));
     $exception = new \Exception('Exception');
     $this->resultRedirect->expects($this->at(0))->method('setPath')->with('customer/group')->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addError')->with('Exception');
     $this->dataObjectProcessorMock->expects($this->once())->method('buildOutputDataArray')->with($this->group, '\\Magento\\Customer\\Api\\Data\\GroupInterface')->willReturn(['code' => $code]);
     $this->session->expects($this->once())->method('setCustomerGroupData')->with(['customer_group_code' => $code]);
     $this->resultRedirect->expects($this->at(1))->method('setPath')->with('customer/group/edit', ['id' => $groupId]);
     $this->assertSame($this->resultRedirect, $this->controller->execute());
 }
コード例 #26
0
ファイル: RemoveTest.php プロジェクト: koliaGI/magento2
 public function testExecuteCanNotSaveWishlistAndWithRedirect()
 {
     $referer = 'http://referer-url.com';
     $exception = new \Exception('Message');
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
     $wishlist->expects($this->once())->method('save')->willThrowException($exception);
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->with(2)->willReturn($wishlist);
     $this->messageManager->expects($this->once())->method('addError')->with('We can\'t delete the item from the Wish List right now.')->willReturn(true);
     $wishlistHelper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false);
     $wishlistHelper->expects($this->once())->method('calculate')->willReturnSelf();
     $this->om->expects($this->once())->method('get')->with('Magento\\Wishlist\\Helper\\Data')->will($this->returnValue($wishlistHelper));
     $item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false);
     $item->expects($this->once())->method('load')->with(1)->willReturnSelf();
     $item->expects($this->once())->method('getId')->willReturn(1);
     $item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(2);
     $item->expects($this->once())->method('delete')->willReturn(true);
     $this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item);
     $this->request->expects($this->once())->method('getServer')->with('HTTP_REFERER')->willReturn($referer);
     $this->request->expects($this->exactly(3))->method('getParam')->willReturnMap([['item', null, 1], ['referer_url', null, $referer], ['uenc', null, false]]);
     $this->url->expects($this->once())->method('getUrl')->with('*/*')->willReturn('http://test.com/frontname/module/controller/action');
     $this->redirect->expects($this->once())->method('getRedirectUrl')->willReturn('http://test.com/frontname/module/controller/action');
     $this->resultRedirectMock->expects($this->once())->method('setUrl')->with('http://test.com/frontname/module/controller/action')->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->getController()->execute());
 }
コード例 #27
0
ファイル: Redirect.php プロジェクト: pradeep-wagento/magento2
 /**
  * {@inheritdoc}
  */
 protected function render(App\ResponseInterface $response)
 {
     $this->session->setIsUrlNotice($this->actionFlag->get('', AbstractAction::FLAG_IS_URLS_CHECKED));
     return parent::render($response);
 }
コード例 #28
0
ファイル: CartTest.php プロジェクト: vasiljok/magento2
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteWithoutQuantityArrayAndConfigurable()
 {
     $itemId = 2;
     $wishlistId = 1;
     $qty = [];
     $productId = 4;
     $indexUrl = 'index_url';
     $configureUrl = 'configure_url';
     $options = [5 => 'option'];
     $params = ['item' => $itemId, 'qty' => $qty];
     $itemMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->disableOriginalConstructor()->setMethods(['load', 'getId', 'getWishlistId', 'setQty', 'setOptions', 'getBuyRequest', 'mergeBuyRequest', 'addToCart', 'getProduct', 'getProductId'])->getMock();
     $this->requestMock->expects($this->at(0))->method('getParam')->with('item', null)->willReturn($itemId);
     $this->itemFactoryMock->expects($this->once())->method('create')->willReturn($itemMock);
     $itemMock->expects($this->once())->method('load')->with($itemId, null)->willReturnSelf();
     $itemMock->expects($this->exactly(2))->method('getId')->willReturn($itemId);
     $itemMock->expects($this->once())->method('getWishlistId')->willReturn($wishlistId);
     $wishlistMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock();
     $this->wishlistProviderMock->expects($this->once())->method('getWishlist')->with($wishlistId)->willReturn($wishlistMock);
     $this->requestMock->expects($this->at(1))->method('getParam')->with('qty', null)->willReturn($qty);
     $this->quantityProcessorMock->expects($this->once())->method('process')->with(1)->willReturnArgument(0);
     $itemMock->expects($this->once())->method('setQty')->with(1)->willReturnSelf();
     $this->urlMock->expects($this->at(0))->method('getUrl')->with('*/*', null)->willReturn($indexUrl);
     $itemMock->expects($this->once())->method('getProductId')->willReturn($productId);
     $this->urlMock->expects($this->at(1))->method('getUrl')->with('*/*/configure/', ['id' => $itemId, 'product_id' => $productId])->willReturn($configureUrl);
     $optionMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item\\Option')->disableOriginalConstructor()->getMock();
     $this->optionFactoryMock->expects($this->once())->method('create')->willReturn($optionMock);
     $optionsMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Resource\\Item\\Option\\Collection')->disableOriginalConstructor()->getMock();
     $optionMock->expects($this->once())->method('getCollection')->willReturn($optionsMock);
     $optionsMock->expects($this->once())->method('addItemFilter')->with([$itemId])->willReturnSelf();
     $optionsMock->expects($this->once())->method('getOptionsByItem')->with($itemId)->willReturn($options);
     $itemMock->expects($this->once())->method('setOptions')->with($options)->willReturnSelf();
     $this->requestMock->expects($this->once())->method('getParams')->willReturn($params);
     $buyRequestMock = $this->getMockBuilder('Magento\\Framework\\Object')->disableOriginalConstructor()->getMock();
     $itemMock->expects($this->once())->method('getBuyRequest')->willReturn($buyRequestMock);
     $this->productHelperMock->expects($this->once())->method('addParamsToBuyRequest')->with($params, ['current_config' => $buyRequestMock])->willReturn($buyRequestMock);
     $itemMock->expects($this->once())->method('mergeBuyRequest')->with($buyRequestMock)->willReturnSelf();
     $itemMock->expects($this->once())->method('addToCart')->with($this->checkoutCartMock, true)->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('message')));
     $this->messageManagerMock->expects($this->once())->method('addNotice')->with('message', null)->willReturnSelf();
     $this->helperMock->expects($this->once())->method('calculate')->willReturnSelf();
     $this->resultRedirectMock->expects($this->once())->method('setUrl')->with($configureUrl)->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->model->execute());
 }
コード例 #29
0
 public function testRender()
 {
     $this->response->expects($this->once())->method('setRedirect');
     $this->assertInstanceOf('Magento\\Framework\\Controller\\Result\\Redirect', $this->redirect->renderResult($this->response));
 }
コード例 #30
0
ファイル: Index.php プロジェクト: shabbirvividads/magento2
 /**
  * Index action
  *
  * @return $this
  */
 public function execute()
 {
     $resultRedirect = $this->resultRedirectFactory->create();
     return $resultRedirect->setPath('/');
 }