Ejemplo n.º 1
0
 public function testAddPrefix()
 {
     $collection = new RouteCollection();
     $collection->addRoute('foo', $foo = new Route('/foo'));
     $collection->addRoute('bar', $bar = new Route('/bar'));
     $collection->addPrefix('/admin');
     $this->assertEquals('/admin/foo', $collection->getRoute('foo')->getPattern(), '->addPrefix() adds a prefix to all routes');
     $this->assertEquals('/admin/bar', $collection->getRoute('bar')->getPattern(), '->addPrefix() adds a prefix to all routes');
 }
Ejemplo n.º 2
0
 /**
  * @covers Symfony\Components\Routing\Loader\ClosureLoader::load
  */
 public function testLoad()
 {
     $loader = new ClosureLoader();
     $route = new Route('/');
     $routes = $loader->load(function () use($route) {
         $routes = new RouteCollection();
         $routes->addRoute('foo', $route);
         return $routes;
     });
     $this->assertEquals($route, $routes->getRoute('foo'), '->load() loads a \\Closure resource');
 }
Ejemplo n.º 3
0
 /**
  * @covers Symfony\Components\Routing\Loader\DelegatingLoader::load
  */
 public function testLoad()
 {
     $resolver = new LoaderResolver(array(new ClosureLoader()));
     $loader = new DelegatingLoader($resolver);
     $route = new Route('/');
     $routes = $loader->load(function () use($route) {
         $routes = new RouteCollection();
         $routes->addRoute('foo', $route);
         return $routes;
     });
     $this->assertSame($route, $routes->getRoute('foo'), '->load() loads a resource using the loaders from the resolver');
     try {
         $loader->load('foo.foo');
         $this->fail('->load() throws an \\InvalidArgumentException if the resource cannot be loaded');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an \\InvalidArgumentException if the resource cannot be loaded');
     }
 }
$collection->addRoute('foo', $foo = new Route('/foo'));
$collection1 = new RouteCollection();
$collection1->addRoute('foo', $foo1 = new Route('/foo1'));
$collection1->addRoute('bar', $bar1 = new Route('/bar1'));
$collection->addCollection($collection1);
$t->is($collection->getRoutes(), array('foo' => $foo1, 'bar' => $bar1), '->addCollection() adds routes from another collection');
$collection = new RouteCollection();
$collection->addRoute('foo', $foo = new Route('/foo'));
$collection1 = new RouteCollection();
$collection1->addRoute('foo', $foo1 = new Route('/foo1'));
$collection->addCollection($collection1, '/foo');
$t->is($collection->getRoute('foo')->getPattern(), '/foo/foo1', '->addCollection() can add a prefix to all merged routes');
$collection = new RouteCollection();
$collection->addResource($foo = new FileResource('foo'));
$collection1 = new RouteCollection();
$collection1->addResource($foo1 = new FileResource('foo1'));
$collection->addCollection($collection1);
$t->is($collection->getResources(), array($foo, $foo1), '->addCollection() merges resources');
// ->addPrefix()
$t->diag('->addPrefix()');
$collection = new RouteCollection();
$collection->addRoute('foo', $foo = new Route('/foo'));
$collection->addRoute('bar', $bar = new Route('/bar'));
$collection->addPrefix('/admin');
$t->is($collection->getRoute('foo')->getPattern(), '/admin/foo', '->addPrefix() adds a prefix to all routes');
$t->is($collection->getRoute('bar')->getPattern(), '/admin/bar', '->addPrefix() adds a prefix to all routes');
// ->getResources() ->addResource()
$t->diag('->getResources() ->addResource()');
$collection = new RouteCollection();
$collection->addResource($foo = new FileResource('foo'));
$t->is($collection->getResources(), array($foo), '->addResources() adds a resource');