/** * @return Mage_Backend_Model_Menu * @throws OutOfRangeException in case given parent id does not exists */ public function getResult() { /** @var $items Mage_Backend_Model_Menu_Item[] */ $params = array(); $items = array(); // Create menu items foreach ($this->_commands as $id => $command) { $params[$id] = $command->execute(); $item = $this->_itemFactory->createFromArray($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) { $this->_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 $this->_menu; }
public function testCreateFromArrayProvidesDefaultHelper() { $this->_objectFactoryMock->expects($this->once())->method('getModelInstance')->with($this->equalTo('Mage_Backend_Model_Menu_Item'), $this->equalTo(array('module' => $this->_helpers['Mage_Backend_Helper_Data'], 'acl' => $this->_aclMock, 'menuFactory' => $this->_factoryMock, 'urlModel' => $this->_urlModelMock, 'appConfig' => $this->_appConfigMock, 'storeConfig' => $this->_storeConfigMock, 'validator' => $this->_itemValidatorMock))); $model = new Mage_Backend_Model_Menu_Item_Factory($this->_params); $model->createFromArray(array()); }
public function testCreateFromArrayProvidesDefaultHelper() { $this->_objectFactoryMock->expects($this->once())->method('create')->with($this->equalTo('Mage_Backend_Model_Menu_Item'), $this->equalTo(array('authorization' => $this->_aclMock, 'menuFactory' => $this->_factoryMock, 'urlModel' => $this->_urlModelMock, 'applicationConfig' => $this->_appConfigMock, 'storeConfig' => $this->_storeConfigMock, 'validator' => $this->_itemValidatorMock, 'helper' => $this->_helpers['Mage_Backend_Helper_Data'], 'data' => array()))); $this->_model->createFromArray(array()); }