/** * Set Cookie for msg box when it displays first * * @param \Magento\Framework\App\FrontController $subject * @param \Magento\Framework\App\ResponseInterface $response * * @return \Magento\Framework\App\ResponseInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterDispatch(\Magento\Framework\App\FrontController $subject, \Magento\Framework\App\ResponseInterface $response) { if ($this->request->isPost() && $this->messageManager->hasMessages()) { $this->cookie->set(self::COOKIE_NAME, 1, self::COOKIE_PERIOD, '/'); } return $response; }
public function testExecuteNotPost() { $this->validatorMock->expects($this->once())->method('validate')->willReturn(false); $this->request->expects($this->once())->method('isPost')->willReturn(false); $this->messageManager->expects($this->once())->method('addError')->with('You have not canceled the item.'); $this->resultRedirect->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf(); $this->assertEquals($this->resultRedirect, $this->controller->execute()); }
/** * Set Cookie for msg box when it displays first * * @param FrontController $subject * @param \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface $result * * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterDispatch(FrontController $subject, $result) { if ($this->request->isPost() && $this->messageManager->hasMessages()) { $publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()->setDuration(self::COOKIE_PERIOD)->setPath('/')->setHttpOnly(false); $this->cookieManager->setPublicCookie(self::COOKIE_NAME, 1, $publicCookieMetadata); } return $result; }
public function testExecute() { $path = '*/*'; $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect); $this->messageManager->expects($this->once())->method('addSuccess')->with(__('We updated lifetime statistic.')); $this->objectManager->expects($this->any())->method('create')->with('Magento\\Sales\\Model\\Resource\\Report\\Order')->willReturn($this->order); $this->resultRedirect->expects($this->once())->method('setPath')->with($path)->willReturnSelf(); $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Redirect', $this->refreshStatisticsController->execute()); }
/** * @param bool $isPost * @param int $numOfCalls * @dataProvider afterDispatchTestDataProvider */ public function testAfterDispatch($isPost, $numOfCalls) { $this->messageManagerMock->expects($this->exactly($numOfCalls))->method('hasMessages')->will($this->returnValue(true)); $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost)); $this->cookieMetadataFactoryMock->expects($this->exactly($numOfCalls))->method('createPublicCookieMetadata')->will($this->returnValue($this->publicCookieMetadataMock)); $this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setDuration')->with(MessageBox::COOKIE_PERIOD)->will($this->returnValue($this->publicCookieMetadataMock)); $this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setPath')->with('/')->will($this->returnValue($this->publicCookieMetadataMock)); $this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setHttpOnly')->with(false)->will($this->returnValue($this->publicCookieMetadataMock)); $this->cookieManagerMock->expects($this->exactly($numOfCalls))->method('setPublicCookie')->with(MessageBox::COOKIE_NAME, 1, $this->publicCookieMetadataMock); $this->assertSame($this->responseMock, $this->msgBox->afterDispatch($this->objectMock, $this->responseMock)); }
/** * Run test execute method (fail load shipment model) */ public function testExecuteLoadShipmentFail() { $this->shipmentLoaderMock->expects($this->once())->method('load')->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('message'))); $this->messageManagerMock->expects($this->once())->method('addError')->will($this->returnSelf()); $this->redirectSection(); $this->assertNull($this->controller->execute()); }
public function testEmail() { $cmId = 10000031; $cmManagement = 'Magento\Sales\Api\CreditmemoManagementInterface'; $cmManagementMock = $this->getMock($cmManagement, [], [], '', false); $this->prepareRedirect($cmId); $this->request->expects($this->once()) ->method('getParam') ->with('creditmemo_id') ->willReturn($cmId); $this->objectManager->expects($this->once()) ->method('create') ->with($cmManagement) ->willReturn($cmManagementMock); $cmManagementMock->expects($this->once()) ->method('notify') ->willReturn(true); $this->messageManager->expects($this->once()) ->method('addSuccess') ->with('You sent the message.'); $this->assertInstanceOf( 'Magento\Backend\Model\View\Result\Redirect', $this->creditmemoEmail->executeInternal() ); $this->assertEquals($this->response, $this->creditmemoEmail->getResponse()); }
/** * @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 testEmail() { $shipmentId = 1000012; $orderId = 10003; $tracking = []; $shipment = ['items' => []]; $orderShipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['load', 'save', '__wakeup'], [], '', false); $shipmentNotifierClassName = 'Magento\\Shipping\\Model\\ShipmentNotifier'; $shipmentNotifier = $this->getMock($shipmentNotifierClassName, ['notify', '__wakeup'], [], '', false); $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipment], ['tracking', null, $tracking]])); $this->shipmentLoader->expects($this->once())->method('setShipmentId')->with($shipmentId); $this->shipmentLoader->expects($this->once())->method('setOrderId')->with($orderId); $this->shipmentLoader->expects($this->once())->method('setShipment')->with($shipment); $this->shipmentLoader->expects($this->once())->method('setTracking')->with($tracking); $this->shipmentLoader->expects($this->once())->method('load')->will($this->returnValue($orderShipment)); $orderShipment->expects($this->once())->method('save')->will($this->returnSelf()); $this->objectManager->expects($this->once())->method('create')->with($shipmentNotifierClassName)->will($this->returnValue($shipmentNotifier)); $shipmentNotifier->expects($this->once())->method('notify')->with($orderShipment)->will($this->returnValue(true)); $this->messageManager->expects($this->once())->method('addSuccess')->with('You sent the shipment.'); $path = '*/*/view'; $arguments = ['shipment_id' => $shipmentId]; $this->prepareRedirect($path, $arguments, 0); $this->shipmentEmail->execute(); $this->assertEquals($this->response, $this->shipmentEmail->getResponse()); }
/** * 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 testEmailNoOrderId() { $this->request->expects($this->once()) ->method('getParam') ->with('order_id') ->will($this->returnValue(null)); $this->orderRepositoryMock->expects($this->once()) ->method('get') ->with(null) ->willThrowException( new \Magento\Framework\Exception\NoSuchEntityException(__('Requested entity doesn\'t exist')) ); $this->messageManager->expects($this->once()) ->method('addError') ->with('This order no longer exists.'); $this->actionFlag->expects($this->once()) ->method('set') ->with('', 'no-dispatch', true) ->will($this->returnValue(true)); $this->resultRedirect->expects($this->once()) ->method('setPath') ->with('sales/*/') ->willReturnSelf(); $this->assertInstanceOf( 'Magento\Backend\Model\View\Result\Redirect', $this->orderEmail->executeInternal() ); }
public function testAddMessages() { $messageCollection = $this->getMock('Magento\\Framework\\Message\\Collection', ['getItems', 'addMessage'], [], '', false); $this->session->expects($this->any())->method('getData')->will($this->returnValue($messageCollection)); $this->eventManager->expects($this->once())->method('dispatch')->with('session_abstract_add_message'); $messageCollection->expects($this->once())->method('addMessage')->with($this->messageMock); $this->model->addMessages([$this->messageMock]); }
public function testExecuteWithException() { $customersIds = [10, 11, 12]; $this->customerCollectionMock->expects($this->any())->method('getAllIds')->willReturn($customersIds); $this->customerRepositoryMock->expects($this->any())->method('getById')->willThrowException(new \Exception('Some message.')); $this->messageManagerMock->expects($this->once())->method('addError')->with('Some message.'); $this->massAction->execute(); }
public function testExecuteUpdateAction() { $orderId = 30; $action = 'update'; $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->willReturn($orderId); $this->requestMock->expects($this->at(1))->method('getParam')->with('action')->willReturn($action); $this->resultRedirectFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRedirectMock); $this->orderRepositoryMock->expects($this->once())->method('get')->with($orderId)->willReturn($this->orderMock); $this->orderMock->expects($this->any())->method('getEntityId')->willReturn($orderId); $this->orderMock->expects($this->any())->method('getPayment')->willReturn($this->paymentMock); $this->orderRepositoryMock->expects($this->once())->method('save')->with($this->orderMock)->willReturnSelf(); $this->paymentMock->expects($this->once())->method('update'); $this->paymentMock->expects($this->any())->method('getIsTransactionApproved')->willReturn(true); $this->messageManagerMock->expects($this->once())->method('addSuccess'); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/order/view')->willReturnSelf(); $result = $this->reviewPayment->execute(); $this->assertEquals($this->resultRedirectMock, $result); }
public function testExecuteUpdateAction() { $orderId = 30; $action = 'update'; $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->willReturn($orderId); $this->requestMock->expects($this->at(1))->method('getParam')->with('action')->willReturn($action); $this->resultRedirectFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRedirectMock); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Sales\\Model\\Order')->willReturn($this->orderMock); $this->orderMock->expects($this->once())->method('load')->with($orderId)->willReturn($this->orderMock); $this->orderMock->expects($this->any())->method('getId')->willReturn($orderId); $this->orderMock->expects($this->once())->method('getPayment')->willReturn($this->paymentMock); $this->orderMock->expects($this->once())->method('save')->willReturnSelf(); $this->messageManagerMock->expects($this->once())->method('addSuccess')->with('The payment update has been made.'); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf(); $this->paymentMock->expects($this->once())->method('update'); $result = $this->reviewPayment->execute(); $this->assertEquals($this->resultRedirectMock, $result); }
/** * Run test execute method */ public function testExecute() { $this->shipmentLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->shipmentMock)); $this->labelGenerator->expects($this->once())->method('create')->with($this->shipmentMock, $this->requestMock)->will($this->returnValue(true)); $this->shipmentMock->expects($this->once())->method('save')->will($this->returnSelf()); $this->messageManagerMock->expects($this->once())->method('addSuccess'); $this->responseMock->expects($this->once())->method('representJson'); $this->assertNull($this->controller->execute()); }
/** * Order throws exception while canceling */ public function testException() { $exception = new \Exception('Can not cancel'); $order1 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $this->orderCollectionMock->expects($this->any())->method('getItems')->willReturn([$order1]); $order1->expects($this->once())->method('canCancel')->willReturn(true); $order1->expects($this->once())->method('cancel')->willThrowException($exception); $this->messageManagerMock->expects($this->once())->method('addError')->with('Can not cancel'); $this->massAction->execute(); }
public function testEmail() { $invoiceId = 10000031; $orderId = 100000030; $invoiceClassName = 'Magento\Sales\Model\Order\Invoice'; $cmNotifierClassName = 'Magento\Sales\Api\InvoiceManagementInterface'; $invoice = $this->getMock($invoiceClassName, [], [], '', false); $invoice->expects($this->once()) ->method('getEntityId') ->willReturn($invoiceId); $order = $this->getMock('Magento\Sales\Model\Order', [], [], '', false); $order->expects($this->once()) ->method('getId') ->willReturn($orderId); $this->request->expects($this->once()) ->method('getParam') ->with('invoice_id') ->willReturn($invoiceId); $invoiceRepository = $this->getMockBuilder('Magento\Sales\Api\InvoiceRepositoryInterface') ->disableOriginalConstructor() ->getMock(); $invoiceRepository->expects($this->any()) ->method('get') ->willReturn($invoice); $this->objectManager->expects($this->at(0)) ->method('create') ->with('Magento\Sales\Api\InvoiceRepositoryInterface') ->willReturn($invoiceRepository); $invoice->expects($this->once()) ->method('getOrder') ->willReturn($order); $this->objectManager->expects($this->at(1)) ->method('create') ->with($cmNotifierClassName) ->willReturn($this->invoiceManagement); $this->invoiceManagement->expects($this->once()) ->method('notify') ->with($invoiceId) ->willReturn(true); $this->messageManager->expects($this->once()) ->method('addSuccess') ->with('You sent the message.'); $this->resultRedirectFactory->expects($this->atLeastOnce()) ->method('create') ->willReturn($this->resultRedirect); $this->resultRedirect->expects($this->once()) ->method('setPath') ->with('sales/invoice/view', ['order_id' => $orderId, 'invoice_id' => $invoiceId]) ->willReturnSelf(); $this->assertInstanceOf('Magento\Backend\Model\View\Result\Redirect', $this->invoiceEmail->executeInternal()); }
public function testEmailNoOrderId() { $orderClassName = 'Magento\\Sales\\Model\\Order'; $order = $this->getMock($orderClassName, ['load', 'getId', '__wakeup'], [], '', false); $this->request->expects($this->once())->method('getParam')->with('order_id')->will($this->returnValue(null)); $this->objectManager->expects($this->at(0))->method('create')->with($orderClassName)->will($this->returnValue($order)); $order->expects($this->once())->method('load')->with(null)->will($this->returnSelf()); $this->messageManager->expects($this->once())->method('addError')->with('This order no longer exists.'); $this->actionFlag->expects($this->once())->method('set')->with('', 'no-dispatch', true)->will($this->returnValue(true)); $this->resultRedirect->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf(); $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Redirect', $this->orderEmail->execute()); }
public function testExecuteNoReleasedOrderFromHold() { $order1 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $order2 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $orders = [$order1, $order2]; $this->orderCollectionMock->expects($this->any())->method('getItems')->willReturn($orders); $order1->expects($this->once())->method('canUnhold')->willReturn(false); $this->orderCollectionMock->expects($this->once())->method('count')->willReturn(count($orders)); $order2->expects($this->once())->method('canUnhold')->willReturn(false); $this->messageManagerMock->expects($this->once())->method('addError')->with('No order(s) were released from on hold status.'); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf(); $this->massAction->execute(); }
/** * @magentoAppIsolation enabled */ public function testAddError() { $customGroup = 'custom-group'; $this->model->addError('some text'); $this->model->addError('some text 2', $customGroup); $this->assertEquals(1, $this->model->getMessages()->getCount()); $this->assertEquals(1, $this->model->getMessages()->getCountByType(MessageInterface::TYPE_ERROR)); $this->assertEquals(0, $this->model->getMessages()->getCountByType(MessageInterface::TYPE_WARNING)); $this->assertEquals(0, $this->model->getMessages()->getCountByType(MessageInterface::TYPE_NOTICE)); $this->assertEquals(0, $this->model->getMessages()->getCountByType(MessageInterface::TYPE_SUCCESS)); $this->assertEquals('some text', $this->model->getMessages()->getLastAddedMessage()->getText()); $this->assertEquals(1, $this->model->getMessages(false, $customGroup)->getCount()); $this->assertEquals('some text 2', $this->model->getMessages(false, $customGroup)->getLastAddedMessage()->getText()); }
/** * Order throws exception while canceling */ public function testException() { $selected = [1]; $exception = new \Exception('Can not cancel'); $order1 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $this->requestMock->expects($this->at(0))->method('getParam')->with('selected')->willReturn($selected); $this->requestMock->expects($this->at(1))->method('getParam')->with('excluded')->willReturn([]); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Sales\\Model\\Resource\\Order\\Grid\\Collection')->willReturn($this->orderCollectionMock); $this->orderCollectionMock->expects($this->once())->method('addFieldToFilter')->with(\Magento\Sales\Controller\Adminhtml\Order\MassCancel::ID_FIELD, ['in' => $selected]); $this->orderCollectionMock->expects($this->any())->method('getItems')->willReturn([$order1]); $order1->expects($this->once())->method('canCancel')->willReturn(true); $order1->expects($this->once())->method('cancel')->willThrowException($exception); $this->messageManagerMock->expects($this->once())->method('addError')->with('Can not cancel'); $this->massAction->execute(); }
public function testEmail() { $cmId = 10000031; $creditmemoClassName = 'Magento\\Sales\\Model\\Order\\Creditmemo'; $cmNotifierClassName = 'Magento\\Sales\\Model\\Order\\CreditmemoNotifier'; $creditmemo = $this->getMock($creditmemoClassName, ['load', '__wakeup'], [], '', false); $cmNotifier = $this->getMock($cmNotifierClassName, ['notify', '__wakeup'], [], '', false); $this->request->expects($this->once())->method('getParam')->with('creditmemo_id')->will($this->returnValue($cmId)); $this->objectManager->expects($this->at(0))->method('create')->with($creditmemoClassName)->will($this->returnValue($creditmemo)); $creditmemo->expects($this->once())->method('load')->with($cmId)->will($this->returnSelf()); $this->objectManager->expects($this->at(1))->method('create')->with($cmNotifierClassName)->will($this->returnValue($cmNotifier)); $cmNotifier->expects($this->once())->method('notify')->will($this->returnValue(true)); $this->messageManager->expects($this->once())->method('addSuccess')->with('We sent the message.'); $this->prepareRedirect($cmId); $this->creditmemoEmail->execute(); $this->assertEquals($this->response, $this->creditmemoEmail->getResponse()); }
protected function checkSalesRuleAvailability($attributeCode) { $collection = $this->getMock('Magento\\SalesRule\\Model\\Resource\\Rule\\Collection', ['addAttributeInConditionFilter', '__wakeup'], [], '', false); $rule = $this->getMock('Magento\\SalesRule\\Model\\Rule', ['setIsActive', 'getConditions', 'getActions', 'save', '__wakeup'], [], '', false); $combine = $this->getMock('Magento\\Rule\\Model\\Condition\\Combine', ['getConditions', 'setConditions', '__wakeup'], [], '', false); $combineProduct = $this->getMock('Magento\\SalesRule\\Model\\Rule\\Condition\\Product', ['getAttribute', 'setConditions', '__wakeup'], [], '', false); $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($collection)); $collection->expects($this->once())->method('addAttributeInConditionFilter')->with($attributeCode)->will($this->returnValue([$rule])); $rule->expects($this->once())->method('setIsActive')->with(0); $rule->expects($this->once())->method('getConditions')->will($this->returnValue($combine)); $rule->expects($this->once())->method('getActions')->will($this->returnValue($combine)); $combine->expects($this->at(0))->method('getConditions')->will($this->returnValue([$combine])); $combine->expects($this->at(1))->method('getConditions')->will($this->returnValue([$combineProduct])); $combine->expects($this->at(4))->method('getConditions')->will($this->returnValue([])); $combineProduct->expects($this->once())->method('getAttribute')->will($this->returnValue($attributeCode)); $combine->expects($this->any())->method('setConditions')->will($this->returnValueMap([[[], null], [[$combine], null], [[], null]])); $this->messageManager->expects($this->once())->method('addWarning')->with(sprintf('1 Shopping Cart Price Rules based on "%s" attribute have been disabled.', $attributeCode)); }
public function testExecuteNotPost() { $this->validatorMock->expects($this->once()) ->method('validate') ->willReturn(false); $this->request->expects($this->once()) ->method('isPost') ->willReturn(false); $this->messageManager->expects($this->once()) ->method('addError') ->with('Can\'t unhold order.'); $this->resultRedirect->expects($this->once()) ->method('setPath') ->with('sales/*/') ->willReturnSelf(); $this->assertEquals($this->resultRedirect, $this->controller->executeInternal()); }
public function testExecuteOneOrderCannotBePutOnHold() { $excluded = [1, 2]; $countOrders = count($excluded); $order1 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $order2 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $this->requestMock->expects($this->at(0))->method('getParam')->with('selected')->willReturn([]); $this->requestMock->expects($this->at(1))->method('getParam')->with('excluded')->willReturn($excluded); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Sales\\Model\\Resource\\Order\\Grid\\Collection')->willReturn($this->orderCollectionMock); $this->orderCollectionMock->expects($this->once())->method('addFieldToFilter')->with(\Magento\Sales\Controller\Adminhtml\Order\MassCancel::ID_FIELD, ['nin' => $excluded]); $this->orderCollectionMock->expects($this->any())->method('getItems')->willReturn([$order1, $order2]); $order1->expects($this->once())->method('canHold')->willReturn(false); $this->orderCollectionMock->expects($this->once())->method('count')->willReturn($countOrders); $order2->expects($this->once())->method('canHold')->willReturn(false); $this->messageManagerMock->expects($this->once())->method('addError')->with('No order(s) were put on hold.'); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf(); $this->massAction->execute(); }
/** * @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 testEmail() { $invoiceId = 10000031; $orderId = 100000030; $invoiceClassName = 'Magento\\Sales\\Model\\Order\\Invoice'; $cmNotifierClassName = 'Magento\\Sales\\Model\\Order\\InvoiceNotifier'; $invoice = $this->getMock($invoiceClassName, [], [], '', false); $notifier = $this->getMock($cmNotifierClassName, [], [], '', false); $order = $this->getMock('Magento\\Sales\\Model\\Order', [], [], '', false); $order->expects($this->once())->method('getId')->willReturn($orderId); $this->request->expects($this->once())->method('getParam')->with('invoice_id')->willReturn($invoiceId); $this->objectManager->expects($this->at(0))->method('create')->with($invoiceClassName)->willReturn($invoice); $invoice->expects($this->once())->method('load')->with($invoiceId)->willReturnSelf(); $invoice->expects($this->once())->method('getOrder')->willReturn($order); $this->objectManager->expects($this->at(1))->method('create')->with($cmNotifierClassName)->willReturn($notifier); $notifier->expects($this->once())->method('notify')->willReturn(true); $this->messageManager->expects($this->once())->method('addSuccess')->with('We sent the message.'); $this->resultRedirectFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->resultRedirect); $this->resultRedirect->expects($this->once())->method('setPath')->with('sales/invoice/view', ['order_id' => $orderId, 'invoice_id' => $invoiceId])->willReturnSelf(); $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Redirect', $this->invoiceEmail->execute()); }
public function testExecuteNoOrdersPutOnHold() { $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); $order2 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); $orders = [$order1, $order2]; $countOrders = count($orders); $this->orderCollectionMock->expects($this->any()) ->method('getItems') ->willReturn($orders); $order1->expects($this->once()) ->method('canHold') ->willReturn(false); $this->orderCollectionMock->expects($this->once()) ->method('count') ->willReturn($countOrders); $order2->expects($this->once()) ->method('canHold') ->willReturn(false); $this->messageManagerMock->expects($this->once()) ->method('addError') ->with('No order(s) were put on hold.'); $this->resultRedirectMock->expects($this->once()) ->method('setPath') ->with('sales/*/') ->willReturnSelf(); $this->massAction->executeInternal(); }
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('An error occurred while deleting the item from wish list.')->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->response->expects($this->once())->method('setRedirect')->with('http:/test.com/frontname/module/controller/action')->willReturn(true); $this->getController()->execute(); }