本文整理匯總了PHP中Magento\Framework\View\LayoutInterface::addBlock方法的典型用法代碼示例。如果您正苦於以下問題:PHP LayoutInterface::addBlock方法的具體用法?PHP LayoutInterface::addBlock怎麽用?PHP LayoutInterface::addBlock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Framework\View\LayoutInterface
的用法示例。
在下文中一共展示了LayoutInterface::addBlock方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testSetListCollection
public function testSetListCollection()
{
/** @var $childBlock \Magento\Framework\View\Element\Text */
$childBlock = $this->_layout->addBlock('Magento\\Framework\\View\\Element\\Text', 'search_result_list', 'block');
$this->assertEmpty($childBlock->getCollection());
$this->_block->setListCollection();
$this->assertInstanceOf('Magento\\CatalogSearch\\Model\\ResourceModel\\Advanced\\Collection', $childBlock->getCollection());
}
示例2: testToHtmlWithContainer
public function testToHtmlWithContainer()
{
$listName = $this->_block->getNameInLayout();
$block1 = $this->_layout->addBlock('Magento\\Framework\\View\\Element\\Text', '', $listName);
$this->_layout->addContainer('container', 'Container', [], $listName);
$block2 = $this->_layout->addBlock('Magento\\Framework\\View\\Element\\Text', '', 'container');
$block3 = $this->_layout->addBlock('Magento\\Framework\\View\\Element\\Text', '', $listName);
$block1->setText('text1');
$block2->setText('text2');
$block3->setText('text3');
$html = $this->_block->toHtml();
$this->assertEquals('text1text2text3', $html);
}
示例3: testGetInvoiceCommentsHtml
public function testGetInvoiceCommentsHtml()
{
$childBlock = $this->_layout->addBlock('Magento\\Framework\\View\\Element\\Text', 'invoice_comments', 'block');
$expectedHtml = '<b>Any html</b>';
$this->assertEmpty($childBlock->getEntity());
$this->assertEmpty($childBlock->getTitle());
$this->assertNotEquals($expectedHtml, $this->_block->getInvoiceCommentsHtml($this->_invoice));
$childBlock->setText($expectedHtml);
$actualHtml = $this->_block->getInvoiceCommentsHtml($this->_invoice);
$this->assertSame($this->_invoice, $childBlock->getEntity());
$this->assertNotEmpty($childBlock->getTitle());
$this->assertEquals($expectedHtml, $actualHtml);
}
示例4: testToHtmlPropagatesUrl
public function testToHtmlPropagatesUrl()
{
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\State')->setAreaCode('frontend');
$this->_block->setShouldPrepareInfoTabs(true);
$childOne = $this->_layout->addBlock('Magento\\Framework\\View\\Element\\Text', 'child1', 'block');
$this->_layout->addToParentGroup('child1', 'info_tabs');
$childTwo = $this->_layout->addBlock('Magento\\Framework\\View\\Element\\Text', 'child2', 'block');
$this->_layout->addToParentGroup('child2', 'info_tabs');
$this->assertEmpty($childOne->getViewUrl());
$this->assertEmpty($childTwo->getViewUrl());
$this->_block->toHtml();
$this->assertNotEmpty($childOne->getViewUrl());
$this->assertNotEmpty($childTwo->getViewUrl());
}
示例5: _createBlockWithLayout
/**
* Create Block with Layout
*
* @param string $name
* @param null|string $alias
* @param null|string $type
* @return \Magento\Framework\View\Element\AbstractBlock
*/
protected function _createBlockWithLayout($name = 'block', $alias = null, $type = 'Magento\\Framework\\View\\Element\\AbstractBlock')
{
$typePart = explode('\\', $type);
$mockClass = array_pop($typePart) . 'Mock';
if (!isset(self::$_mocks[$mockClass])) {
self::$_mocks[$mockClass] = $this->getMockForAbstractClass($type, [\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\Element\\Context'), ['module_name' => 'Magento_Theme']], $mockClass);
}
if ($this->_layout === null) {
$this->_layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface');
}
$block = $this->_layout->addBlock($mockClass, $name, '', $alias);
return $block;
}
示例6: setUp
protected function setUp()
{
$this->_layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface');
$this->_block = $this->_layout->addBlock('Magento\\Wishlist\\Block\\Customer\\Wishlist\\Item\\Column', 'test');
$this->_layout->addBlock('Magento\\Framework\\View\\Element\\Text', 'child', 'test');
}
示例7: _applyAccountLinksPersistentData
/**
* Emulate 'account links' block with persistent data
*
* @return void
*/
protected function _applyAccountLinksPersistentData()
{
if (!$this->_layout->getBlock('header.additional')) {
$this->_layout->addBlock('Magento\\Persistent\\Block\\Header\\Additional', 'header.additional');
}
}