예제 #1
0
$r->clearRoutes();
$r->connect('test', new sfRoute('/test/:id', array('module' => 'default', 'action' => 'integer'), array('id' => '\\d+')));
$params = array('module' => 'default', 'action' => 'integer', 'id' => 12);
$url = '/test/12';
$named_params = array('id' => 12);
$t->is($r->generate('', $params), $url, '->generate() can take an empty route name as its first parameter');
$t->is($r->generate('test', $params), $url, '->generate() can take a route name as its first parameter');
$t->is($r->generate('test', $named_params), $url, '->generate() with named routes needs only parameters not defined in route default');
// ->appendRoute()
$t->diag('->appendRoute()');
$r->clearRoutes();
$r->connect('test', new sfRoute('/:module', array('action' => 'index')));
$r->connect('test1', new sfRoute('/:module/:action/*', array()));
$routes = $r->getRoutes();
$r->clearRoutes();
$r->appendRoute('test', new sfRoute('/:module', array('action' => 'index')));
$r->appendRoute('test1', new sfRoute('/:module/:action/*', array()));
$t->is($r->getRoutes(), $routes, '->appendRoute() is an alias for ->connect()');
// ->prependRoute()
$t->diag('->prependRoute()');
$r->clearRoutes();
$r->connect('test', new sfRoute('/:module', array('action' => 'index')));
$r->connect('test1', new sfRoute('/:module/:action/*', array()));
$route_names = array_keys($r->getRoutes());
$r->clearRoutes();
$r->prependRoute('test', new sfRoute('/:module', array('action' => 'index')));
$r->prependRoute('test1', new sfRoute('/:module/:action/*', array()));
$p_route_names = array_keys($r->getRoutes());
$t->is(implode('-', $p_route_names), implode('-', array_reverse($route_names)), '->prependRoute() adds new routes at the beginning of the existings ones');
// ->addRouteBefore()
$t->diag('->insertRouteBefore()');