示例#1
0
 /**
  * @covers Mage_Core_Model_Layout_ScheduledStructure::setElement
  */
 public function testSetElement()
 {
     $data = array('some', 'new', 'data');
     /** Test add new element */
     $this->assertFalse($this->_model->hasElement('new_element'));
     $this->_model->setElement('new_element', $data);
     $this->assertEquals($data, $this->_model->getElement('new_element'));
     /** Test override existing element */
     $this->assertTrue($this->_model->hasElement('element1'));
     $this->_model->setElement('element1', $data);
     $this->assertEquals($data, $this->_model->getElement('element1'));
 }
示例#2
0
 /**
  * Creates block object based on xml node data and add it to the layout
  *
  * @param string $elementName
  * @return Mage_Core_Block_Abstract
  * @throws Magento_Exception
  */
 protected function _generateBlock($elementName)
 {
     list($type, $node, $actions, $arguments) = $this->_scheduledStructure->getElement($elementName);
     if ($type !== self::TYPE_BLOCK) {
         throw new Magento_Exception("Unexpected element type specified for generating block: {$type}.");
     }
     // create block
     if (!empty($node['class'])) {
         $className = (string) $node['class'];
     } else {
         $className = (string) $node['type'];
     }
     $arguments = $this->_argumentProcessor->process($arguments);
     $block = $this->_createBlock($className, $elementName, $arguments);
     if (!empty($node['template'])) {
         $block->setTemplate((string) $node['template']);
     }
     $this->_scheduledStructure->unsetElement($elementName);
     // execute block methods
     foreach ($actions as $action) {
         list($actionNode, $parent) = $action;
         $this->_generateAction($actionNode, $parent);
     }
     return $block;
 }