/** * Test protected `_toHtml` method via public `toHtml` method. */ public function testToHtml() { $eventManager = $this->getMockBuilder('Magento\\Framework\\Event\\Manager')->disableOriginalConstructor()->setMethods(['dispatch'])->getMock(); $eventManager->expects($this->once())->method('dispatch')->will($this->returnValue(true)); $scopeConfig = $this->getMockBuilder('\\Magento\\Framework\\App\\Config')->setMethods(['getValue'])->disableOriginalConstructor()->getMock(); $scopeConfig->expects($this->once())->method('getValue')->withAnyParameters()->will($this->returnValue(false)); $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['setStoreId', 'load', 'getId', '__wakeup', '__sleep'])->getMock(); $product->expects($this->once())->method('setStoreId')->will($this->returnSelf()); $product->expects($this->once())->method('load')->will($this->returnSelf()); $product->expects($this->once())->method('getId')->will($this->returnValue(1)); $optionsBlock = $this->getMockBuilder('Magento\\Catalog\\Block\\Adminhtml\\Product\\Edit\\Tab\\Options\\Option')->setMethods(['setIgnoreCaching', 'setProduct', 'getOptionValues'])->disableOriginalConstructor()->getMock(); $optionsBlock->expects($this->once())->method('setIgnoreCaching')->with(true)->will($this->returnSelf()); $optionsBlock->expects($this->once())->method('setProduct')->with($product)->will($this->returnSelf()); $optionsBlock->expects($this->once())->method('getOptionValues')->will($this->returnValue([])); $layout = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Element\\Layout')->disableOriginalConstructor()->setMethods(['createBlock'])->getMock(); $layout->expects($this->once())->method('createBlock')->with('Magento\\Catalog\\Block\\Adminhtml\\Product\\Edit\\Tab\\Options\\Option')->will($this->returnValue($optionsBlock)); $request = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->setMethods(['getParam'])->disableOriginalConstructor()->getMock(); $request->expects($this->once())->method('getParam')->with('store')->will($this->returnValue(0)); $this->context->expects($this->once())->method('getEventManager')->will($this->returnValue($eventManager)); $this->context->expects($this->once())->method('getScopeConfig')->will($this->returnValue($scopeConfig)); $this->context->expects($this->once())->method('getLayout')->will($this->returnValue($layout)); $this->context->expects($this->once())->method('getRequest')->will($this->returnValue($request)); $this->registry->expects($this->once())->method('registry')->with('import_option_products')->will($this->returnValue([1])); $this->productFactory->expects($this->once())->method('create')->will($this->returnValue($product)); $this->block = $this->objectManagerHelper->getObject('Magento\\Catalog\\Block\\Adminhtml\\Product\\Options\\Ajax', ['context' => $this->context, 'jsonEncoder' => $this->encoderInterface, 'productFactory' => $this->productFactory, 'registry' => $this->registry]); $this->block->toHtml(); }
/** * {@inheritDoc} */ protected function setUp() { $this->localeDate = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->disableOriginalConstructor()->getMock(); $this->localeDate->expects($this->once())->method('date')->will($this->returnArgument(0)); $this->contextMock = $this->getMockBuilder('Magento\\Backend\\Block\\Context')->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->once())->method('getLocaleDate')->will($this->returnValue($this->localeDate)); $this->resolverMock = $this->getMockBuilder('Magento\\Framework\\Locale\\ResolverInterface')->getMock(); $this->date = new Date($this->contextMock, $this->resolverMock); }
protected function setUp() { $this->escaperMock = $this->getMock('Magento\\Framework\\Escaper', [], [], '', false); $this->escaperMock->expects($this->any())->method('escapeHtml')->willReturnArgument(0); $this->contextMock = $this->getMock('Magento\\Backend\\Block\\Context', ['getEscaper'], [], '', false); $this->contextMock->expects($this->any())->method('getEscaper')->will($this->returnValue($this->escaperMock)); $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->buttonRenderer = $this->objectManagerHelper->getObject('Magento\\Integration\\Block\\Adminhtml\\Widget\\Grid\\Column\\Renderer\\Button', ['context' => $this->contextMock]); }
protected function setUp() { $this->context = $this->getMockBuilder('Magento\\Backend\\Block\\Context')->setMethods(['getEscaper'])->disableOriginalConstructor()->getMock(); $this->escaper = $this->getMock('Magento\\Framework\\Escaper', ['escapeHtml'], [], '', false); $this->helper = $this->getMock('Magento\\Framework\\DB\\Helper', [], [], '', false); $this->context->expects($this->once())->method('getEscaper')->willReturn($this->escaper); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->block = $this->objectManagerHelper->getObject('Magento\\Backend\\Block\\Widget\\Grid\\Column\\Filter\\Text', ['context' => $this->context, 'resourceHelper' => $this->helper]); }
/** * Set up */ protected function setUp() { $urlModel = $this->getMock('Magento\\Backend\\Model\\Url', ['getUrl'], [], '', false); $urlModel->expects($this->any())->method('getUrl')->willReturn('url'); $this->context = $this->getMock('Magento\\Backend\\Block\\Context', ['getUrlBuilder'], [], '', false); $this->context->expects($this->any())->method('getUrlBuilder')->willReturn($urlModel); $data = []; $this->objectManagerHelper = new ObjectManagerHelper($this); $this->download = $this->objectManagerHelper->getObject('Magento\\ImportExport\\Block\\Adminhtml\\Grid\\Column\\Renderer\\Download', ['context' => $this->context, 'data' => $data]); }
/** * {@inheritDoc} */ protected function setUp() { $this->localeDate = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->disableOriginalConstructor()->getMock(); $this->localeDate->expects($this->once())->method('date')->willReturnArgument(0); $this->contextMock = $this->getMockBuilder('Magento\\Backend\\Block\\Context')->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->once())->method('getLocaleDate')->willReturn($this->localeDate); $this->resolverMock = $this->getMockBuilder('Magento\\Framework\\Locale\\ResolverInterface')->getMock(); $this->dateTimeFormatter = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\DateTimeFormatterInterface'); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->date = $objectManager->getObject('Magento\\Reports\\Block\\Adminhtml\\Sales\\Grid\\Column\\Renderer\\Date', ['context' => $this->contextMock, 'localeResolver' => $this->resolverMock, 'dateTimeFormatter' => $this->dateTimeFormatter]); $this->globalStateLocaleBackup = \Locale::getDefault(); }
protected function setUp() { $this->urlInterfaceMock = $this->getMock('Magento\\Framework\\UrlInterface', [], [], '', false); $this->contextMock = $this->getMock('Magento\\Backend\\Block\\Context', [], [], '', false); $this->contextMock->expects($this->once())->method('getUrlBuilder')->will($this->returnValue($this->urlInterfaceMock)); $this->rssFactoryMock = $this->getMock('Magento\\Rss\\Model\\RssFactory'); $this->iteratorMock = $this->getMock('Magento\\Framework\\Model\\Resource\\Iterator', [], [], '', false); $this->reviewFactoryMock = $this->getMock('Magento\\Review\\Model\\ReviewFactory'); $this->storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManager', ['getStore', 'getName'], [], '', false); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->review = $this->objectManagerHelper->getObject('Magento\\Rss\\Block\\Catalog\\Review', ['context' => $this->contextMock, 'rssFactory' => $this->rssFactoryMock, 'resourceIterator' => $this->iteratorMock, 'reviewFactory' => $this->reviewFactoryMock, 'storeManager' => $this->storeManagerMock]); }
/** * @return void */ protected function setUp() { $this->objectManagerHelper = new ObjectManagerHelper($this); $this->eventManagerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Manager')->setMethods(['dispatch'])->disableOriginalConstructor()->getMock(); $this->scopeConfigMock = $this->getMockBuilder('Magento\\Framework\\App\\Config')->setMethods(['getValue'])->disableOriginalConstructor()->getMock(); $this->themeCollectionFactoryMock = $this->getMock('Magento\\Theme\\Model\\ResourceModel\\Theme\\CollectionFactory', ['create'], [], '', false); $this->themeCollectionMock = $this->getMockBuilder('Magento\\Theme\\Model\\ResourceModel\\Theme\\Collection')->disableOriginalConstructor()->setMethods(['getItemById'])->getMock(); $this->themeMock = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock(); $this->layoutProcessorFactoryMock = $this->getMock('Magento\\Framework\\View\\Layout\\ProcessorFactory', ['create'], [], '', false); $this->layoutMergeMock = $this->getMockBuilder('Magento\\Framework\\View\\Model\\Layout\\Merge')->setMethods(['addPageHandles', 'load', 'getContainers'])->disableOriginalConstructor()->getMock(); $this->escaperMock = $this->getMock('Magento\\Framework\\Escaper', ['escapeHtml'], [], '', false); $this->contextMock = $this->getMockBuilder('Magento\\Backend\\Block\\Context')->setMethods(['getEventManager', 'getScopeConfig', 'getEscaper'])->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->once())->method('getEventManager')->willReturn($this->eventManagerMock); $this->contextMock->expects($this->once())->method('getScopeConfig')->willReturn($this->scopeConfigMock); $this->contextMock->expects($this->once())->method('getEscaper')->willReturn($this->escaperMock); }
protected function generalGetProductCollection() { $this->eventManager->expects($this->once())->method('dispatch')->will($this->returnValue(true)); $this->scopeConfig->expects($this->once())->method('getValue')->withAnyParameters()->willReturn(false); $this->cacheState->expects($this->atLeastOnce())->method('isEnabled')->withAnyParameters()->willReturn(false); $this->catalogConfig->expects($this->once())->method('getProductAttributes')->willReturn([]); $this->localDate->expects($this->any())->method('date')->willReturn(new \DateTime('now', new \DateTimeZone('UTC'))); $this->context->expects($this->once())->method('getEventManager')->willReturn($this->eventManager); $this->context->expects($this->once())->method('getScopeConfig')->willReturn($this->scopeConfig); $this->context->expects($this->once())->method('getCacheState')->willReturn($this->cacheState); $this->context->expects($this->once())->method('getCatalogConfig')->willReturn($this->catalogConfig); $this->context->expects($this->once())->method('getLocaleDate')->willReturn($this->localDate); $this->productCollection = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection')->setMethods(['setVisibility', 'addMinimalPrice', 'addFinalPrice', 'addTaxPercents', 'addAttributeToSelect', 'addUrlRewrite', 'addStoreFilter', 'addAttributeToSort', 'setPageSize', 'setCurPage', 'addAttributeToFilter'])->disableOriginalConstructor()->getMock(); $this->productCollection->expects($this->once())->method('setVisibility')->willReturnSelf(); $this->productCollection->expects($this->once())->method('addMinimalPrice')->willReturnSelf(); $this->productCollection->expects($this->once())->method('addFinalPrice')->willReturnSelf(); $this->productCollection->expects($this->once())->method('addTaxPercents')->willReturnSelf(); $this->productCollection->expects($this->once())->method('addAttributeToSelect')->willReturnSelf(); $this->productCollection->expects($this->once())->method('addUrlRewrite')->willReturnSelf(); $this->productCollection->expects($this->once())->method('addStoreFilter')->willReturnSelf(); $this->productCollection->expects($this->once())->method('addAttributeToSort')->willReturnSelf(); $this->productCollection->expects($this->atLeastOnce())->method('setCurPage')->willReturnSelf(); $this->productCollection->expects($this->any())->method('addAttributeToFilter')->willReturnSelf(); }