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()); }
/** * Loads a Magento layout block * * @param string $name Reference name of block * @param boolean $render true: As HTML string; false: As block object * * @return string|Mage_Core_Block_Abstract|boolean */ public static function getBlock($name, $render = true) { /** * @var Mage_Core_Block_Abstract $block */ $block = self::$layout->getBlock($name); if ($block && $render) { return $block->toHtml(); } else { if ($block && $render === false) { return $block; } } return false; }
/** * @param Mage_Core_Model_Layout */ protected function showAddressFields(Mage_Core_Model_Layout $layout) { $registerForm = $layout->getBlock('customer_form_register'); if ($registerForm instanceof Mage_Core_Block_Abstract) { $registerForm->setShowAddressFields(true); } }
/** * @magentoConfigFixture adminhtml/design/theme/full_name test/default */ public function testGridContainsMassactionColumn() { $this->_layout->getBlock('admin.test.grid')->toHtml(); $gridMassactionColumn = $this->_layout->getBlock('admin.test.grid')->getColumnSet()->getChildBlock('massaction'); $this->assertNotNull($gridMassactionColumn, 'Massaction column is not existed in grid column set'); $this->assertInstanceOf('Mage_Backend_Block_Widget_Grid_Column', $gridMassactionColumn, 'Massaction column is not instance of Mage_Backend_Block_Widget_Column'); }
public function testGetBlock() { $this->assertFalse($this->_layout->getBlock('test')); $block = new Mage_Core_Block_Text(); $this->_layout->setBlock('test', $block); $this->assertSame($block, $this->_layout->getBlock('test')); }
/** * Retrieve block html * * @param string $name * @return string */ public function getBlockHtml($name) { $block = $this->_layout->getBlock($name); if ($block) { return $block->toHtml(); } return ''; }
public function testSetUnsetBlock() { $expectedBlockName = 'block_' . __METHOD__; $expectedBlock = new Mage_Core_Block_Text(); $this->_model->setBlock($expectedBlockName, $expectedBlock); $this->assertSame($expectedBlock, $this->_model->getBlock($expectedBlockName)); $this->_model->unsetBlock($expectedBlockName); $this->assertFalse($this->_model->getBlock($expectedBlockName)); }
/** * 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; }
/** * @magentoDataFixture Mage/Catalog/_files/product_simple.php * @magentoAppIsolation enabled */ public function testPrepareLayout() { Mage::getConfig()->setCurrentAreaCode(Mage::helper("Mage_Backend_Helper_Data")->getAreaCode()); $product = new Mage_Catalog_Model_Product(); $product->load(1); // fixture Mage::register('product', $product); $layout = new Mage_Core_Model_Layout(); $layout->addBlock('Mage_Core_Block_Text', 'head'); $block = new Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs(); $layout->addBlock($block); $this->assertArrayHasKey(0, $block->getTabsIds()); $this->assertNotEmpty($layout->getBlock('adminhtml.catalog.product.edit.tab.attributes')); }
public function testRenameElement() { $blockName = 'block'; $expBlockName = 'block_renamed'; $containerName = 'container'; $expContainerName = 'container_renamed'; $block = $this->_layout->createBlock('Mage_Core_Block_Text', $blockName); //$this->_layout->insertContainer('', $containerName); $this->assertEquals($block, $this->_layout->getBlock($blockName)); //$this->_layout->renameElement($blockName, $expBlockName); $this->assertEquals($block, $this->_layout->getBlock($expBlockName)); $this->_layout->hasElement($containerName); //$this->_layout->renameElement($containerName, $expContainerName); $this->_layout->hasElement($expContainerName); }
protected function _renderBlock() { $layout = new Mage_Core_Model_Layout($this->_definition['layout']); $layout->generateBlocks(); $block = $layout->getBlock($this->_definition['block_name']); if ($block) { $block->setProductIds($this->_getProductIds()); $collection = $block->getItemsCollection(); // set correct order if (is_object($collection)) { foreach ($this->_getProductIds() as $productId) { $item = $collection->getItemById($productId); $collection->removeItemByKey($productId); if ($item) { $collection->addItem($item); } } } $html = $block->toHtml(); } else { $html = self::EMPTY_VALUE; } return $html; }
/** * Insert block * * @param string $blockName * @param Mage_Core_Model_Layout $layout */ protected function _insertBlock($blockName, Mage_Core_Model_Layout $layout) { $destination = null; switch (true) { case $layout->getBlock('form.additional.info') instanceof Mage_Core_Block_Text_List: $destination = $layout->getBlock('form.additional.info'); break; case $layout->getBlock('before_body_end') instanceof Mage_Core_Block_Text_List: $destination = $layout->getBlock('before_body_end'); break; case $layout->getBlock('content') instanceof Mage_Core_Block_Text_List: $destination = $layout->getBlock('content'); break; default: $destination = null; break; } if ($destination) { $destination->insert($blockName); } }
public function addAssets(Mage_Core_Model_Layout $layout) { $head = $layout->getBlock('head'); $content = $layout->getBlock('content'); if ($head && $content) { $head->addCss('webforms/form.css'); $head->addJs('prototype/window.js'); $head->addItem('js_css', 'prototype/windows/themes/default.css'); $head->addItem('js_css', 'prototype/windows/themes/alphacube.css'); // logic $head->addJs('webforms/logic.js'); // stars $head->addJs('webforms/stars.js'); $head->addCss('webforms/stars.css'); // tooltips $head->addJs('webforms/HelpBalloon.js'); $head->addCss('webforms/helpballoon.css'); // wysiwyg $head->addJs('tiny_mce/tiny_mce.js'); // calendar $head->addJs('calendar/calendar.js'); $head->addJs('calendar/calendar-setup.js'); $head->addItem('js_css', 'calendar/calendar-blue.css'); // ajax file uploader if (Mage::getStoreConfig('webforms/files/ajax')) { if (Mage::getStoreConfig('webforms/files/load_jquery')) { $head->addJs('webforms/jQuery/jquery-1.7.1.min.js'); $head->addJs('webforms/jQuery/no-conflict.js'); } $head->addJs('webforms/blueimp/js/vendor/jquery.ui.widget.js'); $head->addJs('webforms/blueimp/js/jquery.iframe-transport.js'); $head->addJs('webforms/blueimp/js/jquery.fileupload.js'); $head->addCss('webforms/file-upload.css'); } } if (in_array('cms_page', $layout->getUpdate()->getHandles()) || in_array('webforms_index_index', $layout->getUpdate()->getHandles())) { if (!$this->isProduction()) { Mage::getSingleton('core/session')->addError($this->getNote()); } } // add custom assets Mage::dispatchEvent('webforms_add_assets', array('layout' => $layout)); return $this; }
public function addAssets(Mage_Core_Model_Layout $layout) { if ($layout->getBlock('head')) { $layout->getBlock('head')->addCss('webforms/form.css'); $layout->getBlock('head')->addCss('webforms/results.css'); $layout->getBlock('head')->addJs('prototype/window.js'); $layout->getBlock('head')->addItem('js_css', 'prototype/windows/themes/default.css'); $layout->getBlock('head')->addItem('js_css', 'prototype/windows/themes/magento.css'); } // add custom assets Mage::dispatchEvent('webforms_add_assets', array('layout' => $layout)); return $this; }
public function testLayoutDirectives() { /** * Test correct move */ $layout = new Mage_Core_Model_Layout(); $layout->getUpdate()->load(array('layout_test_handle_move')); $layout->generateXml()->generateElements(); $this->assertEquals('container2', $layout->getParentName('container1')); $this->assertEquals('container1', $layout->getParentName('no.name2')); $this->assertEquals('block_container', $layout->getParentName('no_name3')); // verify `after` attribute $this->assertEquals('block_container', $layout->getParentName('no_name')); $childrenOrderArray = array_keys($layout->getChildBlocks($layout->getParentName('no_name'))); $positionAfter = array_search('child_block1', $childrenOrderArray); $positionToVerify = array_search('no_name', $childrenOrderArray); $this->assertEquals($positionAfter, --$positionToVerify); // verify `before` attribute $this->assertEquals('block_container', $layout->getParentName('no_name4')); $childrenOrderArray = array_keys($layout->getChildBlocks($layout->getParentName('no_name4'))); $positionBefore = array_search('child_block2', $childrenOrderArray); $positionToVerify = array_search('no_name4', $childrenOrderArray); $this->assertEquals($positionBefore, ++$positionToVerify); /** * Test move with the same alias */ $layout = new Mage_Core_Model_Layout(); $layout->getUpdate()->load(array('layout_test_handle_move_the_same_alias')); $layout->generateXml()->generateElements(); $this->assertEquals('container1', $layout->getParentName('no_name3')); /** * Test move with a new alias */ $layout = new Mage_Core_Model_Layout(); $layout->getUpdate()->load(array('layout_test_handle_move_new_alias')); $layout->generateXml()->generateElements(); $this->assertEquals('new_alias', $layout->getElementAlias('no_name3')); /** * Test layout action with anonymous parent block */ $layout = new Mage_Core_Model_Layout(); $layout->getUpdate()->load(array('layout_test_handle_action_for_anonymous_parent_block')); $layout->generateXml()->generateElements(); $this->assertEquals('schedule_block', $layout->getParentName('test.block.insert')); $this->assertEquals('schedule_block_1', $layout->getParentName('test.block.append')); /** * Test layout remove directive */ $layout = new Mage_Core_Model_Layout(); $layout->getUpdate()->load(array('layout_test_handle_remove')); $layout->generateXml()->generateElements(); $this->assertFalse($layout->getBlock('no_name2')); $this->assertFalse($layout->getBlock('child_block1')); $this->assertTrue($layout->isBlock('child_block2')); }
public function addAssets(Mage_Core_Model_Layout $layout) { $head = $layout->getBlock('head'); $content = $layout->getBlock('content'); if ($head && $content) { $head->addCss('webforms/form.css'); $head->addJs('prototype/window.js'); $head->addItem('js_css', 'prototype/windows/themes/default.css'); $head->addItem('js_css', 'prototype/windows/themes/alphacube.css'); } // add custom assets Mage::dispatchEvent('webforms_add_assets', array('layout' => $layout)); return $this; }
/** * Add css customization * * @param Mage_Core_Model_Layout $layout * @return Mage_Core_Model_Theme_Service */ protected function _addCssCustomization($layout) { /** @var $theme Mage_Core_Model_Theme_Files */ $customCssFile = $this->_design->getDesignTheme()->getCustomCssFile(); if ($customCssFile->getContent()) { $layout->getBlock('head')->addCss($customCssFile->getFilePath()); } return $this; }
public function testGetJs() { $expected = uniqid(); $this->_layout->getBlock('child')->setJs($expected); $this->assertEquals($expected, $this->_block->getJs()); }
/** * @param Mage_Core_Model_Layout $layout * @return bool|Mage_Catalog_Block_Product_List */ protected function _getProductList($layout) { foreach (array('product_list', 'search_result_list') as $blockName) { if ($result = $layout->getBlock($blockName)) { return $result; } } return false; }
/** * Creates block encoded in the marker for further processing. * * @return Mage_Core_Block_Abstract|null */ protected function _createBlock() { $args = $this->_blockArgs; $layout = new Mage_Core_Model_Layout($args['layout']); $layout->generateBlocks(); return $this->_block = $layout->getBlock($args['name']); }
public function addMagentoCss(Mage_Core_Model_Layout $layout) { $fileName1 = 'lib/prototype/windows/themes/magento.css'; if (is_file(Mage::getDesign()->getSkinBaseDir() . DS . str_replace('/', DS, $fileName1))) { return $layout->getBlock('head')->addCss($fileName1); } $fileName2 = 'prototype/windows/themes/magento.css'; if (is_file(Mage::getBaseDir() . DS . 'js' . DS . str_replace('/', DS, $fileName2))) { return $layout->getBlock('head')->addItem('js_css', $fileName2); } $layout->getBlock('head')->addCss($fileName1); $layout->getBlock('head')->addItem('js_css', $fileName2); }
/** * @param Mage_Core_Model_Layout $layout * @param Mage_Customer_Model_Session $session * @param array $dynamicBlocks * @param array $lazyBlocks */ protected function _insertDynamicBlocks(Mage_Core_Model_Layout &$layout, Mage_Customer_Model_Session &$session, array &$dynamicBlocks, array &$lazyBlocks) { foreach ($dynamicBlocks as $blockName) { $block = $layout->getBlock($blockName); if ($block) { $this->_placeholder[] = Mage::helper('fpc/block')->getPlaceholderHtml($blockName); $html = $block->toHtml(); if (in_array($blockName, $lazyBlocks)) { $session->setData('fpc_lazy_block_' . $blockName, $html); } $this->_html[] = $html; } } }