示例#1
0
 protected function setUp()
 {
     $logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->_menuModel = new \Magento\Backend\Model\Menu($logger);
     $this->_menuSubModel = new \Magento\Backend\Model\Menu($logger);
     $this->_factoryMock = $this->getMock('Magento\\Backend\\Model\\Menu\\Filter\\IteratorFactory', ['create'], [], '', false);
     $itemOne = $this->getMock('Magento\\Backend\\Model\\Menu\\Item', [], [], '', false);
     $itemOne->expects($this->any())->method('getId')->will($this->returnValue('item1'));
     $itemOne->expects($this->any())->method('getTitle')->will($this->returnValue('Item 1'));
     $itemOne->expects($this->any())->method('isAllowed')->will($this->returnValue(true));
     $itemOne->expects($this->any())->method('isDisabled')->will($this->returnValue(false));
     $itemOne->expects($this->any())->method('getAction')->will($this->returnValue('adminhtml/item1'));
     $itemOne->expects($this->any())->method('getChildren')->will($this->returnValue($this->_menuSubModel));
     $itemOne->expects($this->any())->method('hasChildren')->will($this->returnValue(true));
     $this->_menuModel->add($itemOne);
     $itemTwo = $this->getMock('Magento\\Backend\\Model\\Menu\\Item', [], [], '', false);
     $itemTwo->expects($this->any())->method('getId')->will($this->returnValue('item2'));
     $itemTwo->expects($this->any())->method('getTitle')->will($this->returnValue('Item 2'));
     $itemTwo->expects($this->any())->method('isAllowed')->will($this->returnValue(true));
     $itemTwo->expects($this->any())->method('isDisabled')->will($this->returnValue(false));
     $itemTwo->expects($this->any())->method('getAction')->will($this->returnValue('adminhtml/item2'));
     $itemTwo->expects($this->any())->method('hasChildren')->will($this->returnValue(false));
     $this->_menuSubModel->add($itemTwo);
     $menuConfig = $this->getMock('Magento\\Backend\\Model\\Menu\\Config', [], [], '', false);
     $menuConfig->expects($this->once())->method('getMenu')->will($this->returnValue($this->_menuModel));
     $this->_model = new \Magento\Config\Model\Config\Source\Admin\Page($this->_factoryMock, $menuConfig);
 }
示例#2
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;
 }
示例#3
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);
 }
示例#4
0
 public function testSerialize()
 {
     $this->assertNotEmpty($this->_model->serialize());
     $this->_model->add($this->_items['item1']);
 }
示例#5
0
 public function testSerialize()
 {
     $this->assertNotEmpty($this->_model->serialize());
     $this->_logger->expects($this->once())->method('log');
     $this->_model->add($this->_items['item1']);
 }