aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/ApacheUrlMatcherTest.php
blob: 6550911eb7b24ff3d39aa125ea8ae2e70bc6faa5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Routing\Tests\Matcher;

use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Matcher\ApacheUrlMatcher;

class ApacheUrlMatcherTest extends \PHPUnit_Framework_TestCase
{
    protected $server;

    protected function setUp()
    {
        $this->server = $_SERVER;
    }

    protected function tearDown()
    {
        $_SERVER = $this->server;
    }

    /**
     * @dataProvider getMatchData
     */
    public function testMatch($name, $pathinfo, $server, $expect)
    {
        $collection = new RouteCollection();
        $context = new RequestContext();
        $matcher = new ApacheUrlMatcher($collection, $context);

        $_SERVER = $server;

        $result = $matcher->match($pathinfo, $server);
        $this->assertSame(var_export($expect, true), var_export($result, true));
    }

    public function getMatchData()
    {
        return array(
            array(
                'Simple route',
                '/hello/world',
                array(
                    '_ROUTING_route' => 'hello',
                    '_ROUTING_param__controller' => 'AcmeBundle:Default:index',
                    '_ROUTING_param_name' => 'world',
                ),
                array(
                    '_controller' => 'AcmeBundle:Default:index',
                    'name' => 'world',
                    '_route' => 'hello',
                ),
            ),
            array(
                'Route with params and defaults',
                '/hello/hugo',
                array(
                    '_ROUTING_route' => 'hello',
                    '_ROUTING_param__controller' => 'AcmeBundle:Default:index',
                    '_ROUTING_param_name' => 'hugo',
                    '_ROUTING_default_name' => 'world',
                ),
                array(
                    'name' => 'hugo',
                    '_controller' => 'AcmeBundle:Default:index',
                    '_route' => 'hello',
                ),
            ),
            array(
                'Route with defaults only',
                '/hello',
                array(
                    '_ROUTING_route' => 'hello',
                    '_ROUTING_param__controller' => 'AcmeBundle:Default:index',
                    '_ROUTING_default_name' => 'world',
                ),
                array(
                    'name' => 'world',
                    '_controller' => 'AcmeBundle:Default:index',
                    '_route' => 'hello',
                ),
            ),
            array(
                'REDIRECT_ envs',
                '/hello/world',
                array(
                    'REDIRECT__ROUTING_route' => 'hello',
                    'REDIRECT__ROUTING_param__controller' => 'AcmeBundle:Default:index',
                    'REDIRECT__ROUTING_param_name' => 'world',
                ),
                array(
                    '_controller' => 'AcmeBundle:Default:index',
                    'name' => 'world',
                    '_route' => 'hello',
                ),
            ),
            array(
                'REDIRECT_REDIRECT_ envs',
                '/hello/world',
                array(
                    'REDIRECT_REDIRECT__ROUTING_route' => 'hello',
                    'REDIRECT_REDIRECT__ROUTING_param__controller' => 'AcmeBundle:Default:index',
                    'REDIRECT_REDIRECT__ROUTING_param_name' => 'world',
                ),
                array(
                    '_controller' => 'AcmeBundle:Default:index',
                    'name' => 'world',
                    '_route' => 'hello',
                ),
            ),
            array(
                'REDIRECT_REDIRECT_ envs',
                '/hello/world',
                array(
                    'REDIRECT_REDIRECT__ROUTING_route' => 'hello',
                    'REDIRECT_REDIRECT__ROUTING_param__controller' => 'AcmeBundle:Default:index',
                    'REDIRECT_REDIRECT__ROUTING_param_name' => 'world',
                ),
                array(
                    '_controller' => 'AcmeBundle:Default:index',
                    'name' => 'world',
                    '_route' => 'hello',
                ),
            ),
        );
    }
}