Skip to content

Commit

Permalink
Fixing connection of plugin routes, the were being connected in the w…
Browse files Browse the repository at this point in the history
…rong spot.

Moving admin route + plugin tests to correct place.
Fixing order of methods in tests. parse() should only be called after routes are connected otherwise the default routes will precede the custom routes.
  • Loading branch information
markstory committed Dec 1, 2009
1 parent a5a0292 commit 21dd7fd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
8 changes: 3 additions & 5 deletions cake/libs/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,16 +520,15 @@ function __connectDefaultRoutes() {
foreach ($plugins as $key => $value) {
$plugins[$key] = Inflector::underscore($value);
}

$match = array('plugin' => implode('|', $plugins));
$this->connect('/:plugin/:controller/:action/*', array(), $match);

foreach ($this->__prefixes as $prefix) {
$params = array('prefix' => $prefix, $prefix => true);
$indexParams = $params + array('action' => 'index');
$this->connect("/{$prefix}/:plugin/:controller", $indexParams, $match);
$this->connect("/{$prefix}/:plugin/:controller/:action/*", $params, $match);
}
$this->connect('/:plugin/:controller/:action/*', array(), $match);
}

foreach ($this->__prefixes as $prefix) {
Expand Down Expand Up @@ -1405,11 +1404,10 @@ function match($url) {
continue;
}
$pass[] = $url[$i];
unset($url[$i]);
unset($url[$i], $params[$i]);
$i++;
}



//check patterns for routed params
if (!empty($this->params)) {
foreach ($this->params as $key => $pattern) {
Expand Down
60 changes: 30 additions & 30 deletions cake/tests/cases/libs/router.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ function testUrlGenerationWithAdminPrefix() {

Router::reload();
Router::connect('/admin/subscriptions/:action/*', array('controller' => 'subscribe', 'admin' => true, 'prefix' => 'admin'));
Router::parse('/');
Router::setRequestInfo(array(
array(
'pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscribe',
Expand All @@ -640,7 +641,6 @@ function testUrlGenerationWithAdminPrefix() {
'webroot' => '/magazine/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2),
)
));
Router::parse('/');

$result = Router::url(array('action' => 'edit', 1));
$expected = '/magazine/admin/subscriptions/edit/1';
Expand Down Expand Up @@ -681,81 +681,60 @@ function testUrlGenerationWithAdminPrefix() {


Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'pages', 'action' => 'admin_add', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/pages/add')),
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/')
));
Router::parse('/');

$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false));
$expected = '/admin/pages/add';
$this->assertEqual($result, $expected);

Router::reload();
Router::connect('/admin/:controller/:action/:id', array('admin' => true), array('id' => '[0-9]+'));
Router::parse('/');
Router::setRequestInfo(array(
array ('plugin' => null, 'controller' => 'pages', 'action' => 'admin_edit', 'pass' => array('284'), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/pages/edit/284')),
array ('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/edit/284', 'webroot' => '/')
));

Router::connect('/admin/:controller/:action/:id', array('admin' => true), array('id' => '[0-9]+'));
Router::parse('/');

$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'edit', 'id' => '284'));
$expected = '/admin/pages/edit/284';
$this->assertEqual($result, $expected);


Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
array ('plugin' => null, 'controller' => 'pages', 'action' => 'admin_add', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/pages/add')),
array ('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/')
));
Router::parse('/');

$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false));
$expected = '/admin/pages/add';
$this->assertEqual($result, $expected);


Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'pages', 'action' => 'admin_edit', 'pass' => array('284'), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/pages/edit/284')),
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/edit/284', 'webroot' => '/')
));
Router::parse('/');

$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'edit', 284));
$expected = '/admin/pages/edit/284';
$this->assertEqual($result, $expected);

Router::reload();
Router::setRequestInfo(array(
array(
'plugin' => 'shows', 'controller' => 'show_tickets', 'action' => 'admin_edit',
'pass' => array('6'), 'prefix' => 'admin', 'admin' => true, 'form' => array(),
'url' => array('url' => 'admin/shows/show_tickets/edit/6')
),
array(
'plugin' => null, 'controller' => null, 'action' => null, 'base' => '',
'here' => '/admin/shows/show_tickets/edit/6', 'webroot' => '/'
)
));
Router::parse('/');

$result = Router::url(array(
'plugin' => 'shows', 'controller' => 'show_tickets', 'action' => 'edit', 6,
'admin' => true, 'prefix' => 'admin'
));
$expected = '/admin/shows/show_tickets/edit/6';
$this->assertEqual($result, $expected);

Router::reload();
Router::connect('/admin/posts/*', array('controller' => 'posts', 'action' => 'index', 'admin' => true));
Router::parse('/');
Router::setRequestInfo(array(
array('pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'posts', 'prefix' => 'admin', 'admin' => true, 'url' => array('url' => 'admin/posts')),
array('base' => '', 'here' => '/admin/posts', 'webroot' => '/')
));
Router::connect('/admin/posts/*', array('controller' => 'posts', 'action' => 'index', 'admin' => true));
Router::parse('/');

$result = Router::url(array('all'));
$expected = '/admin/posts/all';
Expand Down Expand Up @@ -1161,7 +1140,7 @@ function testPrefixRoutingAndPlugins() {
Router::reload();
Router::setRequestInfo(array(
array('admin' => true, 'controller' => 'controller', 'action' => 'action',
'form' => array(), 'url' => array(), 'plugin' => null),
'form' => array(), 'url' => array(), 'plugin' => null, 'prefix' => 'admin'),
array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(),
'argSeparator' => ':', 'namedArgs' => array())
));
Expand All @@ -1170,6 +1149,27 @@ function testPrefixRoutingAndPlugins() {
$result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index'));
$expected = '/admin/test_plugin';
$this->assertEqual($result, $expected);

Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
array(
'plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'admin_edit',
'pass' => array('6'), 'prefix' => 'admin', 'admin' => true, 'form' => array(),
'url' => array('url' => 'admin/shows/show_tickets/edit/6')
),
array(
'plugin' => null, 'controller' => null, 'action' => null, 'base' => '',
'here' => '/admin/shows/show_tickets/edit/6', 'webroot' => '/'
)
));

$result = Router::url(array(
'plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'edit', 6,
'admin' => true, 'prefix' => 'admin'
));
$expected = '/admin/test_plugin/show_tickets/edit/6';
$this->assertEqual($result, $expected);

App::build(array('plugins' => $paths));
}
Expand Down

0 comments on commit 21dd7fd

Please sign in to comment.