From ed60939292d8626bdfa11e411e0d90dd6c1b4949 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 3 Apr 2010 23:32:14 -0400 Subject: [PATCH] Fixing tests that should have never worked, and removing additional calls to _restructureParams. Adding in prefixed plugin shortcuts as they were missing. --- cake/dispatcher.php | 11 +------ cake/libs/router.php | 7 +++-- cake/tests/cases/dispatcher.test.php | 46 +++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 4de05fc8fe7..efc554703a4 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -398,23 +398,14 @@ function _restructureParams($params, $reverse = false) { * @access private */ function &__getController() { - $original = $params = $this->params; - $controller = false; - $ctrlClass = $this->__loadController($params); + $ctrlClass = $this->__loadController($this->params); if (!$ctrlClass) { return $controller; } $name = $ctrlClass; $ctrlClass .= 'Controller'; if (class_exists($ctrlClass)) { - if ( - empty($params['plugin']) && - strtolower(get_parent_class($ctrlClass)) === strtolower($name . 'AppController') - ) { - $params = $this->_restructureParams($params); - } - $this->params = $params; $controller =& new $ctrlClass(); } return $controller; diff --git a/cake/libs/router.php b/cake/libs/router.php index f124b0d678c..85b268a9f15 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -560,15 +560,18 @@ function __connectDefaultRoutes() { foreach ($plugins as $key => $value) { $plugins[$key] = Inflector::underscore($value); } - $match = array('plugin' => implode('|', $plugins)); + $pluginPiped = implode('|', $plugins); + $match = array('plugin' => $pluginPiped); + $shortPlugin = array('plugin' => $pluginPiped, 'routeClass' => 'PluginShortRoute'); foreach ($this->__prefixes as $prefix) { $params = array('prefix' => $prefix, $prefix => true); $indexParams = $params + array('action' => 'index'); + $this->connect("/{$prefix}/:plugin", $indexParams, $shortPlugin); + $this->connect("/{$prefix}/:plugin/:action/*", $params, $shortPlugin); $this->connect("/{$prefix}/:plugin/:controller", $indexParams, $match); $this->connect("/{$prefix}/:plugin/:controller/:action/*", $params, $match); } - $shortPlugin = array_merge($match, array('routeClass' => 'PluginShortRoute')); $this->connect('/:plugin', array('action' => 'index'), $shortPlugin); $this->connect('/:plugin/:action/*', array(), $shortPlugin); $this->connect('/:plugin/:controller', array('action' => 'index'), $match); diff --git a/cake/tests/cases/dispatcher.test.php b/cake/tests/cases/dispatcher.test.php index 48c0c340f2a..ceaddcdefc9 100644 --- a/cake/tests/cases/dispatcher.test.php +++ b/cake/tests/cases/dispatcher.test.php @@ -340,6 +340,14 @@ class ArticlesTestController extends ArticlesTestAppController { function admin_index() { return true; } +/** + * fake index method. + * + * @return void + */ + function index() { + return true; + } } /** @@ -1423,7 +1431,10 @@ function testPluginDispatch() { Router::reload(); $Dispatcher =& new TestDispatcher(); - Router::connect('/my_plugin/:controller/*', array('plugin'=>'my_plugin', 'controller'=>'pages', 'action'=>'display')); + Router::connect( + '/my_plugin/:controller/*', + array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display') + ); $Dispatcher->base = false; $url = 'my_plugin/some_pages/home/param:value/param2:value2'; @@ -1472,7 +1483,10 @@ function testAutomaticPluginDispatch() { Router::reload(); $Dispatcher =& new TestDispatcher(); - Router::connect('/my_plugin/:controller/:action/*', array('plugin'=>'my_plugin', 'controller'=>'pages', 'action'=>'display')); + Router::connect( + '/my_plugin/:controller/:action/*', + array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display') + ); $Dispatcher->base = false; @@ -1508,6 +1522,13 @@ function testAutomaticPluginControllerDispatch() { $_POST = array(); $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; + $plugins = App::objects('plugin'); + $plugins[] = 'MyPlugin'; + $plugins[] = 'ArticlesTest'; + + $app = App::getInstance(); + $app->__objects['plugin'] = $plugins; + Router::reload(); $Dispatcher =& new TestDispatcher(); $Dispatcher->base = false; @@ -1526,7 +1547,7 @@ function testAutomaticPluginControllerDispatch() { $Dispatcher =& new TestDispatcher(); $Dispatcher->base = false; - /* Simulates the Route for a real plugin, installed in APP/plugins */ + // Simulates the Route for a real plugin, installed in APP/plugins Router::connect('/my_plugin/:controller/:action/*', array('plugin' => 'my_plugin')); $plugin = 'MyPlugin'; @@ -1550,6 +1571,12 @@ function testAutomaticPluginControllerDispatch() { $url = 'admin/my_plugin/add/5/param:value/param2:value2'; $controller = $Dispatcher->dispatch($url, array('return' => 1)); + + $this->assertEqual($controller->params['plugin'], 'my_plugin'); + $this->assertEqual($controller->params['controller'], 'my_plugin'); + $this->assertEqual($controller->params['action'], 'admin_add'); + $this->assertEqual($controller->params['pass'], array(5)); + $this->assertEqual($controller->params['named'], array('param' => 'value', 'param2' => 'value2')); $this->assertIdentical($controller->plugin, 'my_plugin'); $this->assertIdentical($controller->name, 'MyPlugin'); $this->assertIdentical($controller->action, 'admin_add'); @@ -1557,6 +1584,7 @@ function testAutomaticPluginControllerDispatch() { $expected = array(0 => 5, 'param'=>'value', 'param2'=>'value2'); $this->assertEqual($controller->passedArgs, $expected); + Configure::write('Routing.prefixes', array('admin')); Router::reload(); $Dispatcher =& new TestDispatcher(); @@ -1568,8 +1596,16 @@ function testAutomaticPluginControllerDispatch() { $this->assertIdentical($controller->action, 'admin_index'); $expected = array( - 'pass'=> array(), 'named' => array(), 'controller' => 'articles_test', 'plugin' => 'articles_test', 'action' => 'admin_index', - 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/articles_test'), 'return' => 1 + 'pass'=> array(), + 'named' => array(), + 'controller' => 'articles_test', + 'plugin' => 'articles_test', + 'action' => 'admin_index', + 'prefix' => 'admin', + 'admin' => true, + 'form' => array(), + 'url' => array('url' => 'admin/articles_test'), + 'return' => 1 ); $this->assertEqual($controller->params, $expected); }