0c5f73f3eacc8e206fc454ac1590537d662fb06a
[yaffs-website] / vendor / symfony / routing / Tests / Matcher / LegacyApacheUrlMatcherTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Routing\Tests\Matcher;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Routing\RouteCollection;
16 use Symfony\Component\Routing\RequestContext;
17 use Symfony\Component\Routing\Matcher\ApacheUrlMatcher;
18
19 /**
20  * @group legacy
21  */
22 class LegacyApacheUrlMatcherTest extends TestCase
23 {
24     protected $server;
25
26     protected function setUp()
27     {
28         $this->server = $_SERVER;
29     }
30
31     protected function tearDown()
32     {
33         $_SERVER = $this->server;
34     }
35
36     /**
37      * @dataProvider getMatchData
38      */
39     public function testMatch($name, $pathinfo, $server, $expect)
40     {
41         $collection = new RouteCollection();
42         $context = new RequestContext();
43         $matcher = new ApacheUrlMatcher($collection, $context);
44
45         $_SERVER = $server;
46
47         $result = $matcher->match($pathinfo);
48         $this->assertSame(var_export($expect, true), var_export($result, true));
49     }
50
51     public function getMatchData()
52     {
53         return array(
54             array(
55                 'Simple route',
56                 '/hello/world',
57                 array(
58                     '_ROUTING_route' => 'hello',
59                     '_ROUTING_param__controller' => 'AcmeBundle:Default:index',
60                     '_ROUTING_param_name' => 'world',
61                 ),
62                 array(
63                     '_controller' => 'AcmeBundle:Default:index',
64                     'name' => 'world',
65                     '_route' => 'hello',
66                 ),
67             ),
68             array(
69                 'Route with params and defaults',
70                 '/hello/hugo',
71                 array(
72                     '_ROUTING_route' => 'hello',
73                     '_ROUTING_param__controller' => 'AcmeBundle:Default:index',
74                     '_ROUTING_param_name' => 'hugo',
75                     '_ROUTING_default_name' => 'world',
76                 ),
77                 array(
78                     'name' => 'hugo',
79                     '_controller' => 'AcmeBundle:Default:index',
80                     '_route' => 'hello',
81                 ),
82             ),
83             array(
84                 'Route with defaults only',
85                 '/hello',
86                 array(
87                     '_ROUTING_route' => 'hello',
88                     '_ROUTING_param__controller' => 'AcmeBundle:Default:index',
89                     '_ROUTING_default_name' => 'world',
90                 ),
91                 array(
92                     'name' => 'world',
93                     '_controller' => 'AcmeBundle:Default:index',
94                     '_route' => 'hello',
95                 ),
96             ),
97             array(
98                 'Redirect with many ignored attributes',
99                 '/legacy/{cat1}/{cat2}/{id}.html',
100                 array(
101                     '_ROUTING_route' => 'product_view',
102                     '_ROUTING_param__controller' => 'FrameworkBundle:Redirect:redirect',
103                     '_ROUTING_default_ignoreAttributes[0]' => 'attr_a',
104                     '_ROUTING_default_ignoreAttributes[1]' => 'attr_b',
105                 ),
106                 array(
107                     'ignoreAttributes' => array('attr_a', 'attr_b'),
108                     '_controller' => 'FrameworkBundle:Redirect:redirect',
109                     '_route' => 'product_view',
110                 ),
111             ),
112             array(
113                 'REDIRECT_ envs',
114                 '/hello/world',
115                 array(
116                     'REDIRECT__ROUTING_route' => 'hello',
117                     'REDIRECT__ROUTING_param__controller' => 'AcmeBundle:Default:index',
118                     'REDIRECT__ROUTING_param_name' => 'world',
119                 ),
120                 array(
121                     '_controller' => 'AcmeBundle:Default:index',
122                     'name' => 'world',
123                     '_route' => 'hello',
124                 ),
125             ),
126             array(
127                 'REDIRECT_REDIRECT_ envs',
128                 '/hello/world',
129                 array(
130                     'REDIRECT_REDIRECT__ROUTING_route' => 'hello',
131                     'REDIRECT_REDIRECT__ROUTING_param__controller' => 'AcmeBundle:Default:index',
132                     'REDIRECT_REDIRECT__ROUTING_param_name' => 'world',
133                 ),
134                 array(
135                     '_controller' => 'AcmeBundle:Default:index',
136                     'name' => 'world',
137                     '_route' => 'hello',
138                 ),
139             ),
140             array(
141                 'REDIRECT_REDIRECT_ envs',
142                 '/hello/world',
143                 array(
144                     'REDIRECT_REDIRECT__ROUTING_route' => 'hello',
145                     'REDIRECT_REDIRECT__ROUTING_param__controller' => 'AcmeBundle:Default:index',
146                     'REDIRECT_REDIRECT__ROUTING_param_name' => 'world',
147                 ),
148                 array(
149                     '_controller' => 'AcmeBundle:Default:index',
150                     'name' => 'world',
151                     '_route' => 'hello',
152                 ),
153             ),
154         );
155     }
156 }