Example #1
0
$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');
$t->is($r->getCurrentInternalUri(), null, '->getCurrentInternalUri() reseted after negative match');