diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-03 19:26:54 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-03 19:26:54 +0200 |
commit | 4f5b44bd3bd490309eb2ba7b44df4769816ba729 (patch) | |
tree | 6cefe170dfe0a5a361cb1e2d1fc4d580a3316d02 /vendor/symfony/routing/Symfony/Component/Routing/Tests | |
parent | 2b840e0cfb63a453bea67a98541f3df9c273c5f5 (diff) | |
download | wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.gz wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.zst wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.zip |
twig implementation
Diffstat (limited to 'vendor/symfony/routing/Symfony/Component/Routing/Tests')
57 files changed, 4658 insertions, 0 deletions
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Annotation/RouteTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Annotation/RouteTest.php new file mode 100644 index 00000000..b58869f7 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Annotation/RouteTest.php | |||
@@ -0,0 +1,49 @@ | |||
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\Annotation; | ||
13 | |||
14 | use Symfony\Component\Routing\Annotation\Route; | ||
15 | |||
16 | class RouteTest extends \PHPUnit_Framework_TestCase | ||
17 | { | ||
18 | /** | ||
19 | * @expectedException \BadMethodCallException | ||
20 | */ | ||
21 | public function testInvalidRouteParameter() | ||
22 | { | ||
23 | $route = new Route(array('foo' => 'bar')); | ||
24 | } | ||
25 | |||
26 | /** | ||
27 | * @dataProvider getValidParameters | ||
28 | */ | ||
29 | public function testRouteParameters($parameter, $value, $getter) | ||
30 | { | ||
31 | $route = new Route(array($parameter => $value)); | ||
32 | $this->assertEquals($route->$getter(), $value); | ||
33 | } | ||
34 | |||
35 | public function getValidParameters() | ||
36 | { | ||
37 | return array( | ||
38 | array('value', '/Blog', 'getPattern'), | ||
39 | array('value', '/Blog', 'getPath'), | ||
40 | array('requirements', array('_method' => 'GET'), 'getRequirements'), | ||
41 | array('options', array('compiler_class' => 'RouteCompiler'), 'getOptions'), | ||
42 | array('name', 'blog_index', 'getName'), | ||
43 | array('defaults', array('_controller' => 'MyBlogBundle:Blog:index'), 'getDefaults'), | ||
44 | array('schemes', array('https'), 'getSchemes'), | ||
45 | array('methods', array('GET', 'POST'), 'getMethods'), | ||
46 | array('host', array('{locale}.example.com'), 'getHost') | ||
47 | ); | ||
48 | } | ||
49 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/CompiledRouteTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/CompiledRouteTest.php new file mode 100644 index 00000000..215ebb70 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/CompiledRouteTest.php | |||
@@ -0,0 +1,26 @@ | |||
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; | ||
13 | |||
14 | use Symfony\Component\Routing\CompiledRoute; | ||
15 | |||
16 | class CompiledRouteTest extends \PHPUnit_Framework_TestCase | ||
17 | { | ||
18 | public function testAccessors() | ||
19 | { | ||
20 | $compiled = new CompiledRoute('prefix', 'regex', array('tokens'), array(), array(), array(), array(), array('variables')); | ||
21 | $this->assertEquals('prefix', $compiled->getStaticPrefix(), '__construct() takes a static prefix as its second argument'); | ||
22 | $this->assertEquals('regex', $compiled->getRegex(), '__construct() takes a regexp as its third argument'); | ||
23 | $this->assertEquals(array('tokens'), $compiled->getTokens(), '__construct() takes an array of tokens as its fourth argument'); | ||
24 | $this->assertEquals(array('variables'), $compiled->getVariables(), '__construct() takes an array of variables as its ninth argument'); | ||
25 | } | ||
26 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/AbstractClass.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/AbstractClass.php new file mode 100644 index 00000000..56bcab2a --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/AbstractClass.php | |||
@@ -0,0 +1,16 @@ | |||
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\Fixtures\AnnotatedClasses; | ||
13 | |||
14 | abstract class AbstractClass | ||
15 | { | ||
16 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/BarClass.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/BarClass.php new file mode 100644 index 00000000..a3882773 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/BarClass.php | |||
@@ -0,0 +1,19 @@ | |||
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\Fixtures\AnnotatedClasses; | ||
13 | |||
14 | class BarClass | ||
15 | { | ||
16 | public function routeAction($arg1, $arg2 = 'defaultValue2', $arg3 = 'defaultValue3') | ||
17 | { | ||
18 | } | ||
19 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/FooClass.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/FooClass.php new file mode 100644 index 00000000..320dc350 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/FooClass.php | |||
@@ -0,0 +1,16 @@ | |||
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\Fixtures\AnnotatedClasses; | ||
13 | |||
14 | class FooClass | ||
15 | { | ||
16 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/CustomXmlFileLoader.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/CustomXmlFileLoader.php new file mode 100644 index 00000000..12a5bedb --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/CustomXmlFileLoader.php | |||
@@ -0,0 +1,26 @@ | |||
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\Fixtures; | ||
13 | |||
14 | use Symfony\Component\Routing\Loader\XmlFileLoader; | ||
15 | use Symfony\Component\Config\Util\XmlUtils; | ||
16 | |||
17 | /** | ||
18 | * XmlFileLoader with schema validation turned off | ||
19 | */ | ||
20 | class CustomXmlFileLoader extends XmlFileLoader | ||
21 | { | ||
22 | protected function loadFile($file) | ||
23 | { | ||
24 | return XmlUtils::loadFile($file, function() { return true; }); | ||
25 | } | ||
26 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/RedirectableUrlMatcher.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/RedirectableUrlMatcher.php new file mode 100644 index 00000000..e95c1f26 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/RedirectableUrlMatcher.php | |||
@@ -0,0 +1,30 @@ | |||
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\Fixtures; | ||
13 | |||
14 | use Symfony\Component\Routing\Matcher\UrlMatcher; | ||
15 | use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface; | ||
16 | |||
17 | /** | ||
18 | * @author Fabien Potencier <fabien@symfony.com> | ||
19 | */ | ||
20 | class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface | ||
21 | { | ||
22 | public function redirect($path, $route, $scheme = null) | ||
23 | { | ||
24 | return array( | ||
25 | '_controller' => 'Some controller reference...', | ||
26 | 'path' => $path, | ||
27 | 'scheme' => $scheme, | ||
28 | ); | ||
29 | } | ||
30 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/annotated.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/annotated.php new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/annotated.php | |||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.apache b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.apache new file mode 100644 index 00000000..26a561cc --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.apache | |||
@@ -0,0 +1,163 @@ | |||
1 | # skip "real" requests | ||
2 | RewriteCond %{REQUEST_FILENAME} -f | ||
3 | RewriteRule .* - [QSA,L] | ||
4 | |||
5 | # foo | ||
6 | RewriteCond %{REQUEST_URI} ^/foo/(baz|symfony)$ | ||
7 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:foo,E=_ROUTING_param_bar:%1,E=_ROUTING_default_def:test] | ||
8 | |||
9 | # foobar | ||
10 | RewriteCond %{REQUEST_URI} ^/foo(?:/([^/]++))?$ | ||
11 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:foobar,E=_ROUTING_param_bar:%1,E=_ROUTING_default_bar:toto] | ||
12 | |||
13 | # bar | ||
14 | RewriteCond %{REQUEST_URI} ^/bar/([^/]++)$ | ||
15 | RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)$ [NC] | ||
16 | RewriteRule .* - [S=1,E=_ROUTING_allow_GET:1,E=_ROUTING_allow_HEAD:1] | ||
17 | RewriteCond %{REQUEST_URI} ^/bar/([^/]++)$ | ||
18 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:bar,E=_ROUTING_param_foo:%1] | ||
19 | |||
20 | # baragain | ||
21 | RewriteCond %{REQUEST_URI} ^/baragain/([^/]++)$ | ||
22 | RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD)$ [NC] | ||
23 | RewriteRule .* - [S=1,E=_ROUTING_allow_GET:1,E=_ROUTING_allow_POST:1,E=_ROUTING_allow_HEAD:1] | ||
24 | RewriteCond %{REQUEST_URI} ^/baragain/([^/]++)$ | ||
25 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baragain,E=_ROUTING_param_foo:%1] | ||
26 | |||
27 | # baz | ||
28 | RewriteCond %{REQUEST_URI} ^/test/baz$ | ||
29 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz] | ||
30 | |||
31 | # baz2 | ||
32 | RewriteCond %{REQUEST_URI} ^/test/baz\.html$ | ||
33 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz2] | ||
34 | |||
35 | # baz3 | ||
36 | RewriteCond %{REQUEST_URI} ^/test/baz3$ | ||
37 | RewriteRule .* $0/ [QSA,L,R=301] | ||
38 | RewriteCond %{REQUEST_URI} ^/test/baz3/$ | ||
39 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz3] | ||
40 | |||
41 | # baz4 | ||
42 | RewriteCond %{REQUEST_URI} ^/test/([^/]++)$ | ||
43 | RewriteRule .* $0/ [QSA,L,R=301] | ||
44 | RewriteCond %{REQUEST_URI} ^/test/([^/]++)/$ | ||
45 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz4,E=_ROUTING_param_foo:%1] | ||
46 | |||
47 | # baz5 | ||
48 | RewriteCond %{REQUEST_URI} ^/test/([^/]++)/$ | ||
49 | RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)$ [NC] | ||
50 | RewriteRule .* - [S=2,E=_ROUTING_allow_GET:1,E=_ROUTING_allow_HEAD:1] | ||
51 | RewriteCond %{REQUEST_URI} ^/test/([^/]++)$ | ||
52 | RewriteRule .* $0/ [QSA,L,R=301] | ||
53 | RewriteCond %{REQUEST_URI} ^/test/([^/]++)/$ | ||
54 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz5,E=_ROUTING_param_foo:%1] | ||
55 | |||
56 | # baz5unsafe | ||
57 | RewriteCond %{REQUEST_URI} ^/testunsafe/([^/]++)/$ | ||
58 | RewriteCond %{REQUEST_METHOD} !^(POST)$ [NC] | ||
59 | RewriteRule .* - [S=1,E=_ROUTING_allow_POST:1] | ||
60 | RewriteCond %{REQUEST_URI} ^/testunsafe/([^/]++)/$ | ||
61 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz5unsafe,E=_ROUTING_param_foo:%1] | ||
62 | |||
63 | # baz6 | ||
64 | RewriteCond %{REQUEST_URI} ^/test/baz$ | ||
65 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz6,E=_ROUTING_default_foo:bar\ baz] | ||
66 | |||
67 | # baz7 | ||
68 | RewriteCond %{REQUEST_URI} ^/te\ st/baz$ | ||
69 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz7] | ||
70 | |||
71 | # baz8 | ||
72 | RewriteCond %{REQUEST_URI} ^/te\\\ st/baz$ | ||
73 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz8] | ||
74 | |||
75 | # baz9 | ||
76 | RewriteCond %{REQUEST_URI} ^/test/(te\\\ st)$ | ||
77 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz9,E=_ROUTING_param_baz:%1] | ||
78 | |||
79 | RewriteCond %{HTTP:Host} ^a\.example\.com$ | ||
80 | RewriteRule .? - [E=__ROUTING_host_1:1] | ||
81 | |||
82 | # route1 | ||
83 | RewriteCond %{ENV:__ROUTING_host_1} =1 | ||
84 | RewriteCond %{REQUEST_URI} ^/route1$ | ||
85 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route1] | ||
86 | |||
87 | # route2 | ||
88 | RewriteCond %{ENV:__ROUTING_host_1} =1 | ||
89 | RewriteCond %{REQUEST_URI} ^/c2/route2$ | ||
90 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route2] | ||
91 | |||
92 | RewriteCond %{HTTP:Host} ^b\.example\.com$ | ||
93 | RewriteRule .? - [E=__ROUTING_host_2:1] | ||
94 | |||
95 | # route3 | ||
96 | RewriteCond %{ENV:__ROUTING_host_2} =1 | ||
97 | RewriteCond %{REQUEST_URI} ^/c2/route3$ | ||
98 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route3] | ||
99 | |||
100 | RewriteCond %{HTTP:Host} ^a\.example\.com$ | ||
101 | RewriteRule .? - [E=__ROUTING_host_3:1] | ||
102 | |||
103 | # route4 | ||
104 | RewriteCond %{ENV:__ROUTING_host_3} =1 | ||
105 | RewriteCond %{REQUEST_URI} ^/route4$ | ||
106 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route4] | ||
107 | |||
108 | RewriteCond %{HTTP:Host} ^c\.example\.com$ | ||
109 | RewriteRule .? - [E=__ROUTING_host_4:1] | ||
110 | |||
111 | # route5 | ||
112 | RewriteCond %{ENV:__ROUTING_host_4} =1 | ||
113 | RewriteCond %{REQUEST_URI} ^/route5$ | ||
114 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route5] | ||
115 | |||
116 | # route6 | ||
117 | RewriteCond %{REQUEST_URI} ^/route6$ | ||
118 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route6] | ||
119 | |||
120 | RewriteCond %{HTTP:Host} ^([^\.]++)\.example\.com$ | ||
121 | RewriteRule .? - [E=__ROUTING_host_5:1,E=__ROUTING_host_5_var1:%1] | ||
122 | |||
123 | # route11 | ||
124 | RewriteCond %{ENV:__ROUTING_host_5} =1 | ||
125 | RewriteCond %{REQUEST_URI} ^/route11$ | ||
126 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route11,E=_ROUTING_param_var1:%{ENV:__ROUTING_host_5_var1}] | ||
127 | |||
128 | # route12 | ||
129 | RewriteCond %{ENV:__ROUTING_host_5} =1 | ||
130 | RewriteCond %{REQUEST_URI} ^/route12$ | ||
131 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route12,E=_ROUTING_param_var1:%{ENV:__ROUTING_host_5_var1},E=_ROUTING_default_var1:val] | ||
132 | |||
133 | # route13 | ||
134 | RewriteCond %{ENV:__ROUTING_host_5} =1 | ||
135 | RewriteCond %{REQUEST_URI} ^/route13/([^/]++)$ | ||
136 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route13,E=_ROUTING_param_var1:%{ENV:__ROUTING_host_5_var1},E=_ROUTING_param_name:%1] | ||
137 | |||
138 | # route14 | ||
139 | RewriteCond %{ENV:__ROUTING_host_5} =1 | ||
140 | RewriteCond %{REQUEST_URI} ^/route14/([^/]++)$ | ||
141 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route14,E=_ROUTING_param_var1:%{ENV:__ROUTING_host_5_var1},E=_ROUTING_param_name:%1,E=_ROUTING_default_var1:val] | ||
142 | |||
143 | RewriteCond %{HTTP:Host} ^c\.example\.com$ | ||
144 | RewriteRule .? - [E=__ROUTING_host_6:1] | ||
145 | |||
146 | # route15 | ||
147 | RewriteCond %{ENV:__ROUTING_host_6} =1 | ||
148 | RewriteCond %{REQUEST_URI} ^/route15/([^/]++)$ | ||
149 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route15,E=_ROUTING_param_name:%1] | ||
150 | |||
151 | # route16 | ||
152 | RewriteCond %{REQUEST_URI} ^/route16/([^/]++)$ | ||
153 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route16,E=_ROUTING_param_name:%1,E=_ROUTING_default_var1:val] | ||
154 | |||
155 | # route17 | ||
156 | RewriteCond %{REQUEST_URI} ^/route17$ | ||
157 | RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route17] | ||
158 | |||
159 | # 405 Method Not Allowed | ||
160 | RewriteCond %{ENV:_ROUTING__allow_GET} =1 [OR] | ||
161 | RewriteCond %{ENV:_ROUTING__allow_HEAD} =1 [OR] | ||
162 | RewriteCond %{ENV:_ROUTING__allow_POST} =1 | ||
163 | RewriteRule .* app.php [QSA,L] | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php new file mode 100644 index 00000000..e5f7665c --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php | |||
@@ -0,0 +1,310 @@ | |||
1 | <?php | ||
2 | |||
3 | use Symfony\Component\Routing\Exception\MethodNotAllowedException; | ||
4 | use Symfony\Component\Routing\Exception\ResourceNotFoundException; | ||
5 | use Symfony\Component\Routing\RequestContext; | ||
6 | |||
7 | /** | ||
8 | * ProjectUrlMatcher | ||
9 | * | ||
10 | * This class has been auto-generated | ||
11 | * by the Symfony Routing Component. | ||
12 | */ | ||
13 | class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher | ||
14 | { | ||
15 | /** | ||
16 | * Constructor. | ||
17 | */ | ||
18 | public function __construct(RequestContext $context) | ||
19 | { | ||
20 | $this->context = $context; | ||
21 | } | ||
22 | |||
23 | public function match($pathinfo) | ||
24 | { | ||
25 | $allow = array(); | ||
26 | $pathinfo = rawurldecode($pathinfo); | ||
27 | |||
28 | // foo | ||
29 | if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?P<bar>baz|symfony)$#s', $pathinfo, $matches)) { | ||
30 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',)); | ||
31 | } | ||
32 | |||
33 | if (0 === strpos($pathinfo, '/bar')) { | ||
34 | // bar | ||
35 | if (preg_match('#^/bar/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) { | ||
36 | if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) { | ||
37 | $allow = array_merge($allow, array('GET', 'HEAD')); | ||
38 | goto not_bar; | ||
39 | } | ||
40 | |||
41 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ()); | ||
42 | } | ||
43 | not_bar: | ||
44 | |||
45 | // barhead | ||
46 | if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) { | ||
47 | if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) { | ||
48 | $allow = array_merge($allow, array('GET', 'HEAD')); | ||
49 | goto not_barhead; | ||
50 | } | ||
51 | |||
52 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ()); | ||
53 | } | ||
54 | not_barhead: | ||
55 | |||
56 | } | ||
57 | |||
58 | if (0 === strpos($pathinfo, '/test')) { | ||
59 | if (0 === strpos($pathinfo, '/test/baz')) { | ||
60 | // baz | ||
61 | if ($pathinfo === '/test/baz') { | ||
62 | return array('_route' => 'baz'); | ||
63 | } | ||
64 | |||
65 | // baz2 | ||
66 | if ($pathinfo === '/test/baz.html') { | ||
67 | return array('_route' => 'baz2'); | ||
68 | } | ||
69 | |||
70 | // baz3 | ||
71 | if ($pathinfo === '/test/baz3/') { | ||
72 | return array('_route' => 'baz3'); | ||
73 | } | ||
74 | |||
75 | } | ||
76 | |||
77 | // baz4 | ||
78 | if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) { | ||
79 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ()); | ||
80 | } | ||
81 | |||
82 | // baz5 | ||
83 | if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) { | ||
84 | if ($this->context->getMethod() != 'POST') { | ||
85 | $allow[] = 'POST'; | ||
86 | goto not_baz5; | ||
87 | } | ||
88 | |||
89 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ()); | ||
90 | } | ||
91 | not_baz5: | ||
92 | |||
93 | // baz.baz6 | ||
94 | if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) { | ||
95 | if ($this->context->getMethod() != 'PUT') { | ||
96 | $allow[] = 'PUT'; | ||
97 | goto not_bazbaz6; | ||
98 | } | ||
99 | |||
100 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ()); | ||
101 | } | ||
102 | not_bazbaz6: | ||
103 | |||
104 | } | ||
105 | |||
106 | // foofoo | ||
107 | if ($pathinfo === '/foofoo') { | ||
108 | return array ( 'def' => 'test', '_route' => 'foofoo',); | ||
109 | } | ||
110 | |||
111 | // quoter | ||
112 | if (preg_match('#^/(?P<quoter>[\']+)$#s', $pathinfo, $matches)) { | ||
113 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'quoter')), array ()); | ||
114 | } | ||
115 | |||
116 | // space | ||
117 | if ($pathinfo === '/spa ce') { | ||
118 | return array('_route' => 'space'); | ||
119 | } | ||
120 | |||
121 | if (0 === strpos($pathinfo, '/a')) { | ||
122 | if (0 === strpos($pathinfo, '/a/b\'b')) { | ||
123 | // foo1 | ||
124 | if (preg_match('#^/a/b\'b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) { | ||
125 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo1')), array ()); | ||
126 | } | ||
127 | |||
128 | // bar1 | ||
129 | if (preg_match('#^/a/b\'b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) { | ||
130 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar1')), array ()); | ||
131 | } | ||
132 | |||
133 | } | ||
134 | |||
135 | // overridden | ||
136 | if (preg_match('#^/a/(?P<var>.*)$#s', $pathinfo, $matches)) { | ||
137 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'overridden')), array ()); | ||
138 | } | ||
139 | |||
140 | if (0 === strpos($pathinfo, '/a/b\'b')) { | ||
141 | // foo2 | ||
142 | if (preg_match('#^/a/b\'b/(?P<foo1>[^/]++)$#s', $pathinfo, $matches)) { | ||
143 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo2')), array ()); | ||
144 | } | ||
145 | |||
146 | // bar2 | ||
147 | if (preg_match('#^/a/b\'b/(?P<bar1>[^/]++)$#s', $pathinfo, $matches)) { | ||
148 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar2')), array ()); | ||
149 | } | ||
150 | |||
151 | } | ||
152 | |||
153 | } | ||
154 | |||
155 | if (0 === strpos($pathinfo, '/multi')) { | ||
156 | // helloWorld | ||
157 | if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P<who>[^/]++))?$#s', $pathinfo, $matches)) { | ||
158 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'helloWorld')), array ( 'who' => 'World!',)); | ||
159 | } | ||
160 | |||
161 | // overridden2 | ||
162 | if ($pathinfo === '/multi/new') { | ||
163 | return array('_route' => 'overridden2'); | ||
164 | } | ||
165 | |||
166 | // hey | ||
167 | if ($pathinfo === '/multi/hey/') { | ||
168 | return array('_route' => 'hey'); | ||
169 | } | ||
170 | |||
171 | } | ||
172 | |||
173 | // foo3 | ||
174 | if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) { | ||
175 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo3')), array ()); | ||
176 | } | ||
177 | |||
178 | // bar3 | ||
179 | if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) { | ||
180 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar3')), array ()); | ||
181 | } | ||
182 | |||
183 | if (0 === strpos($pathinfo, '/aba')) { | ||
184 | // ababa | ||
185 | if ($pathinfo === '/ababa') { | ||
186 | return array('_route' => 'ababa'); | ||
187 | } | ||
188 | |||
189 | // foo4 | ||
190 | if (preg_match('#^/aba/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) { | ||
191 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo4')), array ()); | ||
192 | } | ||
193 | |||
194 | } | ||
195 | |||
196 | $host = $this->context->getHost(); | ||
197 | |||
198 | if (preg_match('#^a\\.example\\.com$#s', $host, $hostMatches)) { | ||
199 | // route1 | ||
200 | if ($pathinfo === '/route1') { | ||
201 | return array('_route' => 'route1'); | ||
202 | } | ||
203 | |||
204 | // route2 | ||
205 | if ($pathinfo === '/c2/route2') { | ||
206 | return array('_route' => 'route2'); | ||
207 | } | ||
208 | |||
209 | } | ||
210 | |||
211 | if (preg_match('#^b\\.example\\.com$#s', $host, $hostMatches)) { | ||
212 | // route3 | ||
213 | if ($pathinfo === '/c2/route3') { | ||
214 | return array('_route' => 'route3'); | ||
215 | } | ||
216 | |||
217 | } | ||
218 | |||
219 | if (preg_match('#^a\\.example\\.com$#s', $host, $hostMatches)) { | ||
220 | // route4 | ||
221 | if ($pathinfo === '/route4') { | ||
222 | return array('_route' => 'route4'); | ||
223 | } | ||
224 | |||
225 | } | ||
226 | |||
227 | if (preg_match('#^c\\.example\\.com$#s', $host, $hostMatches)) { | ||
228 | // route5 | ||
229 | if ($pathinfo === '/route5') { | ||
230 | return array('_route' => 'route5'); | ||
231 | } | ||
232 | |||
233 | } | ||
234 | |||
235 | // route6 | ||
236 | if ($pathinfo === '/route6') { | ||
237 | return array('_route' => 'route6'); | ||
238 | } | ||
239 | |||
240 | if (preg_match('#^(?P<var1>[^\\.]++)\\.example\\.com$#s', $host, $hostMatches)) { | ||
241 | if (0 === strpos($pathinfo, '/route1')) { | ||
242 | // route11 | ||
243 | if ($pathinfo === '/route11') { | ||
244 | return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route11')), array ()); | ||
245 | } | ||
246 | |||
247 | // route12 | ||
248 | if ($pathinfo === '/route12') { | ||
249 | return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route12')), array ( 'var1' => 'val',)); | ||
250 | } | ||
251 | |||
252 | // route13 | ||
253 | if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?P<name>[^/]++)$#s', $pathinfo, $matches)) { | ||
254 | return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route13')), array ()); | ||
255 | } | ||
256 | |||
257 | // route14 | ||
258 | if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?P<name>[^/]++)$#s', $pathinfo, $matches)) { | ||
259 | return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route14')), array ( 'var1' => 'val',)); | ||
260 | } | ||
261 | |||
262 | } | ||
263 | |||
264 | } | ||
265 | |||
266 | if (preg_match('#^c\\.example\\.com$#s', $host, $hostMatches)) { | ||
267 | // route15 | ||
268 | if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?P<name>[^/]++)$#s', $pathinfo, $matches)) { | ||
269 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'route15')), array ()); | ||
270 | } | ||
271 | |||
272 | } | ||
273 | |||
274 | if (0 === strpos($pathinfo, '/route1')) { | ||
275 | // route16 | ||
276 | if (0 === strpos($pathinfo, '/route16') && preg_match('#^/route16/(?P<name>[^/]++)$#s', $pathinfo, $matches)) { | ||
277 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',)); | ||
278 | } | ||
279 | |||
280 | // route17 | ||
281 | if ($pathinfo === '/route17') { | ||
282 | return array('_route' => 'route17'); | ||
283 | } | ||
284 | |||
285 | } | ||
286 | |||
287 | if (0 === strpos($pathinfo, '/a')) { | ||
288 | // a | ||
289 | if ($pathinfo === '/a/a...') { | ||
290 | return array('_route' => 'a'); | ||
291 | } | ||
292 | |||
293 | if (0 === strpos($pathinfo, '/a/b')) { | ||
294 | // b | ||
295 | if (preg_match('#^/a/b/(?P<var>[^/]++)$#s', $pathinfo, $matches)) { | ||
296 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ()); | ||
297 | } | ||
298 | |||
299 | // c | ||
300 | if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P<var>[^/]++)$#s', $pathinfo, $matches)) { | ||
301 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ()); | ||
302 | } | ||
303 | |||
304 | } | ||
305 | |||
306 | } | ||
307 | |||
308 | throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException(); | ||
309 | } | ||
310 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.apache b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.apache new file mode 100644 index 00000000..309f2ff0 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.apache | |||
@@ -0,0 +1,7 @@ | |||
1 | # skip "real" requests | ||
2 | RewriteCond %{REQUEST_FILENAME} -f | ||
3 | RewriteRule .* - [QSA,L] | ||
4 | |||
5 | # foo | ||
6 | RewriteCond %{REQUEST_URI} ^/foo$ | ||
7 | RewriteRule .* ap\ p_d\ ev.php [QSA,L,E=_ROUTING_route:foo] | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php new file mode 100644 index 00000000..ad157909 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php | |||
@@ -0,0 +1,340 @@ | |||
1 | <?php | ||
2 | |||
3 | use Symfony\Component\Routing\Exception\MethodNotAllowedException; | ||
4 | use Symfony\Component\Routing\Exception\ResourceNotFoundException; | ||
5 | use Symfony\Component\Routing\RequestContext; | ||
6 | |||
7 | /** | ||
8 | * ProjectUrlMatcher | ||
9 | * | ||
10 | * This class has been auto-generated | ||
11 | * by the Symfony Routing Component. | ||
12 | */ | ||
13 | class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher | ||
14 | { | ||
15 | /** | ||
16 | * Constructor. | ||
17 | */ | ||
18 | public function __construct(RequestContext $context) | ||
19 | { | ||
20 | $this->context = $context; | ||
21 | } | ||
22 | |||
23 | public function match($pathinfo) | ||
24 | { | ||
25 | $allow = array(); | ||
26 | $pathinfo = rawurldecode($pathinfo); | ||
27 | |||
28 | // foo | ||
29 | if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?P<bar>baz|symfony)$#s', $pathinfo, $matches)) { | ||
30 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',)); | ||
31 | } | ||
32 | |||
33 | if (0 === strpos($pathinfo, '/bar')) { | ||
34 | // bar | ||
35 | if (preg_match('#^/bar/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) { | ||
36 | if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) { | ||
37 | $allow = array_merge($allow, array('GET', 'HEAD')); | ||
38 | goto not_bar; | ||
39 | } | ||
40 | |||
41 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ()); | ||
42 | } | ||
43 | not_bar: | ||
44 | |||
45 | // barhead | ||
46 | if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) { | ||
47 | if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) { | ||
48 | $allow = array_merge($allow, array('GET', 'HEAD')); | ||
49 | goto not_barhead; | ||
50 | } | ||
51 | |||
52 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ()); | ||
53 | } | ||
54 | not_barhead: | ||
55 | |||
56 | } | ||
57 | |||
58 | if (0 === strpos($pathinfo, '/test')) { | ||
59 | if (0 === strpos($pathinfo, '/test/baz')) { | ||
60 | // baz | ||
61 | if ($pathinfo === '/test/baz') { | ||
62 | return array('_route' => 'baz'); | ||
63 | } | ||
64 | |||
65 | // baz2 | ||
66 | if ($pathinfo === '/test/baz.html') { | ||
67 | return array('_route' => 'baz2'); | ||
68 | } | ||
69 | |||
70 | // baz3 | ||
71 | if (rtrim($pathinfo, '/') === '/test/baz3') { | ||
72 | if (substr($pathinfo, -1) !== '/') { | ||
73 | return $this->redirect($pathinfo.'/', 'baz3'); | ||
74 | } | ||
75 | |||
76 | return array('_route' => 'baz3'); | ||
77 | } | ||
78 | |||
79 | } | ||
80 | |||
81 | // baz4 | ||
82 | if (preg_match('#^/test/(?P<foo>[^/]++)/?$#s', $pathinfo, $matches)) { | ||
83 | if (substr($pathinfo, -1) !== '/') { | ||
84 | return $this->redirect($pathinfo.'/', 'baz4'); | ||
85 | } | ||
86 | |||
87 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ()); | ||
88 | } | ||
89 | |||
90 | // baz5 | ||
91 | if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) { | ||
92 | if ($this->context->getMethod() != 'POST') { | ||
93 | $allow[] = 'POST'; | ||
94 | goto not_baz5; | ||
95 | } | ||
96 | |||
97 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ()); | ||
98 | } | ||
99 | not_baz5: | ||
100 | |||
101 | // baz.baz6 | ||
102 | if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) { | ||
103 | if ($this->context->getMethod() != 'PUT') { | ||
104 | $allow[] = 'PUT'; | ||
105 | goto not_bazbaz6; | ||
106 | } | ||
107 | |||
108 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ()); | ||
109 | } | ||
110 | not_bazbaz6: | ||
111 | |||
112 | } | ||
113 | |||
114 | // foofoo | ||
115 | if ($pathinfo === '/foofoo') { | ||
116 | return array ( 'def' => 'test', '_route' => 'foofoo',); | ||
117 | } | ||
118 | |||
119 | // quoter | ||
120 | if (preg_match('#^/(?P<quoter>[\']+)$#s', $pathinfo, $matches)) { | ||
121 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'quoter')), array ()); | ||
122 | } | ||
123 | |||
124 | // space | ||
125 | if ($pathinfo === '/spa ce') { | ||
126 | return array('_route' => 'space'); | ||
127 | } | ||
128 | |||
129 | if (0 === strpos($pathinfo, '/a')) { | ||
130 | if (0 === strpos($pathinfo, '/a/b\'b')) { | ||
131 | // foo1 | ||
132 | if (preg_match('#^/a/b\'b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) { | ||
133 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo1')), array ()); | ||
134 | } | ||
135 | |||
136 | // bar1 | ||
137 | if (preg_match('#^/a/b\'b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) { | ||
138 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar1')), array ()); | ||
139 | } | ||
140 | |||
141 | } | ||
142 | |||
143 | // overridden | ||
144 | if (preg_match('#^/a/(?P<var>.*)$#s', $pathinfo, $matches)) { | ||
145 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'overridden')), array ()); | ||
146 | } | ||
147 | |||
148 | if (0 === strpos($pathinfo, '/a/b\'b')) { | ||
149 | // foo2 | ||
150 | if (preg_match('#^/a/b\'b/(?P<foo1>[^/]++)$#s', $pathinfo, $matches)) { | ||
151 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo2')), array ()); | ||
152 | } | ||
153 | |||
154 | // bar2 | ||
155 | if (preg_match('#^/a/b\'b/(?P<bar1>[^/]++)$#s', $pathinfo, $matches)) { | ||
156 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar2')), array ()); | ||
157 | } | ||
158 | |||
159 | } | ||
160 | |||
161 | } | ||
162 | |||
163 | if (0 === strpos($pathinfo, '/multi')) { | ||
164 | // helloWorld | ||
165 | if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P<who>[^/]++))?$#s', $pathinfo, $matches)) { | ||
166 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'helloWorld')), array ( 'who' => 'World!',)); | ||
167 | } | ||
168 | |||
169 | // overridden2 | ||
170 | if ($pathinfo === '/multi/new') { | ||
171 | return array('_route' => 'overridden2'); | ||
172 | } | ||
173 | |||
174 | // hey | ||
175 | if (rtrim($pathinfo, '/') === '/multi/hey') { | ||
176 | if (substr($pathinfo, -1) !== '/') { | ||
177 | return $this->redirect($pathinfo.'/', 'hey'); | ||
178 | } | ||
179 | |||
180 | return array('_route' => 'hey'); | ||
181 | } | ||
182 | |||
183 | } | ||
184 | |||
185 | // foo3 | ||
186 | if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) { | ||
187 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo3')), array ()); | ||
188 | } | ||
189 | |||
190 | // bar3 | ||
191 | if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) { | ||
192 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar3')), array ()); | ||
193 | } | ||
194 | |||
195 | if (0 === strpos($pathinfo, '/aba')) { | ||
196 | // ababa | ||
197 | if ($pathinfo === '/ababa') { | ||
198 | return array('_route' => 'ababa'); | ||
199 | } | ||
200 | |||
201 | // foo4 | ||
202 | if (preg_match('#^/aba/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) { | ||
203 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo4')), array ()); | ||
204 | } | ||
205 | |||
206 | } | ||
207 | |||
208 | $host = $this->context->getHost(); | ||
209 | |||
210 | if (preg_match('#^a\\.example\\.com$#s', $host, $hostMatches)) { | ||
211 | // route1 | ||
212 | if ($pathinfo === '/route1') { | ||
213 | return array('_route' => 'route1'); | ||
214 | } | ||
215 | |||
216 | // route2 | ||
217 | if ($pathinfo === '/c2/route2') { | ||
218 | return array('_route' => 'route2'); | ||
219 | } | ||
220 | |||
221 | } | ||
222 | |||
223 | if (preg_match('#^b\\.example\\.com$#s', $host, $hostMatches)) { | ||
224 | // route3 | ||
225 | if ($pathinfo === '/c2/route3') { | ||
226 | return array('_route' => 'route3'); | ||
227 | } | ||
228 | |||
229 | } | ||
230 | |||
231 | if (preg_match('#^a\\.example\\.com$#s', $host, $hostMatches)) { | ||
232 | // route4 | ||
233 | if ($pathinfo === '/route4') { | ||
234 | return array('_route' => 'route4'); | ||
235 | } | ||
236 | |||
237 | } | ||
238 | |||
239 | if (preg_match('#^c\\.example\\.com$#s', $host, $hostMatches)) { | ||
240 | // route5 | ||
241 | if ($pathinfo === '/route5') { | ||
242 | return array('_route' => 'route5'); | ||
243 | } | ||
244 | |||
245 | } | ||
246 | |||
247 | // route6 | ||
248 | if ($pathinfo === '/route6') { | ||
249 | return array('_route' => 'route6'); | ||
250 | } | ||
251 | |||
252 | if (preg_match('#^(?P<var1>[^\\.]++)\\.example\\.com$#s', $host, $hostMatches)) { | ||
253 | if (0 === strpos($pathinfo, '/route1')) { | ||
254 | // route11 | ||
255 | if ($pathinfo === '/route11') { | ||
256 | return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route11')), array ()); | ||
257 | } | ||
258 | |||
259 | // route12 | ||
260 | if ($pathinfo === '/route12') { | ||
261 | return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route12')), array ( 'var1' => 'val',)); | ||
262 | } | ||
263 | |||
264 | // route13 | ||
265 | if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?P<name>[^/]++)$#s', $pathinfo, $matches)) { | ||
266 | return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route13')), array ()); | ||
267 | } | ||
268 | |||
269 | // route14 | ||
270 | if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?P<name>[^/]++)$#s', $pathinfo, $matches)) { | ||
271 | return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route14')), array ( 'var1' => 'val',)); | ||
272 | } | ||
273 | |||
274 | } | ||
275 | |||
276 | } | ||
277 | |||
278 | if (preg_match('#^c\\.example\\.com$#s', $host, $hostMatches)) { | ||
279 | // route15 | ||
280 | if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?P<name>[^/]++)$#s', $pathinfo, $matches)) { | ||
281 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'route15')), array ()); | ||
282 | } | ||
283 | |||
284 | } | ||
285 | |||
286 | if (0 === strpos($pathinfo, '/route1')) { | ||
287 | // route16 | ||
288 | if (0 === strpos($pathinfo, '/route16') && preg_match('#^/route16/(?P<name>[^/]++)$#s', $pathinfo, $matches)) { | ||
289 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',)); | ||
290 | } | ||
291 | |||
292 | // route17 | ||
293 | if ($pathinfo === '/route17') { | ||
294 | return array('_route' => 'route17'); | ||
295 | } | ||
296 | |||
297 | } | ||
298 | |||
299 | if (0 === strpos($pathinfo, '/a')) { | ||
300 | // a | ||
301 | if ($pathinfo === '/a/a...') { | ||
302 | return array('_route' => 'a'); | ||
303 | } | ||
304 | |||
305 | if (0 === strpos($pathinfo, '/a/b')) { | ||
306 | // b | ||
307 | if (preg_match('#^/a/b/(?P<var>[^/]++)$#s', $pathinfo, $matches)) { | ||
308 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ()); | ||
309 | } | ||
310 | |||
311 | // c | ||
312 | if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P<var>[^/]++)$#s', $pathinfo, $matches)) { | ||
313 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ()); | ||
314 | } | ||
315 | |||
316 | } | ||
317 | |||
318 | } | ||
319 | |||
320 | // secure | ||
321 | if ($pathinfo === '/secure') { | ||
322 | if ($this->context->getScheme() !== 'https') { | ||
323 | return $this->redirect($pathinfo, 'secure', 'https'); | ||
324 | } | ||
325 | |||
326 | return array('_route' => 'secure'); | ||
327 | } | ||
328 | |||
329 | // nonsecure | ||
330 | if ($pathinfo === '/nonsecure') { | ||
331 | if ($this->context->getScheme() !== 'http') { | ||
332 | return $this->redirect($pathinfo, 'nonsecure', 'http'); | ||
333 | } | ||
334 | |||
335 | return array('_route' => 'nonsecure'); | ||
336 | } | ||
337 | |||
338 | throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException(); | ||
339 | } | ||
340 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php new file mode 100644 index 00000000..f2f642eb --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php | |||
@@ -0,0 +1,43 @@ | |||
1 | <?php | ||
2 | |||
3 | use Symfony\Component\Routing\Exception\MethodNotAllowedException; | ||
4 | use Symfony\Component\Routing\Exception\ResourceNotFoundException; | ||
5 | use Symfony\Component\Routing\RequestContext; | ||
6 | |||
7 | /** | ||
8 | * ProjectUrlMatcher | ||
9 | * | ||
10 | * This class has been auto-generated | ||
11 | * by the Symfony Routing Component. | ||
12 | */ | ||
13 | class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher | ||
14 | { | ||
15 | /** | ||
16 | * Constructor. | ||
17 | */ | ||
18 | public function __construct(RequestContext $context) | ||
19 | { | ||
20 | $this->context = $context; | ||
21 | } | ||
22 | |||
23 | public function match($pathinfo) | ||
24 | { | ||
25 | $allow = array(); | ||
26 | $pathinfo = rawurldecode($pathinfo); | ||
27 | |||
28 | if (0 === strpos($pathinfo, '/rootprefix')) { | ||
29 | // static | ||
30 | if ($pathinfo === '/rootprefix/test') { | ||
31 | return array('_route' => 'static'); | ||
32 | } | ||
33 | |||
34 | // dynamic | ||
35 | if (preg_match('#^/rootprefix/(?P<var>[^/]++)$#s', $pathinfo, $matches)) { | ||
36 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'dynamic')), array ()); | ||
37 | } | ||
38 | |||
39 | } | ||
40 | |||
41 | throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException(); | ||
42 | } | ||
43 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/empty.yml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/empty.yml new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/empty.yml | |||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/foo.xml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/foo.xml new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/foo.xml | |||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/foo1.xml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/foo1.xml new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/foo1.xml | |||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/incomplete.yml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/incomplete.yml new file mode 100644 index 00000000..df64d324 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/incomplete.yml | |||
@@ -0,0 +1,2 @@ | |||
1 | blog_show: | ||
2 | defaults: { _controller: MyBlogBundle:Blog:show } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/missing_id.xml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/missing_id.xml new file mode 100644 index 00000000..4ea4115f --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/missing_id.xml | |||
@@ -0,0 +1,8 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
2 | |||
3 | <routes xmlns="http://symfony.com/schema/routing" | ||
4 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
5 | xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> | ||
6 | |||
7 | <route path="/test"></route> | ||
8 | </routes> | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/missing_path.xml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/missing_path.xml new file mode 100644 index 00000000..ef5bc088 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/missing_path.xml | |||
@@ -0,0 +1,8 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
2 | |||
3 | <routes xmlns="http://symfony.com/schema/routing" | ||
4 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
5 | xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> | ||
6 | |||
7 | <route id="myroute"></route> | ||
8 | </routes> | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/namespaceprefix.xml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/namespaceprefix.xml new file mode 100644 index 00000000..bdd6a473 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/namespaceprefix.xml | |||
@@ -0,0 +1,13 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
2 | |||
3 | <r:routes xmlns:r="http://symfony.com/schema/routing" | ||
4 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
5 | xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> | ||
6 | |||
7 | <r:route id="blog_show" path="/blog/{slug}" host="{_locale}.example.com"> | ||
8 | <r:default key="_controller">MyBundle:Blog:show</r:default> | ||
9 | <requirement xmlns="http://symfony.com/schema/routing" key="slug">\w+</requirement> | ||
10 | <r2:requirement xmlns:r2="http://symfony.com/schema/routing" key="_locale">en|fr|de</r2:requirement> | ||
11 | <r:option key="compiler_class">RouteCompiler</r:option> | ||
12 | </r:route> | ||
13 | </r:routes> | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonesense_resource_plus_path.yml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonesense_resource_plus_path.yml new file mode 100644 index 00000000..a3e94737 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonesense_resource_plus_path.yml | |||
@@ -0,0 +1,3 @@ | |||
1 | blog_show: | ||
2 | resource: validpattern.yml | ||
3 | path: /test | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonesense_type_without_resource.yml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonesense_type_without_resource.yml new file mode 100644 index 00000000..547cda3b --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonesense_type_without_resource.yml | |||
@@ -0,0 +1,3 @@ | |||
1 | blog_show: | ||
2 | path: /blog/{slug} | ||
3 | type: custom | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalid.xml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalid.xml new file mode 100644 index 00000000..755e4430 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalid.xml | |||
@@ -0,0 +1,11 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
2 | |||
3 | <routes xmlns="http://symfony.com/schema/routing" | ||
4 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
5 | xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> | ||
6 | |||
7 | <route id="blog_show" path="/blog/{slug}"> | ||
8 | <default key="_controller">MyBundle:Blog:show</default> | ||
9 | <requirement key="_method">GET</requirement> | ||
10 | <!-- </route> --> | ||
11 | </routes> | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalid.yml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalid.yml new file mode 100644 index 00000000..257cc564 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalid.yml | |||
@@ -0,0 +1 @@ | |||
foo | |||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalid2.yml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalid2.yml new file mode 100644 index 00000000..cfa9992b --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalid2.yml | |||
@@ -0,0 +1 @@ | |||
route: string | |||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalidkeys.yml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalidkeys.yml new file mode 100644 index 00000000..015e270f --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalidkeys.yml | |||
@@ -0,0 +1,3 @@ | |||
1 | someroute: | ||
2 | resource: path/to/some.yml | ||
3 | name_prefix: test_ | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalidnode.xml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalidnode.xml new file mode 100644 index 00000000..863ef03b --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalidnode.xml | |||
@@ -0,0 +1,8 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
2 | |||
3 | <routes xmlns="http://symfony.com/schema/routing" | ||
4 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
5 | xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> | ||
6 | |||
7 | <foo>bar</foo> | ||
8 | </routes> | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalidroute.xml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalidroute.xml new file mode 100644 index 00000000..a46961ee --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalidroute.xml | |||
@@ -0,0 +1,13 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
2 | |||
3 | <routes xmlns="http://symfony.com/schema/routing" | ||
4 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
5 | xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> | ||
6 | |||
7 | <route id="blog_show" path="/blog/{slug}"> | ||
8 | <default key="_controller">MyBundle:Blog:show</default> | ||
9 | <requirement key="_method">GET</requirement> | ||
10 | <option key="compiler_class">RouteCompiler</option> | ||
11 | <foo key="bar">baz</foo> | ||
12 | </route> | ||
13 | </routes> | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/special_route_name.yml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/special_route_name.yml new file mode 100644 index 00000000..78be239a --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/special_route_name.yml | |||
@@ -0,0 +1,2 @@ | |||
1 | "#$péß^a|": | ||
2 | path: "true" | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validpattern.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validpattern.php new file mode 100644 index 00000000..b8bbbb5f --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validpattern.php | |||
@@ -0,0 +1,23 @@ | |||
1 | <?php | ||
2 | use Symfony\Component\Routing\RouteCollection; | ||
3 | use Symfony\Component\Routing\Route; | ||
4 | |||
5 | $collection = new RouteCollection(); | ||
6 | $collection->add('blog_show', new Route( | ||
7 | '/blog/{slug}', | ||
8 | array('_controller' => 'MyBlogBundle:Blog:show'), | ||
9 | array('locale' => '\w+'), | ||
10 | array('compiler_class' => 'RouteCompiler'), | ||
11 | '{locale}.example.com', | ||
12 | array('https'), | ||
13 | array('GET','POST','put','OpTiOnS') | ||
14 | )); | ||
15 | $collection->add('blog_show_legacy', new Route( | ||
16 | '/blog/{slug}', | ||
17 | array('_controller' => 'MyBlogBundle:Blog:show'), | ||
18 | array('_method' => 'GET|POST|put|OpTiOnS', '_scheme' => 'https', 'locale' => '\w+',), | ||
19 | array('compiler_class' => 'RouteCompiler'), | ||
20 | '{locale}.example.com' | ||
21 | )); | ||
22 | |||
23 | return $collection; | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml new file mode 100644 index 00000000..b9f22347 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml | |||
@@ -0,0 +1,21 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
2 | |||
3 | <routes xmlns="http://symfony.com/schema/routing" | ||
4 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
5 | xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> | ||
6 | |||
7 | <route id="blog_show" path="/blog/{slug}" host="{locale}.example.com" methods="GET|POST put,OpTiOnS" schemes="hTTps"> | ||
8 | <default key="_controller">MyBundle:Blog:show</default> | ||
9 | <requirement key="locale">\w+</requirement> | ||
10 | <option key="compiler_class">RouteCompiler</option> | ||
11 | </route> | ||
12 | |||
13 | <route id="blog_show_legacy" pattern="/blog/{slug}" host="{locale}.example.com"> | ||
14 | <default key="_controller">MyBundle:Blog:show</default> | ||
15 | <default key="slug" xsi:nil="true" /> | ||
16 | <requirement key="_method">GET|POST|put|OpTiOnS</requirement> | ||
17 | <requirement key="_scheme">hTTps</requirement> | ||
18 | <requirement key="locale">\w+</requirement> | ||
19 | <option key="compiler_class">RouteCompiler</option> | ||
20 | </route> | ||
21 | </routes> | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validpattern.yml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validpattern.yml new file mode 100644 index 00000000..4ada8832 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validpattern.yml | |||
@@ -0,0 +1,17 @@ | |||
1 | blog_show: | ||
2 | path: /blog/{slug} | ||
3 | defaults: { _controller: "MyBundle:Blog:show" } | ||
4 | host: "{locale}.example.com" | ||
5 | requirements: { 'locale': '\w+' } | ||
6 | methods: ['GET','POST','put','OpTiOnS'] | ||
7 | schemes: ['https'] | ||
8 | options: | ||
9 | compiler_class: RouteCompiler | ||
10 | |||
11 | blog_show_legacy: | ||
12 | pattern: /blog/{slug} | ||
13 | defaults: { _controller: "MyBundle:Blog:show" } | ||
14 | host: "{locale}.example.com" | ||
15 | requirements: { '_method': 'GET|POST|put|OpTiOnS', _scheme: https, 'locale': '\w+' } | ||
16 | options: | ||
17 | compiler_class: RouteCompiler | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validresource.xml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validresource.xml new file mode 100644 index 00000000..295c3cc4 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validresource.xml | |||
@@ -0,0 +1,12 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
2 | |||
3 | <routes xmlns="http://symfony.com/schema/routing" | ||
4 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
5 | xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> | ||
6 | |||
7 | <import resource="validpattern.xml" prefix="/{foo}" host=""> | ||
8 | <default key="foo">123</default> | ||
9 | <requirement key="foo">\d+</requirement> | ||
10 | <option key="foo">bar</option> | ||
11 | </import> | ||
12 | </routes> | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validresource.yml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validresource.yml new file mode 100644 index 00000000..495ed854 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validresource.yml | |||
@@ -0,0 +1,7 @@ | |||
1 | _blog: | ||
2 | resource: validpattern.yml | ||
3 | prefix: /{foo} | ||
4 | defaults: { 'foo': '123' } | ||
5 | requirements: { 'foo': '\d+' } | ||
6 | options: { 'foo': 'bar' } | ||
7 | host: "" | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/withdoctype.xml b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/withdoctype.xml new file mode 100644 index 00000000..f217d5bc --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/withdoctype.xml | |||
@@ -0,0 +1,3 @@ | |||
1 | <?xml version="1.0"?> | ||
2 | <!DOCTYPE foo> | ||
3 | <foo></foo> | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php new file mode 100644 index 00000000..ab5f4cda --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php | |||
@@ -0,0 +1,117 @@ | |||
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\Generator\Dumper; | ||
13 | |||
14 | use Symfony\Component\Routing\RouteCollection; | ||
15 | use Symfony\Component\Routing\Route; | ||
16 | use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper; | ||
17 | use Symfony\Component\Routing\RequestContext; | ||
18 | |||
19 | class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase | ||
20 | { | ||
21 | /** | ||
22 | * @var RouteCollection | ||
23 | */ | ||
24 | private $routeCollection; | ||
25 | |||
26 | /** | ||
27 | * @var PhpGeneratorDumper | ||
28 | */ | ||
29 | private $generatorDumper; | ||
30 | |||
31 | /** | ||
32 | * @var string | ||
33 | */ | ||
34 | private $testTmpFilepath; | ||
35 | |||
36 | protected function setUp() | ||
37 | { | ||
38 | parent::setUp(); | ||
39 | |||
40 | $this->routeCollection = new RouteCollection(); | ||
41 | $this->generatorDumper = new PhpGeneratorDumper($this->routeCollection); | ||
42 | $this->testTmpFilepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'php_generator.php'; | ||
43 | @unlink($this->testTmpFilepath); | ||
44 | } | ||
45 | |||
46 | protected function tearDown() | ||
47 | { | ||
48 | parent::tearDown(); | ||
49 | |||
50 | @unlink($this->testTmpFilepath); | ||
51 | |||
52 | $this->routeCollection = null; | ||
53 | $this->generatorDumper = null; | ||
54 | $this->testTmpFilepath = null; | ||
55 | } | ||
56 | |||
57 | public function testDumpWithRoutes() | ||
58 | { | ||
59 | $this->routeCollection->add('Test', new Route('/testing/{foo}')); | ||
60 | $this->routeCollection->add('Test2', new Route('/testing2')); | ||
61 | |||
62 | file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump()); | ||
63 | include ($this->testTmpFilepath); | ||
64 | |||
65 | $projectUrlGenerator = new \ProjectUrlGenerator(new RequestContext('/app.php')); | ||
66 | |||
67 | $absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), true); | ||
68 | $absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), true); | ||
69 | $relativeUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), false); | ||
70 | $relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), false); | ||
71 | |||
72 | $this->assertEquals($absoluteUrlWithParameter, 'http://localhost/app.php/testing/bar'); | ||
73 | $this->assertEquals($absoluteUrlWithoutParameter, 'http://localhost/app.php/testing2'); | ||
74 | $this->assertEquals($relativeUrlWithParameter, '/app.php/testing/bar'); | ||
75 | $this->assertEquals($relativeUrlWithoutParameter, '/app.php/testing2'); | ||
76 | } | ||
77 | |||
78 | /** | ||
79 | * @expectedException \InvalidArgumentException | ||
80 | */ | ||
81 | public function testDumpWithoutRoutes() | ||
82 | { | ||
83 | file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'WithoutRoutesUrlGenerator'))); | ||
84 | include ($this->testTmpFilepath); | ||
85 | |||
86 | $projectUrlGenerator = new \WithoutRoutesUrlGenerator(new RequestContext('/app.php')); | ||
87 | |||
88 | $projectUrlGenerator->generate('Test', array()); | ||
89 | } | ||
90 | |||
91 | /** | ||
92 | * @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException | ||
93 | */ | ||
94 | public function testGenerateNonExistingRoute() | ||
95 | { | ||
96 | $this->routeCollection->add('Test', new Route('/test')); | ||
97 | |||
98 | file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'NonExistingRoutesUrlGenerator'))); | ||
99 | include ($this->testTmpFilepath); | ||
100 | |||
101 | $projectUrlGenerator = new \NonExistingRoutesUrlGenerator(new RequestContext()); | ||
102 | $url = $projectUrlGenerator->generate('NonExisting', array()); | ||
103 | } | ||
104 | |||
105 | public function testDumpForRouteWithDefaults() | ||
106 | { | ||
107 | $this->routeCollection->add('Test', new Route('/testing/{foo}', array('foo' => 'bar'))); | ||
108 | |||
109 | file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'DefaultRoutesUrlGenerator'))); | ||
110 | include ($this->testTmpFilepath); | ||
111 | |||
112 | $projectUrlGenerator = new \DefaultRoutesUrlGenerator(new RequestContext()); | ||
113 | $url = $projectUrlGenerator->generate('Test', array()); | ||
114 | |||
115 | $this->assertEquals($url, '/testing'); | ||
116 | } | ||
117 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php new file mode 100644 index 00000000..5f8ef491 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php | |||
@@ -0,0 +1,635 @@ | |||
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\Generator; | ||
13 | |||
14 | use Symfony\Component\Routing\RouteCollection; | ||
15 | use Symfony\Component\Routing\Route; | ||
16 | use Symfony\Component\Routing\Generator\UrlGenerator; | ||
17 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
18 | use Symfony\Component\Routing\RequestContext; | ||
19 | |||
20 | class UrlGeneratorTest extends \PHPUnit_Framework_TestCase | ||
21 | { | ||
22 | public function testAbsoluteUrlWithPort80() | ||
23 | { | ||
24 | $routes = $this->getRoutes('test', new Route('/testing')); | ||
25 | $url = $this->getGenerator($routes)->generate('test', array(), true); | ||
26 | |||
27 | $this->assertEquals('http://localhost/app.php/testing', $url); | ||
28 | } | ||
29 | |||
30 | public function testAbsoluteSecureUrlWithPort443() | ||
31 | { | ||
32 | $routes = $this->getRoutes('test', new Route('/testing')); | ||
33 | $url = $this->getGenerator($routes, array('scheme' => 'https'))->generate('test', array(), true); | ||
34 | |||
35 | $this->assertEquals('https://localhost/app.php/testing', $url); | ||
36 | } | ||
37 | |||
38 | public function testAbsoluteUrlWithNonStandardPort() | ||
39 | { | ||
40 | $routes = $this->getRoutes('test', new Route('/testing')); | ||
41 | $url = $this->getGenerator($routes, array('httpPort' => 8080))->generate('test', array(), true); | ||
42 | |||
43 | $this->assertEquals('http://localhost:8080/app.php/testing', $url); | ||
44 | } | ||
45 | |||
46 | public function testAbsoluteSecureUrlWithNonStandardPort() | ||
47 | { | ||
48 | $routes = $this->getRoutes('test', new Route('/testing')); | ||
49 | $url = $this->getGenerator($routes, array('httpsPort' => 8080, 'scheme' => 'https'))->generate('test', array(), true); | ||
50 | |||
51 | $this->assertEquals('https://localhost:8080/app.php/testing', $url); | ||
52 | } | ||
53 | |||
54 | public function testRelativeUrlWithoutParameters() | ||
55 | { | ||
56 | $routes = $this->getRoutes('test', new Route('/testing')); | ||
57 | $url = $this->getGenerator($routes)->generate('test', array(), false); | ||
58 | |||
59 | $this->assertEquals('/app.php/testing', $url); | ||
60 | } | ||
61 | |||
62 | public function testRelativeUrlWithParameter() | ||
63 | { | ||
64 | $routes = $this->getRoutes('test', new Route('/testing/{foo}')); | ||
65 | $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), false); | ||
66 | |||
67 | $this->assertEquals('/app.php/testing/bar', $url); | ||
68 | } | ||
69 | |||
70 | public function testRelativeUrlWithNullParameter() | ||
71 | { | ||
72 | $routes = $this->getRoutes('test', new Route('/testing.{format}', array('format' => null))); | ||
73 | $url = $this->getGenerator($routes)->generate('test', array(), false); | ||
74 | |||
75 | $this->assertEquals('/app.php/testing', $url); | ||
76 | } | ||
77 | |||
78 | /** | ||
79 | * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException | ||
80 | */ | ||
81 | public function testRelativeUrlWithNullParameterButNotOptional() | ||
82 | { | ||
83 | $routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', array('foo' => null))); | ||
84 | // This must raise an exception because the default requirement for "foo" is "[^/]+" which is not met with these params. | ||
85 | // Generating path "/testing//bar" would be wrong as matching this route would fail. | ||
86 | $this->getGenerator($routes)->generate('test', array(), false); | ||
87 | } | ||
88 | |||
89 | public function testRelativeUrlWithOptionalZeroParameter() | ||
90 | { | ||
91 | $routes = $this->getRoutes('test', new Route('/testing/{page}')); | ||
92 | $url = $this->getGenerator($routes)->generate('test', array('page' => 0), false); | ||
93 | |||
94 | $this->assertEquals('/app.php/testing/0', $url); | ||
95 | } | ||
96 | |||
97 | public function testNotPassedOptionalParameterInBetween() | ||
98 | { | ||
99 | $routes = $this->getRoutes('test', new Route('/{slug}/{page}', array('slug' => 'index', 'page' => 0))); | ||
100 | $this->assertSame('/app.php/index/1', $this->getGenerator($routes)->generate('test', array('page' => 1))); | ||
101 | $this->assertSame('/app.php/', $this->getGenerator($routes)->generate('test')); | ||
102 | } | ||
103 | |||
104 | public function testRelativeUrlWithExtraParameters() | ||
105 | { | ||
106 | $routes = $this->getRoutes('test', new Route('/testing')); | ||
107 | $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), false); | ||
108 | |||
109 | $this->assertEquals('/app.php/testing?foo=bar', $url); | ||
110 | } | ||
111 | |||
112 | public function testAbsoluteUrlWithExtraParameters() | ||
113 | { | ||
114 | $routes = $this->getRoutes('test', new Route('/testing')); | ||
115 | $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true); | ||
116 | |||
117 | $this->assertEquals('http://localhost/app.php/testing?foo=bar', $url); | ||
118 | } | ||
119 | |||
120 | public function testUrlWithNullExtraParameters() | ||
121 | { | ||
122 | $routes = $this->getRoutes('test', new Route('/testing')); | ||
123 | $url = $this->getGenerator($routes)->generate('test', array('foo' => null), true); | ||
124 | |||
125 | $this->assertEquals('http://localhost/app.php/testing', $url); | ||
126 | } | ||
127 | |||
128 | public function testUrlWithExtraParametersFromGlobals() | ||
129 | { | ||
130 | $routes = $this->getRoutes('test', new Route('/testing')); | ||
131 | $generator = $this->getGenerator($routes); | ||
132 | $context = new RequestContext('/app.php'); | ||
133 | $context->setParameter('bar', 'bar'); | ||
134 | $generator->setContext($context); | ||
135 | $url = $generator->generate('test', array('foo' => 'bar')); | ||
136 | |||
137 | $this->assertEquals('/app.php/testing?foo=bar', $url); | ||
138 | } | ||
139 | |||
140 | public function testUrlWithGlobalParameter() | ||
141 | { | ||
142 | $routes = $this->getRoutes('test', new Route('/testing/{foo}')); | ||
143 | $generator = $this->getGenerator($routes); | ||
144 | $context = new RequestContext('/app.php'); | ||
145 | $context->setParameter('foo', 'bar'); | ||
146 | $generator->setContext($context); | ||
147 | $url = $generator->generate('test', array()); | ||
148 | |||
149 | $this->assertEquals('/app.php/testing/bar', $url); | ||
150 | } | ||
151 | |||
152 | public function testGlobalParameterHasHigherPriorityThanDefault() | ||
153 | { | ||
154 | $routes = $this->getRoutes('test', new Route('/{_locale}', array('_locale' => 'en'))); | ||
155 | $generator = $this->getGenerator($routes); | ||
156 | $context = new RequestContext('/app.php'); | ||
157 | $context->setParameter('_locale', 'de'); | ||
158 | $generator->setContext($context); | ||
159 | $url = $generator->generate('test', array()); | ||
160 | |||
161 | $this->assertSame('/app.php/de', $url); | ||
162 | } | ||
163 | |||
164 | /** | ||
165 | * @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException | ||
166 | */ | ||
167 | public function testGenerateWithoutRoutes() | ||
168 | { | ||
169 | $routes = $this->getRoutes('foo', new Route('/testing/{foo}')); | ||
170 | $this->getGenerator($routes)->generate('test', array(), true); | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * @expectedException \Symfony\Component\Routing\Exception\MissingMandatoryParametersException | ||
175 | */ | ||
176 | public function testGenerateForRouteWithoutMandatoryParameter() | ||
177 | { | ||
178 | $routes = $this->getRoutes('test', new Route('/testing/{foo}')); | ||
179 | $this->getGenerator($routes)->generate('test', array(), true); | ||
180 | } | ||
181 | |||
182 | /** | ||
183 | * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException | ||
184 | */ | ||
185 | public function testGenerateForRouteWithInvalidOptionalParameter() | ||
186 | { | ||
187 | $routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+'))); | ||
188 | $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true); | ||
189 | } | ||
190 | |||
191 | /** | ||
192 | * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException | ||
193 | */ | ||
194 | public function testGenerateForRouteWithInvalidParameter() | ||
195 | { | ||
196 | $routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => '1|2'))); | ||
197 | $this->getGenerator($routes)->generate('test', array('foo' => '0'), true); | ||
198 | } | ||
199 | |||
200 | public function testGenerateForRouteWithInvalidOptionalParameterNonStrict() | ||
201 | { | ||
202 | $routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+'))); | ||
203 | $generator = $this->getGenerator($routes); | ||
204 | $generator->setStrictRequirements(false); | ||
205 | $this->assertNull($generator->generate('test', array('foo' => 'bar'), true)); | ||
206 | } | ||
207 | |||
208 | public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLogger() | ||
209 | { | ||
210 | if (!interface_exists('Psr\Log\LoggerInterface')) { | ||
211 | $this->markTestSkipped('The "psr/log" package is not available'); | ||
212 | } | ||
213 | |||
214 | $routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+'))); | ||
215 | $logger = $this->getMock('Psr\Log\LoggerInterface'); | ||
216 | $logger->expects($this->once()) | ||
217 | ->method('error'); | ||
218 | $generator = $this->getGenerator($routes, array(), $logger); | ||
219 | $generator->setStrictRequirements(false); | ||
220 | $this->assertNull($generator->generate('test', array('foo' => 'bar'), true)); | ||
221 | } | ||
222 | |||
223 | public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsCheck() | ||
224 | { | ||
225 | $routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+'))); | ||
226 | $generator = $this->getGenerator($routes); | ||
227 | $generator->setStrictRequirements(null); | ||
228 | $this->assertSame('/app.php/testing/bar', $generator->generate('test', array('foo' => 'bar'))); | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException | ||
233 | */ | ||
234 | public function testGenerateForRouteWithInvalidMandatoryParameter() | ||
235 | { | ||
236 | $routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => 'd+'))); | ||
237 | $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true); | ||
238 | } | ||
239 | |||
240 | /** | ||
241 | * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException | ||
242 | */ | ||
243 | public function testRequiredParamAndEmptyPassed() | ||
244 | { | ||
245 | $routes = $this->getRoutes('test', new Route('/{slug}', array(), array('slug' => '.+'))); | ||
246 | $this->getGenerator($routes)->generate('test', array('slug' => '')); | ||
247 | } | ||
248 | |||
249 | public function testSchemeRequirementDoesNothingIfSameCurrentScheme() | ||
250 | { | ||
251 | $routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'http'))); | ||
252 | $this->assertEquals('/app.php/', $this->getGenerator($routes)->generate('test')); | ||
253 | |||
254 | $routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'https'))); | ||
255 | $this->assertEquals('/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test')); | ||
256 | } | ||
257 | |||
258 | public function testSchemeRequirementForcesAbsoluteUrl() | ||
259 | { | ||
260 | $routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'https'))); | ||
261 | $this->assertEquals('https://localhost/app.php/', $this->getGenerator($routes)->generate('test')); | ||
262 | |||
263 | $routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'http'))); | ||
264 | $this->assertEquals('http://localhost/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test')); | ||
265 | } | ||
266 | |||
267 | public function testPathWithTwoStartingSlashes() | ||
268 | { | ||
269 | $routes = $this->getRoutes('test', new Route('//path-and-not-domain')); | ||
270 | |||
271 | // this must not generate '//path-and-not-domain' because that would be a network path | ||
272 | $this->assertSame('/path-and-not-domain', $this->getGenerator($routes, array('BaseUrl' => ''))->generate('test')); | ||
273 | } | ||
274 | |||
275 | public function testNoTrailingSlashForMultipleOptionalParameters() | ||
276 | { | ||
277 | $routes = $this->getRoutes('test', new Route('/category/{slug1}/{slug2}/{slug3}', array('slug2' => null, 'slug3' => null))); | ||
278 | |||
279 | $this->assertEquals('/app.php/category/foo', $this->getGenerator($routes)->generate('test', array('slug1' => 'foo'))); | ||
280 | } | ||
281 | |||
282 | public function testWithAnIntegerAsADefaultValue() | ||
283 | { | ||
284 | $routes = $this->getRoutes('test', new Route('/{default}', array('default' => 0))); | ||
285 | |||
286 | $this->assertEquals('/app.php/foo', $this->getGenerator($routes)->generate('test', array('default' => 'foo'))); | ||
287 | } | ||
288 | |||
289 | public function testNullForOptionalParameterIsIgnored() | ||
290 | { | ||
291 | $routes = $this->getRoutes('test', new Route('/test/{default}', array('default' => 0))); | ||
292 | |||
293 | $this->assertEquals('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => null))); | ||
294 | } | ||
295 | |||
296 | public function testQueryParamSameAsDefault() | ||
297 | { | ||
298 | $routes = $this->getRoutes('test', new Route('/test', array('default' => 'value'))); | ||
299 | |||
300 | $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => 'foo'))); | ||
301 | $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => 'value'))); | ||
302 | $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test')); | ||
303 | } | ||
304 | |||
305 | public function testGenerateWithSpecialRouteName() | ||
306 | { | ||
307 | $routes = $this->getRoutes('$péß^a|', new Route('/bar')); | ||
308 | |||
309 | $this->assertSame('/app.php/bar', $this->getGenerator($routes)->generate('$péß^a|')); | ||
310 | } | ||
311 | |||
312 | public function testUrlEncoding() | ||
313 | { | ||
314 | // This tests the encoding of reserved characters that are used for delimiting of URI components (defined in RFC 3986) | ||
315 | // and other special ASCII chars. These chars are tested as static text path, variable path and query param. | ||
316 | $chars = '@:[]/()*\'" +,;-._~&$<>|{}%\\^`!?foo=bar#id'; | ||
317 | $routes = $this->getRoutes('test', new Route("/$chars/{varpath}", array(), array('varpath' => '.+'))); | ||
318 | $this->assertSame('/app.php/@:%5B%5D/%28%29*%27%22%20+,;-._~%26%24%3C%3E|%7B%7D%25%5C%5E%60!%3Ffoo=bar%23id' | ||
319 | .'/@:%5B%5D/%28%29*%27%22%20+,;-._~%26%24%3C%3E|%7B%7D%25%5C%5E%60!%3Ffoo=bar%23id' | ||
320 | .'?query=%40%3A%5B%5D%2F%28%29%2A%27%22+%2B%2C%3B-._%7E%26%24%3C%3E%7C%7B%7D%25%5C%5E%60%21%3Ffoo%3Dbar%23id', | ||
321 | $this->getGenerator($routes)->generate('test', array( | ||
322 | 'varpath' => $chars, | ||
323 | 'query' => $chars | ||
324 | )) | ||
325 | ); | ||
326 | } | ||
327 | |||
328 | public function testEncodingOfRelativePathSegments() | ||
329 | { | ||
330 | $routes = $this->getRoutes('test', new Route('/dir/../dir/..')); | ||
331 | $this->assertSame('/app.php/dir/%2E%2E/dir/%2E%2E', $this->getGenerator($routes)->generate('test')); | ||
332 | $routes = $this->getRoutes('test', new Route('/dir/./dir/.')); | ||
333 | $this->assertSame('/app.php/dir/%2E/dir/%2E', $this->getGenerator($routes)->generate('test')); | ||
334 | $routes = $this->getRoutes('test', new Route('/a./.a/a../..a/...')); | ||
335 | $this->assertSame('/app.php/a./.a/a../..a/...', $this->getGenerator($routes)->generate('test')); | ||
336 | } | ||
337 | |||
338 | public function testAdjacentVariables() | ||
339 | { | ||
340 | $routes = $this->getRoutes('test', new Route('/{x}{y}{z}.{_format}', array('z' => 'default-z', '_format' => 'html'), array('y' => '\d+'))); | ||
341 | $generator = $this->getGenerator($routes); | ||
342 | $this->assertSame('/app.php/foo123', $generator->generate('test', array('x' => 'foo', 'y' => '123'))); | ||
343 | $this->assertSame('/app.php/foo123bar.xml', $generator->generate('test', array('x' => 'foo', 'y' => '123', 'z' => 'bar', '_format' => 'xml'))); | ||
344 | |||
345 | // The default requirement for 'x' should not allow the separator '.' in this case because it would otherwise match everything | ||
346 | // and following optional variables like _format could never match. | ||
347 | $this->setExpectedException('Symfony\Component\Routing\Exception\InvalidParameterException'); | ||
348 | $generator->generate('test', array('x' => 'do.t', 'y' => '123', 'z' => 'bar', '_format' => 'xml')); | ||
349 | } | ||
350 | |||
351 | public function testOptionalVariableWithNoRealSeparator() | ||
352 | { | ||
353 | $routes = $this->getRoutes('test', new Route('/get{what}', array('what' => 'All'))); | ||
354 | $generator = $this->getGenerator($routes); | ||
355 | |||
356 | $this->assertSame('/app.php/get', $generator->generate('test')); | ||
357 | $this->assertSame('/app.php/getSites', $generator->generate('test', array('what' => 'Sites'))); | ||
358 | } | ||
359 | |||
360 | public function testRequiredVariableWithNoRealSeparator() | ||
361 | { | ||
362 | $routes = $this->getRoutes('test', new Route('/get{what}Suffix')); | ||
363 | $generator = $this->getGenerator($routes); | ||
364 | |||
365 | $this->assertSame('/app.php/getSitesSuffix', $generator->generate('test', array('what' => 'Sites'))); | ||
366 | } | ||
367 | |||
368 | public function testDefaultRequirementOfVariable() | ||
369 | { | ||
370 | $routes = $this->getRoutes('test', new Route('/{page}.{_format}')); | ||
371 | $generator = $this->getGenerator($routes); | ||
372 | |||
373 | $this->assertSame('/app.php/index.mobile.html', $generator->generate('test', array('page' => 'index', '_format' => 'mobile.html'))); | ||
374 | } | ||
375 | |||
376 | /** | ||
377 | * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException | ||
378 | */ | ||
379 | public function testDefaultRequirementOfVariableDisallowsSlash() | ||
380 | { | ||
381 | $routes = $this->getRoutes('test', new Route('/{page}.{_format}')); | ||
382 | $this->getGenerator($routes)->generate('test', array('page' => 'index', '_format' => 'sl/ash')); | ||
383 | } | ||
384 | |||
385 | /** | ||
386 | * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException | ||
387 | */ | ||
388 | public function testDefaultRequirementOfVariableDisallowsNextSeparator() | ||
389 | { | ||
390 | $routes = $this->getRoutes('test', new Route('/{page}.{_format}')); | ||
391 | $this->getGenerator($routes)->generate('test', array('page' => 'do.t', '_format' => 'html')); | ||
392 | } | ||
393 | |||
394 | public function testWithHostDifferentFromContext() | ||
395 | { | ||
396 | $routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com')); | ||
397 | |||
398 | $this->assertEquals('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test', array('name' =>'Fabien', 'locale' => 'fr'))); | ||
399 | } | ||
400 | |||
401 | public function testWithHostSameAsContext() | ||
402 | { | ||
403 | $routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com')); | ||
404 | |||
405 | $this->assertEquals('/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' =>'Fabien', 'locale' => 'fr'))); | ||
406 | } | ||
407 | |||
408 | public function testWithHostSameAsContextAndAbsolute() | ||
409 | { | ||
410 | $routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com')); | ||
411 | |||
412 | $this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' =>'Fabien', 'locale' => 'fr'), true)); | ||
413 | } | ||
414 | |||
415 | /** | ||
416 | * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException | ||
417 | */ | ||
418 | public function testUrlWithInvalidParameterInHost() | ||
419 | { | ||
420 | $routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com')); | ||
421 | $this->getGenerator($routes)->generate('test', array('foo' => 'baz'), false); | ||
422 | } | ||
423 | |||
424 | /** | ||
425 | * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException | ||
426 | */ | ||
427 | public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue() | ||
428 | { | ||
429 | $routes = $this->getRoutes('test', new Route('/', array('foo' => 'bar'), array('foo' => 'bar'), array(), '{foo}.example.com')); | ||
430 | $this->getGenerator($routes)->generate('test', array('foo' => 'baz'), false); | ||
431 | } | ||
432 | |||
433 | /** | ||
434 | * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException | ||
435 | */ | ||
436 | public function testUrlWithInvalidParameterEqualsDefaultValueInHost() | ||
437 | { | ||
438 | $routes = $this->getRoutes('test', new Route('/', array('foo' => 'baz'), array('foo' => 'bar'), array(), '{foo}.example.com')); | ||
439 | $this->getGenerator($routes)->generate('test', array('foo' => 'baz'), false); | ||
440 | } | ||
441 | |||
442 | public function testUrlWithInvalidParameterInHostInNonStrictMode() | ||
443 | { | ||
444 | $routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com')); | ||
445 | $generator = $this->getGenerator($routes); | ||
446 | $generator->setStrictRequirements(false); | ||
447 | $this->assertNull($generator->generate('test', array('foo' => 'baz'), false)); | ||
448 | } | ||
449 | |||
450 | public function testGenerateNetworkPath() | ||
451 | { | ||
452 | $routes = $this->getRoutes('test', new Route('/{name}', array(), array('_scheme' => 'http'), array(), '{locale}.example.com')); | ||
453 | |||
454 | $this->assertSame('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test', | ||
455 | array('name' =>'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::NETWORK_PATH), 'network path with different host' | ||
456 | ); | ||
457 | $this->assertSame('//fr.example.com/app.php/Fabien?query=string', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', | ||
458 | array('name' =>'Fabien', 'locale' => 'fr', 'query' => 'string'), UrlGeneratorInterface::NETWORK_PATH), 'network path although host same as context' | ||
459 | ); | ||
460 | $this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test', | ||
461 | array('name' =>'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::NETWORK_PATH), 'absolute URL because scheme requirement does not match context' | ||
462 | ); | ||
463 | $this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test', | ||
464 | array('name' =>'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::ABSOLUTE_URL), 'absolute URL with same scheme because it is requested' | ||
465 | ); | ||
466 | } | ||
467 | |||
468 | public function testGenerateRelativePath() | ||
469 | { | ||
470 | $routes = new RouteCollection(); | ||
471 | $routes->add('article', new Route('/{author}/{article}/')); | ||
472 | $routes->add('comments', new Route('/{author}/{article}/comments')); | ||
473 | $routes->add('host', new Route('/{article}', array(), array(), array(), '{author}.example.com')); | ||
474 | $routes->add('scheme', new Route('/{author}', array(), array('_scheme' => 'https'))); | ||
475 | $routes->add('unrelated', new Route('/about')); | ||
476 | |||
477 | $generator = $this->getGenerator($routes, array('host' => 'example.com', 'pathInfo' => '/fabien/symfony-is-great/')); | ||
478 | |||
479 | $this->assertSame('comments', $generator->generate('comments', | ||
480 | array('author' =>'fabien', 'article' => 'symfony-is-great'), UrlGeneratorInterface::RELATIVE_PATH) | ||
481 | ); | ||
482 | $this->assertSame('comments?page=2', $generator->generate('comments', | ||
483 | array('author' =>'fabien', 'article' => 'symfony-is-great', 'page' => 2), UrlGeneratorInterface::RELATIVE_PATH) | ||
484 | ); | ||
485 | $this->assertSame('../twig-is-great/', $generator->generate('article', | ||
486 | array('author' =>'fabien', 'article' => 'twig-is-great'), UrlGeneratorInterface::RELATIVE_PATH) | ||
487 | ); | ||
488 | $this->assertSame('../../bernhard/forms-are-great/', $generator->generate('article', | ||
489 | array('author' =>'bernhard', 'article' => 'forms-are-great'), UrlGeneratorInterface::RELATIVE_PATH) | ||
490 | ); | ||
491 | $this->assertSame('//bernhard.example.com/app.php/forms-are-great', $generator->generate('host', | ||
492 | array('author' =>'bernhard', 'article' => 'forms-are-great'), UrlGeneratorInterface::RELATIVE_PATH) | ||
493 | ); | ||
494 | $this->assertSame('https://example.com/app.php/bernhard', $generator->generate('scheme', | ||
495 | array('author' =>'bernhard'), UrlGeneratorInterface::RELATIVE_PATH) | ||
496 | ); | ||
497 | $this->assertSame('../../about', $generator->generate('unrelated', | ||
498 | array(), UrlGeneratorInterface::RELATIVE_PATH) | ||
499 | ); | ||
500 | } | ||
501 | |||
502 | /** | ||
503 | * @dataProvider provideRelativePaths | ||
504 | */ | ||
505 | public function testGetRelativePath($sourcePath, $targetPath, $expectedPath) | ||
506 | { | ||
507 | $this->assertSame($expectedPath, UrlGenerator::getRelativePath($sourcePath, $targetPath)); | ||
508 | } | ||
509 | |||
510 | public function provideRelativePaths() | ||
511 | { | ||
512 | return array( | ||
513 | array( | ||
514 | '/same/dir/', | ||
515 | '/same/dir/', | ||
516 | '' | ||
517 | ), | ||
518 | array( | ||
519 | '/same/file', | ||
520 | '/same/file', | ||
521 | '' | ||
522 | ), | ||
523 | array( | ||
524 | '/', | ||
525 | '/file', | ||
526 | 'file' | ||
527 | ), | ||
528 | array( | ||
529 | '/', | ||
530 | '/dir/file', | ||
531 | 'dir/file' | ||
532 | ), | ||
533 | array( | ||
534 | '/dir/file.html', | ||
535 | '/dir/different-file.html', | ||
536 | 'different-file.html' | ||
537 | ), | ||
538 | array( | ||
539 | '/same/dir/extra-file', | ||
540 | '/same/dir/', | ||
541 | './' | ||
542 | ), | ||
543 | array( | ||
544 | '/parent/dir/', | ||
545 | '/parent/', | ||
546 | '../' | ||
547 | ), | ||
548 | array( | ||
549 | '/parent/dir/extra-file', | ||
550 | '/parent/', | ||
551 | '../' | ||
552 | ), | ||
553 | array( | ||
554 | '/a/b/', | ||
555 | '/x/y/z/', | ||
556 | '../../x/y/z/' | ||
557 | ), | ||
558 | array( | ||
559 | '/a/b/c/d/e', | ||
560 | '/a/c/d', | ||
561 | '../../../c/d' | ||
562 | ), | ||
563 | array( | ||
564 | '/a/b/c//', | ||
565 | '/a/b/c/', | ||
566 | '../' | ||
567 | ), | ||
568 | array( | ||
569 | '/a/b/c/', | ||
570 | '/a/b/c//', | ||
571 | './/' | ||
572 | ), | ||
573 | array( | ||
574 | '/root/a/b/c/', | ||
575 | '/root/x/b/c/', | ||
576 | '../../../x/b/c/' | ||
577 | ), | ||
578 | array( | ||
579 | '/a/b/c/d/', | ||
580 | '/a', | ||
581 | '../../../../a' | ||
582 | ), | ||
583 | array( | ||
584 | '/special-chars/sp%20ce/1€/mäh/e=mc²', | ||
585 | '/special-chars/sp%20ce/1€/<µ>/e=mc²', | ||
586 | '../<µ>/e=mc²' | ||
587 | ), | ||
588 | array( | ||
589 | 'not-rooted', | ||
590 | 'dir/file', | ||
591 | 'dir/file' | ||
592 | ), | ||
593 | array( | ||
594 | '//dir/', | ||
595 | '', | ||
596 | '../../' | ||
597 | ), | ||
598 | array( | ||
599 | '/dir/', | ||
600 | '/dir/file:with-colon', | ||
601 | './file:with-colon' | ||
602 | ), | ||
603 | array( | ||
604 | '/dir/', | ||
605 | '/dir/subdir/file:with-colon', | ||
606 | 'subdir/file:with-colon' | ||
607 | ), | ||
608 | array( | ||
609 | '/dir/', | ||
610 | '/dir/:subdir/', | ||
611 | './:subdir/' | ||
612 | ), | ||
613 | ); | ||
614 | } | ||
615 | |||
616 | protected function getGenerator(RouteCollection $routes, array $parameters = array(), $logger = null) | ||
617 | { | ||
618 | $context = new RequestContext('/app.php'); | ||
619 | foreach ($parameters as $key => $value) { | ||
620 | $method = 'set'.$key; | ||
621 | $context->$method($value); | ||
622 | } | ||
623 | $generator = new UrlGenerator($routes, $context, $logger); | ||
624 | |||
625 | return $generator; | ||
626 | } | ||
627 | |||
628 | protected function getRoutes($name, Route $route) | ||
629 | { | ||
630 | $routes = new RouteCollection(); | ||
631 | $routes->add($name, $route); | ||
632 | |||
633 | return $routes; | ||
634 | } | ||
635 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AbstractAnnotationLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AbstractAnnotationLoaderTest.php new file mode 100644 index 00000000..c927ae4a --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AbstractAnnotationLoaderTest.php | |||
@@ -0,0 +1,38 @@ | |||
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\Loader; | ||
13 | |||
14 | abstract class AbstractAnnotationLoaderTest extends \PHPUnit_Framework_TestCase | ||
15 | { | ||
16 | protected function setUp() | ||
17 | { | ||
18 | if (!class_exists('Doctrine\\Common\\Version')) { | ||
19 | $this->markTestSkipped('Doctrine is not available.'); | ||
20 | } | ||
21 | } | ||
22 | |||
23 | public function getReader() | ||
24 | { | ||
25 | return $this->getMockBuilder('Doctrine\Common\Annotations\Reader') | ||
26 | ->disableOriginalConstructor() | ||
27 | ->getMock() | ||
28 | ; | ||
29 | } | ||
30 | |||
31 | public function getClassLoader($reader) | ||
32 | { | ||
33 | return $this->getMockBuilder('Symfony\Component\Routing\Loader\AnnotationClassLoader') | ||
34 | ->setConstructorArgs(array($reader)) | ||
35 | ->getMockForAbstractClass() | ||
36 | ; | ||
37 | } | ||
38 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php new file mode 100644 index 00000000..31c43f58 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php | |||
@@ -0,0 +1,119 @@ | |||
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\Loader; | ||
13 | |||
14 | class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest | ||
15 | { | ||
16 | protected $loader; | ||
17 | |||
18 | protected function setUp() | ||
19 | { | ||
20 | parent::setUp(); | ||
21 | |||
22 | $this->reader = $this->getReader(); | ||
23 | $this->loader = $this->getClassLoader($this->reader); | ||
24 | } | ||
25 | |||
26 | /** | ||
27 | * @expectedException \InvalidArgumentException | ||
28 | */ | ||
29 | public function testLoadMissingClass() | ||
30 | { | ||
31 | $this->loader->load('MissingClass'); | ||
32 | } | ||
33 | |||
34 | /** | ||
35 | * @expectedException \InvalidArgumentException | ||
36 | */ | ||
37 | public function testLoadAbstractClass() | ||
38 | { | ||
39 | $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\AbstractClass'); | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * @dataProvider provideTestSupportsChecksResource | ||
44 | */ | ||
45 | public function testSupportsChecksResource($resource, $expectedSupports) | ||
46 | { | ||
47 | $this->assertSame($expectedSupports, $this->loader->supports($resource), '->supports() returns true if the resource is loadable'); | ||
48 | } | ||
49 | |||
50 | public function provideTestSupportsChecksResource() | ||
51 | { | ||
52 | return array( | ||
53 | array('class', true), | ||
54 | array('\fully\qualified\class\name', true), | ||
55 | array('namespaced\class\without\leading\slash', true), | ||
56 | array('ÿClassWithLegalSpecialCharacters', true), | ||
57 | array('5', false), | ||
58 | array('foo.foo', false), | ||
59 | array(null, false), | ||
60 | ); | ||
61 | } | ||
62 | |||
63 | public function testSupportsChecksTypeIfSpecified() | ||
64 | { | ||
65 | $this->assertTrue($this->loader->supports('class', 'annotation'), '->supports() checks the resource type if specified'); | ||
66 | $this->assertFalse($this->loader->supports('class', 'foo'), '->supports() checks the resource type if specified'); | ||
67 | } | ||
68 | |||
69 | public function getLoadTests() | ||
70 | { | ||
71 | return array( | ||
72 | array( | ||
73 | 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass', | ||
74 | array('name'=>'route1'), | ||
75 | array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3') | ||
76 | ), | ||
77 | array( | ||
78 | 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass', | ||
79 | array('name'=>'route1', 'defaults' => array('arg2' => 'foo')), | ||
80 | array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3') | ||
81 | ), | ||
82 | ); | ||
83 | } | ||
84 | |||
85 | /** | ||
86 | * @dataProvider getLoadTests | ||
87 | */ | ||
88 | public function testLoad($className, $routeDatas = array(), $methodArgs = array()) | ||
89 | { | ||
90 | $routeDatas = array_replace(array( | ||
91 | 'name' => 'route', | ||
92 | 'path' => '/', | ||
93 | 'requirements' => array(), | ||
94 | 'options' => array(), | ||
95 | 'defaults' => array(), | ||
96 | 'schemes' => array(), | ||
97 | 'methods' => array(), | ||
98 | ), $routeDatas); | ||
99 | |||
100 | $this->reader | ||
101 | ->expects($this->once()) | ||
102 | ->method('getMethodAnnotations') | ||
103 | ->will($this->returnValue(array($this->getAnnotatedRoute($routeDatas)))) | ||
104 | ; | ||
105 | $routeCollection = $this->loader->load($className); | ||
106 | $route = $routeCollection->get($routeDatas['name']); | ||
107 | |||
108 | $this->assertSame($routeDatas['path'], $route->getPath(), '->load preserves path annotation'); | ||
109 | $this->assertSame($routeDatas['requirements'],$route->getRequirements(), '->load preserves requirements annotation'); | ||
110 | $this->assertCount(0, array_intersect($route->getOptions(), $routeDatas['options']), '->load preserves options annotation'); | ||
111 | $this->assertSame(array_replace($routeDatas['defaults'], $methodArgs), $route->getDefaults(), '->load preserves defaults annotation'); | ||
112 | } | ||
113 | |||
114 | private function getAnnotatedRoute($datas) | ||
115 | { | ||
116 | return new \Symfony\Component\Routing\Annotation\Route($datas); | ||
117 | } | ||
118 | |||
119 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php new file mode 100644 index 00000000..29126ba4 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php | |||
@@ -0,0 +1,53 @@ | |||
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\Loader; | ||
13 | |||
14 | use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader; | ||
15 | use Symfony\Component\Config\FileLocator; | ||
16 | |||
17 | class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest | ||
18 | { | ||
19 | protected $loader; | ||
20 | protected $reader; | ||
21 | |||
22 | protected function setUp() | ||
23 | { | ||
24 | parent::setUp(); | ||
25 | |||
26 | $this->reader = $this->getReader(); | ||
27 | $this->loader = new AnnotationDirectoryLoader(new FileLocator(), $this->getClassLoader($this->reader)); | ||
28 | } | ||
29 | |||
30 | public function testLoad() | ||
31 | { | ||
32 | $this->reader->expects($this->exactly(2))->method('getClassAnnotation'); | ||
33 | |||
34 | $this->reader | ||
35 | ->expects($this->any()) | ||
36 | ->method('getMethodAnnotations') | ||
37 | ->will($this->returnValue(array())) | ||
38 | ; | ||
39 | |||
40 | $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses'); | ||
41 | } | ||
42 | |||
43 | public function testSupports() | ||
44 | { | ||
45 | $fixturesDir = __DIR__.'/../Fixtures'; | ||
46 | |||
47 | $this->assertTrue($this->loader->supports($fixturesDir), '->supports() returns true if the resource is loadable'); | ||
48 | $this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); | ||
49 | |||
50 | $this->assertTrue($this->loader->supports($fixturesDir, 'annotation'), '->supports() checks the resource type if specified'); | ||
51 | $this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports() checks the resource type if specified'); | ||
52 | } | ||
53 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php new file mode 100644 index 00000000..f0a8a0e3 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php | |||
@@ -0,0 +1,47 @@ | |||
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\Loader; | ||
13 | |||
14 | use Symfony\Component\Routing\Loader\AnnotationFileLoader; | ||
15 | use Symfony\Component\Config\FileLocator; | ||
16 | |||
17 | class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest | ||
18 | { | ||
19 | protected $loader; | ||
20 | protected $reader; | ||
21 | |||
22 | protected function setUp() | ||
23 | { | ||
24 | parent::setUp(); | ||
25 | |||
26 | $this->reader = $this->getReader(); | ||
27 | $this->loader = new AnnotationFileLoader(new FileLocator(), $this->getClassLoader($this->reader)); | ||
28 | } | ||
29 | |||
30 | public function testLoad() | ||
31 | { | ||
32 | $this->reader->expects($this->once())->method('getClassAnnotation'); | ||
33 | |||
34 | $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php'); | ||
35 | } | ||
36 | |||
37 | public function testSupports() | ||
38 | { | ||
39 | $fixture = __DIR__.'/../Fixtures/annotated.php'; | ||
40 | |||
41 | $this->assertTrue($this->loader->supports($fixture), '->supports() returns true if the resource is loadable'); | ||
42 | $this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); | ||
43 | |||
44 | $this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified'); | ||
45 | $this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified'); | ||
46 | } | ||
47 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/ClosureLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/ClosureLoaderTest.php new file mode 100644 index 00000000..64d1b086 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/ClosureLoaderTest.php | |||
@@ -0,0 +1,55 @@ | |||
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\Loader; | ||
13 | |||
14 | use Symfony\Component\Routing\Loader\ClosureLoader; | ||
15 | use Symfony\Component\Routing\Route; | ||
16 | use Symfony\Component\Routing\RouteCollection; | ||
17 | |||
18 | class ClosureLoaderTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | protected function setUp() | ||
21 | { | ||
22 | if (!class_exists('Symfony\Component\Config\FileLocator')) { | ||
23 | $this->markTestSkipped('The "Config" component is not available'); | ||
24 | } | ||
25 | } | ||
26 | |||
27 | public function testSupports() | ||
28 | { | ||
29 | $loader = new ClosureLoader(); | ||
30 | |||
31 | $closure = function () {}; | ||
32 | |||
33 | $this->assertTrue($loader->supports($closure), '->supports() returns true if the resource is loadable'); | ||
34 | $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); | ||
35 | |||
36 | $this->assertTrue($loader->supports($closure, 'closure'), '->supports() checks the resource type if specified'); | ||
37 | $this->assertFalse($loader->supports($closure, 'foo'), '->supports() checks the resource type if specified'); | ||
38 | } | ||
39 | |||
40 | public function testLoad() | ||
41 | { | ||
42 | $loader = new ClosureLoader(); | ||
43 | |||
44 | $route = new Route('/'); | ||
45 | $routes = $loader->load(function () use ($route) { | ||
46 | $routes = new RouteCollection(); | ||
47 | |||
48 | $routes->add('foo', $route); | ||
49 | |||
50 | return $routes; | ||
51 | }); | ||
52 | |||
53 | $this->assertEquals($route, $routes->get('foo'), '->load() loads a \Closure resource'); | ||
54 | } | ||
55 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php new file mode 100644 index 00000000..18b166fc --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php | |||
@@ -0,0 +1,55 @@ | |||
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\Loader; | ||
13 | |||
14 | use Symfony\Component\Config\FileLocator; | ||
15 | use Symfony\Component\Routing\Loader\PhpFileLoader; | ||
16 | |||
17 | class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | if (!class_exists('Symfony\Component\Config\FileLocator')) { | ||
22 | $this->markTestSkipped('The "Config" component is not available'); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | public function testSupports() | ||
27 | { | ||
28 | $loader = new PhpFileLoader($this->getMock('Symfony\Component\Config\FileLocator')); | ||
29 | |||
30 | $this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable'); | ||
31 | $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); | ||
32 | |||
33 | $this->assertTrue($loader->supports('foo.php', 'php'), '->supports() checks the resource type if specified'); | ||
34 | $this->assertFalse($loader->supports('foo.php', 'foo'), '->supports() checks the resource type if specified'); | ||
35 | } | ||
36 | |||
37 | public function testLoadWithRoute() | ||
38 | { | ||
39 | $loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
40 | $routeCollection = $loader->load('validpattern.php'); | ||
41 | $routes = $routeCollection->all(); | ||
42 | |||
43 | $this->assertCount(2, $routes, 'Two routes are loaded'); | ||
44 | $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); | ||
45 | |||
46 | foreach ($routes as $route) { | ||
47 | $this->assertSame('/blog/{slug}', $route->getPath()); | ||
48 | $this->assertSame('MyBlogBundle:Blog:show', $route->getDefault('_controller')); | ||
49 | $this->assertSame('{locale}.example.com', $route->getHost()); | ||
50 | $this->assertSame('RouteCompiler', $route->getOption('compiler_class')); | ||
51 | $this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods()); | ||
52 | $this->assertEquals(array('https'), $route->getSchemes()); | ||
53 | } | ||
54 | } | ||
55 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php new file mode 100644 index 00000000..9f038c16 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php | |||
@@ -0,0 +1,127 @@ | |||
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\Loader; | ||
13 | |||
14 | use Symfony\Component\Config\FileLocator; | ||
15 | use Symfony\Component\Routing\Loader\XmlFileLoader; | ||
16 | use Symfony\Component\Routing\Tests\Fixtures\CustomXmlFileLoader; | ||
17 | |||
18 | class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | protected function setUp() | ||
21 | { | ||
22 | if (!class_exists('Symfony\Component\Config\FileLocator')) { | ||
23 | $this->markTestSkipped('The "Config" component is not available'); | ||
24 | } | ||
25 | } | ||
26 | |||
27 | public function testSupports() | ||
28 | { | ||
29 | $loader = new XmlFileLoader($this->getMock('Symfony\Component\Config\FileLocator')); | ||
30 | |||
31 | $this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable'); | ||
32 | $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); | ||
33 | |||
34 | $this->assertTrue($loader->supports('foo.xml', 'xml'), '->supports() checks the resource type if specified'); | ||
35 | $this->assertFalse($loader->supports('foo.xml', 'foo'), '->supports() checks the resource type if specified'); | ||
36 | } | ||
37 | |||
38 | public function testLoadWithRoute() | ||
39 | { | ||
40 | $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
41 | $routeCollection = $loader->load('validpattern.xml'); | ||
42 | $routes = $routeCollection->all(); | ||
43 | |||
44 | $this->assertCount(2, $routes, 'Two routes are loaded'); | ||
45 | $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); | ||
46 | |||
47 | foreach ($routes as $route) { | ||
48 | $this->assertSame('/blog/{slug}', $route->getPath()); | ||
49 | $this->assertSame('{locale}.example.com', $route->getHost()); | ||
50 | $this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller')); | ||
51 | $this->assertSame('\w+', $route->getRequirement('locale')); | ||
52 | $this->assertSame('RouteCompiler', $route->getOption('compiler_class')); | ||
53 | $this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods()); | ||
54 | $this->assertEquals(array('https'), $route->getSchemes()); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | public function testLoadWithNamespacePrefix() | ||
59 | { | ||
60 | $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
61 | $routeCollection = $loader->load('namespaceprefix.xml'); | ||
62 | |||
63 | $this->assertCount(1, $routeCollection->all(), 'One route is loaded'); | ||
64 | |||
65 | $route = $routeCollection->get('blog_show'); | ||
66 | $this->assertSame('/blog/{slug}', $route->getPath()); | ||
67 | $this->assertSame('{_locale}.example.com', $route->getHost()); | ||
68 | $this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller')); | ||
69 | $this->assertSame('\w+', $route->getRequirement('slug')); | ||
70 | $this->assertSame('en|fr|de', $route->getRequirement('_locale')); | ||
71 | $this->assertSame(null, $route->getDefault('slug')); | ||
72 | $this->assertSame('RouteCompiler', $route->getOption('compiler_class')); | ||
73 | } | ||
74 | |||
75 | public function testLoadWithImport() | ||
76 | { | ||
77 | $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
78 | $routeCollection = $loader->load('validresource.xml'); | ||
79 | $routes = $routeCollection->all(); | ||
80 | |||
81 | $this->assertCount(2, $routes, 'Two routes are loaded'); | ||
82 | $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); | ||
83 | |||
84 | foreach ($routes as $route) { | ||
85 | $this->assertSame('/{foo}/blog/{slug}', $route->getPath()); | ||
86 | $this->assertSame('123', $route->getDefault('foo')); | ||
87 | $this->assertSame('\d+', $route->getRequirement('foo')); | ||
88 | $this->assertSame('bar', $route->getOption('foo')); | ||
89 | $this->assertSame('', $route->getHost()); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * @expectedException \InvalidArgumentException | ||
95 | * @dataProvider getPathsToInvalidFiles | ||
96 | */ | ||
97 | public function testLoadThrowsExceptionWithInvalidFile($filePath) | ||
98 | { | ||
99 | $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
100 | $loader->load($filePath); | ||
101 | } | ||
102 | |||
103 | /** | ||
104 | * @expectedException \InvalidArgumentException | ||
105 | * @dataProvider getPathsToInvalidFiles | ||
106 | */ | ||
107 | public function testLoadThrowsExceptionWithInvalidFileEvenWithoutSchemaValidation($filePath) | ||
108 | { | ||
109 | $loader = new CustomXmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
110 | $loader->load($filePath); | ||
111 | } | ||
112 | |||
113 | public function getPathsToInvalidFiles() | ||
114 | { | ||
115 | return array(array('nonvalidnode.xml'), array('nonvalidroute.xml'), array('nonvalid.xml'), array('missing_id.xml'), array('missing_path.xml')); | ||
116 | } | ||
117 | |||
118 | /** | ||
119 | * @expectedException \InvalidArgumentException | ||
120 | * @expectedExceptionMessage Document types are not allowed. | ||
121 | */ | ||
122 | public function testDocTypeIsNotAllowed() | ||
123 | { | ||
124 | $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
125 | $loader->load('withdoctype.xml'); | ||
126 | } | ||
127 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php new file mode 100644 index 00000000..a3e934ce --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php | |||
@@ -0,0 +1,113 @@ | |||
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\Loader; | ||
13 | |||
14 | use Symfony\Component\Config\FileLocator; | ||
15 | use Symfony\Component\Routing\Loader\YamlFileLoader; | ||
16 | use Symfony\Component\Config\Resource\FileResource; | ||
17 | |||
18 | class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | protected function setUp() | ||
21 | { | ||
22 | if (!class_exists('Symfony\Component\Config\FileLocator')) { | ||
23 | $this->markTestSkipped('The "Config" component is not available'); | ||
24 | } | ||
25 | |||
26 | if (!class_exists('Symfony\Component\Yaml\Yaml')) { | ||
27 | $this->markTestSkipped('The "Yaml" component is not available'); | ||
28 | } | ||
29 | } | ||
30 | |||
31 | public function testSupports() | ||
32 | { | ||
33 | $loader = new YamlFileLoader($this->getMock('Symfony\Component\Config\FileLocator')); | ||
34 | |||
35 | $this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable'); | ||
36 | $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); | ||
37 | |||
38 | $this->assertTrue($loader->supports('foo.yml', 'yaml'), '->supports() checks the resource type if specified'); | ||
39 | $this->assertFalse($loader->supports('foo.yml', 'foo'), '->supports() checks the resource type if specified'); | ||
40 | } | ||
41 | |||
42 | public function testLoadDoesNothingIfEmpty() | ||
43 | { | ||
44 | $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
45 | $collection = $loader->load('empty.yml'); | ||
46 | |||
47 | $this->assertEquals(array(), $collection->all()); | ||
48 | $this->assertEquals(array(new FileResource(realpath(__DIR__.'/../Fixtures/empty.yml'))), $collection->getResources()); | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * @expectedException \InvalidArgumentException | ||
53 | * @dataProvider getPathsToInvalidFiles | ||
54 | */ | ||
55 | public function testLoadThrowsExceptionWithInvalidFile($filePath) | ||
56 | { | ||
57 | $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
58 | $loader->load($filePath); | ||
59 | } | ||
60 | |||
61 | public function getPathsToInvalidFiles() | ||
62 | { | ||
63 | return array(array('nonvalid.yml'), array('nonvalid2.yml'), array('incomplete.yml'), array('nonvalidkeys.yml'), array('nonesense_resource_plus_path.yml'), array('nonesense_type_without_resource.yml')); | ||
64 | } | ||
65 | |||
66 | public function testLoadSpecialRouteName() | ||
67 | { | ||
68 | $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
69 | $routeCollection = $loader->load('special_route_name.yml'); | ||
70 | $route = $routeCollection->get('#$péß^a|'); | ||
71 | |||
72 | $this->assertInstanceOf('Symfony\Component\Routing\Route', $route); | ||
73 | $this->assertSame('/true', $route->getPath()); | ||
74 | } | ||
75 | |||
76 | public function testLoadWithRoute() | ||
77 | { | ||
78 | $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
79 | $routeCollection = $loader->load('validpattern.yml'); | ||
80 | $routes = $routeCollection->all(); | ||
81 | |||
82 | $this->assertCount(2, $routes, 'Two routes are loaded'); | ||
83 | $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); | ||
84 | |||
85 | foreach ($routes as $route) { | ||
86 | $this->assertSame('/blog/{slug}', $route->getPath()); | ||
87 | $this->assertSame('{locale}.example.com', $route->getHost()); | ||
88 | $this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller')); | ||
89 | $this->assertSame('\w+', $route->getRequirement('locale')); | ||
90 | $this->assertSame('RouteCompiler', $route->getOption('compiler_class')); | ||
91 | $this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods()); | ||
92 | $this->assertEquals(array('https'), $route->getSchemes()); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | public function testLoadWithResource() | ||
97 | { | ||
98 | $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
99 | $routeCollection = $loader->load('validresource.yml'); | ||
100 | $routes = $routeCollection->all(); | ||
101 | |||
102 | $this->assertCount(2, $routes, 'Two routes are loaded'); | ||
103 | $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); | ||
104 | |||
105 | foreach ($routes as $route) { | ||
106 | $this->assertSame('/{foo}/blog/{slug}', $route->getPath()); | ||
107 | $this->assertSame('123', $route->getDefault('foo')); | ||
108 | $this->assertSame('\d+', $route->getRequirement('foo')); | ||
109 | $this->assertSame('bar', $route->getOption('foo')); | ||
110 | $this->assertSame('', $route->getHost()); | ||
111 | } | ||
112 | } | ||
113 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/ApacheUrlMatcherTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/ApacheUrlMatcherTest.php new file mode 100644 index 00000000..6550911e --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/ApacheUrlMatcherTest.php | |||
@@ -0,0 +1,137 @@ | |||
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\RouteCollection; | ||
15 | use Symfony\Component\Routing\RequestContext; | ||
16 | use Symfony\Component\Routing\Matcher\ApacheUrlMatcher; | ||
17 | |||
18 | class ApacheUrlMatcherTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | protected $server; | ||
21 | |||
22 | protected function setUp() | ||
23 | { | ||
24 | $this->server = $_SERVER; | ||
25 | } | ||
26 | |||
27 | protected function tearDown() | ||
28 | { | ||
29 | $_SERVER = $this->server; | ||
30 | } | ||
31 | |||
32 | /** | ||
33 | * @dataProvider getMatchData | ||
34 | */ | ||
35 | public function testMatch($name, $pathinfo, $server, $expect) | ||
36 | { | ||
37 | $collection = new RouteCollection(); | ||
38 | $context = new RequestContext(); | ||
39 | $matcher = new ApacheUrlMatcher($collection, $context); | ||
40 | |||
41 | $_SERVER = $server; | ||
42 | |||
43 | $result = $matcher->match($pathinfo, $server); | ||
44 | $this->assertSame(var_export($expect, true), var_export($result, true)); | ||
45 | } | ||
46 | |||
47 | public function getMatchData() | ||
48 | { | ||
49 | return array( | ||
50 | array( | ||
51 | 'Simple route', | ||
52 | '/hello/world', | ||
53 | array( | ||
54 | '_ROUTING_route' => 'hello', | ||
55 | '_ROUTING_param__controller' => 'AcmeBundle:Default:index', | ||
56 | '_ROUTING_param_name' => 'world', | ||
57 | ), | ||
58 | array( | ||
59 | '_controller' => 'AcmeBundle:Default:index', | ||
60 | 'name' => 'world', | ||
61 | '_route' => 'hello', | ||
62 | ), | ||
63 | ), | ||
64 | array( | ||
65 | 'Route with params and defaults', | ||
66 | '/hello/hugo', | ||
67 | array( | ||
68 | '_ROUTING_route' => 'hello', | ||
69 | '_ROUTING_param__controller' => 'AcmeBundle:Default:index', | ||
70 | '_ROUTING_param_name' => 'hugo', | ||
71 | '_ROUTING_default_name' => 'world', | ||
72 | ), | ||
73 | array( | ||
74 | 'name' => 'hugo', | ||
75 | '_controller' => 'AcmeBundle:Default:index', | ||
76 | '_route' => 'hello', | ||
77 | ), | ||
78 | ), | ||
79 | array( | ||
80 | 'Route with defaults only', | ||
81 | '/hello', | ||
82 | array( | ||
83 | '_ROUTING_route' => 'hello', | ||
84 | '_ROUTING_param__controller' => 'AcmeBundle:Default:index', | ||
85 | '_ROUTING_default_name' => 'world', | ||
86 | ), | ||
87 | array( | ||
88 | 'name' => 'world', | ||
89 | '_controller' => 'AcmeBundle:Default:index', | ||
90 | '_route' => 'hello', | ||
91 | ), | ||
92 | ), | ||
93 | array( | ||
94 | 'REDIRECT_ envs', | ||
95 | '/hello/world', | ||
96 | array( | ||
97 | 'REDIRECT__ROUTING_route' => 'hello', | ||
98 | 'REDIRECT__ROUTING_param__controller' => 'AcmeBundle:Default:index', | ||
99 | 'REDIRECT__ROUTING_param_name' => 'world', | ||
100 | ), | ||
101 | array( | ||
102 | '_controller' => 'AcmeBundle:Default:index', | ||
103 | 'name' => 'world', | ||
104 | '_route' => 'hello', | ||
105 | ), | ||
106 | ), | ||
107 | array( | ||
108 | 'REDIRECT_REDIRECT_ envs', | ||
109 | '/hello/world', | ||
110 | array( | ||
111 | 'REDIRECT_REDIRECT__ROUTING_route' => 'hello', | ||
112 | 'REDIRECT_REDIRECT__ROUTING_param__controller' => 'AcmeBundle:Default:index', | ||
113 | 'REDIRECT_REDIRECT__ROUTING_param_name' => 'world', | ||
114 | ), | ||
115 | array( | ||
116 | '_controller' => 'AcmeBundle:Default:index', | ||
117 | 'name' => 'world', | ||
118 | '_route' => 'hello', | ||
119 | ), | ||
120 | ), | ||
121 | array( | ||
122 | 'REDIRECT_REDIRECT_ envs', | ||
123 | '/hello/world', | ||
124 | array( | ||
125 | 'REDIRECT_REDIRECT__ROUTING_route' => 'hello', | ||
126 | 'REDIRECT_REDIRECT__ROUTING_param__controller' => 'AcmeBundle:Default:index', | ||
127 | 'REDIRECT_REDIRECT__ROUTING_param_name' => 'world', | ||
128 | ), | ||
129 | array( | ||
130 | '_controller' => 'AcmeBundle:Default:index', | ||
131 | 'name' => 'world', | ||
132 | '_route' => 'hello', | ||
133 | ), | ||
134 | ), | ||
135 | ); | ||
136 | } | ||
137 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/ApacheMatcherDumperTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/ApacheMatcherDumperTest.php new file mode 100644 index 00000000..72bee710 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/ApacheMatcherDumperTest.php | |||
@@ -0,0 +1,196 @@ | |||
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\RouteCollection; | ||
16 | use Symfony\Component\Routing\Matcher\Dumper\ApacheMatcherDumper; | ||
17 | |||
18 | class ApacheMatcherDumperTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | protected static $fixturesPath; | ||
21 | |||
22 | public static function setUpBeforeClass() | ||
23 | { | ||
24 | self::$fixturesPath = realpath(__DIR__.'/../../Fixtures/'); | ||
25 | } | ||
26 | |||
27 | public function testDump() | ||
28 | { | ||
29 | $dumper = new ApacheMatcherDumper($this->getRouteCollection()); | ||
30 | |||
31 | $this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher1.apache', $dumper->dump(), '->dump() dumps basic routes to the correct apache format.'); | ||
32 | } | ||
33 | |||
34 | /** | ||
35 | * @dataProvider provideEscapeFixtures | ||
36 | */ | ||
37 | public function testEscapePattern($src, $dest, $char, $with, $message) | ||
38 | { | ||
39 | $r = new \ReflectionMethod(new ApacheMatcherDumper($this->getRouteCollection()), 'escape'); | ||
40 | $r->setAccessible(true); | ||
41 | $this->assertEquals($dest, $r->invoke(null, $src, $char, $with), $message); | ||
42 | } | ||
43 | |||
44 | public function provideEscapeFixtures() | ||
45 | { | ||
46 | return array( | ||
47 | array('foo', 'foo', ' ', '-', 'Preserve string that should not be escaped'), | ||
48 | array('fo-o', 'fo-o', ' ', '-', 'Preserve string that should not be escaped'), | ||
49 | array('fo o', 'fo- o', ' ', '-', 'Escape special characters'), | ||
50 | array('fo-- o', 'fo--- o', ' ', '-', 'Escape special characters'), | ||
51 | array('fo- o', 'fo- o', ' ', '-', 'Do not escape already escaped string'), | ||
52 | ); | ||
53 | } | ||
54 | |||
55 | public function testEscapeScriptName() | ||
56 | { | ||
57 | $collection = new RouteCollection(); | ||
58 | $collection->add('foo', new Route('/foo')); | ||
59 | $dumper = new ApacheMatcherDumper($collection); | ||
60 | $this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher2.apache', $dumper->dump(array('script_name' => 'ap p_d\ ev.php'))); | ||
61 | } | ||
62 | |||
63 | private function getRouteCollection() | ||
64 | { | ||
65 | $collection = new RouteCollection(); | ||
66 | |||
67 | // defaults and requirements | ||
68 | $collection->add('foo', new Route( | ||
69 | '/foo/{bar}', | ||
70 | array('def' => 'test'), | ||
71 | array('bar' => 'baz|symfony') | ||
72 | )); | ||
73 | // defaults parameters in pattern | ||
74 | $collection->add('foobar', new Route( | ||
75 | '/foo/{bar}', | ||
76 | array('bar' => 'toto') | ||
77 | )); | ||
78 | // method requirement | ||
79 | $collection->add('bar', new Route( | ||
80 | '/bar/{foo}', | ||
81 | array(), | ||
82 | array('_method' => 'GET|head') | ||
83 | )); | ||
84 | // method requirement (again) | ||
85 | $collection->add('baragain', new Route( | ||
86 | '/baragain/{foo}', | ||
87 | array(), | ||
88 | array('_method' => 'get|post') | ||
89 | )); | ||
90 | // simple | ||
91 | $collection->add('baz', new Route( | ||
92 | '/test/baz' | ||
93 | )); | ||
94 | // simple with extension | ||
95 | $collection->add('baz2', new Route( | ||
96 | '/test/baz.html' | ||
97 | )); | ||
98 | // trailing slash | ||
99 | $collection->add('baz3', new Route( | ||
100 | '/test/baz3/' | ||
101 | )); | ||
102 | // trailing slash with variable | ||
103 | $collection->add('baz4', new Route( | ||
104 | '/test/{foo}/' | ||
105 | )); | ||
106 | // trailing slash and safe method | ||
107 | $collection->add('baz5', new Route( | ||
108 | '/test/{foo}/', | ||
109 | array(), | ||
110 | array('_method' => 'get') | ||
111 | )); | ||
112 | // trailing slash and unsafe method | ||
113 | $collection->add('baz5unsafe', new Route( | ||
114 | '/testunsafe/{foo}/', | ||
115 | array(), | ||
116 | array('_method' => 'post') | ||
117 | )); | ||
118 | // complex | ||
119 | $collection->add('baz6', new Route( | ||
120 | '/test/baz', | ||
121 | array('foo' => 'bar baz') | ||
122 | )); | ||
123 | // space in path | ||
124 | $collection->add('baz7', new Route( | ||
125 | '/te st/baz' | ||
126 | )); | ||
127 | // space preceded with \ in path | ||
128 | $collection->add('baz8', new Route( | ||
129 | '/te\\ st/baz' | ||
130 | )); | ||
131 | // space preceded with \ in requirement | ||
132 | $collection->add('baz9', new Route( | ||
133 | '/test/{baz}', | ||
134 | array(), | ||
135 | array( | ||
136 | 'baz' => 'te\\\\ st', | ||
137 | ) | ||
138 | )); | ||
139 | |||
140 | $collection1 = new RouteCollection(); | ||
141 | |||
142 | $route1 = new Route('/route1', array(), array(), array(), 'a.example.com'); | ||
143 | $collection1->add('route1', $route1); | ||
144 | |||
145 | $collection2 = new RouteCollection(); | ||
146 | |||
147 | $route2 = new Route('/route2', array(), array(), array(), 'a.example.com'); | ||
148 | $collection2->add('route2', $route2); | ||
149 | |||
150 | $route3 = new Route('/route3', array(), array(), array(), 'b.example.com'); | ||
151 | $collection2->add('route3', $route3); | ||
152 | |||
153 | $collection2->addPrefix('/c2'); | ||
154 | $collection1->addCollection($collection2); | ||
155 | |||
156 | $route4 = new Route('/route4', array(), array(), array(), 'a.example.com'); | ||
157 | $collection1->add('route4', $route4); | ||
158 | |||
159 | $route5 = new Route('/route5', array(), array(), array(), 'c.example.com'); | ||
160 | $collection1->add('route5', $route5); | ||
161 | |||
162 | $route6 = new Route('/route6', array(), array(), array(), null); | ||
163 | $collection1->add('route6', $route6); | ||
164 | |||
165 | $collection->addCollection($collection1); | ||
166 | |||
167 | // host and variables | ||
168 | |||
169 | $collection1 = new RouteCollection(); | ||
170 | |||
171 | $route11 = new Route('/route11', array(), array(), array(), '{var1}.example.com'); | ||
172 | $collection1->add('route11', $route11); | ||
173 | |||
174 | $route12 = new Route('/route12', array('var1' => 'val'), array(), array(), '{var1}.example.com'); | ||
175 | $collection1->add('route12', $route12); | ||
176 | |||
177 | $route13 = new Route('/route13/{name}', array(), array(), array(), '{var1}.example.com'); | ||
178 | $collection1->add('route13', $route13); | ||
179 | |||
180 | $route14 = new Route('/route14/{name}', array('var1' => 'val'), array(), array(), '{var1}.example.com'); | ||
181 | $collection1->add('route14', $route14); | ||
182 | |||
183 | $route15 = new Route('/route15/{name}', array(), array(), array(), 'c.example.com'); | ||
184 | $collection1->add('route15', $route15); | ||
185 | |||
186 | $route16 = new Route('/route16/{name}', array('var1' => 'val'), array(), array(), null); | ||
187 | $collection1->add('route16', $route16); | ||
188 | |||
189 | $route17 = new Route('/route17', array(), array(), array(), null); | ||
190 | $collection1->add('route17', $route17); | ||
191 | |||
192 | $collection->addCollection($collection1); | ||
193 | |||
194 | return $collection; | ||
195 | } | ||
196 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperCollectionTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperCollectionTest.php new file mode 100644 index 00000000..54b37727 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperCollectionTest.php | |||
@@ -0,0 +1,33 @@ | |||
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\Test\Matcher\Dumper; | ||
13 | |||
14 | use Symfony\Component\Routing\Matcher\Dumper\DumperCollection; | ||
15 | |||
16 | class DumperCollectionTest extends \PHPUnit_Framework_TestCase | ||
17 | { | ||
18 | public function testGetRoot() | ||
19 | { | ||
20 | $a = new DumperCollection(); | ||
21 | |||
22 | $b = new DumperCollection(); | ||
23 | $a->add($b); | ||
24 | |||
25 | $c = new DumperCollection(); | ||
26 | $b->add($c); | ||
27 | |||
28 | $d = new DumperCollection(); | ||
29 | $c->add($d); | ||
30 | |||
31 | $this->assertSame($a, $c->getRoot()); | ||
32 | } | ||
33 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperPrefixCollectionTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperPrefixCollectionTest.php new file mode 100644 index 00000000..7b4565c4 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperPrefixCollectionTest.php | |||
@@ -0,0 +1,123 @@ | |||
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 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php new file mode 100644 index 00000000..542ede85 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php | |||
@@ -0,0 +1,261 @@ | |||
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\Matcher\Dumper\PhpMatcherDumper; | ||
15 | use Symfony\Component\Routing\Route; | ||
16 | use Symfony\Component\Routing\RouteCollection; | ||
17 | |||
18 | class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | /** | ||
21 | * @expectedException \LogicException | ||
22 | */ | ||
23 | public function testDumpWhenSchemeIsUsedWithoutAProperDumper() | ||
24 | { | ||
25 | $collection = new RouteCollection(); | ||
26 | $collection->add('secure', new Route( | ||
27 | '/secure', | ||
28 | array(), | ||
29 | array('_scheme' => 'https') | ||
30 | )); | ||
31 | $dumper = new PhpMatcherDumper($collection); | ||
32 | $dumper->dump(); | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | * @dataProvider getRouteCollections | ||
37 | */ | ||
38 | public function testDump(RouteCollection $collection, $fixture, $options = array()) | ||
39 | { | ||
40 | $basePath = __DIR__.'/../../Fixtures/dumper/'; | ||
41 | |||
42 | $dumper = new PhpMatcherDumper($collection); | ||
43 | $this->assertStringEqualsFile($basePath.$fixture, $dumper->dump($options), '->dump() correctly dumps routes as optimized PHP code.'); | ||
44 | } | ||
45 | |||
46 | public function getRouteCollections() | ||
47 | { | ||
48 | /* test case 1 */ | ||
49 | |||
50 | $collection = new RouteCollection(); | ||
51 | |||
52 | $collection->add('overridden', new Route('/overridden')); | ||
53 | |||
54 | // defaults and requirements | ||
55 | $collection->add('foo', new Route( | ||
56 | '/foo/{bar}', | ||
57 | array('def' => 'test'), | ||
58 | array('bar' => 'baz|symfony') | ||
59 | )); | ||
60 | // method requirement | ||
61 | $collection->add('bar', new Route( | ||
62 | '/bar/{foo}', | ||
63 | array(), | ||
64 | array('_method' => 'GET|head') | ||
65 | )); | ||
66 | // GET method requirement automatically adds HEAD as valid | ||
67 | $collection->add('barhead', new Route( | ||
68 | '/barhead/{foo}', | ||
69 | array(), | ||
70 | array('_method' => 'GET') | ||
71 | )); | ||
72 | // simple | ||
73 | $collection->add('baz', new Route( | ||
74 | '/test/baz' | ||
75 | )); | ||
76 | // simple with extension | ||
77 | $collection->add('baz2', new Route( | ||
78 | '/test/baz.html' | ||
79 | )); | ||
80 | // trailing slash | ||
81 | $collection->add('baz3', new Route( | ||
82 | '/test/baz3/' | ||
83 | )); | ||
84 | // trailing slash with variable | ||
85 | $collection->add('baz4', new Route( | ||
86 | '/test/{foo}/' | ||
87 | )); | ||
88 | // trailing slash and method | ||
89 | $collection->add('baz5', new Route( | ||
90 | '/test/{foo}/', | ||
91 | array(), | ||
92 | array('_method' => 'post') | ||
93 | )); | ||
94 | // complex name | ||
95 | $collection->add('baz.baz6', new Route( | ||
96 | '/test/{foo}/', | ||
97 | array(), | ||
98 | array('_method' => 'put') | ||
99 | )); | ||
100 | // defaults without variable | ||
101 | $collection->add('foofoo', new Route( | ||
102 | '/foofoo', | ||
103 | array('def' => 'test') | ||
104 | )); | ||
105 | // pattern with quotes | ||
106 | $collection->add('quoter', new Route( | ||
107 | '/{quoter}', | ||
108 | array(), | ||
109 | array('quoter' => '[\']+') | ||
110 | )); | ||
111 | // space in pattern | ||
112 | $collection->add('space', new Route( | ||
113 | '/spa ce' | ||
114 | )); | ||
115 | |||
116 | // prefixes | ||
117 | $collection1 = new RouteCollection(); | ||
118 | $collection1->add('overridden', new Route('/overridden1')); | ||
119 | $collection1->add('foo1', new Route('/{foo}')); | ||
120 | $collection1->add('bar1', new Route('/{bar}')); | ||
121 | $collection1->addPrefix('/b\'b'); | ||
122 | $collection2 = new RouteCollection(); | ||
123 | $collection2->addCollection($collection1); | ||
124 | $collection2->add('overridden', new Route('/{var}', array(), array('var' => '.*'))); | ||
125 | $collection1 = new RouteCollection(); | ||
126 | $collection1->add('foo2', new Route('/{foo1}')); | ||
127 | $collection1->add('bar2', new Route('/{bar1}')); | ||
128 | $collection1->addPrefix('/b\'b'); | ||
129 | $collection2->addCollection($collection1); | ||
130 | $collection2->addPrefix('/a'); | ||
131 | $collection->addCollection($collection2); | ||
132 | |||
133 | // overridden through addCollection() and multiple sub-collections with no own prefix | ||
134 | $collection1 = new RouteCollection(); | ||
135 | $collection1->add('overridden2', new Route('/old')); | ||
136 | $collection1->add('helloWorld', new Route('/hello/{who}', array('who' => 'World!'))); | ||
137 | $collection2 = new RouteCollection(); | ||
138 | $collection3 = new RouteCollection(); | ||
139 | $collection3->add('overridden2', new Route('/new')); | ||
140 | $collection3->add('hey', new Route('/hey/')); | ||
141 | $collection2->addCollection($collection3); | ||
142 | $collection1->addCollection($collection2); | ||
143 | $collection1->addPrefix('/multi'); | ||
144 | $collection->addCollection($collection1); | ||
145 | |||
146 | // "dynamic" prefix | ||
147 | $collection1 = new RouteCollection(); | ||
148 | $collection1->add('foo3', new Route('/{foo}')); | ||
149 | $collection1->add('bar3', new Route('/{bar}')); | ||
150 | $collection1->addPrefix('/b'); | ||
151 | $collection1->addPrefix('{_locale}'); | ||
152 | $collection->addCollection($collection1); | ||
153 | |||
154 | // route between collections | ||
155 | $collection->add('ababa', new Route('/ababa')); | ||
156 | |||
157 | // collection with static prefix but only one route | ||
158 | $collection1 = new RouteCollection(); | ||
159 | $collection1->add('foo4', new Route('/{foo}')); | ||
160 | $collection1->addPrefix('/aba'); | ||
161 | $collection->addCollection($collection1); | ||
162 | |||
163 | // prefix and host | ||
164 | |||
165 | $collection1 = new RouteCollection(); | ||
166 | |||
167 | $route1 = new Route('/route1', array(), array(), array(), 'a.example.com'); | ||
168 | $collection1->add('route1', $route1); | ||
169 | |||
170 | $collection2 = new RouteCollection(); | ||
171 | |||
172 | $route2 = new Route('/c2/route2', array(), array(), array(), 'a.example.com'); | ||
173 | $collection1->add('route2', $route2); | ||
174 | |||
175 | $route3 = new Route('/c2/route3', array(), array(), array(), 'b.example.com'); | ||
176 | $collection1->add('route3', $route3); | ||
177 | |||
178 | $route4 = new Route('/route4', array(), array(), array(), 'a.example.com'); | ||
179 | $collection1->add('route4', $route4); | ||
180 | |||
181 | $route5 = new Route('/route5', array(), array(), array(), 'c.example.com'); | ||
182 | $collection1->add('route5', $route5); | ||
183 | |||
184 | $route6 = new Route('/route6', array(), array(), array(), null); | ||
185 | $collection1->add('route6', $route6); | ||
186 | |||
187 | $collection->addCollection($collection1); | ||
188 | |||
189 | // host and variables | ||
190 | |||
191 | $collection1 = new RouteCollection(); | ||
192 | |||
193 | $route11 = new Route('/route11', array(), array(), array(), '{var1}.example.com'); | ||
194 | $collection1->add('route11', $route11); | ||
195 | |||
196 | $route12 = new Route('/route12', array('var1' => 'val'), array(), array(), '{var1}.example.com'); | ||
197 | $collection1->add('route12', $route12); | ||
198 | |||
199 | $route13 = new Route('/route13/{name}', array(), array(), array(), '{var1}.example.com'); | ||
200 | $collection1->add('route13', $route13); | ||
201 | |||
202 | $route14 = new Route('/route14/{name}', array('var1' => 'val'), array(), array(), '{var1}.example.com'); | ||
203 | $collection1->add('route14', $route14); | ||
204 | |||
205 | $route15 = new Route('/route15/{name}', array(), array(), array(), 'c.example.com'); | ||
206 | $collection1->add('route15', $route15); | ||
207 | |||
208 | $route16 = new Route('/route16/{name}', array('var1' => 'val'), array(), array(), null); | ||
209 | $collection1->add('route16', $route16); | ||
210 | |||
211 | $route17 = new Route('/route17', array(), array(), array(), null); | ||
212 | $collection1->add('route17', $route17); | ||
213 | |||
214 | $collection->addCollection($collection1); | ||
215 | |||
216 | // multiple sub-collections with a single route and a prefix each | ||
217 | $collection1 = new RouteCollection(); | ||
218 | $collection1->add('a', new Route('/a...')); | ||
219 | $collection2 = new RouteCollection(); | ||
220 | $collection2->add('b', new Route('/{var}')); | ||
221 | $collection3 = new RouteCollection(); | ||
222 | $collection3->add('c', new Route('/{var}')); | ||
223 | $collection3->addPrefix('/c'); | ||
224 | $collection2->addCollection($collection3); | ||
225 | $collection2->addPrefix('/b'); | ||
226 | $collection1->addCollection($collection2); | ||
227 | $collection1->addPrefix('/a'); | ||
228 | $collection->addCollection($collection1); | ||
229 | |||
230 | /* test case 2 */ | ||
231 | |||
232 | $redirectCollection = clone $collection; | ||
233 | |||
234 | // force HTTPS redirection | ||
235 | $redirectCollection->add('secure', new Route( | ||
236 | '/secure', | ||
237 | array(), | ||
238 | array('_scheme' => 'https') | ||
239 | )); | ||
240 | |||
241 | // force HTTP redirection | ||
242 | $redirectCollection->add('nonsecure', new Route( | ||
243 | '/nonsecure', | ||
244 | array(), | ||
245 | array('_scheme' => 'http') | ||
246 | )); | ||
247 | |||
248 | /* test case 3 */ | ||
249 | |||
250 | $rootprefixCollection = new RouteCollection(); | ||
251 | $rootprefixCollection->add('static', new Route('/test')); | ||
252 | $rootprefixCollection->add('dynamic', new Route('/{var}')); | ||
253 | $rootprefixCollection->addPrefix('rootprefix'); | ||
254 | |||
255 | return array( | ||
256 | array($collection, 'url_matcher1.php', array()), | ||
257 | array($redirectCollection, 'url_matcher2.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')), | ||
258 | array($rootprefixCollection, 'url_matcher3.php', array()) | ||
259 | ); | ||
260 | } | ||
261 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php new file mode 100644 index 00000000..2ad4fc87 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php | |||
@@ -0,0 +1,58 @@ | |||
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 | |||
18 | class RedirectableUrlMatcherTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | public function testRedirectWhenNoSlash() | ||
21 | { | ||
22 | $coll = new RouteCollection(); | ||
23 | $coll->add('foo', new Route('/foo/')); | ||
24 | |||
25 | $matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext())); | ||
26 | $matcher->expects($this->once())->method('redirect'); | ||
27 | $matcher->match('/foo'); | ||
28 | } | ||
29 | |||
30 | /** | ||
31 | * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException | ||
32 | */ | ||
33 | public function testRedirectWhenNoSlashForNonSafeMethod() | ||
34 | { | ||
35 | $coll = new RouteCollection(); | ||
36 | $coll->add('foo', new Route('/foo/')); | ||
37 | |||
38 | $context = new RequestContext(); | ||
39 | $context->setMethod('POST'); | ||
40 | $matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, $context)); | ||
41 | $matcher->match('/foo'); | ||
42 | } | ||
43 | |||
44 | public function testSchemeRedirect() | ||
45 | { | ||
46 | $coll = new RouteCollection(); | ||
47 | $coll->add('foo', new Route('/foo', array(), array('_scheme' => 'https'))); | ||
48 | |||
49 | $matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext())); | ||
50 | $matcher | ||
51 | ->expects($this->once()) | ||
52 | ->method('redirect') | ||
53 | ->with('/foo', 'foo', 'https') | ||
54 | ->will($this->returnValue(array('_route' => 'foo'))) | ||
55 | ; | ||
56 | $matcher->match('/foo'); | ||
57 | } | ||
58 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/TraceableUrlMatcherTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/TraceableUrlMatcherTest.php new file mode 100644 index 00000000..86d8d954 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/TraceableUrlMatcherTest.php | |||
@@ -0,0 +1,66 @@ | |||
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 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php new file mode 100644 index 00000000..8a1428f1 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php | |||
@@ -0,0 +1,383 @@ | |||
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\Exception\MethodNotAllowedException; | ||
15 | use Symfony\Component\Routing\Exception\ResourceNotFoundException; | ||
16 | use Symfony\Component\Routing\Matcher\UrlMatcher; | ||
17 | use Symfony\Component\Routing\Route; | ||
18 | use Symfony\Component\Routing\RouteCollection; | ||
19 | use Symfony\Component\Routing\RequestContext; | ||
20 | |||
21 | class UrlMatcherTest extends \PHPUnit_Framework_TestCase | ||
22 | { | ||
23 | public function testNoMethodSoAllowed() | ||
24 | { | ||
25 | $coll = new RouteCollection(); | ||
26 | $coll->add('foo', new Route('/foo')); | ||
27 | |||
28 | $matcher = new UrlMatcher($coll, new RequestContext()); | ||
29 | $matcher->match('/foo'); | ||
30 | } | ||
31 | |||
32 | public function testMethodNotAllowed() | ||
33 | { | ||
34 | $coll = new RouteCollection(); | ||
35 | $coll->add('foo', new Route('/foo', array(), array('_method' => 'post'))); | ||
36 | |||
37 | $matcher = new UrlMatcher($coll, new RequestContext()); | ||
38 | |||
39 | try { | ||
40 | $matcher->match('/foo'); | ||
41 | $this->fail(); | ||
42 | } catch (MethodNotAllowedException $e) { | ||
43 | $this->assertEquals(array('POST'), $e->getAllowedMethods()); | ||
44 | } | ||
45 | } | ||
46 | |||
47 | public function testHeadAllowedWhenRequirementContainsGet() | ||
48 | { | ||
49 | $coll = new RouteCollection(); | ||
50 | $coll->add('foo', new Route('/foo', array(), array('_method' => 'get'))); | ||
51 | |||
52 | $matcher = new UrlMatcher($coll, new RequestContext('', 'head')); | ||
53 | $matcher->match('/foo'); | ||
54 | } | ||
55 | |||
56 | public function testMethodNotAllowedAggregatesAllowedMethods() | ||
57 | { | ||
58 | $coll = new RouteCollection(); | ||
59 | $coll->add('foo1', new Route('/foo', array(), array('_method' => 'post'))); | ||
60 | $coll->add('foo2', new Route('/foo', array(), array('_method' => 'put|delete'))); | ||
61 | |||
62 | $matcher = new UrlMatcher($coll, new RequestContext()); | ||
63 | |||
64 | try { | ||
65 | $matcher->match('/foo'); | ||
66 | $this->fail(); | ||
67 | } catch (MethodNotAllowedException $e) { | ||
68 | $this->assertEquals(array('POST', 'PUT', 'DELETE'), $e->getAllowedMethods()); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | public function testMatch() | ||
73 | { | ||
74 | // test the patterns are matched and parameters are returned | ||
75 | $collection = new RouteCollection(); | ||
76 | $collection->add('foo', new Route('/foo/{bar}')); | ||
77 | $matcher = new UrlMatcher($collection, new RequestContext()); | ||
78 | try { | ||
79 | $matcher->match('/no-match'); | ||
80 | $this->fail(); | ||
81 | } catch (ResourceNotFoundException $e) {} | ||
82 | $this->assertEquals(array('_route' => 'foo', 'bar' => 'baz'), $matcher->match('/foo/baz')); | ||
83 | |||
84 | // test that defaults are merged | ||
85 | $collection = new RouteCollection(); | ||
86 | $collection->add('foo', new Route('/foo/{bar}', array('def' => 'test'))); | ||
87 | $matcher = new UrlMatcher($collection, new RequestContext()); | ||
88 | $this->assertEquals(array('_route' => 'foo', 'bar' => 'baz', 'def' => 'test'), $matcher->match('/foo/baz')); | ||
89 | |||
90 | // test that route "method" is ignored if no method is given in the context | ||
91 | $collection = new RouteCollection(); | ||
92 | $collection->add('foo', new Route('/foo', array(), array('_method' => 'GET|head'))); | ||
93 | $matcher = new UrlMatcher($collection, new RequestContext()); | ||
94 | $this->assertInternalType('array', $matcher->match('/foo')); | ||
95 | |||
96 | // route does not match with POST method context | ||
97 | $matcher = new UrlMatcher($collection, new RequestContext('', 'post')); | ||
98 | try { | ||
99 | $matcher->match('/foo'); | ||
100 | $this->fail(); | ||
101 | } catch (MethodNotAllowedException $e) {} | ||
102 | |||
103 | // route does match with GET or HEAD method context | ||
104 | $matcher = new UrlMatcher($collection, new RequestContext()); | ||
105 | $this->assertInternalType('array', $matcher->match('/foo')); | ||
106 | $matcher = new UrlMatcher($collection, new RequestContext('', 'head')); | ||
107 | $this->assertInternalType('array', $matcher->match('/foo')); | ||
108 | |||
109 | // route with an optional variable as the first segment | ||
110 | $collection = new RouteCollection(); | ||
111 | $collection->add('bar', new Route('/{bar}/foo', array('bar' => 'bar'), array('bar' => 'foo|bar'))); | ||
112 | $matcher = new UrlMatcher($collection, new RequestContext()); | ||
113 | $this->assertEquals(array('_route' => 'bar', 'bar' => 'bar'), $matcher->match('/bar/foo')); | ||
114 | $this->assertEquals(array('_route' => 'bar', 'bar' => 'foo'), $matcher->match('/foo/foo')); | ||
115 | |||
116 | $collection = new RouteCollection(); | ||
117 | $collection->add('bar', new Route('/{bar}', array('bar' => 'bar'), array('bar' => 'foo|bar'))); | ||
118 | $matcher = new UrlMatcher($collection, new RequestContext()); | ||
119 | $this->assertEquals(array('_route' => 'bar', 'bar' => 'foo'), $matcher->match('/foo')); | ||
120 | $this->assertEquals(array('_route' => 'bar', 'bar' => 'bar'), $matcher->match('/')); | ||
121 | |||
122 | // route with only optional variables | ||
123 | $collection = new RouteCollection(); | ||
124 | $collection->add('bar', new Route('/{foo}/{bar}', array('foo' => 'foo', 'bar' => 'bar'), array())); | ||
125 | $matcher = new UrlMatcher($collection, new RequestContext()); | ||
126 | $this->assertEquals(array('_route' => 'bar', 'foo' => 'foo', 'bar' => 'bar'), $matcher->match('/')); | ||
127 | $this->assertEquals(array('_route' => 'bar', 'foo' => 'a', 'bar' => 'bar'), $matcher->match('/a')); | ||
128 | $this->assertEquals(array('_route' => 'bar', 'foo' => 'a', 'bar' => 'b'), $matcher->match('/a/b')); | ||
129 | } | ||
130 | |||
131 | public function testMatchWithPrefixes() | ||
132 | { | ||
133 | $collection = new RouteCollection(); | ||
134 | $collection->add('foo', new Route('/{foo}')); | ||
135 | $collection->addPrefix('/b'); | ||
136 | $collection->addPrefix('/a'); | ||
137 | |||
138 | $matcher = new UrlMatcher($collection, new RequestContext()); | ||
139 | $this->assertEquals(array('_route' => 'foo', 'foo' => 'foo'), $matcher->match('/a/b/foo')); | ||
140 | } | ||
141 | |||
142 | public function testMatchWithDynamicPrefix() | ||
143 | { | ||
144 | $collection = new RouteCollection(); | ||
145 | $collection->add('foo', new Route('/{foo}')); | ||
146 | $collection->addPrefix('/b'); | ||
147 | $collection->addPrefix('/{_locale}'); | ||
148 | |||
149 | $matcher = new UrlMatcher($collection, new RequestContext()); | ||
150 | $this->assertEquals(array('_locale' => 'fr', '_route' => 'foo', 'foo' => 'foo'), $matcher->match('/fr/b/foo')); | ||
151 | } | ||
152 | |||
153 | public function testMatchSpecialRouteName() | ||
154 | { | ||
155 | $collection = new RouteCollection(); | ||
156 | $collection->add('$péß^a|', new Route('/bar')); | ||
157 | |||
158 | $matcher = new UrlMatcher($collection, new RequestContext()); | ||
159 | $this->assertEquals(array('_route' => '$péß^a|'), $matcher->match('/bar')); | ||
160 | } | ||
161 | |||
162 | public function testMatchNonAlpha() | ||
163 | { | ||
164 | $collection = new RouteCollection(); | ||
165 | $chars = '!"$%éà &\'()*+,./:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\[]^_`abcdefghijklmnopqrstuvwxyz{|}~-'; | ||
166 | $collection->add('foo', new Route('/{foo}/bar', array(), array('foo' => '['.preg_quote($chars).']+'))); | ||
167 | |||
168 | $matcher = new UrlMatcher($collection, new RequestContext()); | ||
169 | $this->assertEquals(array('_route' => 'foo', 'foo' => $chars), $matcher->match('/'.rawurlencode($chars).'/bar')); | ||
170 | $this->assertEquals(array('_route' => 'foo', 'foo' => $chars), $matcher->match('/'.strtr($chars, array('%' => '%25')).'/bar')); | ||
171 | } | ||
172 | |||
173 | public function testMatchWithDotMetacharacterInRequirements() | ||
174 | { | ||
175 | $collection = new RouteCollection(); | ||
176 | $collection->add('foo', new Route('/{foo}/bar', array(), array('foo' => '.+'))); | ||
177 | |||
178 | $matcher = new UrlMatcher($collection, new RequestContext()); | ||
179 | $this->assertEquals(array('_route' => 'foo', 'foo' => "\n"), $matcher->match('/'.urlencode("\n").'/bar'), 'linefeed character is matched'); | ||
180 | } | ||
181 | |||
182 | public function testMatchOverriddenRoute() | ||
183 | { | ||
184 | $collection = new RouteCollection(); | ||
185 | $collection->add('foo', new Route('/foo')); | ||
186 | |||
187 | $collection1 = new RouteCollection(); | ||
188 | $collection1->add('foo', new Route('/foo1')); | ||
189 | |||
190 | $collection->addCollection($collection1); | ||
191 | |||
192 | $matcher = new UrlMatcher($collection, new RequestContext()); | ||
193 | |||
194 | $this->assertEquals(array('_route' => 'foo'), $matcher->match('/foo1')); | ||
195 | $this->setExpectedException('Symfony\Component\Routing\Exception\ResourceNotFoundException'); | ||
196 | $this->assertEquals(array(), $matcher->match('/foo')); | ||
197 | } | ||
198 | |||
199 | public function testMatchRegression() | ||
200 | { | ||
201 | $coll = new RouteCollection(); | ||
202 | $coll->add('foo', new Route('/foo/{foo}')); | ||
203 | $coll->add('bar', new Route('/foo/bar/{foo}')); | ||
204 | |||
205 | $matcher = new UrlMatcher($coll, new RequestContext()); | ||
206 | $this->assertEquals(array('foo' => 'bar', '_route' => 'bar'), $matcher->match('/foo/bar/bar')); | ||
207 | |||
208 | $collection = new RouteCollection(); | ||
209 | $collection->add('foo', new Route('/{bar}')); | ||
210 | $matcher = new UrlMatcher($collection, new RequestContext()); | ||
211 | try { | ||
212 | $matcher->match('/'); | ||
213 | $this->fail(); | ||
214 | } catch (ResourceNotFoundException $e) { | ||
215 | } | ||
216 | } | ||
217 | |||
218 | public function testDefaultRequirementForOptionalVariables() | ||
219 | { | ||
220 | $coll = new RouteCollection(); | ||
221 | $coll->add('test', new Route('/{page}.{_format}', array('page' => 'index', '_format' => 'html'))); | ||
222 | |||
223 | $matcher = new UrlMatcher($coll, new RequestContext()); | ||
224 | $this->assertEquals(array('page' => 'my-page', '_format' => 'xml', '_route' => 'test'), $matcher->match('/my-page.xml')); | ||
225 | } | ||
226 | |||
227 | public function testMatchingIsEager() | ||
228 | { | ||
229 | $coll = new RouteCollection(); | ||
230 | $coll->add('test', new Route('/{foo}-{bar}-', array(), array('foo' => '.+', 'bar' => '.+'))); | ||
231 | |||
232 | $matcher = new UrlMatcher($coll, new RequestContext()); | ||
233 | $this->assertEquals(array('foo' => 'text1-text2-text3', 'bar' => 'text4', '_route' => 'test'), $matcher->match('/text1-text2-text3-text4-')); | ||
234 | } | ||
235 | |||
236 | public function testAdjacentVariables() | ||
237 | { | ||
238 | $coll = new RouteCollection(); | ||
239 | $coll->add('test', new Route('/{w}{x}{y}{z}.{_format}', array('z' => 'default-z', '_format' => 'html'), array('y' => 'y|Y'))); | ||
240 | |||
241 | $matcher = new UrlMatcher($coll, new RequestContext()); | ||
242 | // 'w' eagerly matches as much as possible and the other variables match the remaining chars. | ||
243 | // This also shows that the variables w-z must all exclude the separating char (the dot '.' in this case) by default requirement. | ||
244 | // Otherwise they would also consume '.xml' and _format would never match as it's an optional variable. | ||
245 | $this->assertEquals(array('w' => 'wwwww', 'x' => 'x', 'y' => 'Y', 'z' => 'Z','_format' => 'xml', '_route' => 'test'), $matcher->match('/wwwwwxYZ.xml')); | ||
246 | // As 'y' has custom requirement and can only be of value 'y|Y', it will leave 'ZZZ' to variable z. | ||
247 | // So with carefully chosen requirements adjacent variables, can be useful. | ||
248 | $this->assertEquals(array('w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'ZZZ','_format' => 'html', '_route' => 'test'), $matcher->match('/wwwwwxyZZZ')); | ||
249 | // z and _format are optional. | ||
250 | $this->assertEquals(array('w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'default-z','_format' => 'html', '_route' => 'test'), $matcher->match('/wwwwwxy')); | ||
251 | |||
252 | $this->setExpectedException('Symfony\Component\Routing\Exception\ResourceNotFoundException'); | ||
253 | $matcher->match('/wxy.html'); | ||
254 | } | ||
255 | |||
256 | public function testOptionalVariableWithNoRealSeparator() | ||
257 | { | ||
258 | $coll = new RouteCollection(); | ||
259 | $coll->add('test', new Route('/get{what}', array('what' => 'All'))); | ||
260 | $matcher = new UrlMatcher($coll, new RequestContext()); | ||
261 | |||
262 | $this->assertEquals(array('what' => 'All', '_route' => 'test'), $matcher->match('/get')); | ||
263 | $this->assertEquals(array('what' => 'Sites', '_route' => 'test'), $matcher->match('/getSites')); | ||
264 | |||
265 | // Usually the character in front of an optional parameter can be left out, e.g. with pattern '/get/{what}' just '/get' would match. | ||
266 | // But here the 't' in 'get' is not a separating character, so it makes no sense to match without it. | ||
267 | $this->setExpectedException('Symfony\Component\Routing\Exception\ResourceNotFoundException'); | ||
268 | $matcher->match('/ge'); | ||
269 | } | ||
270 | |||
271 | public function testRequiredVariableWithNoRealSeparator() | ||
272 | { | ||
273 | $coll = new RouteCollection(); | ||
274 | $coll->add('test', new Route('/get{what}Suffix')); | ||
275 | $matcher = new UrlMatcher($coll, new RequestContext()); | ||
276 | |||
277 | $this->assertEquals(array('what' => 'Sites', '_route' => 'test'), $matcher->match('/getSitesSuffix')); | ||
278 | } | ||
279 | |||
280 | public function testDefaultRequirementOfVariable() | ||
281 | { | ||
282 | $coll = new RouteCollection(); | ||
283 | $coll->add('test', new Route('/{page}.{_format}')); | ||
284 | $matcher = new UrlMatcher($coll, new RequestContext()); | ||
285 | |||
286 | $this->assertEquals(array('page' => 'index', '_format' => 'mobile.html', '_route' => 'test'), $matcher->match('/index.mobile.html')); | ||
287 | } | ||
288 | |||
289 | /** | ||
290 | * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException | ||
291 | */ | ||
292 | public function testDefaultRequirementOfVariableDisallowsSlash() | ||
293 | { | ||
294 | $coll = new RouteCollection(); | ||
295 | $coll->add('test', new Route('/{page}.{_format}')); | ||
296 | $matcher = new UrlMatcher($coll, new RequestContext()); | ||
297 | |||
298 | $matcher->match('/index.sl/ash'); | ||
299 | } | ||
300 | |||
301 | /** | ||
302 | * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException | ||
303 | */ | ||
304 | public function testDefaultRequirementOfVariableDisallowsNextSeparator() | ||
305 | { | ||
306 | $coll = new RouteCollection(); | ||
307 | $coll->add('test', new Route('/{page}.{_format}', array(), array('_format' => 'html|xml'))); | ||
308 | $matcher = new UrlMatcher($coll, new RequestContext()); | ||
309 | |||
310 | $matcher->match('/do.t.html'); | ||
311 | } | ||
312 | |||
313 | /** | ||
314 | * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException | ||
315 | */ | ||
316 | public function testSchemeRequirement() | ||
317 | { | ||
318 | $coll = new RouteCollection(); | ||
319 | $coll->add('foo', new Route('/foo', array(), array('_scheme' => 'https'))); | ||
320 | $matcher = new UrlMatcher($coll, new RequestContext()); | ||
321 | $matcher->match('/foo'); | ||
322 | } | ||
323 | |||
324 | public function testDecodeOnce() | ||
325 | { | ||
326 | $coll = new RouteCollection(); | ||
327 | $coll->add('foo', new Route('/foo/{foo}')); | ||
328 | |||
329 | $matcher = new UrlMatcher($coll, new RequestContext()); | ||
330 | $this->assertEquals(array('foo' => 'bar%23', '_route' => 'foo'), $matcher->match('/foo/bar%2523')); | ||
331 | } | ||
332 | |||
333 | public function testCannotRelyOnPrefix() | ||
334 | { | ||
335 | $coll = new RouteCollection(); | ||
336 | |||
337 | $subColl = new RouteCollection(); | ||
338 | $subColl->add('bar', new Route('/bar')); | ||
339 | $subColl->addPrefix('/prefix'); | ||
340 | // overwrite the pattern, so the prefix is not valid anymore for this route in the collection | ||
341 | $subColl->get('bar')->setPattern('/new'); | ||
342 | |||
343 | $coll->addCollection($subColl); | ||
344 | |||
345 | $matcher = new UrlMatcher($coll, new RequestContext()); | ||
346 | $this->assertEquals(array('_route' => 'bar'), $matcher->match('/new')); | ||
347 | } | ||
348 | |||
349 | public function testWithHost() | ||
350 | { | ||
351 | $coll = new RouteCollection(); | ||
352 | $coll->add('foo', new Route('/foo/{foo}', array(), array(), array(), '{locale}.example.com')); | ||
353 | |||
354 | $matcher = new UrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com')); | ||
355 | $this->assertEquals(array('foo' => 'bar', '_route' => 'foo', 'locale' => 'en'), $matcher->match('/foo/bar')); | ||
356 | } | ||
357 | |||
358 | public function testWithHostOnRouteCollection() | ||
359 | { | ||
360 | $coll = new RouteCollection(); | ||
361 | $coll->add('foo', new Route('/foo/{foo}')); | ||
362 | $coll->add('bar', new Route('/bar/{foo}', array(), array(), array(), '{locale}.example.net')); | ||
363 | $coll->setHost('{locale}.example.com'); | ||
364 | |||
365 | $matcher = new UrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com')); | ||
366 | $this->assertEquals(array('foo' => 'bar', '_route' => 'foo', 'locale' => 'en'), $matcher->match('/foo/bar')); | ||
367 | |||
368 | $matcher = new UrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com')); | ||
369 | $this->assertEquals(array('foo' => 'bar', '_route' => 'bar', 'locale' => 'en'), $matcher->match('/bar/bar')); | ||
370 | } | ||
371 | |||
372 | /** | ||
373 | * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException | ||
374 | */ | ||
375 | public function testWithOutHostHostDoesNotMatch() | ||
376 | { | ||
377 | $coll = new RouteCollection(); | ||
378 | $coll->add('foo', new Route('/foo/{foo}', array(), array(), array(), '{locale}.example.com')); | ||
379 | |||
380 | $matcher = new UrlMatcher($coll, new RequestContext('', 'GET', 'example.com')); | ||
381 | $matcher->match('/foo/bar'); | ||
382 | } | ||
383 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/RouteCollectionTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/RouteCollectionTest.php new file mode 100644 index 00000000..3d78adf9 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/RouteCollectionTest.php | |||
@@ -0,0 +1,255 @@ | |||
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; | ||
13 | |||
14 | use Symfony\Component\Routing\RouteCollection; | ||
15 | use Symfony\Component\Routing\Route; | ||
16 | use Symfony\Component\Config\Resource\FileResource; | ||
17 | |||
18 | class RouteCollectionTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | public function testRoute() | ||
21 | { | ||
22 | $collection = new RouteCollection(); | ||
23 | $route = new Route('/foo'); | ||
24 | $collection->add('foo', $route); | ||
25 | $this->assertEquals(array('foo' => $route), $collection->all(), '->add() adds a route'); | ||
26 | $this->assertEquals($route, $collection->get('foo'), '->get() returns a route by name'); | ||
27 | $this->assertNull($collection->get('bar'), '->get() returns null if a route does not exist'); | ||
28 | } | ||
29 | |||
30 | public function testOverriddenRoute() | ||
31 | { | ||
32 | $collection = new RouteCollection(); | ||
33 | $collection->add('foo', new Route('/foo')); | ||
34 | $collection->add('foo', new Route('/foo1')); | ||
35 | |||
36 | $this->assertEquals('/foo1', $collection->get('foo')->getPath()); | ||
37 | } | ||
38 | |||
39 | public function testDeepOverriddenRoute() | ||
40 | { | ||
41 | $collection = new RouteCollection(); | ||
42 | $collection->add('foo', new Route('/foo')); | ||
43 | |||
44 | $collection1 = new RouteCollection(); | ||
45 | $collection1->add('foo', new Route('/foo1')); | ||
46 | |||
47 | $collection2 = new RouteCollection(); | ||
48 | $collection2->add('foo', new Route('/foo2')); | ||
49 | |||
50 | $collection1->addCollection($collection2); | ||
51 | $collection->addCollection($collection1); | ||
52 | |||
53 | $this->assertEquals('/foo2', $collection1->get('foo')->getPath()); | ||
54 | $this->assertEquals('/foo2', $collection->get('foo')->getPath()); | ||
55 | } | ||
56 | |||
57 | public function testIterator() | ||
58 | { | ||
59 | $collection = new RouteCollection(); | ||
60 | $collection->add('foo', new Route('/foo')); | ||
61 | |||
62 | $collection1 = new RouteCollection(); | ||
63 | $collection1->add('bar', $bar = new Route('/bar')); | ||
64 | $collection1->add('foo', $foo = new Route('/foo-new')); | ||
65 | $collection->addCollection($collection1); | ||
66 | $collection->add('last', $last = new Route('/last')); | ||
67 | |||
68 | $this->assertInstanceOf('\ArrayIterator', $collection->getIterator()); | ||
69 | $this->assertSame(array('bar' => $bar, 'foo' => $foo, 'last' => $last), $collection->getIterator()->getArrayCopy()); | ||
70 | } | ||
71 | |||
72 | public function testCount() | ||
73 | { | ||
74 | $collection = new RouteCollection(); | ||
75 | $collection->add('foo', new Route('/foo')); | ||
76 | |||
77 | $collection1 = new RouteCollection(); | ||
78 | $collection1->add('bar', new Route('/bar')); | ||
79 | $collection->addCollection($collection1); | ||
80 | |||
81 | $this->assertCount(2, $collection); | ||
82 | } | ||
83 | |||
84 | public function testAddCollection() | ||
85 | { | ||
86 | $collection = new RouteCollection(); | ||
87 | $collection->add('foo', new Route('/foo')); | ||
88 | |||
89 | $collection1 = new RouteCollection(); | ||
90 | $collection1->add('bar', $bar = new Route('/bar')); | ||
91 | $collection1->add('foo', $foo = new Route('/foo-new')); | ||
92 | |||
93 | $collection2 = new RouteCollection(); | ||
94 | $collection2->add('grandchild', $grandchild = new Route('/grandchild')); | ||
95 | |||
96 | $collection1->addCollection($collection2); | ||
97 | $collection->addCollection($collection1); | ||
98 | $collection->add('last', $last = new Route('/last')); | ||
99 | |||
100 | $this->assertSame(array('bar' => $bar, 'foo' => $foo, 'grandchild' => $grandchild, 'last' => $last), $collection->all(), | ||
101 | '->addCollection() imports routes of another collection, overrides if necessary and adds them at the end'); | ||
102 | } | ||
103 | |||
104 | public function testAddCollectionWithResources() | ||
105 | { | ||
106 | if (!class_exists('Symfony\Component\Config\Resource\FileResource')) { | ||
107 | $this->markTestSkipped('The "Config" component is not available'); | ||
108 | } | ||
109 | |||
110 | $collection = new RouteCollection(); | ||
111 | $collection->addResource($foo = new FileResource(__DIR__.'/Fixtures/foo.xml')); | ||
112 | $collection1 = new RouteCollection(); | ||
113 | $collection1->addResource($foo1 = new FileResource(__DIR__.'/Fixtures/foo1.xml')); | ||
114 | $collection->addCollection($collection1); | ||
115 | $this->assertEquals(array($foo, $foo1), $collection->getResources(), '->addCollection() merges resources'); | ||
116 | } | ||
117 | |||
118 | public function testAddDefaultsAndRequirementsAndOptions() | ||
119 | { | ||
120 | $collection = new RouteCollection(); | ||
121 | $collection->add('foo', new Route('/{placeholder}')); | ||
122 | $collection1 = new RouteCollection(); | ||
123 | $collection1->add('bar', new Route('/{placeholder}', | ||
124 | array('_controller' => 'fixed', 'placeholder' => 'default'), array('placeholder' => '.+'), array('option' => 'value')) | ||
125 | ); | ||
126 | $collection->addCollection($collection1); | ||
127 | |||
128 | $collection->addDefaults(array('placeholder' => 'new-default')); | ||
129 | $this->assertEquals(array('placeholder' => 'new-default'), $collection->get('foo')->getDefaults(), '->addDefaults() adds defaults to all routes'); | ||
130 | $this->assertEquals(array('_controller' => 'fixed', 'placeholder' => 'new-default'), $collection->get('bar')->getDefaults(), | ||
131 | '->addDefaults() adds defaults to all routes and overwrites existing ones'); | ||
132 | |||
133 | $collection->addRequirements(array('placeholder' => '\d+')); | ||
134 | $this->assertEquals(array('placeholder' => '\d+'), $collection->get('foo')->getRequirements(), '->addRequirements() adds requirements to all routes'); | ||
135 | $this->assertEquals(array('placeholder' => '\d+'), $collection->get('bar')->getRequirements(), | ||
136 | '->addRequirements() adds requirements to all routes and overwrites existing ones'); | ||
137 | |||
138 | $collection->addOptions(array('option' => 'new-value')); | ||
139 | $this->assertEquals( | ||
140 | array('option' => 'new-value', 'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler'), | ||
141 | $collection->get('bar')->getOptions(), '->addOptions() adds options to all routes and overwrites existing ones' | ||
142 | ); | ||
143 | } | ||
144 | |||
145 | public function testAddPrefix() | ||
146 | { | ||
147 | $collection = new RouteCollection(); | ||
148 | $collection->add('foo', $foo = new Route('/foo')); | ||
149 | $collection2 = new RouteCollection(); | ||
150 | $collection2->add('bar', $bar = new Route('/bar')); | ||
151 | $collection->addCollection($collection2); | ||
152 | $collection->addPrefix(' / '); | ||
153 | $this->assertSame('/foo', $collection->get('foo')->getPattern(), '->addPrefix() trims the prefix and a single slash has no effect'); | ||
154 | $collection->addPrefix('/{admin}', array('admin' => 'admin'), array('admin' => '\d+')); | ||
155 | $this->assertEquals('/{admin}/foo', $collection->get('foo')->getPath(), '->addPrefix() adds a prefix to all routes'); | ||
156 | $this->assertEquals('/{admin}/bar', $collection->get('bar')->getPath(), '->addPrefix() adds a prefix to all routes'); | ||
157 | $this->assertEquals(array('admin' => 'admin'), $collection->get('foo')->getDefaults(), '->addPrefix() adds defaults to all routes'); | ||
158 | $this->assertEquals(array('admin' => 'admin'), $collection->get('bar')->getDefaults(), '->addPrefix() adds defaults to all routes'); | ||
159 | $this->assertEquals(array('admin' => '\d+'), $collection->get('foo')->getRequirements(), '->addPrefix() adds requirements to all routes'); | ||
160 | $this->assertEquals(array('admin' => '\d+'), $collection->get('bar')->getRequirements(), '->addPrefix() adds requirements to all routes'); | ||
161 | $collection->addPrefix('0'); | ||
162 | $this->assertEquals('/0/{admin}/foo', $collection->get('foo')->getPattern(), '->addPrefix() ensures a prefix must start with a slash and must not end with a slash'); | ||
163 | $collection->addPrefix('/ /'); | ||
164 | $this->assertSame('/ /0/{admin}/foo', $collection->get('foo')->getPath(), '->addPrefix() can handle spaces if desired'); | ||
165 | $this->assertSame('/ /0/{admin}/bar', $collection->get('bar')->getPath(), 'the route pattern of an added collection is in synch with the added prefix'); | ||
166 | } | ||
167 | |||
168 | public function testAddPrefixOverridesDefaultsAndRequirements() | ||
169 | { | ||
170 | $collection = new RouteCollection(); | ||
171 | $collection->add('foo', $foo = new Route('/foo')); | ||
172 | $collection->add('bar', $bar = new Route('/bar', array(), array('_scheme' => 'http'))); | ||
173 | $collection->addPrefix('/admin', array(), array('_scheme' => 'https')); | ||
174 | |||
175 | $this->assertEquals('https', $collection->get('foo')->getRequirement('_scheme'), '->addPrefix() overrides existing requirements'); | ||
176 | $this->assertEquals('https', $collection->get('bar')->getRequirement('_scheme'), '->addPrefix() overrides existing requirements'); | ||
177 | } | ||
178 | |||
179 | public function testResource() | ||
180 | { | ||
181 | if (!class_exists('Symfony\Component\Config\Resource\FileResource')) { | ||
182 | $this->markTestSkipped('The "Config" component is not available'); | ||
183 | } | ||
184 | |||
185 | $collection = new RouteCollection(); | ||
186 | $collection->addResource($foo = new FileResource(__DIR__.'/Fixtures/foo.xml')); | ||
187 | $collection->addResource($bar = new FileResource(__DIR__.'/Fixtures/bar.xml')); | ||
188 | $collection->addResource(new FileResource(__DIR__.'/Fixtures/foo.xml')); | ||
189 | |||
190 | $this->assertEquals(array($foo, $bar), $collection->getResources(), | ||
191 | '->addResource() adds a resource and getResources() only returns unique ones by comparing the string representation'); | ||
192 | } | ||
193 | |||
194 | public function testUniqueRouteWithGivenName() | ||
195 | { | ||
196 | $collection1 = new RouteCollection(); | ||
197 | $collection1->add('foo', new Route('/old')); | ||
198 | $collection2 = new RouteCollection(); | ||
199 | $collection3 = new RouteCollection(); | ||
200 | $collection3->add('foo', $new = new Route('/new')); | ||
201 | |||
202 | $collection2->addCollection($collection3); | ||
203 | $collection1->addCollection($collection2); | ||
204 | |||
205 | $this->assertSame($new, $collection1->get('foo'), '->get() returns new route that overrode previous one'); | ||
206 | // size of 1 because collection1 contains /new but not /old anymore | ||
207 | $this->assertCount(1, $collection1->getIterator(), '->addCollection() removes previous routes when adding new routes with the same name'); | ||
208 | } | ||
209 | |||
210 | public function testGet() | ||
211 | { | ||
212 | $collection1 = new RouteCollection(); | ||
213 | $collection1->add('a', $a = new Route('/a')); | ||
214 | $collection2 = new RouteCollection(); | ||
215 | $collection2->add('b', $b = new Route('/b')); | ||
216 | $collection1->addCollection($collection2); | ||
217 | $collection1->add('$péß^a|', $c = new Route('/special')); | ||
218 | |||
219 | $this->assertSame($b, $collection1->get('b'), '->get() returns correct route in child collection'); | ||
220 | $this->assertSame($c, $collection1->get('$péß^a|'), '->get() can handle special characters'); | ||
221 | $this->assertNull($collection2->get('a'), '->get() does not return the route defined in parent collection'); | ||
222 | $this->assertNull($collection1->get('non-existent'), '->get() returns null when route does not exist'); | ||
223 | $this->assertNull($collection1->get(0), '->get() does not disclose internal child RouteCollection'); | ||
224 | } | ||
225 | |||
226 | public function testRemove() | ||
227 | { | ||
228 | $collection = new RouteCollection(); | ||
229 | $collection->add('foo', $foo = new Route('/foo')); | ||
230 | |||
231 | $collection1 = new RouteCollection(); | ||
232 | $collection1->add('bar', $bar = new Route('/bar')); | ||
233 | $collection->addCollection($collection1); | ||
234 | $collection->add('last', $last = new Route('/last')); | ||
235 | |||
236 | $collection->remove('foo'); | ||
237 | $this->assertSame(array('bar' => $bar, 'last' => $last), $collection->all(), '->remove() can remove a single route'); | ||
238 | $collection->remove(array('bar', 'last')); | ||
239 | $this->assertSame(array(), $collection->all(), '->remove() accepts an array and can remove multiple routes at once'); | ||
240 | } | ||
241 | |||
242 | public function testSetHost() | ||
243 | { | ||
244 | $collection = new RouteCollection(); | ||
245 | $routea = new Route('/a'); | ||
246 | $routeb = new Route('/b', array(), array(), array(), '{locale}.example.net'); | ||
247 | $collection->add('a', $routea); | ||
248 | $collection->add('b', $routeb); | ||
249 | |||
250 | $collection->setHost('{locale}.example.com'); | ||
251 | |||
252 | $this->assertEquals('{locale}.example.com', $routea->getHost()); | ||
253 | $this->assertEquals('{locale}.example.com', $routeb->getHost()); | ||
254 | } | ||
255 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/RouteCompilerTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/RouteCompilerTest.php new file mode 100644 index 00000000..d663ae96 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/RouteCompilerTest.php | |||
@@ -0,0 +1,253 @@ | |||
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; | ||
13 | |||
14 | use Symfony\Component\Routing\Route; | ||
15 | |||
16 | class RouteCompilerTest extends \PHPUnit_Framework_TestCase | ||
17 | { | ||
18 | /** | ||
19 | * @dataProvider provideCompileData | ||
20 | */ | ||
21 | public function testCompile($name, $arguments, $prefix, $regex, $variables, $tokens) | ||
22 | { | ||
23 | $r = new \ReflectionClass('Symfony\\Component\\Routing\\Route'); | ||
24 | $route = $r->newInstanceArgs($arguments); | ||
25 | |||
26 | $compiled = $route->compile(); | ||
27 | $this->assertEquals($prefix, $compiled->getStaticPrefix(), $name.' (static prefix)'); | ||
28 | $this->assertEquals($regex, $compiled->getRegex(), $name.' (regex)'); | ||
29 | $this->assertEquals($variables, $compiled->getVariables(), $name.' (variables)'); | ||
30 | $this->assertEquals($tokens, $compiled->getTokens(), $name.' (tokens)'); | ||
31 | } | ||
32 | |||
33 | public function provideCompileData() | ||
34 | { | ||
35 | return array( | ||
36 | array( | ||
37 | 'Static route', | ||
38 | array('/foo'), | ||
39 | '/foo', '#^/foo$#s', array(), array( | ||
40 | array('text', '/foo'), | ||
41 | )), | ||
42 | |||
43 | array( | ||
44 | 'Route with a variable', | ||
45 | array('/foo/{bar}'), | ||
46 | '/foo', '#^/foo/(?P<bar>[^/]++)$#s', array('bar'), array( | ||
47 | array('variable', '/', '[^/]++', 'bar'), | ||
48 | array('text', '/foo'), | ||
49 | )), | ||
50 | |||
51 | array( | ||
52 | 'Route with a variable that has a default value', | ||
53 | array('/foo/{bar}', array('bar' => 'bar')), | ||
54 | '/foo', '#^/foo(?:/(?P<bar>[^/]++))?$#s', array('bar'), array( | ||
55 | array('variable', '/', '[^/]++', 'bar'), | ||
56 | array('text', '/foo'), | ||
57 | )), | ||
58 | |||
59 | array( | ||
60 | 'Route with several variables', | ||
61 | array('/foo/{bar}/{foobar}'), | ||
62 | '/foo', '#^/foo/(?P<bar>[^/]++)/(?P<foobar>[^/]++)$#s', array('bar', 'foobar'), array( | ||
63 | array('variable', '/', '[^/]++', 'foobar'), | ||
64 | array('variable', '/', '[^/]++', 'bar'), | ||
65 | array('text', '/foo'), | ||
66 | )), | ||
67 | |||
68 | array( | ||
69 | 'Route with several variables that have default values', | ||
70 | array('/foo/{bar}/{foobar}', array('bar' => 'bar', 'foobar' => '')), | ||
71 | '/foo', '#^/foo(?:/(?P<bar>[^/]++)(?:/(?P<foobar>[^/]++))?)?$#s', array('bar', 'foobar'), array( | ||
72 | array('variable', '/', '[^/]++', 'foobar'), | ||
73 | array('variable', '/', '[^/]++', 'bar'), | ||
74 | array('text', '/foo'), | ||
75 | )), | ||
76 | |||
77 | array( | ||
78 | 'Route with several variables but some of them have no default values', | ||
79 | array('/foo/{bar}/{foobar}', array('bar' => 'bar')), | ||
80 | '/foo', '#^/foo/(?P<bar>[^/]++)/(?P<foobar>[^/]++)$#s', array('bar', 'foobar'), array( | ||
81 | array('variable', '/', '[^/]++', 'foobar'), | ||
82 | array('variable', '/', '[^/]++', 'bar'), | ||
83 | array('text', '/foo'), | ||
84 | )), | ||
85 | |||
86 | array( | ||
87 | 'Route with an optional variable as the first segment', | ||
88 | array('/{bar}', array('bar' => 'bar')), | ||
89 | '', '#^/(?P<bar>[^/]++)?$#s', array('bar'), array( | ||
90 | array('variable', '/', '[^/]++', 'bar'), | ||
91 | )), | ||
92 | |||
93 | array( | ||
94 | 'Route with a requirement of 0', | ||
95 | array('/{bar}', array('bar' => null), array('bar' => '0')), | ||
96 | '', '#^/(?P<bar>0)?$#s', array('bar'), array( | ||
97 | array('variable', '/', '0', 'bar'), | ||
98 | )), | ||
99 | |||
100 | array( | ||
101 | 'Route with an optional variable as the first segment with requirements', | ||
102 | array('/{bar}', array('bar' => 'bar'), array('bar' => '(foo|bar)')), | ||
103 | '', '#^/(?P<bar>(foo|bar))?$#s', array('bar'), array( | ||
104 | array('variable', '/', '(foo|bar)', 'bar'), | ||
105 | )), | ||
106 | |||
107 | array( | ||
108 | 'Route with only optional variables', | ||
109 | array('/{foo}/{bar}', array('foo' => 'foo', 'bar' => 'bar')), | ||
110 | '', '#^/(?P<foo>[^/]++)?(?:/(?P<bar>[^/]++))?$#s', array('foo', 'bar'), array( | ||
111 | array('variable', '/', '[^/]++', 'bar'), | ||
112 | array('variable', '/', '[^/]++', 'foo'), | ||
113 | )), | ||
114 | |||
115 | array( | ||
116 | 'Route with a variable in last position', | ||
117 | array('/foo-{bar}'), | ||
118 | '/foo', '#^/foo\-(?P<bar>[^/]++)$#s', array('bar'), array( | ||
119 | array('variable', '-', '[^/]++', 'bar'), | ||
120 | array('text', '/foo'), | ||
121 | )), | ||
122 | |||
123 | array( | ||
124 | 'Route with nested placeholders', | ||
125 | array('/{static{var}static}'), | ||
126 | '/{static', '#^/\{static(?P<var>[^/]+)static\}$#s', array('var'), array( | ||
127 | array('text', 'static}'), | ||
128 | array('variable', '', '[^/]+', 'var'), | ||
129 | array('text', '/{static'), | ||
130 | )), | ||
131 | |||
132 | array( | ||
133 | 'Route without separator between variables', | ||
134 | array('/{w}{x}{y}{z}.{_format}', array('z' => 'default-z', '_format' => 'html'), array('y' => '(y|Y)')), | ||
135 | '', '#^/(?P<w>[^/\.]+)(?P<x>[^/\.]+)(?P<y>(y|Y))(?:(?P<z>[^/\.]++)(?:\.(?P<_format>[^/]++))?)?$#s', array('w', 'x', 'y', 'z', '_format'), array( | ||
136 | array('variable', '.', '[^/]++', '_format'), | ||
137 | array('variable', '', '[^/\.]++', 'z'), | ||
138 | array('variable', '', '(y|Y)', 'y'), | ||
139 | array('variable', '', '[^/\.]+', 'x'), | ||
140 | array('variable', '/', '[^/\.]+', 'w'), | ||
141 | )), | ||
142 | |||
143 | array( | ||
144 | 'Route with a format', | ||
145 | array('/foo/{bar}.{_format}'), | ||
146 | '/foo', '#^/foo/(?P<bar>[^/\.]++)\.(?P<_format>[^/]++)$#s', array('bar', '_format'), array( | ||
147 | array('variable', '.', '[^/]++', '_format'), | ||
148 | array('variable', '/', '[^/\.]++', 'bar'), | ||
149 | array('text', '/foo'), | ||
150 | )), | ||
151 | ); | ||
152 | } | ||
153 | |||
154 | /** | ||
155 | * @expectedException \LogicException | ||
156 | */ | ||
157 | public function testRouteWithSameVariableTwice() | ||
158 | { | ||
159 | $route = new Route('/{name}/{name}'); | ||
160 | |||
161 | $compiled = $route->compile(); | ||
162 | } | ||
163 | |||
164 | /** | ||
165 | * @dataProvider getNumericVariableNames | ||
166 | * @expectedException \DomainException | ||
167 | */ | ||
168 | public function testRouteWithNumericVariableName($name) | ||
169 | { | ||
170 | $route = new Route('/{'. $name.'}'); | ||
171 | $route->compile(); | ||
172 | } | ||
173 | |||
174 | public function getNumericVariableNames() | ||
175 | { | ||
176 | return array( | ||
177 | array('09'), | ||
178 | array('123'), | ||
179 | array('1e2') | ||
180 | ); | ||
181 | } | ||
182 | |||
183 | /** | ||
184 | * @dataProvider provideCompileWithHostData | ||
185 | */ | ||
186 | public function testCompileWithHost($name, $arguments, $prefix, $regex, $variables, $pathVariables, $tokens, $hostRegex, $hostVariables, $hostTokens) | ||
187 | { | ||
188 | $r = new \ReflectionClass('Symfony\\Component\\Routing\\Route'); | ||
189 | $route = $r->newInstanceArgs($arguments); | ||
190 | |||
191 | $compiled = $route->compile(); | ||
192 | $this->assertEquals($prefix, $compiled->getStaticPrefix(), $name.' (static prefix)'); | ||
193 | $this->assertEquals($regex, str_replace(array("\n", ' '), '', $compiled->getRegex()), $name.' (regex)'); | ||
194 | $this->assertEquals($variables, $compiled->getVariables(), $name.' (variables)'); | ||
195 | $this->assertEquals($pathVariables, $compiled->getPathVariables(), $name.' (path variables)'); | ||
196 | $this->assertEquals($tokens, $compiled->getTokens(), $name.' (tokens)'); | ||
197 | $this->assertEquals($hostRegex, str_replace(array("\n", ' '), '', $compiled->getHostRegex()), $name.' (host regex)'); | ||
198 | $this->assertEquals($hostVariables, $compiled->getHostVariables(), $name.' (host variables)'); | ||
199 | $this->assertEquals($hostTokens, $compiled->getHostTokens(), $name.' (host tokens)'); | ||
200 | } | ||
201 | |||
202 | public function provideCompileWithHostData() | ||
203 | { | ||
204 | return array( | ||
205 | array( | ||
206 | 'Route with host pattern', | ||
207 | array('/hello', array(), array(), array(), 'www.example.com'), | ||
208 | '/hello', '#^/hello$#s', array(), array(), array( | ||
209 | array('text', '/hello'), | ||
210 | ), | ||
211 | '#^www\.example\.com$#s', array(), array( | ||
212 | array('text', 'www.example.com'), | ||
213 | ), | ||
214 | ), | ||
215 | array( | ||
216 | 'Route with host pattern and some variables', | ||
217 | array('/hello/{name}', array(), array(), array(), 'www.example.{tld}'), | ||
218 | '/hello', '#^/hello/(?P<name>[^/]++)$#s', array('tld', 'name'), array('name'), array( | ||
219 | array('variable', '/', '[^/]++', 'name'), | ||
220 | array('text', '/hello'), | ||
221 | ), | ||
222 | '#^www\.example\.(?P<tld>[^\.]++)$#s', array('tld'), array( | ||
223 | array('variable', '.', '[^\.]++', 'tld'), | ||
224 | array('text', 'www.example'), | ||
225 | ), | ||
226 | ), | ||
227 | array( | ||
228 | 'Route with variable at beginning of host', | ||
229 | array('/hello', array(), array(), array(), '{locale}.example.{tld}'), | ||
230 | '/hello', '#^/hello$#s', array('locale', 'tld'), array(), array( | ||
231 | array('text', '/hello'), | ||
232 | ), | ||
233 | '#^(?P<locale>[^\.]++)\.example\.(?P<tld>[^\.]++)$#s', array('locale', 'tld'), array( | ||
234 | array('variable', '.', '[^\.]++', 'tld'), | ||
235 | array('text', '.example'), | ||
236 | array('variable', '', '[^\.]++', 'locale'), | ||
237 | ), | ||
238 | ), | ||
239 | array( | ||
240 | 'Route with host variables that has a default value', | ||
241 | array('/hello', array('locale' => 'a', 'tld' => 'b'), array(), array(), '{locale}.example.{tld}'), | ||
242 | '/hello', '#^/hello$#s', array('locale', 'tld'), array(), array( | ||
243 | array('text', '/hello'), | ||
244 | ), | ||
245 | '#^(?P<locale>[^\.]++)\.example\.(?P<tld>[^\.]++)$#s', array('locale', 'tld'), array( | ||
246 | array('variable', '.', '[^\.]++', 'tld'), | ||
247 | array('text', '.example'), | ||
248 | array('variable', '', '[^\.]++', 'locale'), | ||
249 | ), | ||
250 | ), | ||
251 | ); | ||
252 | } | ||
253 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/RouteTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/RouteTest.php new file mode 100644 index 00000000..31f1066f --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/RouteTest.php | |||
@@ -0,0 +1,192 @@ | |||
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; | ||
13 | |||
14 | use Symfony\Component\Routing\Route; | ||
15 | |||
16 | class RouteTest extends \PHPUnit_Framework_TestCase | ||
17 | { | ||
18 | public function testConstructor() | ||
19 | { | ||
20 | $route = new Route('/{foo}', array('foo' => 'bar'), array('foo' => '\d+'), array('foo' => 'bar'), '{locale}.example.com'); | ||
21 | $this->assertEquals('/{foo}', $route->getPath(), '__construct() takes a path as its first argument'); | ||
22 | $this->assertEquals(array('foo' => 'bar'), $route->getDefaults(), '__construct() takes defaults as its second argument'); | ||
23 | $this->assertEquals(array('foo' => '\d+'), $route->getRequirements(), '__construct() takes requirements as its third argument'); | ||
24 | $this->assertEquals('bar', $route->getOption('foo'), '__construct() takes options as its fourth argument'); | ||
25 | $this->assertEquals('{locale}.example.com', $route->getHost(), '__construct() takes a host pattern as its fifth argument'); | ||
26 | |||
27 | $route = new Route('/', array(), array(), array(), '', array('Https'), array('POST', 'put')); | ||
28 | $this->assertEquals(array('https'), $route->getSchemes(), '__construct() takes schemes as its sixth argument and lowercases it'); | ||
29 | $this->assertEquals(array('POST', 'PUT'), $route->getMethods(), '__construct() takes methods as its seventh argument and uppercases it'); | ||
30 | |||
31 | $route = new Route('/', array(), array(), array(), '', 'Https', 'Post'); | ||
32 | $this->assertEquals(array('https'), $route->getSchemes(), '__construct() takes a single scheme as its sixth argument'); | ||
33 | $this->assertEquals(array('POST'), $route->getMethods(), '__construct() takes a single method as its seventh argument'); | ||
34 | } | ||
35 | |||
36 | public function testPath() | ||
37 | { | ||
38 | $route = new Route('/{foo}'); | ||
39 | $route->setPath('/{bar}'); | ||
40 | $this->assertEquals('/{bar}', $route->getPath(), '->setPath() sets the path'); | ||
41 | $route->setPath(''); | ||
42 | $this->assertEquals('/', $route->getPath(), '->setPath() adds a / at the beginning of the path if needed'); | ||
43 | $route->setPath('bar'); | ||
44 | $this->assertEquals('/bar', $route->getPath(), '->setPath() adds a / at the beginning of the path if needed'); | ||
45 | $this->assertEquals($route, $route->setPath(''), '->setPath() implements a fluent interface'); | ||
46 | $route->setPath('//path'); | ||
47 | $this->assertEquals('/path', $route->getPath(), '->setPath() does not allow two slahes "//" at the beginning of the path as it would be confused with a network path when generating the path from the route'); | ||
48 | } | ||
49 | |||
50 | public function testOptions() | ||
51 | { | ||
52 | $route = new Route('/{foo}'); | ||
53 | $route->setOptions(array('foo' => 'bar')); | ||
54 | $this->assertEquals(array_merge(array( | ||
55 | 'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler', | ||
56 | ), array('foo' => 'bar')), $route->getOptions(), '->setOptions() sets the options'); | ||
57 | $this->assertEquals($route, $route->setOptions(array()), '->setOptions() implements a fluent interface'); | ||
58 | |||
59 | $route->setOptions(array('foo' => 'foo')); | ||
60 | $route->addOptions(array('bar' => 'bar')); | ||
61 | $this->assertEquals($route, $route->addOptions(array()), '->addOptions() implements a fluent interface'); | ||
62 | $this->assertEquals(array('foo' => 'foo', 'bar' => 'bar', 'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler'), $route->getOptions(), '->addDefaults() keep previous defaults'); | ||
63 | } | ||
64 | |||
65 | public function testDefaults() | ||
66 | { | ||
67 | $route = new Route('/{foo}'); | ||
68 | $route->setDefaults(array('foo' => 'bar')); | ||
69 | $this->assertEquals(array('foo' => 'bar'), $route->getDefaults(), '->setDefaults() sets the defaults'); | ||
70 | $this->assertEquals($route, $route->setDefaults(array()), '->setDefaults() implements a fluent interface'); | ||
71 | |||
72 | $route->setDefault('foo', 'bar'); | ||
73 | $this->assertEquals('bar', $route->getDefault('foo'), '->setDefault() sets a default value'); | ||
74 | |||
75 | $route->setDefault('foo2', 'bar2'); | ||
76 | $this->assertEquals('bar2', $route->getDefault('foo2'), '->getDefault() return the default value'); | ||
77 | $this->assertNull($route->getDefault('not_defined'), '->getDefault() return null if default value is not setted'); | ||
78 | |||
79 | $route->setDefault('_controller', $closure = function () { return 'Hello'; }); | ||
80 | $this->assertEquals($closure, $route->getDefault('_controller'), '->setDefault() sets a default value'); | ||
81 | |||
82 | $route->setDefaults(array('foo' => 'foo')); | ||
83 | $route->addDefaults(array('bar' => 'bar')); | ||
84 | $this->assertEquals($route, $route->addDefaults(array()), '->addDefaults() implements a fluent interface'); | ||
85 | $this->assertEquals(array('foo' => 'foo', 'bar' => 'bar'), $route->getDefaults(), '->addDefaults() keep previous defaults'); | ||
86 | } | ||
87 | |||
88 | public function testRequirements() | ||
89 | { | ||
90 | $route = new Route('/{foo}'); | ||
91 | $route->setRequirements(array('foo' => '\d+')); | ||
92 | $this->assertEquals(array('foo' => '\d+'), $route->getRequirements(), '->setRequirements() sets the requirements'); | ||
93 | $this->assertEquals('\d+', $route->getRequirement('foo'), '->getRequirement() returns a requirement'); | ||
94 | $this->assertNull($route->getRequirement('bar'), '->getRequirement() returns null if a requirement is not defined'); | ||
95 | $route->setRequirements(array('foo' => '^\d+$')); | ||
96 | $this->assertEquals('\d+', $route->getRequirement('foo'), '->getRequirement() removes ^ and $ from the path'); | ||
97 | $this->assertEquals($route, $route->setRequirements(array()), '->setRequirements() implements a fluent interface'); | ||
98 | |||
99 | $route->setRequirements(array('foo' => '\d+')); | ||
100 | $route->addRequirements(array('bar' => '\d+')); | ||
101 | $this->assertEquals($route, $route->addRequirements(array()), '->addRequirements() implements a fluent interface'); | ||
102 | $this->assertEquals(array('foo' => '\d+', 'bar' => '\d+'), $route->getRequirements(), '->addRequirement() keep previous requirements'); | ||
103 | } | ||
104 | |||
105 | public function testRequirement() | ||
106 | { | ||
107 | $route = new Route('/{foo}'); | ||
108 | $route->setRequirement('foo', '^\d+$'); | ||
109 | $this->assertEquals('\d+', $route->getRequirement('foo'), '->setRequirement() removes ^ and $ from the path'); | ||
110 | } | ||
111 | |||
112 | /** | ||
113 | * @dataProvider getInvalidRequirements | ||
114 | * @expectedException \InvalidArgumentException | ||
115 | */ | ||
116 | public function testSetInvalidRequirement($req) | ||
117 | { | ||
118 | $route = new Route('/{foo}'); | ||
119 | $route->setRequirement('foo', $req); | ||
120 | } | ||
121 | |||
122 | public function getInvalidRequirements() | ||
123 | { | ||
124 | return array( | ||
125 | array(''), | ||
126 | array(array()), | ||
127 | array('^$'), | ||
128 | array('^'), | ||
129 | array('$') | ||
130 | ); | ||
131 | } | ||
132 | |||
133 | public function testHost() | ||
134 | { | ||
135 | $route = new Route('/'); | ||
136 | $route->setHost('{locale}.example.net'); | ||
137 | $this->assertEquals('{locale}.example.net', $route->getHost(), '->setHost() sets the host pattern'); | ||
138 | } | ||
139 | |||
140 | public function testScheme() | ||
141 | { | ||
142 | $route = new Route('/'); | ||
143 | $this->assertEquals(array(), $route->getSchemes(), 'schemes is initialized with array()'); | ||
144 | $route->setSchemes('hTTp'); | ||
145 | $this->assertEquals(array('http'), $route->getSchemes(), '->setSchemes() accepts a single scheme string and lowercases it'); | ||
146 | $route->setSchemes(array('HttpS', 'hTTp')); | ||
147 | $this->assertEquals(array('https', 'http'), $route->getSchemes(), '->setSchemes() accepts an array of schemes and lowercases them'); | ||
148 | } | ||
149 | |||
150 | public function testSchemeIsBC() | ||
151 | { | ||
152 | $route = new Route('/'); | ||
153 | $route->setRequirement('_scheme', 'http|https'); | ||
154 | $this->assertEquals('http|https', $route->getRequirement('_scheme')); | ||
155 | $this->assertEquals(array('http', 'https'), $route->getSchemes()); | ||
156 | $route->setSchemes(array('hTTp')); | ||
157 | $this->assertEquals('http', $route->getRequirement('_scheme')); | ||
158 | $route->setSchemes(array()); | ||
159 | $this->assertNull($route->getRequirement('_scheme')); | ||
160 | } | ||
161 | |||
162 | public function testMethod() | ||
163 | { | ||
164 | $route = new Route('/'); | ||
165 | $this->assertEquals(array(), $route->getMethods(), 'methods is initialized with array()'); | ||
166 | $route->setMethods('gEt'); | ||
167 | $this->assertEquals(array('GET'), $route->getMethods(), '->setMethods() accepts a single method string and uppercases it'); | ||
168 | $route->setMethods(array('gEt', 'PosT')); | ||
169 | $this->assertEquals(array('GET', 'POST'), $route->getMethods(), '->setMethods() accepts an array of methods and uppercases them'); | ||
170 | } | ||
171 | |||
172 | public function testMethodIsBC() | ||
173 | { | ||
174 | $route = new Route('/'); | ||
175 | $route->setRequirement('_method', 'GET|POST'); | ||
176 | $this->assertEquals('GET|POST', $route->getRequirement('_method')); | ||
177 | $this->assertEquals(array('GET', 'POST'), $route->getMethods()); | ||
178 | $route->setMethods(array('gEt')); | ||
179 | $this->assertEquals('GET', $route->getRequirement('_method')); | ||
180 | $route->setMethods(array()); | ||
181 | $this->assertNull($route->getRequirement('_method')); | ||
182 | } | ||
183 | |||
184 | public function testCompile() | ||
185 | { | ||
186 | $route = new Route('/{foo}'); | ||
187 | $this->assertInstanceOf('Symfony\Component\Routing\CompiledRoute', $compiled = $route->compile(), '->compile() returns a compiled route'); | ||
188 | $this->assertSame($compiled, $route->compile(), '->compile() only compiled the route once if unchanged'); | ||
189 | $route->setRequirement('foo', '.*'); | ||
190 | $this->assertNotSame($compiled, $route->compile(), '->compile() recompiles if the route was modified'); | ||
191 | } | ||
192 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/RouterTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/RouterTest.php new file mode 100644 index 00000000..a3c336e5 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/RouterTest.php | |||
@@ -0,0 +1,138 @@ | |||
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; | ||
13 | |||
14 | use Symfony\Component\Routing\Router; | ||
15 | |||
16 | class RouterTest extends \PHPUnit_Framework_TestCase | ||
17 | { | ||
18 | private $router = null; | ||
19 | |||
20 | private $loader = null; | ||
21 | |||
22 | protected function setUp() | ||
23 | { | ||
24 | $this->loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'); | ||
25 | $this->router = new Router($this->loader, 'routing.yml'); | ||
26 | } | ||
27 | |||
28 | public function testSetOptionsWithSupportedOptions() | ||
29 | { | ||
30 | $this->router->setOptions(array( | ||
31 | 'cache_dir' => './cache', | ||
32 | 'debug' => true, | ||
33 | 'resource_type' => 'ResourceType' | ||
34 | )); | ||
35 | |||
36 | $this->assertSame('./cache', $this->router->getOption('cache_dir')); | ||
37 | $this->assertTrue($this->router->getOption('debug')); | ||
38 | $this->assertSame('ResourceType', $this->router->getOption('resource_type')); | ||
39 | } | ||
40 | |||
41 | /** | ||
42 | * @expectedException \InvalidArgumentException | ||
43 | * @expectedExceptionMessage The Router does not support the following options: "option_foo", "option_bar" | ||
44 | */ | ||
45 | public function testSetOptionsWithUnsupportedOptions() | ||
46 | { | ||
47 | $this->router->setOptions(array( | ||
48 | 'cache_dir' => './cache', | ||
49 | 'option_foo' => true, | ||
50 | 'option_bar' => 'baz', | ||
51 | 'resource_type' => 'ResourceType' | ||
52 | )); | ||
53 | } | ||
54 | |||
55 | public function testSetOptionWithSupportedOption() | ||
56 | { | ||
57 | $this->router->setOption('cache_dir', './cache'); | ||
58 | |||
59 | $this->assertSame('./cache', $this->router->getOption('cache_dir')); | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * @expectedException \InvalidArgumentException | ||
64 | * @expectedExceptionMessage The Router does not support the "option_foo" option | ||
65 | */ | ||
66 | public function testSetOptionWithUnsupportedOption() | ||
67 | { | ||
68 | $this->router->setOption('option_foo', true); | ||
69 | } | ||
70 | |||
71 | /** | ||
72 | * @expectedException \InvalidArgumentException | ||
73 | * @expectedExceptionMessage The Router does not support the "option_foo" option | ||
74 | */ | ||
75 | public function testGetOptionWithUnsupportedOption() | ||
76 | { | ||
77 | $this->router->getOption('option_foo', true); | ||
78 | } | ||
79 | |||
80 | public function testThatRouteCollectionIsLoaded() | ||
81 | { | ||
82 | $this->router->setOption('resource_type', 'ResourceType'); | ||
83 | |||
84 | $routeCollection = $this->getMock('Symfony\Component\Routing\RouteCollection'); | ||
85 | |||
86 | $this->loader->expects($this->once()) | ||
87 | ->method('load')->with('routing.yml', 'ResourceType') | ||
88 | ->will($this->returnValue($routeCollection)); | ||
89 | |||
90 | $this->assertSame($routeCollection, $this->router->getRouteCollection()); | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * @dataProvider provideMatcherOptionsPreventingCaching | ||
95 | */ | ||
96 | public function testMatcherIsCreatedIfCacheIsNotConfigured($option) | ||
97 | { | ||
98 | $this->router->setOption($option, null); | ||
99 | |||
100 | $this->loader->expects($this->once()) | ||
101 | ->method('load')->with('routing.yml', null) | ||
102 | ->will($this->returnValue($this->getMock('Symfony\Component\Routing\RouteCollection'))); | ||
103 | |||
104 | $this->assertInstanceOf('Symfony\\Component\\Routing\\Matcher\\UrlMatcher', $this->router->getMatcher()); | ||
105 | |||
106 | } | ||
107 | |||
108 | public function provideMatcherOptionsPreventingCaching() | ||
109 | { | ||
110 | return array( | ||
111 | array('cache_dir'), | ||
112 | array('matcher_cache_class') | ||
113 | ); | ||
114 | } | ||
115 | |||
116 | /** | ||
117 | * @dataProvider provideGeneratorOptionsPreventingCaching | ||
118 | */ | ||
119 | public function testGeneratorIsCreatedIfCacheIsNotConfigured($option) | ||
120 | { | ||
121 | $this->router->setOption($option, null); | ||
122 | |||
123 | $this->loader->expects($this->once()) | ||
124 | ->method('load')->with('routing.yml', null) | ||
125 | ->will($this->returnValue($this->getMock('Symfony\Component\Routing\RouteCollection'))); | ||
126 | |||
127 | $this->assertInstanceOf('Symfony\\Component\\Routing\\Generator\\UrlGenerator', $this->router->getGenerator()); | ||
128 | |||
129 | } | ||
130 | |||
131 | public function provideGeneratorOptionsPreventingCaching() | ||
132 | { | ||
133 | return array( | ||
134 | array('cache_dir'), | ||
135 | array('generator_cache_class') | ||
136 | ); | ||
137 | } | ||
138 | } | ||