/
RouteCompilerTest.php
96 lines (83 loc) · 3.81 KB
/
RouteCompilerTest.php
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
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Tests\Components\Routing;
use Symfony\Components\Routing\Route;
require __DIR__.'/RouteCompiler.php';
class RouteCompilerTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider provideCompileData
*/
public function testCompile($name, $arguments, $prefix, $regex, $variables, $tokens)
{
$r = new \ReflectionClass('Symfony\\Components\\Routing\\Route');
$route = $r->newInstanceArgs($arguments);
$compiled = $route->compile();
$this->assertEquals($prefix, $compiled->getStaticPrefix(), $name.' (static prefix)');
$this->assertEquals($regex, $compiled->getRegex(), $name.' (regex)');
$this->assertEquals($variables, $compiled->getVariables(), $name.' (variables)');
$this->assertEquals($tokens, $compiled->getTokens(), $name.' (tokens)');
}
public function provideCompileData()
{
return array(
array(
'Static route',
array('/foo'),
'/foo', '#^/foo$#x', array(), array(
array('text', '/', 'foo', null),
)),
array(
'Route with a variable',
array('/foo/:bar'),
'/foo', '#^/foo/(?P<bar>[^/\.]+?)$#x', array('bar' => ':bar'), array(
array('variable', '/', ':bar', 'bar'),
array('text', '/', 'foo', null),
)),
array(
'Route with a variable that has a default value',
array('/foo/:bar', array('bar' => 'bar')),
'/foo', '#^/foo(?:/(?P<bar>[^/\.]+?))?$#x', array('bar' => ':bar'), array(
array('variable', '/', ':bar', 'bar'),
array('text', '/', 'foo', null),
)),
array(
'Route with several variables',
array('/foo/:bar/:foobar'),
'/foo', '#^/foo/(?P<bar>[^/\.]+?)/(?P<foobar>[^/\.]+?)$#x', array('bar' => ':bar', 'foobar' => ':foobar'), array(
array('variable', '/', ':foobar', 'foobar'),
array('variable', '/', ':bar', 'bar'),
array('text', '/', 'foo', null),
)),
array(
'Route with several variables that have default values',
array('/foo/:bar/:foobar', array('bar' => 'bar', 'foobar' => 'foobar')),
'/foo', '#^/foo(?:/(?P<bar>[^/\.]+?) (?:/(?P<foobar>[^/\.]+?) )?)?$#x', array('bar' => ':bar', 'foobar' => ':foobar'), array(
array('variable', '/', ':foobar', 'foobar'),
array('variable', '/', ':bar', 'bar'),
array('text', '/', 'foo', null),
)),
array(
'Route with several variables but some of them have no default values',
array('/foo/:bar/:foobar', array('bar' => 'bar')),
'/foo', '#^/foo/(?P<bar>[^/\.]+?)/(?P<foobar>[^/\.]+?)$#x', array('bar' => ':bar', 'foobar' => ':foobar'), array(
array('variable', '/', ':foobar', 'foobar'),
array('variable', '/', ':bar', 'bar'),
array('text', '/', 'foo', null),
)),
array(
'Route with a custom token',
array('/=foo', array(), array(), array('compiler_class' => 'Symfony\\Tests\\Components\\Routing\\RouteCompiler')),
'', '#^/foo/(?P<foo>[^/\.]+?)$#x', array('foo' => '=foo'), array(
array('label', '/', '=foo', 'foo'),
)),
);
}
}