1
|
|
|
<?php |
2
|
|
|
namespace GoetasWebservices\XML\XSDReader\Tests; |
3
|
|
|
|
4
|
|
|
class ElementsTest extends BaseTest |
5
|
|
|
{ |
6
|
|
|
|
7
|
|
|
public function testBase() |
8
|
|
|
{ |
9
|
|
|
$schema = $this->reader->readString( |
10
|
|
|
' |
11
|
|
|
<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
12
|
|
|
<xs:element name="myElement" type="xs:string"></xs:element> |
13
|
|
|
|
14
|
|
|
<xs:element name="myElementAnonType"> |
15
|
|
|
<xs:simpleType> |
16
|
|
|
<xs:restriction base="xs:string"></xs:restriction> |
17
|
|
|
</xs:simpleType> |
18
|
|
|
</xs:element> |
19
|
|
|
|
20
|
|
|
<xs:group name="myGroup"> |
21
|
|
|
<xs:sequence> |
22
|
|
|
<xs:element name="alone" type="xs:string"></xs:element> |
23
|
|
|
<xs:element ref="ex:myElement"></xs:element> |
24
|
|
|
<xs:group ref="ex:myGroup2"></xs:group> |
25
|
|
|
</xs:sequence> |
26
|
|
|
</xs:group> |
27
|
|
|
|
28
|
|
|
<xs:group name="myGroup2"> |
29
|
|
|
<xs:element name="alone2" type="xs:string"></xs:element> |
30
|
|
|
</xs:group> |
31
|
|
|
</xs:schema>'); |
32
|
|
|
|
33
|
|
|
$myElement = $schema->findElement('myElement', 'http://www.example.com'); |
34
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef', $myElement); |
35
|
|
|
//$this->assertEquals('http://www.example.com', $myElement->getSchema()->getTargetNamespace()); |
|
|
|
|
36
|
|
|
$this->assertEquals('myElement', $myElement->getName()); |
37
|
|
|
$this->assertEquals("string", $myElement->getType()->getName()); |
38
|
|
|
|
39
|
|
|
$myGroup = $schema->findGroup('myGroup', 'http://www.example.com'); |
40
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Element\Group', $myGroup); |
41
|
|
|
//$this->assertEquals('http://www.example.com', $myElement->getSchema()->getTargetNamespace()); |
|
|
|
|
42
|
|
|
$this->assertEquals('myGroup', $myGroup->getName()); |
43
|
|
|
$elementsInGroup = $myGroup->getElements(); |
44
|
|
|
$this->assertCount(3, $elementsInGroup); |
45
|
|
|
|
46
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Element\Element', $elementsInGroup[0]); |
47
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Element\ElementItem', $elementsInGroup[1]); |
48
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Element\Group', $elementsInGroup[2]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
View Code Duplication |
public function testAnonym() |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$schema = $this->reader->readString( |
54
|
|
|
' |
55
|
|
|
<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
56
|
|
|
<xs:element name="myElement" type="xs:string"></xs:element> |
57
|
|
|
|
58
|
|
|
<xs:element name="myElementAnonType"> |
59
|
|
|
<xs:simpleType> |
60
|
|
|
<xs:restriction base="xs:string"></xs:restriction> |
61
|
|
|
</xs:simpleType> |
62
|
|
|
</xs:element> |
63
|
|
|
|
64
|
|
|
</xs:schema>'); |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
$myElementAnon = $schema->findElement('myElementAnonType', 'http://www.example.com'); |
68
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef', $myElementAnon); |
69
|
|
|
//$this->assertEquals('http://www.example.com', $myElement->getSchema()->getTargetNamespace()); |
|
|
|
|
70
|
|
|
$this->assertEquals('myElementAnonType', $myElementAnon->getName()); |
71
|
|
|
$this->assertNull($myElementAnon->getType()->getName()); |
72
|
|
|
|
73
|
|
|
$base2 = $myElementAnon->getType(); |
74
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $base2); |
75
|
|
|
$this->assertEquals('http://www.example.com', $base2->getSchema()->getTargetNamespace()); |
76
|
|
|
$this->assertTrue(!$base2->getName()); |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
$restriction1 = $base2->getRestriction(); |
80
|
|
|
$base3 = $restriction1->getBase(); |
81
|
|
|
$this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $base3); |
82
|
|
|
$this->assertEquals('http://www.w3.org/2001/XMLSchema', $base3->getSchema()->getTargetNamespace()); |
83
|
|
|
$this->assertEquals('string', $base3->getName()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.