Skip to content

Commit fa58c70

Browse files
authored
ENGCOM-3466: [FEATURE] added ability to create default/fixed value nodes during XSD Schema Validation #13184
2 parents eb3a122 + 88111b4 commit fa58c70

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

dev/tests/integration/testsuite/Magento/Framework/Search/_files/search_request_merged.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'match_query' => [
3636
'value' => '$match_term_override$',
3737
'name' => 'match_query',
38+
'boost' => '1',
3839
'match' => [
3940
0 => [
4041
'field' => 'match_field',
@@ -50,6 +51,7 @@
5051
],
5152
'must_query' => [
5253
'name' => 'must_query',
54+
'boost' => '1',
5355
'filterReference' => [
5456
0 => [
5557
'clause' => 'must',
@@ -60,6 +62,7 @@
6062
],
6163
'should_query' => [
6264
'name' => 'should_query',
65+
'boost' => '1',
6366
'filterReference' => [
6467
0 => [
6568
'clause' => 'should',
@@ -70,6 +73,7 @@
7073
],
7174
'not_query' => [
7275
'name' => 'not_query',
76+
'boost' => '1',
7377
'filterReference' => [
7478
0 => [
7579
'clause' => 'not',
@@ -80,6 +84,7 @@
8084
],
8185
'match_query_2' => [
8286
'value' => '$match_term_override$',
87+
'boost' => '1',
8388
'name' => 'match_query_2',
8489
'match' => [
8590
0 => [
@@ -163,6 +168,7 @@
163168
'queries' => [
164169
'filter_query' => [
165170
'name' => 'filter_query',
171+
'boost' => '1',
166172
'filterReference' => [
167173
0 =>
168174
[
@@ -230,6 +236,7 @@
230236
'new_match_query' => [
231237
'value' => '$match_term$',
232238
'name' => 'new_match_query',
239+
'boost' => '1',
233240
'match' => [
234241
0 =>
235242
[

lib/internal/Magento/Framework/Config/Dom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public static function validateDomDocument(
318318
libxml_set_external_entity_loader([self::$urnResolver, 'registerEntityLoader']);
319319
$errors = [];
320320
try {
321-
$result = $dom->schemaValidate($schema);
321+
$result = $dom->schemaValidate($schema, LIBXML_SCHEMA_CREATE);
322322
if (!$result) {
323323
$errors = self::getXmlErrors($errorFormat);
324324
}

lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,48 @@ public function validateDataProvider()
135135
];
136136
}
137137

138+
/**
139+
* @param string $xml
140+
* @param string $expectedValue
141+
* @dataProvider validateWithDefaultValueDataProvider
142+
*/
143+
public function testValidateWithDefaultValue($xml, $expectedValue)
144+
{
145+
if (!function_exists('libxml_set_external_entity_loader')) {
146+
$this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
147+
}
148+
149+
$actualErrors = [];
150+
151+
$dom = new \Magento\Framework\Config\Dom($xml, $this->validationStateMock);
152+
$dom->validate(__DIR__ . '/_files/sample.xsd', $actualErrors);
153+
154+
$actualValue = $dom->getDom()
155+
->getElementsByTagName('root')->item(0)
156+
->getElementsByTagName('node')->item(0)
157+
->getAttribute('attribute_with_default_value');
158+
159+
$this->assertEmpty($actualErrors);
160+
$this->assertEquals($expectedValue, $actualValue);
161+
}
162+
163+
/**
164+
* @return array
165+
*/
166+
public function validateWithDefaultValueDataProvider()
167+
{
168+
return [
169+
'default_value' => [
170+
'<root><node id="id1"/></root>',
171+
'default_value'
172+
],
173+
'custom_value' => [
174+
'<root><node id="id1" attribute_with_default_value="non_default_value"/></root>',
175+
'non_default_value'
176+
],
177+
];
178+
}
179+
138180
public function testValidateCustomErrorFormat()
139181
{
140182
$xml = '<root><unknown_node/></root>';

lib/internal/Magento/Framework/Config/Test/Unit/_files/sample.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<xs:simpleContent>
2222
<xs:extension base="xs:string">
2323
<xs:attribute name="id" type="xs:string" use="required"/>
24+
<xs:attribute name="attribute_with_default_value" type="xs:string" default="default_value"/>
2425
</xs:extension>
2526
</xs:simpleContent>
2627
</xs:complexType>

0 commit comments

Comments
 (0)