Explorar el Código

[Routing] Added XmlFileLoader tests for valid resource and pattern routing definitions.

Jakub Zalas hace 14 años
padre
commit
2a17126309

+ 12 - 0
tests/Symfony/Tests/Component/Routing/Fixtures/validpattern.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/validresource.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">
+
+    <import resource="validpattern.xml" />
+</routes>

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

@@ -12,6 +12,7 @@
 namespace Symfony\Tests\Component\Routing\Loader;
 
 use Symfony\Component\Config\Loader\LoaderResolver;
+use Symfony\Component\Config\FileLocator;
 use Symfony\Component\Routing\Loader\XmlFileLoader;
 use Symfony\Component\Routing\Route;
 use Symfony\Component\Routing\RouteCollection;
@@ -31,4 +32,25 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
         $this->assertTrue($loader->supports('foo.xml', 'xml'), '->supports() checks the resource type if specified');
         $this->assertFalse($loader->supports('foo.xml', 'foo'), '->supports() checks the resource type if specified');
     }
+
+    public function testLoadWithRoute()
+    {
+        $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
+        $routeCollection = $loader->load('validpattern.xml');
+        $routes = $routeCollection->all();
+
+        $this->assertEquals(1, count($routes), 'One route is loaded');
+        $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
+    }
+
+    public function testLoadWithImport()
+    {
+        $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
+        $routeCollection = $loader->load('validresource.xml');
+        $routes = $routeCollection->all();
+
+        $this->assertEquals(1, count($routes), 'One route is loaded');
+        $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
+    }
 }
+