-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathUrnResolverTest.php
89 lines (76 loc) · 3.08 KB
/
UrnResolverTest.php
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
84
85
86
87
88
89
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Framework\Config\Test\Unit\Dom;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Config\Dom\UrnResolver;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\TestCase;
class UrnResolverTest extends TestCase
{
/**
* @var UrnResolver
*/
protected $urnResolver;
/**
* @var ObjectManager
*/
protected $objectManagerHelper;
protected function setUp(): void
{
$this->objectManagerHelper = new ObjectManager($this);
$this->urnResolver = $this->objectManagerHelper->getObject(UrnResolver::class);
}
public function testGetRealPathNoUrn()
{
$xsdPath = '../../testPath/test.xsd';
$result = $this->urnResolver->getRealPath($xsdPath);
$this->assertSame($xsdPath, $result, 'XSD paths does not match.');
}
public function testGetRealPathWithFrameworkUrn()
{
$xsdUrn = 'urn:magento:framework:Config/Test/Unit/_files/sample.xsd';
$xsdPath = str_replace('\\', '/', realpath(dirname(__DIR__)) . '/_files/sample.xsd');
$result = $this->urnResolver->getRealPath($xsdUrn);
$this->assertSame($xsdPath, $result, 'XSD paths does not match.');
}
public function testGetRealPathWithModuleUrn()
{
$xsdUrn = 'urn:magento:module:Magento_Customer:etc/address_formats.xsd';
$componentRegistrar = new ComponentRegistrar();
$xsdPath = $componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Customer')
. '/etc/address_formats.xsd';
$result = $this->urnResolver->getRealPath($xsdUrn);
$this->assertSame($xsdPath, $result, 'XSD paths does not match.');
}
public function testGetRealPathWithSetupUrn()
{
$xsdUrn = 'urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd';
$componentRegistrar = new ComponentRegistrar();
$xsdPath = $componentRegistrar->getPath(ComponentRegistrar::LIBRARY, 'magento/framework')
. '/Setup/Declaration/Schema/etc/schema.xsd';
$result = $this->urnResolver->getRealPath($xsdUrn);
$this->assertSame($xsdPath, $result, 'XSD paths does not match.');
}
public function testGetRealPathWrongSection()
{
$this->expectException('Magento\Framework\Exception\NotFoundException');
$this->expectExceptionMessage(
'Unsupported format of schema location: \'urn:magento:test:test:etc/test_test.xsd\''
);
$xsdUrn = 'urn:magento:test:test:etc/test_test.xsd';
$this->urnResolver->getRealPath($xsdUrn);
}
public function testGetRealPathWrongModule()
{
$this->expectException('Magento\Framework\Exception\NotFoundException');
$this->expectExceptionMessage(
'Could not locate schema: \'urn:magento:module:Magento_Test:test.xsd\' at \'/test.xsd\''
);
$xsdUrn = 'urn:magento:module:Magento_Test:test.xsd';
$this->urnResolver->getRealPath($xsdUrn);
}
}