Example #1
0
 public function testToOptionArray()
 {
     $this->_factoryMock->expects($this->at(0))->method('getModelInstance')->with($this->equalTo('Mage_Backend_Model_Menu_Filter_Iterator'), $this->equalTo(array('iterator' => $this->_menuModel->getIterator())))->will($this->returnValue(new Mage_Backend_Model_Menu_Filter_Iterator($this->_menuModel->getIterator())));
     $this->_factoryMock->expects($this->at(1))->method('getModelInstance')->with($this->equalTo('Mage_Backend_Model_Menu_Filter_Iterator'), $this->equalTo(array('iterator' => $this->_menuSubModel->getIterator())))->will($this->returnValue(new Mage_Backend_Model_Menu_Filter_Iterator($this->_menuSubModel->getIterator())));
     $nonEscapableNbspChar = html_entity_decode(' ', ENT_NOQUOTES, 'UTF-8');
     $paddingString = str_repeat($nonEscapableNbspChar, 4);
     $expected = array(array('label' => 'Item 1', 'value' => 'item1'), array('label' => $paddingString . 'Item 2', 'value' => 'item2'));
     $this->assertEquals($expected, $this->_model->toOptionArray());
 }
Example #2
0
 /**
  * @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;
 }
Example #3
0
 public function testLoopIteratesMixedItems()
 {
     $this->_menuModel->add($this->getMock('Mage_Backend_Model_Menu_Item', array(), array(), '', false));
     $this->_menuModel->add($this->getMock('Mage_Backend_Model_Menu_Item', array(), array(), '', false));
     $this->_menuModel->add($this->_items['item1']);
     $this->_menuModel->add($this->_items['item2']);
     $this->_menuModel->add($this->_items['item3']);
     $this->_menuModel->add($this->getMock('Mage_Backend_Model_Menu_Item', array(), array(), '', false));
     $this->_menuModel->add($this->getMock('Mage_Backend_Model_Menu_Item', array(), array(), '', false));
     $items = array();
     foreach ($this->_filterIteratorModel as $item) {
         $items[] = $item;
     }
     $this->assertCount(1, $items);
 }
Example #4
0
 /**
  * Test reset iterator to first element before each foreach
  */
 public function testNestedLoop()
 {
     $this->_model->add($this->_items['item1']);
     $this->_model->add($this->_items['item2']);
     $this->_model->add($this->_items['item3']);
     $expected = array('item1' => array('item1', 'item2', 'item3'), 'item2' => array('item1', 'item2', 'item3'), 'item3' => array('item1', 'item2', 'item3'));
     $actual = array();
     foreach ($this->_model as $valLoop1) {
         $keyLevel1 = $valLoop1->getId();
         foreach ($this->_model as $valLoop2) {
             $actual[$keyLevel1][] = $valLoop2->getId();
         }
     }
     $this->assertEquals($expected, $actual);
 }
Example #5
0
 /**
  * Initialize menu object
  *
  * @return void
  */
 protected function _initMenu()
 {
     if (!$this->_menu) {
         $this->_menu = $this->_menuFactory->getMenuInstance();
         if ($this->_cache->canUse('config')) {
             $cache = $this->_cache->load(self::CACHE_MENU_OBJECT);
             if ($cache) {
                 $this->_menu->unserialize($cache);
                 return;
             }
         }
         /* @var $director Mage_Backend_Model_Menu_Builder */
         $menuBuilder = $this->_appConfig->getModelInstance('Mage_Backend_Model_Menu_Builder', array('menu' => $this->_menu, 'itemFactory' => $this->_appConfig->getModelInstance('Mage_Backend_Model_Menu_Item_Factory')));
         /* @var $director Mage_Backend_Model_Menu_Director_Dom */
         $director = $this->_appConfig->getModelInstance('Mage_Backend_Model_Menu_Director_Dom', array('config' => $this->_getDom(), 'factory' => $this->_appConfig, 'logger' => $this->_logger));
         $director->buildMenu($menuBuilder);
         $this->_menu = $menuBuilder->getResult();
         $this->_eventManager->dispatch('backend_menu_load_after', array('menu' => $this->_menu));
         if ($this->_cache->canUse('config')) {
             $this->_cache->save($this->_menu->serialize(), self::CACHE_MENU_OBJECT, array(Mage_Core_Model_Config::CACHE_TAG));
         }
     }
 }
Example #6
0
 /**
  * Get menu filter iterator
  *
  * @param Mage_Backend_Model_Menu $menu menu model
  * @return Mage_Backend_Model_Menu_Filter_Iterator
  */
 protected function _getMenuIterator(Mage_Backend_Model_Menu $menu)
 {
     return $this->_objectFactory->getModelInstance('Mage_Backend_Model_Menu_Filter_Iterator', $menu->getIterator());
 }
Example #7
0
 /**
  * Get menu filter iterator
  *
  * @param Mage_Backend_Model_Menu $menu
  * @return Mage_Backend_Model_Menu_Filter_Iterator
  */
 protected function _getMenuIterator($menu)
 {
     return Mage::getModel('Mage_Backend_Model_Menu_Filter_Iterator', $menu->getIterator());
 }
Example #8
0
 /**
  * Check whether item has subnodes
  *
  * @return bool
  */
 public function hasChildren()
 {
     return !is_null($this->_submenu) && (bool) $this->_submenu->count();
 }
Example #9
0
 public function __wakeup()
 {
     if (Mage::getIsSerializable()) {
         $this->_moduleHelper = Mage::helper($this->_moduleHelperName);
         $this->_validator = Mage::getSingleton('Mage_Backend_Model_Menu_Item_Validator');
         $this->_acl = Mage::getSingleton('Mage_Core_Model_Authorization');
         $this->_appConfig = Mage::getConfig();
         $this->_storeConfig = Mage::getSingleton('Mage_Core_Model_Store_Config');
         $this->_menuFactory = Mage::getSingleton('Mage_Backend_Model_Menu_Factory');
         $this->_urlModel = Mage::getSingleton('Mage_Backend_Model_Url');
         if ($this->_serializedSubmenu) {
             $this->_submenu = $this->_menuFactory->getMenuInstance();
             $this->_submenu->unserialize($this->_serializedSubmenu);
         }
     }
 }
Example #10
0
 public function testSerialize()
 {
     $this->assertNotEmpty($this->_model->serialize());
     $this->_logger->expects($this->once())->method('log');
     $this->_model->add($this->_items['item1']);
 }