From 95d44c36946d93a13bd639d4bc82c0fe65b97758 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 10 Mar 2011 03:54:20 +0530 Subject: [PATCH 1/5] Updating example code in comment to reflect renaming of Controller::$view to Controller::$viewClass. Closes #1579 --- cake/libs/view/media.php | 2 +- cake/libs/view/theme.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/libs/view/media.php b/cake/libs/view/media.php index 34b047aef..a2b9c1cff 100644 --- a/cake/libs/view/media.php +++ b/cake/libs/view/media.php @@ -38,7 +38,7 @@ App::import('View', 'View', false); * {{{ * class ExampleController extends AppController { * function download () { - * $this->view = 'Media'; + * $this->viewClass = 'Media'; * $params = array( * 'id' => 'example.zip', * 'name' => 'example', diff --git a/cake/libs/view/theme.php b/cake/libs/view/theme.php index 24e06e29b..544aacdc3 100644 --- a/cake/libs/view/theme.php +++ b/cake/libs/view/theme.php @@ -23,7 +23,7 @@ App::import('View', 'View'); * * Allows the creation of multiple themes to be used in an app. Theme views are regular view files * that can provide unique HTML and static assets. If theme views are not found for the current view - * the default app view files will be used. You can set `$this->theme` and `$this->view = 'Theme'` + * the default app view files will be used. You can set `$this->theme` and `$this->viewClass = 'Theme'` * in your Controller to use the ThemeView. * * Example of theme path with `$this->theme = 'super_hot';` Would be `app/views/themed/super_hot/posts` From 0cc55d8f45aa0ee1497d98b5086c2e4478615936 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 9 Mar 2011 22:27:19 -0500 Subject: [PATCH 2/5] Removing calls to Dispatcher::_stop(). Updating tests. Fixes #1578 --- cake/libs/dispatcher.php | 6 ++-- cake/tests/cases/libs/dispatcher.test.php | 35 +++++------------------ 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/cake/libs/dispatcher.php b/cake/libs/dispatcher.php index 387eac89c..c7cce1188 100644 --- a/cake/libs/dispatcher.php +++ b/cake/libs/dispatcher.php @@ -302,13 +302,13 @@ class Dispatcher { if (($isCss && empty($filters['css'])) || ($isJs && empty($filters['js']))) { $this->response->statusCode(404); $this->response->send(); - return $this->_stop(); + return true; } elseif ($isCss) { include WWW_ROOT . DS . $filters['css']; - $this->_stop(); + return true; } elseif ($isJs) { include WWW_ROOT . DS . $filters['js']; - $this->_stop(); + return true; } $controller = null; $pathSegments = explode('.', $url); diff --git a/cake/tests/cases/libs/dispatcher.test.php b/cake/tests/cases/libs/dispatcher.test.php index e7e3ae8b9..07823552a 100644 --- a/cake/tests/cases/libs/dispatcher.test.php +++ b/cake/tests/cases/libs/dispatcher.test.php @@ -59,15 +59,6 @@ class TestDispatcher extends Dispatcher { return $controller; } -/** - * _stop method - * - * @return void - */ - protected function _stop() { - $this->stopped = true; - return true; - } } /** @@ -1356,9 +1347,8 @@ class DispatcherTest extends CakeTestCase { )); ob_start(); - $Dispatcher->asset('ccss/cake.generic.css'); + $this->assertTrue($Dispatcher->asset('ccss/cake.generic.css')); $result = ob_get_clean(); - $this->assertTrue($Dispatcher->stopped); } /** @@ -1373,28 +1363,17 @@ class DispatcherTest extends CakeTestCase { 'js' => '', 'css' => '' )); - $Dispatcher->asset('theme/test_theme/ccss/cake.generic.css'); - $this->assertTrue($Dispatcher->stopped); + $this->assertTrue($Dispatcher->asset('theme/test_theme/ccss/cake.generic.css')); - $Dispatcher->stopped = false; - $Dispatcher->asset('theme/test_theme/cjs/debug_kit.js'); - $this->assertTrue($Dispatcher->stopped); + $this->assertTrue($Dispatcher->asset('theme/test_theme/cjs/debug_kit.js')); - $Dispatcher->stopped = false; - $Dispatcher->asset('test_plugin/ccss/cake.generic.css'); - $this->assertTrue($Dispatcher->stopped); + $this->assertTrue($Dispatcher->asset('test_plugin/ccss/cake.generic.css')); - $Dispatcher->stopped = false; - $Dispatcher->asset('test_plugin/cjs/debug_kit.js'); - $this->assertTrue($Dispatcher->stopped); + $this->assertTrue($Dispatcher->asset('test_plugin/cjs/debug_kit.js')); - $Dispatcher->stopped = false; - $Dispatcher->asset('css/ccss/debug_kit.css'); - $this->assertFalse($Dispatcher->stopped); + $this->assertFalse($Dispatcher->asset('css/ccss/debug_kit.css')); - $Dispatcher->stopped = false; - $Dispatcher->asset('js/cjs/debug_kit.js'); - $this->assertFalse($Dispatcher->stopped); + $this->assertFalse($Dispatcher->asset('js/cjs/debug_kit.js')); } /** * testFullPageCachingDispatch method From ab4ce97cad7812724f53577724f6f71c7bee3706 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 10 Mar 2011 22:00:08 -0500 Subject: [PATCH 3/5] Fixin CakeErrorController's constructor, so it matches the parent class. Removing duplicated code. --- cake/libs/controller/cake_error_controller.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cake/libs/controller/cake_error_controller.php b/cake/libs/controller/cake_error_controller.php index f55649672..7fd3b46f4 100644 --- a/cake/libs/controller/cake_error_controller.php +++ b/cake/libs/controller/cake_error_controller.php @@ -22,10 +22,8 @@ class CakeErrorController extends AppController { * @access public * @return void */ - function __construct() { - parent::__construct(); - $this->_set(Router::getPaths()); - $this->request = Router::getRequest(false); + function __construct($request = null) { + parent::__construct($request); $this->constructClasses(); $this->Components->trigger('initialize', array(&$this)); $this->_set(array('cacheAction' => false, 'viewPath' => 'errors')); From b292f4ffaa60483c71f66e8ae8de322101cd9eec Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 10 Mar 2011 22:01:23 -0500 Subject: [PATCH 4/5] Fixing tests that were failing due to missing methods, and changes in CakeRoute. Making ExceptionRenderer pass in the current request to the controller constructor. This fixes fatal errors on PrivateActionExceptions. --- cake/libs/error/exception_renderer.php | 4 ++-- .../cases/libs/controller/components/auth.test.php | 10 ++++++++++ .../tests/cases/libs/error/exception_renderer.test.php | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cake/libs/error/exception_renderer.php b/cake/libs/error/exception_renderer.php index 25adff3aa..328fffd8d 100644 --- a/cake/libs/error/exception_renderer.php +++ b/cake/libs/error/exception_renderer.php @@ -146,9 +146,9 @@ class ExceptionRenderer { if ($__previousError != $exception) { $__previousError = $exception; - $controller = new CakeErrorController(); + $controller = new CakeErrorController(Router::getRequest(false)); } else { - $controller = new Controller(); + $controller = new Controller(Router::getRequest(false)); $controller->viewPath = 'errors'; } return $controller; diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index 2c6701e93..fc32e2709 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -147,6 +147,15 @@ class AuthTestController extends Controller { function admin_login() { } +/** + * admin_add method + * + * @access public + * @return void + */ + function admin_add() { + } + /** * logout method * @@ -916,6 +925,7 @@ class AuthTest extends CakeTestCase { $this->Auth->request->addParams(Router::parse($url)); $this->Auth->request->query['url'] = ltrim($url, '/'); $this->Auth->request->base = ''; + Router::setRequestInfo($this->Auth->request); $this->Auth->initialize($this->Controller); diff --git a/cake/tests/cases/libs/error/exception_renderer.test.php b/cake/tests/cases/libs/error/exception_renderer.test.php index 1f0c0a150..b8a25ddfb 100644 --- a/cake/tests/cases/libs/error/exception_renderer.test.php +++ b/cake/tests/cases/libs/error/exception_renderer.test.php @@ -356,7 +356,7 @@ class ExceptionRendererTest extends CakeTestCase { $result = ob_get_clean(); $this->assertPattern('/

Custom message<\/h2>/', $result); - $this->assertPattern("/'\/posts\/view\/1000'<\/strong>/", $result); + $this->assertPattern("/'.*?\/posts\/view\/1000'<\/strong>/", $result); } /** From 7f18f05de4d5303f9ce137899ebbe8c49b9f6dd9 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 10 Mar 2011 22:04:46 -0500 Subject: [PATCH 5/5] Moving appending of prefix to action into the Router. This makes Router::parse() always return what you get in the controller. Updating Dispatcher to not hold a reference to the current request, as its not used. Updating private action detection so its simpler. Fixes issues with prefix actions not getting the correct default view. Fixes #1580 --- cake/libs/dispatcher.php | 24 ++++++------------------ cake/libs/router.php | 3 +++ cake/tests/cases/libs/router.test.php | 8 ++++++-- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/cake/libs/dispatcher.php b/cake/libs/dispatcher.php index c7cce1188..9d82935a8 100644 --- a/cake/libs/dispatcher.php +++ b/cake/libs/dispatcher.php @@ -37,14 +37,6 @@ App::import('Controller', 'Controller', false); */ class Dispatcher { -/** - * The request object - * - * @var CakeRequest - * @access public - */ - public $request = null; - /** * Response object used for asset/cached responses. * @@ -87,18 +79,16 @@ class Dispatcher { return; } - $this->request = $this->parseParams($request, $additionalParams); - $controller = $this->_getController($this->request); + $request = $this->parseParams($request, $additionalParams); + Router::setRequestInfo($request); + $controller = $this->_getController($request); - if (!is_object($controller)) { - Router::setRequestInfo($request); + if (!($controller instanceof Controller)) { throw new MissingControllerException(array( 'controller' => Inflector::camelize($request->params['controller']) . 'Controller' )); } - Router::setRequestInfo($request); - if ($this->_isPrivateAction($request)) { throw new PrivateActionException(array( 'controller' => Inflector::camelize($request->params['controller']) . "Controller", @@ -120,10 +110,8 @@ class Dispatcher { $privateAction = $request->params['action'][0] === '_'; $prefixes = Router::prefixes(); - if (!empty($prefixes)) { - if (isset($request->params['prefix'])) { - $request->params['action'] = $request->params['prefix'] . '_' . $request->params['action']; - } elseif (strpos($request->params['action'], '_') > 0) { + if (!$privateAction && !empty($prefixes)) { + if (empty($request->params['prefix']) && strpos($request->params['action'], '_') > 0) { list($prefix, $action) = explode('_', $request->params['action']); $privateAction = in_array($prefix, $prefixes); } diff --git a/cake/libs/router.php b/cake/libs/router.php index 08372f7c7..53f2da089 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -503,6 +503,9 @@ class Router { break; } } + if (isset($out['prefix'])) { + $out['action'] = $out['prefix'] . '_' . $out['action']; + } if (!empty($ext) && !isset($out['url']['ext'])) { $out['url']['ext'] = $ext; diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index 9a4ce30d7..682c9238c 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -1877,7 +1877,7 @@ class RouterTest extends CakeTestCase { ); $result = Router::parse('/admin/posts/'); - $expected = array('pass' => array(), 'named' => array(), 'prefix' => 'admin', 'plugin' => null, 'controller' => 'posts', 'action' => 'index', 'admin' => true); + $expected = array('pass' => array(), 'named' => array(), 'prefix' => 'admin', 'plugin' => null, 'controller' => 'posts', 'action' => 'admin_index', 'admin' => true); $this->assertEqual($result, $expected); $result = Router::parse('/admin/posts'); @@ -1911,7 +1911,7 @@ class RouterTest extends CakeTestCase { ); $result = Router::parse('/members/posts/index'); - $expected = array('pass' => array(), 'named' => array(), 'prefix' => 'members', 'plugin' => null, 'controller' => 'posts', 'action' => 'index', 'members' => true); + $expected = array('pass' => array(), 'named' => array(), 'prefix' => 'members', 'plugin' => null, 'controller' => 'posts', 'action' => 'members_index', 'members' => true); $this->assertEqual($result, $expected); $result = Router::url(array('members' => true, 'controller' => 'posts', 'action' =>'index', 'page' => 2)); @@ -1941,6 +1941,10 @@ class RouterTest extends CakeTestCase { $expected = '/company/users/login'; $this->assertEqual($result, $expected); + $result = Router::url(array('controller' => 'users', 'action' => 'company_login', 'company' => true)); + $expected = '/company/users/login'; + $this->assertEqual($result, $expected); + $request = new CakeRequest(); Router::setRequestInfo( $request->addParams(array(