-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #906 from Vinai/view-layout-reader-block
Add tests for View\Layout\Reader\Block and slight refactoring (MAGETWO-32829)
- Loading branch information
Showing
4 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
dev/tests/integration/testsuite/Magento/Framework/View/Layout/Reader/BlockTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace Magento\Framework\View\Layout\Reader; | ||
|
||
class BlockTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
const IDX_TYPE = 0; | ||
const IDX_PARENT = 2; | ||
|
||
/** | ||
* @var Block | ||
*/ | ||
private $block; | ||
|
||
/** | ||
* @var Context | ||
*/ | ||
private $readerContext; | ||
|
||
private $blockName = 'test.block'; | ||
private $childBlockName = 'test.child.block'; | ||
|
||
public function setUp() | ||
{ | ||
$this->block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( | ||
'Magento\Framework\View\Layout\Reader\Block' | ||
); | ||
|
||
$this->readerContext = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( | ||
'Magento\Framework\View\Layout\Reader\Context' | ||
); | ||
} | ||
|
||
public function testInterpretBlockDirective() | ||
{ | ||
$pageXml = new \Magento\Framework\View\Layout\Element(__DIR__ . '/_files/_layout_update_block.xml', 0, true); | ||
$parentElement = new \Magento\Framework\View\Layout\Element('<page></page>'); | ||
|
||
foreach ($pageXml->xpath('body/block') as $blockElement) { | ||
$this->assertTrue(in_array($blockElement->getName(), $this->block->getSupportedNodes())); | ||
|
||
$this->block->interpret($this->readerContext, $blockElement, $parentElement); | ||
} | ||
|
||
$structure = $this->readerContext->getScheduledStructure(); | ||
$this->assertArrayHasKey($this->blockName, $structure->getStructure()); | ||
$this->assertEquals('block', $structure->getStructure()[$this->blockName][self::IDX_TYPE]); | ||
|
||
$resultElementData = $structure->getStructureElementData($this->blockName); | ||
|
||
$this->assertEquals( | ||
['group' => 'test.group', 'class' => 'Dummy\Class', 'template' => 'test.phtml', 'ttl' => 3], | ||
$resultElementData['attributes'] | ||
); | ||
$this->assertEquals( | ||
['test_arg' => ['name' => 'test_arg', 'xsi:type' => 'string', 'value' => 'test-argument-value']], | ||
$resultElementData['arguments'] | ||
); | ||
|
||
$this->assertEquals('block', $structure->getStructure()[$this->childBlockName][self::IDX_TYPE]); | ||
$this->assertEquals($this->blockName, $structure->getStructure()[$this->childBlockName][self::IDX_PARENT]); | ||
} | ||
|
||
/** | ||
* @depends testInterpretBlockDirective | ||
*/ | ||
public function testInterpretReferenceBlockDirective() | ||
{ | ||
$pageXml = new \Magento\Framework\View\Layout\Element( | ||
__DIR__ . '/_files/_layout_update_reference.xml', 0, true | ||
); | ||
$parentElement = new \Magento\Framework\View\Layout\Element('<page></page>'); | ||
|
||
foreach ($pageXml->xpath('body/*') as $element) { | ||
$this->assertTrue(in_array($element->getName(), $this->block->getSupportedNodes())); | ||
|
||
$this->block->interpret($this->readerContext, $element, $parentElement); | ||
} | ||
|
||
$structure = $this->readerContext->getScheduledStructure(); | ||
$this->assertArrayHasKey($this->blockName, $structure->getStructure()); | ||
$this->assertEquals('block', $structure->getStructure()[$this->blockName][self::IDX_TYPE]); | ||
|
||
$resultElementData = $structure->getStructureElementData($this->blockName); | ||
|
||
$this->assertEquals( | ||
['test_arg' => ['name' => 'test_arg', 'xsi:type' => 'string', 'value' => 'test-argument-value']], | ||
$resultElementData['arguments'] | ||
); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ntegration/testsuite/Magento/Framework/View/Layout/Reader/_files/_layout_update_block.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="../../../../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<block class="Dummy\Class" | ||
name="test.block" | ||
group="test.group" | ||
template="test.phtml" | ||
ttl="3"> | ||
<arguments> | ||
<argument name="test_arg" xsi:type="string">test-argument-value</argument> | ||
</arguments> | ||
<block class="Dummy\Class" name="test.child.block"/> | ||
</block> | ||
</body> | ||
</page> |
12 changes: 12 additions & 0 deletions
12
...ration/testsuite/Magento/Framework/View/Layout/Reader/_files/_layout_update_reference.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="../../../../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<block class="Dummy\Class" name="test.block"/> | ||
<referenceBlock name="test.block"> | ||
<arguments> | ||
<argument name="test_arg" xsi:type="string">test-argument-value</argument> | ||
</arguments> | ||
</referenceBlock> | ||
</body> | ||
</page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters