public function testGetDefaultRedirect() { $expectedResult = '/index'; $this->redirect->expects($this->once())->method('setRefererOrBaseUrl')->willReturn('/index'); $result = $this->action->getDefaultResult(); $this->assertSame($expectedResult, $result); }
/** * @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(); }
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()); }
/** * 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)); }
/** * 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()); }
/** * 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()); }
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()); }
/** * @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()); }
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()); }
/** * 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()); }
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()); }
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()); }
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(); }
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()); }
/** * @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(); }
/** * @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()); }
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(); }
/** * @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()); }
/** * 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()); }
/** * @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()); } }
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()); }
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()); }
/** * @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()); }