class TraceableUrlMatcherTest

Hierarchy

  • class \Symfony\Component\Routing\Tests\Matcher\TraceableUrlMatcherTest extends \Symfony\Component\Routing\Tests\Matcher\PHPUnit_Framework_TestCase

Expanded class hierarchy of TraceableUrlMatcherTest

File

drupal/core/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/TraceableUrlMatcherTest.php, line 19

Namespace

Symfony\Component\Routing\Tests\Matcher
View source
class TraceableUrlMatcherTest extends \PHPUnit_Framework_TestCase {
  public function test() {
    $coll = new RouteCollection();
    $coll
      ->add('foo', new Route('/foo', array(), array(
      '_method' => 'POST',
    )));
    $coll
      ->add('bar', new Route('/bar/{id}', array(), array(
      'id' => '\\d+',
    )));
    $coll
      ->add('bar1', new Route('/bar/{name}', array(), array(
      'id' => '\\w+',
      '_method' => 'POST',
    )));
    $coll
      ->add('bar2', new Route('/foo', array(), array(), array(), 'baz'));
    $coll
      ->add('bar3', new Route('/foo1', array(), array(), array(), 'baz'));
    $context = new RequestContext();
    $context
      ->setHost('baz');
    $matcher = new TraceableUrlMatcher($coll, $context);
    $traces = $matcher
      ->getTraces('/babar');
    $this
      ->assertEquals(array(
      0,
      0,
      0,
      0,
      0,
    ), $this
      ->getLevels($traces));
    $traces = $matcher
      ->getTraces('/foo');
    $this
      ->assertEquals(array(
      1,
      0,
      0,
      2,
    ), $this
      ->getLevels($traces));
    $traces = $matcher
      ->getTraces('/bar/12');
    $this
      ->assertEquals(array(
      0,
      2,
    ), $this
      ->getLevels($traces));
    $traces = $matcher
      ->getTraces('/bar/dd');
    $this
      ->assertEquals(array(
      0,
      1,
      1,
      0,
      0,
    ), $this
      ->getLevels($traces));
    $traces = $matcher
      ->getTraces('/foo1');
    $this
      ->assertEquals(array(
      0,
      0,
      0,
      0,
      2,
    ), $this
      ->getLevels($traces));
    $context
      ->setMethod('POST');
    $traces = $matcher
      ->getTraces('/foo');
    $this
      ->assertEquals(array(
      2,
    ), $this
      ->getLevels($traces));
    $traces = $matcher
      ->getTraces('/bar/dd');
    $this
      ->assertEquals(array(
      0,
      1,
      2,
    ), $this
      ->getLevels($traces));
  }
  public function getLevels($traces) {
    $levels = array();
    foreach ($traces as $trace) {
      $levels[] = $trace['level'];
    }
    return $levels;
  }

}

Members