1
|
|
|
<?php |
2
|
|
|
namespace GoetasWebservices\XML\XSDReader\Tests; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* @group Restriction |
6
|
|
|
*/ |
7
|
|
|
class RestrictionsTest extends BaseTest |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Test the correct detection an Enumeration-restriction. |
11
|
|
|
*/ |
12
|
|
|
public function testRestriction_1() |
13
|
|
|
{ |
14
|
|
|
$schema = $this->reader->readString( |
15
|
|
|
' |
16
|
|
|
<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
17
|
|
|
|
18
|
|
|
<xs:element name="enumeration"> |
19
|
|
|
<xs:simpleType> |
20
|
|
|
<xs:restriction base="xs:string"> |
21
|
|
|
<xs:enumeration value="foo"/> |
22
|
|
|
<xs:enumeration value="bar"/> |
23
|
|
|
</xs:restriction> |
24
|
|
|
</xs:simpleType> |
25
|
|
|
</xs:element> |
26
|
|
|
|
27
|
|
|
</xs:schema>'); |
28
|
|
|
|
29
|
|
|
$element = $schema->findElement('enumeration', 'http://www.example.com'); |
30
|
|
|
$simpleType = $element->getType(); |
31
|
|
|
$restriction = $simpleType->getRestriction(); |
32
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction); |
33
|
|
|
|
34
|
|
|
$expectedChecks = array( |
35
|
|
|
'enumeration' => array( |
36
|
|
|
array( |
37
|
|
|
'value' => 'foo', |
38
|
|
|
'doc' => '', |
39
|
|
|
), |
40
|
|
|
array( |
41
|
|
|
'value' => 'bar', |
42
|
|
|
'doc' => '', |
43
|
|
|
), |
44
|
|
|
), |
45
|
|
|
); |
46
|
|
|
$this->assertEquals($expectedChecks, $restriction->getChecks()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Test the correct detection a pattern-restriction. |
51
|
|
|
*/ |
52
|
|
|
public function testRestriction_2() |
53
|
|
|
{ |
54
|
|
|
$schema = $this->reader->readString( |
55
|
|
|
' |
56
|
|
|
<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
57
|
|
|
|
58
|
|
|
<xs:element name="pattern"> |
59
|
|
|
<xs:simpleType> |
60
|
|
|
<xs:restriction base="xs:string"> |
61
|
|
|
<xs:pattern value="[a-zA-Z0-9]"/> |
62
|
|
|
</xs:restriction> |
63
|
|
|
</xs:simpleType> |
64
|
|
|
</xs:element> |
65
|
|
|
|
66
|
|
|
</xs:schema>'); |
67
|
|
|
|
68
|
|
|
$element = $schema->findElement('pattern', 'http://www.example.com'); |
69
|
|
|
$simpleType = $element->getType(); |
70
|
|
|
$restriction = $simpleType->getRestriction(); |
71
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction); |
72
|
|
|
|
73
|
|
|
$expectedChecks = array( |
74
|
|
|
'pattern' => array( |
75
|
|
|
array( |
76
|
|
|
'value' => '[a-zA-Z0-9]', |
77
|
|
|
'doc' => '', |
78
|
|
|
), |
79
|
|
|
), |
80
|
|
|
); |
81
|
|
|
$this->assertEquals($expectedChecks, $restriction->getChecks()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Test the correct detection a length-restriction. |
86
|
|
|
*/ |
87
|
|
|
public function testRestriction_3() |
88
|
|
|
{ |
89
|
|
|
$schema = $this->reader->readString( |
90
|
|
|
' |
91
|
|
|
<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
92
|
|
|
|
93
|
|
|
<xs:element name="length"> |
94
|
|
|
<xs:simpleType> |
95
|
|
|
<xs:restriction base="xs:string"> |
96
|
|
|
<xs:length value="10"/> |
97
|
|
|
</xs:restriction> |
98
|
|
|
</xs:simpleType> |
99
|
|
|
</xs:element> |
100
|
|
|
|
101
|
|
|
</xs:schema>'); |
102
|
|
|
|
103
|
|
|
$element = $schema->findElement('length', 'http://www.example.com'); |
104
|
|
|
$simpleType = $element->getType(); |
105
|
|
|
$restriction = $simpleType->getRestriction(); |
106
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction); |
107
|
|
|
|
108
|
|
|
$expectedChecks = array( |
109
|
|
|
'length' => array( |
110
|
|
|
array( |
111
|
|
|
'value' => '10', |
112
|
|
|
'doc' => '', |
113
|
|
|
), |
114
|
|
|
), |
115
|
|
|
); |
116
|
|
|
$this->assertEquals($expectedChecks, $restriction->getChecks()); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Test the correct detection a minLength- and maxLength-restriction. |
121
|
|
|
*/ |
122
|
|
|
public function testRestriction_4() |
123
|
|
|
{ |
124
|
|
|
$schema = $this->reader->readString( |
125
|
|
|
' |
126
|
|
|
<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
127
|
|
|
|
128
|
|
|
<xs:element name="minMaxLength"> |
129
|
|
|
<xs:simpleType> |
130
|
|
|
<xs:restriction base="xs:string"> |
131
|
|
|
<xs:minLength value="5"/> |
132
|
|
|
<xs:maxLength value="8"/> |
133
|
|
|
</xs:restriction> |
134
|
|
|
</xs:simpleType> |
135
|
|
|
</xs:element> |
136
|
|
|
|
137
|
|
|
</xs:schema>'); |
138
|
|
|
|
139
|
|
|
$element = $schema->findElement('minMaxLength', 'http://www.example.com'); |
140
|
|
|
$simpleType = $element->getType(); |
141
|
|
|
$restriction = $simpleType->getRestriction(); |
142
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction); |
143
|
|
|
|
144
|
|
|
$expectedChecks = array( |
145
|
|
|
'minLength' => array( |
146
|
|
|
array( |
147
|
|
|
'value' => '5', |
148
|
|
|
'doc' => '', |
149
|
|
|
), |
150
|
|
|
), |
151
|
|
|
'maxLength' => array( |
152
|
|
|
array( |
153
|
|
|
'value' => '8', |
154
|
|
|
'doc' => '', |
155
|
|
|
), |
156
|
|
|
), |
157
|
|
|
); |
158
|
|
|
$this->assertEquals($expectedChecks, $restriction->getChecks()); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Test the correct detection a minInclusive- and maxInclusive-restriction. |
163
|
|
|
*/ |
164
|
|
|
public function testRestriction_5() |
165
|
|
|
{ |
166
|
|
|
$schema = $this->reader->readString( |
167
|
|
|
' |
168
|
|
|
<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
169
|
|
|
|
170
|
|
|
<xs:element name="minMaxInclusive"> |
171
|
|
|
<xs:simpleType> |
172
|
|
|
<xs:restriction base="xs:integer"> |
173
|
|
|
<xs:minInclusive value="1"/> |
174
|
|
|
<xs:maxInclusive value="10"/> |
175
|
|
|
</xs:restriction> |
176
|
|
|
</xs:simpleType> |
177
|
|
|
</xs:element> |
178
|
|
|
|
179
|
|
|
</xs:schema>'); |
180
|
|
|
|
181
|
|
|
$element = $schema->findElement('minMaxInclusive', 'http://www.example.com'); |
182
|
|
|
$simpleType = $element->getType(); |
183
|
|
|
$restriction = $simpleType->getRestriction(); |
184
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction); |
185
|
|
|
|
186
|
|
|
$expectedChecks = array( |
187
|
|
|
'minInclusive' => array( |
188
|
|
|
array( |
189
|
|
|
'value' => '1', |
190
|
|
|
'doc' => '', |
191
|
|
|
), |
192
|
|
|
), |
193
|
|
|
'maxInclusive' => array( |
194
|
|
|
array( |
195
|
|
|
'value' => '10', |
196
|
|
|
'doc' => '', |
197
|
|
|
), |
198
|
|
|
), |
199
|
|
|
); |
200
|
|
|
$this->assertEquals($expectedChecks, $restriction->getChecks()); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Test the correct detection a minExclusive- and maxExclusive-restriction. |
205
|
|
|
*/ |
206
|
|
|
public function testRestriction_6() |
207
|
|
|
{ |
208
|
|
|
$schema = $this->reader->readString( |
209
|
|
|
' |
210
|
|
|
<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
211
|
|
|
|
212
|
|
|
<xs:element name="minMaxExclusive"> |
213
|
|
|
<xs:simpleType> |
214
|
|
|
<xs:restriction base="xs:integer"> |
215
|
|
|
<xs:minExclusive value="1"/> |
216
|
|
|
<xs:maxExclusive value="10"/> |
217
|
|
|
</xs:restriction> |
218
|
|
|
</xs:simpleType> |
219
|
|
|
</xs:element> |
220
|
|
|
|
221
|
|
|
</xs:schema>'); |
222
|
|
|
|
223
|
|
|
$element = $schema->findElement('minMaxExclusive', 'http://www.example.com'); |
224
|
|
|
$simpleType = $element->getType(); |
225
|
|
|
$restriction = $simpleType->getRestriction(); |
226
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction); |
227
|
|
|
|
228
|
|
|
$expectedChecks = array( |
229
|
|
|
'minExclusive' => array( |
230
|
|
|
array( |
231
|
|
|
'value' => '1', |
232
|
|
|
'doc' => '', |
233
|
|
|
), |
234
|
|
|
), |
235
|
|
|
'maxExclusive' => array( |
236
|
|
|
array( |
237
|
|
|
'value' => '10', |
238
|
|
|
'doc' => '', |
239
|
|
|
), |
240
|
|
|
), |
241
|
|
|
); |
242
|
|
|
$this->assertEquals($expectedChecks, $restriction->getChecks()); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* Test the correct detection a fractionDigits-restriction. |
247
|
|
|
*/ |
248
|
|
|
public function testRestriction_7() |
249
|
|
|
{ |
250
|
|
|
$schema = $this->reader->readString( |
251
|
|
|
' |
252
|
|
|
<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
253
|
|
|
|
254
|
|
|
<xs:element name="fractionDigits"> |
255
|
|
|
<xs:simpleType> |
256
|
|
|
<xs:restriction base="xs:decimal"> |
257
|
|
|
<xs:fractionDigits value="2"/> |
258
|
|
|
</xs:restriction> |
259
|
|
|
</xs:simpleType> |
260
|
|
|
</xs:element> |
261
|
|
|
|
262
|
|
|
</xs:schema>'); |
263
|
|
|
|
264
|
|
|
$element = $schema->findElement('fractionDigits', 'http://www.example.com'); |
265
|
|
|
$simpleType = $element->getType(); |
266
|
|
|
$restriction = $simpleType->getRestriction(); |
267
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction); |
268
|
|
|
|
269
|
|
|
$expectedChecks = array( |
270
|
|
|
'fractionDigits' => array( |
271
|
|
|
array( |
272
|
|
|
'value' => '2', |
273
|
|
|
'doc' => '', |
274
|
|
|
), |
275
|
|
|
), |
276
|
|
|
); |
277
|
|
|
$this->assertEquals($expectedChecks, $restriction->getChecks()); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Test the correct detection a totalDigits-restriction. |
282
|
|
|
*/ |
283
|
|
|
public function testRestriction_8() |
284
|
|
|
{ |
285
|
|
|
$schema = $this->reader->readString( |
286
|
|
|
' |
287
|
|
|
<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
288
|
|
|
|
289
|
|
|
<xs:element name="totalDigits"> |
290
|
|
|
<xs:simpleType> |
291
|
|
|
<xs:restriction base="xs:decimal"> |
292
|
|
|
<xs:totalDigits value="4"/> |
293
|
|
|
</xs:restriction> |
294
|
|
|
</xs:simpleType> |
295
|
|
|
</xs:element> |
296
|
|
|
|
297
|
|
|
</xs:schema>'); |
298
|
|
|
|
299
|
|
|
$element = $schema->findElement('totalDigits', 'http://www.example.com'); |
300
|
|
|
$simpleType = $element->getType(); |
301
|
|
|
$restriction = $simpleType->getRestriction(); |
302
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction); |
303
|
|
|
|
304
|
|
|
$expectedChecks = array( |
305
|
|
|
'totalDigits' => array( |
306
|
|
|
array( |
307
|
|
|
'value' => '4', |
308
|
|
|
'doc' => '', |
309
|
|
|
), |
310
|
|
|
), |
311
|
|
|
); |
312
|
|
|
$this->assertEquals($expectedChecks, $restriction->getChecks()); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Test the correct detection a totalDigits- and fractionDigits-restriction. |
317
|
|
|
*/ |
318
|
|
|
public function testRestriction_9() |
319
|
|
|
{ |
320
|
|
|
$schema = $this->reader->readString( |
321
|
|
|
' |
322
|
|
|
<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
323
|
|
|
|
324
|
|
|
<xs:element name="totalFractionDigits"> |
325
|
|
|
<xs:simpleType> |
326
|
|
|
<xs:restriction base="xs:decimal"> |
327
|
|
|
<xs:totalDigits value="4"/> |
328
|
|
|
<xs:fractionDigits value="2"/> |
329
|
|
|
</xs:restriction> |
330
|
|
|
</xs:simpleType> |
331
|
|
|
</xs:element> |
332
|
|
|
|
333
|
|
|
</xs:schema>'); |
334
|
|
|
|
335
|
|
|
$element = $schema->findElement('totalFractionDigits', 'http://www.example.com'); |
336
|
|
|
$simpleType = $element->getType(); |
337
|
|
|
$restriction = $simpleType->getRestriction(); |
338
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction); |
339
|
|
|
|
340
|
|
|
$expectedChecks = array( |
341
|
|
|
'totalDigits' => array( |
342
|
|
|
array( |
343
|
|
|
'value' => '4', |
344
|
|
|
'doc' => '', |
345
|
|
|
), |
346
|
|
|
), |
347
|
|
|
'fractionDigits' => array( |
348
|
|
|
array( |
349
|
|
|
'value' => '2', |
350
|
|
|
'doc' => '', |
351
|
|
|
), |
352
|
|
|
), |
353
|
|
|
); |
354
|
|
|
$this->assertEquals($expectedChecks, $restriction->getChecks()); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Test the correct detection a whiteSpace-restriction. |
359
|
|
|
*/ |
360
|
|
|
public function testRestriction_10() |
361
|
|
|
{ |
362
|
|
|
$schema = $this->reader->readString( |
363
|
|
|
' |
364
|
|
|
<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
365
|
|
|
|
366
|
|
|
<xs:element name="whiteSpace"> |
367
|
|
|
<xs:simpleType> |
368
|
|
|
<xs:restriction base="xs:string"> |
369
|
|
|
<xs:whiteSpace value="replace"/> |
370
|
|
|
</xs:restriction> |
371
|
|
|
</xs:simpleType> |
372
|
|
|
</xs:element> |
373
|
|
|
|
374
|
|
|
</xs:schema>'); |
375
|
|
|
|
376
|
|
|
$element = $schema->findElement('whiteSpace', 'http://www.example.com'); |
377
|
|
|
$simpleType = $element->getType(); |
378
|
|
|
$restriction = $simpleType->getRestriction(); |
379
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction); |
380
|
|
|
|
381
|
|
|
$expectedChecks = array( |
382
|
|
|
'whiteSpace' => array( |
383
|
|
|
array( |
384
|
|
|
'value' => 'replace', |
385
|
|
|
'doc' => '', |
386
|
|
|
), |
387
|
|
|
), |
388
|
|
|
); |
389
|
|
|
$this->assertEquals($expectedChecks, $restriction->getChecks()); |
390
|
|
|
} |
391
|
|
|
} |
392
|
|
|
|