/** * @covers Mage_Core_Block_Abstract::getChildHtml * @covers Mage_Core_Block_Abstract::getChildChildHtml */ public function testGetChildHtml() { // Without layout $this->assertEmpty($this->_block->getChildHtml()); $this->assertEmpty($this->_block->getChildHtml('block')); // With layout $parent = $this->_createBlockWithLayout('parent', 'parent'); $blockOne = $this->_createBlockWithLayout('block1', 'block1', 'Mage_Core_Block_Text'); $blockTwo = $this->_createBlockWithLayout('block2', 'block2', 'Mage_Core_Block_Text'); $blockOne->setText('one'); $blockTwo->setText('two'); $parent->insert($blockTwo, '-', false, 'block2'); // make block2 1st $parent->insert($blockOne, '-', false, 'block1'); // make block1 1st $this->assertEquals('one', $parent->getChildHtml('block1')); $this->assertEquals('two', $parent->getChildHtml('block2')); // Sorted will render in the designated order $this->assertEquals('onetwo', $parent->getChildHtml('', true, true)); // GetChildChildHtml $blockTwo->setChild('block11', $blockOne); $this->assertEquals('one', $parent->getChildChildHtml('block2')); $this->assertEquals('', $parent->getChildChildHtml('')); $this->assertEquals('', $parent->getChildChildHtml('block3')); }
/** * @covers Mage_Core_Block_Abstract::getChildHtml * @covers Mage_Core_Block_Abstract::getChildChildHtml */ public function testGetChildHtml() { $blockOne = new Mage_Core_Block_Text(); $blockOne->setText('one')->setNameInLayout(uniqid('block.one.')); $blockTwo = new Mage_Core_Block_Text(); $blockTwo->setText('two')->setNameInLayout(uniqid('block.two.')); $this->_block->insert($blockTwo, '', false, 'block2'); // make block2 1st $this->_block->insert($blockOne, '', false, 'block1'); // make block1 1st $this->assertEquals('one', $this->_block->getChildHtml('block1')); $this->assertEquals('two', $this->_block->getChildHtml('block2')); // unsorted children will render in the order they were added $this->assertEquals('twoone', $this->_block->getChildHtml()); // hack: rendering sorted children requires layout $layout = new Mage_Core_Model_Layout(); $this->_block->setLayout($layout); $blockOne->setLayout($layout); $layout->setBlock($blockOne->getNameInLayout(), $blockOne); $blockTwo->setLayout($layout); $layout->setBlock($blockTwo->getNameInLayout(), $blockTwo); // sorted will render in the designated order $this->assertEquals('onetwo', $this->_block->getChildHtml('', true, true)); // getChildChildHtml $blockTwo->setChild('block11', $blockOne); $this->assertEquals('one', $this->_block->getChildChildHtml('block2')); $this->assertEquals('', $this->_block->getChildChildHtml('')); $this->assertEquals('', $this->_block->getChildChildHtml('block3')); }
/** * Inject child blocks * * @param $source * @param Mage_Core_Block_Abstract $block * @return mixed */ public function injectChildBlocks($source, Mage_Core_Block_Abstract $block) { $count = null; $source = preg_replace_callback('/<!--\\s*###(.+)###\\s*-->(.*)<!--\\s*###\\/\\1###\\s*-->/s', function ($matches) use($block) { //if (Mage::getIsDeveloperMode()) { // Mage::log('[Aoe_TemplateImport] Injecting block: ' . $matches[1]); //} return '<!-- BEGIN BLOCK: ' . $matches[1] . ' -->' . $block->getChildHtml($matches[1]) . '<!-- END BLOCK: ' . $matches[1] . ' -->'; }, $source, -1, $count); //if (Mage::getIsDeveloperMode()) { // Mage::log('[Aoe_TemplateImport] Match count: ' . $count); //} return $source; }
/** * @param Mage_Core_Block_Abstract $block * @return string */ public function getActionHtml($block) { $html = ''; $actions = $block->getChildGroup('actions'); uasort($actions, array($this, 'compareBySortOrder')); foreach ($actions as $alias => $action) { /* @var $action Mana_Admin_Block_Action */ $params = $action->getData(); $this->copyParam($params, 'title', 'label'); $action->setData($params); $html .= $block->getChildHtml($alias); } return $html; }