Skip to content

Commit aae9d69

Browse files
author
Oleksii Korshenko
committed
MAGETWO-52792: ACL node title stated as optional in xsd but required in logic
- added unit tests
1 parent 0c0fcde commit aae9d69

File tree

6 files changed

+280
-26
lines changed

6 files changed

+280
-26
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Acl\Test\Unit\AclResource\Config;
7+
8+
class MergedXsdTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\Framework\Acl\AclResource\Config\SchemaLocator
12+
*/
13+
protected $_schemaLocator;
14+
15+
/**
16+
* Path to xsd schema file
17+
* @var string
18+
*/
19+
protected $_xsdSchema;
20+
21+
/**
22+
* @var \Magento\Framework\TestFramework\Unit\Utility\XsdValidator
23+
*/
24+
protected $_xsdValidator;
25+
26+
protected function setUp()
27+
{
28+
if (!function_exists('libxml_set_external_entity_loader')) {
29+
$this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
30+
}
31+
$this->_schemaLocator = new \Magento\Framework\Acl\AclResource\Config\SchemaLocator(
32+
new \Magento\Framework\Config\Dom\UrnResolver()
33+
);
34+
$this->_xsdSchema = $this->_schemaLocator->getSchema();
35+
$this->_xsdValidator = new \Magento\Framework\TestFramework\Unit\Utility\XsdValidator();
36+
}
37+
38+
/**
39+
* @param string $xmlString
40+
* @param array $expectedError
41+
* @dataProvider schemaCorrectlyIdentifiesInvalidXmlDataProvider
42+
*/
43+
public function testSchemaCorrectlyIdentifiesInvalidXml($xmlString, $expectedError)
44+
{
45+
$actualError = $this->_xsdValidator->validate($this->_xsdSchema, $xmlString);
46+
$this->assertEquals($expectedError, $actualError);
47+
}
48+
49+
public function testSchemaCorrectlyIdentifiesValidXml()
50+
{
51+
$xmlString = file_get_contents(__DIR__ . '/_files/valid_merged_acl.xml');
52+
$actualResult = $this->_xsdValidator->validate($this->_xsdSchema, $xmlString);
53+
54+
$this->assertEmpty($actualResult);
55+
}
56+
57+
/**
58+
* Data provider with invalid xml array according to acl.xsd
59+
*/
60+
public function schemaCorrectlyIdentifiesInvalidXmlDataProvider()
61+
{
62+
return include __DIR__ . '/_files/invalidMergedAclXmlArray.php';
63+
}
64+
}

lib/internal/Magento/Framework/Acl/Test/Unit/AclResource/Config/XsdTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function setUp()
3131
$this->_schemaLocator = new \Magento\Framework\Acl\AclResource\Config\SchemaLocator(
3232
new \Magento\Framework\Config\Dom\UrnResolver()
3333
);
34-
$this->_xsdSchema = $this->_schemaLocator->getSchema();
34+
$this->_xsdSchema = $this->_schemaLocator->getPerFileSchema();
3535
$this->_xsdValidator = new \Magento\Framework\TestFramework\Unit\Utility\XsdValidator();
3636
}
3737

lib/internal/Magento/Framework/Acl/Test/Unit/AclResource/Config/_files/invalidAclXmlArray.php

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@
99
'disabled=""/></resources></acl></config>',
1010
[
1111
"Element 'resource', attribute 'disabled': '' is not a valid value of the atomic" .
12-
" type 'xs:boolean'.\nLine: 1\n",
13-
"Element 'resource': The attribute 'title' is required but missing.\nLine: 1\n",
14-
],
12+
" type 'xs:boolean'.\nLine: 1\n"],
1513
],
1614
'disabled_attribute_wrong_type_value' => [
1715
'<?xml version="1.0"?><config><acl><resources><resource id="Test_Value::show_toolbar" ' .
1816
'disabled="notBool"/></resources></acl></config>',
1917
[
2018
"Element 'resource', attribute 'disabled': 'notBool' is not a valid value of the atomic type " .
21-
"'xs:boolean'.\nLine: 1\n",
22-
"Element 'resource': The attribute 'title' is required but missing.\nLine: 1\n",
19+
"'xs:boolean'.\nLine: 1\n"
2320
],
2421
],
2522
'double_acl' => [
@@ -62,8 +59,7 @@
6259
"'typeId'.\nLine: 1\n",
6360
"Element 'resource', attribute 'id': Warning: No precomputed value available, " .
6461
"the value was either invalid or " .
65-
"something strange happend.\nLine: 1\n",
66-
"Element 'resource': The attribute 'title' is required but missing.\nLine: 1\n",
62+
"something strange happend.\nLine: 1\n"
6763
],
6864
],
6965
'notvalid_id_attribute_value_regexp2' => [
@@ -75,8 +71,7 @@
7571
"Element 'resource', attribute 'id': 'Test_value::show_toolbar' is not a valid value of the atomic type " .
7672
"'typeId'.\nLine: 1\n",
7773
"Element 'resource', attribute 'id': Warning: No precomputed value available, " .
78-
"the value was either invalid or something strange happend.\nLine: 1\n",
79-
"Element 'resource': The attribute 'title' is required but missing.\nLine: 1\n",
74+
"the value was either invalid or something strange happend.\nLine: 1\n"
8075
],
8176
],
8277
'notvalid_id_attribute_value_regexp3' => [
@@ -88,8 +83,7 @@
8883
"Element 'resource', attribute 'id': 'M@#$%^*_Value::show_toolbar' " .
8984
"is not a valid value of the atomic type 'typeId'.\nLine: 1\n",
9085
"Element 'resource', attribute 'id': Warning: No precomputed value available, " .
91-
"the value was either invalid or something strange happend.\nLine: 1\n",
92-
"Element 'resource': The attribute 'title' is required but missing.\nLine: 1\n",
86+
"the value was either invalid or something strange happend.\nLine: 1\n"
9387
],
9488
],
9589
'notvalid_id_attribute_value_regexp4' => [
@@ -102,8 +96,7 @@
10296
"is not a valid value of the atomic type 'typeId'.\nLine: 1\n",
10397
"Element 'resource', attribute 'id': " .
10498
"Warning: No precomputed value available, the value was either invalid " .
105-
"or something strange happend.\nLine: 1\n",
106-
"Element 'resource': The attribute 'title' is required but missing.\nLine: 1\n",
99+
"or something strange happend.\nLine: 1\n"
107100
],
108101
],
109102
'notvalid_id_attribute_value_regexp5' => [
@@ -116,8 +109,7 @@
116109
"is not a valid value of the atomic type 'typeId'.\nLine: 1\n",
117110
"Element 'resource', attribute 'id': " .
118111
"Warning: No precomputed value available, the value was either invalid " .
119-
"or something strange happend.\nLine: 1\n",
120-
"Element 'resource': The attribute 'title' is required but missing.\nLine: 1\n",
112+
"or something strange happend.\nLine: 1\n"
121113
],
122114
],
123115
'notvalid_id_attribute_value_regexp6' => [
@@ -130,8 +122,7 @@
130122
"type 'typeId'.\nLine: 1\n",
131123
"Element 'resource', attribute 'id': " .
132124
"Warning: No precomputed value available, the value was either invalid " .
133-
"or something strange happend.\nLine: 1\n",
134-
"Element 'resource': The attribute 'title' is required but missing.\nLine: 1\n",
125+
"or something strange happend.\nLine: 1\n"
135126
],
136127
],
137128
'notvalid_id_attribute_value_regexp7' => [
@@ -143,8 +134,7 @@
143134
" 'typeId'.\nLine: 1\n",
144135
"Element 'resource', attribute 'id': " .
145136
"Warning: No precomputed value available, the value was either invalid " .
146-
"or something strange happend.\nLine: 1\n",
147-
"Element 'resource': The attribute 'title' is required but missing.\nLine: 1\n",
137+
"or something strange happend.\nLine: 1\n"
148138
],
149139
],
150140
'sortOrder_attribute_empty_value' => [
@@ -163,10 +153,7 @@
163153
'with_not_allowed_attribute' => [
164154
'<?xml version="1.0"?><config><acl><resources><resource id="Test_Value::show_toolbar" ' .
165155
'someatrrname="some value"/></resources></acl></config>',
166-
[
167-
"Element 'resource', attribute 'someatrrname': The attribute 'someatrrname' is not allowed.\nLine: 1\n",
168-
"Element 'resource': The attribute 'title' is required but missing.\nLine: 1\n",
169-
],
156+
["Element 'resource', attribute 'someatrrname': The attribute 'someatrrname' is not allowed.\nLine: 1\n"],
170157
],
171158
'with_two_same_id' => [
172159
'<?xml version="1.0"?><config><acl><resources><resource id="Test_Value::show_toolbar" ' .
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
return [
7+
'disabled_attribute_empty_value' => [
8+
'<?xml version="1.0"?><config><acl><resources><resource id="Test_Value::show_toolbar" ' .
9+
'disabled="" title="test"/></resources></acl></config>',
10+
[
11+
"Element 'resource', attribute 'disabled': '' is not a valid value of the atomic" .
12+
" type 'xs:boolean'.\nLine: 1\n"],
13+
],
14+
'disabled_attribute_wrong_type_value' => [
15+
'<?xml version="1.0"?><config><acl><resources><resource id="Test_Value::show_toolbar" ' .
16+
'disabled="notBool" title="test"/></resources></acl></config>',
17+
[
18+
"Element 'resource', attribute 'disabled': 'notBool' is not a valid value of the atomic type " .
19+
"'xs:boolean'.\nLine: 1\n"
20+
],
21+
],
22+
'double_acl' => [
23+
'<?xml version="1.0"?><config><acl><resources></resources></acl><acl/></config>',
24+
["Element 'acl': This element is not expected.\nLine: 1\n"],
25+
],
26+
'double_resource' => [
27+
'<?xml version="1.0"?><config><acl><resources></resources><resources></resources></acl></config>',
28+
["Element 'resources': This element is not expected.\nLine: 1\n"],
29+
],
30+
'less_minLength_title_attribute' => [
31+
'<?xml version="1.0"?><config><acl><resources><resource id="Test_Value::show_toolbar" ' .
32+
'title="Sh"/></resources></acl></config>',
33+
[
34+
"Element 'resource', attribute 'title': [facet 'minLength'] The value 'Sh' has a length of '2'; " .
35+
"this underruns the allowed minimum length of '3'.\nLine: 1\n",
36+
"Element 'resource', attribute 'title': 'Sh' is not a valid value of the atomic type" .
37+
" 'typeTitle'.\nLine: 1\n"
38+
],
39+
],
40+
'more_maxLength_title_attribute' => [
41+
'<?xml version="1.0"?><config><acl><resources><resource id="Test_Value::show_toolbar"' .
42+
' title="Lorem ipsum dolor sit amet, consectetur adipisicing"/></resources></acl></config>',
43+
[
44+
"Element 'resource', attribute 'title': [facet 'maxLength'] The value 'Lorem ipsum dolor sit amet, " .
45+
"consectetur adipisicing' has a length of '51'; this exceeds the allowed maximum" .
46+
" length of '50'.\nLine: 1\n",
47+
"Element 'resource', attribute 'title': 'Lorem ipsum dolor sit amet, consectetur adipisicing' is not " .
48+
"a valid value of the atomic type 'typeTitle'.\nLine: 1\n"
49+
],
50+
],
51+
'notvalid_id_attribute_value_regexp1' => [
52+
'<?xml version="1.0"?><config><acl><resources><resource id="test_Value::show_toolbar" title="test"/>' .
53+
'</resources></acl></config>',
54+
[
55+
"Element 'resource', attribute 'id': [facet 'pattern'] The value 'test_Value::show_toolbar' is " .
56+
"not accepted by the pattern" .
57+
" '([A-Z]+[a-zA-Z0-9]{1,}){1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.\nLine: 1\n",
58+
"Element 'resource', attribute 'id': 'test_Value::show_toolbar' is not a valid value of the atomic type " .
59+
"'typeId'.\nLine: 1\n",
60+
"Element 'resource', attribute 'id': Warning: No precomputed value available, " .
61+
"the value was either invalid or " .
62+
"something strange happend.\nLine: 1\n"
63+
],
64+
],
65+
'notvalid_id_attribute_value_regexp2' => [
66+
'<?xml version="1.0"?><config><acl><resources><resource id="Test_value::show_toolbar" title="test"/>' .
67+
'</resources></acl></config>',
68+
[
69+
"Element 'resource', attribute 'id': [facet 'pattern'] The value 'Test_value::show_toolbar' is not " .
70+
"accepted by the pattern '([A-Z]+[a-zA-Z0-9]{1,}){1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.\nLine: 1\n",
71+
"Element 'resource', attribute 'id': 'Test_value::show_toolbar' is not a valid value of the atomic type " .
72+
"'typeId'.\nLine: 1\n",
73+
"Element 'resource', attribute 'id': Warning: No precomputed value available, " .
74+
"the value was either invalid or something strange happend.\nLine: 1\n"
75+
],
76+
],
77+
'notvalid_id_attribute_value_regexp3' => [
78+
'<?xml version="1.0"?><config><acl><resources><resource id="M@#$%^*_Value::show_toolbar" title="test"/>' .
79+
'</resources></acl></config>',
80+
[
81+
"Element 'resource', attribute 'id': [facet 'pattern'] The value 'M@#$%^*_Value::show_toolbar' is not " .
82+
"accepted by the pattern '([A-Z]+[a-zA-Z0-9]{1,}){1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.\nLine: 1\n",
83+
"Element 'resource', attribute 'id': 'M@#$%^*_Value::show_toolbar' " .
84+
"is not a valid value of the atomic type 'typeId'.\nLine: 1\n",
85+
"Element 'resource', attribute 'id': Warning: No precomputed value available, " .
86+
"the value was either invalid or something strange happend.\nLine: 1\n"
87+
],
88+
],
89+
'notvalid_id_attribute_value_regexp4' => [
90+
'<?xml version="1.0"?><config><acl><resources><resource id="_Value::show_toolbar" title="test"/>' .
91+
'</resources></acl></config>',
92+
[
93+
"Element 'resource', attribute 'id': [facet 'pattern'] The value '_Value::show_toolbar' is not " .
94+
"accepted by the pattern '([A-Z]+[a-zA-Z0-9]{1,}){1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.\nLine: 1\n",
95+
"Element 'resource', attribute 'id': '_Value::show_toolbar' " .
96+
"is not a valid value of the atomic type 'typeId'.\nLine: 1\n",
97+
"Element 'resource', attribute 'id': " .
98+
"Warning: No precomputed value available, the value was either invalid " .
99+
"or something strange happend.\nLine: 1\n"
100+
],
101+
],
102+
'notvalid_id_attribute_value_regexp5' => [
103+
'<?xml version="1.0"?><config><acl><resources><resource id="Value_::show_toolbar" title="test"/></resources>' .
104+
'</acl></config>',
105+
[
106+
"Element 'resource', attribute 'id': [facet 'pattern'] The value 'Value_::show_toolbar' is not " .
107+
"accepted by the pattern '([A-Z]+[a-zA-Z0-9]{1,}){1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.\nLine: 1\n",
108+
"Element 'resource', attribute 'id': 'Value_::show_toolbar' " .
109+
"is not a valid value of the atomic type 'typeId'.\nLine: 1\n",
110+
"Element 'resource', attribute 'id': " .
111+
"Warning: No precomputed value available, the value was either invalid " .
112+
"or something strange happend.\nLine: 1\n"
113+
],
114+
],
115+
'notvalid_id_attribute_value_regexp6' => [
116+
'<?xml version="1.0"?><config><acl><resources><resource id="Test_value:show_toolbar" title="test"/>' .
117+
'</resources></acl></config>',
118+
[
119+
"Element 'resource', attribute 'id': [facet 'pattern'] The value 'Test_value:show_toolbar' is not " .
120+
"accepted by the pattern '([A-Z]+[a-zA-Z0-9]{1,}){1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.\nLine: 1\n",
121+
"Element 'resource', attribute 'id': 'Test_value:show_toolbar' is not a valid value of the atomic " .
122+
"type 'typeId'.\nLine: 1\n",
123+
"Element 'resource', attribute 'id': " .
124+
"Warning: No precomputed value available, the value was either invalid " .
125+
"or something strange happend.\nLine: 1\n"
126+
],
127+
],
128+
'notvalid_id_attribute_value_regexp7' => [
129+
'<?xml version="1.0"?><config><acl><resources><resource id="Test_Value::" title="test"/></resources>' .
130+
'</acl></config>',
131+
[
132+
"Element 'resource', attribute 'id': [facet 'pattern'] The value 'Test_Value::' is not accepted by " .
133+
"the pattern '([A-Z]+[a-zA-Z0-9]{1,}){1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.\nLine: 1\n",
134+
"Element 'resource', attribute 'id': 'Test_Value::' is not a valid value of the atomic type" .
135+
" 'typeId'.\nLine: 1\n",
136+
"Element 'resource', attribute 'id': " .
137+
"Warning: No precomputed value available, the value was either invalid " .
138+
"or something strange happend.\nLine: 1\n"
139+
],
140+
],
141+
'sortOrder_attribute_empty_value' => [
142+
'<?xml version="1.0"?><config><acl><resources><resource id="Test_Value::show_toolbar" ' .
143+
'title="Lorem ipsum" sortOrder="stringValue"/></resources></acl></config>',
144+
[
145+
"Element 'resource', attribute 'sortOrder': 'stringValue' is not a valid value of the atomic " .
146+
"type 'xs:int'.\nLine: 1\n"
147+
],
148+
],
149+
'sortOrder_attribute_wrong_type_value' => [
150+
'<?xml version="1.0"?><config><acl><resources><resource id="Test_Value::show_toolbar" ' .
151+
'title="Lorem ipsum" sortOrder=""/></resources></acl></config>',
152+
["Element 'resource', attribute 'sortOrder': '' is not a valid value of the atomic type 'xs:int'.\nLine: 1\n"],
153+
],
154+
'with_not_allowed_attribute' => [
155+
'<?xml version="1.0"?><config><acl><resources><resource id="Test_Value::show_toolbar" title="test" ' .
156+
'someatrrname="some value"/></resources></acl></config>',
157+
["Element 'resource', attribute 'someatrrname': The attribute 'someatrrname' is not allowed.\nLine: 1\n"],
158+
],
159+
'with_two_same_id' => [
160+
'<?xml version="1.0"?><config><acl><resources><resource id="Test_Value::show_toolbar" ' .
161+
'title="Lorem ipsum"/><resource id="Test_Value::show_toolbar" title="Lorem ipsum"/>' .
162+
'</resources></acl></config>',
163+
[
164+
"Element 'resource': Duplicate key-sequence ['Test_Value::show_toolbar'] in unique identity-constraint " .
165+
"'uniqueResourceId'.\nLine: 1\n"
166+
],
167+
],
168+
'without_acl' => [
169+
'<?xml version="1.0"?><config/>',
170+
["Element 'config': Missing child element(s). Expected is ( acl ).\nLine: 1\n"],
171+
],
172+
'without_required_id_attribute' => [
173+
'<?xml version="1.0"?><config><acl><resources><resource title="Notifications"/></resources></acl></config>',
174+
["Element 'resource': The attribute 'id' is required but missing.\nLine: 1\n"],
175+
],
176+
'without_resource' => [
177+
'<?xml version="1.0"?><config><acl/></config>',
178+
["Element 'acl': Missing child element(s). Expected is ( resources ).\nLine: 1\n"],
179+
],
180+
'without_title' => [
181+
'<?xml version="1.0"?><config><acl><resources><resource id="Test_Value::show_toolbar" />' .
182+
'</resources></acl></config>',
183+
["Element 'resource': The attribute 'title' is required but missing.\nLine: 1\n"],
184+
],
185+
];

lib/internal/Magento/Framework/Acl/Test/Unit/AclResource/Config/_files/valid_acl.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<acl>
1010
<resources>
1111
<resource id="Test_Value::show_toolbar" title="Lorem ipsum" sortOrder="12">
12-
<resource id="Test_Value::global_search" title="some string for title" sortOrder="66" disabled="true">
13-
<resource id="Test_Value::dev" title="123" disabled="false" sortOrder="500" />
12+
<resource id="Test_Value::global_search" sortOrder="66" disabled="true">
13+
<resource id="Test_Value::dev" disabled="false" />
1414
</resource>
1515
</resource>
1616
</resources>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
9+
<acl>
10+
<resources>
11+
<resource id="Test_Value::show_toolbar" title="Lorem ipsum" sortOrder="12">
12+
<resource id="Test_Value::global_search" title="some string for title" sortOrder="66" disabled="true">
13+
<resource id="Test_Value::dev" title="123" disabled="false" sortOrder="500" />
14+
</resource>
15+
</resource>
16+
</resources>
17+
</acl>
18+
</config>

0 commit comments

Comments
 (0)