markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
}
$urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
$this->schemaFile = $urnResolver->getRealPath(
'urn:magento:module:Magento_Integration:etc/integration/api.xsd'
);
}
/**
* @param string $fixtureXml
* @param array $expectedErrors
* @dataProvider exemplarXmlDataProvider
*/
public function testExemplarXml($fixtureXml, array $expectedErrors)
{
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
$validationStateMock->method('isValidationRequired')
->willReturn(true);
$messageFormat = '%message%';
$dom = new \Magento\Framework\Config\Dom($fixtureXml, $validationStateMock, [], null, null, $messageFormat);
$actualResult = $dom->validate($this->schemaFile, $actualErrors);
$this->assertEquals(empty($expectedErrors), $actualResult, "Validation result is invalid.");
$this->assertEquals($expectedErrors, $actualErrors, "Validation errors does not match.");
}
/**
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function exemplarXmlDataProvider()
{
return [
/** Valid configurations */
'valid' => [
'
',
[],
],
'valid with several entities' => [
'
',
[],
],
/** Missing required nodes */
'empty root node' => [
'',
["Element 'integrations': Missing child element(s). Expected is ( integration )."],
],
'empty integration' => [
'
',
["Element 'integration': Missing child element(s). Expected is ( resources )."],
],
'empty resources' => [
'
',
["Element 'resources': Missing child element(s). Expected is ( resource )."],
],
'irrelevant root node' => [
'',
["Element 'integration': No matching global declaration available for the validation root."],
],
/** Excessive nodes */
'irrelevant node in root' => [
'
',
["Element 'invalid': This element is not expected. Expected is ( integration )."],
],
'irrelevant node in integration' => [
'
',
["Element 'invalid': This element is not expected."],
],
'irrelevant node in resources' => [
'
',
["Element 'invalid': This element is not expected. Expected is ( resource )."],
],
'irrelevant node in resource' => [
'
',
[
"Element 'resource': Element content is not allowed, " .
"because the content type is a simple type definition."
],
],
/** Excessive attributes */
'invalid attribute in root' => [
'
',
["Element 'integrations', attribute 'invalid': The attribute 'invalid' is not allowed."],
],
'invalid attribute in integration' => [
'
',
["Element 'integration', attribute 'invalid': The attribute 'invalid' is not allowed."],
],
'invalid attribute in resources' => [
'
',
["Element 'resources', attribute 'invalid': The attribute 'invalid' is not allowed."],
],
'invalid attribute in resource' => [
'
',
["Element 'resource', attribute 'invalid': The attribute 'invalid' is not allowed."],
],
/** Missing or empty required attributes */
'integration without name' => [
'
',
["Element 'integration': The attribute 'name' is required but missing."],
],
'integration with empty name' => [
'
',
[
"Element 'integration', attribute 'name': [facet 'minLength'] The value '' has a length of '0'; " .
"this underruns the allowed minimum length of '2'.",
"Element 'integration', attribute 'name': " .
"'' is not a valid value of the atomic type 'integrationNameType'."
],
],
'resource without name' => [
'
',
["Element 'resource': The attribute 'name' is required but missing."],
],
'resource with empty name' => [
'
',
[
"Element 'resource', attribute 'name': [facet 'pattern'] " .
"The value '' is not accepted by the pattern '.+_.+::.+'.",
"Element 'resource', attribute 'name': '' " .
"is not a valid value of the atomic type 'resourceNameType'."
],
],
/** Invalid values */
'resource with invalid name' => [
'
',
[
"Element 'resource', attribute 'name': [facet 'pattern'] " .
"The value 'customer_manage' is not accepted by the pattern '.+_.+::.+'.",
"Element 'resource', attribute 'name': 'customer_manage' " .
"is not a valid value of the atomic type 'resourceNameType'."
],
]
];
}
}