diff --git a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php index 30fc1dac6a..a07c7f80a5 100644 --- a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php @@ -166,7 +166,9 @@ class XmlFileLoader extends FileLoader * * @return \DOMDocument * - * @throws \InvalidArgumentException When loading of XML file returns error + * @throws \InvalidArgumentException When loading of XML file fails because of syntax errors + * or when the XML structure is not as expected by the scheme - + * see validate() */ protected function loadFile($file) { diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/missing_id.xml b/src/Symfony/Component/Routing/Tests/Fixtures/missing_id.xml new file mode 100644 index 0000000000..52719be167 --- /dev/null +++ b/src/Symfony/Component/Routing/Tests/Fixtures/missing_id.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/missing_path.xml b/src/Symfony/Component/Routing/Tests/Fixtures/missing_path.xml new file mode 100644 index 0000000000..a7a8e7b39b --- /dev/null +++ b/src/Symfony/Component/Routing/Tests/Fixtures/missing_path.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/namespaceprefix.xml b/src/Symfony/Component/Routing/Tests/Fixtures/namespaceprefix.xml new file mode 100644 index 0000000000..efc4da9b37 --- /dev/null +++ b/src/Symfony/Component/Routing/Tests/Fixtures/namespaceprefix.xml @@ -0,0 +1,13 @@ + + + + + + MyBundle:Blog:show + \w+ + en|fr|de + RouteCompiler + + diff --git a/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php index 235a9d13af..993a121071 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php @@ -56,6 +56,21 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals('RouteCompiler', $route->getOption('compiler_class')); } + public function testLoadWithNamespacePrefix() + { + $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); + $routeCollection = $loader->load('namespaceprefix.xml'); + + $this->assertCount(1, $routeCollection, 'One route is loaded'); + $route = $routeCollection->get('blog_show'); + $this->assertEquals('/blog/{slug}', $route->getPattern()); + $this->assertEquals('MyBundle:Blog:show', $route->getDefault('_controller')); + $this->assertEquals('\w+', $route->getRequirement('slug')); + $this->assertEquals('en|fr|de', $route->getRequirement('_locale')); + $this->assertEquals('{_locale}.example.com', $route->getHostnamePattern()); + $this->assertEquals('RouteCompiler', $route->getOption('compiler_class')); + } + public function testLoadWithImport() { $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); @@ -94,7 +109,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase public function getPathsToInvalidFiles() { - return array(array('nonvalidnode.xml'), array('nonvalidroute.xml'), array('nonvalid.xml')); + return array(array('nonvalidnode.xml'), array('nonvalidroute.xml'), array('nonvalid.xml'), array('missing_id.xml'), array('missing_path.xml')); } /**