/** * Retrieve additional html and put it at the end of element html * * @return string */ public function getAfterElementHtml() { $html = parent::getAfterElementHtml(); if ($this->getIsWysiwygEnabled()) { $disabled = $this->getDisabled() || $this->getReadonly(); $html .= $this->_layout->createBlock('Magento\\Backend\\Block\\Widget\\Button', '', array('data' => array('label' => __('WYSIWYG Editor'), 'type' => 'button', 'disabled' => $disabled, 'class' => $disabled ? 'disabled action-wysiwyg' : 'action-wysiwyg', 'onclick' => 'catalogWysiwygEditor.open(\'' . $this->_backendData->getUrl('catalog/product/wysiwyg') . '\', \'' . $this->getHtmlId() . '\')')))->toHtml(); $html .= <<<HTML <script type="text/javascript"> jQuery('#{$this->getHtmlId()}') .addClass('wysiwyg-editor') .data( 'wysiwygEditor', new tinyMceWysiwygSetup( '{$this->getHtmlId()}', { settings: { theme_advanced_buttons1 : 'bold,italic,|,justifyleft,justifycenter,justifyright,|,' + 'fontselect,fontsizeselect,|,forecolor,backcolor,|,link,unlink,image,|,bullist,numlist,|,code', theme_advanced_buttons2: null, theme_advanced_buttons3: null, theme_advanced_buttons4: null, theme_advanced_statusbar_location: null } } ).turnOn() ); </script> HTML; } return $html; }
/** * @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)); }
/** * After generate Xml * * @param \Magento\Framework\View\LayoutInterface $subject * @param \Magento\Framework\View\LayoutInterface $result * @return \Magento\Framework\View\LayoutInterface */ public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result) { if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && !$this->request->isAjax() && $subject->isCacheable()) { $this->checkoutSession->clearStorage(); } return $result; }
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)); }
public function testSetListCollection() { /** @var $childBlock \Magento\Framework\View\Element\Text */ $childBlock = $this->_layout->addBlock('Magento\\Framework\\View\\Element\\Text', 'search_result_list', 'block'); $this->assertEmpty($childBlock->getCollection()); $this->_block->setListCollection(); $this->assertInstanceOf('Magento\\CatalogSearch\\Model\\ResourceModel\\Advanced\\Collection', $childBlock->getCollection()); }
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()); }
protected function setUp() { parent::setUp(); $this->_layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface'); $this->_theme = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\View\\Design\\ThemeInterface'); $this->_theme->setType(\Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL); $this->_block = $this->_layout->createBlock('Magento\\Theme\\Block\\Adminhtml\\System\\Design\\Theme\\Edit\\Tab\\General'); }
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)); }
protected function setUp() { parent::setUp(); $this->_layoutMock = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface'); $context = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Backend\\Block\\Template\\Context', ['layout' => $this->_layoutMock]); $this->_block = $this->_layoutMock->createBlock('Magento\\Backend\\Block\\Widget\\Grid\\Extended', 'grid', ['context' => $context]); $this->_block->addColumn('column1', ['id' => 'columnId1']); $this->_block->addColumn('column2', ['id' => 'columnId2']); }
/** * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @param \Magento\LayeredNavigation\Block\Navigation\FilterRenderer $subject * @param \Closure $proceed * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter * @return mixed * @throws \Magento\Framework\Exception\LocalizedException */ public function aroundRender(\Magento\LayeredNavigation\Block\Navigation\FilterRenderer $subject, \Closure $proceed, \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter) { if ($filter->hasAttributeModel()) { if ($this->swatchHelper->isSwatchAttribute($filter->getAttributeModel())) { return $this->layout->createBlock($this->block)->setSwatchFilter($filter)->toHtml(); } } return $proceed($filter); }
/** * After generate Xml * * @param \Magento\Framework\View\LayoutInterface $subject * @param \Magento\Framework\View\LayoutInterface $result * @return \Magento\Framework\View\LayoutInterface */ public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result) { if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && !$this->request->isAjax() && $subject->isCacheable()) { $this->eventManager->dispatch('depersonalize_clear_session'); session_write_close(); $this->messageSession->clearStorage(); } return $result; }
/** * 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')); }
/** * Get renderer for element * * @param string $elementClassName * @param string $rendererName * @return RendererInterface * @throws \Magento\Framework\Exception\LocalizedException */ public function create($elementClassName, $rendererName) { if (!isset($this->_rendererByElement[$elementClassName])) { throw new \Magento\Framework\Exception\LocalizedException(__('No renderer registered for elements of class "%1"', $elementClassName)); } $rendererClass = $this->_rendererByElement[$elementClassName]; $renderer = $this->_layout->createBlock($rendererClass, $rendererName); return $renderer; }
/** * Adds Google Experiment tab to the category edit page * * @param EventObserver $observer * @return void */ public function execute(EventObserver $observer) { if ($this->_helper->isGoogleExperimentActive()) { $block = $this->_layout->createBlock('Magento\\GoogleOptimizer\\Block\\Adminhtml\\Catalog\\Category\\Edit\\Tab\\Googleoptimizer', 'google-experiment-form'); /** @var $tabs \Magento\Catalog\Block\Adminhtml\Category\Tabs */ $tabs = $observer->getEvent()->getTabs(); $tabs->addTab('google-experiment-tab', ['label' => __('Category View Optimization'), 'content' => $block->toHtml()]); } }
/** * Prepares content block * * @return string */ public function getContentHtml() { /* @var $content \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content */ $content = $this->_layout->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Product\\Helper\\Form\\Gallery\\Content'); $content->setId($this->getHtmlId() . '_content')->setElement($this); $galleryJs = $content->getJsObjectName(); $content->getUploader()->getConfig()->setMegiaGallery($galleryJs); return $content->toHtml(); }
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')); }
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')); }
/** * Add order information into GA block to render on checkout success pages * * @param EventObserver $observer * @return void */ public function setGoogleAnalyticsOnOrderSuccessPageView(EventObserver $observer) { $orderIds = $observer->getEvent()->getOrderIds(); if (empty($orderIds) || !is_array($orderIds)) { return; } $block = $this->_layout->getBlock('google_analytics'); if ($block) { $block->setOrderIds($orderIds); } }
/** * 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); }
/** * Add order information into GA block to render on checkout success pages * * @param EventObserver $observer * @return void */ public function execute(EventObserver $observer) { $orderIds = $observer->getEvent()->getOrderIds(); if (empty($orderIds) || !is_array($orderIds)) { return; } $block = $this->_layout->getBlock('magepal_gtm_datalayer'); if ($block) { $block->setOrderIds($orderIds); } }
/** * @covers \Magento\Sales\Block\Adminhtml\Report\Filter\Form\Coupon::_afterToHtml */ public function testAfterToHtml() { /** @var $block \Magento\Sales\Block\Adminhtml\Report\Filter\Form\Coupon */ $block = $this->_layout->createBlock('Magento\\Sales\\Block\\Adminhtml\\Report\\Filter\\Form\\Coupon'); $block->setFilterData(new \Magento\Framework\DataObject()); $html = $block->toHtml(); $expectedStrings = ['FormElementDependenceController', 'sales_report_rules_list', 'sales_report_price_rule_type']; foreach ($expectedStrings as $expectedString) { $this->assertContains($expectedString, $html); } }
/** * 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 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); }
public function testGetInvoiceCommentsHtml() { $childBlock = $this->_layout->addBlock('Magento\\Framework\\View\\Element\\Text', 'invoice_comments', 'block'); $expectedHtml = '<b>Any html</b>'; $this->assertEmpty($childBlock->getEntity()); $this->assertEmpty($childBlock->getTitle()); $this->assertNotEquals($expectedHtml, $this->_block->getInvoiceCommentsHtml($this->_invoice)); $childBlock->setText($expectedHtml); $actualHtml = $this->_block->getInvoiceCommentsHtml($this->_invoice); $this->assertSame($this->_invoice, $childBlock->getEntity()); $this->assertNotEmpty($childBlock->getTitle()); $this->assertEquals($expectedHtml, $actualHtml); }
public function testToHtmlWithContainer() { $listName = $this->_block->getNameInLayout(); $block1 = $this->_layout->addBlock('Magento\\Framework\\View\\Element\\Text', '', $listName); $this->_layout->addContainer('container', 'Container', [], $listName); $block2 = $this->_layout->addBlock('Magento\\Framework\\View\\Element\\Text', '', 'container'); $block3 = $this->_layout->addBlock('Magento\\Framework\\View\\Element\\Text', '', $listName); $block1->setText('text1'); $block2->setText('text2'); $block3->setText('text3'); $html = $this->_block->toHtml(); $this->assertEquals('text1text2text3', $html); }
/** * @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'); }
/** * @magentoDataFixture Magento/Customer/_files/customer_group.php */ public function testDeleteButtonExistInCustomGroup() { $builder = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\FilterBuilder'); /** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteria */ $searchCriteria = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\SearchCriteriaBuilder')->addFilters([$builder->setField('code')->setValue('custom_group')->create()])->create(); $customerGroup = $this->groupRepository->getList($searchCriteria)->getItems()[0]; $this->getRequest()->setParam('id', $customerGroup->getId()); $this->registry->register(RegistryConstants::CURRENT_GROUP_ID, $customerGroup->getId()); /** @var $block Edit */ $block = $this->layout->createBlock('Magento\\Customer\\Block\\Adminhtml\\Group\\Edit', 'block'); $buttonsHtml = $block->getButtonsHtml(); $this->assertContains('delete', $buttonsHtml); }
/** * Assign custom renderer for product create/edit form weee attribute element * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function setWeeeRendererInForm(\Magento\Framework\Event\Observer $observer) { /** @var \Magento\Framework\Data\Form $form */ $form = $observer->getEvent()->getForm(); $attributes = $this->_weeeTax->getWeeeAttributeCodes(true); foreach ($attributes as $code) { $weeeTax = $form->getElement($code); if ($weeeTax) { $weeeTax->setRenderer($this->_layout->createBlock('Magento\\Weee\\Block\\Renderer\\Weee\\Tax')); } } return $this; }
public function testToHtmlPropagatesUrl() { \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\State')->setAreaCode('frontend'); $this->_block->setShouldPrepareInfoTabs(true); $childOne = $this->_layout->addBlock('Magento\\Framework\\View\\Element\\Text', 'child1', 'block'); $this->_layout->addToParentGroup('child1', 'info_tabs'); $childTwo = $this->_layout->addBlock('Magento\\Framework\\View\\Element\\Text', 'child2', 'block'); $this->_layout->addToParentGroup('child2', 'info_tabs'); $this->assertEmpty($childOne->getViewUrl()); $this->assertEmpty($childTwo->getViewUrl()); $this->_block->toHtml(); $this->assertNotEmpty($childOne->getViewUrl()); $this->assertNotEmpty($childTwo->getViewUrl()); }