]>
Commit | Line | Data |
---|---|---|
4f5b44bd NL |
1 | <?php |
2 | ||
3 | /* | |
4 | * This file is part of the Symfony package. | |
5 | * | |
6 | * (c) Fabien Potencier <fabien@symfony.com> | |
7 | * | |
8 | * For the full copyright and license information, please view the LICENSE | |
9 | * file that was distributed with this source code. | |
10 | */ | |
11 | ||
12 | namespace Symfony\Component\Routing\Tests\Matcher; | |
13 | ||
14 | use Symfony\Component\Routing\Route; | |
15 | use Symfony\Component\Routing\RouteCollection; | |
16 | use Symfony\Component\Routing\RequestContext; | |
17 | use Symfony\Component\Routing\Matcher\TraceableUrlMatcher; | |
18 | ||
19 | class TraceableUrlMatcherTest extends \PHPUnit_Framework_TestCase | |
20 | { | |
21 | public function test() | |
22 | { | |
23 | $coll = new RouteCollection(); | |
24 | $coll->add('foo', new Route('/foo', array(), array('_method' => 'POST'))); | |
25 | $coll->add('bar', new Route('/bar/{id}', array(), array('id' => '\d+'))); | |
26 | $coll->add('bar1', new Route('/bar/{name}', array(), array('id' => '\w+', '_method' => 'POST'))); | |
27 | $coll->add('bar2', new Route('/foo', array(), array(), array(), 'baz')); | |
28 | $coll->add('bar3', new Route('/foo1', array(), array(), array(), 'baz')); | |
29 | ||
30 | $context = new RequestContext(); | |
31 | $context->setHost('baz'); | |
32 | ||
33 | $matcher = new TraceableUrlMatcher($coll, $context); | |
34 | $traces = $matcher->getTraces('/babar'); | |
35 | $this->assertEquals(array(0, 0, 0, 0, 0), $this->getLevels($traces)); | |
36 | ||
37 | $traces = $matcher->getTraces('/foo'); | |
38 | $this->assertEquals(array(1, 0, 0, 2), $this->getLevels($traces)); | |
39 | ||
40 | $traces = $matcher->getTraces('/bar/12'); | |
41 | $this->assertEquals(array(0, 2), $this->getLevels($traces)); | |
42 | ||
43 | $traces = $matcher->getTraces('/bar/dd'); | |
44 | $this->assertEquals(array(0, 1, 1, 0, 0), $this->getLevels($traces)); | |
45 | ||
46 | $traces = $matcher->getTraces('/foo1'); | |
47 | $this->assertEquals(array(0, 0, 0, 0, 2), $this->getLevels($traces)); | |
48 | ||
49 | $context->setMethod('POST'); | |
50 | $traces = $matcher->getTraces('/foo'); | |
51 | $this->assertEquals(array(2), $this->getLevels($traces)); | |
52 | ||
53 | $traces = $matcher->getTraces('/bar/dd'); | |
54 | $this->assertEquals(array(0, 1, 2), $this->getLevels($traces)); | |
55 | } | |
56 | ||
57 | public function getLevels($traces) | |
58 | { | |
59 | $levels = array(); | |
60 | foreach ($traces as $trace) { | |
61 | $levels[] = $trace['level']; | |
62 | } | |
63 | ||
64 | return $levels; | |
65 | } | |
66 | } |