LayoutTest.php 2.8 KB

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