2010-06-24 07:46:50 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-06-24 07:46:50 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
namespace Symfony\Tests\Component\Routing;
|
2010-06-24 07:46:50 +01:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Routing\Route;
|
2010-06-24 07:46:50 +01:00
|
|
|
|
|
|
|
require __DIR__.'/RouteCompiler.php';
|
|
|
|
|
|
|
|
class RouteCompilerTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider provideCompileData
|
|
|
|
*/
|
|
|
|
public function testCompile($name, $arguments, $prefix, $regex, $variables, $tokens)
|
|
|
|
{
|
2010-08-20 22:09:55 +01:00
|
|
|
$r = new \ReflectionClass('Symfony\\Component\\Routing\\Route');
|
2010-06-24 07:46:50 +01:00
|
|
|
$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',
|
2010-11-23 14:11:28 +00:00
|
|
|
array('/foo/{bar}'),
|
|
|
|
'/foo', '#^/foo/(?P<bar>[^/\.]+?)$#x', array('bar' => '{bar}'), array(
|
|
|
|
array('variable', '/', '{bar}', 'bar'),
|
2010-06-24 07:46:50 +01:00
|
|
|
array('text', '/', 'foo', null),
|
|
|
|
)),
|
|
|
|
|
|
|
|
array(
|
|
|
|
'Route with a variable that has a default value',
|
2010-11-23 14:11:28 +00:00
|
|
|
array('/foo/{bar}', array('bar' => 'bar')),
|
|
|
|
'/foo', '#^/foo(?:/(?P<bar>[^/\.]+?))?$#x', array('bar' => '{bar}'), array(
|
|
|
|
array('variable', '/', '{bar}', 'bar'),
|
2010-06-24 07:46:50 +01:00
|
|
|
array('text', '/', 'foo', null),
|
|
|
|
)),
|
|
|
|
|
|
|
|
array(
|
|
|
|
'Route with several variables',
|
2010-11-23 14:11:28 +00:00
|
|
|
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'),
|
2010-06-24 07:46:50 +01:00
|
|
|
array('text', '/', 'foo', null),
|
|
|
|
)),
|
|
|
|
|
|
|
|
array(
|
|
|
|
'Route with several variables that have default values',
|
2011-03-13 17:13:41 +00:00
|
|
|
array('/foo/{bar}/{foobar}', array('bar' => 'bar', 'foobar' => '')),
|
2010-11-23 14:11:28 +00:00
|
|
|
'/foo', '#^/foo(?:/(?P<bar>[^/\.]+?) (?:/(?P<foobar>[^/\.]+?) )?)?$#x', array('bar' => '{bar}', 'foobar' => '{foobar}'), array(
|
|
|
|
array('variable', '/', '{foobar}', 'foobar'),
|
|
|
|
array('variable', '/', '{bar}', 'bar'),
|
2010-06-24 07:46:50 +01:00
|
|
|
array('text', '/', 'foo', null),
|
|
|
|
)),
|
|
|
|
|
|
|
|
array(
|
|
|
|
'Route with several variables but some of them have no default values',
|
2010-11-23 14:11:28 +00:00
|
|
|
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'),
|
2010-06-24 07:46:50 +01:00
|
|
|
array('text', '/', 'foo', null),
|
|
|
|
)),
|
|
|
|
|
|
|
|
array(
|
|
|
|
'Route with a custom token',
|
2010-08-20 22:09:55 +01:00
|
|
|
array('/=foo', array(), array(), array('compiler_class' => 'Symfony\\Tests\\Component\\Routing\\RouteCompiler')),
|
2010-06-24 07:46:50 +01:00
|
|
|
'', '#^/foo/(?P<foo>[^/\.]+?)$#x', array('foo' => '=foo'), array(
|
|
|
|
array('label', '/', '=foo', 'foo'),
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|