You are here

public function RouteTest::testRequirements in Zircon Profile 8

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

File

vendor/symfony/routing/Tests/RouteTest.php, line 98

Class

RouteTest

Namespace

Symfony\Component\Routing\Tests

Code

public function testRequirements() {
  $route = new Route('/{foo}');
  $route
    ->setRequirements(array(
    'foo' => '\\d+',
  ));
  $this
    ->assertEquals(array(
    'foo' => '\\d+',
  ), $route
    ->getRequirements(), '->setRequirements() sets the requirements');
  $this
    ->assertEquals('\\d+', $route
    ->getRequirement('foo'), '->getRequirement() returns a requirement');
  $this
    ->assertNull($route
    ->getRequirement('bar'), '->getRequirement() returns null if a requirement is not defined');
  $route
    ->setRequirements(array(
    'foo' => '^\\d+$',
  ));
  $this
    ->assertEquals('\\d+', $route
    ->getRequirement('foo'), '->getRequirement() removes ^ and $ from the path');
  $this
    ->assertEquals($route, $route
    ->setRequirements(array()), '->setRequirements() implements a fluent interface');
  $route
    ->setRequirements(array(
    'foo' => '\\d+',
  ));
  $route
    ->addRequirements(array(
    'bar' => '\\d+',
  ));
  $this
    ->assertEquals($route, $route
    ->addRequirements(array()), '->addRequirements() implements a fluent interface');
  $this
    ->assertEquals(array(
    'foo' => '\\d+',
    'bar' => '\\d+',
  ), $route
    ->getRequirements(), '->addRequirement() keep previous requirements');
}