UrnResolverTest.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Config\Test\Unit\Dom;
  7. use Magento\Framework\Config\Dom\UrnResolver;
  8. use Magento\Framework\Component\ComponentRegistrar;
  9. class UrnResolverTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var UrnResolver
  13. */
  14. protected $urnResolver;
  15. /**
  16. * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
  17. */
  18. protected $objectManagerHelper;
  19. protected function setUp()
  20. {
  21. $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  22. $this->urnResolver = $this->objectManagerHelper->getObject(\Magento\Framework\Config\Dom\UrnResolver::class);
  23. }
  24. public function testGetRealPathNoUrn()
  25. {
  26. $xsdPath = '../../testPath/test.xsd';
  27. $result = $this->urnResolver->getRealPath($xsdPath);
  28. $this->assertSame($xsdPath, $result, 'XSD paths does not match.');
  29. }
  30. public function testGetRealPathWithFrameworkUrn()
  31. {
  32. $xsdUrn = 'urn:magento:framework:Config/Test/Unit/_files/sample.xsd';
  33. $xsdPath = str_replace('\\', '/', realpath(dirname(__DIR__)) . '/_files/sample.xsd');
  34. $result = $this->urnResolver->getRealPath($xsdUrn);
  35. $this->assertSame($xsdPath, $result, 'XSD paths does not match.');
  36. }
  37. public function testGetRealPathWithModuleUrn()
  38. {
  39. $xsdUrn = 'urn:magento:module:Magento_Customer:etc/address_formats.xsd';
  40. $componentRegistrar = new ComponentRegistrar();
  41. $xsdPath = $componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Customer')
  42. . '/etc/address_formats.xsd';
  43. $result = $this->urnResolver->getRealPath($xsdUrn);
  44. $this->assertSame($xsdPath, $result, 'XSD paths does not match.');
  45. }
  46. public function testGetRealPathWithSetupUrn()
  47. {
  48. $xsdUrn = 'urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd';
  49. $componentRegistrar = new ComponentRegistrar();
  50. $xsdPath = $componentRegistrar->getPath(ComponentRegistrar::LIBRARY, 'magento/framework')
  51. . '/Setup/Declaration/Schema/etc/schema.xsd';
  52. $result = $this->urnResolver->getRealPath($xsdUrn);
  53. $this->assertSame($xsdPath, $result, 'XSD paths does not match.');
  54. }
  55. /**
  56. * @expectedException \Magento\Framework\Exception\NotFoundException
  57. * @expectedExceptionMessage Unsupported format of schema location: 'urn:magento:test:test:etc/test_test.xsd'
  58. */
  59. public function testGetRealPathWrongSection()
  60. {
  61. $xsdUrn = 'urn:magento:test:test:etc/test_test.xsd';
  62. $this->urnResolver->getRealPath($xsdUrn);
  63. }
  64. /**
  65. * @expectedException \Magento\Framework\Exception\NotFoundException
  66. * @expectedExceptionMessage Could not locate schema: 'urn:magento:module:Magento_Test:test.xsd' at '/test.xsd'
  67. */
  68. public function testGetRealPathWrongModule()
  69. {
  70. $xsdUrn = 'urn:magento:module:Magento_Test:test.xsd';
  71. $this->urnResolver->getRealPath($xsdUrn);
  72. }
  73. }