Skip to content

Commit

Permalink
added additional tests for redefine
Browse files Browse the repository at this point in the history
cover the case when file has not been loaded yet
  • Loading branch information
cebe committed Apr 2, 2019
1 parent 00d8ba0 commit 472ea58
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tests/RedefineTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace GoetasWebservices\XML\XSDReader\Tests;

use GoetasWebservices\XML\XSDReader\Schema\Schema;

class RedefineTest extends BaseTest
{
public function testBase()
Expand Down Expand Up @@ -54,7 +56,7 @@ public function testBase()
/* @var $type \GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType */
$type = $localAttr->getType();

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

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

$this->assertContains('generation', $children);
}

public function testReadSchemaLocation()
{
$schema = $this->reader->readFile(__DIR__ . '/schema/extend-components.xsd');
$this->assertInstanceOf(Schema::class, $schema);

$this->assertEquals('spec:example:xsd:CommonBasicComponents-1.0', $schema->getTargetNamespace());

// defined in /schema/base-components.xsd
$dateElement = $schema->findElement("Date", 'spec:example:xsd:CommonBasicComponents-1.0');
$this->assertNotNull($dateElement);
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef::class, $dateElement);
$type = $dateElement->getType();
$this->assertEquals('DateType', $type->getName());
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType::class, $type);

$dateType = $schema->findType("DateType", 'spec:example:xsd:CommonBasicComponents-1.0');
$this->assertNotNull($dateType);
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType::class, $dateType);

// defined in /schema/extend-components.xsd
$deliveryDateElement = $schema->findElement("DeliveryDate", 'spec:example:xsd:CommonBasicComponents-1.0');
$this->assertNotNull($deliveryDateElement);
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef::class, $deliveryDateElement);
$type = $deliveryDateElement->getType();
$this->assertEquals('DateType', $type->getName());
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType::class, $type);
}
}
15 changes: 15 additions & 0 deletions tests/schema/base-components.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="spec:example:xsd:CommonBasicComponents-1.0"
targetNamespace="spec:example:xsd:CommonBasicComponents-1.0"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:element name="Date" type="DateType"/>
<xsd:element name="Indicator" type="IndicatorType"/>

<xsd:complexType name="DateType">
</xsd:complexType>
<xsd:complexType name="IndicatorType">
</xsd:complexType>

</xsd:schema>
19 changes: 19 additions & 0 deletions tests/schema/extend-components.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="spec:example:xsd:CommonBasicComponents-1.0"
targetNamespace="spec:example:xsd:CommonBasicComponents-1.0"
elementFormDefault="qualified"
attributeFormDefault="unqualified">

<xsd:redefine schemaLocation="base-components.xsd">
</xsd:redefine>

<xsd:element name="DeliveryDate" type="DateType">
<xsd:annotation><xsd:documentation>Lieferdatum</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="BacklogIndicator" type="IndicatorType">
<xsd:annotation><xsd:documentation>Indikator</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:schema>

0 comments on commit 472ea58

Please sign in to comment.