views:

46

answers:

1

Unfortunately I'am currently forced to use concrete URI in my functional test (get('/articles/index') in case of my backend admin testing).

It's obviously not good because this way im depending on concrete project URI settings which is not the point of this tests, is possibly somehow use routing rules in this get() method?

A: 

You can generate the URI of the route you need, and then pass that URI to get(). To get the routing set up appropriately, add this at the beginning of your test:

$routing = sfContext::getInstance()->getRouting();
$routingOptions = $routing->getOptions();
$routingOptions['context']['prefix'] = '';
$routing->initialize(sfContext::getInstance()->getEventDispatcher(), $routing->getCache(), $routingOptions);

To generate the URI you want, do

$uri = $routing->generate('route_name', array('param' => 'value'));
$test->get($uri);
lyoshenka
Nice-one, thx, i was looking for some 'rails-like' shortcut as 'resourcename_new', unfortunately symfony has very bad information basis, everything iam looking for iam searching in source code itself :-/
palmic
... unfortunatelly this is does not relevant for collections routes (i have one displaying all the model actions). How can i generate uri for index, or new action generated from this route?:institutka_faq: class: sfDoctrineRouteCollection options: model: InstitutkaFaq module: faq prefix_path: /faq column: id with_wildcard_routes: true
palmic
It works exactly the same as with regular routes. A route collection is just a shortcut for creating the 7 basic CRUD routes. To see all the routes a route collection creates, run `symfony app:routes frontend` or see this link: http://www.symfony-project.org/jobeet/1_4/Doctrine/en/05#chapter_05_collection_route_class . Just call `$routing->generate('institutka_faq')` or `$routing->generate('institutka_faq_edit')`.
lyoshenka