1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details.
5
- */
6
-
7
- /**
8
- * Test for validation rules implemented by XSD schemas for email templates configuration
3
+ * Copyright 2013 Adobe
4
+ * All Rights Reserved.
9
5
*/
10
6
declare (strict_types=1 );
11
7
14
10
use Magento \Framework \Config \Dom ;
15
11
use Magento \Framework \Config \Dom \UrnResolver ;
16
12
use Magento \Framework \Config \ValidationStateInterface ;
13
+ use PHPUnit \Framework \AssertionFailedError ;
17
14
use PHPUnit \Framework \TestCase ;
18
15
16
+ /**
17
+ * Test for validation rules implemented by XSD schemas for email templates configuration
18
+ */
19
19
class XsdTest extends TestCase
20
20
{
21
21
/**
@@ -50,114 +50,150 @@ public static function mergedXmlDataProvider()
50
50
'empty root node ' => [
51
51
'<config/> ' ,
52
52
[
53
- "Element 'config': Missing child element(s). Expected is ( template ).The xml was: \n" .
54
- "0:<?xml version= \"1.0 \"?> \n1:<config/> \n2: \n"
53
+ [
54
+ "Element 'config': Missing child element(s). Expected is ( template ).The xml was: \n" .
55
+ "0:<?xml version= \"1.0 \"?> \n1:<config/> \n2: \n" ,
56
+ false ,
57
+ ],
55
58
],
56
59
],
57
60
'irrelevant root node ' => [
58
61
'<template id="test" label="Test" file="test.txt" type="text" module="Module" area="frontend"/> ' ,
59
62
[
60
- "Element 'template': No matching global declaration available for the validation root. " .
61
- "The xml was: \n0:<?xml version= \"1.0 \"?> \n1:<template id= \"test \" label= \"Test \" " .
62
- "file= \"test.txt \" type= \"text \" module= \"Module \" area= \"frontend \"/> \n2: \n"
63
+ [
64
+ "Element 'template': No matching global declaration available for the validation root. " .
65
+ "The xml was: \n0:<?xml version= \"1.0 \"?> \n1:<template id= \"test \" label= \"Test \" " .
66
+ "file= \"test.txt \" type= \"text \" module= \"Module \" area= \"frontend \"/> \n2: \n" ,
67
+ false ,
68
+ ],
63
69
],
64
70
],
65
71
'invalid node ' => [
66
72
'<config><invalid/></config> ' ,
67
73
[
68
- "Element 'invalid': This element is not expected. Expected is ( template ).The xml was: \n" .
69
- "0:<?xml version= \"1.0 \"?> \n1:<config><invalid/></config> \n2: \n"
74
+ [
75
+ "Element 'invalid': This element is not expected. Expected is ( template ).The xml was: \n" .
76
+ "0:<?xml version= \"1.0 \"?> \n1:<config><invalid/></config> \n2: \n" ,
77
+ false ,
78
+ ],
70
79
],
71
80
],
72
81
'node "template" with value ' => [
73
82
'<config>
74
83
<template id="test" label="Test" file="test.txt" type="text" module="Module" area="frontend">invalid</template>
75
84
</config> ' ,
76
85
[
77
- "Element 'template': Character content is not allowed, because the content type is empty. " .
78
- "The xml was: \n0:<?xml version= \"1.0 \"?> \n1:<config> \n2: <template " .
79
- "id= \"test \" label= \"Test \" file= \"test.txt \" type= \"text \" module= \"Module \" " .
80
- "area= \"frontend \">invalid</template> \n3: </config> \n4: \n"
86
+ [
87
+ "Element 'template': Character content is not allowed, because the content type is empty. " .
88
+ "The xml was: \n0:<?xml version= \"1.0 \"?> \n1:<config> \n2: <template " .
89
+ "id= \"test \" label= \"Test \" file= \"test.txt \" type= \"text \" module= \"Module \" " .
90
+ "area= \"frontend \">invalid</template> \n3: </config> \n4: \n" ,
91
+ false ,
92
+ ],
81
93
],
82
94
],
83
95
'node "template" with children ' => [
84
96
'<config>
85
97
<template id="test" label="Test" file="test.txt" type="text" module="Module" area="frontend"><invalid/></template>
86
98
</config> ' ,
87
99
[
88
- "Element 'template': Element content is not allowed, because the content type is empty.The xml " .
89
- "was: \n0:<?xml version= \"1.0 \"?> \n1:<config> \n2: <template id= \"test \" " .
90
- "label= \"Test \" file= \"test.txt \" type= \"text \" module= \"Module \" area= \"frontend \"><invalid/> " .
91
- "</template> \n3: </config> \n4: \n"
100
+ [
101
+ "Element 'template': Element content is not allowed, because the content type is empty.The xml " .
102
+ "was: \n0:<?xml version= \"1.0 \"?> \n1:<config> \n2: <template id= \"test \" " .
103
+ "label= \"Test \" file= \"test.txt \" type= \"text \" module= \"Module \" area= \"frontend \"><invalid/> " .
104
+ "</template> \n3: </config> \n4: \n" ,
105
+ false ,
106
+ ],
92
107
],
93
108
],
94
109
'node "template" without attribute "id" ' => [
95
110
'<config><template label="Test" file="test.txt" type="text" module="Module" area="frontend"/></config> ' ,
96
111
[
97
- "Element 'template': The attribute 'id' is required but missing.The xml was: \n" .
98
- "0:<?xml version= \"1.0 \"?> \n1:<config><template label= \"Test \" file= \"test.txt \" type= \"text \" " .
99
- "module= \"Module \" area= \"frontend \"/></config> \n2: \n"
112
+ [
113
+ "Element 'template': The attribute 'id' is required but missing.The xml was: \n" .
114
+ "0:<?xml version= \"1.0 \"?> \n1:<config><template label= \"Test \" file= \"test.txt \" type= \"text \" " .
115
+ "module= \"Module \" area= \"frontend \"/></config> \n2: \n" ,
116
+ false ,
117
+ ],
100
118
],
101
119
],
102
120
'node "template" without attribute "label" ' => [
103
121
'<config><template id="test" file="test.txt" type="text" module="Module" area="frontend"/></config> ' ,
104
122
[
105
- "Element 'template': The attribute 'label' is required but missing.The xml was: \n" .
106
- "0:<?xml version= \"1.0 \"?> \n1:<config><template id= \"test \" file= \"test.txt \" type= \"text \" " .
107
- "module= \"Module \" area= \"frontend \"/></config> \n2: \n"
123
+ [
124
+ "Element 'template': The attribute 'label' is required but missing.The xml was: \n" .
125
+ "0:<?xml version= \"1.0 \"?> \n1:<config><template id= \"test \" file= \"test.txt \" type= \"text \" " .
126
+ "module= \"Module \" area= \"frontend \"/></config> \n2: \n" ,
127
+ false ,
128
+ ],
108
129
],
109
130
],
110
131
'node "template" without attribute "file" ' => [
111
132
'<config><template id="test" label="Test" type="text" module="Module" area="frontend"/></config> ' ,
112
133
[
113
- "Element 'template': The attribute 'file' is required but missing.The xml was: \n" .
114
- "0:<?xml version= \"1.0 \"?> \n1:<config><template id= \"test \" label= \"Test \" type= \"text \" " .
115
- "module= \"Module \" area= \"frontend \"/></config> \n2: \n"
134
+ [
135
+ "Element 'template': The attribute 'file' is required but missing.The xml was: \n" .
136
+ "0:<?xml version= \"1.0 \"?> \n1:<config><template id= \"test \" label= \"Test \" type= \"text \" " .
137
+ "module= \"Module \" area= \"frontend \"/></config> \n2: \n" ,
138
+ false ,
139
+ ],
116
140
],
117
141
],
118
142
'node "template" without attribute "type" ' => [
119
143
'<config><template id="test" label="Test" file="test.txt" module="Module" area="frontend"/></config> ' ,
120
144
[
121
- "Element 'template': The attribute 'type' is required but missing.The xml was: \n" .
122
- "0:<?xml version= \"1.0 \"?> \n1:<config><template id= \"test \" label= \"Test \" file= \"test.txt \" " .
123
- "module= \"Module \" area= \"frontend \"/></config> \n2: \n"
145
+ [
146
+ "Element 'template': The attribute 'type' is required but missing.The xml was: \n" .
147
+ "0:<?xml version= \"1.0 \"?> \n1:<config><template id= \"test \" label= \"Test \" file= \"test.txt \" " .
148
+ "module= \"Module \" area= \"frontend \"/></config> \n2: \n" ,
149
+ false ,
150
+ ],
124
151
],
125
152
],
126
153
'node "template" with invalid attribute "type" ' => [
127
154
'<config><template id="test" label="Test" file="test.txt" type="invalid" module="Module" area="frontend"/></config> ' ,
128
155
[
129
- "Element 'template', attribute 'type': [facet 'enumeration'] The value 'invalid' is not an " .
130
- "element of the set {'html', 'text'}.The xml was: \n0:<?xml version= \"1.0 \"?> \n" .
131
- "1:<config><template id= \"test \" label= \"Test \" file= \"test.txt \" type= \"invalid \" " .
132
- "module= \"Module \" area= \"frontend \"/></config> \n2: \n"
156
+ [
157
+ "Element 'template', attribute 'type': [facet 'enumeration'] The value 'invalid' is not an " .
158
+ "element of the set {'html', 'text'}.The xml was: \n0:<?xml version= \"1.0 \"?> \n" .
159
+ "1:<config><template id= \"test \" label= \"Test \" file= \"test.txt \" type= \"invalid \" " .
160
+ "module= \"Module \" area= \"frontend \"/></config> \n2: \n" ,
161
+ false ,
162
+ ],
133
163
],
134
164
],
135
165
'node "template" without attribute "area" ' => [
136
166
'<config><template id="test" label="Test" file="test.txt" type="text" module="Module"/></config> ' ,
137
167
[
138
- "Element 'template': The attribute 'area' is required but missing.The xml was: \n" .
139
- "0:<?xml version= \"1.0 \"?> \n1:<config><template id= \"test \" label= \"Test \" file= \"test.txt \" " .
140
- "type= \"text \" module= \"Module \"/></config> \n2: \n"
168
+ [
169
+ "Element 'template': The attribute 'area' is required but missing.The xml was: \n" .
170
+ "0:<?xml version= \"1.0 \"?> \n1:<config><template id= \"test \" label= \"Test \" file= \"test.txt \" " .
171
+ "type= \"text \" module= \"Module \"/></config> \n2: \n" ,
172
+ false ,
173
+ ],
141
174
],
142
175
],
143
176
'node "template" with invalid attribute "area" ' => [
144
177
'<config><template id="test" label="Test" file="test.txt" type="text" module="Module" area="invalid"/></config> ' ,
145
178
[
146
- " Element 'template', attribute 'area': 'invalid' is not a valid value of the atomic type " .
147
- " 'areaType'.The xml was: \n 0:<?xml version= \" 1.0 \" ?> \n 1:<config><template id= \" test \" " .
148
- " label= \" Test \" file= \" test.txt \" type= \" text \" module= \" Module \" area= \" invalid \" /> " .
149
- " </config> \n 2: \n" ,
179
+ [
180
+ " /Element \'template\', attribute \'area\': .*\'invalid\' is not (a valid value|an element of the set).*/ " ,
181
+ true ,
182
+ ] ,
150
183
],
151
184
],
152
185
'node "template" with unknown attribute ' => [
153
186
'<config>
154
187
<template id="test" label="Test" file="test.txt" type="text" module="Module" area="frontend" unknown="true"/>
155
188
</config> ' ,
156
189
[
157
- "Element 'template', attribute 'unknown': The attribute 'unknown' is not allowed.The xml was: \n" .
158
- "0:<?xml version= \"1.0 \"?> \n1:<config> \n2: <template id= \"test \" " .
159
- "label= \"Test \" file= \"test.txt \" type= \"text \" module= \"Module \" area= \"frontend \" " .
160
- "unknown= \"true \"/> \n3: </config> \n4: \n"
190
+ [
191
+ "Element 'template', attribute 'unknown': The attribute 'unknown' is not allowed.The xml was: \n" .
192
+ "0:<?xml version= \"1.0 \"?> \n1:<config> \n2: <template id= \"test \" " .
193
+ "label= \"Test \" file= \"test.txt \" type= \"text \" module= \"Module \" area= \"frontend \" " .
194
+ "unknown= \"true \"/> \n3: </config> \n4: \n" ,
195
+ false ,
196
+ ],
161
197
],
162
198
]
163
199
];
@@ -179,8 +215,22 @@ protected function _testXmlAgainstXsd($fixtureXml, $schemaFile, array $expectedE
179
215
$ dom = new Dom ($ fixtureXml , $ validationStateMock , [], null , null , '%message% ' );
180
216
$ actualResult = $ dom ->validate ($ schemaFile , $ actualErrors );
181
217
$ this ->assertEquals (empty ($ expectedErrors ), $ actualResult );
182
- foreach ($ expectedErrors as $ error ) {
183
- $ this ->assertContains ($ error , $ actualErrors );
218
+ $ this ->assertEquals (empty ($ expectedErrors ), empty ($ actualErrors ));
219
+ foreach ($ expectedErrors as [$ error , $ isRegex ]) {
220
+ if ($ isRegex ) {
221
+ $ matched = false ;
222
+ foreach ($ actualErrors as $ actualError ) {
223
+ try {
224
+ $ this ->assertMatchesRegularExpression ($ error , $ actualError );
225
+ $ matched = true ;
226
+ break ;
227
+ } catch (AssertionFailedError ) {
228
+ }
229
+ }
230
+ $ this ->assertTrue ($ matched , "None of the errors matched: $ error " );
231
+ } else {
232
+ $ this ->assertContains ($ error , $ actualErrors );
233
+ }
184
234
}
185
235
}
186
236
}
0 commit comments