/** * Run test execute method */ public function testExecute() { $orderId = 1; $shipmentId = 1; $shipment = []; $tracking = []; $result = 'result-html'; $layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', ['createBlock'], [], '', false); $gridMock = $this->getMock('Magento\\Shipping\\Block\\Adminhtml\\Order\\Packaging\\Grid', ['setIndex', 'toHtml'], [], '', false); $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->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'); $layoutMock->expects($this->once())->method('createBlock')->with('Magento\\Shipping\\Block\\Adminhtml\\Order\\Packaging\\Grid')->will($this->returnValue($gridMock)); $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($layoutMock)); $this->responseMock->expects($this->once())->method('setBody')->with($result)->will($this->returnSelf()); $this->requestMock->expects($this->at(4))->method('getParam')->with('index'); $gridMock->expects($this->once())->method('setIndex')->will($this->returnSelf()); $gridMock->expects($this->once())->method('toHtml')->will($this->returnValue($result)); $this->assertNotEmpty('result-html', $this->controller->execute()); }
/** * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setUp() { $this->registryMock = $this->getMockBuilder('Magento\\Framework\\Registry')->disableOriginalConstructor()->setMethods(['registry', 'register'])->getMock(); $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock(); $this->viewMock = $this->getMockBuilder('Magento\\Framework\\App\\View')->disableOriginalConstructor()->setMethods(['loadLayout', 'getLayout', 'getPage', 'renderLayout'])->getMock(); $this->layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods(['getBlock', 'createBlock', 'setChild'])->getMock(); $this->menuBlockMock = $this->getMockBuilder('\\Magento\\Backend\\Block\\Menu')->disableOriginalConstructor()->setMethods(['setActive', 'getMenuModel', 'getParentItems'])->getMock(); $this->breadcrumbsBlockMock = $this->getMockBuilder('\\Magento\\Backend\\Block\\Widget\\Breadcrumbs')->disableOriginalConstructor()->setMethods(['addLink'])->getMock(); $this->editBlockMock = $this->getMockBuilder('\\Magento\\Backend\\Block\\Widget\\Breadcrumbs')->disableOriginalConstructor()->setMethods(['setEditMode'])->getMock(); $this->resultPageMock = $this->getMockBuilder('Magento\\Framework\\View\\Result\\Page')->disableOriginalConstructor()->setMethods(['setActiveMenu', 'getConfig', 'addBreadcrumb'])->getMock(); $this->pageConfigMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock(); $this->pageTitleMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock(); $this->viewMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($this->layoutMock); $this->layoutMock->expects($this->any())->method('getBlock')->willReturnMap([['menu', $this->menuBlockMock], ['breadcrumbs', $this->breadcrumbsBlockMock], ['edit', $this->editBlockMock]]); $this->menuBlockMock->expects($this->any())->method('getMenuModel')->will($this->returnSelf()); $this->menuBlockMock->expects($this->any())->method('getParentItems')->will($this->returnValue([])); $this->viewMock->expects($this->any())->method('getPage')->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->any())->method('getTitle')->willReturn($this->pageTitleMock); $this->layoutMock->expects($this->once())->method('createBlock')->with('Magento\\Email\\Block\\Adminhtml\\Template\\Edit', 'template_edit', [])->willReturn($this->editBlockMock); $this->editBlockMock->expects($this->once())->method('setEditMode')->willReturnSelf(); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $templateMock = $this->getMockBuilder('Magento\\Email\\Model\\Template')->disableOriginalConstructor()->getMock(); $templateMock->expects($this->once())->method('getId')->willReturn(1); $templateMock->expects($this->any())->method('getTemplateCode')->willReturn('My Template'); $objectManagerMock = $this->getMockBuilder('Magento\\Framework\\App\\ObjectManager')->disableOriginalConstructor()->getMock(); $objectManagerMock->expects($this->once())->method('create')->with('Magento\\Email\\Model\\BackendTemplate')->willReturn($templateMock); $this->context = $objectManager->getObject('Magento\\Backend\\App\\Action\\Context', ['request' => $this->requestMock, 'objectManager' => $objectManagerMock, 'view' => $this->viewMock]); $this->editController = $objectManager->getObject('Magento\\Email\\Controller\\Adminhtml\\Email\\Template\\Edit', ['context' => $this->context, 'coreRegistry' => $this->registryMock]); }
public function testExecuteInternal() { $this->viewMock->expects($this->once())->method('getPage')->willReturn($this->pageMock); $this->pageMock->expects($this->once())->method('getConfig')->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->once())->method('getTitle')->willReturn($this->pageTitleMock); $this->pageTitleMock->expects($this->once())->method('prepend')->willReturnSelf(); $this->assertNull($this->object->executeInternal()); }
protected function prepareMocks() { $this->contextMock = $this->getMock('Magento\\Framework\\App\\Helper\\Context', [], [], '', false); $this->viewMock = $this->getMock('Magento\\Framework\\App\\View', ['getLayout'], ['getPageLayoutHandles'], '', false); $layoutMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', array(), '', false, true, true, array('getUpdate')); $this->updateLayoutMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Layout\\ProcessorInterface', array(), '', false, true, true, array()); $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($layoutMock)); $layoutMock->expects($this->once())->method('getUpdate')->will($this->returnValue($this->updateLayoutMock)); $this->helper = new Data($this->contextMock, $this->viewMock); }
public function testExecutePassed() { $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false); $layout = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false); $layout->expects($this->once())->method('initMessages')->willReturn(true); $this->wishlistProvider->expects($this->once())->method('getWishlist')->willReturn($wishlist); $this->view->expects($this->once())->method('loadLayout')->willReturn(true); $this->view->expects($this->once())->method('getLayout')->willReturn($layout); $this->view->expects($this->once())->method('renderLayout')->willReturn(true); $this->getController()->execute(); }
/** * @covers \Magento\Email\Controller\Adminhtml\Email\Template\Index::execute */ public function testExecute() { $this->prepareExecute(); $this->viewMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($this->layoutMock); $this->layoutMock->expects($this->at(0))->method('getBlock')->with('menu')->will($this->returnValue($this->menuBlockMock)); $this->menuBlockMock->expects($this->any())->method('getMenuModel')->will($this->returnSelf()); $this->menuBlockMock->expects($this->any())->method('getParentItems')->will($this->returnValue([])); $this->viewMock->expects($this->once())->method('getPage')->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->once())->method('getConfig')->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->once())->method('getTitle')->willReturn($this->pageTitleMock); $this->pageTitleMock->expects($this->once())->method('prepend')->with('Email Templates'); $this->layoutMock->expects($this->at(1))->method('getBlock')->with('breadcrumbs')->will($this->returnValue($this->breadcrumbsBlockMock)); $this->breadcrumbsBlockMock->expects($this->any())->method('addLink')->willReturnSelf(); $this->assertNull($this->indexController->execute()); }
public function testRenderLayoutWhenOutputEmpty() { $this->_actionFlagMock->expects($this->once())->method('get')->with('', 'no-renderLayout')->will($this->returnValue(false)); $this->_layoutMock->expects($this->never())->method('addOutputElement'); $this->resultPage->expects($this->once())->method('renderResult')->with($this->response); $this->_view->renderLayout(); }
private function initLayoutMock() { $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock)); $this->viewMock->expects($this->once())->method('loadLayout')->willReturnSelf(); $this->viewMock->expects($this->once())->method('renderLayout')->willReturnSelf(); $this->layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($this->blockMock)); }
public function testExecute() { $blocks = ['block1', 'block2']; $handles = ['handle1', 'handle2']; $originalRequest = '{"route":"route","controller":"controller","action":"action","uri":"uri"}'; $expectedData = ['block1' => 'data1', 'block2' => 'data2']; $blockInstance1 = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false); $blockInstance1->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block1'])); $blockInstance2 = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false); $blockInstance2->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block2'])); $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true)); $this->requestMock->expects($this->at(1))->method('getRouteName')->will($this->returnValue('magento_pagecache')); $this->requestMock->expects($this->at(2))->method('getControllerName')->will($this->returnValue('block')); $this->requestMock->expects($this->at(3))->method('getActionName')->will($this->returnValue('render')); $this->requestMock->expects($this->at(4))->method('getRequestUri')->will($this->returnValue('uri')); $this->requestMock->expects($this->at(5))->method('getParam')->with($this->equalTo('originalRequest'))->will($this->returnValue($originalRequest)); $this->requestMock->expects($this->at(10))->method('getParam')->with($this->equalTo('blocks'), $this->equalTo(''))->will($this->returnValue(json_encode($blocks))); $this->requestMock->expects($this->at(11))->method('getParam')->with($this->equalTo('handles'), $this->equalTo(''))->will($this->returnValue(json_encode($handles))); $this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles)); $this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock)); $this->layoutMock->expects($this->at(0))->method('getBlock')->with($this->equalTo($blocks[0]))->will($this->returnValue($blockInstance1)); $this->layoutMock->expects($this->at(1))->method('getBlock')->with($this->equalTo($blocks[1]))->will($this->returnValue($blockInstance2)); $this->translateInline->expects($this->once())->method('processResponseBody')->with($expectedData)->willReturnSelf(); $this->responseMock->expects($this->once())->method('appendBody')->with($this->equalTo(json_encode($expectedData))); $this->action->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)); $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 testExecuteBlockNotExists() { $handles = json_encode(['handle1', 'handle2']); $mapData = [['blocks', '', null], ['handles', '', $handles]]; $this->requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap($mapData)); $this->viewMock->expects($this->never())->method('getLayout')->will($this->returnValue($this->layoutMock)); $this->action->execute(); }
/** * {@inheritdoc} */ public function loadLayout($handles = null, $generateBlocks = true, $generateXml = true, $addActionHandles = true) { parent::loadLayout($handles, false, $generateXml, $addActionHandles); $this->_aclFilter->filterAclNodes($this->getLayout()->getNode()); if ($generateBlocks) { $this->generateLayoutBlocks(); $this->_isLayoutLoaded = true; } $this->getLayout()->initMessages(); return $this; }
public function testExecute() { $blocks = ['block1', 'block2']; $handles = ['handle1', 'handle2']; $expectedData = ['block1' => 'data1', 'block2' => 'data2']; $blockInstance1 = $this->getMock('Magento\\PageCache\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false); $blockInstance1->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block1'])); $blockInstance2 = $this->getMock('Magento\\PageCache\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false); $blockInstance2->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block2'])); $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true)); $this->requestMock->expects($this->at(1))->method('getParam')->with($this->equalTo('blocks'), $this->equalTo(''))->will($this->returnValue(json_encode($blocks))); $this->requestMock->expects($this->at(2))->method('getParam')->with($this->equalTo('handles'), $this->equalTo(''))->will($this->returnValue(json_encode($handles))); $this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles)); $this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock)); $this->layoutMock->expects($this->at(0))->method('getBlock')->with($this->equalTo($blocks[0]))->will($this->returnValue($blockInstance1)); $this->layoutMock->expects($this->at(1))->method('getBlock')->with($this->equalTo($blocks[1]))->will($this->returnValue($blockInstance2)); $this->translateInline->expects($this->once())->method('processResponseBody')->with($expectedData)->willReturnSelf(); $this->responseMock->expects($this->once())->method('appendBody')->with($this->equalTo(json_encode($expectedData))); $this->action->execute(); }
/** * Run test execute method */ public function testExecute() { $response = 'html-data'; $this->shipmentLoad(); $this->shipmentLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->shipmentMock)); $this->shipmentTrackMock->expects($this->once())->method('delete')->will($this->returnSelf()); $layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', ['getBlock'], [], '', false); $trackingBlockMock = $this->getMock('Magento\\Shipping\\Block\\Adminhtml\\Order\\Tracking', ['toHtml'], [], '', false); $trackingBlockMock->expects($this->once())->method('toHtml')->will($this->returnValue($response)); $layoutMock->expects($this->once())->method('getBlock')->with('shipment_tracking')->will($this->returnValue($trackingBlockMock)); $this->viewMock->expects($this->once())->method('loadLayout')->will($this->returnSelf()); $this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock)); $this->responseMock->expects($this->once())->method('setBody')->with($response); $this->assertNull($this->controller->execute()); }
/** * @param $state * @param $restoreQuote * @param $expectedGotoSection * @dataProvider testNotAllowedOrderStateDataProvider */ public function testExecuteNotAllowedOrderState($state, $restoreQuote, $expectedGotoSection) { $lastRealOrderId = '000000001'; $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock)); $this->layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($this->blockMock)); $this->checkoutSessionMock->expects($this->any())->method('getLastRealOrderId')->will($this->returnValue($lastRealOrderId)); $this->checkoutSessionMock->expects($this->any())->method('getLastRealOrder')->will($this->returnValue($this->orderMock)); $this->checkoutSessionMock->expects($this->any())->method('restoreQuote')->will($this->returnValue($restoreQuote)); $this->orderFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->orderMock)); $this->orderMock->expects($this->once())->method('loadByIncrementId')->with($lastRealOrderId)->will($this->returnSelf()); $this->orderMock->expects($this->once())->method('getIncrementId')->will($this->returnValue($lastRealOrderId)); $this->orderMock->expects($this->once())->method('getState')->will($this->returnValue($state)); $this->blockMock->expects($this->at(0))->method('setData')->with('goto_section', $expectedGotoSection)->will($this->returnSelf()); $this->blockMock->expects($this->at(1))->method('setData')->with('error_msg', __('Your payment has been declined. Please try again.'))->will($this->returnSelf()); $this->returnUrl->execute(); }
/** * Get handles applied for current page * * @return array */ public function getActualHandles() { return $this->view->getLayout()->getUpdate()->getHandles(); }