예제 #1
0
$t->isnt($r->generate('', $params), $url, '->generate() does not remove the last parameter if the parameter is default value');
$t->is($r->parse($url), $params, '->parse() removes the last parameter if the parameter is default value');
$r->clearRoutes();
$r->connect('test', new sfRoute('/:module/:action/:test/:id', array('module' => 'default', 'action' => 'index', 'test' => 'foo', 'id' => 'bar')));
$params = array('module' => 'default', 'action' => 'index', 'test' => 'foo', 'id' => 'bar');
$url = '/default/index';
$t->isnt($r->generate('', $params), $url, '->generate() does not remove last parameters if they have default values');
$t->is($r->parse($url), $params, '->parse() removes last parameters if they have default values');
// routing defaults parameters
$r->setDefaultParameter('foo', 'bar');
$r->clearRoutes();
$r->connect('test', new sfRoute('/test/:foo/:id', array('module' => 'default', 'action' => 'index')));
$params = array('module' => 'default', 'action' => 'index', 'id' => 12);
$url = '/test/bar/12';
$t->is($r->generate('', $params), $url, '->generate() merges parameters with defaults from "sf_routing_defaults"');
$r->setDefaultParameters(array());
// unnamed wildcard *
$t->diag('unnamed wildcard *');
$r->clearRoutes();
$r->connect('test', new sfRoute('/:module/:action/test/*', array('module' => 'default', 'action' => 'index')));
$params = array('module' => 'default', 'action' => 'index');
$url = '/default/index/test';
$t->is($r->parse($url), $params, '->parse() finds route for URL   with no additional parameters when route ends with unnamed wildcard *');
$t->is($r->generate('', $params), $url, '->generate() creates URL for route with no additional parameters when route ends with unnamed wildcard *');
// #4173
$url = '/default/index/test/';
$t->is($r->parse($url), $params, '->parse() finds route for URL   with no additional parameters and trailing slash when route ends with unnamed wildcard *');
$params = array('module' => 'default', 'action' => 'index', 'titi' => 'toto');
$url = '/default/index/test/titi/toto/';
$t->is($r->parse($url), $params, '->parse() finds route for URL   with additional parameters and trailing slash when route ends with unnamed wildcard *');
$params = array('module' => 'default', 'action' => 'index', 'page' => '4.html', 'toto' => true, 'titi' => 'toto', 'OK' => true);