|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony framework. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * This source file is subject to the MIT license that is bundled |
| 9 | + * with this source code in the file LICENSE. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bundle\FrameworkBundle\Tests\Routing; |
| 13 | + |
| 14 | +use Symfony\Bundle\FrameworkBundle\Routing\Router; |
| 15 | +use Symfony\Component\Routing\Route; |
| 16 | +use Symfony\Component\Routing\RouteCollection; |
| 17 | + |
| 18 | +class RoutingTest extends \PHPUnit_Framework_TestCase |
| 19 | +{ |
| 20 | + public function testPlaceholders() |
| 21 | + { |
| 22 | + $routes = new RouteCollection(); |
| 23 | + $routes->add('foo', new Route('/foo', array( |
| 24 | + 'foo' => '%foo%', |
| 25 | + 'bar' => '%bar%', |
| 26 | + 'foobar' => 'foobar', |
| 27 | + 'foo1' => '%foo', |
| 28 | + 'foo2' => 'foo%', |
| 29 | + 'foo3' => 'f%o%o', |
| 30 | + ))); |
| 31 | + |
| 32 | + $sc = $this->getServiceContainer($routes); |
| 33 | + $sc |
| 34 | + ->expects($this->at(1)) |
| 35 | + ->method('hasParameter') |
| 36 | + ->will($this->returnValue(false)) |
| 37 | + ; |
| 38 | + $sc |
| 39 | + ->expects($this->at(2)) |
| 40 | + ->method('hasParameter') |
| 41 | + ->will($this->returnValue(true)) |
| 42 | + ; |
| 43 | + $sc |
| 44 | + ->expects($this->at(3)) |
| 45 | + ->method('getParameter') |
| 46 | + ->will($this->returnValue('bar')) |
| 47 | + ; |
| 48 | + |
| 49 | + $router = new Router($sc, 'foo'); |
| 50 | + $route = $router->getRouteCollection()->get('foo'); |
| 51 | + |
| 52 | + $this->assertEquals('%foo%', $route->getDefault('foo')); |
| 53 | + $this->assertEquals('bar', $route->getDefault('bar')); |
| 54 | + $this->assertEquals('foobar', $route->getDefault('foobar')); |
| 55 | + $this->assertEquals('%foo', $route->getDefault('foo1')); |
| 56 | + $this->assertEquals('foo%', $route->getDefault('foo2')); |
| 57 | + $this->assertEquals('f%o%o', $route->getDefault('foo3')); |
| 58 | + } |
| 59 | + |
| 60 | + private function getServiceContainer(RouteCollection $routes) |
| 61 | + { |
| 62 | + $sc = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
| 63 | + $sc |
| 64 | + ->expects($this->once()) |
| 65 | + ->method('get') |
| 66 | + ->will($this->returnValue($this->getLoader($routes))) |
| 67 | + ; |
| 68 | + |
| 69 | + return $sc; |
| 70 | + } |
| 71 | + |
| 72 | + private function getLoader(RouteCollection $routes) |
| 73 | + { |
| 74 | + $loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'); |
| 75 | + $loader |
| 76 | + ->expects($this->any()) |
| 77 | + ->method('load') |
| 78 | + ->will($this->returnValue($routes)) |
| 79 | + ; |
| 80 | + |
| 81 | + return $loader; |
| 82 | + } |
| 83 | +} |
0 commit comments