8 class DomTest extends \PHPUnit\Framework\TestCase
17 $this->validationStateMock = $this->getMockForAbstractClass(
18 \
Magento\Framework\Config\ValidationStateInterface::class
20 $this->validationStateMock->method(
'isValidationRequired')
32 public function testMerge($xmlFile, $newXmlFile, $ids, $typeAttributeName, $expectedXmlFile)
36 $config = new \Magento\Framework\Config\Dom($xml, $this->validationStateMock, $ids, $typeAttributeName);
38 $this->assertXmlStringEqualsXmlFile(
__DIR__ .
"/_files/dom/{$expectedXmlFile}",
$config->getDom()->saveXML());
52 '/root/node/subnode' =>
'id',
53 '/root/other_node' =>
'id',
54 '/root/other_node/child' =>
'identifier',
59 [
'no_ids.xml',
'no_ids_new.xml', [],
null,
'no_ids_merged.xml'],
60 [
'ambiguous_one.xml',
'ambiguous_new_two.xml', [],
null,
'ambiguous_merged.xml'],
61 [
'namespaced.xml',
'namespaced_new.xml', [
'/root/node' =>
'id'],
null,
'namespaced_merged.xml'],
62 [
'override_node.xml',
'override_node_new.xml', [],
null,
'override_node_merged.xml'],
63 [
'override_node_new.xml',
'override_node.xml', [],
null,
'override_node_merged.xml'],
64 [
'text_node.xml',
'text_node_new.xml', [],
null,
'text_node_merged.xml'],
68 [
'/root/(node|another_node)(/param)?' =>
'name',
'/root/node/param(/complex/item)+' =>
'key'],
70 'recursive_merged.xml',
74 'recursive_deep_new.xml',
75 [
'/root(/node)+' =>
'name'],
77 'recursive_deep_merged.xml',
82 [
'/root/item' =>
'id',
'/root/item/subitem' =>
'id'],
89 [
'/root/item' =>
'id',
'/root/item/subitem' =>
'id'],
91 'attributes_merged.xml',
104 $config = new \Magento\Framework\Config\Dom($xml, $this->validationStateMock);
116 $this->markTestSkipped(
'Skipped on HHVM. Will be fixed in MAGETWO-45033');
118 $dom = new \Magento\Framework\Config\Dom($xml, $this->validationStateMock);
119 $actualResult = $dom->validate(
__DIR__ .
'/_files/sample.xsd', $actualErrors);
120 $this->assertEquals(empty($expectedErrors), $actualResult);
121 $this->assertEquals($expectedErrors, $actualErrors);
130 'valid' => [
'<root><node id="id1"/><node id="id2"/></root>', []],
132 '<root><node id="id1"/><unknown_node/></root>',
133 [
"Element 'unknown_node': This element is not expected. Expected is ( node ).\nLine: 1\n"],
140 $xml =
'<root><unknown_node/></root>';
141 $errorFormat =
'Error: `%message%`';
143 "Error: `Element 'unknown_node': This element is not expected. Expected is ( node ).`",
145 $dom = new \Magento\Framework\Config\Dom($xml, $this->validationStateMock, [],
null,
null, $errorFormat);
146 $actualResult = $dom->validate(
__DIR__ .
'/_files/sample.xsd', $actualErrors);
147 $this->assertFalse($actualResult);
148 $this->assertEquals($expectedErrors, $actualErrors);
157 $xml =
'<root><unknown_node/></root>';
158 $errorFormat =
'%message%,%unknown%';
159 $dom = new \Magento\Framework\Config\Dom($xml, $this->validationStateMock, [],
null,
null, $errorFormat);
160 $dom->validate(
__DIR__ .
'/_files/sample.xsd');
166 $this->markTestSkipped(
'Skipped on HHVM. Will be fixed in MAGETWO-45033');
168 $xml =
'<root><node id="id1"/><node id="id2"/></root>';
169 $schemaFile =
__DIR__ .
'/_files/sample.xsd';
170 $dom = new \Magento\Framework\Config\Dom($xml, $this->validationStateMock);
171 $domMock = $this->createPartialMock(\DOMDocument::class, [
'schemaValidate']);
172 $domMock->expects($this->once())
173 ->method(
'schemaValidate')
177 [
"Element 'unknown_node': This element is not expected. Expected is ( node ).\nLine: 1\n"],
178 $dom->validateDomDocument($domMock, $schemaFile)
188 $this->markTestSkipped(
'Skipped on HHVM. Will be fixed in MAGETWO-45033');
190 $xml =
'<root><node id="id1"/><node id="id2"/></root>';
191 $schemaFile =
__DIR__ .
'/_files/sample.xsd';
192 $dom = new \Magento\Framework\Config\Dom($xml, $this->validationStateMock);
193 $domMock = $this->createPartialMock(\DOMDocument::class, [
'schemaValidate']);
194 $domMock->expects($this->once())
195 ->method(
'schemaValidate')
198 $dom->validateDomDocument($domMock, $schemaFile);
testValidateCustomErrorFormatInvalid()
testMerge($xmlFile, $newXmlFile, $ids, $typeAttributeName, $expectedXmlFile)
defined('TESTS_BP')||define('TESTS_BP' __DIR__
testValidate($xml, array $expectedErrors)
testValidateDomDocumentThrowsException()
testValidateCustomErrorFormat()
testValidateUnknownError()