You are here

public function TraceableUrlMatcherTest::test in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/routing/Tests/Matcher/TraceableUrlMatcherTest.php \Symfony\Component\Routing\Tests\Matcher\TraceableUrlMatcherTest::test()

File

vendor/symfony/routing/Tests/Matcher/TraceableUrlMatcherTest.php, line 21

Class

TraceableUrlMatcherTest

Namespace

Symfony\Component\Routing\Tests\Matcher

Code

public function test() {
  $coll = new RouteCollection();
  $coll
    ->add('foo', new Route('/foo', array(), array(), array(), '', array(), array(
    'POST',
  )));
  $coll
    ->add('bar', new Route('/bar/{id}', array(), array(
    'id' => '\\d+',
  )));
  $coll
    ->add('bar1', new Route('/bar/{name}', array(), array(
    'id' => '\\w+',
  ), array(), '', array(), array(
    'POST',
  )));
  $coll
    ->add('bar2', new Route('/foo', array(), array(), array(), 'baz'));
  $coll
    ->add('bar3', new Route('/foo1', array(), array(), array(), 'baz'));
  $coll
    ->add('bar4', new Route('/foo2', array(), array(), array(), 'baz', array(), array(), 'context.getMethod() == "GET"'));
  $context = new RequestContext();
  $context
    ->setHost('baz');
  $matcher = new TraceableUrlMatcher($coll, $context);
  $traces = $matcher
    ->getTraces('/babar');
  $this
    ->assertSame(array(
    0,
    0,
    0,
    0,
    0,
    0,
  ), $this
    ->getLevels($traces));
  $traces = $matcher
    ->getTraces('/foo');
  $this
    ->assertSame(array(
    1,
    0,
    0,
    2,
  ), $this
    ->getLevels($traces));
  $traces = $matcher
    ->getTraces('/bar/12');
  $this
    ->assertSame(array(
    0,
    2,
  ), $this
    ->getLevels($traces));
  $traces = $matcher
    ->getTraces('/bar/dd');
  $this
    ->assertSame(array(
    0,
    1,
    1,
    0,
    0,
    0,
  ), $this
    ->getLevels($traces));
  $traces = $matcher
    ->getTraces('/foo1');
  $this
    ->assertSame(array(
    0,
    0,
    0,
    0,
    2,
  ), $this
    ->getLevels($traces));
  $context
    ->setMethod('POST');
  $traces = $matcher
    ->getTraces('/foo');
  $this
    ->assertSame(array(
    2,
  ), $this
    ->getLevels($traces));
  $traces = $matcher
    ->getTraces('/bar/dd');
  $this
    ->assertSame(array(
    0,
    1,
    2,
  ), $this
    ->getLevels($traces));
  $traces = $matcher
    ->getTraces('/foo2');
  $this
    ->assertSame(array(
    0,
    0,
    0,
    0,
    0,
    1,
  ), $this
    ->getLevels($traces));
}