示例#1
0
 public function setUp()
 {
     $logger = $this->getMock('Mage_Core_Model_Logger', array(), array(), '', false);
     $this->_menuModel = new Mage_Backend_Model_Menu($logger);
     $this->_menuSubModel = new Mage_Backend_Model_Menu($logger);
     $this->_factoryMock = $this->getMock('Mage_Core_Model_Config', array(), array(), '', false);
     $item1 = $this->getMock('Mage_Backend_Model_Menu_Item', array(), array(), '', false);
     $item1->expects($this->any())->method('getId')->will($this->returnValue('item1'));
     $item1->expects($this->any())->method('getTitle')->will($this->returnValue('Item 1'));
     $item1->expects($this->any())->method('isAllowed')->will($this->returnValue(true));
     $item1->expects($this->any())->method('isDisabled')->will($this->returnValue(false));
     $item1->expects($this->any())->method('getAction')->will($this->returnValue('adminhtml/item1'));
     $item1->expects($this->any())->method('getChildren')->will($this->returnValue($this->_menuSubModel));
     $item1->expects($this->any())->method('hasChildren')->will($this->returnValue(true));
     $this->_menuModel->add($item1);
     $item2 = $this->getMock('Mage_Backend_Model_Menu_Item', array(), array(), '', false);
     $item2->expects($this->any())->method('getId')->will($this->returnValue('item2'));
     $item2->expects($this->any())->method('getTitle')->will($this->returnValue('Item 2'));
     $item2->expects($this->any())->method('isAllowed')->will($this->returnValue(true));
     $item2->expects($this->any())->method('isDisabled')->will($this->returnValue(false));
     $item2->expects($this->any())->method('getAction')->will($this->returnValue('adminhtml/item2'));
     $item2->expects($this->any())->method('hasChildren')->will($this->returnValue(false));
     $this->_menuSubModel->add($item2);
     $this->_model = new Mage_Backend_Model_Config_Source_Admin_Page(array('menu' => $this->_menuModel, 'objectFactory' => $this->_factoryMock));
 }
示例#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;
 }
示例#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);
 }
示例#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);
 }
示例#5
0
 public function testSerialize()
 {
     $this->assertNotEmpty($this->_model->serialize());
     $this->_logger->expects($this->once())->method('log');
     $this->_model->add($this->_items['item1']);
 }