public function testGetBlock() { $blockName = 'block.name'; $block = $this->getMock('Magento\\Framework\\View\\Element\\BlockInterface'); $this->layout->expects($this->once())->method('getBlock')->with($blockName)->will($this->returnValue($block)); $this->assertEquals($block, $this->model->getBlock($blockName)); }
/** * @covers \Magento\Cms\Block\Adminhtml\Block\Widget\Chooser::prepareElementHtml * @param string $elementValue * @param integer|null $modelBlockId * * @dataProvider prepareElementHtmlDataProvider */ public function testPrepareElementHtml($elementValue, $modelBlockId) { $elementId = 1; $uniqId = '126hj4h3j73hk7b347jhkl37gb34'; $sourceUrl = 'cms/block_widget/chooser/126hj4h3j73hk7b347jhkl37gb34'; $config = ['key1' => 'value1']; $fieldsetId = 2; $html = 'some html'; $title = 'some title'; $this->this->setConfig($config); $this->this->setFieldsetId($fieldsetId); $this->elementMock->expects($this->atLeastOnce())->method('getId')->willReturn($elementId); $this->mathRandomMock->expects($this->atLeastOnce())->method('getUniqueHash')->with($elementId)->willReturn($uniqId); $this->urlBuilderMock->expects($this->atLeastOnce())->method('getUrl')->with('cms/block_widget/chooser', ['uniq_id' => $uniqId])->willReturn($sourceUrl); $this->layoutMock->expects($this->atLeastOnce())->method('createBlock')->with('Magento\\Widget\\Block\\Adminhtml\\Widget\\Chooser')->willReturn($this->chooserMock); $this->chooserMock->expects($this->atLeastOnce())->method('setElement')->with($this->elementMock)->willReturnSelf(); $this->chooserMock->expects($this->atLeastOnce())->method('setConfig')->with($config)->willReturnSelf(); $this->chooserMock->expects($this->atLeastOnce())->method('setFieldsetId')->with($fieldsetId)->willReturnSelf(); $this->chooserMock->expects($this->atLeastOnce())->method('setSourceUrl')->with($sourceUrl)->willReturnSelf(); $this->chooserMock->expects($this->atLeastOnce())->method('setUniqId')->with($uniqId)->willReturnSelf(); $this->elementMock->expects($this->atLeastOnce())->method('getValue')->willReturn($elementValue); $this->blockFactoryMock->expects($this->any())->method('create')->willReturn($this->modelBlockMock); $this->modelBlockMock->expects($this->any())->method('load')->with($elementValue)->willReturnSelf(); $this->modelBlockMock->expects($this->any())->method('getId')->willReturn($modelBlockId); $this->modelBlockMock->expects($this->any())->method('getTitle')->willReturn($title); $this->chooserMock->expects($this->any())->method('setLabel')->with($title)->willReturnSelf(); $this->chooserMock->expects($this->atLeastOnce())->method('toHtml')->willReturn($html); $this->elementMock->expects($this->atLeastOnce())->method('setData')->with('after_element_html', $html)->willReturnSelf(); $this->assertEquals($this->elementMock, $this->this->prepareElementHtml($this->elementMock)); }
public function testGetGridHtml() { $html = '<body></body>'; $this->layoutMock->expects($this->any())->method('getChildName')->willReturn('userGrid'); $this->layoutMock->expects($this->any())->method('renderElement')->willReturn($html); $this->model->setLayout($this->layoutMock); $this->assertEquals($html, $this->model->getGridHtml()); }
public function testAddBreadcrumbNoBlock() { $label = 'label'; $title = 'title'; $this->layoutMock->expects($this->once())->method('getBlock')->with('breadcrumbs')->willReturn(false); $this->breadcrumbsBlockMock->expects($this->never())->method('addLink'); $this->assertSame($this->resultPage, $this->resultPage->addBreadcrumb($label, $title)); }
/** * Test testGetProductPriceHtml */ public function testGetProductPriceHtml() { $expectedPriceHtml = '<html>Expected Price html with price $30</html>'; $priceRenderBlock = $this->getMock('Magento\\Framework\\Pricing\\Render', ['render'], [], '', false); $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $this->layoutMock->expects($this->once())->method('getBlock')->with('product.price.render.default')->will($this->returnValue($priceRenderBlock)); $priceRenderBlock->expects($this->once())->method('render')->will($this->returnValue($expectedPriceHtml)); $this->assertEquals($expectedPriceHtml, $this->block->getProductPriceHtml($product, 'price_code', 'zone_code')); }
public function testPrepareLayoutSuccessOnFalseGetId() { $tab = 'tab'; $this->registryMock->expects($this->once())->method('registry')->willReturn($this->layoutInterfaceMock); $this->layoutInterfaceMock->expects($this->any())->method('createBlock')->willReturnSelf(); $this->layoutInterfaceMock->expects($this->once())->method('setRole')->willReturnSelf(); $this->layoutInterfaceMock->expects($this->once())->method('setActive')->willReturn($tab); $this->layoutInterfaceMock->expects($this->once())->method('getId')->willReturn(false); $this->assertInstanceOf('Magento\\Backend\\Block\\Widget\\Tabs', $this->invokeMethod($this->model, '_prepareLayout')); }
/** * test getCustomer method, method returns depersonalized customer Data */ public function testGetCustomerDepersonalizeCustomerData() { $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(false)); $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true)); $this->viewMock->expects($this->once())->method('isLayoutLoaded')->will($this->returnValue(true)); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(true)); $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue($this->customerGroupId)); $this->customerInterfaceFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->customerDataMock)); $this->customerDataMock->expects($this->once())->method('setGroupId')->with($this->equalTo($this->customerGroupId))->will($this->returnSelf()); $this->assertEquals($this->customerDataMock, $this->currentCustomer->getCustomer()); }
public function testGetRenderer() { $this->blockMock->expects($this->any())->method('setRenderedBlock')->will($this->returnValue($this->blockMock)); $this->blockMock->expects($this->any())->method('getTemplate')->will($this->returnValue('template')); $this->blockMock->expects($this->any())->method('setTemplate')->will($this->returnValue($this->blockMock)); $this->layoutMock->expects($this->any())->method('getChildName')->will($this->returnValue(true)); /** During the first call cache will be generated */ $this->assertInstanceOf('\\Magento\\Framework\\View\\Element\\BlockInterface', $this->renderList->getRenderer('type', null, null)); /** Cached value should be returned during second call */ $this->assertInstanceOf('\\Magento\\Framework\\View\\Element\\BlockInterface', $this->renderList->getRenderer('type', null, 'renderer_template')); }
/** * Test method afterGenerateXml */ public function testAfterGenerateXml() { $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($this->once()))->method('isAjax')->will($this->returnValue(false)); $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true)); $this->checkoutSessionMock->expects($this->once())->method('clearStorage')->will($this->returnValue($expectedResult)); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult); $this->assertEquals($expectedResult, $actualResult); }
public function testGetProductPriceHtmlCreateBlock() { $priceType = 'wishlist_configured_price'; $expected = 'block content'; $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $renderMock = $this->getMockBuilder('\\Magento\\Framework\\Pricing\\Render')->disableOriginalConstructor()->getMock(); $renderMock->expects($this->once())->method('render')->with($priceType, $productMock, ['zone' => Render::ZONE_ITEM_LIST])->willReturn($expected); $this->layout->expects($this->once())->method('getBlock')->with('product.price.render.default')->willReturn(false); $this->layout->expects($this->once())->method('createBlock')->with('Magento\\Framework\\Pricing\\Render', 'product.price.render.default', ['data' => ['price_render_handle' => 'catalog_product_prices']])->willReturn($renderMock); $result = $this->block->getProductPriceHtml($productMock, $priceType, Render::ZONE_ITEM_LIST); $this->assertEquals($expected, $result); }
/** * @param mixed $result * @param string[] $responseArray * @dataProvider executeDataProvider */ public function testExecute($result, $responseArray) { $getParamMap = [['variable_id', null, null], ['store', 0, 0]]; $this->requestMock->expects($this->any())->method('getParam')->willReturnMap($getParamMap); $this->requestMock->expects($this->any())->method('getPost')->with('variable')->will($this->returnValue([])); $this->variableMock->expects($this->any())->method('validate')->willReturn($result); if ($result instanceof \Magento\Framework\Phrase) { $this->messageManagerMock->expects($this->once())->method('addError')->with($result->getText()); $this->layoutMock->expects($this->once())->method('initMessages'); } $this->resultJsonMock->expects($this->once())->method('setData')->with($responseArray); $this->validateMock->execute(); }
protected function setUp() { $this->_layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false); $this->_columnSetMock = $this->_getColumnSetMock(); $returnValueMap = [['grid', 'grid.columnSet', 'grid.columnSet'], ['grid', 'reset_filter_button', 'reset_filter_button'], ['grid', 'search_button', 'search_button']]; $this->_layoutMock->expects($this->any())->method('getChildName')->will($this->returnValueMap($returnValueMap)); $this->_layoutMock->expects($this->any())->method('getBlock')->with('grid.columnSet')->will($this->returnValue($this->_columnSetMock)); $this->_layoutMock->expects($this->any())->method('createBlock')->with('Magento\\Backend\\Block\\Widget\\Button')->will($this->returnValue(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Backend\\Block\\Widget\\Button'))); $this->_layoutMock->expects($this->any())->method('helper')->with('Magento\\Framework\\Json\\Helper\\Data')->will($this->returnValue(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\Json\\Helper\\Data'))); $this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Backend\\Block\\Widget\\Grid'); $this->_block->setLayout($this->_layoutMock); $this->_block->setNameInLayout('grid'); }
protected function setUp() { $this->contextMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\Template\\Context')->disableOriginalConstructor()->getMock(); $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['isSecure', 'getModuleName', 'setModuleName', 'getActionName', 'setActionName', 'getParam', 'getCookie'])->getMock(); $this->layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->disableOriginalConstructor()->getMock(); $this->layoutUpdateMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\ProcessorInterface')->disableOriginalConstructor()->getMock(); $this->urlBuilderMock = $this->getMockBuilder('Magento\\Framework\\UrlInterface')->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock); $this->contextMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock); $this->contextMock->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilderMock); $this->layoutMock->expects($this->any())->method('getUpdate')->willReturn($this->layoutUpdateMock); $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->blockJavascript = $objectManager->getObject('Magento\\PageCache\\Block\\Javascript', ['context' => $this->contextMock]); }
private function initLayoutMock() { $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock)); $this->viewMock->expects($this->once())->method('loadLayout')->willReturnSelf(); $this->viewMock->expects($this->once())->method('renderLayout')->willReturnSelf(); $this->layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($this->blockMock)); }
/** * @param string $actionName * @return \Magento\Integration\Controller\Adminhtml\Integration */ protected function _createIntegrationController($actionName) { // Mock Layout passed into constructor $this->_viewMock = $this->getMock('Magento\\Framework\\App\\ViewInterface'); $this->_layoutMock = $this->getMock('Magento\\Framework\\View\\LayoutInterface'); $this->_layoutMergeMock = $this->getMockBuilder('Magento\\Core\\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('Magento\\Framework\\Logger', [], [], '', false)]); $loggerMock = $this->getMockBuilder('Magento\\Framework\\Logger')->disableOriginalConstructor()->getMock(); $loggerMock->expects($this->any())->method('logException')->will($this->returnSelf()); $menuMock->expects($this->any())->method('getParentItems')->will($this->returnValue(array())); $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->_escaper->expects($this->any())->method('escapeHtml')->will($this->returnArgument(0)); $contextParameters = array('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 = array('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; }
/** * Set up before test * * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setUp() { $this->_objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->_installerMock = $this->getMock('\\Magento\\Install\\Model\\Installer', array('isApplicationInstalled'), array(), '', false); $this->_installerMock->expects($this->any())->method('isApplicationInstalled')->will($this->returnValue(true)); $this->_blockMock = $this->getMock('\\Magento\\Install\\Block\\Locale', array(), array(), '', false); $this->_layoutMock = $this->getMock('\\Magento\\Framework\\View\\Layout', array('getBlock', 'initMessages', 'addBlock'), array(), '', false); $this->_layoutMock->expects($this->any())->method('initMessages')->withAnyParameters()->will($this->returnValue(true)); $this->_layoutMock->expects($this->any())->method('addBlock')->withAnyParameters()->will($this->returnValue(true)); $this->_viewMock = $this->getMockForAbstractClass('\\Magento\\Framework\\App\\ViewInterface', array(), '', false, false, true, array('getLayout')); $this->_viewMock->expects($this->any())->method('getLayout')->withAnyParameters()->will($this->returnValue($this->_layoutMock)); $this->_requestMock = $this->_getClearMock('\\Magento\\Framework\\App\\RequestInterface'); $this->_responseMock = $this->_getClearMock('\\Magento\\Framework\\App\\ResponseInterface'); $this->_actionFlagMock = $this->_getClearMock('\\Magento\\Framework\\App\\ActionFlag'); $this->_contextMock = $this->getMock('\\Magento\\Framework\\App\\Action\\Context', array('getView', 'getRequest', 'getResponse', 'getActionFlag'), array(), '', false); $this->_contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->_viewMock)); $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('getActionFlag')->will($this->returnValue($this->_actionFlagMock)); $this->_blockContextMock = $this->getMock('\\Magento\\Framework\\View\\Element\\Template\\Context', array(), array(), '', false); $this->_wizardMock = $this->getMock('\\Magento\\Install\\Model\\Wizard', array('getStepByRequest'), array(), '', false); $this->_wizardMock->expects($this->any())->method('getStepByRequest')->withAnyParameters()->will($this->returnValue(false)); $this->_sessionMock = $this->getMock('\\Magento\\Framework\\Session\\Generic', array('getLocale'), array(), '', false); $this->_sessionMock->expects($this->any())->method('getLocale')->will($this->returnValue(self::LOCALE)); $this->_block = $this->_objectManager->getObject('Magento\\Install\\Block\\Locale', array('context' => $this->_blockContextMock, 'installer' => $this->_installerMock, 'installWizard' => $this->_wizardMock, 'session' => $this->_sessionMock, 'data' => array())); $this->_layoutMock->expects($this->any())->method('getBlock')->with('install.locale')->will($this->returnValue($this->_block)); $this->_controller = $this->_objectManager->getObject('Magento\\Install\\Controller\\Wizard\\Locale', array('context' => $this->_contextMock, 'configScope' => $this->_getClearMock('Magento\\Framework\\Config\\Scope'), 'installer' => $this->_getClearMock('Magento\\Install\\Model\\Installer'), 'wizard' => $this->_wizardMock, 'session' => $this->_sessionMock, 'dbUpdater' => $this->_getClearMock('Magento\\Framework\\Module\\UpdaterInterface'), 'storeManager' => $this->_getClearMock('Magento\\Store\\Model\\StoreManagerInterface'), 'appState' => $this->_getClearMock('Magento\\Framework\\App\\State'))); }
public function testRenderPriceString() { $includeContainer = false; $priceHtml = 'price-html'; $selection = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $bundlePrice = $this->getMockBuilder('Magento\\Bundle\\Pricing\\Price\\BundleOptionPrice')->disableOriginalConstructor()->getMock(); $priceInfo = $this->getMock('Magento\\Framework\\Pricing\\PriceInfo\\Base', [], [], '', false); $amount = $this->getMock('Magento\\Framework\\Pricing\\Amount\\AmountInterface'); $priceRenderBlock = $this->getMockBuilder('Magento\\Framework\\Pricing\\Render')->disableOriginalConstructor()->setMethods(['renderAmount'])->getMock(); $this->product->expects($this->atLeastOnce())->method('getPriceInfo')->will($this->returnValue($priceInfo)); $priceInfo->expects($this->atLeastOnce())->method('getPrice')->with('bundle_option')->will($this->returnValue($bundlePrice)); $bundlePrice->expects($this->atLeastOnce())->method('getOptionSelectionAmount')->with($selection)->will($this->returnValue($amount)); $this->layout->expects($this->atLeastOnce())->method('getBlock')->with('product.price.render.default')->will($this->returnValue($priceRenderBlock)); $priceRenderBlock->expects($this->atLeastOnce())->method('renderAmount')->with($amount, $bundlePrice, $selection, ['include_container' => $includeContainer])->will($this->returnValue($priceHtml)); $this->assertEquals($priceHtml, $this->block->renderPriceString($selection, $includeContainer)); }
public function testLayoutIsNotCacheable() { $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->willReturn(true); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true); $this->requestMock->expects($this->once($this->once()))->method('isAjax')->willReturn(false); $this->layoutMock->expects($this->once())->method('isCacheable')->willReturn(false); $this->catalogSessionMock->expects($this->never())->method('clearStorage'); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $this->resultLayout); $this->assertEquals($this->resultLayout, $actualResult); }
public function testAddErrorMessageWhenProductWithoutStores() { $form = $this->getMock('Magento\\Framework\\Data\\Form', [], [], '', false); $form->expects($this->any())->method('getElement')->will($this->returnValue($this->getMockForAbstractClass('\\Magento\\Framework\\Data\\Form\\Element\\AbstractElement', [], '', false))); $this->formFactory->expects($this->once())->method('create')->will($this->returnValue($form)); $fieldset = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false); $form->expects($this->once())->method('addFieldset')->will($this->returnValue($fieldset)); $storeElement = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\AbstractElement', ['setAfterElementHtml', 'setValues'], [], '', false); $fieldset->expects($this->at(2))->method('addField')->with('store_id', 'select', ['label' => 'Store', 'title' => 'Store', 'name' => 'store_id', 'required' => true, 'value' => 0])->willReturn($storeElement); $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $product->expects($this->any())->method('getId')->willReturn('product_id'); $product->expects($this->once())->method('getStoreIds')->willReturn([]); $this->productFactory->expects($this->once())->method('create')->willReturn($product); $this->categoryFactory->expects($this->once())->method('create')->willReturn($this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false)); $storeElement->expects($this->once())->method('setAfterElementHtml'); $storeElement->expects($this->once())->method('setValues')->with([]); $this->layout->expects($this->once())->method('createBlock')->willReturn($this->getMock('Magento\\Framework\\Data\\Form\\Element\\Renderer\\RendererInterface')); $this->form->toHtml(); }
public function testGetProductPriceHtml() { $id = 6; $expectedHtml = ' <div class="price-box price-final_price"> <span class="regular-price" id="product-price-' . $id . '"> <span class="price">$0.00</span> </span> </div>'; $type = 'widget-new-list'; $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getId'], [], '', false, false); $productMock->expects($this->once())->method('getId')->willReturn($id); $arguments = ['price_id' => 'old-price-' . $id . '-' . $type, 'display_minimal_price' => true, 'include_container' => true, 'zone' => \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST]; $priceBoxMock = $this->getMock('Magento\\Framework\\Pricing\\Render', ['render'], [], '', false, false); $this->layout->expects($this->once())->method('getBlock')->with($this->equalTo('product.price.render.default'))->willReturn($priceBoxMock); $priceBoxMock->expects($this->once())->method('render')->with($this->equalTo('final_price'), $this->equalTo($productMock), $this->equalTo($arguments))->willReturn($expectedHtml); $result = $this->block->getProductPriceHtml($productMock, $type); $this->assertEquals($expectedHtml, $result); }
/** * {@inheritDoc} */ protected function setUp() { $this->requestMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\App\\RequestInterface', ['isDispatched', 'initForward', 'setDispatched', 'isForwarded']); $this->breadcrumbsBlockMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\View\\Element\\BlockInterface', ['addLink']); $this->menuBlockMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\View\\Element\\BlockInterface', ['setActive', 'getMenuModel']); $this->viewMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\App\\ViewInterface'); $this->layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->disableOriginalConstructor()->getMock(); $this->switcherBlockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\BlockInterface')->disableOriginalConstructor()->getMock(); $this->contextMock = $this->getMockBuilder('Magento\\Backend\\App\\Action\\Context')->disableOriginalConstructor()->getMock(); $this->fileFactoryMock = $this->getMockBuilder('Magento\\Framework\\App\\Response\\Http\\FileFactory')->disableOriginalConstructor()->getMock(); $this->menuModelMock = $this->getMockBuilder('Magento\\Backend\\Model\\Menu')->disableOriginalConstructor()->getMock(); $this->abstractBlockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\AbstractBlock')->setMethods(['getCsvFile', 'getExcelFile', 'setSaveParametersInSession', 'getCsv', 'getExcel'])->disableOriginalConstructor()->getMock(); $this->menuModelMock->expects($this->any())->method('getParentItems')->willReturn([]); $this->menuBlockMock->expects($this->any())->method('getMenuModel')->willReturn($this->menuModelMock); $this->viewMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock); $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock); $this->contextMock->expects($this->any())->method('getView')->willReturn($this->viewMock); $this->layoutMock->expects($this->any())->method('getBlock')->will($this->returnValueMap([['breadcrumbs', $this->breadcrumbsBlockMock], ['menu', $this->menuBlockMock], ['store_switcher', $this->switcherBlockMock]])); $this->layoutMock->expects($this->any())->method('getChildBlock')->willReturn($this->abstractBlockMock); }
/** * @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)); }
public function testToHtml() { $childNameOne = 'child.1'; $childNameTextOne = 'child.1 text'; $childNameTwo = 'child.2'; $childNames = [$childNameOne, $childNameTwo]; $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false); /** * @var Item|\PHPUnit_Framework_MockObject_MockObject $itemMock */ $itemMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Item')->disableOriginalConstructor()->getMock(); $this->model->setItem($itemMock); $this->layoutMock->expects($this->once())->method('getChildNames')->with($this->model->getNameInLayout())->willReturn($childNames); /** @var Generic|\PHPUnit_Framework_MockObject_MockObject $childMockOne */ $childMockOne = $this->getMockBuilder('Magento\\Checkout\\Block\\Cart\\Item\\Renderer\\Actions\\Generic')->disableOriginalConstructor()->getMock(); $childMockOne->expects($this->once())->method('setItem')->with($itemMock); $childMockTwo = false; $this->layoutMock->expects($this->once())->method('renderElement')->with($childNameOne, false)->willReturn($childNameTextOne); $this->layoutMock->expects($this->exactly(2))->method('getBlock')->willReturnMap([[$childNameOne, $childMockOne], [$childNameTwo, $childMockTwo]]); $this->assertEquals($childNameTextOne, $this->model->toHtml()); }
public function testCountrySelect() { $html = "<select>"; $default = 'default'; $name = 'US'; $id = '3'; $title = "United States"; $directoryDataMock = $this->getMockBuilder('\\Magento\\Braintree\\Block\\Directory\\Data')->disableOriginalConstructor()->getMock(); $this->layoutMock->expects($this->any())->method('getChildName')->willReturn(true); $this->layoutMock->expects($this->any())->method('getBlock')->willReturn($directoryDataMock); $directoryDataMock->expects($this->once())->method('getCountryHtmlSelect')->with($default, $name, $id, $title)->willReturn($html); $this->assertEquals($html, $this->block->countrySelect($name, $id, $default, $title)); }
/** * Set up test * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setUp() { $this->contextMock = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getAuthorization', 'getSession', 'getActionFlag', 'getAuth', 'getView', 'getHelper', 'getBackendUrl', 'getFormKeyValidator', 'getLocaleResolver', 'getCanUseBaseUrl', 'getRequest', 'getResponse', 'getObjectManager', 'getMessageManager'], [], '', false); $this->response = $this->getMock('Magento\\Framework\\App\\ResponseInterface', ['setRedirect', 'sendResponse'], [], '', false); $this->request = $this->getMockForAbstractClass('\\Magento\\Framework\\App\\RequestInterface', ['getParam', 'getRequest'], '', false); $this->view = $this->getMock('\\Magento\\Framework\\App\\ViewInterface', ['loadLayout', 'getPage', 'getConfig', 'getTitle', 'loadLayoutUpdates', 'renderLayout', 'getDefaultLayoutHandle', 'generateLayoutXml', 'addPageLayoutHandles', 'generateLayoutBlocks', 'getLayout', 'addActionLayoutHandles', 'setIsLayoutLoaded', 'isLayoutLoaded'], [], '', false); $this->block = $this->getMock('\\Magento\\Framework\\View\\Element\\AbstractBlock', ['setActive', 'getMenuModel'], [], '', false); $this->layout = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\LayoutInterface', ['getBlock'], '', false); $this->menu = $this->getMock('\\Magento\\Backend\\Model\\Menu', ['getParentItems'], [], '', false); $this->items = $this->getMock('\\Magento\\Backend\\Model\\Menu\\Item', ['getParentItems'], [], '', false); $this->contextMock->expects($this->any())->method("getRequest")->willReturn($this->request); $this->contextMock->expects($this->any())->method("getResponse")->willReturn($this->response); $this->contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->view)); $this->page = $this->getMock('\\Magento\\Framework\\View\\Result\\Page', ['getConfig'], [], '', false); $this->config = $this->getMock('\\Magento\\Framework\\View\\Result\\Page', ['getTitle'], [], '', false); $this->title = $this->getMock('\\Title', ['prepend'], [], '', false); $this->block->expects($this->any())->method('setActive')->will($this->returnValue(1)); $this->view->expects($this->any())->method('getLayout')->will($this->returnValue($this->layout)); $this->layout->expects($this->any())->method('getBlock')->with('menu')->will($this->returnValue($this->block)); $this->block->expects($this->any())->method('getMenuModel')->will($this->returnValue($this->menu)); $this->menu->expects($this->any())->method('getParentItems')->will($this->returnValue($this->items)); $this->object = new \Magento\Indexer\Controller\Adminhtml\Indexer\ListAction($this->contextMock); }
/** * @param $state * @param $restoreQuote * @param $expectedGotoSection * @dataProvider testNotAllowedOrderStateDataProvider */ public function testExecuteNotAllowedOrderState($state, $restoreQuote, $expectedGotoSection) { $lastRealOrderId = '000000001'; $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock)); $this->layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($this->blockMock)); $this->checkoutSessionMock->expects($this->any())->method('getLastRealOrderId')->will($this->returnValue($lastRealOrderId)); $this->checkoutSessionMock->expects($this->any())->method('getLastRealOrder')->will($this->returnValue($this->orderMock)); $this->checkoutSessionMock->expects($this->any())->method('restoreQuote')->will($this->returnValue($restoreQuote)); $this->orderFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->orderMock)); $this->orderMock->expects($this->once())->method('loadByIncrementId')->with($lastRealOrderId)->will($this->returnSelf()); $this->orderMock->expects($this->once())->method('getIncrementId')->will($this->returnValue($lastRealOrderId)); $this->orderMock->expects($this->once())->method('getState')->will($this->returnValue($state)); $this->blockMock->expects($this->at(0))->method('setData')->with('goto_section', $expectedGotoSection)->will($this->returnSelf()); $this->blockMock->expects($this->at(1))->method('setData')->with('error_msg', __('Your payment has been declined. Please try again.'))->will($this->returnSelf()); $this->returnUrl->execute(); }
/** * @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 string $actionName * @return \Magento\Integration\Controller\Adminhtml\Integration * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ 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)); $this->resultRedirectFactory = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\RedirectFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->resultFactory = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->_authMock->expects($this->any())->method('getUser')->will($this->returnValue($this->_userMock)); $this->_userMock->expects($this->any())->method('load')->willReturn($this->_userMock); $this->_backendSessionMock->expects($this->any())->method('getIntegrationData')->willReturn(['all_resources' => 1]); $contextParameters = ['view' => $this->_viewMock, 'objectManager' => $this->_objectManagerMock, 'session' => $this->_backendSessionMock, 'translator' => $this->_translateModelMock, 'request' => $this->_requestMock, 'response' => $this->_responseMock, 'messageManager' => $this->_messageManager, 'resultRedirectFactory' => $this->resultRedirectFactory, 'resultFactory' => $this->resultFactory, 'auth' => $this->_authMock, 'eventManager' => $this->_eventManagerMock]; $this->_backendActionCtxMock = $this->_objectManagerHelper->getObject('Magento\\Backend\\App\\Action\\Context', $contextParameters); $integrationCollection = $this->getMockBuilder('\\Magento\\Integration\\Model\\ResourceModel\\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); if ($actionName == 'Save') { $reflection = new \ReflectionClass(get_class($controller)); $reflectionProperty = $reflection->getProperty('securityCookie'); $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($controller, $this->securityCookieMock); } return $controller; }
public function testGetPagerHtml() { $collection = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Resource\\Product\\Collection')->setMethods(['getSize'])->disableOriginalConstructor()->getMock(); $collection->expects($this->once())->method('getSize')->willReturn(3); $this->productsList->setData('show_pager', true); $this->productsList->setData('products_per_page', 2); $this->productsList->setData('product_collection', $collection); $pagerBlock = $this->getMockBuilder('Magento\\Catalog\\Block\\Product\\Widget\\Html\\Pager')->setMethods(['toHtml', 'setUseContainer', 'setShowAmounts', 'setShowPerPage', 'setPageVarName', 'setLimit', 'setTotalLimit', 'setCollection'])->disableOriginalConstructor()->getMock(); $pagerBlock->expects($this->once())->method('setUseContainer')->willReturnSelf(); $pagerBlock->expects($this->once())->method('setShowAmounts')->willReturnSelf(); $pagerBlock->expects($this->once())->method('setShowPerPage')->willReturnSelf(); $pagerBlock->expects($this->once())->method('setPageVarName')->willReturnSelf(); $pagerBlock->expects($this->once())->method('setLimit')->willReturnSelf(); $pagerBlock->expects($this->once())->method('setTotalLimit')->willReturnSelf(); $pagerBlock->expects($this->once())->method('setCollection')->with($collection)->willReturnSelf(); $pagerBlock->expects($this->once())->method('toHtml')->willReturn('<pager_html>'); $this->layout->expects($this->once())->method('createBlock')->willReturn($pagerBlock); $this->assertEquals('<pager_html>', $this->productsList->getPagerHtml()); }
protected function setUp() { $this->objectManager = new ObjectManager($this); $this->contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); $this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class)->disableOriginalConstructor()->getMock(); $this->layoutMock = $this->getMockBuilder(LayoutInterface::class)->disableOriginalConstructor()->getMock(); $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass(); $this->productBuilderMock = $this->getMockBuilder(Builder::class)->disableOriginalConstructor()->getMock(); $this->resultMock = $this->getMockBuilder(ResultInterface::class)->setMethods(['forward', 'setJsonData', 'getLayout'])->getMockForAbstractClass(); $this->productMock = $this->getMockBuilder(ProductInterface::class)->getMockForAbstractClass(); $this->uiComponentMock = $this->getMockBuilder(UiComponent::class)->disableOriginalConstructor()->getMock(); $this->processorMock = $this->getMockBuilder(ProcessorInterface::class)->getMockForAbstractClass(); $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock); $this->resultFactoryMock->expects($this->any())->method('create')->willReturn($this->resultMock); $this->contextMock->expects($this->any())->method('getResultFactory')->willReturn($this->resultFactoryMock); $this->productBuilderMock->expects($this->any())->method('build')->willReturn($this->productMock); $this->layoutMock->expects($this->any())->method('getBlock')->willReturn($this->uiComponentMock); $this->layoutMock->expects($this->any())->method('getUpdate')->willReturn($this->processorMock); $this->resultMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock); $this->model = $this->objectManager->getObject(Reload::class, ['context' => $this->contextMock, 'productBuilder' => $this->productBuilderMock, 'layout' => $this->layoutMock]); }