public function testAddPrependTrue() { $this->_model->add('First Title'); $this->_model->add('Second Title', true); $actual = $this->_model->get(); $expected = array('Second Title', 'First Title'); $this->assertEquals($expected, $actual); }
public function testExecute() { $shipmentId = 1000012; $orderId = 10003; $tracking = []; $shipmentData = ['items' => [], 'send_email' => '']; $shipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['load', 'save', 'register', 'getOrder', 'getOrderId', '__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)); $this->session->expects($this->once())->method('getCommentText')->with(true)->will($this->returnValue('')); $this->objectManager->expects($this->atLeastOnce())->method('get')->with('Magento\\Backend\\Model\\Session')->will($this->returnValue($this->session)); $this->view->expects($this->once())->method('loadLayout')->will($this->returnSelf()); $this->view->expects($this->once())->method('renderLayout')->will($this->returnSelf()); $layout = $this->getMock('Magento\\Framework\\View\\Layout\\Element\\Layout', ['getBlock'], [], '', false); $menuBlock = $this->getMock('Magento\\Framework\\View\\Element\\BlockInterface', ['toHtml', 'setActive', 'getMenuModel'], [], '', false); $menuModel = $this->getMockBuilder('Magento\\Backend\\Model\\Menu')->disableOriginalConstructor()->getMock(); $itemId = 'Magento_Sales::sales_order'; $parents = [new \Magento\Framework\Object(['title' => 'title1']), new \Magento\Framework\Object(['title' => 'title2']), new \Magento\Framework\Object(['title' => 'title3'])]; $menuModel->expects($this->once())->method('getParentItems')->with($itemId)->will($this->returnValue($parents)); $menuBlock->expects($this->once())->method('setActive')->with($itemId); $menuBlock->expects($this->once())->method('getMenuModel')->will($this->returnValue($menuModel)); $this->view->expects($this->once())->method('getLayout')->will($this->returnValue($layout)); $layout->expects($this->once())->method('getBlock')->with('menu')->will($this->returnValue($menuBlock)); $this->title->expects($this->any())->method('add')->will($this->returnValueMap(['Shipments', false, $this->title], [$parents[0]->getData('title'), true, $this->title], [$parents[1]->getData('title'), true, $this->title], [$parents[2]->getData('title'), true, $this->title])); $this->assertNull($this->newAction->execute()); }
/** * Run test execute method */ public function testExecute() { $orderId = 1; $shipmentId = 1; $shipment = []; $tracking = []; $incrementId = '10000001'; $comeFrom = true; $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId)); $this->requestMock->expects($this->at(1))->method('getParam')->with('shipment_id')->will($this->returnValue($shipmentId)); $this->requestMock->expects($this->at(2))->method('getParam')->with('shipment')->will($this->returnValue($shipment)); $this->requestMock->expects($this->at(3))->method('getParam')->with('tracking')->will($this->returnValue($tracking)); $this->requestMock->expects($this->at(4))->method('getParam')->with('come_from')->will($this->returnValue($comeFrom)); $this->shipmentLoaderMock->expects($this->once())->method('setOrderId')->with($orderId); $this->shipmentLoaderMock->expects($this->once())->method('setShipmentId')->with($shipmentId); $this->shipmentLoaderMock->expects($this->once())->method('setShipment')->with($shipment); $this->shipmentLoaderMock->expects($this->once())->method('setTracking')->with($tracking); $this->shipmentLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->shipmentMock)); $this->shipmentMock->expects($this->once())->method('getIncrementId')->will($this->returnValue($incrementId)); $this->titleMock->expects($this->at(0))->method('add')->with('Shipments')->will($this->returnSelf()); $this->titleMock->expects($this->at(1))->method('add')->with('#' . $incrementId)->will($this->returnSelf()); $menuBlockMock = $this->getMock('Magento\\Backend\\Block\\Menu', ['getParentItems', 'getMenuModel'], [], '', false); $menuBlockMock->expects($this->any())->method('getMenuModel')->will($this->returnSelf()); $menuBlockMock->expects($this->any())->method('getParentItems')->with('Magento_Sales::sales_order')->will($this->returnValue([])); $shipmentBlockMock = $this->getMock('Magento\\Shipping\\Block\\Adminhtml\\View', ['updateBackButtonUrl'], [], '', false); $layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', ['getBlock'], [], '', false); $shipmentBlockMock->expects($this->once())->method('updateBackButtonUrl')->with($comeFrom)->will($this->returnSelf()); $layoutMock->expects($this->at(0))->method('getBlock')->with('sales_shipment_view')->will($this->returnValue($shipmentBlockMock)); $layoutMock->expects($this->at(1))->method('getBlock')->with('menu')->will($this->returnValue($menuBlockMock)); $this->viewMock->expects($this->once())->method('loadLayout')->will($this->returnSelf()); $this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock)); $this->viewMock->expects($this->once())->method('renderLayout')->will($this->returnSelf()); $this->assertNull($this->controller->execute()); }
public function testExecute() { $carrier = 'carrier'; $number = 'number'; $title = 'title'; $shipmentId = 1000012; $orderId = 10003; $tracking = []; $shipmentData = ['items' => [], 'send_email' => '']; $shipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['addTrack', '__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->request->expects($this->any())->method('getPost')->will($this->returnValueMap([['carrier', $carrier], ['number', $number], ['title', $title]])); $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)); $this->title->expects($this->any())->method('add')->with('Shipments')->will($this->returnSelf()); $track = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Shipment\\Track')->disableOriginalConstructor()->setMethods(['__wakeup', 'setNumber', 'setCarrierCode', 'setTitle'])->getMock(); $this->objectManager->expects($this->atLeastOnce())->method('create')->with('Magento\\Sales\\Model\\Order\\Shipment\\Track')->will($this->returnValue($track)); $track->expects($this->once())->method('setNumber')->with($number)->will($this->returnSelf()); $track->expects($this->once())->method('setCarrierCode')->with($carrier)->will($this->returnSelf()); $track->expects($this->once())->method('setTitle')->with($title)->will($this->returnSelf()); $this->view->expects($this->once())->method('loadLayout')->will($this->returnSelf()); $layout = $this->getMock('Magento\\Framework\\View\\Layout\\Element\\Layout', ['getBlock'], [], '', false); $menuBlock = $this->getMock('Magento\\Framework\\View\\Element\\BlockInterface', ['toHtml'], [], '', false); $html = 'html string'; $this->view->expects($this->once())->method('getLayout')->will($this->returnValue($layout)); $layout->expects($this->once())->method('getBlock')->with('shipment_tracking')->will($this->returnValue($menuBlock)); $menuBlock->expects($this->once())->method('toHtml')->will($this->returnValue($html)); $shipment->expects($this->once())->method('addTrack')->with($this->equalTo($track))->will($this->returnSelf()); $shipment->expects($this->any())->method('save')->will($this->returnSelf()); $this->response->expects($this->once())->method('setBody')->with($html); $this->assertNull($this->controller->execute()); }
/** * Generic payment view action * * @return void */ protected function _viewAction() { try { $payment = $this->_initPayment(); $this->_title->add(__('Recurring Billing Payments')); $this->_title->add(__('Payment #%1', $payment->getReferenceId())); $this->_view->loadLayout(); $this->_view->getLayout()->initMessages(); $this->_view->renderLayout(); return; } catch (\Magento\Framework\Model\Exception $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e); } $this->_redirect('*/*/'); }
/** * Shipment load sections * * @return void */ protected function shipmentLoad() { $orderId = 1; $shipmentId = 1; $trackId = 1; $shipment = []; $tracking = []; $this->shipmentTrackMock->expects($this->once())->method('load')->with($trackId)->will($this->returnSelf()); $this->shipmentTrackMock->expects($this->once())->method('getId')->will($this->returnValue($trackId)); $this->titleMock->expects($this->once())->method('add')->with('Shipments')->will($this->returnSelf()); $this->requestMock->expects($this->at(0))->method('getParam')->with('track_id')->will($this->returnValue($trackId)); $this->requestMock->expects($this->at(1))->method('getParam')->with('order_id')->will($this->returnValue($orderId)); $this->requestMock->expects($this->at(2))->method('getParam')->with('shipment_id')->will($this->returnValue($shipmentId)); $this->requestMock->expects($this->at(3))->method('getParam')->with('shipment')->will($this->returnValue($shipment)); $this->requestMock->expects($this->at(4))->method('getParam')->with('tracking')->will($this->returnValue($tracking)); $this->shipmentLoaderMock->expects($this->once())->method('setOrderId')->with($orderId); $this->shipmentLoaderMock->expects($this->once())->method('setShipmentId')->with($shipmentId); $this->shipmentLoaderMock->expects($this->once())->method('setShipment')->with($shipment); $this->shipmentLoaderMock->expects($this->once())->method('setTracking')->with($tracking); }
/** * Run test execute method (save exception) */ public function testExecuteExceptionSave() { $data = ['comment' => 'comment']; $orderId = 1; $shipmentId = 1; $shipment = []; $tracking = []; $this->requestMock->expects($this->once())->method('setParam')->with('shipment_id', $shipmentId); $this->requestMock->expects($this->once())->method('getPost')->with('comment')->will($this->returnValue($data)); $this->titleMock->expects($this->once())->method('add'); $this->requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap([['id', null, $shipmentId], ['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipment], ['tracking', null, $tracking]])); $this->shipmentLoaderMock->expects($this->once())->method('setOrderId')->with($orderId); $this->shipmentLoaderMock->expects($this->once())->method('setShipmentId')->with($shipmentId); $this->shipmentLoaderMock->expects($this->once())->method('setShipment')->with($shipment); $this->shipmentLoaderMock->expects($this->once())->method('setTracking')->with($tracking); $this->shipmentLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->shipmentMock)); $this->shipmentMock->expects($this->once())->method('addComment'); $this->shipmentSenderMock->expects($this->once())->method('send'); $this->shipmentMock->expects($this->once())->method('save')->will($this->throwException(new \Exception())); $this->exceptionResponse(); $this->assertNull($this->controller->execute()); }
/** * test execute method */ public function testExecute() { $this->requestMock->expects($this->exactly(4))->method('getParam')->will($this->returnValueMap([['order_id', null, 'order_id'], ['creditmemo_id', null, 'creditmemo_id'], ['creditmemo', null, 'creditmemo'], ['invoice_id', null, 'invoice_id']])); $this->creditmemoLoaderMock->expects($this->once())->method('setOrderId')->with($this->equalTo('order_id')); $this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemoId')->with($this->equalTo('creditmemo_id')); $this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemo')->with($this->equalTo('creditmemo')); $this->creditmemoLoaderMock->expects($this->once())->method('setInvoiceId')->with($this->equalTo('invoice_id')); $this->creditmemoLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->creditmemoMock)); $this->creditmemoMock->expects($this->exactly(2))->method('getInvoice')->will($this->returnValue($this->invoiceMock)); $this->invoiceMock->expects($this->once())->method('getIncrementId')->will($this->returnValue('invoice-increment-id')); $this->titleMock->expects($this->exactly(3))->method('add')->will($this->returnValueMap([['Credit Memos', null], ['New Memo for #invoice-increment-id', null], ['item-title', null]])); $this->objectManagerMock->expects($this->once())->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Session'))->will($this->returnValue($this->backendSessionMock)); $this->backendSessionMock->expects($this->once())->method('getCommentText')->with($this->equalTo(true))->will($this->returnValue('comment')); $this->creditmemoMock->expects($this->once())->method('setCommentText')->with($this->equalTo('comment')); $this->viewMock->expects($this->once())->method('loadLayout'); $this->viewMock->expects($this->once())->method('renderLayout'); $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock)); $this->layoutMock->expects($this->once())->method('getBlock')->with($this->equalTo('menu'))->will($this->returnValue($this->blockMenuMock)); $this->blockMenuMock->expects($this->once())->method('setActive')->with($this->equalTo('Magento_Sales::sales_order')); $this->blockMenuMock->expects($this->once())->method('getMenuModel')->will($this->returnValue($this->modelMenuMock)); $this->modelMenuMock->expects($this->once())->method('getParentItems')->will($this->returnValue([$this->modelMenuItem])); $this->modelMenuItem->expects($this->once())->method('getTitle')->will($this->returnValue('item-title')); $this->assertNull($this->controller->execute()); }
/** * Define active menu item in menu block * * @param string $itemId current active menu item * @return $this */ protected function _setActiveMenu($itemId) { /** @var $menuBlock \Magento\Backend\Block\Menu */ $menuBlock = $this->_view->getLayout()->getBlock('menu'); $menuBlock->setActive($itemId); $parents = $menuBlock->getMenuModel()->getParentItems($itemId); $parents = array_reverse($parents); foreach ($parents as $item) { /** @var $item \Magento\Backend\Model\Menu\Item */ $this->_title->add($item->getTitle(), true); } return $this; }