diff --git a/README.md b/README.md
index 935e14a4..1b322ada 100644
--- a/README.md
+++ b/README.md
@@ -33,16 +33,16 @@ Getting started
---------------
```php
-use Goetas\XML\XSDReader\SchemaReader;
+use GoetasWebservices\XML\XSDReader\SchemaReader;
$reader = new SchemaReader();
$schema = $reader->readFile("http://www.example.com/exaple.xsd");
-// $schema is instance of Goetas\XML\XSDReader\Schema\Schema;
+// $schema is instance of GoetasWebservices\XML\XSDReader\Schema\Schema;
// Now you can navigate the entire schema structure
-foreach ($schema->getSchema() as $innerSchema){
+foreach ($schema->getSchemas() as $innerSchema){
}
foreach ($schema->getTypes() as $type){
@@ -67,5 +67,5 @@ foreach ($schema->getAttributeGroups() as $attrGroup){
Note
----
-I'm sorry for the *terrible* english fluency used inside the documentation, I'm trying to improve it.
+I'm sorry for the *terrible* english fluency used inside the documentation, I'm trying to improve it.
Pull Requests are welcome.
diff --git a/src/SchemaReader.php b/src/SchemaReader.php
index c26e2a73..ede04e96 100644
--- a/src/SchemaReader.php
+++ b/src/SchemaReader.php
@@ -532,10 +532,10 @@ private function loadRestriction(Type $type, DOMElement $node)
'length',
'minLength',
'maxLength',
- 'minInclusve',
- 'maxInclusve',
- 'minExclusve',
- 'maxEXclusve'
+ 'minInclusive',
+ 'maxInclusive',
+ 'minExclusive',
+ 'maxExclusive'
], true)) {
$restriction->addCheck($childNode->localName,
[
@@ -555,7 +555,7 @@ private static function splitParts(DOMElement $node, $typeName)
list ($prefix, $name) = explode(':', $typeName);
}
- $namespace = $node->lookupNamespaceURI($prefix);
+ $namespace = $node->lookupNamespaceURI($prefix ?: null);
return array(
$name,
$namespace,
@@ -633,7 +633,8 @@ private function fillItem(Item $element, DOMElement $node)
private function loadImport(Schema $schema, DOMElement $node)
{
- $file = UrlUtils::resolveRelativeUrl($node->ownerDocument->documentURI, $node->getAttribute("schemaLocation"));
+ $base = urldecode($node->ownerDocument->documentURI);
+ $file = UrlUtils::resolveRelativeUrl($base, $node->getAttribute("schemaLocation"));
if ($node->hasAttribute("namespace")
&& isset(self::$globalSchemaInfo[$node->getAttribute("namespace")])
&& isset($this->loadedFiles[self::$globalSchemaInfo[$node->getAttribute("namespace")]])
diff --git a/tests/FilesystemTest.php b/tests/FilesystemTest.php
new file mode 100644
index 00000000..eba23b56
--- /dev/null
+++ b/tests/FilesystemTest.php
@@ -0,0 +1,27 @@
+reader->readFile($schemaXsd);
+
+ $this->assertCount(1, $schema->getTypes());
+ $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType', $schema->findType('myType', 'http://www.example.com'));
+ }
+
+}
\ No newline at end of file
diff --git a/tests/RestrictionsTest.php b/tests/RestrictionsTest.php
new file mode 100644
index 00000000..40b9ae2f
--- /dev/null
+++ b/tests/RestrictionsTest.php
@@ -0,0 +1,244 @@
+reader->readString(
+ '
+
+
+
+
+
+
+
+
+
+
+
+ ');
+
+ $element = $schema->findElement('enumeration', 'http://www.example.com');
+ $simpleType = $element->getType();
+ $restriction = $simpleType->getRestriction();
+ $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction);
+
+ $expectedChecks = array(
+ 'enumeration' => array(
+ array(
+ 'value' => 'foo',
+ 'doc' => '',
+ ),
+ array(
+ 'value' => 'bar',
+ 'doc' => '',
+ ),
+ ),
+ );
+ $this->assertEquals($expectedChecks, $restriction->getChecks());
+ }
+
+ /**
+ * Test the correct detection a pattern-restriction.
+ */
+ public function testRestriction_2()
+ {
+ $schema = $this->reader->readString(
+ '
+
+
+
+
+
+
+
+
+
+
+ ');
+
+ $element = $schema->findElement('pattern', 'http://www.example.com');
+ $simpleType = $element->getType();
+ $restriction = $simpleType->getRestriction();
+ $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction);
+
+ $expectedChecks = array(
+ 'pattern' => array(
+ array(
+ 'value' => '[a-zA-Z0-9]',
+ 'doc' => '',
+ ),
+ ),
+ );
+ $this->assertEquals($expectedChecks, $restriction->getChecks());
+ }
+
+ /**
+ * Test the correct detection a length-restriction.
+ */
+ public function testRestriction_3()
+ {
+ $schema = $this->reader->readString(
+ '
+
+
+
+
+
+
+
+
+
+
+ ');
+
+ $element = $schema->findElement('length', 'http://www.example.com');
+ $simpleType = $element->getType();
+ $restriction = $simpleType->getRestriction();
+ $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction);
+
+ $expectedChecks = array(
+ 'length' => array(
+ array(
+ 'value' => '10',
+ 'doc' => '',
+ ),
+ ),
+ );
+ $this->assertEquals($expectedChecks, $restriction->getChecks());
+ }
+
+ /**
+ * Test the correct detection a minLength- and maxLength-restriction.
+ */
+ public function testRestriction_4()
+ {
+ $schema = $this->reader->readString(
+ '
+
+
+
+
+
+
+
+
+
+
+
+ ');
+
+ $element = $schema->findElement('minMaxLength', 'http://www.example.com');
+ $simpleType = $element->getType();
+ $restriction = $simpleType->getRestriction();
+ $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction);
+
+ $expectedChecks = array(
+ 'minLength' => array(
+ array(
+ 'value' => '5',
+ 'doc' => '',
+ ),
+ ),
+ 'maxLength' => array(
+ array(
+ 'value' => '8',
+ 'doc' => '',
+ ),
+ ),
+ );
+ $this->assertEquals($expectedChecks, $restriction->getChecks());
+ }
+
+ /**
+ * Test the correct detection a minInclusive- and maxInclusive-restriction.
+ */
+ public function testRestriction_5()
+ {
+ $schema = $this->reader->readString(
+ '
+
+
+
+
+
+
+
+
+
+
+
+ ');
+
+ $element = $schema->findElement('minMaxInclusive', 'http://www.example.com');
+ $simpleType = $element->getType();
+ $restriction = $simpleType->getRestriction();
+ $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction);
+
+ $expectedChecks = array(
+ 'minInclusive' => array(
+ array(
+ 'value' => '1',
+ 'doc' => '',
+ ),
+ ),
+ 'maxInclusive' => array(
+ array(
+ 'value' => '10',
+ 'doc' => '',
+ ),
+ ),
+ );
+ $this->assertEquals($expectedChecks, $restriction->getChecks());
+ }
+
+ /**
+ * Test the correct detection a minExclusive- and maxExclusive-restriction.
+ */
+ public function testRestriction_6()
+ {
+ $schema = $this->reader->readString(
+ '
+
+
+
+
+
+
+
+
+
+
+
+ ');
+
+ $element = $schema->findElement('minMaxExclusive', 'http://www.example.com');
+ $simpleType = $element->getType();
+ $restriction = $simpleType->getRestriction();
+ $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction', $restriction);
+
+ $expectedChecks = array(
+ 'minExclusive' => array(
+ array(
+ 'value' => '1',
+ 'doc' => '',
+ ),
+ ),
+ 'maxExclusive' => array(
+ array(
+ 'value' => '10',
+ 'doc' => '',
+ ),
+ ),
+ );
+ $this->assertEquals($expectedChecks, $restriction->getChecks());
+ }
+}
diff --git a/tests/UrlUtilsTest.php b/tests/UrlUtilsTest.php
index 7f523ddd..ab6c6484 100644
--- a/tests/UrlUtilsTest.php
+++ b/tests/UrlUtilsTest.php
@@ -63,6 +63,8 @@ public function testFilePaths()
{
$this->assertEquals('file:///test', UrlUtils::resolveRelativeUrl('file:///', '/test'));
$this->assertEquals('file:///test', UrlUtils::resolveRelativeUrl('file:///', 'test'));
+ /* Assert that any filenames will be stripped from base */
+ $this->assertEquals('file:///bar.xsd', UrlUtils::resolveRelativeUrl('file:///foo.xsd', 'bar.xsd'));
}
@@ -79,4 +81,4 @@ public function testRegularPathsParent()
$this->assertEquals('/testing', UrlUtils::resolveRelativeUrl('/test/child', '../testing'));
}
-}
+}
diff --git a/tests/foo bar/referenced.xsd b/tests/foo bar/referenced.xsd
new file mode 100644
index 00000000..cf6ca250
--- /dev/null
+++ b/tests/foo bar/referenced.xsd
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/foo bar/schema.xsd b/tests/foo bar/schema.xsd
new file mode 100644
index 00000000..700ee8dc
--- /dev/null
+++ b/tests/foo bar/schema.xsd
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/tests/fooz%20baz/referenced.xsd b/tests/fooz%20baz/referenced.xsd
new file mode 100644
index 00000000..cf6ca250
--- /dev/null
+++ b/tests/fooz%20baz/referenced.xsd
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/fooz%20baz/schema.xsd b/tests/fooz%20baz/schema.xsd
new file mode 100644
index 00000000..700ee8dc
--- /dev/null
+++ b/tests/fooz%20baz/schema.xsd
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file