Пример #1
0
$dispatcher = new sfEventDispatcher();
$dispatcher->connect('routing.load_configuration', 'configureRouting');
function configureRouting($event)
{
    $event->getSubject()->connect('first', new sfRoute('/first'));
    $event->getSubject()->connect('second', new sfRoute('/', array()));
}
// these tests are against r7363
$t->is($r->getCurrentInternalUri(false), 'foo/bar?id=2', '->getCurrentInternalUri() returns the internal URI for last parsed URL');
$t->is($r->getCurrentInternalUri(true), '@test2?id=2', '->getCurrentInternalUri() returns the internal URI for last parsed URL');
$t->is($r->getCurrentInternalUri(false), 'foo/bar?id=2', '->getCurrentInternalUri() returns the internal URI for last parsed URL');
// regression for ticket #3423  occuring when cache is used. (for the test its enough to have it non null)
$rCached = new sfPatternRoutingTest(new sfEventDispatcher(), new sfNoCache(), $options);
$rCached->connect('test', new sfRoute('/:module', array('action' => 'index')));
$rCached->connect('test2', new sfRoute('/', array()));
$rCached->parse('/');
$t->is($rCached->getCurrentInternalUri(), 'default/index', '->getCurrentInternalUri() returns the internal URI for last parsed URL using cache');
$rCached->parse('/test');
$t->is($rCached->getCurrentInternalUri(), 'test/index', '->getCurrentInternalUri() returns the internal URI for last parsed URL using cache');
$rCached->parse('/');
$t->is($rCached->getCurrentInternalUri(), 'default/index', '->getCurrentInternalUri() returns the internal URI for last parsed URL using cache');
// findRoute was added to be the side effectless version to check an uri
$parameters = $rCached->findRoute('/test');
$t->is($parameters, array('name' => 'test', 'pattern' => '/:module', 'parameters' => array('action' => 'index', 'module' => 'test')), '->findRoute() returns information about matching route');
$t->is($rCached->getCurrentInternalUri(), 'default/index', '->findRoute() does not change the internal URI of sfPatternRouting');
$t->is($rCached->findRoute('/no/match/found'), null, '->findRoute() returns null on non-matching route');
// current internal uri is reset after negative match
$r->clearRoutes();
$r->connect('test', new sfRoute('/test', array('bar' => 'foo')));
$r->parse('/test');
$r->parse('/notfound');
Пример #2
0
$r->connect('default', new sfAlwaysAbsoluteRoute('/:module/:action'));
$t->is($r->generate('', array('module' => 'foo', 'action' => 'bar')), 'http://localhost/foo/bar', '->generate() allows route to generate absolute urls');
$t->is($r->generate('', array('module' => 'foo', 'action' => 'bar'), true), 'http://localhost/foo/bar', '->generate() does not double-absolutize urls');
$t->diag('suffix handling with generate_shortest_url option');
$r = new sfPatternRoutingTest(new sfEventDispatcher(), null, array('generate_shortest_url' => true, 'extra_parameters_as_query_string' => false, 'suffix' => '.html'));
$r->connect('test2', new sfRoute('/users/:username/:sort/:start/', array('module' => 'user', 'action' => 'show', 'sort' => 'all', 'start' => '0'), array('requirements' => array('username' => '\\w+', 'start' => '\\d+'))));
$t->is($r->generate('', array('username' => 'test1', 'module' => 'user', 'action' => 'show')), '/users/test1/', '->generate() creates URL when using suffix and generate_shortest_url');
$t->is($r->generate('', array('username' => 'test1', 'module' => 'user', 'action' => 'show', 'sort' => 'all', 'start' => '1')), '/users/test1/all/1/', '->generate() creates URL when using suffix and generate_shortest_url');
$t->is($r->parse('/users/test1/'), array('module' => 'user', 'action' => 'show', 'sort' => 'all', 'start' => '0', 'username' => 'test1'), '->parse() returns all default parameters when provided suffix and generate_shortest_url enabled with / suffix');
$r = new sfPatternRoutingTest(new sfEventDispatcher(), null, array('generate_shortest_url' => true, 'extra_parameters_as_query_string' => false, 'suffix' => '.html'));
$r->connect('test1', new sfRoute('/users/:username/:sort/:start', array('module' => 'user', 'action' => 'show', 'sort' => 'all', 'start' => '0'), array('requirements' => array('username' => '\\w+', 'start' => '\\d+'))));
$t->is($r->generate('', array('username' => 'test1', 'module' => 'user', 'action' => 'show')), '/users/test1.html', '->generate() creates URL when using suffix and generate_shortest_url');
$t->is($r->generate('', array('username' => 'test1', 'module' => 'user', 'action' => 'show', 'sort' => 'all', 'start' => '0')), '/users/test1.html', '->generate() creates URL when using suffix and generate_shortest_url');
$t->is($r->generate('', array('username' => 'test1', 'module' => 'user', 'action' => 'show', 'sort' => 'all', 'start' => '1')), '/users/test1/all/1.html', '->generate() creates URL when using suffix and generate_shortest_url');
$t->is($r->parse('/users/test1.html'), array('module' => 'user', 'action' => 'show', 'sort' => 'all', 'start' => '0', 'username' => 'test1'), '->parse() returns all default parameters when provided suffix and generate_shortest_url enabled with .html suffix');
$r = new sfPatternRoutingTest(new sfEventDispatcher(), null, array('generate_shortest_url' => true, 'extra_parameters_as_query_string' => false, 'suffix' => '.html'));
$r->connect('posts', new sfRoute('/posts', array('module' => 'posts', 'action' => 'index', 'page' => '1')));
$r->connect('posts_pages', new sfRoute('/posts/:page', array('module' => 'posts', 'action' => 'index', 'page' => '1')));
$t->is($r->generate('', array('module' => 'posts', 'action' => 'index')), '/posts.html', '->generate() creates URL when using suffix and generate_shortest_url');
$t->is($r->generate('', array('module' => 'posts', 'action' => 'index', 'page' => '1')), '/posts.html', '->generate() creates URL when using suffix and generate_shortest_url');
$t->is($r->generate('', array('module' => 'posts', 'action' => 'index', 'page' => '2')), '/posts/2.html', '->generate() creates URL when using suffix and generate_shortest_url');
$t->diag('load_configuration with serialized routes');
// see fixtures/config_routing.yml.php
$r = new sfPatternRoutingTest(new sfEventDispatcher(), new sfNoCache(), array('load_configuration' => true));
$t->ok($r->hasRouteName('test1'), '->loadConfiguration() Config file is loaded');
$routes = $r->getRoutes();
$t->ok(is_string($routes['test1']), '->loadConfiguration() Route objects are not serialized in cache');
$route = $r->getRoute('test1');
$t->ok(is_object($route), '->loadConfiguration() Route objects are unserialized on demand');
$t->is_deeply($r->parse('/'), array('module' => 'default', 'action' => 'index'), '->parse() Default parameters are applied to serialized routes');