Skip to content

Commit

Permalink
Removing controller key as a default when Routes are connected. Was c…
Browse files Browse the repository at this point in the history
…ausing issues when using regex qualifiers on controller keys.

Tests added.
  • Loading branch information
markstory committed Dec 16, 2009
1 parent 09966a7 commit 7ceb50b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
8 changes: 6 additions & 2 deletions cake/libs/router.php
Expand Up @@ -272,7 +272,7 @@ function connect($route, $defaults = array(), $options = array()) {
$self->__prefixes[] = $defaults['prefix'];
$self->__prefixes = array_keys(array_flip($self->__prefixes));
}
$defaults += array('action' => 'index', 'plugin' => null, 'controller' => null);
$defaults += array('action' => 'index', 'plugin' => null);
$routeClass = 'CakeRoute';
if (isset($options['routeClass'])) {
$routeClass = $options['routeClass'];
Expand Down Expand Up @@ -424,7 +424,11 @@ function parse($url) {
if (!$self->__defaultsMapped && $self->__connectDefaults) {
$self->__connectDefaultRoutes();
}
$out = array('pass' => array(), 'named' => array());
$out = array(
'pass' => array(),
'named' => array(),
'controller' => null,
);
$r = $ext = null;

if (ini_get('magic_quotes_gpc') === '1') {
Expand Down
39 changes: 33 additions & 6 deletions cake/tests/cases/libs/router.test.php
Expand Up @@ -508,6 +508,16 @@ function testUrlGenerationWithRegexQualifiedParams() {
$result = Router::url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'year' => 2007, 'month' => 10, 'min-forestilling'));
$expected = '/kalender/10/2007/min-forestilling';
$this->assertEqual($result, $expected);

Router::reload();
Router::connect('/:controller/:action/*', array(), array(
'controller' => 'source|wiki|commits|tickets|comments|view',
'action' => 'branches|history|branch|logs|view|start|add|edit|modify'
));
Router::defaults(false);
$result = Router::parse('/foo/bar');
$expected = array('pass' => array(), 'named' => array(), 'controller' => null);
$this->assertEqual($result, $expected);
}

/**
Expand Down Expand Up @@ -1844,7 +1854,7 @@ function testCurentRoute() {
Router::connect('/government', $url);
Router::parse('/government');
$route =& Router::currentRoute();
$this->assertEqual(array_merge($url, array('plugin' => false)), $route->defaults);
$this->assertEqual(array_merge($url, array('plugin' => null)), $route->defaults);
}
/**
* testRequestRoute
Expand All @@ -1857,21 +1867,21 @@ function testRequestRoute() {
Router::connect('/government', $url);
Router::parse('/government');
$route =& Router::requestRoute();
$this->assertEqual(array_merge($url, array('plugin' => false)), $route->defaults);
$this->assertEqual(array_merge($url, array('plugin' => null)), $route->defaults);

// test that the first route is matched
$newUrl = array('controller' => 'products', 'action' => 'display', 6);
Router::connect('/government', $url);
Router::parse('/government');
$route =& Router::requestRoute();
$this->assertEqual(array_merge($url, array('plugin' => false)), $route->defaults);
$this->assertEqual(array_merge($url, array('plugin' => null)), $route->defaults);

// test that an unmatched route does not change the current route
$newUrl = array('controller' => 'products', 'action' => 'display', 6);
Router::connect('/actor', $url);
Router::parse('/government');
$route =& Router::requestRoute();
$this->assertEqual(array_merge($url, array('plugin' => false)), $route->defaults);
$this->assertEqual(array_merge($url, array('plugin' => null)), $route->defaults);
}
/**
* testGetParams
Expand All @@ -1884,7 +1894,7 @@ function testGetParams() {
$params = array('param1' => '1', 'param2' => '2');
Router::setRequestInfo(array($params, $paths));
$expected = array(
'plugin' => false, 'controller' => false, 'action' => false,
'plugin' => null, 'controller' => false, 'action' => false,
'param1' => '1', 'param2' => '2'
);
$this->assertEqual(Router::getparams(), $expected);
Expand All @@ -1896,7 +1906,7 @@ function testGetParams() {

$params = array('controller' => 'pages', 'action' => 'display');
Router::setRequestInfo(array($params, $paths));
$expected = array('plugin' => false, 'controller' => 'pages', 'action' => 'display');
$expected = array('plugin' => null, 'controller' => 'pages', 'action' => 'display');
$this->assertEqual(Router::getparams(), $expected);
$this->assertEqual(Router::getparams(true), $expected);
}
Expand Down Expand Up @@ -2125,6 +2135,23 @@ function testComplexRouteCompilingAndParsing() {
'extra' => null,
);
$this->assertEqual($route->defaults, $expected);

$route =& new CakeRoute(
'/:controller/:action/*',
array('project' => false),
array(
'controller' => 'source|wiki|commits|tickets|comments|view',
'action' => 'branches|history|branch|logs|view|start|add|edit|modify'
)
);
$this->assertFalse($route->parse('/chaw_test/wiki'));

$result = $route->compile();
$this->assertNoPattern($result, '/some_project/source');
$this->assertPattern($result, '/source/view');
$this->assertPattern($result, '/source/view/other/params');
$this->assertNoPattern($result, '/chaw_test/wiki');
$this->assertNoPattern($result, '/source/wierd_action');
}

/**
Expand Down

0 comments on commit 7ceb50b

Please sign in to comment.