]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperPrefixCollectionTest.php
gitignore vendor
[github/wallabag/wallabag.git] / vendor / symfony / routing / Symfony / Component / Routing / Tests / Matcher / Dumper / DumperPrefixCollectionTest.php
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\Dumper;
13
14 use Symfony\Component\Routing\Route;
15 use Symfony\Component\Routing\Matcher\Dumper\DumperPrefixCollection;
16 use Symfony\Component\Routing\Matcher\Dumper\DumperRoute;
17 use Symfony\Component\Routing\Matcher\Dumper\DumperCollection;
18
19 class DumperPrefixCollectionTest extends \PHPUnit_Framework_TestCase
20 {
21 public function testAddPrefixRoute()
22 {
23 $coll = new DumperPrefixCollection;
24 $coll->setPrefix('');
25
26 $route = new DumperRoute('bar', new Route('/foo/bar'));
27 $coll = $coll->addPrefixRoute($route);
28
29 $route = new DumperRoute('bar2', new Route('/foo/bar'));
30 $coll = $coll->addPrefixRoute($route);
31
32 $route = new DumperRoute('qux', new Route('/foo/qux'));
33 $coll = $coll->addPrefixRoute($route);
34
35 $route = new DumperRoute('bar3', new Route('/foo/bar'));
36 $coll = $coll->addPrefixRoute($route);
37
38 $route = new DumperRoute('bar4', new Route(''));
39 $result = $coll->addPrefixRoute($route);
40
41 $expect = <<<'EOF'
42 |-coll /
43 | |-coll /f
44 | | |-coll /fo
45 | | | |-coll /foo
46 | | | | |-coll /foo/
47 | | | | | |-coll /foo/b
48 | | | | | | |-coll /foo/ba
49 | | | | | | | |-coll /foo/bar
50 | | | | | | | | |-route bar /foo/bar
51 | | | | | | | | |-route bar2 /foo/bar
52 | | | | | |-coll /foo/q
53 | | | | | | |-coll /foo/qu
54 | | | | | | | |-coll /foo/qux
55 | | | | | | | | |-route qux /foo/qux
56 | | | | | |-coll /foo/b
57 | | | | | | |-coll /foo/ba
58 | | | | | | | |-coll /foo/bar
59 | | | | | | | | |-route bar3 /foo/bar
60 | |-route bar4 /
61
62 EOF;
63
64 $this->assertSame($expect, $this->collectionToString($result->getRoot(), ' '));
65 }
66
67 public function testMergeSlashNodes()
68 {
69 $coll = new DumperPrefixCollection;
70 $coll->setPrefix('');
71
72 $route = new DumperRoute('bar', new Route('/foo/bar'));
73 $coll = $coll->addPrefixRoute($route);
74
75 $route = new DumperRoute('bar2', new Route('/foo/bar'));
76 $coll = $coll->addPrefixRoute($route);
77
78 $route = new DumperRoute('qux', new Route('/foo/qux'));
79 $coll = $coll->addPrefixRoute($route);
80
81 $route = new DumperRoute('bar3', new Route('/foo/bar'));
82 $result = $coll->addPrefixRoute($route);
83
84 $result->getRoot()->mergeSlashNodes();
85
86 $expect = <<<'EOF'
87 |-coll /f
88 | |-coll /fo
89 | | |-coll /foo
90 | | | |-coll /foo/b
91 | | | | |-coll /foo/ba
92 | | | | | |-coll /foo/bar
93 | | | | | | |-route bar /foo/bar
94 | | | | | | |-route bar2 /foo/bar
95 | | | |-coll /foo/q
96 | | | | |-coll /foo/qu
97 | | | | | |-coll /foo/qux
98 | | | | | | |-route qux /foo/qux
99 | | | |-coll /foo/b
100 | | | | |-coll /foo/ba
101 | | | | | |-coll /foo/bar
102 | | | | | | |-route bar3 /foo/bar
103
104 EOF;
105
106 $this->assertSame($expect, $this->collectionToString($result->getRoot(), ' '));
107 }
108
109 private function collectionToString(DumperCollection $collection, $prefix)
110 {
111 $string = '';
112 foreach ($collection as $route) {
113 if ($route instanceof DumperCollection) {
114 $string .= sprintf("%s|-coll %s\n", $prefix, $route->getPrefix());
115 $string .= $this->collectionToString($route, $prefix.'| ');
116 } else {
117 $string .= sprintf("%s|-route %s %s\n", $prefix, $route->getName(), $route->getRoute()->getPath());
118 }
119 }
120
121 return $string;
122 }
123 }