Esempio n. 1
0
 /**
  * Populate menu object
  *
  * @param \Magento\Backend\Model\Menu $menu
  * @return \Magento\Backend\Model\Menu
  * @throws \OutOfRangeException in case given parent id does not exists
  */
 public function getResult(\Magento\Backend\Model\Menu $menu)
 {
     /** @var $items \Magento\Backend\Model\Menu\Item[] */
     $params = [];
     $items = [];
     // Create menu items
     foreach ($this->_commands as $id => $command) {
         $params[$id] = $command->execute();
         $item = $this->_itemFactory->create($params[$id]);
         $items[$id] = $item;
     }
     // Build menu tree based on "parent" param
     foreach ($items as $id => $item) {
         $sortOrder = $this->_getParam($params[$id], 'sortOrder');
         $parentId = $this->_getParam($params[$id], 'parent');
         $isRemoved = isset($params[$id]['removed']);
         if ($isRemoved) {
             continue;
         }
         if (!$parentId) {
             $menu->add($item, null, $sortOrder);
         } else {
             if (!isset($items[$parentId])) {
                 throw new \OutOfRangeException(sprintf('Specified invalid parent id (%s)', $parentId));
             }
             if (isset($params[$parentId]['removed'])) {
                 continue;
             }
             $items[$parentId]->getChildren()->add($item, null, $sortOrder);
         }
     }
     return $menu;
 }
Esempio n. 2
0
 /**
  * Removes 'Web Setup Wizard' from the menu if doc root is pub and no setup url variable is specified.
  *
  * @param Builder $subject
  * @param Menu $menu
  * @return Menu
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterGetResult(Builder $subject, Menu $menu)
 {
     if ($this->docRootLocator->isPub()) {
         $menu->remove('Magento_Backend::setup_wizard');
     }
     return $menu;
 }
Esempio n. 3
0
 public function testToOptionArray()
 {
     $this->_factoryMock->expects($this->at(0))->method('create')->with($this->equalTo(['iterator' => $this->_menuModel->getIterator()]))->will($this->returnValue(new \Magento\Backend\Model\Menu\Filter\Iterator($this->_menuModel->getIterator())));
     $this->_factoryMock->expects($this->at(1))->method('create')->with($this->equalTo(['iterator' => $this->_menuSubModel->getIterator()]))->will($this->returnValue(new \Magento\Backend\Model\Menu\Filter\Iterator($this->_menuSubModel->getIterator())));
     $nonEscapableNbspChar = html_entity_decode(' ', ENT_NOQUOTES, 'UTF-8');
     $paddingString = str_repeat($nonEscapableNbspChar, 4);
     $expected = [['label' => 'Item 1', 'value' => 'item1'], ['label' => $paddingString . 'Item 2', 'value' => 'item2']];
     $this->assertEquals($expected, $this->_model->toOptionArray());
 }
 /**
  * Removes 'Search Synonyms' from the menu if 'synonyms' is not supported
  *
  * @param Builder $subject
  * @param Menu $menu
  * @return Menu
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterGetResult(Builder $subject, Menu $menu)
 {
     $searchEngine = $this->engineResolver->getCurrentSearchEngine();
     if (!$this->searchFeatureConfig->isFeatureSupported(ConfigInterface::SEARCH_ENGINE_FEATURE_SYNONYMS, $searchEngine)) {
         // "Search Synonyms" feature is not supported by the current configured search engine.
         // Menu will be updated to remove it from the list
         $menu->remove(self::SEARCH_SYNONYMS_MENU_ITEM_ID);
     }
     return $menu;
 }
Esempio n. 5
0
 /**
  * Count All Subnavigation Items
  *
  * @param \Magento\Backend\Model\Menu $items
  * @return int
  */
 protected function _countItems($items)
 {
     $total = $items->count();
     foreach ($items as $item) {
         /** @var $item \Magento\Backend\Model\Menu\Item */
         if ($item->hasChildren()) {
             $total += $this->_countItems($item->getChildren());
         }
     }
     return $total;
 }
Esempio n. 6
0
 public function testExecute()
 {
     $this->menuMock->expects($this->once())->method('getParentItems')->willReturn([$this->menuItemMock]);
     $this->titleMock->expects($this->atLeastOnce())->method('prepend');
     $this->pageConfigMock->expects($this->atLeastOnce())->method('getTitle')->willReturn($this->titleMock);
     $this->pageMock->expects($this->atLeastOnce())->method('getConfig')->willReturn($this->pageConfigMock);
     $this->blockMock->expects($this->atLeastOnce())->method('addLink');
     $this->blockMock->expects($this->once())->method('setActive');
     $this->blockMock->expects($this->once())->method('getMenuModel')->willReturn($this->menuMock);
     $this->layoutMock->expects($this->atLeastOnce())->method('getBlock')->willReturn($this->blockMock);
     $this->viewMock->expects($this->once())->method('loadLayout')->willReturnSelf();
     $this->viewMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($this->layoutMock);
     $this->viewMock->expects($this->atLeastOnce())->method('getPage')->willReturn($this->pageMock);
     $this->action->executeInternal();
 }
 /**
  * {@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);
 }
 /**
  * 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);
 }
Esempio n. 9
0
 /**
  * Initialize menu object
  *
  * @return void
  */
 protected function _initMenu()
 {
     if (!$this->_menu) {
         $this->_menu = $this->_menuFactory->create();
         $cache = $this->_configCacheType->load(self::CACHE_MENU_OBJECT);
         if ($cache) {
             $this->_menu->unserialize($cache);
             return;
         }
         $this->_director->direct($this->_configReader->read($this->_appState->getAreaCode()), $this->_menuBuilder, $this->_logger);
         $this->_menu = $this->_menuBuilder->getResult($this->_menu);
         $this->_configCacheType->save($this->_menu->serialize(), self::CACHE_MENU_OBJECT);
     }
 }
Esempio n. 10
0
 public function testLoopIteratesMixedItems()
 {
     $this->_menuModel->add($this->getMock('Magento\\Backend\\Model\\Menu\\Item', [], [], '', false));
     $this->_menuModel->add($this->getMock('Magento\\Backend\\Model\\Menu\\Item', [], [], '', false));
     $this->_menuModel->add($this->_items['item1']);
     $this->_menuModel->add($this->_items['item2']);
     $this->_menuModel->add($this->_items['item3']);
     $this->_menuModel->add($this->getMock('Magento\\Backend\\Model\\Menu\\Item', [], [], '', false));
     $this->_menuModel->add($this->getMock('Magento\\Backend\\Model\\Menu\\Item', [], [], '', false));
     $items = [];
     foreach ($this->_filterIteratorModel as $item) {
         $items[] = $item;
     }
     $this->assertCount(1, $items);
 }
Esempio n. 11
0
 /**
  * Get menu filter iterator
  *
  * @param \Magento\Backend\Model\Menu $menu
  * @return \Magento\Backend\Model\Menu\Filter\Iterator
  */
 protected function _getMenuIterator($menu)
 {
     return $this->_iteratorFactory->create(['iterator' => $menu->getIterator()]);
 }
Esempio n. 12
0
 public function testSerialize()
 {
     $this->assertNotEmpty($this->_model->serialize());
     $this->_logger->expects($this->once())->method('log');
     $this->_model->add($this->_items['item1']);
 }
Esempio n. 13
0
 /**
  * Get menu filter iterator
  *
  * @param \Magento\Backend\Model\Menu $menu
  * @return \Magento\Backend\Model\Menu\Filter\Iterator
  */
 protected function getMenuIterator($menu)
 {
     return $this->_iteratorFactory->create(array('iterator' => $menu->getIterator()));
 }
Esempio n. 14
0
 public function testSerialize()
 {
     $this->assertNotEmpty($this->_model->serialize());
     $this->_model->add($this->_items['item1']);
 }
Esempio n. 15
0
 /**
  * Get menu filter iterator
  *
  * @param \Magento\Backend\Model\Menu $menu menu model
  * @return \Magento\Backend\Model\Menu\Filter\Iterator
  */
 protected function _getMenuIterator(\Magento\Backend\Model\Menu $menu)
 {
     return $this->_iteratorFactory->create(['iterator' => $menu->getIterator()]);
 }
Esempio n. 16
0
 /**
  * @return void
  */
 public function __wakeup()
 {
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
     $this->_moduleManager = $objectManager->get('Magento\\Framework\\Module\\Manager');
     $this->_validator = $objectManager->get('Magento\\Backend\\Model\\Menu\\Item\\Validator');
     $this->_acl = $objectManager->get('Magento\\Framework\\AuthorizationInterface');
     $this->_scopeConfig = $objectManager->get('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->_menuFactory = $objectManager->get('Magento\\Backend\\Model\\MenuFactory');
     $this->_urlModel = $objectManager->get('Magento\\Backend\\Model\\UrlInterface');
     $this->_moduleList = $objectManager->get('Magento\\Framework\\Module\\ModuleListInterface');
     if ($this->_serializedSubmenu) {
         $this->_submenu = $this->_menuFactory->create();
         $this->_submenu->unserialize($this->_serializedSubmenu);
     }
 }
Esempio n. 17
0
 /**
  *  test execute method
  */
 public function testExecute()
 {
     $this->requestMock->expects($this->exactly(4))->method('getParam')->will($this->returnValueMap([['order_id', null, 'order_id'], ['creditmemo_id', null, 'creditmemo_id'], ['creditmemo', null, 'creditmemo'], ['invoice_id', null, 'invoice_id']]));
     $this->creditmemoLoaderMock->expects($this->once())->method('setOrderId')->with($this->equalTo('order_id'));
     $this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemoId')->with($this->equalTo('creditmemo_id'));
     $this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemo')->with($this->equalTo('creditmemo'));
     $this->creditmemoLoaderMock->expects($this->once())->method('setInvoiceId')->with($this->equalTo('invoice_id'));
     $this->creditmemoLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->creditmemoMock));
     $this->creditmemoMock->expects($this->exactly(2))->method('getInvoice')->will($this->returnValue($this->invoiceMock));
     $this->invoiceMock->expects($this->once())->method('getIncrementId')->will($this->returnValue('invoice-increment-id'));
     $this->titleMock->expects($this->exactly(3))->method('add')->will($this->returnValueMap([['Credit Memos', null], ['New Memo for #invoice-increment-id', null], ['item-title', null]]));
     $this->objectManagerMock->expects($this->once())->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Session'))->will($this->returnValue($this->backendSessionMock));
     $this->backendSessionMock->expects($this->once())->method('getCommentText')->with($this->equalTo(true))->will($this->returnValue('comment'));
     $this->creditmemoMock->expects($this->once())->method('setCommentText')->with($this->equalTo('comment'));
     $this->viewMock->expects($this->once())->method('loadLayout');
     $this->viewMock->expects($this->once())->method('renderLayout');
     $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock));
     $this->layoutMock->expects($this->once())->method('getBlock')->with($this->equalTo('menu'))->will($this->returnValue($this->blockMenuMock));
     $this->blockMenuMock->expects($this->once())->method('setActive')->with($this->equalTo('Magento_Sales::sales_order'));
     $this->blockMenuMock->expects($this->once())->method('getMenuModel')->will($this->returnValue($this->modelMenuMock));
     $this->modelMenuMock->expects($this->once())->method('getParentItems')->will($this->returnValue([$this->modelMenuItem]));
     $this->modelMenuItem->expects($this->once())->method('getTitle')->will($this->returnValue('item-title'));
     $this->assertNull($this->controller->execute());
 }