mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
fix for router and edit links, added tests, closes #3108
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5592 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
37ff270d04
commit
7793b4f5c0
2 changed files with 72 additions and 14 deletions
|
@ -643,7 +643,7 @@ class Router extends Object {
|
|||
$path = end($_this->__paths);
|
||||
}
|
||||
}
|
||||
$base = $_this->stripPlugin($path['base'], $params['plugin']);
|
||||
$base = $path['base']; // dont need this anymore $_this->stripPlugin($path['base'], $params['plugin']);
|
||||
$extension = $output = $mapped = $q = $frag = null;
|
||||
|
||||
if (is_array($url) && !empty($url)) {
|
||||
|
@ -667,7 +667,7 @@ class Router extends Object {
|
|||
}
|
||||
}
|
||||
if ($admin) {
|
||||
if (!isset($url[$admin]) && isset($params[$admin])) {
|
||||
if (!isset($url[$admin]) && !empty($params[$admin])) {
|
||||
$url[$admin] = true;
|
||||
} elseif ($admin && array_key_exists($admin, $url) && !$url[$admin]) {
|
||||
unset($url[$admin]);
|
||||
|
@ -719,10 +719,15 @@ class Router extends Object {
|
|||
if (empty($named) && empty($args) && (!isset($url['action']) || $url['action'] == 'index')) {
|
||||
$url['action'] = null;
|
||||
}
|
||||
$urlOut = Set::filter(array($url['plugin'], $url['controller'], $url['action']));
|
||||
|
||||
if ($url['plugin'] == $url['controller']) {
|
||||
array_shift($urlOut);
|
||||
$urlOut = Set::filter(array($url['controller'], $url['action']));
|
||||
|
||||
if($admin && isset($url['admin'])) {
|
||||
array_unshift($urlOut, $admin);
|
||||
}
|
||||
|
||||
if (isset($url['plugin']) && $url['plugin'] != $url['controller']) {
|
||||
array_unshift($urlOut, $url['plugin']);
|
||||
}
|
||||
$output = join('/', $urlOut) . '/';
|
||||
}
|
||||
|
|
|
@ -183,10 +183,9 @@ class RouterTest extends UnitTestCase {
|
|||
|
||||
Configure::write('Routing.admin', 'admin');
|
||||
$this->router->reload();
|
||||
$this->router->connect('/admin/subscriptions/:action/*', array('controller' => 'subscribe', 'admin' => true, 'prefix' => 'admin'));
|
||||
$this->router->setRequestInfo(array(
|
||||
array(
|
||||
'pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscribe',
|
||||
'pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscriptions',
|
||||
'admin' => true, 'url' => array('url' => 'admin/subscriptions/index/page:2'), 'bare' => 0, 'webservices' => ''
|
||||
),
|
||||
array(
|
||||
|
@ -201,6 +200,26 @@ class RouterTest extends UnitTestCase {
|
|||
$expected = '/magazine/admin/subscriptions/index/page:3';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
Configure::write('Routing.admin', 'admin');
|
||||
$this->router->reload();
|
||||
//$this->router->connect('/admin/subscriptions/edit/*', array('controller' => 'subscriptions', 'admin' => true, 'prefix' => 'admin'));
|
||||
$this->router->setRequestInfo(array(
|
||||
array(
|
||||
'pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscriptions',
|
||||
'admin' => true, 'url' => array('url' => 'admin/subscriptions/edit/1'), 'bare' => 0, 'webservices' => ''
|
||||
),
|
||||
array(
|
||||
'base' => '/magazine', 'here' => '/magazine/admin/subscriptions/edit/1',
|
||||
'webroot' => '/magazine/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2),
|
||||
'webservices' => null
|
||||
)
|
||||
));
|
||||
$this->router->parse('/');
|
||||
|
||||
$result = $this->router->url(array('action'=>'edit', 'id'=> 1));
|
||||
$expected = '/magazine/admin/subscriptions/edit/1';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->router->reload();
|
||||
$this->router->setRequestInfo(array(
|
||||
array(
|
||||
|
@ -336,17 +355,17 @@ class RouterTest extends UnitTestCase {
|
|||
);
|
||||
|
||||
$this->router->connect('/kalender/*', array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'));
|
||||
|
||||
|
||||
$this->router->testing = true;
|
||||
$result = $this->router->url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'min-forestilling'));
|
||||
$result = $this->router->url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'min-forestilling'));
|
||||
unset($this->router->testing);
|
||||
$expected = '/kalender/min-forestilling';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->router->url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'year' => 2007, 'month' => 10, 'min-forestilling'));
|
||||
$result = $this->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);
|
||||
|
||||
|
||||
Configure::write('Routing.admin', 'admin');
|
||||
$this->router->reload();
|
||||
|
||||
|
@ -370,6 +389,7 @@ class RouterTest extends UnitTestCase {
|
|||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->router->reload();
|
||||
//Configure::write('Routing.admin', false);
|
||||
|
||||
$this->router->setRequestInfo(array(
|
||||
array(
|
||||
|
@ -473,11 +493,11 @@ class RouterTest extends UnitTestCase {
|
|||
$expected = array('pass' => array('my-page'), 'plugin' => null, 'controller' => 'test', 'action' => 'index');
|
||||
|
||||
$this->router->reload();
|
||||
$this->router->connect('/:language/contact', array('language' => 'eng', 'plugin' => 'contact', 'controller' => 'contact', 'action' => 'index'), array('language' => '[a-z]{3}'));
|
||||
$this->router->connect('/:language/contact', array('language' => 'eng', 'plugin' => 'contact', 'controller' => 'contact', 'action' => 'index'), array('language' => '[a-z]{3}'));
|
||||
$result = $this->router->parse('/eng/contact');
|
||||
$expected = array('pass' => array(), 'language' => 'eng', 'plugin' => 'contact', 'controller' => 'contact', 'action' => 'index');
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
|
||||
$this->router->reload();
|
||||
$this->router->connect('/forestillinger/:month/:year/*',
|
||||
array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'),
|
||||
|
@ -487,7 +507,7 @@ class RouterTest extends UnitTestCase {
|
|||
$result = $this->router->parse('/forestillinger/10/2007/min-forestilling');
|
||||
$expected = array('pass' => array('min-forestilling'), 'plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'year' => 2007, 'month' => 10);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function testAdminRouting() {
|
||||
|
@ -660,6 +680,39 @@ class RouterTest extends UnitTestCase {
|
|||
$expected = array('admin');
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testGenerateUrl() {
|
||||
Configure::write('Routing.admin', 'admin');
|
||||
|
||||
// ADD (Passes)
|
||||
$this->router->reload();
|
||||
|
||||
$this->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', ), 'bare' => 0, 'webservices' => NULL, ),
|
||||
array ( 'plugin' => NULL, 'controller' => NULL, 'action' => NULL, 'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/', )
|
||||
));
|
||||
|
||||
$this->router->parse('/');
|
||||
|
||||
$result = $this->router->url(array ( 'plugin' => NULL, 'controller' => 'pages', 'action' => 'add', 'id' => false, ));
|
||||
$expected = '/admin/pages/add';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
|
||||
// EDIT (Fails)
|
||||
$this->router->reload();
|
||||
|
||||
$this->router->setRequestInfo(array(
|
||||
array ( 'plugin' => NULL, 'controller' => 'pages', 'action' => 'admin_edit', 'pass' => array ( 0 => '284', ), 'prefix' => 'admin', 'admin' => true, 'form' => array ( ), 'url' => array ( 'url' => 'admin/pages/edit/284', ), 'bare' => 0, 'webservices' => NULL, ),
|
||||
array ( 'plugin' => NULL, 'controller' => NULL, 'action' => NULL, 'base' => '', 'here' => '/admin/pages/edit/284', 'webroot' => '/', )
|
||||
));
|
||||
|
||||
$this->router->parse('/');
|
||||
|
||||
$result = $this->router->url(array ( 'plugin' => NULL, 'controller' => 'pages', 'action' => 'edit', 'id' => '284'));
|
||||
$expected = '/admin/pages/edit/284';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Reference in a new issue