Example #1
0
 /**
  * Attributes validation action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function executeInternal()
 {
     $response = $this->_objectManager->create('Magento\\Framework\\DataObject');
     $response->setError(false);
     $attributesData = $this->getRequest()->getParam('attributes', []);
     $data = $this->_objectManager->create('Magento\\Catalog\\Model\\Product');
     try {
         if ($attributesData) {
             foreach ($attributesData as $attributeCode => $value) {
                 $attribute = $this->_objectManager->get('Magento\\Eav\\Model\\Config')->getAttribute('catalog_product', $attributeCode);
                 if (!$attribute->getAttributeId()) {
                     unset($attributesData[$attributeCode]);
                     continue;
                 }
                 $data->setData($attributeCode, $value);
                 $attribute->getBackend()->validate($data);
             }
         }
     } catch (\Magento\Eav\Model\Entity\Attribute\Exception $e) {
         $response->setError(true);
         $response->setAttribute($e->getAttributeCode());
         $response->setMessage($e->getMessage());
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $response->setError(true);
         $response->setMessage($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('Something went wrong while updating the product(s) attributes.'));
         $layout = $this->layoutFactory->create();
         $layout->initMessages();
         $response->setError(true);
         $response->setHtmlMessage($layout->getMessagesBlock()->getGroupedHtml());
     }
     return $this->resultJsonFactory->create()->setJsonData($response->toJson());
 }
Example #2
0
 /**
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $response = new \Magento\Framework\Object();
     $response->setError(false);
     $attributeCode = $this->getRequest()->getParam('attribute_code');
     $frontendLabel = $this->getRequest()->getParam('frontend_label');
     $attributeCode = $attributeCode ?: $this->generateCode($frontendLabel[0]);
     $attributeId = $this->getRequest()->getParam('attribute_id');
     $attribute = $this->_objectManager->create('Magento\\Catalog\\Model\\Resource\\Eav\\Attribute')->loadByCode($this->_entityTypeId, $attributeCode);
     if ($attribute->getId() && !$attributeId) {
         if (strlen($this->getRequest()->getParam('attribute_code'))) {
             $response->setAttributes(['attribute_code' => __('An attribute with this code already exists.')]);
         } else {
             $response->setAttributes(['attribute_label' => __('Attribute with the same code (%1) already exists.', $attributeCode)]);
         }
         $response->setError(true);
     }
     if ($this->getRequest()->has('new_attribute_set_name')) {
         $setName = $this->getRequest()->getParam('new_attribute_set_name');
         /** @var $attributeSet \Magento\Eav\Model\Entity\Attribute\Set */
         $attributeSet = $this->_objectManager->create('Magento\\Eav\\Model\\Entity\\Attribute\\Set');
         $attributeSet->setEntityTypeId($this->_entityTypeId)->load($setName, 'attribute_set_name');
         if ($attributeSet->getId()) {
             $setName = $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($setName);
             $this->messageManager->addError(__('Attribute Set with name \'%1\' already exists.', $setName));
             $layout = $this->layoutFactory->create();
             $layout->initMessages();
             $response->setError(true);
             $response->setHtmlMessage($layout->getMessagesBlock()->getGroupedHtml());
         }
     }
     return $this->resultJsonFactory->create()->setJsonData($response->toJson());
 }
Example #3
0
 /**
  * @return string
  */
 protected function getStatusHtml()
 {
     $layout = $this->layoutFactory->create();
     /** @var \Tobai\GeoIp2\Block\Adminhtml\System\Config\Status $statusBlock */
     $statusBlock = $layout->createBlock('Tobai\\GeoIp2\\Block\\Adminhtml\\System\\Config\\Status');
     return $statusBlock->getDbStatus();
 }
 /**
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $layout = $this->layoutFactory->create();
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultFactory->create(ResultFactory::TYPE_RAW);
     $resultRaw->setContents($layout->createBlock('Magento\\Review\\Block\\Adminhtml\\Rating\\Detailed')->setIndependentMode()->toHtml());
     return $resultRaw;
 }
Example #5
0
 /**
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function executeInternal()
 {
     $layout = $this->layoutFactory->create();
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultFactory->create(ResultFactory::TYPE_RAW);
     $resultRaw->setContents($layout->createBlock('Magento\Review\Block\Adminhtml\Grid')->toHtml());
     return $resultRaw;
 }
Example #6
0
 /**
  * Grid with Google Content items
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
     /** @var \Magento\GoogleShopping\Block\Adminhtml\Items\Item $block */
     $block = $this->layoutFactory->create()->createBlock('Magento\\GoogleShopping\\Block\\Adminhtml\\Items\\Item');
     return $resultRaw->setContents($block->setIndex($this->getRequest()->getParam('index'))->toHtml());
 }
Example #7
0
 /**
  * Construct
  *
  * @param \Magento\Framework\App\Helper\Context $context
  * @param LayoutFactory $layoutFactory
  * @param \Magento\Payment\Model\Method\Factory $paymentMethodFactory
  * @param \Magento\Store\Model\App\Emulation $appEmulation
  * @param \Magento\Payment\Model\Config $paymentConfig
  * @param \Magento\Framework\App\Config\Initial $initialConfig
  */
 public function __construct(\Magento\Framework\App\Helper\Context $context, LayoutFactory $layoutFactory, \Magento\Payment\Model\Method\Factory $paymentMethodFactory, \Magento\Store\Model\App\Emulation $appEmulation, \Magento\Payment\Model\Config $paymentConfig, \Magento\Framework\App\Config\Initial $initialConfig)
 {
     parent::__construct($context);
     $this->_layout = $layoutFactory->create();
     $this->_methodFactory = $paymentMethodFactory;
     $this->_appEmulation = $appEmulation;
     $this->_paymentConfig = $paymentConfig;
     $this->_initialConfig = $initialConfig;
 }
Example #8
0
 public function testConstructorStructure()
 {
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $structure = $objectManager->get('Magento\\Framework\\View\\Layout\\Data\\Structure');
     $structure->createElement('test.container', []);
     /** @var $layout \Magento\Framework\View\LayoutInterface */
     $layout = $this->layoutFactory->create(['structure' => $structure]);
     $this->assertTrue($layout->hasElement('test.container'));
 }
Example #9
0
 /**
  * Get specified tab grid
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Products'));
     $this->productBuilder->build($this->getRequest());
     $block = $this->getRequest()->getParam('gridOnlyBlock');
     $blockClassSuffix = str_replace(' ', '_', ucwords(str_replace('_', ' ', $block)));
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Product\\Edit\\Tab\\' . $blockClassSuffix)->toHtml());
 }
Example #10
0
 /**
  * WYSIWYG editor action for ajax request
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $elementId = $this->getRequest()->getParam('element_id', md5(microtime()));
     $storeId = $this->getRequest()->getParam('store_id', 0);
     $storeMediaUrl = $this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore($storeId)->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
     $content = $this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Helper\\Form\\Wysiwyg\\Content', '', ['data' => ['editor_element_id' => $elementId, 'store_id' => $storeId, 'store_media_url' => $storeMediaUrl]]);
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($content->toHtml());
 }
 /**
  * Prepare a layout model with pre-loaded fixture of an update XML
  *
  * @param string $fixtureFile
  * @return \Magento\Framework\View\LayoutInterface
  */
 protected function _getLayoutModel($fixtureFile)
 {
     $this->objectManager->get('Magento\\Framework\\App\\Cache\\Type\\Layout')->clean();
     $layout = $this->layoutFactory->create();
     /** @var $xml \Magento\Framework\View\Layout\Element */
     $xml = simplexml_load_file(__DIR__ . "/_files/layout_directives_test/{$fixtureFile}", 'Magento\\Framework\\View\\Layout\\Element');
     $layout->loadString($xml->asXml());
     $layout->generateElements();
     return $layout;
 }
Example #12
0
 /**
  * Chooser Source action
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $uniqId = $this->getRequest()->getParam('uniq_id');
     /** @var \Magento\Framework\View\Layout $layout */
     $layout = $this->layoutFactory->create();
     $pagesGrid = $layout->createBlock('Magento\\Cms\\Block\\Adminhtml\\Page\\Widget\\Chooser', '', ['data' => ['id' => $uniqId]]);
     $html = $pagesGrid->toHtml();
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($html);
 }
 /**
  * Generate order history for ajax request
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $this->_initOrder();
     $layout = $this->layoutFactory->create();
     $html = $layout->createBlock('Magento\\Sales\\Block\\Adminhtml\\Order\\View\\Tab\\History')->toHtml();
     $this->_translateInline->processResponseBody($html);
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     $resultRaw->setContents($html);
     return $resultRaw;
 }
Example #14
0
 /**
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $output = '';
     $blockTab = $this->getRequest()->getParam('block');
     $blockClassSuffix = str_replace(' ', '\\', ucwords(str_replace('_', ' ', $blockTab)));
     if (in_array($blockTab, ['tab_orders', 'tab_amounts', 'totals'])) {
         $output = $this->layoutFactory->create()->createBlock('Magento\\Backend\\Block\\Dashboard\\' . $blockClassSuffix)->toHtml();
     }
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($output);
 }
Example #15
0
 /**
  * Grid Action
  * Display list of products related to current category
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $category = $this->_initCategory(true);
     if (!$category) {
         /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]);
     }
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Category\\Tab\\Product', 'category.product.grid')->toHtml());
 }
 /**
  * Get available attribute sets
  *
  * @return \Magento\Framework\Controller\Result\Raw
  * @throws \Exception
  */
 public function execute()
 {
     try {
         /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
         $resultRaw = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
         return $resultRaw->setContents($this->layoutFactory->create()->getBlockSingleton('Magento\\GoogleShopping\\Block\\Adminhtml\\Types\\Edit\\Form')->getAttributeSetsSelectElement($this->getRequest()->getParam('target_country'))->toHtml());
     } catch (\Exception $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         // just need to output text with error
         $this->messageManager->addError(__("We can't load attribute sets."));
     }
 }
Example #17
0
 /**
  * Get Google Content attributes list
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
     try {
         $resultRaw->setContents($this->layoutFactory->create()->createBlock('Magento\\GoogleShopping\\Block\\Adminhtml\\Types\\Edit\\Attributes')->setAttributeSetId($this->getRequest()->getParam('attribute_set_id'))->setTargetCountry($this->getRequest()->getParam('target_country'))->setAttributeSetSelected(true)->toHtml());
     } catch (\Exception $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         // just need to output text with error
         $this->messageManager->addError(__('We can\'t load attributes right now.'));
     }
     return $resultRaw;
 }
Example #18
0
 /**
  * Constructor
  *
  * @param View\Element\Template\Context $context
  * @param View\LayoutFactory $layoutFactory
  * @param View\Layout\ReaderPool $layoutReaderPool
  * @param Framework\Translate\InlineInterface $translateInline
  * @param View\Layout\BuilderFactory $layoutBuilderFactory
  * @param View\Layout\GeneratorPool $generatorPool
  * @param bool $isIsolated
  */
 public function __construct(View\Element\Template\Context $context, View\LayoutFactory $layoutFactory, View\Layout\ReaderPool $layoutReaderPool, Framework\Translate\InlineInterface $translateInline, View\Layout\BuilderFactory $layoutBuilderFactory, View\Layout\GeneratorPool $generatorPool, $isIsolated = false)
 {
     $this->layoutFactory = $layoutFactory;
     $this->layoutBuilderFactory = $layoutBuilderFactory;
     $this->layoutReaderPool = $layoutReaderPool;
     $this->eventManager = $context->getEventManager();
     $this->request = $context->getRequest();
     $this->translateInline = $translateInline;
     // TODO Shared layout object will be deleted in MAGETWO-28359
     $this->layout = $isIsolated ? $this->layoutFactory->create(['reader' => $this->layoutReaderPool, 'generatorPool' => $generatorPool]) : $context->getLayout();
     $this->layout->setGeneratorPool($generatorPool);
     $this->initLayoutBuilder();
 }
Example #19
0
 public function testUpdate()
 {
     $statusInfo = 'some status info';
     $data = ['status' => 'success', 'message' => __('Database(s) successfully updated.'), 'status_info' => $statusInfo];
     $this->resultJson->expects($this->once())->method('setData')->with($data)->willReturnSelf();
     $this->updaterSelected->expects($this->once())->method('update')->willReturnSelf();
     $statusBlock = $this->getMockBuilder('Tobai\\GeoIp2\\Block\\Adminhtml\\System\\Config\\Status')->disableOriginalConstructor()->getMock();
     $layout = $this->getMock('Magento\\Framework\\View\\LayoutInterface');
     $this->layoutFactory->expects($this->once())->method('create')->willReturn($layout);
     $layout->expects($this->once())->method('createBlock')->with('Tobai\\GeoIp2\\Block\\Adminhtml\\System\\Config\\Status')->willReturn($statusBlock);
     $statusBlock->expects($this->once())->method('getDbStatus')->willReturn($statusInfo);
     $this->logger->expects($this->never())->method('critical');
     $this->assertSame($this->resultJson, $this->controllerUpdate->execute());
 }
Example #20
0
 /**
  * Tree json action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultJsonFactory->create();
     try {
         $this->_initAction();
         /** @var \Magento\Framework\View\Layout $layout */
         $layout = $this->layoutFactory->create();
         $resultJson->setJsonData($layout->createBlock('Magento\\Cms\\Block\\Adminhtml\\Wysiwyg\\Images\\Tree')->getTreeJson());
     } catch (\Exception $e) {
         $result = ['error' => true, 'message' => $e->getMessage()];
         $resultJson->setData($result);
     }
     return $resultJson;
 }
Example #21
0
 protected function initEmptyLayout()
 {
     if (!is_null($this->emptyLayout)) {
         return;
     }
     $this->emptyLayout = $this->layoutFactory->create();
 }
Example #22
0
 /**
  * Retrieve layout html directive callback
  *
  * @return string
  */
 public function emulateAreaCallback()
 {
     $skipParams = ['handle', 'area'];
     /** @var $layout \Magento\Framework\View\LayoutInterface */
     $layout = $this->_layoutFactory->create(['cacheable' => false]);
     $layout->getUpdate()->addHandle($this->_directiveParams['handle'])->load();
     $layout->generateXml();
     $layout->generateElements();
     $rootBlock = false;
     foreach ($layout->getAllBlocks() as $block) {
         /* @var $block \Magento\Framework\View\Element\AbstractBlock */
         if (!$block->getParentBlock() && !$rootBlock) {
             $rootBlock = $block;
         }
         foreach ($this->_directiveParams as $k => $v) {
             if (in_array($k, $skipParams)) {
                 continue;
             }
             $block->setDataUsingMethod($k, $v);
         }
     }
     /**
      * Add root block to output
      */
     if ($rootBlock) {
         $layout->addOutputElement($rootBlock->getNameInLayout());
     }
     $result = $layout->getOutput();
     $layout->__destruct();
     // To overcome bug with SimpleXML memory leak (https://bugs.php.net/bug.php?id=62468)
     return $result;
 }
Example #23
0
 /**
  * Retrieve inline giftmessage edit form for specified entity
  *
  * @param string $type
  * @param \Magento\Framework\Object $entity
  * @param bool $dontDisplayContainer
  * @return string
  */
 public function getInline($type, \Magento\Framework\Object $entity, $dontDisplayContainer = false)
 {
     if (!$this->skipPage($type) && !$this->isMessagesAvailable($type, $entity)) {
         return '';
     }
     return $this->_layoutFactory->create()->createBlock('Magento\\GiftMessage\\Block\\Message\\Inline')->setId('giftmessage_form_' . $this->_nextId++)->setDontDisplayContainer($dontDisplayContainer)->setEntity($entity)->setType($type)->toHtml();
 }
 /**
  * Run test execute method
  *
  * @param int|bool $categoryId
  * @param int $storeId
  * @return void
  *
  * @dataProvider dataProviderExecute
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecute($categoryId, $storeId)
 {
     $rootCategoryId = 2;
     $this->requestMock->expects($this->atLeastOnce())->method('getParam')->will($this->returnValueMap([['id', false, $categoryId], ['store', null, $storeId]]));
     $this->requestMock->expects($this->atLeastOnce())->method('getQuery')->with('isAjax')->will($this->returnValue(false));
     $this->mockInitCategoryCall();
     $this->sessionMock->expects($this->once())->method('__call')->will($this->returnValue([]));
     if (!$categoryId) {
         if ($storeId) {
             $this->storeManagerInterfaceMock->expects($this->once())->method('getStore')->with($storeId)->will($this->returnSelf());
         } else {
             $this->storeManagerInterfaceMock->expects($this->once())->method('getDefaultStoreView')->will($this->returnSelf());
         }
         $this->storeManagerInterfaceMock->expects($this->once())->method('getRootCategoryId')->will($this->returnValue($rootCategoryId));
         $categoryId = $rootCategoryId;
     }
     $this->requestMock->expects($this->atLeastOnce())->method('setParam')->with('id', $categoryId)->will($this->returnValue(true));
     $this->categoryMock->expects($this->atLeastOnce())->method('getId')->will($this->returnValue($categoryId));
     /**
      * @var \Magento\Framework\View\Element\Template
      * |\PHPUnit_Framework_MockObject_MockObject $blockMock
      */
     $blockMock = $this->getMock('Magento\\Framework\\View\\Element\\Template', ['setStoreId'], [], '', false);
     $blockMock->expects($this->once())->method('setStoreId')->with($storeId);
     $this->resultPageMock->expects($this->once())->method('getLayout')->will($this->returnSelf());
     $this->resultPageMock->expects($this->once())->method('getBlock')->willReturn($blockMock);
     $this->edit->execute();
 }
Example #25
0
 /**
  * Chooser Source action
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function executeInternal()
 {
     $uniqId = $this->getRequest()->getParam('uniq_id');
     $massAction = $this->getRequest()->getParam('use_massaction', false);
     $productTypeId = $this->getRequest()->getParam('product_type_id', null);
     $layout = $this->layoutFactory->create();
     $productsGrid = $layout->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Product\\Widget\\Chooser', '', ['data' => ['id' => $uniqId, 'use_massaction' => $massAction, 'product_type_id' => $productTypeId, 'category_id' => $this->getRequest()->getParam('category_id')]]);
     $html = $productsGrid->toHtml();
     if (!$this->getRequest()->getParam('products_grid')) {
         $categoriesTree = $layout->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Category\\Widget\\Chooser', '', ['data' => ['id' => $uniqId . 'Tree', 'node_click_listener' => $productsGrid->getCategoryClickListenerJs(), 'with_empty_node' => true]]);
         $html = $layout->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Product\\Widget\\Chooser\\Container')->setTreeHtml($categoriesTree->toHtml())->setGridHtml($html)->toHtml();
     }
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($html);
 }
Example #26
0
 /**
  * Get progress html checkout step
  *
  * @param string $checkoutStep
  * @return mixed
  */
 protected function getProgressHtml($checkoutStep = '')
 {
     $layout = $this->layoutFactory->create();
     $layout->getUpdate()->load(['checkout_onepage_progress']);
     $layout->generateXml();
     $layout->generateElements();
     $block = $layout->getBlock('progress')->setAttribute('next_step', $checkoutStep);
     return $block->toHtml();
 }
Example #27
0
 /**
  * Render HTML based on requested layout handle name
  *
  * @param string $handle
  * @return string
  */
 protected function _getHtmlByHandle($handle)
 {
     $layout = $this->layoutFactory->create();
     $layout->getUpdate()->load([$handle]);
     $layout->generateXml();
     $layout->generateElements();
     $output = $layout->getOutput();
     $this->_translateInline->processResponseBody($output);
     return $output;
 }
Example #28
0
 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]);
 }
Example #29
0
 /**
  * @param string $path
  * @param array $params
  * @param array $response
  * @return \Magento\Framework\Controller\Result\Json|\Magento\Backend\Model\View\Result\Redirect
  */
 private function returnResult($path = '', array $params = [], array $response = [])
 {
     if ($this->isAjax()) {
         $layout = $this->layoutFactory->create();
         $layout->initMessages();
         $response['messages'] = [$layout->getMessagesBlock()->getGroupedHtml()];
         $response['params'] = $params;
         return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($response);
     }
     return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath($path, $params);
 }
 /**
  * Get tree node (Ajax version)
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     if ($this->getRequest()->getParam('expand_all')) {
         $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session')->setIsTreeWasExpanded(true);
     } else {
         $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session')->setIsTreeWasExpanded(false);
     }
     $categoryId = (int) $this->getRequest()->getPost('id');
     if ($categoryId) {
         $this->getRequest()->setParam('id', $categoryId);
         $category = $this->_initCategory();
         if (!$category) {
             /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
             $resultRedirect = $this->resultRedirectFactory->create();
             return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]);
         }
         /** @var \Magento\Framework\Controller\Result\Json $resultJson */
         $resultJson = $this->resultJsonFactory->create();
         return $resultJson->setJsonData($this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Category\\Tree')->getTreeJson($category));
     }
 }