public function testExecute() { $this->menuMock->expects($this->once())->method('getParentItems')->willReturn([$this->menuItemMock]); $this->titleMock->expects($this->atLeastOnce())->method('prepend'); $this->pageConfigMock->expects($this->atLeastOnce())->method('getTitle')->willReturn($this->titleMock); $this->pageMock->expects($this->atLeastOnce())->method('getConfig')->willReturn($this->pageConfigMock); $this->blockMock->expects($this->atLeastOnce())->method('addLink'); $this->blockMock->expects($this->once())->method('setActive'); $this->blockMock->expects($this->once())->method('getMenuModel')->willReturn($this->menuMock); $this->layoutMock->expects($this->atLeastOnce())->method('getBlock')->willReturn($this->blockMock); $this->viewMock->expects($this->once())->method('loadLayout')->willReturnSelf(); $this->viewMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($this->layoutMock); $this->viewMock->expects($this->atLeastOnce())->method('getPage')->willReturn($this->pageMock); $this->action->executeInternal(); }
/** * {@inheritDoc} */ protected function setUp() { $this->requestMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\App\\RequestInterface', ['isDispatched', 'initForward', 'setDispatched', 'isForwarded']); $this->breadcrumbsBlockMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\View\\Element\\BlockInterface', ['addLink']); $this->menuBlockMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\View\\Element\\BlockInterface', ['setActive', 'getMenuModel']); $this->viewMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\App\\ViewInterface'); $this->layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->disableOriginalConstructor()->getMock(); $this->switcherBlockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\BlockInterface')->disableOriginalConstructor()->getMock(); $this->contextMock = $this->getMockBuilder('Magento\\Backend\\App\\Action\\Context')->disableOriginalConstructor()->getMock(); $this->fileFactoryMock = $this->getMockBuilder('Magento\\Framework\\App\\Response\\Http\\FileFactory')->disableOriginalConstructor()->getMock(); $this->menuModelMock = $this->getMockBuilder('Magento\\Backend\\Model\\Menu')->disableOriginalConstructor()->getMock(); $this->abstractBlockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\AbstractBlock')->setMethods(['getCsvFile', 'getExcelFile', 'setSaveParametersInSession', 'getCsv', 'getExcel'])->disableOriginalConstructor()->getMock(); $this->menuModelMock->expects($this->any())->method('getParentItems')->willReturn([]); $this->menuBlockMock->expects($this->any())->method('getMenuModel')->willReturn($this->menuModelMock); $this->viewMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock); $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock); $this->contextMock->expects($this->any())->method('getView')->willReturn($this->viewMock); $this->layoutMock->expects($this->any())->method('getBlock')->will($this->returnValueMap([['breadcrumbs', $this->breadcrumbsBlockMock], ['menu', $this->menuBlockMock], ['store_switcher', $this->switcherBlockMock]])); $this->layoutMock->expects($this->any())->method('getChildBlock')->willReturn($this->abstractBlockMock); }
/** * Set up test * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setUp() { $this->contextMock = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getAuthorization', 'getSession', 'getActionFlag', 'getAuth', 'getView', 'getHelper', 'getBackendUrl', 'getFormKeyValidator', 'getLocaleResolver', 'getCanUseBaseUrl', 'getRequest', 'getResponse', 'getObjectManager', 'getMessageManager'], [], '', false); $this->response = $this->getMock('Magento\\Framework\\App\\ResponseInterface', ['setRedirect', 'sendResponse'], [], '', false); $this->request = $this->getMockForAbstractClass('\\Magento\\Framework\\App\\RequestInterface', ['getParam', 'getRequest'], '', false); $this->view = $this->getMock('\\Magento\\Framework\\App\\ViewInterface', ['loadLayout', 'getPage', 'getConfig', 'getTitle', 'loadLayoutUpdates', 'renderLayout', 'getDefaultLayoutHandle', 'generateLayoutXml', 'addPageLayoutHandles', 'generateLayoutBlocks', 'getLayout', 'addActionLayoutHandles', 'setIsLayoutLoaded', 'isLayoutLoaded'], [], '', false); $this->block = $this->getMock('\\Magento\\Framework\\View\\Element\\AbstractBlock', ['setActive', 'getMenuModel'], [], '', false); $this->layout = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\LayoutInterface', ['getBlock'], '', false); $this->menu = $this->getMock('\\Magento\\Backend\\Model\\Menu', ['getParentItems'], [], '', false); $this->items = $this->getMock('\\Magento\\Backend\\Model\\Menu\\Item', ['getParentItems'], [], '', false); $this->contextMock->expects($this->any())->method("getRequest")->willReturn($this->request); $this->contextMock->expects($this->any())->method("getResponse")->willReturn($this->response); $this->contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->view)); $this->page = $this->getMock('\\Magento\\Framework\\View\\Result\\Page', ['getConfig'], [], '', false); $this->config = $this->getMock('\\Magento\\Framework\\View\\Result\\Page', ['getTitle'], [], '', false); $this->title = $this->getMock('\\Title', ['prepend'], [], '', false); $this->block->expects($this->any())->method('setActive')->will($this->returnValue(1)); $this->view->expects($this->any())->method('getLayout')->will($this->returnValue($this->layout)); $this->layout->expects($this->any())->method('getBlock')->with('menu')->will($this->returnValue($this->block)); $this->block->expects($this->any())->method('getMenuModel')->will($this->returnValue($this->menu)); $this->menu->expects($this->any())->method('getParentItems')->will($this->returnValue($this->items)); $this->object = new \Magento\Indexer\Controller\Adminhtml\Indexer\ListAction($this->contextMock); }
/** * 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()); }