ConfigTest.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\Test\Unit\PageLayout;
  7. /**
  8. * Page layouts configuration
  9. */
  10. class ConfigTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Framework\View\PageLayout\Config
  14. */
  15. protected $config;
  16. protected function setUp()
  17. {
  18. $urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
  19. $urnResolverMock = $this->createMock(\Magento\Framework\Config\Dom\UrnResolver::class);
  20. $urnResolverMock->expects($this->once())
  21. ->method('getRealPath')
  22. ->with('urn:magento:framework:View/PageLayout/etc/layouts.xsd')
  23. ->willReturn($urnResolver->getRealPath('urn:magento:framework:View/PageLayout/etc/layouts.xsd'));
  24. $validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
  25. $validationStateMock->method('isValidationRequired')
  26. ->willReturn(true);
  27. $domFactoryMock = $this->createMock(\Magento\Framework\Config\DomFactory::class);
  28. $domFactoryMock->expects($this->once())
  29. ->method('createDom')
  30. ->willReturnCallback(
  31. function ($arguments) use ($validationStateMock) {
  32. // @codingStandardsIgnoreStart
  33. return new \Magento\Framework\Config\Dom(
  34. '<?xml version="1.0" encoding="UTF-8"?>'
  35. . '<page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></page_layouts>',
  36. $validationStateMock,
  37. ['/page_layouts/layout' => 'id'],
  38. null,
  39. $arguments['schemaFile']
  40. );
  41. // @codingStandardsIgnoreEnd
  42. }
  43. );
  44. $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  45. $this->config = $objectManagerHelper->getObject(
  46. \Magento\Framework\View\PageLayout\Config::class,
  47. [
  48. 'urnResolver' => $urnResolverMock,
  49. 'configFiles' => [
  50. 'layouts_one.xml' => file_get_contents(__DIR__ . '/_files/layouts_one.xml'),
  51. 'layouts_two.xml' => file_get_contents(__DIR__ . '/_files/layouts_two.xml'),
  52. ],
  53. 'domFactory' => $domFactoryMock
  54. ]
  55. );
  56. }
  57. public function testGetPageLayouts()
  58. {
  59. $this->assertEquals(['one' => 'One', 'two' => 'Two'], $this->config->getPageLayouts());
  60. }
  61. public function testHasPageLayout()
  62. {
  63. $this->assertEquals(true, $this->config->hasPageLayout('one'));
  64. $this->assertEquals(false, $this->config->hasPageLayout('three'));
  65. }
  66. public function testGetOptions()
  67. {
  68. $this->assertEquals(['one' => 'One', 'two' => 'Two'], $this->config->getPageLayouts());
  69. }
  70. public function testToOptionArray()
  71. {
  72. $this->assertEquals(
  73. [
  74. ['label' => 'One', 'value' => 'one'],
  75. ['label' => 'Two', 'value' => 'two'],
  76. ],
  77. $this->config->toOptionArray()
  78. );
  79. $this->assertEquals(
  80. [
  81. ['label' => '-- Please Select --', 'value' => ''],
  82. ['label' => 'One', 'value' => 'one'],
  83. ['label' => 'Two', 'value' => 'two'],
  84. ],
  85. $this->config->toOptionArray(true)
  86. );
  87. }
  88. }