/** * @return void */ public function testGetPageHeading() { $title = 'some title'; $this->pageTitleMock->expects($this->once())->method('getShortHeading')->willReturn($title); $this->pageConfigMock->expects($this->once())->method('getTitle')->willReturn($this->pageTitleMock); $this->assertEquals($title, $this->htmlTitle->getPageHeading()); }
/** * @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 testExecute() { $this->view->expects($this->any())->method('loadLayout')->will($this->returnValue(1)); $this->view->expects($this->any())->method('getPage')->will($this->returnValue($this->page)); $this->page->expects($this->any())->method('getConfig')->will($this->returnValue($this->config)); $this->config->expects($this->any())->method('getTitle')->will($this->returnValue($this->title)); $this->title->expects($this->any())->method('prepend')->with(__('Index Management'))->will($this->returnValue(1)); $this->view->expects($this->any())->method('renderLayout')->will($this->returnValue(1)); $this->object->execute(); }
public function testProcess() { $generatorContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Generator\\Context')->disableOriginalConstructor()->getMock(); $structureMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config\\Structure')->disableOriginalConstructor()->getMock(); $readerContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Reader\\Context')->disableOriginalConstructor()->getMock(); $readerContextMock->expects($this->any())->method('getPageConfigStructure')->willReturn($structureMock); $bodyClasses = ['class_1', 'class_2']; $structureMock->expects($this->once())->method('getBodyClasses')->will($this->returnValue($bodyClasses)); $this->pageConfigMock->expects($this->exactly(2))->method('addBodyClass')->withConsecutive(['class_1'], ['class_2']); $this->assertEquals($this->bodyGenerator, $this->bodyGenerator->process($readerContextMock, $generatorContextMock)); }
/** * @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); }
public function testSetLayout() { $filePath = 'require_js_fie_path'; $asset = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\LocalInterface'); $asset->expects($this->atLeastOnce())->method('getFilePath')->willReturn($filePath); $this->fileManager->expects($this->once())->method('createRequireJsAsset')->will($this->returnValue($asset)); $layout = $this->getMock('Magento\\Framework\\View\\LayoutInterface'); $assetCollection = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\GroupedCollection')->disableOriginalConstructor()->getMock(); $assetCollection->expects($this->once())->method('add')->with($filePath, $asset); $this->pageConfig->expects($this->atLeastOnce())->method('getAssetCollection')->willReturn($assetCollection); $object = new Config($this->context, $this->config, $this->fileManager, $this->pageConfig); $object->setLayout($layout); }
/** * Executes the controller action and asserts non exception logic */ public function testExecute() { $objectManager = new ObjectManagerHelper($this); $this->vault->expects($this->once())->method('storedCard')->willReturn(true); $this->request->expects($this->any())->method('getParam')->willReturn('token'); $this->resultRedirectFactory->expects($this->never())->method('create')->willReturn($this->resultRedirect); $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); $notification = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\Delete', ['request' => $this->request, 'resultPageFactory' => $this->resultPageFactory, 'vault' => $this->vault]); $this->assertSame($this->resultPage, $notification->execute()); }
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(); }
/** * @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()); }
protected function setUp() { $this->_eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false); $this->_actionFlagMock = $this->getMock('Magento\\Framework\\App\\ActionFlag', [], [], '', false); $this->_redirectMock = $this->getMock('Magento\\Framework\\App\\Response\\RedirectInterface', [], [], '', false); $this->_requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock(); $this->_responseMock = $this->getMock('Magento\\Framework\\App\\ResponseInterface', [], [], '', false); $this->pageConfigMock = $this->getMock('Magento\\Framework\\View\\Page\\Config', ['getConfig'], [], '', false); $this->viewMock = $this->getMock('Magento\\Framework\\App\\ViewInterface'); $this->viewMock->expects($this->any())->method('getPage')->will($this->returnValue($this->pageConfigMock)); $this->pageConfigMock->expects($this->any())->method('getConfig')->will($this->returnValue(1)); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->action = $this->objectManagerHelper->getObject('Magento\\Framework\\App\\Test\\Unit\\Action\\ActionFake', ['request' => $this->_requestMock, 'response' => $this->_responseMock, 'eventManager' => $this->_eventManagerMock, 'redirect' => $this->_redirectMock, 'actionFlag' => $this->_actionFlagMock, 'view' => $this->viewMock]); \Magento\Framework\Profiler::disable(); }
protected function setUp() { $this->_eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false); $this->_actionFlagMock = $this->getMock('Magento\\Framework\\App\\ActionFlag', [], [], '', false); $this->_redirectMock = $this->getMock('Magento\\Framework\\App\\Response\\RedirectInterface', [], [], '', false); $this->_requestMock = $this->getMock('Magento\\Framework\\App\\RequestInterface', ['getFullActionName', 'getRouteName', 'isDispatched', 'initForward', 'setParams', 'setControllerName', 'setDispatched', 'getModuleName', 'setModuleName', 'getActionName', 'setActionName', 'getParam', 'getCookie'], [], '', false); $this->_responseMock = $this->getMock('Magento\\Framework\\App\\ResponseInterface', [], [], '', false); $this->pageConfigMock = $this->getMock('Magento\\Framework\\View\\Page\\Config', ['getConfig'], [], '', false); $this->viewMock = $this->getMock('Magento\\Framework\\App\\ViewInterface'); $this->viewMock->expects($this->any())->method('getPage')->will($this->returnValue($this->pageConfigMock)); $this->pageConfigMock->expects($this->any())->method('getConfig')->will($this->returnValue(1)); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->action = $this->objectManagerHelper->getObject('Magento\\Framework\\App\\Action\\ActionFake', ['request' => $this->_requestMock, 'response' => $this->_responseMock, 'eventManager' => $this->_eventManagerMock, 'redirect' => $this->_redirectMock, 'actionFlag' => $this->_actionFlagMock, 'view' => $this->viewMock]); \Magento\Framework\Profiler::disable(); }
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()); $this->view->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); $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\DataObject(['title' => 'title1']), new \Magento\Framework\DataObject(['title' => 'title2']), new \Magento\Framework\DataObject(['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->assertNull($this->newAction->execute()); }
public function testSetLayoutWithoutAddress() { $addressId = 1; $customerPrefix = 'prefix'; $customerFirstName = 'firstname'; $customerMiddlename = 'middlename'; $customerLastname = 'lastname'; $customerSuffix = 'suffix'; $title = 'title'; $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->getMock(); $this->requestMock->expects($this->once())->method('getParam')->with('id', null)->willReturn($addressId); $this->addressRepositoryMock->expects($this->once())->method('getById')->with($addressId)->willThrowException(\Magento\Framework\Exception\NoSuchEntityException::singleField('addressId', $addressId)); $newAddressMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->getMock(); $this->addressDataFactoryMock->expects($this->once())->method('create')->willReturn($newAddressMock); $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $this->currentCustomerMock->expects($this->once())->method('getCustomer')->willReturn($customerMock); $customerMock->expects($this->once())->method('getPrefix')->willReturn($customerPrefix); $customerMock->expects($this->once())->method('getFirstname')->willReturn($customerFirstName); $customerMock->expects($this->once())->method('getMiddlename')->willReturn($customerMiddlename); $customerMock->expects($this->once())->method('getLastname')->willReturn($customerLastname); $customerMock->expects($this->once())->method('getSuffix')->willReturn($customerSuffix); $newAddressMock->expects($this->once())->method('setPrefix')->with($customerPrefix)->willReturnSelf(); $newAddressMock->expects($this->once())->method('setFirstname')->with($customerFirstName)->willReturnSelf(); $newAddressMock->expects($this->once())->method('setMiddlename')->with($customerMiddlename)->willReturnSelf(); $newAddressMock->expects($this->once())->method('setLastname')->with($customerLastname)->willReturnSelf(); $newAddressMock->expects($this->once())->method('setSuffix')->with($customerSuffix)->willReturnSelf(); $pageTitleMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock(); $this->pageConfigMock->expects($this->once())->method('getTitle')->willReturn($pageTitleMock); $this->model->setData('title', $title); $pageTitleMock->expects($this->once())->method('set')->with($title)->willReturnSelf(); $this->assertEquals($this->model, $this->model->setLayout($layoutMock)); $this->assertEquals($layoutMock, $this->model->getLayout()); }
/** * @param $groupOne * @param $groupTwo * @param $expectedResult * @dataProvider dataProviderRenderAssets */ public function testRenderAssets($groupOne, $groupTwo, $expectedResult) { $assetUrl = 'url'; $assetNoRoutUrl = 'no_route_url'; $exception = new \Magento\Framework\Exception('my message'); $assetMockOne = $this->getMock('Magento\\Framework\\View\\Asset\\AssetInterface'); $assetMockOne->expects($this->exactly(2))->method('getUrl')->willReturn($assetUrl); $groupAssetsOne = [$assetMockOne, $assetMockOne]; $groupMockOne = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\PropertyGroup')->disableOriginalConstructor()->getMock(); $groupMockOne->expects($this->once())->method('getAll')->willReturn($groupAssetsOne); $groupMockOne->expects($this->any())->method('getProperty')->willReturnMap([[GroupedCollection::PROPERTY_CAN_MERGE, true], [GroupedCollection::PROPERTY_CONTENT_TYPE, $groupOne['type']], ['attributes', $groupOne['attributes']], ['ie_condition', $groupOne['condition']]]); $assetMockTwo = $this->getMock('Magento\\Framework\\View\\Asset\\AssetInterface'); $assetMockTwo->expects($this->once())->method('getUrl')->willThrowException($exception); $groupAssetsTwo = [$assetMockTwo]; $groupMockTwo = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\PropertyGroup')->disableOriginalConstructor()->getMock(); $groupMockTwo->expects($this->once())->method('getAll')->willReturn($groupAssetsTwo); $groupMockTwo->expects($this->any())->method('getProperty')->willReturnMap([[GroupedCollection::PROPERTY_CAN_MERGE, true], [GroupedCollection::PROPERTY_CONTENT_TYPE, $groupTwo['type']], ['attributes', $groupTwo['attributes']], ['ie_condition', $groupTwo['condition']]]); $this->pageConfigMock->expects($this->once())->method('getAssetCollection')->willReturn($this->assetsCollection); $this->assetsCollection->expects($this->once())->method('getGroups')->willReturn([$groupMockOne, $groupMockTwo]); $this->assetMinifyServiceMock->expects($this->exactly(2))->method('getAssets')->willReturnArgument(0); $this->assetMergeServiceMock->expects($this->exactly(1))->method('getMergedAssets')->willReturnArgument(0); $this->loggerMock->expects($this->once())->method('critical')->with($exception); $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('', ['_direct' => 'core/index/notFound'])->willReturn($assetNoRoutUrl); $this->assertEquals($expectedResult, $this->renderer->renderAssets($this->renderer->getAvailableResultGroups())); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setUp() { $titleMock = $this->getMockBuilder('Magento\\Framework\\App\\Action\\Title')->disableOriginalConstructor()->getMock(); $this->invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->getMock(); $this->creditmemoMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Creditmemo')->disableOriginalConstructor()->setMethods(['getInvoice', 'getOrder', 'cancel', 'getId', '__wakeup'])->getMock(); $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock(); $this->responseMock = $this->getMockBuilder('Magento\\Framework\\App\\Response\\Http')->disableOriginalConstructor()->getMock(); $this->objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface'); $this->messageManagerMock = $this->getMockBuilder('Magento\\Framework\\Message\\Manager')->disableOriginalConstructor()->getMock(); $this->sessionMock = $this->getMockBuilder('Magento\\Backend\\Model\\Session')->disableOriginalConstructor()->getMock(); $this->helperMock = $this->getMockBuilder('Magento\\Backend\\Helper\\Data')->disableOriginalConstructor()->getMock(); $this->contextMock = $this->getMockBuilder('Magento\\Backend\\App\\Action\\Context')->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->any())->method('getHelper')->will($this->returnValue($this->helperMock)); $this->actionFlagMock = $this->getMockBuilder('Magento\\Framework\\App\\ActionFlag')->disableOriginalConstructor()->getMock(); $this->loaderMock = $this->getMockBuilder('Magento\\Sales\\Controller\\Adminhtml\\Order\\CreditmemoLoader')->disableOriginalConstructor()->getMock(); $this->pageConfigMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock(); $this->pageTitleMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock(); $this->resultPageFactoryMock = $this->getMockBuilder('Magento\\Framework\\View\\Result\\PageFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->resultPageMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Page')->disableOriginalConstructor()->getMock(); $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\ForwardFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->resultForwardMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Forward')->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->any())->method('getSession')->will($this->returnValue($this->sessionMock)); $this->contextMock->expects($this->any())->method('getActionFlag')->will($this->returnValue($this->actionFlagMock)); $this->contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock)); $this->contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock)); $this->contextMock->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->objectManagerMock)); $this->contextMock->expects($this->any())->method('getTitle')->will($this->returnValue($titleMock)); $this->contextMock->expects($this->any())->method('getMessageManager')->will($this->returnValue($this->messageManagerMock)); $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->any())->method('getTitle')->willReturn($this->pageTitleMock); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->controller = $objectManager->getObject('Magento\\Sales\\Controller\\Adminhtml\\Order\\Creditmemo\\View', ['context' => $this->contextMock, 'creditmemoLoader' => $this->loaderMock, 'resultPageFactory' => $this->resultPageFactoryMock, 'resultForwardFactory' => $this->resultForwardFactoryMock]); }
public function setUp() { $objectManager = new ObjectManager($this); $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->setMethods([])->getMock(); $this->responseMock = $this->getMockBuilder('Magento\\Framework\\App\\Response\\Http')->disableOriginalConstructor()->setMethods([])->getMock(); $this->titleMock = $this->getMockBuilder('Magento\\Framework\\App\\Action\\Title')->disableOriginalConstructor()->setMethods([])->getMock(); $this->viewMock = $this->getMockBuilder('Magento\\Framework\\App\\View')->disableOriginalConstructor()->setMethods([])->getMock(); $this->actionFlagMock = $this->getMockBuilder('Magento\\Framework\\App\\ActionFlag')->disableOriginalConstructor()->setMethods([])->getMock(); $this->sessionMock = $this->getMockBuilder('Magento\\Backend\\Model\\Session')->disableOriginalConstructor()->setMethods(['getCommentText', 'setIsUrlNotice'])->getMock(); $this->objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface'); $this->resultPageMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Page')->disableOriginalConstructor()->getMock(); $this->pageConfigMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock(); $this->pageTitleMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock(); $contextMock = $this->getMockBuilder('Magento\\Backend\\App\\Action\\Context')->disableOriginalConstructor()->setMethods([])->getMock(); $contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock)); $contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock)); $contextMock->expects($this->any())->method('getTitle')->will($this->returnValue($this->titleMock)); $contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->viewMock)); $contextMock->expects($this->any())->method('getActionFlag')->will($this->returnValue($this->actionFlagMock)); $contextMock->expects($this->any())->method('getSession')->will($this->returnValue($this->sessionMock)); $contextMock->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->objectManagerMock)); $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->resultPageFactoryMock = $this->getMockBuilder('Magento\\Framework\\View\\Result\\PageFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\ForwardFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->controller = $objectManager->getObject('Magento\\Sales\\Controller\\Adminhtml\\Order\\Invoice\\View', ['context' => $contextMock, 'resultPageFactory' => $this->resultPageFactoryMock, 'resultForwardFactory' => $this->resultForwardFactoryMock]); }
/** * @param string $actionName * @return \Magento\Integration\Controller\Adminhtml\Integration */ protected function _createIntegrationController($actionName) { // Mock Layout passed into constructor $this->_viewMock = $this->getMockBuilder('Magento\\Framework\\App\\ViewInterface')->getMock(); $this->_layoutMock = $this->getMock('Magento\\Framework\\View\\LayoutInterface'); $this->_layoutMergeMock = $this->getMockBuilder('Magento\\Framework\\View\\Model\\Layout\\Merge')->disableOriginalConstructor()->getMock(); $this->_layoutMock->expects($this->any())->method('getUpdate')->will($this->returnValue($this->_layoutMergeMock)); $testElement = new \Magento\Framework\Simplexml\Element('<test>test</test>'); $this->_layoutMock->expects($this->any())->method('getNode')->will($this->returnValue($testElement)); // for _setActiveMenu $this->_viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->_layoutMock)); $blockMock = $this->getMockBuilder('Magento\\Backend\\Block\\Menu')->disableOriginalConstructor()->getMock(); $menuMock = $this->getMock('Magento\\Backend\\Model\\Menu', [], [$this->getMock('Psr\\Log\\LoggerInterface')]); $loggerMock = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock(); $loggerMock->expects($this->any())->method('critical')->will($this->returnSelf()); $menuMock->expects($this->any())->method('getParentItems')->will($this->returnValue([])); $blockMock->expects($this->any())->method('getMenuModel')->will($this->returnValue($menuMock)); $this->_layoutMock->expects($this->any())->method('getMessagesBlock')->will($this->returnValue($blockMock)); $this->_layoutMock->expects($this->any())->method('getBlock')->will($this->returnValue($blockMock)); $this->_viewMock->expects($this->any())->method('getPage')->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->viewConfigMock); $this->viewConfigMock->expects($this->any())->method('getTitle')->willReturn($this->pageTitleMock); $this->_escaper->expects($this->any())->method('escapeHtml')->will($this->returnArgument(0)); $contextParameters = ['view' => $this->_viewMock, 'objectManager' => $this->_objectManagerMock, 'session' => $this->_backendSessionMock, 'translator' => $this->_translateModelMock, 'request' => $this->_requestMock, 'response' => $this->_responseMock, 'messageManager' => $this->_messageManager]; $this->_backendActionCtxMock = $this->_objectManagerHelper->getObject('Magento\\Backend\\App\\Action\\Context', $contextParameters); $integrationCollection = $this->getMockBuilder('\\Magento\\Integration\\Model\\Resource\\Integration\\Collection')->disableOriginalConstructor()->setMethods(['addUnsecureUrlsFilter', 'getSize'])->getMock(); $integrationCollection->expects($this->any())->method('addUnsecureUrlsFilter')->will($this->returnValue($integrationCollection)); $integrationCollection->expects($this->any())->method('getSize')->will($this->returnValue(0)); $subControllerParams = ['context' => $this->_backendActionCtxMock, 'integrationService' => $this->_integrationSvcMock, 'oauthService' => $this->_oauthSvcMock, 'registry' => $this->_registryMock, 'logger' => $loggerMock, 'integrationData' => $this->_integrationHelperMock, 'escaper' => $this->_escaper, 'integrationCollection' => $integrationCollection]; /** Create IntegrationController to test */ $controller = $this->_objectManagerHelper->getObject('\\Magento\\Integration\\Controller\\Adminhtml\\Integration\\' . $actionName, $subControllerParams); return $controller; }
/** * @covers \Magento\Sales\Controller\Adminhtml\Order\View::executeInternal */ public function testExecute() { $id = 111; $titlePart = '#111'; $this->initOrder(); $this->initOrderSuccess($id); $this->prepareRedirect(); $this->initAction(); $this->resultPageMock->expects($this->atLeastOnce()) ->method('getConfig') ->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->atLeastOnce()) ->method('getTitle') ->willReturn($this->pageTitleMock); $this->orderMock->expects($this->atLeastOnce()) ->method('getIncrementId') ->willReturn($id); $this->pageTitleMock->expects($this->exactly(2)) ->method('prepend') ->withConsecutive( ['Orders'], [$titlePart] ) ->willReturnSelf(); $this->assertInstanceOf( 'Magento\Backend\Model\View\Result\Page', $this->viewAction->executeInternal() ); }
public function testProcess() { $generatorContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Generator\\Context')->disableOriginalConstructor()->getMock(); $this->title->expects($this->any())->method('set')->with()->will($this->returnSelf()); $structureMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config\\Structure')->disableOriginalConstructor()->getMock(); $readerContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Reader\\Context')->disableOriginalConstructor()->getMock(); $readerContextMock->expects($this->any())->method('getPageConfigStructure')->willReturn($structureMock); $structureMock->expects($this->once())->method('processRemoveAssets'); $structureMock->expects($this->once())->method('processRemoveElementAttributes'); $assets = ['remoteCss' => ['src' => 'file-url', 'src_type' => 'url', 'media' => "all", 'content_type' => 'css'], 'remoteLink' => ['src' => 'file-url', 'src_type' => 'url', 'media' => "all"], 'name' => ['src' => 'file-path', 'ie_condition' => 'lt IE 7', 'media' => "print", 'content_type' => 'css']]; $this->pageConfigMock->expects($this->at(0))->method('addRemotePageAsset')->with('remoteCss', 'css', ['attributes' => ['media' => 'all']]); $this->pageConfigMock->expects($this->at(1))->method('addRemotePageAsset')->with('remoteLink', Head::VIRTUAL_CONTENT_TYPE_LINK, ['attributes' => ['media' => 'all']]); $this->pageConfigMock->expects($this->once())->method('addPageAsset')->with('name', ['attributes' => ['media' => 'print'], 'ie_condition' => 'lt IE 7']); $structureMock->expects($this->once())->method('getAssets')->will($this->returnValue($assets)); $title = 'Page title'; $structureMock->expects($this->atLeastOnce())->method('getTitle')->will($this->returnValue($title)); $this->pageConfigMock->expects($this->any())->method('getTitle')->will($this->returnValue($this->title)); $metadata = ['name1' => 'content1', 'name2' => 'content2']; $structureMock->expects($this->once())->method('getMetadata')->will($this->returnValue($metadata)); $this->pageConfigMock->expects($this->exactly(2))->method('setMetadata')->withConsecutive(['name1', 'content1'], ['name2', 'content2']); $elementAttributes = [PageConfig::ELEMENT_TYPE_BODY => ['body_attr_1' => 'body_value_1', 'body_attr_2' => 'body_value_2'], PageConfig::ELEMENT_TYPE_HTML => ['html_attr_1' => 'html_attr_1']]; $structureMock->expects($this->once())->method('getElementAttributes')->will($this->returnValue($elementAttributes)); $this->pageConfigMock->expects($this->exactly(3))->method('setElementAttribute')->withConsecutive([PageConfig::ELEMENT_TYPE_BODY, 'body_attr_1', 'body_value_1'], [PageConfig::ELEMENT_TYPE_BODY, 'body_attr_2', 'body_value_2'], [PageConfig::ELEMENT_TYPE_HTML, 'html_attr_1', 'html_attr_1']); $this->assertEquals($this->headGenerator, $this->headGenerator->process($readerContextMock, $generatorContextMock)); }
public function testConstructMethod() { $data = []; $customerId = 25; $this->customerSession->expects($this->once())->method('getCustomerId')->will($this->returnValue($customerId)); $statuses = ['pending', 'processing', 'comlete']; $this->orderConfig->expects($this->once())->method('getVisibleOnFrontStatuses')->will($this->returnValue($statuses)); $orderCollection = $this->getMock('Magento\\Sales\\Model\\ResourceModel\\Order\\Collection', ['addFieldToSelect', 'addFieldToFilter', 'setOrder'], [], '', false, false); $this->context->expects($this->any())->method('getPageConfig')->willReturn($this->pageConfig); $orderCollection->expects($this->at(0))->method('addFieldToSelect')->with($this->equalTo('*'))->will($this->returnSelf()); $orderCollection->expects($this->at(1))->method('addFieldToFilter')->with('status', $this->equalTo(['in' => $statuses]))->will($this->returnSelf()); $orderCollection->expects($this->at(2))->method('setOrder')->with('created_at', 'desc')->will($this->returnSelf()); $this->orderCollectionFactoryInterface->expects($this->atLeastOnce())->method('create')->will($this->returnValue($orderCollection)); $this->pageConfig->expects($this->atLeastOnce())->method('getTitle')->willReturn($this->pageTitleMock); $this->pageTitleMock->expects($this->atLeastOnce())->method('set')->willReturnSelf(); $this->model = new \Magento\Sales\Block\Order\History($this->context, $this->orderCollectionFactory, $this->customerSession, $this->orderConfig, $data); $this->assertEquals($orderCollection, $this->model->getOrders()); }
public function testSetLayout() { $this->bundleConfig->expects($this->once())->method('isBundlingJsFiles')->willReturn(true); $filePath = 'require_js_fie_path'; $asset = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\LocalInterface'); $asset->expects($this->atLeastOnce())->method('getFilePath')->willReturn($filePath); $requireJsAsset = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\LocalInterface'); $requireJsAsset->expects($this->atLeastOnce())->method('getFilePath')->willReturn('/path/to/require/require.js'); $this->fileManager->expects($this->once())->method('createRequireJsConfigAsset')->will($this->returnValue($requireJsAsset)); $this->fileManager->expects($this->once())->method('createStaticJsAsset')->will($this->returnValue($requireJsAsset)); $this->fileManager->expects($this->once())->method('createBundleJsPool')->will($this->returnValue([$asset])); $layout = $this->getMock('Magento\\Framework\\View\\LayoutInterface'); $assetCollection = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\GroupedCollection')->disableOriginalConstructor()->getMock(); $this->pageConfig->expects($this->atLeastOnce())->method('getAssetCollection')->willReturn($assetCollection); $assetCollection->expects($this->atLeastOnce())->method('insert')->willReturn(true); $object = new Config($this->context, $this->config, $this->fileManager, $this->pageConfig, $this->bundleConfig); $object->setLayout($layout); }
/** * @covers \Magento\Cms\Helper\Page::renderPageExtended * @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 testRenderPageExtended($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->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->any())->method('setPageLayout')->with($handle)->willReturnSelf(); $this->viewMock->expects($this->any())->method('getPage')->willReturn($this->resultPageMock); $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->viewMock->expects($this->any())->method('addPageLayoutHandles')->with(['id' => $pageIdentifier])->willReturn(true); $this->eventManagerMock->expects($this->any())->method('dispatch')->with('cms_page_render', ['page' => $this->pageMock, 'controller_action' => $this->actionMock]); $this->viewMock->expects($this->any())->method('loadLayoutUpdates')->willReturnSelf(); $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->viewMock->expects($this->any())->method('generateLayoutXml')->willReturnSelf(); $this->viewMock->expects($this->any())->method('generateLayoutBlocks')->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(); $this->viewMock->expects($this->any())->method('renderLayout')->willReturnSelf(); $this->assertEquals($expectedResult, $this->object->renderPageExtended($this->actionMock, $pageId)); }
protected function setUp() { $this->requestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParam'], [], '', false); $this->objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface'); $this->shipmentTrackMock = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment\\Track', ['load', 'getId', 'delete', '__wakeup'], [], '', false); $this->shipmentMock = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['getIncrementId', '__wakeup'], [], '', false); $this->viewMock = $this->getMock('Magento\\Backend\\Model\\View', ['loadLayout', 'getLayout', 'getPage'], [], '', false); $this->responseMock = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false); $this->shipmentLoaderMock = $this->getMock('Magento\\Shipping\\Controller\\Adminhtml\\Order\\ShipmentLoader', ['setOrderId', 'setShipmentId', 'setShipment', 'setTracking', 'load'], [], '', false); $this->resultPageMock = $this->getMockBuilder('Magento\\Framework\\View\\Result\\Page')->disableOriginalConstructor()->getMock(); $this->pageConfigMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock(); $this->pageTitleMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock(); $contextMock = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getRequest', 'getObjectManager', 'getTitle', 'getView', 'getResponse'], [], '', false); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Sales\\Model\\Order\\Shipment\\Track')->will($this->returnValue($this->shipmentTrackMock)); $contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock)); $contextMock->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->objectManagerMock)); $contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->viewMock)); $contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock)); $this->controller = new \Magento\Shipping\Controller\Adminhtml\Order\Shipment\RemoveTrack($contextMock, $this->shipmentLoaderMock); $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); }
/** * 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()); }
/** * @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'; $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(); if ($expectedResult) { $expectedResult = $this->resultPageMock; } $this->assertSame($expectedResult, $this->object->prepareResultPage($this->actionMock, $pageId)); }
/** * @param $contentType * @param $attributes * @param $ieCondition * @param $expectedResult * @dataProvider dataProviderRenderAsset */ public function testRenderAsset($contentType, $attributes, $ieCondition, $expectedResult) { $assetUrl = 'url'; $assetNoRoutUrl = 'no_route_url'; $exception = new \Magento\Framework\Exception('my message'); $assetMock1 = $this->getMock('Magento\\Framework\\View\\Asset\\AssetInterface'); $assetMock1->expects($this->once())->method('getUrl')->willReturn($assetUrl); $assetMock2 = $this->getMock('Magento\\Framework\\View\\Asset\\AssetInterface'); $assetMock2->expects($this->once())->method('getUrl')->willThrowException($exception); $groupAssets = [$assetMock1, $assetMock2]; $this->pageConfigMock->expects($this->once())->method('getAssetCollection')->willReturn($this->assetsCollection); $this->assetsCollection->expects($this->once())->method('getGroups')->willReturn([$this->propertyGroupMock]); $this->propertyGroupMock->expects($this->once())->method('getAll')->willReturn($groupAssets); $this->propertyGroupMock->expects($this->any())->method('getProperty')->willReturnMap([[GroupedCollection::PROPERTY_CAN_MERGE, true], [GroupedCollection::PROPERTY_CONTENT_TYPE, $contentType], ['attributes', $attributes], ['ie_condition', $ieCondition]]); $this->assetMinifyServiceMock->expects($this->once())->method('getAssets')->with($groupAssets)->willReturn($groupAssets); $this->assetMergeServiceMock->expects($this->once())->method('getMergedAssets')->with($groupAssets, $contentType)->willReturnArgument(0); $this->loggerMock->expects($this->once())->method('critical')->with($exception); $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('', ['_direct' => 'core/index/notFound'])->willReturn($assetNoRoutUrl); $this->assertEquals($expectedResult, $this->renderer->renderAssets()); }
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()); }
public function testLoadFileSystemWithPageLayout() { $handles = ['fixture_handle_with_page_layout']; $expectedHandles = ['fixture_handle_with_page_layout', 'fixture_handle_page_layout']; $expectedResult = ' <root> <referenceContainer name="main.container"> <block class="Magento\\Framework\\View\\Element\\Template" template="fixture_template_one.phtml"/> </referenceContainer> <container name="main.container" /> </root> '; $this->pageConfig->expects($this->at(0))->method('getPageLayout')->will($this->returnValue(false)); $this->pageConfig->expects($this->at(1))->method('getPageLayout')->will($this->returnValue(false)); $this->pageConfig->expects($this->at(2))->method('setPageLayout')->with('fixture_handle_page_layout'); $this->pageConfig->expects($this->at(3))->method('getPageLayout')->will($this->returnValue('fixture_handle_page_layout')); $this->assertEmpty($this->_model->getHandles()); $this->assertEmpty($this->_model->asString()); $this->_model->load($handles); $this->assertEquals($expectedHandles, $this->_model->getHandles()); $actualResult = '<root>' . $this->_model->asString() . '</root>'; $this->assertXmlStringEqualsXmlString($expectedResult, $actualResult); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ 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', 'save'], [], '', 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', null, $carrier], ['number', null, $number], ['title', null, $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)); $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->view->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->response->expects($this->once())->method('setBody')->with($html); $this->assertNull($this->controller->execute()); }