@SuppressWarnings(PHPMD.CouplingBetweenObjects)
Definition at line 19 of file LayoutTest.php.
◆ addContainerDataProvider()
addContainerDataProvider |
( |
| ) |
|
◆ blockNotExistsDataProvider()
blockNotExistsDataProvider |
( |
| ) |
|
Definition at line 215 of file LayoutTest.php.
217 return [[
''], [
'block_not_exists']];
◆ createBlockDataProvider()
createBlockDataProvider |
( |
| ) |
|
Definition at line 190 of file LayoutTest.php.
193 'named block' => [\Magento\Framework\View\Element\Template::class,
194 'some_block_name_full_class',
195 [
'type' => \Magento\Framework\View\Element\Template::class,
'is_anonymous' =>
false],
196 '/^some_block_name_full_class$/',
198 'no name block' => [\Magento\Framework\View\Element\Text\ListText::class,
200 [
'type' => \Magento\Framework\View\Element\Text\ListText::class,
'key1' =>
'value1'],
◆ setUp()
Definition at line 31 of file LayoutTest.php.
35 $this->_layout = $this->layoutFactory->create();
static getObjectManager()
◆ testAddBlock()
Definition at line 220 of file LayoutTest.php.
222 $this->assertInstanceOf(
223 \
Magento\Framework\View\Element\Text::class,
224 $this->_layout->addBlock(\
Magento\Framework\View\Element\Text::class,
'block1')
227 \
Magento\Framework\View\Element\Text::class
229 $block2->setNameInLayout(
'block2');
230 $this->_layout->addBlock($block2,
'',
'block1');
232 $this->assertTrue($this->_layout->hasElement(
'block1'));
233 $this->assertTrue($this->_layout->hasElement(
'block2'));
234 $this->assertEquals(
'block1', $this->_layout->getParentName(
'block2'));
static getObjectManager()
◆ testAddBlockInvalidType()
testAddBlockInvalidType |
( |
| ) |
|
@expectedException \Magento\Framework\Exception\LocalizedException
Definition at line 366 of file LayoutTest.php.
368 $this->_layout->addBlock(
'invalid_name',
'child');
◆ testAddContainer()
testAddContainer |
( |
|
$htmlTag | ) |
|
@magentoAppIsolation enabled @dataProvider addContainerDataProvider()
Definition at line 241 of file LayoutTest.php.
243 $this->assertFalse($this->_layout->hasElement(
'container'));
244 $this->_layout->addContainer(
'container',
'Container', [
'htmlTag' => $htmlTag]);
245 $this->assertTrue($this->_layout->hasElement(
'container'));
246 $this->assertTrue($this->_layout->isContainer(
'container'));
247 $this->assertEquals($htmlTag, $this->_layout->getElementProperty(
'container',
'htmlTag'));
249 $this->_layout->addContainer(
'container1',
'Container 1', [],
'container',
'c1');
250 $this->assertEquals(
'container1', $this->_layout->getChildName(
'container',
'c1'));
◆ testAddContainerInvalidHtmlTag()
testAddContainerInvalidHtmlTag |
( |
| ) |
|
@magentoAppIsolation enabled
Definition at line 273 of file LayoutTest.php.
275 $msg =
'Html tag "span" is forbidden for usage in containers. ' .
276 'Consider to use one of the allowed: aside, dd, div, dl, fieldset, main, nav, ' .
277 'header, footer, ol, p, section, table, tfoot, ul.';
278 $this->expectException(\
Magento\Framework\Exception\LocalizedException::class);
279 $this->expectExceptionMessage($msg);
280 $this->_layout->addContainer(
'container',
'Container', [
'htmlTag' =>
'span']);
◆ testCreateBlock()
testCreateBlock |
( |
|
$blockType, |
|
|
|
$blockName, |
|
|
array |
$blockData, |
|
|
|
$expectedName |
|
) |
| |
@dataProvider createBlockDataProvider
Definition at line 180 of file LayoutTest.php.
182 $expectedData = $blockData + [
'type' => $blockType];
184 $block = $this->_layout->createBlock($blockType, $blockName, [
'data' => $blockData]);
186 $this->assertRegExp($expectedName,
$block->getNameInLayout());
187 $this->assertEquals($expectedData,
$block->getData());
◆ testCreateBlockNotExists()
testCreateBlockNotExists |
( |
|
$name | ) |
|
@dataProvider blockNotExistsDataProvider @expectedException \Magento\Framework\Exception\LocalizedException
Definition at line 210 of file LayoutTest.php.
212 $this->_layout->createBlock(
$name);
if(!isset($_GET['name'])) $name
◆ testDestructor()
@magentoAppIsolation enabled @magentoAppArea frontend
Definition at line 53 of file LayoutTest.php.
55 $this->_layout->addBlock(\
Magento\Framework\View\Element\Text::class,
'test');
56 $this->assertNotEmpty($this->_layout->getAllBlocks());
57 $this->_layout->__destruct();
58 $this->assertEmpty($this->_layout->getAllBlocks());
◆ testGenerateGetAllBlocks()
testGenerateGetAllBlocks |
( |
| ) |
|
A smoke test for generating elements
See sophisticated tests at \Magento\Framework\View\LayoutDirectivesTest
- See also
- \Magento\Framework\View\LayoutDirectivesTest @magentoAppIsolation enabled
Definition at line 101 of file LayoutTest.php.
103 $this->_layout->setXml(
104 simplexml_load_string(
106 <block class="Magento\Framework\View\Element\Text" name="block1"> 107 <block class="Magento\Framework\View\Element\Text"/> 109 <block class="Magento\Framework\View\Element\Text" template="test" ttl="360"/> 110 <block class="Magento\Framework\View\Element\Text"/> 112 \
Magento\Framework\View\Layout\Element::class
115 $this->assertEquals([], $this->_layout->getAllBlocks());
116 $this->_layout->generateElements();
117 $expected = [
'block1',
'block1_schedule_block0',
'schedule_block1',
'schedule_block2'];
118 $this->assertSame($expected, array_keys($this->_layout->getAllBlocks()));
119 $child = $this->_layout->getBlock(
'block1_schedule_block0');
120 $this->assertSame($this->_layout->getBlock(
'block1'), $child->getParentBlock());
121 $this->assertEquals(
'test', $this->_layout->getBlock(
'schedule_block1')->getData(
'template'));
122 $this->assertEquals(
'360', $this->_layout->getBlock(
'schedule_block1')->getData(
'ttl'));
123 $this->assertFalse($this->_layout->getBlock(
'nonexisting'));
◆ testGetBlock()
Definition at line 418 of file LayoutTest.php.
420 $this->assertFalse($this->_layout->getBlock(
'test'));
422 \
Magento\Framework\View\Layout::class
424 \
Magento\Framework\View\Element\Text::class
426 $this->_layout->setBlock(
'test',
$block);
427 $this->assertSame(
$block, $this->_layout->getBlock(
'test'));
static getObjectManager()
◆ testGetBlockSingleton()
testGetBlockSingleton |
( |
| ) |
|
Definition at line 476 of file LayoutTest.php.
478 $block = $this->_layout->getBlockSingleton(\
Magento\Framework\View\Element\Text::class);
479 $this->assertInstanceOf(\
Magento\Framework\View\Element\Text::class,
$block);
480 $this->assertSame(
$block, $this->_layout->getBlockSingleton(\
Magento\Framework\View\Element\Text::class));
◆ testGetChildBlock()
@magentoAppIsolation enabled
Definition at line 286 of file LayoutTest.php.
288 $this->_layout->addContainer(
'parent',
'Parent');
289 $block = $this->_layout->addBlock(
290 \
Magento\Framework\View\Element\Text::class,
295 $this->_layout->addContainer(
'container',
'Container', [],
'parent',
'container_alias');
296 $this->assertSame(
$block, $this->_layout->getChildBlock(
'parent',
'block_alias'));
297 $this->assertFalse($this->_layout->getChildBlock(
'parent',
'container_alias'));
◆ testGetChildBlocks()
@magentoAppIsolation enabled
Definition at line 354 of file LayoutTest.php.
356 $this->_layout->addContainer(
'parent',
'Parent');
357 $block1 = $this->_layout->addBlock(\
Magento\Framework\View\Element\Text::class,
'block1',
'parent');
358 $this->_layout->addContainer(
'container',
'Container', [],
'parent');
359 $block2 = $this->_layout->addBlock(\
Magento\Framework\View\Element\Template::class,
'block2',
'parent');
360 $this->assertSame([
'block1' => $block1,
'block2' => $block2], $this->_layout->getChildBlocks(
'parent'));
◆ testGetElementAlias()
Definition at line 441 of file LayoutTest.php.
443 $this->_layout->addContainer(
'one',
'One');
444 $this->_layout->addContainer(
'two',
'One', [],
'one',
'1');
445 $this->assertFalse($this->_layout->getElementAlias(
'one'));
446 $this->assertEquals(
'1', $this->_layout->getElementAlias(
'two'));
◆ testGetElementProperty()
testGetElementProperty |
( |
| ) |
|
Definition at line 126 of file LayoutTest.php.
129 $this->_layout->addContainer(
$name,
'Test', [
'option1' => 1,
'option2' => 2]);
136 $this->_layout->getElementProperty(
$name,
'type')
138 $this->assertSame(2, $this->_layout->getElementProperty(
$name,
'option2'));
140 $this->_layout->addBlock(\
Magento\Framework\View\Element\Text::class,
'text',
$name);
143 $this->_layout->getElementProperty(
'text',
'type')
147 $this->_layout->getElementProperty(
$name, \
Magento\Framework\Data\Structure::CHILDREN)
const CONTAINER_OPT_LABEL
if(!isset($_GET['name'])) $name
◆ testGetMessagesBlock()
Definition at line 471 of file LayoutTest.php.
473 $this->assertInstanceOf(\
Magento\Framework\View\Element\Messages::class, $this->_layout->getMessagesBlock());
◆ testGetOutput()
@covers \Magento\Framework\View\Layout::addOutputElement @covers \Magento\Framework\View\Layout::getOutput @covers \Magento\Framework\View\Layout::removeOutputElement
Definition at line 454 of file LayoutTest.php.
456 $blockName =
'block_' . __METHOD__;
457 $expectedText =
"some_text_for_{$blockName}";
459 $block = $this->_layout->addBlock(\
Magento\Framework\View\Element\Text::class, $blockName);
460 $block->setText($expectedText);
462 $this->_layout->addOutputElement($blockName);
464 $this->_layout->addOutputElement($blockName);
465 $this->assertEquals($expectedText, $this->_layout->getOutput());
467 $this->_layout->removeOutputElement($blockName);
468 $this->assertEmpty($this->_layout->getOutput());
◆ testGetParentName()
@magentoAppIsolation enabled
Definition at line 433 of file LayoutTest.php.
435 $this->_layout->addContainer(
'one',
'One');
436 $this->_layout->addContainer(
'two',
'Two', [],
'one');
437 $this->assertFalse($this->_layout->getParentName(
'one'));
438 $this->assertEquals(
'one', $this->_layout->getParentName(
'two'));
◆ testGetUpdate()
Definition at line 61 of file LayoutTest.php.
63 $this->assertInstanceOf(\
Magento\Framework\View\Layout\ProcessorInterface::class, $this->_layout->getUpdate());
◆ testIsBlock()
@magentoAppIsolation enabled
Definition at line 154 of file LayoutTest.php.
156 $this->assertFalse($this->_layout->isBlock(
'container'));
157 $this->assertFalse($this->_layout->isBlock(
'block'));
158 $this->_layout->addContainer(
'container',
'Container');
159 $this->_layout->addBlock(\
Magento\Framework\View\Element\Text::class,
'block');
160 $this->assertFalse($this->_layout->isBlock(
'container'));
161 $this->assertTrue($this->_layout->isBlock(
'block'));
◆ testIsCacheable()
Definition at line 498 of file LayoutTest.php.
500 $this->_layout->setXml(
502 __DIR__ .
'/_files/layout/cacheable.xml',
503 \
Magento\Framework\View\Layout\Element::class
506 $this->_layout->generateElements();
507 $this->assertTrue($this->_layout->isCacheable());
defined('TESTS_BP')||define('TESTS_BP' __DIR__
◆ testIsContainer()
@magentoAppIsolation enabled
Definition at line 374 of file LayoutTest.php.
377 $container =
'container';
378 $this->_layout->addBlock(\
Magento\Framework\View\Element\Text::class,
$block);
379 $this->_layout->addContainer($container,
'Container');
380 $this->assertFalse($this->_layout->isContainer(
$block));
381 $this->assertTrue($this->_layout->isContainer($container));
382 $this->assertFalse($this->_layout->isContainer(
'invalid_name'));
◆ testIsManipulationAllowed()
testIsManipulationAllowed |
( |
| ) |
|
Definition at line 385 of file LayoutTest.php.
387 $this->_layout->addBlock(\
Magento\Framework\View\Element\Text::class,
'block1');
388 $this->_layout->addBlock(\
Magento\Framework\View\Element\Text::class,
'block2',
'block1');
389 $this->assertFalse($this->_layout->isManipulationAllowed(
'block1'));
390 $this->assertFalse($this->_layout->isManipulationAllowed(
'block2'));
392 $this->_layout->addContainer(
'container1',
'Container 1');
393 $this->_layout->addBlock(\
Magento\Framework\View\Element\Text::class,
'block3',
'container1');
394 $this->_layout->addContainer(
'container2',
'Container 2', [],
'container1');
395 $this->assertFalse($this->_layout->isManipulationAllowed(
'container1'));
396 $this->assertTrue($this->_layout->isManipulationAllowed(
'block3'));
397 $this->assertTrue($this->_layout->isManipulationAllowed(
'container2'));
◆ testIsNonCacheable()
Definition at line 510 of file LayoutTest.php.
512 $this->_layout->setXml(
514 __DIR__ .
'/_files/layout/non_cacheable.xml',
515 \
Magento\Framework\View\Layout\Element::class
518 $this->_layout->generateElements();
519 $this->assertFalse($this->_layout->isCacheable());
defined('TESTS_BP')||define('TESTS_BP' __DIR__
◆ testRenameElement()
Definition at line 400 of file LayoutTest.php.
402 $blockName =
'block';
403 $expBlockName =
'block_renamed';
404 $containerName =
'container';
405 $expContainerName =
'container_renamed';
406 $block = $this->_layout->createBlock(\
Magento\Framework\View\Element\Text::class, $blockName);
407 $this->_layout->addContainer($containerName,
'Container');
409 $this->assertEquals(
$block, $this->_layout->getBlock($blockName));
410 $this->_layout->renameElement($blockName, $expBlockName);
411 $this->assertEquals(
$block, $this->_layout->getBlock($expBlockName));
413 $this->_layout->hasElement($containerName);
414 $this->_layout->renameElement($containerName, $expContainerName);
415 $this->_layout->hasElement($expContainerName);
◆ testReorderChild()
- Parameters
-
\Magento\Framework\View\LayoutInterface | $layout | @depends testSetChild |
Definition at line 318 of file LayoutTest.php.
320 $layout->addContainer(
'four',
'Four', [],
'one');
323 $layout->reorderChild(
'one',
'four', 1);
324 $this->assertSame([
'two',
'four',
'three'], $layout->getChildNames(
'one'));
327 $layout->reorderChild(
'one',
'three', 2,
false);
328 $this->assertSame([
'two',
'three',
'four'], $layout->getChildNames(
'one'));
331 $layout->reorderChild(
'one',
'two',
'three');
332 $this->assertSame([
'three',
'two',
'four'], $layout->getChildNames(
'one'));
335 $layout->reorderChild(
'one',
'three',
'-');
336 $this->assertSame([
'two',
'four',
'three'], $layout->getChildNames(
'one'));
339 $layout->reorderChild(
'one',
'four',
'two',
false);
340 $this->assertSame([
'four',
'two',
'three'], $layout->getChildNames(
'one'));
343 $layout->reorderChild(
'one',
'two',
'-',
false);
344 $this->assertSame([
'two',
'four',
'three'], $layout->getChildNames(
'one'));
347 $layout->reorderChild(
'one',
'two',
'three_alias',
true);
348 $this->assertSame([
'four',
'three',
'two'], $layout->getChildNames(
'one'));
◆ testSetChild()
- Returns
- \Magento\Framework\View\Layout
Definition at line 303 of file LayoutTest.php.
305 $this->_layout->addContainer(
'one',
'One');
306 $this->_layout->addContainer(
'two',
'Two');
307 $this->_layout->addContainer(
'three',
'Three');
308 $this->assertSame($this->_layout, $this->_layout->setChild(
'one',
'two',
''));
309 $this->_layout->setChild(
'one',
'three',
'three_alias');
310 $this->assertSame([
'two',
'three'], $this->_layout->getChildNames(
'one'));
◆ testSetUnsetBlock()
Definition at line 164 of file LayoutTest.php.
166 $expectedBlockName =
'block_' . __METHOD__;
167 $expectedBlock = $this->_layout->createBlock(\
Magento\Framework\View\Element\Text::class);
169 $this->_layout->setBlock($expectedBlockName, $expectedBlock);
170 $this->assertSame($expectedBlock, $this->_layout->getBlock($expectedBlockName));
172 $this->_layout->unsetElement($expectedBlockName);
173 $this->assertFalse($this->_layout->getBlock($expectedBlockName));
174 $this->assertFalse($this->_layout->hasElement($expectedBlockName));
◆ testUpdateContainerAttributes()
testUpdateContainerAttributes |
( |
| ) |
|
Definition at line 483 of file LayoutTest.php.
485 $this->_layout->setXml(
487 __DIR__ .
'/_files/layout/container_attributes.xml',
488 \
Magento\Framework\View\Layout\Element::class
491 $this->_layout->generateElements();
492 $result = $this->_layout->renderElement(
'container1',
false);
493 $this->assertEquals(
'<div id="container1-2" class="class12">Test11Test12</div>',
$result);
494 $result = $this->_layout->renderElement(
'container2',
false);
495 $this->assertEquals(
'<div id="container2-2" class="class22">Test21Test22</div>',
$result);
defined('TESTS_BP')||define('TESTS_BP' __DIR__
◆ $_layout
◆ $layoutFactory
The documentation for this class was generated from the following file:
- vendor/magento/magento2-base/dev/tests/integration/testsuite/Magento/Framework/View/LayoutTest.php