public function testExecute() { $page = 'SamplePageObjectHere'; $this->resultPageFactory->expects($this->once())->method('create')->willReturn($page); $result = $this->controller->execute(); $this->assertEquals($page, $result); }
/** * @return void */ public function testExecuteOrderLoaded() { $this->guestHelperMock->expects($this->once())->method('loadValidOrder')->with($this->requestMock)->willReturn(true); $this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($this->resultPageMock); $this->guestHelperMock->expects($this->once())->method('getBreadcrumbs')->with($this->resultPageMock); $this->assertSame($this->resultPageMock, $this->viewController->execute()); }
/** * @return void */ public function testCreateActionRegistrationEnabled() { $this->customerSession->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false)); $this->registrationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true)); $this->redirectMock->expects($this->never())->method('redirect'); $this->pageFactoryMock->expects($this->once())->method('create')->willReturn($this->resultPageMock); $this->object->execute(); }
/** * @return void */ public function testCreateActionRegistrationEnabled() { $this->customerSession->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false)); $this->registrationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true)); $this->redirectMock->expects($this->never())->method('redirect'); $layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false); $layoutMock->expects($this->once())->method('initMessages')->willReturnSelf(); $this->pageFactoryMock->expects($this->once())->method('create')->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->once())->method('getLayout')->will($this->returnValue($layoutMock)); $this->object->execute(); }
/** * @covers \Magento\Customer\Controller\Adminhtml\Index\Index::execute */ public function testExecute() { $this->prepareExecute(); $this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->once())->method('setActiveMenu')->with('Magento_Customer::customer_manage'); $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('Customers'); $this->resultPageMock->expects($this->atLeastOnce())->method('addBreadcrumb')->withConsecutive(['Customers', 'Customers'], ['Manage Customers', 'Manage Customers']); $this->sessionMock->expects($this->once())->method('unsCustomerData'); $this->assertInstanceOf('Magento\\Framework\\View\\Result\\Page', $this->indexController->execute()); }
/** * test setup */ public function setUp() { $this->pageConfig = $this->getMockBuilder('\\Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->setMethods(['set', 'getTitle'])->getMock(); $this->resultPageFactory = $this->getMockBuilder('\\Magento\\Framework\\View\\Result\\PageFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->resultPage = $this->getMockBuilder('\\Magento\\Framework\\View\\Result\\Page')->disableOriginalConstructor()->getMock(); $this->block = $this->getMockBuilder('\\Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->getMock(); $this->pageLayout = $this->getMockBuilder('\\Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->getMock(); $this->resultPageFactory->expects($this->once())->method('create')->willReturn($this->resultPage); $this->resultPage->expects($this->any())->method('getLayout')->willReturn($this->pageLayout); $this->pageLayout->expects($this->any())->method('getBlock')->willReturn($this->block); $this->pageConfig->expects($this->once())->method('getTitle')->willReturnSelf(); $this->resultPage->expects($this->any())->method('getConfig')->willReturn($this->pageConfig); }
/** * Test execute * * @return void */ public function testExecute() { $orderId = 1; $invoiceData = ['comment_text' => 'test']; $response = 'test data'; $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId)); $this->requestMock->expects($this->at(1))->method('getParam')->with('invoice', [])->will($this->returnValue($invoiceData)); $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock(); $invoiceMock->expects($this->once())->method('getTotalQty')->willReturn(2); $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods(['load', 'getId', 'canInvoice'])->getMock(); $orderMock->expects($this->once())->method('load')->with($orderId)->willReturnSelf(); $orderMock->expects($this->once())->method('getId')->willReturn($orderId); $orderMock->expects($this->once())->method('canInvoice')->willReturn(true); $this->invoiceServiceMock->expects($this->once())->method('prepareInvoice')->with($orderMock, [])->willReturn($invoiceMock); $this->objectManagerMock->expects($this->at(0))->method('create')->with('Magento\\Sales\\Model\\Order')->willReturn($orderMock); $blockItemMock = $this->getMockBuilder('Magento\\Sales\\Block\\Order\\Items')->disableOriginalConstructor()->setMethods([])->getMock(); $blockItemMock->expects($this->once())->method('toHtml')->will($this->returnValue($response)); $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods([])->getMock(); $layoutMock->expects($this->once())->method('getBlock')->with('order_items')->will($this->returnValue($blockItemMock)); $this->resultPageMock->expects($this->once())->method('getLayout')->will($this->returnValue($layoutMock)); $this->resultPageMock->expects($this->once())->method('getConfig')->will($this->returnValue($this->pageConfigMock)); $this->pageConfigMock->expects($this->once())->method('getTitle')->will($this->returnValue($this->titleMock)); $this->resultPageFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->resultPageMock)); $resultRaw = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Raw')->disableOriginalConstructor()->setMethods([])->getMock(); $resultRaw->expects($this->once())->method('setContents')->with($response); $this->resultRawFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultRaw)); $this->assertSame($resultRaw, $this->controller->execute()); }
public function testExecute() { $orderId = 1; $invoiceData = []; $commentText = 'comment test'; $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId)); $this->requestMock->expects($this->at(1))->method('getParam')->with('invoice', [])->will($this->returnValue($invoiceData)); $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock(); $invoiceMock->expects($this->once())->method('getTotalQty')->willReturn(2); $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods(['load', 'getId', 'canInvoice'])->getMock(); $orderMock->expects($this->once())->method('load')->with($orderId)->willReturnSelf(); $orderMock->expects($this->once())->method('getId')->willReturn($orderId); $orderMock->expects($this->once())->method('canInvoice')->willReturn(true); $orderService = $this->getMockBuilder('Magento\\Sales\\Model\\Service\\Order')->disableOriginalConstructor()->setMethods([])->getMock(); $orderService->expects($this->once())->method('prepareInvoice')->willReturn($invoiceMock); $menuBlockMock = $this->getMockBuilder('Magento\\Backend\\Block\\Menu')->disableOriginalConstructor()->setMethods(['getParentItems', 'getMenuModel'])->getMock(); $menuBlockMock->expects($this->any())->method('getMenuModel')->will($this->returnSelf()); $menuBlockMock->expects($this->any())->method('getParentItems')->with('Magento_Sales::sales_order')->will($this->returnValue([])); $this->sessionMock->expects($this->once())->method('getCommentText')->with(true)->will($this->returnValue($commentText)); $this->objectManagerMock->expects($this->at(0))->method('create')->with('Magento\\Sales\\Model\\Order')->willReturn($orderMock); $this->objectManagerMock->expects($this->at(1))->method('create')->with('Magento\\Sales\\Model\\Service\\Order')->willReturn($orderService); $this->objectManagerMock->expects($this->at(2))->method('get')->with('Magento\\Backend\\Model\\Session')->will($this->returnValue($this->sessionMock)); $this->resultPageMock->expects($this->once())->method('setActiveMenu')->with('Magento_Sales::sales_order'); $this->resultPageFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->resultPageMock)); $this->assertSame($this->resultPageMock, $this->controller->execute()); }
/** * Test execute * * @return void */ public function testExecute() { $data = ['comment' => 'test comment']; $invoiceId = 2; $response = 'some result'; $this->requestMock->expects($this->at(0))->method('getParam')->with('id')->willReturn($invoiceId); $this->requestMock->expects($this->at(1))->method('setParam'); $this->requestMock->expects($this->at(2))->method('getPost')->with('comment')->willReturn($data); $this->requestMock->expects($this->at(3))->method('getParam')->with('invoice_id')->willReturn($invoiceId); $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock(); $invoiceMock->expects($this->once())->method('addComment')->with($data['comment'], false, false); $invoiceMock->expects($this->once())->method('save'); $invoiceMock->expects($this->once())->method('load')->willReturnSelf(); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Sales\\Model\\Order\\Invoice')->willReturn($invoiceMock); $commentsBlockMock = $this->getMockBuilder('Magento\\Sales\\Block\\Adminhtml\\Order\\Invoice\\View\\Comments')->disableOriginalConstructor()->setMethods([])->getMock(); $commentsBlockMock->expects($this->once())->method('toHtml')->will($this->returnValue($response)); $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods([])->getMock(); $layoutMock->expects($this->once())->method('getBlock')->with('invoice_comments')->will($this->returnValue($commentsBlockMock)); $this->resultPageFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->resultPageMock)); $this->resultPageMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock)); $this->commentSenderMock->expects($this->once())->method('send')->with($invoiceMock, false, $data['comment']); $resultRaw = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Raw')->disableOriginalConstructor()->setMethods([])->getMock(); $resultRaw->expects($this->once())->method('setContents')->with($response); $this->resultRawFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultRaw)); $this->assertSame($resultRaw, $this->controller->execute()); }
/** * Test execute * * @return void */ public function testExecute() { $comment = 'Test comment'; $data = ['comment' => $comment]; $html = 'test output'; $creditmemoMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo') ->disableOriginalConstructor() ->getMock(); $commentMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo\Comment') ->disableOriginalConstructor() ->getMock(); $layoutMock = $this->getMockBuilder('Magento\Framework\View\Layout') ->disableOriginalConstructor() ->getMock(); $blockMock = $this->getMockBuilder('Magento\Sales\Block\Adminhtml\Order\Creditmemo\View\Comments') ->disableOriginalConstructor() ->getMock(); $this->requestMock->expects($this->once()) ->method('getPost') ->with('comment') ->willReturn($data); $this->requestMock->expects($this->any()) ->method('getParam') ->willReturnArgument(0); $creditmemoMock->expects($this->once()) ->method('addComment') ->willReturn($commentMock); $this->loaderMock->expects($this->once()) ->method('load') ->willReturn($creditmemoMock); $this->resultPageFactoryMock->expects($this->once()) ->method('create') ->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->atLeastOnce()) ->method('getLayout') ->willReturn($layoutMock); $layoutMock->expects($this->once()) ->method('getBlock') ->with('creditmemo_comments') ->willReturn($blockMock); $blockMock->expects($this->once()) ->method('toHtml') ->willReturn($html); $this->resultRawFactoryMock->expects($this->once()) ->method('create') ->willReturn($this->resultRawMock); $this->resultRawMock->expects($this->once()) ->method('setContents') ->with($html) ->willReturnSelf(); $this->assertInstanceOf( 'Magento\Framework\Controller\Result\Raw', $this->controller->executeInternal() ); }
public function testExecuteWithSession() { $token = 'token'; $customerId = '11'; $this->requestMock->expects($this->exactly(2))->method('getParam')->willReturnMap([['token', null, null], ['id', null, $customerId]]); $this->sessionMock->expects($this->once())->method('getRpToken')->willReturn($token); $this->sessionMock->expects($this->once())->method('getRpCustomerId')->willReturn($customerId); $this->accountManagementMock->expects($this->once())->method('validateResetPasswordLinkToken')->with($customerId, $token)->willReturn(true); /** @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject $pageMock */ $pageMock = $this->getMockBuilder('Magento\\Framework\\View\\Result\\Page')->disableOriginalConstructor()->getMock(); $this->pageFactoryMock->expects($this->once())->method('create')->with(false, [])->willReturn($pageMock); /** @var \Magento\Framework\View\Layout|\PHPUnit_Framework_MockObject_MockObject $layoutMock */ $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->getMock(); $pageMock->expects($this->once())->method('getLayout')->willReturn($layoutMock); /** @var \Magento\Customer\Block\Account\Resetpassword|\PHPUnit_Framework_MockObject_MockObject $layoutMock */ $blockMock = $this->getMockBuilder('Magento\\Customer\\Block\\Account\\Resetpassword')->disableOriginalConstructor()->setMethods(['setCustomerId', 'setResetPasswordLinkToken'])->getMock(); $layoutMock->expects($this->once())->method('getBlock')->with('resetPassword')->willReturn($blockMock); $blockMock->expects($this->once())->method('setCustomerId')->with($customerId)->willReturnSelf(); $blockMock->expects($this->once())->method('setResetPasswordLinkToken')->with($token)->willReturnSelf(); $this->assertEquals($pageMock, $this->model->executeInternal()); }
/** * @dataProvider testExecuteDataProvider */ public function testExecute($invoice) { $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->getMock(); $blockMock = $this->getMockBuilder('Magento\\Sales\\Block\\Adminhtml\\Order\\Creditmemo\\View')->disableOriginalConstructor()->getMock(); $this->requestMock->expects($this->any())->method('getParam')->withAnyParameters()->willReturnArgument(0); $this->loaderMock->expects($this->once())->method('load')->willReturn($this->creditmemoMock); $this->creditmemoMock->expects($this->any())->method('getInvoice')->willReturn($invoice); $layoutMock->expects($this->once())->method('getBlock')->with('sales_creditmemo_view')->willReturn($blockMock); $this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($layoutMock); $this->resultPageMock->expects($this->once())->method('setActiveMenu')->with('Magento_Sales::sales_creditmemo')->willReturnSelf(); $this->resultPageMock->expects($this->atLeastOnce())->method('getConfig')->willReturn($this->pageConfigMock); $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Page', $this->controller->execute()); }
/** * Test execute * * @return void */ public function testExecute() { $response = 'output'; $this->requestMock->expects($this->any())->method('getParam')->withAnyParameters()->willReturnArgument(0); $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->getMock(); $blockMock = $this->getMockBuilder('Magento\\Sales\\Block\\Order\\Items')->disableOriginalConstructor()->getMock(); $this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($layoutMock); $blockMock->expects($this->once())->method('toHtml')->willReturn($response); $layoutMock->expects($this->once())->method('getBlock')->with('order_items')->willReturn($blockMock); $this->resultRawFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRawMock); $this->resultRawMock->expects($this->once())->method('setContents')->with($response)->willReturnSelf(); $this->assertInstanceOf('Magento\\Framework\\Controller\\Result\\Raw', $this->controller->execute()); }
/** * Run test execute method */ public function testExecute() { $orderId = 1; $shipmentId = 1; $shipment = []; $tracking = []; $incrementId = '10000001'; $comeFrom = true; $this->loadShipment($orderId, $shipmentId, $shipment, $tracking, $comeFrom, $this->shipmentMock); $this->shipmentMock->expects($this->once())->method('getIncrementId')->willReturn($incrementId); $this->resultPageFactoryMock->expects($this->once()) ->method('create') ->willReturn($this->resultPageMock); $layoutMock = $this->getMock('Magento\Framework\View\Layout', ['getBlock', '__wakeup'], [], '', false); $this->resultPageMock->expects($this->once()) ->method('getLayout') ->willReturn($layoutMock); $layoutMock->expects($this->once()) ->method('getBlock') ->with('sales_shipment_view') ->willReturn($this->blockMock); $this->blockMock->expects($this->once()) ->method('updateBackButtonUrl') ->with($comeFrom) ->willReturnSelf(); $this->resultPageMock->expects($this->once()) ->method('setActiveMenu') ->with('Magento_Sales::sales_shipment') ->willReturnSelf(); $this->resultPageMock->expects($this->atLeastOnce()) ->method('getConfig') ->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->atLeastOnce()) ->method('getTitle') ->willReturn($this->pageTitleMock); $this->pageTitleMock->expects($this->exactly(2)) ->method('prepend') ->withConsecutive( ['Shipments'], ["#" . $incrementId] ) ->willReturnSelf(); $this->assertEquals($this->resultPageMock, $this->controller->executeInternal()); }
/** * Executes the controller action and asserts with redirects for non existing logic */ public function testExecuteNonExistingTokenRedirect() { $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); $notification = $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, $notification->execute()); }
protected function initAction() { $this->resultPageFactoryMock->expects($this->once()) ->method('create') ->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->once()) ->method('setActiveMenu') ->with('Magento_Sales::sales_order') ->willReturnSelf(); $this->resultPageMock->expects($this->exactly(2)) ->method('addBreadcrumb') ->withConsecutive( ['Sales', 'Sales'], ['Orders', 'Orders'] ) ->willReturnSelf(); }
public function testExecute() { $invoiceId = 2; $this->requestMock->expects($this->at(0))->method('getParam')->with('invoice_id')->will($this->returnValue($invoiceId)); $this->requestMock->expects($this->at(1))->method('getParam')->with('come_from')->willReturn('anything'); $menuBlockMock = $this->getMockBuilder('Magento\\Backend\\Block\\Menu')->disableOriginalConstructor()->setMethods(['getParentItems', 'getMenuModel'])->getMock(); $menuBlockMock->expects($this->any())->method('getMenuModel')->will($this->returnSelf()); $menuBlockMock->expects($this->any())->method('getParentItems')->with('Magento_Sales::sales_order')->will($this->returnValue([])); $invoiceViewBlockMock = $this->getMockBuilder('Magento\\Sales\\Block\\Adminhtml\\Order\\Invoice\\View')->disableOriginalConstructor()->setMethods(['updateBackButtonUrl'])->getMock(); $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods([])->getMock(); $layoutMock->expects($this->at(0))->method('getBlock')->with('sales_invoice_view')->will($this->returnValue($invoiceViewBlockMock)); $this->resultPageMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock)); $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock(); $this->invoiceRepository->expects($this->once())->method('get')->willReturn($invoiceMock); $this->resultPageMock->expects($this->once())->method('setActiveMenu')->with('Magento_Sales::sales_order'); $this->resultPageFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->resultPageMock)); $this->assertSame($this->resultPageMock, $this->controller->execute()); }
/** * @param int $blockId * @param string $label * @param string $title * @dataProvider editActionData */ public function testEditAction($blockId, $label, $title) { $this->requestMock->expects($this->once())->method('getParam')->with('block_id')->willReturn($blockId); $this->blockMock->expects($this->any())->method('load')->with($blockId); $this->blockMock->expects($this->any())->method('getId')->willReturn($blockId); $this->blockMock->expects($this->any())->method('getTitle')->willReturn('Test title'); $this->coreRegistryMock->expects($this->once())->method('register')->with('cms_block', $this->blockMock); $resultPageMock = $this->getMock('Magento\\Backend\\Model\\View\\Result\\Page', [], [], '', false); $this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($resultPageMock); $titleMock = $this->getMock('Magento\\Framework\\View\\Page\\Title', [], [], '', false); $titleMock->expects($this->at(0))->method('prepend')->with(__('Blocks')); $titleMock->expects($this->at(1))->method('prepend')->with($this->getTitle()); $pageConfigMock = $this->getMock('Magento\\Framework\\View\\Page\\Config', [], [], '', false); $pageConfigMock->expects($this->exactly(2))->method('getTitle')->willReturn($titleMock); $resultPageMock->expects($this->once())->method('setActiveMenu')->willReturnSelf(); $resultPageMock->expects($this->any())->method('addBreadcrumb')->willReturnSelf(); $resultPageMock->expects($this->at(3))->method('addBreadcrumb')->with(__($label), __($title))->willReturnSelf(); $resultPageMock->expects($this->exactly(2))->method('getConfig')->willReturn($pageConfigMock); $this->assertSame($resultPageMock, $this->editController->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(2))->method('prepend')->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->resultPageMock->expects($this->any())->method('getConfig')->will($this->returnValue($this->pageConfigMock)); $this->pageConfigMock->expects($this->any())->method('getTitle')->willReturn($this->titleMock); $this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->once())->method('setActiveMenu')->with('Magento_Sales::sales_order')->willReturnSelf(); $this->resultPageMock->expects($this->atLeastOnce())->method('getConfig')->willReturn($this->pageConfigMock); $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Page', $this->controller->execute()); }
public function testExecuteNoPopup() { $attributesData = ['frontend_label' => '']; $this->request->expects($this->any())->method('getParam')->willReturnMap([['attribute_id', null, null], ['attribute', null, $attributesData], ['popup', null, false]]); $this->objectManagerMock->expects($this->any())->method('create')->with('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute')->willReturn($this->eavAttribute); $this->objectManagerMock->expects($this->any())->method('get')->with('Magento\\Backend\\Model\\Session')->willReturn($this->session); $this->eavAttribute->expects($this->once())->method('setEntityTypeId')->willReturnSelf(); $this->eavAttribute->expects($this->once())->method('addData')->with($attributesData)->willReturnSelf(); $this->registry->expects($this->any())->method('register')->with('entity_attribute', $this->eavAttribute); $this->resultPage->expects($this->any())->method('addBreadcrumb')->willReturnSelf(); $this->resultPage->expects($this->once())->method('setActiveMenu')->with('Magento_Catalog::catalog_attributes_attributes')->willReturnSelf(); $this->resultPage->expects($this->any())->method('getConfig')->willReturn($this->pageConfig); $this->resultPage->expects($this->once())->method('getLayout')->willReturn($this->layout); $this->resultPageFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->resultPage); $this->pageConfig->expects($this->any())->method('getTitle')->willReturn($this->pageTitle); $this->pageTitle->expects($this->any())->method('prepend')->willReturnSelf(); $this->eavAttribute->expects($this->any())->method('getName')->willReturn(null); $this->layout->expects($this->once())->method('getBlock')->willReturn($this->blockTemplate); $this->blockTemplate->expects($this->any())->method('setIsPopup')->willReturnSelf(); $this->assertSame($this->resultPage, $this->editController->execute()); }
/** * @covers \Magento\Cms\Helper\Page::prepareResultPage * @param integer|null $pageId * @param integer|null $internalPageId * @param integer $pageLoadResultIndex * @param string $customPageLayout * @param string $handle * @param string $customLayoutUpdateXml * @param string $layoutUpdate * @param boolean $expectedResult * * @dataProvider renderPageExtendedDataProvider * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testPrepareResultPage($pageId, $internalPageId, $pageLoadResultIndex, $customPageLayout, $handle, $customLayoutUpdateXml, $layoutUpdate, $expectedResult) { $storeId = 321; $customThemeFrom = 'customThemeFrom'; $customThemeTo = 'customThemeTo'; $isScopeDateInInterval = true; $customTheme = 'customTheme'; $pageLayout = 'pageLayout'; $pageIdentifier = 111; $layoutUpdateXml = 'layoutUpdateXml'; $contentHeading = 'contentHeading'; $escapedContentHeading = 'escapedContentHeading'; $defaultGroup = 'defaultGroup'; $pageLoadResultCollection = [null, $this->pageMock]; $this->pageMock->expects($this->any())->method('getId')->willReturn($internalPageId); $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->any())->method('getId')->willReturn($storeId); $this->pageMock->expects($this->any())->method('setStoreId')->with($storeId)->willReturnSelf(); $this->pageMock->expects($this->any())->method('load')->with($pageId)->willReturn($pageLoadResultCollection[$pageLoadResultIndex]); $this->pageMock->expects($this->any())->method('getCustomThemeFrom')->willReturn($customThemeFrom); $this->pageMock->expects($this->any())->method('getCustomThemeTo')->willReturn($customThemeTo); $this->localeDateMock->expects($this->any())->method('isScopeDateInInterval')->with(null, $customThemeFrom, $customThemeTo)->willReturn($isScopeDateInInterval); $this->pageMock->expects($this->any())->method('getCustomTheme')->willReturn($customTheme); $this->designMock->expects($this->any())->method('setDesignTheme')->with($customTheme)->willReturnSelf(); $this->pageMock->expects($this->any())->method('getPageLayout')->willReturn($pageLayout); $this->pageMock->expects($this->any())->method('getCustomPageLayout')->willReturn($customPageLayout); $this->resultPageFactory->expects($this->any())->method('create')->will($this->returnValue($this->resultPageMock)); $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->any())->method('setPageLayout')->with($handle)->willReturnSelf(); $this->resultPageMock->expects($this->any())->method('initLayout')->willReturnSelf(); $this->resultPageMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock); $this->layoutMock->expects($this->any())->method('getUpdate')->willReturn($this->layoutProcessorMock); $this->layoutProcessorMock->expects($this->any())->method('addHandle')->with('cms_page_view')->willReturnSelf(); $this->pageMock->expects($this->any())->method('getIdentifier')->willReturn($pageIdentifier); $this->eventManagerMock->expects($this->any())->method('dispatch')->with('cms_page_render', ['page' => $this->pageMock, 'controller_action' => $this->actionMock]); $this->pageMock->expects($this->any())->method('getCustomLayoutUpdateXml')->willReturn($customLayoutUpdateXml); $this->pageMock->expects($this->any())->method('getLayoutUpdateXml')->willReturn($layoutUpdateXml); $this->layoutProcessorMock->expects($this->any())->method('addUpdate')->with($layoutUpdate)->willReturnSelf(); $this->layoutMock->expects($this->any())->method('getBlock')->with('page_content_heading')->willReturn($this->blockMock); $this->pageMock->expects($this->any())->method('getContentHeading')->willReturn($contentHeading); $this->escaperMock->expects($this->any())->method('escapeHtml')->with($contentHeading)->willReturn($escapedContentHeading); $this->blockMock->expects($this->any())->method('setContentHeading')->with($escapedContentHeading)->willReturnSelf(); $this->layoutMock->expects($this->any())->method('getMessagesBlock')->willReturn($this->messagesBlockMock); $this->messageManagerMock->expects($this->any())->method('getDefaultGroup')->willReturn($defaultGroup); $this->messagesBlockMock->expects($this->any())->method('addStorageType')->with($defaultGroup); $this->messageManagerMock->expects($this->any())->method('getMessages')->with(true)->willReturn($this->messageCollectionMock); $this->messagesBlockMock->expects($this->any())->method('addMessages')->with($this->messageCollectionMock)->willReturnSelf(); if ($expectedResult) { $expectedResult = $this->resultPageMock; } $this->assertSame($expectedResult, $this->object->prepareResultPage($this->actionMock, $pageId)); }