-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
magento/magento2: Fixes for the schema cache.xsd #27307
Merged
magento-engcom-team
merged 3 commits into
magento:2.4-develop
from
andrewbess:cache-schema-improvements
Mar 25, 2020
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting approach to provide code samples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @lbajsarowicz
Thank you for your remark.
Magento already has the same data providers. Please take a look at the screenshot
Thank you in advance.