mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing connection of plugin routes, the were being connected in the wrong 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.
This commit is contained in:
parent
a5a02925d8
commit
21dd7fd4ca
2 changed files with 33 additions and 35 deletions
|
@ -520,9 +520,7 @@ class Router {
|
||||||
foreach ($plugins as $key => $value) {
|
foreach ($plugins as $key => $value) {
|
||||||
$plugins[$key] = Inflector::underscore($value);
|
$plugins[$key] = Inflector::underscore($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$match = array('plugin' => implode('|', $plugins));
|
$match = array('plugin' => implode('|', $plugins));
|
||||||
$this->connect('/:plugin/:controller/:action/*', array(), $match);
|
|
||||||
|
|
||||||
foreach ($this->__prefixes as $prefix) {
|
foreach ($this->__prefixes as $prefix) {
|
||||||
$params = array('prefix' => $prefix, $prefix => true);
|
$params = array('prefix' => $prefix, $prefix => true);
|
||||||
|
@ -530,6 +528,7 @@ class Router {
|
||||||
$this->connect("/{$prefix}/:plugin/:controller", $indexParams, $match);
|
$this->connect("/{$prefix}/:plugin/:controller", $indexParams, $match);
|
||||||
$this->connect("/{$prefix}/:plugin/:controller/:action/*", $params, $match);
|
$this->connect("/{$prefix}/:plugin/:controller/:action/*", $params, $match);
|
||||||
}
|
}
|
||||||
|
$this->connect('/:plugin/:controller/:action/*', array(), $match);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->__prefixes as $prefix) {
|
foreach ($this->__prefixes as $prefix) {
|
||||||
|
@ -1405,11 +1404,10 @@ class RouterRoute {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$pass[] = $url[$i];
|
$pass[] = $url[$i];
|
||||||
unset($url[$i]);
|
unset($url[$i], $params[$i]);
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//check patterns for routed params
|
//check patterns for routed params
|
||||||
if (!empty($this->params)) {
|
if (!empty($this->params)) {
|
||||||
foreach ($this->params as $key => $pattern) {
|
foreach ($this->params as $key => $pattern) {
|
||||||
|
|
|
@ -630,6 +630,7 @@ class RouterTest extends CakeTestCase {
|
||||||
|
|
||||||
Router::reload();
|
Router::reload();
|
||||||
Router::connect('/admin/subscriptions/:action/*', array('controller' => 'subscribe', 'admin' => true, 'prefix' => 'admin'));
|
Router::connect('/admin/subscriptions/:action/*', array('controller' => 'subscribe', 'admin' => true, 'prefix' => 'admin'));
|
||||||
|
Router::parse('/');
|
||||||
Router::setRequestInfo(array(
|
Router::setRequestInfo(array(
|
||||||
array(
|
array(
|
||||||
'pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscribe',
|
'pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscribe',
|
||||||
|
@ -640,7 +641,6 @@ class RouterTest extends CakeTestCase {
|
||||||
'webroot' => '/magazine/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2),
|
'webroot' => '/magazine/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2),
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
Router::parse('/');
|
|
||||||
|
|
||||||
$result = Router::url(array('action' => 'edit', 1));
|
$result = Router::url(array('action' => 'edit', 1));
|
||||||
$expected = '/magazine/admin/subscriptions/edit/1';
|
$expected = '/magazine/admin/subscriptions/edit/1';
|
||||||
|
@ -681,36 +681,35 @@ class RouterTest extends CakeTestCase {
|
||||||
|
|
||||||
|
|
||||||
Router::reload();
|
Router::reload();
|
||||||
|
Router::parse('/');
|
||||||
Router::setRequestInfo(array(
|
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' => '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' => '/')
|
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));
|
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false));
|
||||||
$expected = '/admin/pages/add';
|
$expected = '/admin/pages/add';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
Router::reload();
|
Router::reload();
|
||||||
|
Router::connect('/admin/:controller/:action/:id', array('admin' => true), array('id' => '[0-9]+'));
|
||||||
|
Router::parse('/');
|
||||||
Router::setRequestInfo(array(
|
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' => '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' => '/')
|
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'));
|
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'edit', 'id' => '284'));
|
||||||
$expected = '/admin/pages/edit/284';
|
$expected = '/admin/pages/edit/284';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
|
||||||
Router::reload();
|
Router::reload();
|
||||||
|
Router::parse('/');
|
||||||
Router::setRequestInfo(array(
|
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' => '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' => '/')
|
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));
|
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false));
|
||||||
$expected = '/admin/pages/add';
|
$expected = '/admin/pages/add';
|
||||||
|
@ -718,44 +717,24 @@ class RouterTest extends CakeTestCase {
|
||||||
|
|
||||||
|
|
||||||
Router::reload();
|
Router::reload();
|
||||||
|
Router::parse('/');
|
||||||
Router::setRequestInfo(array(
|
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' => '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' => '/')
|
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));
|
$result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'edit', 284));
|
||||||
$expected = '/admin/pages/edit/284';
|
$expected = '/admin/pages/edit/284';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
|
||||||
Router::reload();
|
Router::reload();
|
||||||
Router::setRequestInfo(array(
|
Router::connect('/admin/posts/*', array('controller' => 'posts', 'action' => 'index', 'admin' => true));
|
||||||
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('/');
|
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::setRequestInfo(array(
|
Router::setRequestInfo(array(
|
||||||
array('pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'posts', 'prefix' => 'admin', 'admin' => true, 'url' => array('url' => 'admin/posts')),
|
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' => '/')
|
array('base' => '', 'here' => '/admin/posts', 'webroot' => '/')
|
||||||
));
|
));
|
||||||
Router::connect('/admin/posts/*', array('controller' => 'posts', 'action' => 'index', 'admin' => true));
|
|
||||||
Router::parse('/');
|
|
||||||
|
|
||||||
$result = Router::url(array('all'));
|
$result = Router::url(array('all'));
|
||||||
$expected = '/admin/posts/all';
|
$expected = '/admin/posts/all';
|
||||||
|
@ -1161,7 +1140,7 @@ class RouterTest extends CakeTestCase {
|
||||||
Router::reload();
|
Router::reload();
|
||||||
Router::setRequestInfo(array(
|
Router::setRequestInfo(array(
|
||||||
array('admin' => true, 'controller' => 'controller', 'action' => 'action',
|
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(),
|
array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(),
|
||||||
'argSeparator' => ':', 'namedArgs' => array())
|
'argSeparator' => ':', 'namedArgs' => array())
|
||||||
));
|
));
|
||||||
|
@ -1170,6 +1149,27 @@ class RouterTest extends CakeTestCase {
|
||||||
$result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index'));
|
$result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index'));
|
||||||
$expected = '/admin/test_plugin';
|
$expected = '/admin/test_plugin';
|
||||||
$this->assertEqual($result, $expected);
|
$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));
|
App::build(array('plugins' => $paths));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue