File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed
lib/internal/Magento/Framework/Config Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -313,7 +313,7 @@ public static function validateDomDocument(
313
313
libxml_set_external_entity_loader ([self ::$ urnResolver , 'registerEntityLoader ' ]);
314
314
$ errors = [];
315
315
try {
316
- $ result = $ dom ->schemaValidate ($ schema );
316
+ $ result = $ dom ->schemaValidate ($ schema, LIBXML_SCHEMA_CREATE );
317
317
if (!$ result ) {
318
318
$ errors = self ::getXmlErrors ($ errorFormat );
319
319
}
Original file line number Diff line number Diff line change @@ -135,6 +135,48 @@ public function validateDataProvider()
135
135
];
136
136
}
137
137
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
+
138
180
public function testValidateCustomErrorFormat ()
139
181
{
140
182
$ xml = '<root><unknown_node/></root> ' ;
Original file line number Diff line number Diff line change 21
21
<xs : simpleContent >
22
22
<xs : extension base =" xs:string" >
23
23
<xs : attribute name =" id" type =" xs:string" use =" required" />
24
+ <xs : attribute name =" attribute_with_default_value" type =" xs:string" default =" default_value" />
24
25
</xs : extension >
25
26
</xs : simpleContent >
26
27
</xs : complexType >
You can’t perform that action at this time.
0 commit comments