protected function setUp() { $this->_layout = Mage::getModel('Mage_Core_Model_Layout', array('area' => 'adminhtml')); $this->_layout->getUpdate()->load('layout_test_grid_handle'); $this->_layout->generateXml(); $this->_layout->generateElements(); $this->_block = $this->_layout->getBlock('admin.test.grid.massaction'); }
/** * Get block * * @param string $blockName * @return Mage_Core_Block_Abstract */ public function getBlock($blockName) { /** @var $layout Mage_Core_Model_Layouts */ $this->_prepareLayout(); $this->_layout->getUpdate()->load($this->_getHandles()); $this->_layout->generateXml()->generateBlocks(); $block = $this->_layout->getBlock($blockName); $this->unsetLayout(); return $block; }
public function testLayoutObjectArgumentUpdatersDirective() { $layout = new Mage_Core_Model_Layout(); $layout->getUpdate()->load(array('layout_test_handle_arguments_object_type_updaters')); $layout->generateXml()->generateElements(); $expectedObjectData = array(0 => 'updater call', 1 => 'updater call', 2 => 'updater call'); $expectedSimpleData = 2; $block = $layout->getBlock('block_with_object_updater_args')->getOne(); $this->assertInstanceOf('Mage_Core_Block_Text', $block); $this->assertEquals($expectedObjectData, $block->getUpdaterCall()); $this->assertEquals($expectedSimpleData, $layout->getBlock('block_with_object_updater_args')->getTwo()); }
/** * @covers Mage_Core_Model_Layout::getAllBlocks * @covers Mage_Core_Model_Layout::generateBlocks * @covers Mage_Core_Model_Layout::getBlock */ public function testGenerateXmlAndBlocks() { $this->_model->generateXml(); /* Generate fixture file_put_contents(__DIR__ . '/_files/_layout_update.xml', $this->_model->getNode()->asNiceXml()); */ $this->assertXmlStringEqualsXmlFile(__DIR__ . '/_files/_layout_update.xml', $this->_model->getXmlString()); $this->assertEquals(array(), $this->_model->getAllBlocks()); $expectedBlocks = array('root', 'head', 'head.calendar', 'notifications', 'notification_baseurl', 'cache_notifications', 'notification_survey', 'notification_security', 'messages', 'index_notifications', 'index_notifications_copy'); $this->_model->generateBlocks(); $actualBlocks = $this->_model->getAllBlocks(); $this->assertEquals($expectedBlocks, array_keys($actualBlocks)); /** @var $block Mage_Adminhtml_Block_Page_Head */ $block = $this->_model->getBlock('head'); $this->assertEquals('Magento Admin', $block->getTitle()); $block = $this->_model->getBlock('head.calendar'); $this->assertSame($this->_model->getBlock('head'), $block->getParentBlock()); /** @var $block Mage_Core_Block_Template */ $block = $this->_model->getBlock('root'); $this->assertEquals('popup.phtml', $block->getTemplate()); }
/** * Take cache/noache/ESI tags into concern for block rendering * * @return Mage_Core_Model_Layout */ public function generateXml() { parent::generateXml(); $xml = $this->getNode(); // Find blocks to cache $cacheList = $xml->xpath("//cache/*"); if (count($cacheList)) { foreach ($cacheList as $node) { $lifetime = (int) $node->getAttribute('lifetime'); if (empty($lifetime)) { $lifetime = self::DEFAULT_CACHE_LIFETIME; } $modifiers = trim((string) $node->getAttribute('modifiers')); $key = (string) $node->getAttribute('key'); $this->_cacheBlocks[(string) $node] = array('lifetime' => $lifetime, 'key' => $key, 'modifiers' => $modifiers); } } // Find eventual nocache tags $noCacheList = $xml->xpath("//nocache/*"); if (count($noCacheList)) { foreach ($noCacheList as $node) { $blockName = trim((string) $node); if (isset($this->_cacheBlocks[$blockName])) { unset($this->_cacheBlocks[$blockName]); } } } // Find blocks that should be represented by ESI tags $esiList = $xml->xpath("//esi/*"); if (count($esiList)) { foreach ($esiList as $node) { $blockName = trim((string) $node); // Names are unique, an array could hold future settings $unique = trim((string) $node->getAttribute('unique')); $this->_esiBlocks[$blockName] = array('unique' => $unique); } } // Find eventual noesi tags $noEsiList = $xml->xpath("//noesi/*"); if (count($noEsiList)) { foreach ($noEsiList as $node) { $blockName = trim((string) $node); // Names are unique, an array could hold future settings if (isset($this->_esiBlocks[$blockName])) { unset($this->_esiBlocks[$blockName]); } } } return $this; }
protected function _generateBlockLayoutXML($blockName) { if (self::$_layoutXml == null) { self::$_layoutXml = Mage::app()->getLayout()->getUpdate()->asSimplexml(); } $sections = self::$_layoutXml->xpath("//block[@name='{$blockName}'] | //reference[@name='{$blockName}']"); $layoutXml = ''; foreach ($sections as $section) { $layoutXml .= $this->_generateSubBlockLayoutXml($section); } $layout = new Mage_Core_Model_Layout(); $layout->getUpdate()->addUpdate($layoutXml); $layout->generateXml(); $layoutXml = $layout->getXmlString(); return $layoutXml; }
/** * Records information about blocks removal and loaded layout handles * (non-PHPdoc) * @see Mage_Core_Model_Layout::generateXml() */ public function generateXml() { $loadedHandles = $this->getUpdate()->getHandles(); foreach ($loadedHandles as $key => $handle) { $params = array(); if ($key > 0) { $params['after'] = array_slice($loadedHandles, 0, $key); } else { $params['after'] = array(); } if ($key < count($loadedHandles)) { $params['before'] = array_slice($loadedHandles, $key + 1); } else { $params['before'] = array(); } $this->record(self::ACTION_HANDLE_LOADED, $handle, $params); } parent::generateXml(); $removedBlocks = $this->_xml->xpath('//block[@ignore]'); if (is_array($removedBlocks)) { foreach ($removedBlocks as $block) { $this->record(self::ACTION_BLOCK_REMOVED, $block->getBlockName()); } } return $this; }
/** * @expectedException Magento_Exception */ public function testGenerateElementsBroken() { $layout = new Mage_Core_Model_Layout(); $layout->getUpdate()->load('layout_test_handle_remove_broken'); $layout->generateXml()->generateElements(); }