Bläddra i källkod

[Routing] Added XmlFileLoader tests handling invalid xml files when schema validation is not used.

Jakub Zalas 14 år sedan
förälder
incheckning
14b7f12349

+ 12 - 0
tests/Symfony/Tests/Component/Routing/Fixtures/nonvalid.xml

@@ -0,0 +1,12 @@
+<?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="blog_show" pattern="/blog/{slug}">
+        <default key="_controller">MyBundle:Blog:show</default>
+		<requirement key="_method">GET</requirement>
+		<option key="segment_separators">/</option>
+	<!-- </route> -->
+</routes>

+ 8 - 0
tests/Symfony/Tests/Component/Routing/Fixtures/nonvalidnode.xml

@@ -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">
+
+	<foo>bar</foo>
+</routes>

+ 13 - 0
tests/Symfony/Tests/Component/Routing/Fixtures/nonvalidroute.xml

@@ -0,0 +1,13 @@
+<?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="blog_show" pattern="/blog/{slug}">
+        <default key="_controller">MyBundle:Blog:show</default>
+		<requirement key="_method">GET</requirement>
+		<option key="segment_separators">/</option>
+		<foo key="bar">baz</foo>
+    </route>
+</routes>

+ 26 - 0
tests/Symfony/Tests/Component/Routing/Loader/XmlFileLoaderTest.php

@@ -52,5 +52,31 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals(1, count($routes), 'One route is loaded');
         $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
     }
+
+    /**
+     * @expectedException \InvalidArgumentException
+     * @dataProvider getPathsToInvalidFiles
+     */
+    public function testLoadThrowsExceptionWithInvalidFile($filePath)
+    {
+        $loader = new CustomXmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
+        $loader->load($filePath);
+    }
+
+    public function getPathsToInvalidFiles()
+    {
+        return array(array('nonvalidnode.xml'), array('nonvalidroute.xml'), array('nonvalid.xml'));
+    }
+}
+
+/**
+ * XmlFileLoader with schema validation turned off
+ */
+class CustomXmlFileLoader extends XmlFileLoader
+{
+    protected function validate(\DOMDocument $dom)
+    {
+        return true;
+    }
 }