Example #1
0
$params = array('module' => 'default', 'action' => 'index', 'nonsegmented' => 'foo/bar/baz');
$t->is($r->parse('/foo/bar/baz'), $params, '->parse() works without segment_separators');
$t->is($r->generate('', $params), '/foo%2Fbar%2Fbaz', '->generate() works without segment_separators');
$r = new sfPatternRoutingTest(new sfEventDispatcher(), null, array_merge($options, array('segment_separators' => array('~'))));
$r->connect('nosegment', new sfRoute('/:nonsegmented', array()));
$params = array('module' => 'default', 'action' => 'index', 'nonsegmented' => 'plainurl');
$url = '/plainurl';
$t->is($r->parse($url), $params, '->parse() works with segment_separators which are not in url');
$t->is($r->generate('', $params), $url, '->generate() works with segment_separators which are not in url');
$params = array('module' => 'default', 'action' => 'index', 'nonsegmented' => 'foo/bar/baz');
$t->is($r->parse('/foo/bar/baz'), $params, '->parse() works with segment_separators which are not in url');
$t->is($r->generate('', $params), '/foo%2Fbar%2Fbaz', '->generate() works with segment_separators which are not in url');
$r = new sfPatternRoutingTest(new sfEventDispatcher(), null, array_merge($options, array('variable_prefixes' => array(':', '$'))));
// token names
$t->diag('token names');
$r->clearRoutes();
$r->connect('test1', new sfRoute('/:foo_1/:bar2', array()));
$params = array('module' => 'default', 'action' => 'index', 'foo_1' => 'test', 'bar2' => 'foobar');
$url = '/test/foobar';
$t->is($r->parse($url), $params, '->parse() accepts token names composed of letters, digits and _');
$t->is($r->generate('', $params), $url, '->generate() accepts token names composed of letters, digits and _');
// token prefix
$t->diag('token prefix');
$r->clearRoutes();
$r->connect('test2', new sfRoute('/2/$module/$action/$id', array()));
$r->connect('test3', new sfRoute('/3/$module/:action/$first_name/:last_name', array()));
$r->connect('test1', new sfRoute('/1/:module/:action', array()));
$params1 = array('module' => 'foo', 'action' => 'bar');
$url1 = '/1/foo/bar';
$t->is($r->parse($url1), $params1, '->parse() accepts token names starting with :');
$t->is($r->generate('', $params1), $url1, '->generate() accepts token names starting with :');