Permalink
Browse files

added tests for the previous XmlFileLoader fixes

  • Loading branch information...
1 parent b20d6a7 commit 45987eb2b7e12a28590ad3de807d68bac65f692c @Tobion Tobion committed Dec 7, 2012
@@ -166,7 +166,9 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, $
*
* @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)
{
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<routes xmlns="http://symfony.com/schema/routing"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
+
+ <route pattern="/test"></route>
+</routes>
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<routes xmlns="http://symfony.com/schema/routing"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
+
+ <route id="myroute"></route>
+</routes>
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<r:routes xmlns:r="http://symfony.com/schema/routing"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
+
+ <r:route id="blog_show" pattern="/blog/{slug}" hostname-pattern="{_locale}.example.com">
+ <r:default key="_controller">MyBundle:Blog:show</r:default>
+ <requirement xmlns="http://symfony.com/schema/routing" key="slug">\w+</requirement>
+ <r2:requirement xmlns:r2="http://symfony.com/schema/routing" key="_locale">en|fr|de</r2:requirement>
+ <r:option key="compiler_class">RouteCompiler</r:option>
+ </r:route>
+</r:routes>
@@ -56,6 +56,21 @@ public function testLoadWithRoute()
$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 @@ public function testLoadThrowsExceptionWithInvalidFileEvenWithoutSchemaValidatio
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'));
}
/**

0 comments on commit 45987eb

Please sign in to comment.