Beispiel #1
0
 /**
  * @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());
 }
 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;
 }
Beispiel #3
0
 /**
  * @param Mage_Core_Model_Layout $layout
  * @param array $dynamicBlocks
  * @return Mage_Core_Model_Layout
  */
 protected function _prepareLayout(Mage_Core_Model_Layout $layout, array $dynamicBlocks)
 {
     $xml = simplexml_load_string($layout->getXmlString(), Lesti_Fpc_Helper_Data::LAYOUT_ELEMENT_CLASS);
     $cleanXml = simplexml_load_string('<layout/>', Lesti_Fpc_Helper_Data::LAYOUT_ELEMENT_CLASS);
     $types = array('block', 'reference', 'action');
     foreach ($dynamicBlocks as $blockName) {
         foreach ($types as $type) {
             $xPath = $xml->xpath("//" . $type . "[@name='" . $blockName . "']");
             foreach ($xPath as $child) {
                 $cleanXml->appendChild($child);
             }
         }
     }
     $layout->setXml($cleanXml);
     $layout->generateBlocks();
     return Mage::helper('fpc/block_messages')->initLayoutMessages($layout);
 }