Changeset 7625
- Timestamp:
- 02/27/08 08:12:30 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/routing/sfPatternRouting.class.php
r7617 r7625 241 241 242 242 /** 243 * Adds a new route before a given one in the current list of routes. 244 * 245 * @see connect 246 */ 247 public function insertRouteBefore($pivot, $name, $route, $default = array(), $requirements = array()) 248 { 249 if (!isset($this->routes[$pivot])) 250 { 251 throw new sfConfigurationException(sprintf('Unable to insert route "%s" before inexistent route "%s".', $name, $pivot)); 252 } 253 254 $routes = $this->routes; 255 $this->routes = array(); 256 $newroutes = array(); 257 foreach ($routes as $key => $value) 258 { 259 if ($key == $pivot) 260 { 261 $newroutes = array_merge($newroutes, $this->connect($name, $route, $default, $requirements)); 262 } 263 $newroutes[$key] = $value; 264 } 265 266 return $this->routes = $newroutes; 267 } 268 269 /** 243 270 * Adds a new route at the end of the current list of routes. 244 271 * branches/1.1/test/unit/routing/sfPatternRoutingTest.php
r7616 r7625 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(12 3, new lime_output_color());13 $t = new lime_test(125, new lime_output_color()); 14 14 15 15 class sfPatternRoutingTest extends sfPatternRouting … … 409 409 $t->is(implode('-', $p_route_names), implode('-', array_reverse($route_names)), '->prependRoute() adds new routes at the beginning of the existings ones'); 410 410 411 // ->addRouteBefore() 412 $t->diag('->insertRouteBefore()'); 413 $r->clearRoutes(); 414 $r->connect('test1', '/:module', array('action' => 'index')); 415 $r->connect('test3', '/:module/:action/*', array()); 416 $r->insertRouteBefore('test3', 'test2', '/:module/:action', array('module' => 'default')); 417 $route_names = array_keys($r->getRoutes()); 418 $r->clearRoutes(); 419 $r->connect('test1', '/:module', array('action' => 'index')); 420 $r->connect('test2', '/:module/:action', array('module' => 'default')); 421 $r->connect('test3', '/:module/:action/*', array()); 422 $test_route_names = array_keys($r->getRoutes()); 423 $t->is(implode('-', $test_route_names), implode('-', $route_names), '->insertRouteBefore() adds a new route before another existings one'); 424 $r->clearRoutes(); 425 $msg = '->insertRouteBefore() throws an sfConfigurationException when trying to insert a route before a non existent one'; 426 try 427 { 428 $r->insertRouteBefore('test2', 'test', '/index.php/:module/:action', array('module' => 'default', 'action' => 'index')); 429 $t->fail($msg); 430 } 431 catch (sfConfigurationException $e) 432 { 433 $t->pass($msg); 434 } 435 411 436 // ->getCurrentInternalUri() 412 437 $t->diag('->getCurrentInternalUri()');

