Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'match_query' => [
'value' => '$match_term_override$',
'name' => 'match_query',
'boost' => '1',
'match' => [
0 => [
'field' => 'match_field',
Expand All @@ -50,6 +51,7 @@
],
'must_query' => [
'name' => 'must_query',
'boost' => '1',
'filterReference' => [
0 => [
'clause' => 'must',
Expand All @@ -60,6 +62,7 @@
],
'should_query' => [
'name' => 'should_query',
'boost' => '1',
'filterReference' => [
0 => [
'clause' => 'should',
Expand All @@ -70,6 +73,7 @@
],
'not_query' => [
'name' => 'not_query',
'boost' => '1',
'filterReference' => [
0 => [
'clause' => 'not',
Expand All @@ -80,6 +84,7 @@
],
'match_query_2' => [
'value' => '$match_term_override$',
'boost' => '1',
'name' => 'match_query_2',
'match' => [
0 => [
Expand Down Expand Up @@ -163,6 +168,7 @@
'queries' => [
'filter_query' => [
'name' => 'filter_query',
'boost' => '1',
'filterReference' => [
0 =>
[
Expand Down Expand Up @@ -230,6 +236,7 @@
'new_match_query' => [
'value' => '$match_term$',
'name' => 'new_match_query',
'boost' => '1',
'match' => [
0 =>
[
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/Config/Dom.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public static function validateDomDocument(
libxml_set_external_entity_loader([self::$urnResolver, 'registerEntityLoader']);
$errors = [];
try {
$result = $dom->schemaValidate($schema);
$result = $dom->schemaValidate($schema, LIBXML_SCHEMA_CREATE);
if (!$result) {
$errors = self::getXmlErrors($errorFormat);
}
Expand Down
42 changes: 42 additions & 0 deletions lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,48 @@ public function validateDataProvider()
];
}

/**
* @param string $xml
* @param string $expectedValue
* @dataProvider validateWithDefaultValueDataProvider
*/
public function testValidateWithDefaultValue($xml, $expectedValue)
{
if (!function_exists('libxml_set_external_entity_loader')) {
$this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
}

$actualErrors = [];

$dom = new \Magento\Framework\Config\Dom($xml, $this->validationStateMock);
$dom->validate(__DIR__ . '/_files/sample.xsd', $actualErrors);

$actualValue = $dom->getDom()
->getElementsByTagName('root')->item(0)
->getElementsByTagName('node')->item(0)
->getAttribute('attribute_with_default_value');

$this->assertEmpty($actualErrors);
$this->assertEquals($expectedValue, $actualValue);
}

/**
* @return array
*/
public function validateWithDefaultValueDataProvider()
{
return [
'default_value' => [
'<root><node id="id1"/></root>',
'default_value'
],
'custom_value' => [
'<root><node id="id1" attribute_with_default_value="non_default_value"/></root>',
'non_default_value'
],
];
}

public function testValidateCustomErrorFormat()
{
$xml = '<root><unknown_node/></root>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="id" type="xs:string" use="required"/>
<xs:attribute name="attribute_with_default_value" type="xs:string" default="default_value"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand Down