You are here

public function RouteCollectionTest::testAddPrefix in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/routing/Tests/RouteCollectionTest.php \Symfony\Component\Routing\Tests\RouteCollectionTest::testAddPrefix()

File

vendor/symfony/routing/Tests/RouteCollectionTest.php, line 141

Class

RouteCollectionTest

Namespace

Symfony\Component\Routing\Tests

Code

public function testAddPrefix() {
  $collection = new RouteCollection();
  $collection
    ->add('foo', $foo = new Route('/foo'));
  $collection2 = new RouteCollection();
  $collection2
    ->add('bar', $bar = new Route('/bar'));
  $collection
    ->addCollection($collection2);
  $collection
    ->addPrefix(' / ');
  $this
    ->assertSame('/foo', $collection
    ->get('foo')
    ->getPath(), '->addPrefix() trims the prefix and a single slash has no effect');
  $collection
    ->addPrefix('/{admin}', array(
    'admin' => 'admin',
  ), array(
    'admin' => '\\d+',
  ));
  $this
    ->assertEquals('/{admin}/foo', $collection
    ->get('foo')
    ->getPath(), '->addPrefix() adds a prefix to all routes');
  $this
    ->assertEquals('/{admin}/bar', $collection
    ->get('bar')
    ->getPath(), '->addPrefix() adds a prefix to all routes');
  $this
    ->assertEquals(array(
    'admin' => 'admin',
  ), $collection
    ->get('foo')
    ->getDefaults(), '->addPrefix() adds defaults to all routes');
  $this
    ->assertEquals(array(
    'admin' => 'admin',
  ), $collection
    ->get('bar')
    ->getDefaults(), '->addPrefix() adds defaults to all routes');
  $this
    ->assertEquals(array(
    'admin' => '\\d+',
  ), $collection
    ->get('foo')
    ->getRequirements(), '->addPrefix() adds requirements to all routes');
  $this
    ->assertEquals(array(
    'admin' => '\\d+',
  ), $collection
    ->get('bar')
    ->getRequirements(), '->addPrefix() adds requirements to all routes');
  $collection
    ->addPrefix('0');
  $this
    ->assertEquals('/0/{admin}/foo', $collection
    ->get('foo')
    ->getPath(), '->addPrefix() ensures a prefix must start with a slash and must not end with a slash');
  $collection
    ->addPrefix('/ /');
  $this
    ->assertSame('/ /0/{admin}/foo', $collection
    ->get('foo')
    ->getPath(), '->addPrefix() can handle spaces if desired');
  $this
    ->assertSame('/ /0/{admin}/bar', $collection
    ->get('bar')
    ->getPath(), 'the route pattern of an added collection is in synch with the added prefix');
}