Skip to content

Commit

Permalink
Routing condition bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
mjeri authored and fabpot committed Jan 24, 2014
1 parent 07de761 commit 0a2bb7b
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/Symfony/Component/Routing/Loader/XmlFileLoader.php
Expand Up @@ -167,6 +167,9 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, $
if (null !== $host) {
$subCollection->setHost($host);
}
if (null !== $condition) {
$subCollection->setCondition($condition);
}
if (null !== $schemes) {
$subCollection->setSchemes($schemes);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Routing/Loader/YamlFileLoader.php
Expand Up @@ -146,6 +146,7 @@ protected function parseImport(RouteCollection $collection, array $config, $path
$requirements = isset($config['requirements']) ? $config['requirements'] : array();
$options = isset($config['options']) ? $config['options'] : array();
$host = isset($config['host']) ? $config['host'] : null;
$condition = isset($config['condition']) ? $config['condition'] : null;
$schemes = isset($config['schemes']) ? $config['schemes'] : null;
$methods = isset($config['methods']) ? $config['methods'] : null;

Expand All @@ -157,6 +158,9 @@ protected function parseImport(RouteCollection $collection, array $config, $path
if (null !== $host) {
$subCollection->setHost($host);
}
if (null !== $condition) {
$subCollection->setCondition($condition);
}
if (null !== $schemes) {
$subCollection->setSchemes($schemes);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml
Expand Up @@ -20,4 +20,6 @@
<option key="compiler_class">RouteCompiler</option>
<condition>context.getMethod() == "GET"</condition>
</route>

<route id="blog_show_inherited" path="/blog/{slug}" />
</routes>
3 changes: 3 additions & 0 deletions src/Symfony/Component/Routing/Tests/Fixtures/validpattern.yml
Expand Up @@ -17,3 +17,6 @@ blog_show_legacy:
condition: 'context.getMethod() == "GET"'
options:
compiler_class: RouteCompiler

blog_show_inherited:
path: /blog/{slug}
Expand Up @@ -8,5 +8,6 @@
<default key="foo">123</default>
<requirement key="foo">\d+</requirement>
<option key="foo">bar</option>
<condition>context.getMethod() == "POST"</condition>
</import>
</routes>
Expand Up @@ -5,3 +5,4 @@ _blog:
requirements: { 'foo': '\d+' }
options: { 'foo': 'bar' }
host: ""
condition: 'context.getMethod() == "POST"'
Expand Up @@ -34,10 +34,12 @@ public function testLoadWithRoute()
$routeCollection = $loader->load('validpattern.xml');
$routes = $routeCollection->all();

$this->assertCount(2, $routes, 'Two routes are loaded');
$this->assertCount(3, $routes, 'Three routes are loaded');
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);

foreach ($routes as $route) {
$identicalRoutes = array_slice($routes, 0, 2);

foreach ($identicalRoutes as $route) {
$this->assertSame('/blog/{slug}', $route->getPath());
$this->assertSame('{locale}.example.com', $route->getHost());
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
Expand Down Expand Up @@ -72,7 +74,7 @@ public function testLoadWithImport()
$routeCollection = $loader->load('validresource.xml');
$routes = $routeCollection->all();

$this->assertCount(2, $routes, 'Two routes are loaded');
$this->assertCount(3, $routes, 'Three routes are loaded');
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);

foreach ($routes as $route) {
Expand All @@ -81,6 +83,7 @@ public function testLoadWithImport()
$this->assertSame('\d+', $route->getRequirement('foo'));
$this->assertSame('bar', $route->getOption('foo'));
$this->assertSame('', $route->getHost());
$this->assertSame('context.getMethod() == "POST"', $route->getCondition());
}
}

Expand Down
Expand Up @@ -68,10 +68,12 @@ public function testLoadWithRoute()
$routeCollection = $loader->load('validpattern.yml');
$routes = $routeCollection->all();

$this->assertCount(2, $routes, 'Two routes are loaded');
$this->assertCount(3, $routes, 'Three routes are loaded');
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);

foreach ($routes as $route) {
$identicalRoutes = array_slice($routes, 0, 2);

foreach ($identicalRoutes as $route) {
$this->assertSame('/blog/{slug}', $route->getPath());
$this->assertSame('{locale}.example.com', $route->getHost());
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
Expand All @@ -89,7 +91,7 @@ public function testLoadWithResource()
$routeCollection = $loader->load('validresource.yml');
$routes = $routeCollection->all();

$this->assertCount(2, $routes, 'Two routes are loaded');
$this->assertCount(3, $routes, 'Three routes are loaded');
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);

foreach ($routes as $route) {
Expand All @@ -98,6 +100,8 @@ public function testLoadWithResource()
$this->assertSame('\d+', $route->getRequirement('foo'));
$this->assertSame('bar', $route->getOption('foo'));
$this->assertSame('', $route->getHost());
$this->assertSame('context.getMethod() == "POST"', $route->getCondition());
}
}

}

0 comments on commit 0a2bb7b

Please sign in to comment.