1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Utility;
use Magento\Framework\App\Bootstrap;
use Magento\Framework\App\Filesystem\DirectoryList;
class LayoutTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\View\Utility\Layout
*/
protected $_utility;
protected function setUp()
{
\Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize(
[
Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS => [
DirectoryList::APP => ['path' => BP . '/dev/tests/integration'],
],
]
);
$this->_utility = new \Magento\Framework\View\Utility\Layout($this);
}
/**
* Assert that the actual layout update instance represents the expected layout update file
*
* @param string $expectedUpdateFile
* @param \Magento\Framework\View\Layout\ProcessorInterface $actualUpdate
*/
protected function _assertLayoutUpdate($expectedUpdateFile, $actualUpdate)
{
$this->assertInstanceOf(\Magento\Framework\View\Layout\ProcessorInterface::class, $actualUpdate);
$layoutUpdateXml = $actualUpdate->getFileLayoutUpdatesXml();
$this->assertInstanceOf(\Magento\Framework\View\Layout\Element::class, $layoutUpdateXml);
$this->assertXmlStringEqualsXmlFile($expectedUpdateFile, $layoutUpdateXml->asNiceXml());
}
/**
* @param string|array $inputFiles
* @param string $expectedFile
*
* @dataProvider getLayoutFromFixtureDataProvider
*/
public function testGetLayoutUpdateFromFixture($inputFiles, $expectedFile)
{
$layoutUpdate = $this->_utility->getLayoutUpdateFromFixture($inputFiles);
$this->_assertLayoutUpdate($expectedFile, $layoutUpdate);
}
/**
* @param string|array $inputFiles
* @param string $expectedFile
*
* @dataProvider getLayoutFromFixtureDataProvider
*/
public function testGetLayoutFromFixture($inputFiles, $expectedFile)
{
$layout = $this->_utility->getLayoutFromFixture($inputFiles, $this->_utility->getLayoutDependencies());
$this->assertInstanceOf(\Magento\Framework\View\LayoutInterface::class, $layout);
$this->_assertLayoutUpdate($expectedFile, $layout->getUpdate());
}
public function getLayoutFromFixtureDataProvider()
{
return [
'single fixture file' => [
__DIR__ . '/_files/layout/handle_two.xml',
__DIR__ . '/_files/layout_merged/single_handle.xml',
],
'multiple fixture files' => [
glob(__DIR__ . '/_files/layout/*.xml'),
__DIR__ . '/_files/layout_merged/multiple_handles.xml',
]
];
}
}