Skip to content

Commit 472ea58

Browse files
committed
added additional tests for redefine
cover the case when file has not been loaded yet
1 parent 00d8ba0 commit 472ea58

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

tests/RedefineTest.php

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace GoetasWebservices\XML\XSDReader\Tests;
33

4+
use GoetasWebservices\XML\XSDReader\Schema\Schema;
5+
46
class RedefineTest extends BaseTest
57
{
68
public function testBase()
@@ -54,7 +56,7 @@ public function testBase()
5456
/* @var $type \GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType */
5557
$type = $localAttr->getType();
5658

57-
$this->assertInstanceOf('\GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType', $type);
59+
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType::class, $type);
5860

5961
$children = array();
6062
foreach($type->getElements() as $element){
@@ -63,4 +65,32 @@ public function testBase()
6365

6466
$this->assertContains('generation', $children);
6567
}
68+
69+
public function testReadSchemaLocation()
70+
{
71+
$schema = $this->reader->readFile(__DIR__ . '/schema/extend-components.xsd');
72+
$this->assertInstanceOf(Schema::class, $schema);
73+
74+
$this->assertEquals('spec:example:xsd:CommonBasicComponents-1.0', $schema->getTargetNamespace());
75+
76+
// defined in /schema/base-components.xsd
77+
$dateElement = $schema->findElement("Date", 'spec:example:xsd:CommonBasicComponents-1.0');
78+
$this->assertNotNull($dateElement);
79+
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef::class, $dateElement);
80+
$type = $dateElement->getType();
81+
$this->assertEquals('DateType', $type->getName());
82+
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType::class, $type);
83+
84+
$dateType = $schema->findType("DateType", 'spec:example:xsd:CommonBasicComponents-1.0');
85+
$this->assertNotNull($dateType);
86+
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType::class, $dateType);
87+
88+
// defined in /schema/extend-components.xsd
89+
$deliveryDateElement = $schema->findElement("DeliveryDate", 'spec:example:xsd:CommonBasicComponents-1.0');
90+
$this->assertNotNull($deliveryDateElement);
91+
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef::class, $deliveryDateElement);
92+
$type = $deliveryDateElement->getType();
93+
$this->assertEquals('DateType', $type->getName());
94+
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType::class, $type);
95+
}
6696
}

tests/schema/base-components.xsd

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3+
xmlns="spec:example:xsd:CommonBasicComponents-1.0"
4+
targetNamespace="spec:example:xsd:CommonBasicComponents-1.0"
5+
elementFormDefault="qualified"
6+
attributeFormDefault="unqualified">
7+
<xsd:element name="Date" type="DateType"/>
8+
<xsd:element name="Indicator" type="IndicatorType"/>
9+
10+
<xsd:complexType name="DateType">
11+
</xsd:complexType>
12+
<xsd:complexType name="IndicatorType">
13+
</xsd:complexType>
14+
15+
</xsd:schema>

tests/schema/extend-components.xsd

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="iso-8859-1" ?>
2+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3+
xmlns="spec:example:xsd:CommonBasicComponents-1.0"
4+
targetNamespace="spec:example:xsd:CommonBasicComponents-1.0"
5+
elementFormDefault="qualified"
6+
attributeFormDefault="unqualified">
7+
8+
<xsd:redefine schemaLocation="base-components.xsd">
9+
</xsd:redefine>
10+
11+
<xsd:element name="DeliveryDate" type="DateType">
12+
<xsd:annotation><xsd:documentation>Lieferdatum</xsd:documentation>
13+
</xsd:annotation>
14+
</xsd:element>
15+
<xsd:element name="BacklogIndicator" type="IndicatorType">
16+
<xsd:annotation><xsd:documentation>Indikator</xsd:documentation>
17+
</xsd:annotation>
18+
</xsd:element>
19+
</xsd:schema>

0 commit comments

Comments
 (0)