-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-7114: magento/magento2: Fixes for the schema cache.xsd [DONT M…
…ERGE YET] #27307
- Loading branch information
Showing
11 changed files
with
286 additions
and
150 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
dev/tests/static/testsuite/Magento/Test/Integrity/Magento/Framework/Cache/ConfigTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types = 1); | ||
|
||
namespace Magento\Test\Integrity\Magento\Framework\Cache; | ||
|
||
use Magento\Framework\Config\Dom\UrnResolver; | ||
use Magento\Framework\TestFramework\Unit\Utility\XsdValidator; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Unit test of the cache configuration | ||
*/ | ||
class ConfigTest extends TestCase | ||
{ | ||
/** | ||
* Path to xsd schema file | ||
* @var string | ||
*/ | ||
private $xsdSchema; | ||
|
||
/** | ||
* @var UrnResolver | ||
*/ | ||
private $urnResolver; | ||
|
||
/** | ||
* @var XsdValidator | ||
*/ | ||
private $xsdValidator; | ||
|
||
/** | ||
* Setup environment for test | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
if (!function_exists('libxml_set_external_entity_loader')) { | ||
$this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033'); | ||
} | ||
$this->urnResolver = new UrnResolver(); | ||
$this->xsdSchema = $this->urnResolver->getRealPath( | ||
'urn:magento:framework:Cache/etc/cache.xsd' | ||
); | ||
$this->xsdValidator = new XsdValidator(); | ||
} | ||
|
||
/** | ||
* Tests invalid configurations | ||
* | ||
* @param string $xmlString | ||
* @param array $expectedError | ||
* @dataProvider schemaCorrectlyIdentifiesInvalidXmlDataProvider | ||
*/ | ||
public function testSchemaCorrectlyIdentifiesInvalidXml( | ||
string $xmlString, | ||
array $expectedError | ||
): void { | ||
$actualError = $this->xsdValidator->validate( | ||
$this->xsdSchema, | ||
$xmlString | ||
); | ||
$this->assertEquals($expectedError, $actualError); | ||
} | ||
|
||
/** | ||
* Tests valid configurations | ||
*/ | ||
public function testSchemaCorrectlyIdentifiesValidXml(): void | ||
{ | ||
$xmlString = file_get_contents(__DIR__ . '/_files/valid_cache_config.xml'); | ||
$actualResult = $this->xsdValidator->validate( | ||
$this->xsdSchema, | ||
$xmlString | ||
); | ||
|
||
$this->assertEmpty($actualResult); | ||
} | ||
|
||
/** | ||
* Data provider with invalid xml array according to cache.xsd | ||
*/ | ||
public function schemaCorrectlyIdentifiesInvalidXmlDataProvider(): array | ||
{ | ||
return include __DIR__ . '/_files/invalidCacheConfigXmlArray.php'; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...uite/Magento/Test/Integrity/Magento/Framework/Cache/_files/invalidCacheConfigXmlArray.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
return [ | ||
'without_type_handle' => [ | ||
'<?xml version="1.0"?><config></config>', | ||
["Element 'config': Missing child element(s). Expected is ( type ).\nLine: 1\n"], | ||
], | ||
'cache_config_with_notallowed_attribute' => [ | ||
'<?xml version="1.0"?><config>' . | ||
'<type name="test" translate="label,description" instance="Class\Name" notallowed="some value">' . | ||
'<label>Test</label><description>Test</description></type></config>', | ||
["Element 'type', attribute 'notallowed': The attribute 'notallowed' is not allowed.\nLine: 1\n"], | ||
], | ||
'cache_config_without_name_attribute' => [ | ||
'<?xml version="1.0"?><config><type translate="label,description" instance="Class\Name">' . | ||
'<label>Test</label><description>Test</description></type></config>', | ||
["Element 'type': The attribute 'name' is required but missing.\nLine: 1\n"], | ||
], | ||
'cache_config_without_instance_attribute' => [ | ||
'<?xml version="1.0"?><config><type name="test" translate="label,description">' . | ||
'<label>Test</label><description>Test</description></type></config>', | ||
["Element 'type': The attribute 'instance' is required but missing.\nLine: 1\n"], | ||
], | ||
'cache_config_without_label_element' => [ | ||
'<?xml version="1.0"?><config><type name="test" translate="label,description" instance="Class\Name">' . | ||
'<description>Test</description></type></config>', | ||
["Element 'type': Missing child element(s). Expected is ( label ).\nLine: 1\n"], | ||
], | ||
'cache_config_without_description_element' => [ | ||
'<?xml version="1.0"?><config><type name="test" translate="label,description" instance="Class\Name">' . | ||
'<label>Test</label></type></config>', | ||
["Element 'type': Missing child element(s). Expected is ( description ).\nLine: 1\n"], | ||
], | ||
'cache_config_without_child_elements' => [ | ||
'<?xml version="1.0"?><config><type name="test" translate="label,description" instance="Class\Name">' . | ||
'</type></config>', | ||
["Element 'type': Missing child element(s). Expected is one of ( label, description ).\nLine: 1\n"], | ||
], | ||
'cache_config_cache_name_not_unique' => [ | ||
'<?xml version="1.0"?><config><type name="test" translate="label,description" instance="Class\Name1">' . | ||
'<label>Test1</label><description>Test1</description></type>' . | ||
'<type name="test" translate="label,description" instance="Class\Name2">' . | ||
'<label>Test2</label><description>Test2</description></type></config>', | ||
[ | ||
"Element 'type': Duplicate key-sequence ['test'] in unique identity-constraint" | ||
. " 'uniqueCacheName'.\nLine: 1\n" | ||
], | ||
], | ||
]; |
17 changes: 17 additions & 0 deletions
17
...ic/testsuite/Magento/Test/Integrity/Magento/Framework/Cache/_files/valid_cache_config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Cache/etc/cache.xsd"> | ||
<type name="type_name_1" translate="label,description" instance="Instance1\Class\Name"> | ||
<label>Type1</label> | ||
<description>Type1</description> | ||
</type> | ||
<type name="type_name_2" translate="label,description" instance="Instance2\Class\Name"> | ||
<label>Type2</label> | ||
<description>Type2</description> | ||
</type> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.