init
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\View\Layout;
|
||||
|
||||
class ElementTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\View\Layout\Element
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
public function testPrepare()
|
||||
{
|
||||
/**
|
||||
* @TODO: Need to use ObjectManager instead 'new'.
|
||||
* On this moment we have next bug MAGETWO-4274 which blocker for this key.
|
||||
*/
|
||||
$this->model = new \Magento\Framework\View\Layout\Element(__DIR__ . '/_files/_layout_update.xml', 0, true);
|
||||
|
||||
list($blockNode) = $this->model->xpath('//block[@name="nodeForTesting"]');
|
||||
list($actionNode) = $this->model->xpath('//action[@method="setSomething"]');
|
||||
|
||||
$this->assertEmpty($blockNode->attributes()->parent);
|
||||
$this->assertEmpty($actionNode->attributes()->block);
|
||||
|
||||
$this->model->prepare();
|
||||
|
||||
$this->assertEquals('root', (string)$blockNode->attributes()->parent);
|
||||
$this->assertEquals(\Magento\Backend\Block\Page::class, (string)$blockNode->attributes()->class);
|
||||
$this->assertEquals('nodeForTesting', (string)$actionNode->attributes()->block);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,470 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\View\Layout;
|
||||
|
||||
use Magento\Framework\App\State;
|
||||
use Magento\Framework\Phrase;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class MergeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Fixture XML instruction(s) to be used in tests
|
||||
*/
|
||||
// @codingStandardsIgnoreStart
|
||||
const FIXTURE_LAYOUT_XML = '<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_one.phtml"/>';
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\View\Model\Layout\Merge
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $_resource;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $_appState;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $_cache;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $_serializer;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $_theme;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $scope;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $_logger;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $_layoutValidator;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\View\Page\Config|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $pageConfig;
|
||||
|
||||
/**
|
||||
* @var LayoutCacheKeyInterface|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $layoutCacheKeyMock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$files = [];
|
||||
$fileDriver = new \Magento\Framework\Filesystem\Driver\File();
|
||||
foreach ($fileDriver->readDirectory(__DIR__ . '/_mergeFiles/layout/') as $filename) {
|
||||
$files[] = new \Magento\Framework\View\File($filename, 'Magento_Widget');
|
||||
}
|
||||
$fileSource = $this->getMockForAbstractClass(\Magento\Framework\View\File\CollectorInterface::class);
|
||||
$fileSource->expects($this->any())->method('getFiles')->willReturn($files);
|
||||
|
||||
$pageLayoutFileSource = $this->getMockForAbstractClass(\Magento\Framework\View\File\CollectorInterface::class);
|
||||
$pageLayoutFileSource->expects($this->any())->method('getFiles')->willReturn([]);
|
||||
|
||||
$design = $this->getMockForAbstractClass(\Magento\Framework\View\DesignInterface::class);
|
||||
|
||||
$this->scope = $this->createMock(\Magento\Framework\Url\ScopeInterface::class);
|
||||
$this->scope->expects($this->any())->method('getId')->willReturn(20);
|
||||
$scopeResolver = $this->getMockForAbstractClass(\Magento\Framework\Url\ScopeResolverInterface::class);
|
||||
$scopeResolver->expects($this->once())->method('getScope')->with(null)->willReturn($this->scope);
|
||||
|
||||
$this->_resource = $this->createMock(\Magento\Widget\Model\ResourceModel\Layout\Update::class);
|
||||
|
||||
$this->_appState = $this->createMock(\Magento\Framework\App\State::class);
|
||||
|
||||
$this->_logger = $this->createMock(\Psr\Log\LoggerInterface::class);
|
||||
|
||||
$this->_layoutValidator = $this->createMock(\Magento\Framework\View\Model\Layout\Update\Validator::class);
|
||||
|
||||
$this->_cache = $this->getMockForAbstractClass(\Magento\Framework\Cache\FrontendInterface::class);
|
||||
|
||||
$this->_serializer = $this->getMockForAbstractClass(\Magento\Framework\Serialize\SerializerInterface::class);
|
||||
|
||||
$this->_theme = $this->createMock(\Magento\Theme\Model\Theme::class);
|
||||
$this->_theme->expects($this->any())->method('isPhysical')->willReturn(true);
|
||||
$this->_theme->expects($this->any())->method('getArea')->willReturn('area');
|
||||
$this->_theme->expects($this->any())->method('getId')->willReturn(100);
|
||||
|
||||
$objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
|
||||
|
||||
$this->pageConfig = $this->getMockBuilder(\Magento\Framework\View\Page\Config::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$readFactory = $this->createMock(\Magento\Framework\Filesystem\File\ReadFactory::class);
|
||||
$fileReader = $this->createMock(\Magento\Framework\Filesystem\File\Read::class);
|
||||
$readFactory->expects($this->any())->method('create')->willReturn($fileReader);
|
||||
|
||||
$fileDriver = $objectHelper->getObject(\Magento\Framework\Filesystem\Driver\File::class);
|
||||
|
||||
$fileReader->expects($this->any())->method('readAll')
|
||||
->willReturnCallback(
|
||||
function ($filename) use ($fileDriver) {
|
||||
return $fileDriver->fileGetContents(__DIR__ . '/_mergeFiles/layout/' . $filename);
|
||||
}
|
||||
);
|
||||
|
||||
$this->layoutCacheKeyMock = $this->getMockForAbstractClass(LayoutCacheKeyInterface::class);
|
||||
$this->layoutCacheKeyMock->expects($this->any())
|
||||
->method('getCacheKeys')
|
||||
->willReturn([]);
|
||||
|
||||
$this->_model = $objectHelper->getObject(
|
||||
\Magento\Framework\View\Model\Layout\Merge::class,
|
||||
[
|
||||
'design' => $design,
|
||||
'scopeResolver' => $scopeResolver,
|
||||
'fileSource' => $fileSource,
|
||||
'pageLayoutFileSource' => $pageLayoutFileSource,
|
||||
'resource' => $this->_resource,
|
||||
'appState' => $this->_appState,
|
||||
'cache' => $this->_cache,
|
||||
'serializer' => $this->_serializer,
|
||||
'theme' => $this->_theme,
|
||||
'validator' => $this->_layoutValidator,
|
||||
'logger' => $this->_logger,
|
||||
'readFactory' => $readFactory,
|
||||
'pageConfig' => $this->pageConfig,
|
||||
'layoutCacheKey' => $this->layoutCacheKeyMock,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function testAddUpdate()
|
||||
{
|
||||
$this->assertEmpty($this->_model->asArray());
|
||||
$this->assertEmpty($this->_model->asString());
|
||||
$this->_model->addUpdate('test');
|
||||
$this->assertEquals(['test'], $this->_model->asArray());
|
||||
$this->assertEquals('test', $this->_model->asString());
|
||||
}
|
||||
|
||||
public function testAddHandle()
|
||||
{
|
||||
$this->assertEmpty($this->_model->getHandles());
|
||||
$this->_model->addHandle('test');
|
||||
$this->assertEquals(['test'], $this->_model->getHandles());
|
||||
}
|
||||
|
||||
public function testRemoveHandle()
|
||||
{
|
||||
$this->_model->addHandle('test');
|
||||
$this->_model->removeHandle('test');
|
||||
$this->assertEmpty($this->_model->getHandles());
|
||||
}
|
||||
|
||||
public function testAddPageHandles()
|
||||
{
|
||||
/* add a non-page handle to verify that it won't be affected during page handles manipulation */
|
||||
$nonPageHandles = ['non_page_handle'];
|
||||
$this->_model->addHandle($nonPageHandles);
|
||||
|
||||
$this->assertFalse($this->_model->addPageHandles(['non_existing_handle']));
|
||||
$this->assertEmpty($this->_model->getPageHandles());
|
||||
$this->assertEquals($nonPageHandles, $this->_model->getHandles());
|
||||
|
||||
/* test that only the first existing handle is taken into account */
|
||||
$handlesToTry = [
|
||||
'default',
|
||||
'catalog_category_default',
|
||||
'catalog_product_view',
|
||||
'catalog_product_view_type_simple',
|
||||
];
|
||||
$expectedPageHandles = [
|
||||
'default',
|
||||
'catalog_category_default',
|
||||
'catalog_product_view',
|
||||
'catalog_product_view_type_simple',
|
||||
];
|
||||
$this->assertTrue($this->_model->addPageHandles($handlesToTry));
|
||||
$this->assertEquals($expectedPageHandles, $this->_model->getPageHandles());
|
||||
$this->assertEquals(array_merge($nonPageHandles, $expectedPageHandles), $this->_model->getHandles());
|
||||
|
||||
/* test that new handles override the previous ones */
|
||||
$expectedPageHandles = ['default', 'checkout_index_index'];
|
||||
$this->_model->removeHandle('catalog_category_default');
|
||||
$this->_model->removeHandle('catalog_product_view');
|
||||
$this->_model->removeHandle('catalog_product_view_type_simple');
|
||||
$this->assertTrue($this->_model->addPageHandles(['default', 'checkout_index_index']));
|
||||
$this->assertEquals($expectedPageHandles, $this->_model->getPageHandles());
|
||||
$this->assertEquals(array_merge($nonPageHandles, $expectedPageHandles), $this->_model->getHandles());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider pageHandleExistsDataProvider
|
||||
*/
|
||||
public function testPageHandleExists($inputPageHandle, $expectedResult)
|
||||
{
|
||||
$this->assertSame($expectedResult, $this->_model->pageHandleExists($inputPageHandle));
|
||||
}
|
||||
|
||||
public function pageHandleExistsDataProvider()
|
||||
{
|
||||
return [
|
||||
'non-existing handle' => ['non_existing_handle', false],
|
||||
'existing page type' => ['default', true],
|
||||
];
|
||||
}
|
||||
|
||||
public function testLoadFileSystem()
|
||||
{
|
||||
$handles = ['fixture_handle_one', 'fixture_handle_two'];
|
||||
$this->assertEmpty($this->_model->getHandles());
|
||||
$this->assertEmpty($this->_model->asString());
|
||||
$this->_model->load($handles);
|
||||
$this->assertEquals($handles, $this->_model->getHandles());
|
||||
$expectedResult = '
|
||||
<root>
|
||||
<body>
|
||||
<block class="Magento\Framework\View\Element\Template"
|
||||
template="Magento_Framework::fixture_template_one.phtml"/>
|
||||
</body>
|
||||
<body>
|
||||
<block class="Magento\Framework\View\Element\Template"
|
||||
template="Magento_Framework::fixture_template_two.phtml"/>
|
||||
</body>
|
||||
</root>
|
||||
';
|
||||
$actualResult = '<root>' . $this->_model->asString() . '</root>';
|
||||
$this->assertXmlStringEqualsXmlString($expectedResult, $actualResult);
|
||||
}
|
||||
|
||||
public function testLoadFileSystemWithPageLayout()
|
||||
{
|
||||
$handles = ['fixture_handle_with_page_layout'];
|
||||
$expectedHandles = ['fixture_handle_with_page_layout'];
|
||||
$expectedResult = '
|
||||
<root>
|
||||
<body>
|
||||
<referenceContainer name="main.container">
|
||||
<block class="Magento\Framework\View\Element\Template"
|
||||
template="Magento_Framework::fixture_template_one.phtml"/>
|
||||
</referenceContainer>
|
||||
</body>
|
||||
</root>
|
||||
';
|
||||
|
||||
$this->assertEmpty($this->_model->getHandles());
|
||||
$this->assertEmpty($this->_model->asString());
|
||||
$this->_model->load($handles);
|
||||
|
||||
$this->assertEquals($expectedHandles, $this->_model->getHandles());
|
||||
$actualResult = '<root>' . $this->_model->asString() . '</root>';
|
||||
$this->assertXmlStringEqualsXmlString($expectedResult, $actualResult);
|
||||
$this->assertEquals('fixture_handle_page_layout', $this->_model->getPageLayout());
|
||||
}
|
||||
|
||||
public function testLoadCache()
|
||||
{
|
||||
$cacheValue = [
|
||||
"pageLayout" => "1column",
|
||||
"layout" => self::FIXTURE_LAYOUT_XML
|
||||
];
|
||||
|
||||
$this->_cache
|
||||
->method('load')
|
||||
->withConsecutive(['LAYOUT_area_STORE20_100c6a4ccd050e33acef0553f24ef399961_page_layout_merged'])
|
||||
->willReturnOnConsecutiveCalls(json_encode($cacheValue));
|
||||
|
||||
$this->_serializer->expects($this->once())->method('unserialize')->willReturn($cacheValue);
|
||||
|
||||
$this->assertEmpty($this->_model->getHandles());
|
||||
$this->assertEmpty($this->_model->asString());
|
||||
$handles = ['fixture_handle_one', 'fixture_handle_two'];
|
||||
$this->_model->load($handles);
|
||||
$this->assertEquals($handles, $this->_model->getHandles());
|
||||
$this->assertEquals(self::FIXTURE_LAYOUT_XML, $this->_model->asString());
|
||||
}
|
||||
|
||||
public function testLoadDbApp()
|
||||
{
|
||||
$this->_resource->expects(
|
||||
$this->any()
|
||||
)->method(
|
||||
'fetchUpdatesByHandle'
|
||||
)->with(
|
||||
'fixture_handle',
|
||||
$this->_theme,
|
||||
$this->scope
|
||||
)->willReturn(
|
||||
self::FIXTURE_LAYOUT_XML
|
||||
);
|
||||
$this->assertEmpty($this->_model->getHandles());
|
||||
$this->assertEmpty($this->_model->asString());
|
||||
$handles = ['fixture_handle_one'];
|
||||
$this->_model->load($handles);
|
||||
$this->assertEquals($handles, $this->_model->getHandles());
|
||||
$this->assertXmlStringEqualsXmlString(
|
||||
'<body>' . self::FIXTURE_LAYOUT_XML . '</body>',
|
||||
$this->_model->asString()
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetFileLayoutUpdatesXml()
|
||||
{
|
||||
$errorString = "Theme layout update file '" . __DIR__ . "/_mergeFiles/layout/file_wrong.xml' is not valid.";
|
||||
$this->_logger->expects($this->atLeastOnce())->method('info')
|
||||
->with($this->stringStartsWith($errorString));
|
||||
|
||||
$actualXml = $this->_model->getFileLayoutUpdatesXml();
|
||||
$this->assertXmlStringEqualsXmlFile(__DIR__ . '/_mergeFiles/merged.xml', $actualXml->asNiceXml());
|
||||
}
|
||||
|
||||
public function testGetContainers()
|
||||
{
|
||||
$this->_model->addPageHandles(['default']);
|
||||
$this->_model->addPageHandles(['catalog_product_view']);
|
||||
$this->_model->addPageHandles(['catalog_product_view_type_configurable']);
|
||||
$this->_model->load();
|
||||
$expected = [
|
||||
'content' => 'Main Content Area',
|
||||
'product.info.extrahint' => 'Product View Extra Hint',
|
||||
'product.info.configurable.extra' => 'Configurable Product Extra Info',
|
||||
];
|
||||
$this->assertEquals($expected, $this->_model->getContainers());
|
||||
}
|
||||
|
||||
public function testGetAllDesignAbstractions()
|
||||
{
|
||||
$expected = [
|
||||
'customer_account' => [
|
||||
'name' => 'customer_account',
|
||||
'label' => new Phrase('Customer My Account (All Pages)'),
|
||||
'design_abstraction' => 'custom',
|
||||
],
|
||||
'page_empty' => [
|
||||
'name' => 'page_empty',
|
||||
'label' => new Phrase('All Empty Layout Pages'),
|
||||
'design_abstraction' => 'page_layout',
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $this->_model->getAllDesignAbstractions());
|
||||
}
|
||||
|
||||
public function testIsPageLayoutDesignAbstractions()
|
||||
{
|
||||
$expected = [
|
||||
'customer_account' => [
|
||||
'name' => 'customer_account',
|
||||
'label' => 'Customer My Account (All Pages)',
|
||||
'design_abstraction' => 'custom',
|
||||
],
|
||||
'page_empty' => [
|
||||
'name' => 'page_empty',
|
||||
'label' => 'All Empty Layout Pages',
|
||||
'design_abstraction' => 'page_layout',
|
||||
],
|
||||
'empty_data' => [],
|
||||
];
|
||||
|
||||
$this->assertTrue($this->_model->isPageLayoutDesignAbstraction($expected['page_empty']));
|
||||
$this->assertFalse($this->_model->isPageLayoutDesignAbstraction($expected['customer_account']));
|
||||
$this->assertFalse($this->_model->isPageLayoutDesignAbstraction($expected['empty_data']));
|
||||
}
|
||||
|
||||
public function testIsCustomDesignAbstractions()
|
||||
{
|
||||
$expected = [
|
||||
'customer_account' => [
|
||||
'name' => 'customer_account',
|
||||
'label' => 'Customer My Account (All Pages)',
|
||||
'design_abstraction' => 'custom',
|
||||
],
|
||||
'page_empty' => [
|
||||
'name' => 'page_empty',
|
||||
'label' => 'All Empty Layout Pages',
|
||||
'design_abstraction' => 'page_layout',
|
||||
],
|
||||
'empty_data' => [],
|
||||
];
|
||||
$this->assertTrue($this->_model->isCustomerDesignAbstraction($expected['customer_account']));
|
||||
$this->assertFalse($this->_model->isCustomerDesignAbstraction($expected['page_empty']));
|
||||
$this->assertFalse($this->_model->isCustomerDesignAbstraction($expected['empty_data']));
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testLoadWithInvalidArgumentThrowsException()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
$this->expectExceptionMessage('Invalid layout update handle');
|
||||
|
||||
$this->_model->load(123);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test loading invalid layout
|
||||
*
|
||||
*/
|
||||
public function testLoadWithInvalidLayout()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Layout is invalid.');
|
||||
|
||||
$this->_model->addPageHandles(['default']);
|
||||
|
||||
$this->_appState->expects($this->once())->method('getMode')->willReturn(State::MODE_DEVELOPER);
|
||||
|
||||
$this->_layoutValidator->expects($this->any())
|
||||
->method('getMessages')
|
||||
->willReturn(['testMessage1', 'testMessage2']);
|
||||
|
||||
$this->_layoutValidator->expects($this->any())
|
||||
->method('isValid')
|
||||
->willThrowException(new \Exception('Layout is invalid.'));
|
||||
|
||||
// phpcs:ignore Magento2.Security.InsecureFunction
|
||||
$suffix = md5(implode('|', $this->_model->getHandles()));
|
||||
$cacheId = "LAYOUT_{$this->_theme->getArea()}_STORE{$this->scope->getId()}"
|
||||
. "_{$this->_theme->getId()}{$suffix}_page_layout_merged";
|
||||
$messages = $this->_layoutValidator->getMessages();
|
||||
|
||||
// Testing error message is logged with logger
|
||||
$this->_logger->expects($this->once())->method('info')
|
||||
->with(
|
||||
'Cache file with merged layout: ' . $cacheId . ' and handles default' . ': ' . array_shift($messages)
|
||||
);
|
||||
|
||||
$this->_model->load();
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testLayoutUpdateFileIsNotValid()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Config\Dom\ValidationException::class);
|
||||
$this->expectExceptionMessageMatches('/_mergeFiles\\/layout\\/file_wrong\\.xml\\\' is not valid/');
|
||||
|
||||
$this->_appState->expects($this->once())->method('getMode')->willReturn(State::MODE_DEVELOPER);
|
||||
|
||||
$this->_model->addPageHandles(['default']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $blockName = 'test.block';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $childBlockName = 'test.child.block';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\Layout\Reader\Block::class
|
||||
);
|
||||
$this->readerContext = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\Layout\Reader\Context::class
|
||||
);
|
||||
}
|
||||
|
||||
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(
|
||||
[
|
||||
Block::ATTRIBUTE_GROUP => 'test.group',
|
||||
Block::ATTRIBUTE_CLASS => 'Dummy\Class',
|
||||
Block::ATTRIBUTE_TEMPLATE => 'test.phtml',
|
||||
Block::ATTRIBUTE_TTL => 3,
|
||||
Block::ATTRIBUTE_DISPLAY => '',
|
||||
Block::ATTRIBUTE_ACL => '',
|
||||
'visibilityConditions' => [],
|
||||
],
|
||||
$resultElementData['attributes']
|
||||
);
|
||||
$this->assertEquals(
|
||||
['test_arg' => '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]);
|
||||
}
|
||||
|
||||
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' => 'test-argument-value'],
|
||||
$resultElementData['arguments']
|
||||
);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn: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>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn: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>
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<head>
|
||||
<title>Magento Admin</title>
|
||||
<script src="prototype/prototype.js"/>
|
||||
<script src="prototype/window.js"/>
|
||||
<script src="prototype/deprecation.js"/>
|
||||
</head>
|
||||
<block class="Magento\Backend\Block\Page" name="root" output="1" template="Magento_Backend::page.phtml">
|
||||
<block class="Magento\Backend\Block\Page" name="nodeForTesting">
|
||||
<action method="setSomething"/>
|
||||
</block>
|
||||
<block class="Magento\Backend\Block\Page\Header" name="header" as="header"/>
|
||||
<block class="Magento\Backend\Block\Menu" name="menu" as="menu"/>
|
||||
<block class="Magento\Framework\View\Element\Messages" name="messages" as="messages"/>
|
||||
<block class="Magento\Framework\View\Element\Text" as="no_name"/>
|
||||
</block>
|
||||
<update handle="layout_test_handle_sample"/>
|
||||
<referenceBlock name="header" remove="true"/>
|
||||
<referenceBlock name="menu" remove="true"/>
|
||||
<referenceBlock name="some_element_1" remove="true"/>
|
||||
<referenceBlock name="some_element_2" remove="true"/>
|
||||
<referenceBlock name="root">
|
||||
<action method="setTemplate">
|
||||
<argument name="template" xsi:type="string">popup.phtml</argument>
|
||||
</action>
|
||||
</referenceBlock>
|
||||
<referenceBlock name="some_element_1"/>
|
||||
<block class="Magento\Framework\View\Element\Text\ListText" name="test.nonexisting.block"/>
|
||||
<referenceBlock name="test.nonexisting.block" remove="true"/>
|
||||
<referenceBlock name="test.nonexisting.block">
|
||||
<action method="getSomething"/>
|
||||
</referenceBlock>
|
||||
<referenceBlock name="after.body.start">
|
||||
<block class="Magento\Framework\View\Element\Html\Calendar" name="head.calendar" as="calendar" template="Magento_Framework::page/js/calendar.phtml"/>
|
||||
</referenceBlock>
|
||||
</page>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page/>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page/>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page>
|
||||
<body>
|
||||
<container name="product.info.extrahint" as="extrahint" label="Product View Extra Hint"/>
|
||||
</body>
|
||||
</page>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page>
|
||||
<body>
|
||||
<container name="product.info.configurable.extra" as="product_type_data_extra" label="Configurable Product Extra Info"/>
|
||||
</body>
|
||||
</page>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page/>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page/>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page label="Customer My Account (All Pages)" design_abstraction="custom"/>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page>
|
||||
<body>
|
||||
<container name="content" as="content" label="Main Content Area"/>
|
||||
</body>
|
||||
</page>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page>
|
||||
<container name="content" as="content" label="Main Content Area"/>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page>
|
||||
<body>
|
||||
<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_one.phtml"/>
|
||||
</body>
|
||||
</page>
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<layout>
|
||||
<container name="main.container" />
|
||||
</layout>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page>
|
||||
<body>
|
||||
<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_two.phtml"/>
|
||||
</body>
|
||||
</page>
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page layout="fixture_handle_page_layout">
|
||||
<body>
|
||||
<referenceContainer name="main.container">
|
||||
<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_one.phtml"/>
|
||||
</referenceContainer>
|
||||
</body>
|
||||
</page>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page label="Handle that Is Not a Page Type"/>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page label="All Empty Layout Pages" design_abstraction="page_layout"/>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page/>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page/>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page/>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Layout instructions merged from sibling XML files. To be used as an expectation for a test.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<layouts>
|
||||
<handle id="catalog_category_default"/>
|
||||
<handle id="catalog_category_layered"/>
|
||||
<handle id="catalog_product_view">
|
||||
<body>
|
||||
<container name="product.info.extrahint" as="extrahint" label="Product View Extra Hint"/>
|
||||
</body>
|
||||
</handle>
|
||||
<handle id="catalog_product_view_type_configurable">
|
||||
<body>
|
||||
<container name="product.info.configurable.extra" as="product_type_data_extra" label="Configurable Product Extra Info"/>
|
||||
</body>
|
||||
</handle>
|
||||
<handle id="catalog_product_view_type_simple"/>
|
||||
<handle id="checkout_index_index"/>
|
||||
<handle id="customer_account" label="Customer My Account (All Pages)" design_abstraction="custom"/>
|
||||
<handle id="default">
|
||||
<body>
|
||||
<container name="content" as="content" label="Main Content Area"/>
|
||||
</body>
|
||||
</handle>
|
||||
<handle id="fixture_handle_one">
|
||||
<body>
|
||||
<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_one.phtml"/>
|
||||
</body>
|
||||
</handle>
|
||||
<layout id="fixture_handle_page_layout">
|
||||
<container name="main.container"/>
|
||||
</layout>
|
||||
<handle id="fixture_handle_two">
|
||||
<body>
|
||||
<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_two.phtml"/>
|
||||
</body>
|
||||
</handle>
|
||||
<handle id="fixture_handle_with_page_layout" layout="fixture_handle_page_layout">
|
||||
<body>
|
||||
<referenceContainer name="main.container">
|
||||
<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_one.phtml"/>
|
||||
</referenceContainer>
|
||||
</body>
|
||||
</handle>
|
||||
<handle id="not_a_page_type" label="Handle that Is Not a Page Type"/>
|
||||
<handle id="page_empty" label="All Empty Layout Pages" design_abstraction="page_layout"/>
|
||||
<handle id="print"/>
|
||||
<handle id="sales_guest_print"/>
|
||||
<handle id="sales_order_print"/>
|
||||
</layouts>
|
||||
|
||||
Reference in New Issue
Block a user