Skip to content

Commit

Permalink
fix bug when imported routes are prefixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ismail1432 committed May 15, 2018
1 parent f59ce97 commit cb5ce8f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Symfony/Component/Routing/RouteCollection.php
Expand Up @@ -162,6 +162,9 @@ public function addNamePrefix(string $prefix)

foreach ($this->routes as $name => $route) {
$prefixedRoutes[$prefix.$name] = $route;
if (null !== $name = $route->getDefault('_canonical_route')) {
$route->setDefault('_canonical_route', $prefix.$name);
}
}

$this->routes = $prefixedRoutes;
Expand Down
13 changes: 13 additions & 0 deletions src/Symfony/Component/Routing/Tests/RouteCollectionTest.php
Expand Up @@ -317,4 +317,17 @@ public function testAddNamePrefix()
$this->assertNull($collection->get('foo'));
$this->assertNull($collection->get('bar'));
}

public function testAddNamePrefixCanonicalRouteName()
{
$collection = new RouteCollection();
$collection->add('foo', new Route('/foo', array('_canonical_route' => 'foo')));
$collection->add('bar', new Route('/bar', array('_canonical_route' => 'bar')));
$collection->add('api_foo', new Route('/api/foo', array('_canonical_route' => 'api_foo')));
$collection->addNamePrefix('api_');

$this->assertEquals('api_foo', $collection->get('api_foo')->getDefault('_canonical_route'));
$this->assertEquals('api_bar', $collection->get('api_bar')->getDefault('_canonical_route'));
$this->assertEquals('api_api_foo', $collection->get('api_api_foo')->getDefault('_canonical_route'));
}
}

0 comments on commit cb5ce8f

Please sign in to comment.