|
| 1 | +<?php |
| 2 | +namespace GoetasWebservices\XML\XSDReader\Tests; |
| 3 | + |
| 4 | +class RedefineTest extends BaseTest |
| 5 | +{ |
| 6 | + public function testBase() |
| 7 | + { |
| 8 | + $remoteSchema = $this->reader->readString( |
| 9 | + ' |
| 10 | + <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
| 11 | + <xs:complexType name="personName"> |
| 12 | + <xs:sequence> |
| 13 | + <xs:element name="title" minOccurs="0"/> |
| 14 | + <xs:element name="forename" minOccurs="0" maxOccurs="unbounded"/> |
| 15 | + </xs:sequence> |
| 16 | + </xs:complexType> |
| 17 | +
|
| 18 | + <xs:element name="addressee" type="personName"/> |
| 19 | + </xs:schema>', 'http://www.example.com/xsd.xsd'); |
| 20 | + |
| 21 | + |
| 22 | + $schema = $this->reader->readString( |
| 23 | + ' |
| 24 | + <xs:schema targetNamespace="http://www.user.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ex="http://www.example.com"> |
| 25 | + <xs:redefine schemaLocation="http://www.example.com/xsd.xsd"> |
| 26 | + <xs:complexType name="personName"> |
| 27 | + <xs:complexContent> |
| 28 | + <xs:extension base="personName"> |
| 29 | + <xs:sequence> |
| 30 | + <xs:element name="generation" minOccurs="0"/> |
| 31 | + </xs:sequence> |
| 32 | + </xs:extension> |
| 33 | + </xs:complexContent> |
| 34 | + </xs:complexType> |
| 35 | + </xs:redefine> |
| 36 | +
|
| 37 | + <xs:element name="author" type="personName"/> |
| 38 | + </xs:schema>'); |
| 39 | + |
| 40 | + // check if schema is not included |
| 41 | + // we don't want to redefine original schema |
| 42 | + $this->assertNotContains($remoteSchema, $schema->getSchemas(), '', true); |
| 43 | + |
| 44 | + /* @var $localAttr \GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef */ |
| 45 | + |
| 46 | + // it should inherit namespace of main schema |
| 47 | + $localAttr = $schema->findElement("addressee", "http://www.user.com"); |
| 48 | + $this->assertNotNull($localAttr); |
| 49 | + |
| 50 | + // find author element |
| 51 | + $localAttr = $schema->findElement("author", "http://www.user.com"); |
| 52 | + $this->assertNotNull($localAttr); |
| 53 | + |
| 54 | + /* @var $type \GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType */ |
| 55 | + $type = $localAttr->getType(); |
| 56 | + |
| 57 | + $this->assertInstanceOf('\GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType', $type); |
| 58 | + |
| 59 | + $children = array(); |
| 60 | + foreach($type->getElements() as $element){ |
| 61 | + $children[] = $element->getName(); |
| 62 | + } |
| 63 | + |
| 64 | + $this->assertContains('generation', $children); |
| 65 | + } |
| 66 | +} |
0 commit comments