Skip to content

Commit 2a17126

Browse files
committed
[Routing] Added XmlFileLoader tests for valid resource and pattern routing definitions.
1 parent 6235f42 commit 2a17126

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<routes xmlns="http://symfony.com/schema/routing"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
6+
7+
<route id="blog_show" pattern="/blog/{slug}">
8+
<default key="_controller">MyBundle:Blog:show</default>
9+
<requirement key="_method">GET</requirement>
10+
<option key="segment_separators">/</option>
11+
</route>
12+
</routes>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<routes xmlns="http://symfony.com/schema/routing"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
6+
7+
<import resource="validpattern.xml" />
8+
</routes>

tests/Symfony/Tests/Component/Routing/Loader/XmlFileLoaderTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Tests\Component\Routing\Loader;
1313

1414
use Symfony\Component\Config\Loader\LoaderResolver;
15+
use Symfony\Component\Config\FileLocator;
1516
use Symfony\Component\Routing\Loader\XmlFileLoader;
1617
use Symfony\Component\Routing\Route;
1718
use Symfony\Component\Routing\RouteCollection;
@@ -31,4 +32,25 @@ public function testSupports()
3132
$this->assertTrue($loader->supports('foo.xml', 'xml'), '->supports() checks the resource type if specified');
3233
$this->assertFalse($loader->supports('foo.xml', 'foo'), '->supports() checks the resource type if specified');
3334
}
35+
36+
public function testLoadWithRoute()
37+
{
38+
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
39+
$routeCollection = $loader->load('validpattern.xml');
40+
$routes = $routeCollection->all();
41+
42+
$this->assertEquals(1, count($routes), 'One route is loaded');
43+
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
44+
}
45+
46+
public function testLoadWithImport()
47+
{
48+
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
49+
$routeCollection = $loader->load('validresource.xml');
50+
$routes = $routeCollection->all();
51+
52+
$this->assertEquals(1, count($routes), 'One route is loaded');
53+
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
54+
}
3455
}
56+

0 commit comments

Comments
 (0)