Moving pass key restructuring into CakeRoute.

Adding tests for that and http header matching.
This commit is contained in:
mark_story 2011-03-03 07:30:22 -05:00
parent 171830df33
commit 217938a970
2 changed files with 59 additions and 0 deletions

View file

@ -233,6 +233,16 @@ class CakeRoute {
$route['named'] = $named;
unset($route['_args_']);
}
// restructure 'pass' key route params
if (isset($this->options['pass'])) {
$j = count($this->options['pass']);
while($j--) {
if (isset($route[$this->options['pass'][$j]])) {
array_unshift($route['pass'], $route[$this->options['pass'][$j]]);
}
}
}
return $route;
}

View file

@ -450,6 +450,35 @@ class CakeRouteTestCase extends CakeTestCase {
$this->assertEqual($result['action'], 'index');
}
/**
* test numerically indexed defaults, get appeneded to pass
*
* @return void
*/
function testParseWithPassDefaults() {
$route = new Cakeroute('/:controller', array('action' => 'display', 'home'));
$result = $route->parse('/posts');
$expected = array(
'controller' => 'posts',
'action' => 'display',
'pass' => array('home'),
'named' => array()
);
$this->assertEquals($expected, $result);
}
/**
* test that http header conditions can cause route failures.
*
* @return void
*/
function testParseWithHttpHeaderConditions() {
$_SERVER['REQUEST_METHOD'] = 'GET';
$route = new CakeRoute('/sample', array('controller' => 'posts', 'action' => 'index', '[method]' => 'POST'));
$this->assertFalse($route->parse('/sample'));
}
/**
* test that patterns work for :action
*
@ -653,4 +682,24 @@ class CakeRouteTestCase extends CakeTestCase {
);
$this->assertEqual($result, $expected);
}
/**
* test restructuring args with pass key
*
* @return void
*/
function testPassArgRestructure() {
$route = new CakeRoute('/:controller/:action/:slug', array(), array(
'pass' => array('slug')
));
$result = $route->parse('/posts/view/my-title');
$expected = array(
'controller' => 'posts',
'action' => 'view',
'slug' => 'my-title',
'pass' => array('my-title'),
'named' => array()
);
$this->assertEquals($expected, $result, 'Slug should have moved');
}
}