/** * Init context object * * @param array $additionalParams * @return \PHPUnit_Framework_MockObject_MockObject */ protected function initContext(array $additionalParams = []) { $productActionMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Action', [], [], '', false); $objectManagerMock = $this->getMockForAbstractClass('Magento\\Framework\\ObjectManagerInterface'); $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($productActionMock)); $block = $this->getMockBuilder('\\Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->getMockForAbstractClass(); $this->layout = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->setMethods(['getBlock'])->disableOriginalConstructor()->getMock(); $this->layout->expects($this->any())->method('getBlock')->will($this->returnValue($block)); $eventManager = $this->getMockBuilder('Magento\\Framework\\Event\\Manager')->setMethods(['dispatch'])->disableOriginalConstructor()->getMock(); $eventManager->expects($this->any())->method('dispatch')->will($this->returnSelf()); $title = $this->getMockBuilder('\\Magento\\Framework\\App\\Action\\Title')->setMethods(['add'])->disableOriginalConstructor()->getMock(); $title->expects($this->any())->method('prepend')->withAnyParameters()->will($this->returnSelf()); $requestInterfaceMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->setMethods(['getParam', 'getPost', 'getFullActionName', 'getPostValue'])->disableOriginalConstructor()->getMock(); $responseInterfaceMock = $this->getMockBuilder('Magento\\Framework\\App\\ResponseInterface')->setMethods(['setRedirect', 'sendResponse'])->getMock(); $managerInterfaceMock = $this->getMock('Magento\\Framework\\Message\\ManagerInterface'); $sessionMock = $this->getMock('Magento\\Backend\\Model\\Session', ['getProductData', 'setProductData'], [], '', false); $actionFlagMock = $this->getMock('Magento\\Framework\\App\\ActionFlag', [], [], '', false); $helperDataMock = $this->getMock('Magento\\Backend\\Helper\\Data', [], [], '', false); $this->context = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getRequest', 'getResponse', 'getObjectManager', 'getEventManager', 'getMessageManager', 'getSession', 'getActionFlag', 'getHelper', 'getTitle', 'getView', 'getResultRedirectFactory', 'getResultFactory'], [], '', false); $this->context->expects($this->any())->method('getTitle')->will($this->returnValue($title)); $this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager)); $this->context->expects($this->any())->method('getRequest')->will($this->returnValue($requestInterfaceMock)); $this->context->expects($this->any())->method('getResponse')->will($this->returnValue($responseInterfaceMock)); $this->context->expects($this->any())->method('getObjectManager')->will($this->returnValue($objectManagerMock)); $this->context->expects($this->any())->method('getMessageManager')->will($this->returnValue($managerInterfaceMock)); $this->context->expects($this->any())->method('getSession')->will($this->returnValue($sessionMock)); $this->context->expects($this->any())->method('getActionFlag')->will($this->returnValue($actionFlagMock)); $this->context->expects($this->any())->method('getHelper')->will($this->returnValue($helperDataMock)); foreach ($additionalParams as $property => $object) { $this->context->expects($this->any())->method('get' . ucfirst($property))->willReturn($object); } $this->session = $sessionMock; $this->request = $requestInterfaceMock; return $this->context; }
/** * @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]); }
/** * @param bool $cacheState * @param bool $varnishIsEnabled * @param bool $scopeIsPrivate * @param int|null $blockTtl * @param string $expectedOutput * @dataProvider processLayoutRenderDataProvider */ public function testExecute($cacheState, $varnishIsEnabled, $scopeIsPrivate, $blockTtl, $expectedOutput) { $eventMock = $this->getMock('Magento\\Framework\\Event', ['getLayout', 'getElementName', 'getTransport'], [], '', false); $this->_observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock)); $eventMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->_layoutMock)); $this->_configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState)); if ($cacheState) { $eventMock->expects($this->once())->method('getElementName')->will($this->returnValue('blockName')); $eventMock->expects($this->once())->method('getTransport')->will($this->returnValue($this->_transport)); $this->_layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true)); $this->_layoutMock->expects($this->any())->method('getUpdate')->will($this->returnSelf()); $this->_layoutMock->expects($this->any())->method('getHandles')->will($this->returnValue([])); $this->_layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($this->_blockMock)); if ($varnishIsEnabled) { $this->_blockMock->expects($this->once())->method('getData')->with('ttl')->will($this->returnValue($blockTtl)); $this->_blockMock->expects($this->any())->method('getUrl')->will($this->returnValue('page_cache/block/wrapesi/with/handles/and/other/stuff')); } if ($scopeIsPrivate) { $this->_blockMock->expects($this->once())->method('getNameInLayout')->will($this->returnValue('testBlockName')); $this->_blockMock->expects($this->once())->method('isScopePrivate')->will($this->returnValue($scopeIsPrivate)); } $this->_configMock->expects($this->any())->method('getType')->will($this->returnValue($varnishIsEnabled)); } $this->_model->execute($this->_observerMock); $this->assertEquals($expectedOutput, $this->_transport['output']); }
public function testGetItemRowTotalAfterDiscountHtml() { $html = '$34.28'; $this->layoutMock->expects($this->once())->method('getBlock')->with('item_row_total_after_discount')->will($this->returnValue($this->priceRenderBlock)); $this->priceRenderBlock->expects($this->once())->method('setItem')->with($this->itemMock); $this->priceRenderBlock->expects($this->once())->method('toHtml')->will($this->returnValue($html)); $this->assertEquals($html, $this->block->getItemRowTotalAfterDiscountHtml($this->itemMock)); }
public function testGetItemPrice() { $html = '$34.28'; $this->layoutMock->expects($this->once())->method('getBlock')->with('item_price')->will($this->returnValue($this->priceRenderBlock)); $this->priceRenderBlock->expects($this->once())->method('setItem')->with($this->itemMock); $this->priceRenderBlock->expects($this->once())->method('toHtml')->will($this->returnValue($html)); $this->assertEquals($html, $this->block->getItemPrice($this->itemMock)); }
public function testAroundRenderTrue() { $attributeMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false); $this->filterMock->expects($this->atLeastOnce())->method('getAttributeModel')->willReturn($attributeMock); $this->filterMock->expects($this->once())->method('hasAttributeModel')->willReturn(true); $this->swatchHelperMock->expects($this->once())->method('isSwatchAttribute')->with($attributeMock)->willReturn(true); $this->layoutMock->expects($this->once())->method('createBlock')->willReturn($this->blockMock); $this->blockMock->expects($this->once())->method('setSwatchFilter')->will($this->returnSelf()); $this->plugin->aroundRender($this->filterRendererMock, $this->closureMock, $this->filterMock); }
/** * 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); }
/** * 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()); }
/** * @covers \Magento\Email\Controller\Adminhtml\Email\Template\Index::execute */ public function testExecute() { $this->prepareExecute(); $this->viewMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($this->layoutMock); $this->layoutMock->expects($this->at(0))->method('getBlock')->with('menu')->will($this->returnValue($this->menuBlockMock)); $this->menuBlockMock->expects($this->any())->method('getMenuModel')->will($this->returnSelf()); $this->menuBlockMock->expects($this->any())->method('getParentItems')->will($this->returnValue([])); $this->viewMock->expects($this->once())->method('getPage')->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->once())->method('getConfig')->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->once())->method('getTitle')->willReturn($this->pageTitleMock); $this->pageTitleMock->expects($this->once())->method('prepend')->with('Email Templates'); $this->layoutMock->expects($this->at(1))->method('getBlock')->with('breadcrumbs')->will($this->returnValue($this->breadcrumbsBlockMock)); $this->breadcrumbsBlockMock->expects($this->any())->method('addLink')->willReturnSelf(); $this->assertNull($this->indexController->execute()); }
public function 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(); }
public function setUp() { $this->request = $this->getMock('Magento\\Framework\\App\\RequestInterface'); $this->response = $this->getMock('Magento\\Framework\\App\\ResponseInterface'); $this->categoryHelper = $this->getMock('Magento\\Catalog\\Helper\\Category', [], [], '', false); $this->objectManager = $this->getMock('Magento\\Framework\\ObjectManager', [], [], '', false); $this->eventManager = $this->getMock('Magento\\Framework\\Event\\ManagerInterface'); $this->update = $this->getMock('Magento\\Framework\\View\\Layout\\ProcessorInterface'); $this->layout = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false); $this->layout->expects($this->any())->method('getUpdate')->will($this->returnValue($this->update)); $this->view = $this->getMock('Magento\\Framework\\App\\ViewInterface'); $this->view->expects($this->any())->method('getLayout')->will($this->returnValue($this->layout)); $this->context = $this->getMock('Magento\\Backend\\App\\Action\\Context', [], [], '', false); $this->context->expects($this->any())->method('getRequest')->will($this->returnValue($this->request)); $this->context->expects($this->any())->method('getResponse')->will($this->returnValue($this->response)); $this->context->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->objectManager)); $this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($this->eventManager)); $this->context->expects($this->any())->method('getView')->will($this->returnValue($this->view)); $this->category = $this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false); $this->categoryFactory = $this->getMock('Magento\\Catalog\\Model\\CategoryFactory', ['create'], [], '', false); $this->store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface'); $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store)); $this->catalogDesign = $this->getMock('Magento\\Catalog\\Model\\Design', [], [], '', false); $this->layoutHelper = $this->getMock('Magento\\Theme\\Helper\\Layout', [], [], '', false); $this->action = (new ObjectManager($this))->getObject('Magento\\Catalog\\Controller\\Category\\View', ['context' => $this->context, 'catalogDesign' => $this->catalogDesign, 'categoryFactory' => $this->categoryFactory, 'storeManager' => $this->storeManager]); }
public function testExecute() { $blocks = ['block1', 'block2']; $handles = ['handle1', 'handle2']; $originalRequest = '{"route":"route","controller":"controller","action":"action","uri":"uri"}'; $expectedData = ['block1' => 'data1', 'block2' => 'data2']; $blockInstance1 = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false); $blockInstance1->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block1'])); $blockInstance2 = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false); $blockInstance2->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block2'])); $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true)); $this->requestMock->expects($this->at(1))->method('getRouteName')->will($this->returnValue('magento_pagecache')); $this->requestMock->expects($this->at(2))->method('getControllerName')->will($this->returnValue('block')); $this->requestMock->expects($this->at(3))->method('getActionName')->will($this->returnValue('render')); $this->requestMock->expects($this->at(4))->method('getRequestUri')->will($this->returnValue('uri')); $this->requestMock->expects($this->at(5))->method('getParam')->with($this->equalTo('originalRequest'))->will($this->returnValue($originalRequest)); $this->requestMock->expects($this->at(10))->method('getParam')->with($this->equalTo('blocks'), $this->equalTo(''))->will($this->returnValue(json_encode($blocks))); $this->requestMock->expects($this->at(11))->method('getParam')->with($this->equalTo('handles'), $this->equalTo(''))->will($this->returnValue(json_encode($handles))); $this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles)); $this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock)); $this->layoutMock->expects($this->at(0))->method('getBlock')->with($this->equalTo($blocks[0]))->will($this->returnValue($blockInstance1)); $this->layoutMock->expects($this->at(1))->method('getBlock')->with($this->equalTo($blocks[1]))->will($this->returnValue($blockInstance2)); $this->translateInline->expects($this->once())->method('processResponseBody')->with($expectedData)->willReturnSelf(); $this->responseMock->expects($this->once())->method('appendBody')->with($this->equalTo(json_encode($expectedData))); $this->action->execute(); }
/** * @param $cacheState * @param $layoutIsCacheable * @param $expectedTags * @param $configCacheType * @param $ttl * @dataProvider afterGetOutputDataProvider */ public function testAfterGetOutput($cacheState, $layoutIsCacheable, $expectedTags, $configCacheType, $ttl) { $html = 'html'; $this->configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState)); $blockStub = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', null, [], '', false); $blockStub->setTtl($ttl); $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue($layoutIsCacheable)); $this->layoutMock->expects($this->any())->method('getAllBlocks')->will($this->returnValue([$blockStub])); $this->configMock->expects($this->any())->method('getType')->will($this->returnValue($configCacheType)); if ($layoutIsCacheable && $cacheState) { $this->responseMock->expects($this->once())->method('setHeader')->with('X-Magento-Tags', $expectedTags); } else { $this->responseMock->expects($this->never())->method('setHeader'); } $output = $this->model->afterGetOutput($this->layoutMock, $html); $this->assertSame($output, $html); }
public function testAddDefaultHandle() { $processor = $this->getMock('Magento\\Framework\\View\\Layout\\ProcessorInterface', [], [], '', false); $processor->expects($this->once())->method('addHandle')->with('module_controller_action'); $this->layout->expects($this->once())->method('getUpdate')->will($this->returnValue($processor)); $this->request->expects($this->once())->method('getFullActionName')->will($this->returnValue('Module_Controller_Action')); $this->assertSame($this->resultLayout, $this->resultLayout->addDefaultHandle()); }
protected function setUp() { $this->layout = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->setMethods(['addHandle', 'getUpdate', 'isLayoutDefined'])->disableOriginalConstructor()->getMock(); $this->layoutFactory = $this->getMockBuilder('Magento\\Framework\\View\\LayoutFactory')->disableOriginalConstructor()->getMock(); $this->layoutFactory->expects($this->any())->method('create')->will($this->returnValue($this->layout)); $this->layoutMerge = $this->getMockBuilder('Magento\\Framework\\View\\Model\\Layout\\Merge')->disableOriginalConstructor()->getMock(); $this->layout->expects($this->any())->method('getUpdate')->will($this->returnValue($this->layoutMerge)); $this->request = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock(); $this->pageConfig = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock(); $this->viewFileSystem = $this->getMockBuilder('Magento\\Framework\\View\\FileSystem')->disableOriginalConstructor()->getMock(); $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->context = $objectManagerHelper->getObject('Magento\\Framework\\View\\Element\\Template\\Context', ['layout' => $this->layout, 'request' => $this->request, 'viewFileSystem' => $this->viewFileSystem, 'pageConfig' => $this->pageConfig]); $this->translateInline = $this->getMock('Magento\\Framework\\Translate\\InlineInterface'); $this->pageConfigRenderer = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config\\Renderer')->disableOriginalConstructor()->getMock(); $pageConfigRendererFactory = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config\\RendererFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $pageConfigRendererFactory->expects($this->once())->method('create')->with(['pageConfig' => $this->pageConfig])->willReturn($this->pageConfigRenderer); $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->page = $objectManagerHelper->getObject('Magento\\Framework\\View\\Result\\Page', ['isIsolated' => true, 'layoutFactory' => $this->layoutFactory, 'context' => $this->context, 'translateInline' => $this->translateInline, 'pageConfigRendererFactory' => $pageConfigRendererFactory]); }
/** * Test afterGenerateXml method with enabled module PageCache and request is Ajax and Layout is not cacheable */ public function testAfterGenerateXmlLayoutIsNotCacheable() { $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', array(), array(), '', false); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(true)); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true)); $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(false)); $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(false)); $this->visitorMock->expects($this->never())->method('setSkipRequestLogging'); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult); $this->assertSame($expectedResult, $actualResult); }
public function testExecute() { $blocks = ['block1', 'block2']; $handles = ['handle1', 'handle2']; $expectedData = ['block1' => 'data1', 'block2' => 'data2']; $blockInstance1 = $this->getMock('Magento\\PageCache\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false); $blockInstance1->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block1'])); $blockInstance2 = $this->getMock('Magento\\PageCache\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false); $blockInstance2->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block2'])); $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true)); $this->requestMock->expects($this->at(1))->method('getParam')->with($this->equalTo('blocks'), $this->equalTo(''))->will($this->returnValue(json_encode($blocks))); $this->requestMock->expects($this->at(2))->method('getParam')->with($this->equalTo('handles'), $this->equalTo(''))->will($this->returnValue(json_encode($handles))); $this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles)); $this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock)); $this->layoutMock->expects($this->at(0))->method('getBlock')->with($this->equalTo($blocks[0]))->will($this->returnValue($blockInstance1)); $this->layoutMock->expects($this->at(1))->method('getBlock')->with($this->equalTo($blocks[1]))->will($this->returnValue($blockInstance2)); $this->translateInline->expects($this->once())->method('processResponseBody')->with($expectedData)->willReturnSelf(); $this->responseMock->expects($this->once())->method('appendBody')->with($this->equalTo(json_encode($expectedData))); $this->action->execute(); }
/** * @dataProvider executeDataProvider * @param string $blockClass * @param bool $shouldSetHeaders */ public function testExecute($blockClass, $shouldSetHeaders) { $block = 'block'; $handles = array('handle1', 'handle2'); $html = 'some-html'; $mapData = array(array('blocks', '', json_encode(array($block))), array('handles', '', json_encode($handles))); $blockInstance1 = $this->getMock($blockClass, array('toHtml'), array(), '', false); $blockInstance1->expects($this->once())->method('toHtml')->will($this->returnValue($html)); $blockInstance1->setTtl(360); $this->requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap($mapData)); $this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles)); $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock)); $this->layoutMock->expects($this->once())->method('getBlock')->with($this->equalTo($block))->will($this->returnValue($blockInstance1)); if ($shouldSetHeaders) { $this->responseMock->expects($this->once())->method('setHeader')->with('X-Magento-Tags', implode(',', $blockInstance1->getIdentities())); } else { $this->responseMock->expects($this->never())->method('setHeader'); } $this->responseMock->expects($this->once())->method('appendBody')->with($this->equalTo($html)); $this->action->execute(); }
public function testExecute() { $selectedCategories = '1'; $isAnchorOnly = true; $hash = '7e6baeca2d76ca0efc3a299986d31bdc9cd796fb'; $content = 'block_content'; $this->request->expects($this->any())->method('getParam')->willReturnMap( [ ['selected', '', $selectedCategories], ['is_anchor_only', 0, $isAnchorOnly] ] ); $this->mathRandom->expects($this->once())->method('getUniqueHash')->with('categories')->willReturn($hash); $this->chooser->expects($this->once())->method('setUseMassaction')->with()->willReturnSelf(); $this->chooser->expects($this->once())->method('setId')->with($hash)->willReturnSelf(); $this->chooser->expects($this->once())->method('setIsAnchorOnly')->with($isAnchorOnly)->willReturnSelf(); $this->chooser->expects($this->once()) ->method('setSelectedCategories') ->with(explode(',', $selectedCategories)) ->willReturnSelf(); $this->chooser->expects($this->once())->method('toHtml')->willReturn($content); $this->layout->expects($this->once()) ->method('createBlock') ->with($this->blockClass) ->willReturn($this->chooser); $this->resultRaw->expects($this->once())->method('setContents')->with($content)->willReturnSelf(); $this->resultFactory->expects($this->once()) ->method('create') ->with(\Magento\Framework\Controller\ResultFactory::TYPE_RAW) ->willReturn($this->resultRaw); $this->context->expects($this->once())->method('getRequest')->willReturn($this->request); $this->context->expects($this->once())->method('getResultFactory')->willReturn($this->resultFactory); /** @var \Magento\Widget\Controller\Adminhtml\Widget\Instance\Categories $controller */ $this->controller = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this)) ->getObject( 'Magento\Widget\Controller\Adminhtml\Widget\Instance\Categories', [ 'context' => $this->context, 'mathRandom' => $this->mathRandom, 'layout' => $this->layout ] ); $this->assertSame($this->resultRaw, $this->controller->executeInternal()); }
public function testGetPagerHtml() { $limit = 10; $this->layout->expects($this->once())->method('getChildName')->will($this->returnValue('product_list_toolbar_pager')); $this->layout->expects($this->once())->method('getBlock')->will($this->returnValue($this->pagerBlock)); $this->productListHelper->expects($this->exactly(2))->method('getAvailableLimit')->will($this->returnValue([10 => 10, 20 => 20])); $this->model->expects($this->once())->method('getLimit')->will($this->returnValue($limit)); $this->pagerBlock->expects($this->once())->method('setUseContainer')->will($this->returnValue($this->pagerBlock)); $this->pagerBlock->expects($this->once())->method('setShowPerPage')->will($this->returnValue($this->pagerBlock)); $this->pagerBlock->expects($this->once())->method('setShowAmounts')->will($this->returnValue($this->pagerBlock)); $this->pagerBlock->expects($this->once())->method('setFrameLength')->will($this->returnValue($this->pagerBlock)); $this->pagerBlock->expects($this->once())->method('setJump')->will($this->returnValue($this->pagerBlock)); $this->pagerBlock->expects($this->once())->method('setLimit')->with($limit)->will($this->returnValue($this->pagerBlock)); $this->pagerBlock->expects($this->once())->method('setCollection')->will($this->returnValue($this->pagerBlock)); $this->pagerBlock->expects($this->once())->method('toHtml')->will($this->returnValue(true)); $this->assertTrue($this->block->getPagerHtml()); }
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()); }
/** * Set up instances and mock objects */ protected function setUp() { $this->request = $this->getMock('Magento\\Framework\\App\\RequestInterface'); $this->response = $this->getMock('Magento\\Framework\\App\\ResponseInterface'); $this->categoryHelper = $this->getMock('Magento\\Catalog\\Helper\\Category', [], [], '', false); $this->objectManager = $this->getMock('Magento\\Framework\\ObjectManagerInterface'); $this->eventManager = $this->getMock('Magento\\Framework\\Event\\ManagerInterface'); $this->update = $this->getMock('Magento\\Framework\\View\\Layout\\ProcessorInterface'); $this->layout = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false); $this->layout->expects($this->any())->method('getUpdate')->will($this->returnValue($this->update)); $this->pageConfig = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock(); $this->pageConfig->expects($this->any())->method('addBodyClass')->will($this->returnSelf()); $this->page = $this->getMockBuilder('Magento\\Framework\\View\\Page')->setMethods(['getConfig', 'initLayout', 'addPageLayoutHandles', 'getLayout', 'addUpdate'])->disableOriginalConstructor()->getMock(); $this->page->expects($this->any())->method('getConfig')->will($this->returnValue($this->pageConfig)); $this->page->expects($this->any())->method('addPageLayoutHandles')->will($this->returnSelf()); $this->page->expects($this->any())->method('getLayout')->will($this->returnValue($this->layout)); $this->page->expects($this->any())->method('addUpdate')->willReturnSelf(); $this->view = $this->getMock('Magento\\Framework\\App\\ViewInterface'); $this->view->expects($this->any())->method('getLayout')->will($this->returnValue($this->layout)); $this->resultFactory = $this->getMock('Magento\\Framework\\Controller\\ResultFactory', [], [], '', false); $this->resultFactory->expects($this->any())->method('create')->will($this->returnValue($this->page)); $this->context = $this->getMock('Magento\\Backend\\App\\Action\\Context', [], [], '', false); $this->context->expects($this->any())->method('getRequest')->will($this->returnValue($this->request)); $this->context->expects($this->any())->method('getResponse')->will($this->returnValue($this->response)); $this->context->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->objectManager)); $this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($this->eventManager)); $this->context->expects($this->any())->method('getView')->will($this->returnValue($this->view)); $this->context->expects($this->any())->method('getResultFactory')->will($this->returnValue($this->resultFactory)); $this->category = $this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false); $this->categoryRepository = $this->getMock('Magento\\Catalog\\Api\\CategoryRepositoryInterface'); $this->store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface'); $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store)); $this->catalogDesign = $this->getMock('Magento\\Catalog\\Model\\Design', [], [], '', false); $resultPageFactory = $this->getMockBuilder('Magento\\Framework\\View\\Result\\PageFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $resultPageFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->page)); $this->action = (new ObjectManager($this))->getObject('Magento\\Catalog\\Controller\\Category\\View', ['context' => $this->context, 'catalogDesign' => $this->catalogDesign, 'categoryRepository' => $this->categoryRepository, 'storeManager' => $this->storeManager, 'resultPageFactory' => $resultPageFactory]); }
protected function _getTreeBlock() { $this->chooserBlockMock = $this->getMock('Magento\\Catalog\\Block\\Adminhtml\\Category\\Widget\\Chooser', [], [], '', false); $this->layoutMock->expects($this->once())->method('createBlock')->will($this->returnValue($this->chooserBlockMock)); }