From 9641bcc8dfa6a73312a39a3815219f648bbe1b23 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 3 Jul 2011 14:16:27 -0400 Subject: [PATCH 01/25] Modifying Dispatcher and its test cases to accept a CakeResponse as part of its arguments. --- lib/Cake/Controller/Controller.php | 11 +- lib/Cake/Routing/Dispatcher.php | 46 +++--- lib/Cake/Test/Case/Routing/DispatcherTest.php | 155 ++++++++++-------- 3 files changed, 117 insertions(+), 95 deletions(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index b89fd2608..66619a31e 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -291,10 +291,11 @@ class Controller extends Object { /** * Constructor. * - * @param CakeRequest $request Request object for this controller can be null for testing. - * But expect that features that use the params will not work. + * @param CakeRequest $request Request object for this controller. Can be null for testing, + * but expect that features that use the request parameters will not work. + * @param CakeResponse $response Response object for this controller. */ - public function __construct($request = null) { + public function __construct($request = null, $response = null) { if ($this->name === null) { $this->name = substr(get_class($this), 0, strlen(get_class($this)) -10); } @@ -315,7 +316,9 @@ class Controller extends Object { if ($request instanceof CakeRequest) { $this->setRequest($request); } - $this->getResponse(); + if ($response instanceof CakeResponse) { + $this->response = $response; + } parent::__construct(); } diff --git a/lib/Cake/Routing/Dispatcher.php b/lib/Cake/Routing/Dispatcher.php index 23c0ad207..6403465b1 100644 --- a/lib/Cake/Routing/Dispatcher.php +++ b/lib/Cake/Routing/Dispatcher.php @@ -72,19 +72,20 @@ class Dispatcher { * If the controller is found, and the action is not found an exception will be thrown. * * @param CakeRequest $request Request object to dispatch. + * @param CakeResponse $response Response object to put the results of the dispatch into. * @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params * @return boolean Success * @throws MissingControllerException, MissingActionException, PrivateActionException if any of those error states * are encountered. */ - public function dispatch(CakeRequest $request, $additionalParams = array()) { - if ($this->asset($request->url) || $this->cached($request->here)) { + public function dispatch(CakeRequest $request, CakeResponse $response, $additionalParams = array()) { + if ($this->asset($request->url, $response) || $this->cached($request->here)) { return; } $request = $this->parseParams($request, $additionalParams); Router::setRequestInfo($request); - $controller = $this->_getController($request); + $controller = $this->_getController($request, $response); if (!($controller instanceof Controller)) { throw new MissingControllerException(array( @@ -99,7 +100,7 @@ class Dispatcher { )); } - return $this->_invoke($controller, $request); + return $this->_invoke($controller, $request, $response); } /** @@ -133,7 +134,7 @@ class Dispatcher { * @return string Output as sent by controller * @throws MissingActionException when the action being called is missing. */ - protected function _invoke(Controller $controller, CakeRequest $request) { + protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response) { $controller->constructClasses(); $controller->startupProcess(); @@ -149,7 +150,6 @@ class Dispatcher { )); } $result = call_user_func_array(array(&$controller, $request->params['action']), $request->params['pass']); - $response = $controller->getResponse(); if ($controller->autoRender) { $controller->render(); @@ -192,15 +192,16 @@ class Dispatcher { /** * Get controller to use, either plugin controller or application controller * - * @param array $params Array of parameters + * @param CakeRequest $request Request object + * @param CakeResponse $response Response for the controller. * @return mixed name of controller if not loaded, or object if loaded */ - protected function _getController($request) { + protected function _getController($request, $response) { $ctrlClass = $this->_loadController($request); if (!$ctrlClass) { return false; } - return new $ctrlClass($request); + return new $ctrlClass($request, $response); } /** @@ -270,10 +271,11 @@ class Dispatcher { /** * Checks if a requested asset exists and sends it to the browser * - * @param $url string $url Requested URL + * @param string $url Requested URL + * @param CakeResponse $response The response object to put the file contents in. * @return boolean True on success if the asset file was found and sent */ - public function asset($url) { + public function asset($url, CakeResponse $response) { if (strpos($url, '..') !== false || strpos($url, '.') === false) { return false; } @@ -286,12 +288,9 @@ class Dispatcher { strpos($url, 'cjs/') === 0 || preg_match('#^/((theme/[^/]+)/cjs/)|(([^/]+)(?response) { - $this->response = new CakeResponse(); - } if (($isCss && empty($filters['css'])) || ($isJs && empty($filters['js']))) { - $this->response->statusCode(404); - $this->response->send(); + $response->statusCode(404); + $response->send(); return true; } elseif ($isCss) { include WWW_ROOT . DS . $filters['css']; @@ -326,7 +325,7 @@ class Dispatcher { } if ($assetFile !== null) { - $this->_deliverAsset($assetFile, $ext); + $this->_deliverAsset($response, $assetFile, $ext); return true; } return false; @@ -335,23 +334,24 @@ class Dispatcher { /** * Sends an asset file to the client * + * @param CakeResponse $response The response object to use. * @param string $assetFile Path to the asset file in the file system * @param string $ext The extension of the file to determine its mime type * @return void */ - protected function _deliverAsset($assetFile, $ext) { + protected function _deliverAsset(CakeResponse $response, $assetFile, $ext) { ob_start(); - $compressionEnabled = Configure::read('Asset.compress') && $this->response->compress(); - if ($this->response->type($ext) == $ext) { + $compressionEnabled = Configure::read('Asset.compress') && $response->compress(); + if ($response->type($ext) == $ext) { $contentType = 'application/octet-stream'; $agent = env('HTTP_USER_AGENT'); if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) { $contentType = 'application/octetstream'; } - $this->response->type($contentType); + $response->type($contentType); } - $this->response->cache(filemtime($assetFile)); - $this->response->send(); + $response->cache(filemtime($assetFile)); + $response->send(); ob_clean(); if ($ext === 'css' || $ext === 'js') { include($assetFile); diff --git a/lib/Cake/Test/Case/Routing/DispatcherTest.php b/lib/Cake/Test/Case/Routing/DispatcherTest.php index e5a4bd21b..b05724644 100644 --- a/lib/Cake/Test/Case/Routing/DispatcherTest.php +++ b/lib/Cake/Test/Case/Routing/DispatcherTest.php @@ -17,7 +17,6 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ App::uses('Dispatcher', 'Routing'); -App::uses('CakeResponse', 'Network'); if (!class_exists('AppController', false)) { require_once CAKE . 'Controller' . DS . 'AppController.php'; @@ -50,8 +49,8 @@ class TestDispatcher extends Dispatcher { * @param mixed $request * @return void */ - protected function _invoke(Controller $controller, CakeRequest $request) { - if ($result = parent::_invoke($controller, $request)) { + protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response) { + if ($result = parent::_invoke($controller, $request, $response)) { if ($result[0] === 'missingAction') { return $result; } @@ -695,7 +694,8 @@ class DispatcherTest extends CakeTestCase { $Dispatcher = new TestDispatcher(); Configure::write('App.baseUrl', '/index.php'); $url = new CakeRequest('some_controller/home/param:value/param2:value2'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $response = $this->getMock('CakeResponse'); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->fail('No exception thrown'); } catch (MissingControllerException $e) { $this->assertEquals('Controller class SomeControllerController could not be found.', $e->getMessage()); @@ -711,9 +711,10 @@ class DispatcherTest extends CakeTestCase { $Dispatcher = new TestDispatcher(); Configure::write('App.baseUrl','/index.php'); $url = new CakeRequest('some_pages/_protected/param:value/param2:value2'); + $response = $this->getMock('CakeResponse'); try { - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->fail('No exception thrown'); } catch (PrivateActionException $e) { $this->assertEquals( @@ -731,9 +732,10 @@ class DispatcherTest extends CakeTestCase { $Dispatcher = new TestDispatcher(); Configure::write('App.baseUrl', '/index.php'); $url = new CakeRequest('some_pages/home/param:value/param2:value2'); + $response = $this->getMock('CakeResponse'); try { - $controller = $Dispatcher->dispatch($url, array('return'=> 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); $this->fail('No exception thrown'); } catch (MissingActionException $e) { $this->assertEquals('Action SomePagesController::home() could not be found.', $e->getMessage()); @@ -749,9 +751,10 @@ class DispatcherTest extends CakeTestCase { $Dispatcher = new TestDispatcher(); Configure::write('App.baseUrl','/index.php'); $url = new CakeRequest('some_pages/redirect/param:value/param2:value2'); + $response = $this->getMock('CakeResponse'); try { - $controller = $Dispatcher->dispatch($url, array('return'=> 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); $this->fail('No exception thrown'); } catch (MissingActionException $e) { $this->assertEquals('Action SomePagesController::redirect() could not be found.', $e->getMessage()); @@ -770,8 +773,9 @@ class DispatcherTest extends CakeTestCase { $Dispatcher = new TestDispatcher(); Configure::write('App.baseUrl', '/index.php'); $url = new CakeRequest('pages/home/param:value/param2:value2'); + $response = $this->getMock('CakeResponse'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $expected = 'Pages'; $this->assertEqual($expected, $controller->name); @@ -781,13 +785,13 @@ class DispatcherTest extends CakeTestCase { Configure::write('App.baseUrl','/pages/index.php'); $url = new CakeRequest('pages/home'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $expected = 'Pages'; $this->assertEqual($expected, $controller->name); $url = new CakeRequest('pages/home/'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->assertNull($controller->plugin); $expected = 'Pages'; @@ -799,23 +803,23 @@ class DispatcherTest extends CakeTestCase { Configure::write('App.baseUrl', '/timesheets/index.php'); $url = new CakeRequest('timesheets'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $expected = 'Timesheets'; $this->assertEqual($expected, $controller->name); $url = new CakeRequest('timesheets/'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->assertEqual('Timesheets', $controller->name); $this->assertEqual('/timesheets/index.php', $url->base); $url = new CakeRequest('test_dispatch_pages/camelCased'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->assertEqual('TestDispatchPages', $controller->name); $url = new CakeRequest('test_dispatch_pages/camelCased/something. .'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->assertEqual($controller->params['pass'][0], 'something. .', 'Period was chopped off. %s'); } @@ -830,9 +834,10 @@ class DispatcherTest extends CakeTestCase { Configure::write('Routing.prefixes', array('admin')); Configure::write('App.baseUrl','/cake/repo/branches/1.2.x.x/index.php'); $url = new CakeRequest('admin/test_dispatch_pages/index/param:value/param2:value2'); + $response = $this->getMock('CakeResponse'); Router::reload(); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->assertEqual($controller->name, 'TestDispatchPages'); @@ -862,7 +867,8 @@ class DispatcherTest extends CakeTestCase { ); $url = new CakeRequest('my_plugin/some_pages/home/param:value/param2:value2'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $response = $this->getMock('CakeResponse'); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $result = $Dispatcher->parseParams($url); $expected = array( @@ -899,7 +905,8 @@ class DispatcherTest extends CakeTestCase { $Dispatcher->base = false; $url = new CakeRequest('my_plugin/other_pages/index/param:value/param2:value2'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $response = $this->getMock('CakeResponse'); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->assertIdentical($controller->plugin, 'MyPlugin'); $this->assertIdentical($controller->name, 'OtherPages'); @@ -907,10 +914,10 @@ class DispatcherTest extends CakeTestCase { $this->assertIdentical($controller->passedArgs, array('param' => 'value', 'param2' => 'value2')); $expected = '/cake/repo/branches/1.2.x.x/my_plugin/other_pages/index/param:value/param2:value2'; - $this->assertIdentical($expected, $controller->here); + $this->assertIdentical($expected, $url->here); $expected = '/cake/repo/branches/1.2.x.x'; - $this->assertIdentical($expected, $controller->base); + $this->assertIdentical($expected, $url->base); } /** @@ -933,8 +940,9 @@ class DispatcherTest extends CakeTestCase { $Dispatcher->base = false; $url = new CakeRequest('my_plugin/my_plugin/add/param:value/param2:value2'); + $response = $this->getMock('CakeResponse'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->assertIdentical($controller->plugin, 'MyPlugin'); $this->assertIdentical($controller->name, 'MyPlugin'); @@ -953,7 +961,7 @@ class DispatcherTest extends CakeTestCase { $pluginUrl = Inflector::underscore($plugin); $url = new CakeRequest($pluginUrl); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->assertIdentical($controller->plugin, 'MyPlugin'); $this->assertIdentical($controller->name, 'MyPlugin'); $this->assertIdentical($controller->action, 'index'); @@ -968,7 +976,9 @@ class DispatcherTest extends CakeTestCase { $Dispatcher = new TestDispatcher(); $url = new CakeRequest('admin/my_plugin/my_plugin/add/5/param:value/param2:value2'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $response = $this->getMock('CakeResponse'); + + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->assertEqual($controller->params['plugin'], 'my_plugin'); $this->assertEqual($controller->params['controller'], 'my_plugin'); @@ -988,7 +998,7 @@ class DispatcherTest extends CakeTestCase { $Dispatcher = new TestDispatcher(); - $controller = $Dispatcher->dispatch(new CakeRequest('admin/articles_test'), array('return' => 1)); + $controller = $Dispatcher->dispatch(new CakeRequest('admin/articles_test'), $response, array('return' => 1)); $this->assertIdentical($controller->plugin, 'ArticlesTest'); $this->assertIdentical($controller->name, 'ArticlesTest'); $this->assertIdentical($controller->action, 'admin_index'); @@ -1022,7 +1032,9 @@ class DispatcherTest extends CakeTestCase { $Dispatcher->base = false; $url = new CakeRequest('my_plugin/'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $response = $this->getMock('CakeResponse'); + + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->assertEqual($controller->params['controller'], 'my_plugin'); $this->assertEqual($controller->params['plugin'], 'my_plugin'); $this->assertEqual($controller->params['action'], 'index'); @@ -1049,21 +1061,23 @@ class DispatcherTest extends CakeTestCase { $Dispatcher->base = false; $url = new CakeRequest('test_plugin/'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $response = $this->getMock('CakeResponse'); + + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->assertEqual($controller->params['controller'], 'test_plugin'); $this->assertEqual($controller->params['plugin'], 'test_plugin'); $this->assertEqual($controller->params['action'], 'index'); $this->assertFalse(isset($controller->params['pass'][0])); $url = new CakeRequest('/test_plugin/tests/index'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->assertEqual($controller->params['controller'], 'tests'); $this->assertEqual($controller->params['plugin'], 'test_plugin'); $this->assertEqual($controller->params['action'], 'index'); $this->assertFalse(isset($controller->params['pass'][0])); $url = new CakeRequest('/test_plugin/tests/index/some_param'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->assertEqual($controller->params['controller'], 'tests'); $this->assertEqual($controller->params['plugin'], 'test_plugin'); $this->assertEqual($controller->params['action'], 'index'); @@ -1086,9 +1100,10 @@ class DispatcherTest extends CakeTestCase { $Dispatcher->base = false; $url = new CakeRequest('my_plugin/not_here/param:value/param2:value2'); + $response = $this->getMock('CakeResponse'); try { - $controller = $Dispatcher->dispatch($url, array('return'=> 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); $this->fail('No exception.'); } catch (MissingActionException $e) { $this->assertEquals('Action MyPluginController::not_here() could not be found.', $e->getMessage()); @@ -1100,7 +1115,7 @@ class DispatcherTest extends CakeTestCase { $url = new CakeRequest('my_plugin/param:value/param2:value2'); try { - $controller = $Dispatcher->dispatch($url, array('return'=> 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); $this->fail('No exception.'); } catch (MissingActionException $e) { $this->assertEquals('Action MyPluginController::param:value() could not be found.', $e->getMessage()); @@ -1122,8 +1137,9 @@ class DispatcherTest extends CakeTestCase { $Dispatcher = new TestDispatcher(); $url = new CakeRequest('test_dispatch_pages/admin_index/param:value/param2:value2'); + $response = $this->getMock('CakeResponse'); try { - $controller = $Dispatcher->dispatch($url, array('return'=> 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); $this->fail('No exception.'); } catch (PrivateActionException $e) { $this->assertEquals( @@ -1148,7 +1164,8 @@ class DispatcherTest extends CakeTestCase { Router::parse('/'); $url = new CakeRequest('/test_plugin/tests/index'); - $result = $Dispatcher->dispatch($url, array('return' => 1)); + $response = $this->getMock('CakeResponse'); + $result = $Dispatcher->dispatch($url, $response, array('return' => 1)); $this->assertTrue(class_exists('TestsController')); $this->assertTrue(class_exists('TestPluginAppController')); $this->assertTrue(class_exists('PluginsComponentComponent')); @@ -1168,17 +1185,18 @@ class DispatcherTest extends CakeTestCase { public function testChangingParamsFromBeforeFilter() { $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; $Dispatcher = new TestDispatcher(); + $response = $this->getMock('CakeResponse'); $url = new CakeRequest('some_posts/index/param:value/param2:value2'); try { - $controller = $Dispatcher->dispatch($url, array('return'=> 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); $this->fail('No exception.'); } catch (MissingActionException $e) { $this->assertEquals('Action SomePostsController::view() could not be found.', $e->getMessage()); } $url = new CakeRequest('some_posts/something_else/param:value/param2:value2'); - $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); $expected = 'SomePosts'; $this->assertEqual($expected, $controller->name); @@ -1206,24 +1224,24 @@ class DispatcherTest extends CakeTestCase { CakePlugin::loadAll(); $Dispatcher = new TestDispatcher(); - $Dispatcher->response = $this->getMock('CakeResponse', array('_sendHeader')); + $response = $this->getMock('CakeResponse', array('_sendHeader')); try { - $Dispatcher->dispatch(new CakeRequest('theme/test_theme/../webroot/css/test_asset.css')); + $Dispatcher->dispatch(new CakeRequest('theme/test_theme/../webroot/css/test_asset.css'), $response); $this->fail('No exception'); } catch (MissingControllerException $e) { $this->assertEquals('Controller class ThemeController could not be found.', $e->getMessage()); } try { - $Dispatcher->dispatch(new CakeRequest('theme/test_theme/pdfs')); + $Dispatcher->dispatch(new CakeRequest('theme/test_theme/pdfs'), $response); $this->fail('No exception'); } catch (MissingControllerException $e) { $this->assertEquals('Controller class ThemeController could not be found.', $e->getMessage()); } ob_start(); - $Dispatcher->dispatch(new CakeRequest('theme/test_theme/flash/theme_test.swf')); + $Dispatcher->dispatch(new CakeRequest('theme/test_theme/flash/theme_test.swf'), $response); $result = ob_get_clean(); $file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'webroot' . DS . 'flash' . DS . 'theme_test.swf'); @@ -1231,93 +1249,93 @@ class DispatcherTest extends CakeTestCase { $this->assertEqual('this is just a test to load swf file from the theme.', $result); ob_start(); - $Dispatcher->dispatch(new CakeRequest('theme/test_theme/pdfs/theme_test.pdf')); + $Dispatcher->dispatch(new CakeRequest('theme/test_theme/pdfs/theme_test.pdf'), $response); $result = ob_get_clean(); $file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'webroot' . DS . 'pdfs' . DS . 'theme_test.pdf'); $this->assertEqual($file, $result); $this->assertEqual('this is just a test to load pdf file from the theme.', $result); ob_start(); - $Dispatcher->dispatch(new CakeRequest('theme/test_theme/img/test.jpg')); + $Dispatcher->dispatch(new CakeRequest('theme/test_theme/img/test.jpg'), $response); $result = ob_get_clean(); $file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'webroot' . DS . 'img' . DS . 'test.jpg'); $this->assertEqual($file, $result); ob_start(); - $Dispatcher->asset('theme/test_theme/css/test_asset.css'); + $Dispatcher->asset('theme/test_theme/css/test_asset.css', $response); $result = ob_get_clean(); $this->assertEqual('this is the test asset css file', $result); ob_start(); - $Dispatcher->asset('theme/test_theme/js/theme.js'); + $Dispatcher->asset('theme/test_theme/js/theme.js', $response); $result = ob_get_clean(); $this->assertEqual('root theme js file', $result); ob_start(); - $Dispatcher->asset('theme/test_theme/js/one/theme_one.js'); + $Dispatcher->asset('theme/test_theme/js/one/theme_one.js', $response); $result = ob_get_clean(); $this->assertEqual('nested theme js file', $result); ob_start(); - $Dispatcher->asset('test_plugin/root.js'); + $Dispatcher->asset('test_plugin/root.js', $response); $result = ob_get_clean(); $expected = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'webroot' . DS . 'root.js'); $this->assertEqual($expected, $result); ob_start(); - $Dispatcher->dispatch(new CakeRequest('test_plugin/flash/plugin_test.swf')); + $Dispatcher->dispatch(new CakeRequest('test_plugin/flash/plugin_test.swf'), $response); $result = ob_get_clean(); $file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'webroot' . DS . 'flash' . DS . 'plugin_test.swf'); $this->assertEqual($file, $result); $this->assertEqual('this is just a test to load swf file from the plugin.', $result); ob_start(); - $Dispatcher->dispatch(new CakeRequest('test_plugin/pdfs/plugin_test.pdf')); + $Dispatcher->dispatch(new CakeRequest('test_plugin/pdfs/plugin_test.pdf'), $response); $result = ob_get_clean(); $file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'webroot' . DS . 'pdfs' . DS . 'plugin_test.pdf'); $this->assertEqual($file, $result); $this->assertEqual('this is just a test to load pdf file from the plugin.', $result); ob_start(); - $Dispatcher->asset('test_plugin/js/test_plugin/test.js'); + $Dispatcher->asset('test_plugin/js/test_plugin/test.js', $response); $result = ob_get_clean(); $this->assertEqual('alert("Test App");', $result); ob_start(); - $Dispatcher->asset('test_plugin/js/test_plugin/test.js'); + $Dispatcher->asset('test_plugin/js/test_plugin/test.js', $response); $result = ob_get_clean(); $this->assertEqual('alert("Test App");', $result); ob_start(); - $Dispatcher->asset('test_plugin/css/test_plugin_asset.css'); + $Dispatcher->asset('test_plugin/css/test_plugin_asset.css', $response); $result = ob_get_clean(); $this->assertEqual('this is the test plugin asset css file', $result); ob_start(); - $Dispatcher->asset('test_plugin/img/cake.icon.gif'); + $Dispatcher->asset('test_plugin/img/cake.icon.gif', $response); $result = ob_get_clean(); $file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' .DS . 'webroot' . DS . 'img' . DS . 'cake.icon.gif'); $this->assertEqual($file, $result); ob_start(); - $Dispatcher->asset('plugin_js/js/plugin_js.js'); + $Dispatcher->asset('plugin_js/js/plugin_js.js', $response); $result = ob_get_clean(); $expected = "alert('win sauce');"; $this->assertEqual($expected, $result); ob_start(); - $Dispatcher->asset('plugin_js/js/one/plugin_one.js'); + $Dispatcher->asset('plugin_js/js/one/plugin_one.js', $response); $result = ob_get_clean(); $expected = "alert('plugin one nested js file');"; $this->assertEqual($expected, $result); ob_start(); - $Dispatcher->asset('test_plugin/css/unknown.extension'); + $Dispatcher->asset('test_plugin/css/unknown.extension', $response); $result = ob_get_clean(); $this->assertEqual('Testing a file with unknown extension to mime mapping.', $result); ob_start(); - $Dispatcher->asset('test_plugin/css/theme_one.htc'); + $Dispatcher->asset('test_plugin/css/theme_one.htc', $response); $result = ob_get_clean(); $this->assertEqual('htc file', $result); @@ -1334,15 +1352,15 @@ class DispatcherTest extends CakeTestCase { * @return void */ public function testMissingAssetProcessor404() { + $response = $this->getMock('CakeResponse', array('_sendHeader')); $Dispatcher = new TestDispatcher(); - $Dispatcher->response = $this->getMock('CakeResponse', array('_sendHeader')); Configure::write('Asset.filter', array( 'js' => '', 'css' => null )); ob_start(); - $this->assertTrue($Dispatcher->asset('ccss/cake.generic.css')); + $this->assertTrue($Dispatcher->asset('ccss/cake.generic.css', $response)); $result = ob_get_clean(); } @@ -1353,22 +1371,22 @@ class DispatcherTest extends CakeTestCase { */ public function testAssetFilterForThemeAndPlugins() { $Dispatcher = new TestDispatcher(); - $Dispatcher->response = $this->getMock('CakeResponse', array('_sendHeader')); + $response = $this->getMock('CakeResponse', array('_sendHeader')); Configure::write('Asset.filter', array( 'js' => '', 'css' => '' )); - $this->assertTrue($Dispatcher->asset('theme/test_theme/ccss/cake.generic.css')); + $this->assertTrue($Dispatcher->asset('theme/test_theme/ccss/cake.generic.css', $response)); - $this->assertTrue($Dispatcher->asset('theme/test_theme/cjs/debug_kit.js')); + $this->assertTrue($Dispatcher->asset('theme/test_theme/cjs/debug_kit.js', $response)); - $this->assertTrue($Dispatcher->asset('test_plugin/ccss/cake.generic.css')); + $this->assertTrue($Dispatcher->asset('test_plugin/ccss/cake.generic.css', $response)); - $this->assertTrue($Dispatcher->asset('test_plugin/cjs/debug_kit.js')); + $this->assertTrue($Dispatcher->asset('test_plugin/cjs/debug_kit.js', $response)); - $this->assertFalse($Dispatcher->asset('css/ccss/debug_kit.css')); + $this->assertFalse($Dispatcher->asset('css/ccss/debug_kit.css', $response)); - $this->assertFalse($Dispatcher->asset('js/cjs/debug_kit.js')); + $this->assertFalse($Dispatcher->asset('js/cjs/debug_kit.js', $response)); } /** * testFullPageCachingDispatch method @@ -1392,9 +1410,10 @@ class DispatcherTest extends CakeTestCase { $dispatcher = new TestDispatcher(); $request = new CakeRequest('/'); + $response = new CakeResponse(); ob_start(); - $dispatcher->dispatch($request); + $dispatcher->dispatch($request, $response); $out = ob_get_clean(); ob_start(); @@ -1416,7 +1435,7 @@ class DispatcherTest extends CakeTestCase { ); ob_start(); - $dispatcher->dispatch($request); + $dispatcher->dispatch($request, $response); $out = ob_get_clean(); ob_start(); @@ -1434,7 +1453,7 @@ class DispatcherTest extends CakeTestCase { $request = new CakeRequest('TestCachedPages/index'); ob_start(); - $dispatcher->dispatch($request); + $dispatcher->dispatch($request, $response); $out = ob_get_clean(); ob_start(); @@ -1452,7 +1471,7 @@ class DispatcherTest extends CakeTestCase { $request = new CakeRequest('TestCachedPages/test_nocache_tags'); ob_start(); - $dispatcher->dispatch($request); + $dispatcher->dispatch($request, $response); $out = ob_get_clean(); ob_start(); @@ -1470,7 +1489,7 @@ class DispatcherTest extends CakeTestCase { $request = new CakeRequest('test_cached_pages/view/param/param'); ob_start(); - $dispatcher->dispatch($request); + $dispatcher->dispatch($request, $response); $out = ob_get_clean(); ob_start(); @@ -1488,7 +1507,7 @@ class DispatcherTest extends CakeTestCase { $request = new CakeRequest('test_cached_pages/view/foo:bar/value:goo'); ob_start(); - $dispatcher->dispatch($request); + $dispatcher->dispatch($request, $response); $out = ob_get_clean(); ob_start(); From 5240edeb827b81864a379320578d4bdc7e9d8def Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 3 Jul 2011 14:34:33 -0400 Subject: [PATCH 02/25] Refactoring tests to better use PHPUnit's features Removing non-functional cruft. --- lib/Cake/Test/Case/Routing/DispatcherTest.php | 102 +++++++----------- 1 file changed, 37 insertions(+), 65 deletions(-) diff --git a/lib/Cake/Test/Case/Routing/DispatcherTest.php b/lib/Cake/Test/Case/Routing/DispatcherTest.php index b05724644..a7c7ae527 100644 --- a/lib/Cake/Test/Case/Routing/DispatcherTest.php +++ b/lib/Cake/Test/Case/Routing/DispatcherTest.php @@ -687,24 +687,24 @@ class DispatcherTest extends CakeTestCase { /** * testMissingController method * + * @expectedException MissingControllerException + * @expectedExceptionMessage Controller class SomeControllerController could not be found. * @return void */ public function testMissingController() { - try { - $Dispatcher = new TestDispatcher(); - Configure::write('App.baseUrl', '/index.php'); - $url = new CakeRequest('some_controller/home/param:value/param2:value2'); - $response = $this->getMock('CakeResponse'); - $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); - $this->fail('No exception thrown'); - } catch (MissingControllerException $e) { - $this->assertEquals('Controller class SomeControllerController could not be found.', $e->getMessage()); - } + $Dispatcher = new TestDispatcher(); + Configure::write('App.baseUrl', '/index.php'); + $url = new CakeRequest('some_controller/home/param:value/param2:value2'); + $response = $this->getMock('CakeResponse'); + + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); } /** * testPrivate method * + * @expectedException PrivateActionException + * @expectedExceptionMessage Private Action SomePagesController::_protected() is not directly accessible. * @return void */ public function testPrivate() { @@ -713,19 +713,14 @@ class DispatcherTest extends CakeTestCase { $url = new CakeRequest('some_pages/_protected/param:value/param2:value2'); $response = $this->getMock('CakeResponse'); - try { - $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); - $this->fail('No exception thrown'); - } catch (PrivateActionException $e) { - $this->assertEquals( - 'Private Action SomePagesController::_protected() is not directly accessible.', $e->getMessage() - ); - } + $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); } /** * testMissingAction method * + * @expectedException MissingActionException + * @expectedExceptionMessage Action SomePagesController::home() could not be found. * @return void */ public function testMissingAction() { @@ -734,17 +729,14 @@ class DispatcherTest extends CakeTestCase { $url = new CakeRequest('some_pages/home/param:value/param2:value2'); $response = $this->getMock('CakeResponse'); - try { - $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); - $this->fail('No exception thrown'); - } catch (MissingActionException $e) { - $this->assertEquals('Action SomePagesController::home() could not be found.', $e->getMessage()); - } + $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); } /** * test that methods declared in Controller are treated as missing methods. * + * @expectedException MissingActionException + * @expectedExceptionMessage Action SomePagesController::redirect() could not be found. * @return void */ public function testMissingActionFromBaseClassMethods() { @@ -753,12 +745,7 @@ class DispatcherTest extends CakeTestCase { $url = new CakeRequest('some_pages/redirect/param:value/param2:value2'); $response = $this->getMock('CakeResponse'); - try { - $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); - $this->fail('No exception thrown'); - } catch (MissingActionException $e) { - $this->assertEquals('Action SomePagesController::redirect() could not be found.', $e->getMessage()); - } + $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); } /** @@ -926,9 +913,6 @@ class DispatcherTest extends CakeTestCase { * @return void */ public function testAutomaticPluginControllerDispatch() { - $_POST = array(); - $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; - $plugins = App::objects('plugin'); $plugins[] = 'MyPlugin'; $plugins[] = 'ArticlesTest'; @@ -1089,48 +1073,46 @@ class DispatcherTest extends CakeTestCase { /** * testAutomaticPluginControllerMissingActionDispatch method * + * @expectedException MissingActionException + * @expectedExceptionMessage Action MyPluginController::not_here() could not be found. * @return void */ public function testAutomaticPluginControllerMissingActionDispatch() { - $_POST = array(); - $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; - Router::reload(); $Dispatcher = new TestDispatcher(); - $Dispatcher->base = false; $url = new CakeRequest('my_plugin/not_here/param:value/param2:value2'); $response = $this->getMock('CakeResponse'); - try { - $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); - $this->fail('No exception.'); - } catch (MissingActionException $e) { - $this->assertEquals('Action MyPluginController::not_here() could not be found.', $e->getMessage()); - } + $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); + } +/** + * testAutomaticPluginControllerMissingActionDispatch method + * + * @expectedException MissingActionException + * @expectedExceptionMessage Action MyPluginController::param:value() could not be found. + * @return void + */ + + public function testAutomaticPluginControllerIndexMissingAction() { Router::reload(); $Dispatcher = new TestDispatcher(); - $Dispatcher->base = false; $url = new CakeRequest('my_plugin/param:value/param2:value2'); - try { - $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); - $this->fail('No exception.'); - } catch (MissingActionException $e) { - $this->assertEquals('Action MyPluginController::param:value() could not be found.', $e->getMessage()); - } + $response = $this->getMock('CakeResponse'); + + $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); } /** * testPrefixProtection method * + * @expectedException PrivateActionException + * @expectedExceptionMessage Private Action TestDispatchPagesController::admin_index() is not directly accessible. * @return void */ public function testPrefixProtection() { - $_POST = array(); - $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; - Router::reload(); Router::connect('/admin/:controller/:action/*', array('prefix'=>'admin'), array('controller', 'action')); @@ -1138,15 +1120,8 @@ class DispatcherTest extends CakeTestCase { $url = new CakeRequest('test_dispatch_pages/admin_index/param:value/param2:value2'); $response = $this->getMock('CakeResponse'); - try { - $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); - $this->fail('No exception.'); - } catch (PrivateActionException $e) { - $this->assertEquals( - 'Private Action TestDispatchPagesController::admin_index() is not directly accessible.', - $e->getMessage() - ); - } + + $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); } /** @@ -1183,7 +1158,6 @@ class DispatcherTest extends CakeTestCase { * @return void */ public function testChangingParamsFromBeforeFilter() { - $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; $Dispatcher = new TestDispatcher(); $response = $this->getMock('CakeResponse'); $url = new CakeRequest('some_posts/index/param:value/param2:value2'); @@ -1398,8 +1372,6 @@ class DispatcherTest extends CakeTestCase { Configure::write('Cache.check', true); Configure::write('debug', 2); - $_POST = array(); - $_SERVER['PHP_SELF'] = '/'; Router::reload(); Router::connect('/', array('controller' => 'test_cached_pages', 'action' => 'index')); From ec40ce6aadbbea51daa5ec0a15decb096c664a09 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 3 Jul 2011 14:35:54 -0400 Subject: [PATCH 03/25] Updating index.php and skel dir for response change. --- app/webroot/index.php | 3 ++- lib/Cake/Console/Templates/skel/webroot/index.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/webroot/index.php b/app/webroot/index.php index 3a719c5a1..8f84d1883 100644 --- a/app/webroot/index.php +++ b/app/webroot/index.php @@ -76,5 +76,6 @@ } App::uses('Dispatcher', 'Routing'); + $Dispatcher = new Dispatcher(); - $Dispatcher->dispatch(new CakeRequest()); + $Dispatcher->dispatch(new CakeRequest(), new CakeResponse()); diff --git a/lib/Cake/Console/Templates/skel/webroot/index.php b/lib/Cake/Console/Templates/skel/webroot/index.php index 3a719c5a1..f77a92665 100644 --- a/lib/Cake/Console/Templates/skel/webroot/index.php +++ b/lib/Cake/Console/Templates/skel/webroot/index.php @@ -77,4 +77,4 @@ App::uses('Dispatcher', 'Routing'); $Dispatcher = new Dispatcher(); - $Dispatcher->dispatch(new CakeRequest()); + $Dispatcher->dispatch(new CakeRequest(), new CakeResponse()); From fc08784c22c4a104595671a51dfb215a5856c7ba Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 3 Jul 2011 14:51:58 -0400 Subject: [PATCH 04/25] Making Controller tests pass. --- .../Test/Case/Controller/ControllerTest.php | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/Cake/Test/Case/Controller/ControllerTest.php b/lib/Cake/Test/Case/Controller/ControllerTest.php index af63cf88c..185ea5252 100644 --- a/lib/Cake/Test/Case/Controller/ControllerTest.php +++ b/lib/Cake/Test/Case/Controller/ControllerTest.php @@ -418,7 +418,8 @@ class ControllerTest extends CakeTestCase { */ public function testLoadModel() { $request = new CakeRequest('controller_posts/index'); - $Controller = new Controller($request); + $response = $this->getMock('CakeResponse'); + $Controller = new Controller($request, $response); $this->assertFalse(isset($Controller->ControllerPost)); @@ -617,7 +618,7 @@ class ControllerTest extends CakeTestCase { $request = new CakeRequest('controller_posts/index'); $request->params['action'] = 'index'; - $Controller = new Controller($request, $this->getMock('CakeResponse')); + $Controller = new Controller($request, new CakeResponse()); $Controller->viewPath = 'Posts'; $result = $Controller->render('index'); @@ -631,7 +632,7 @@ class ControllerTest extends CakeTestCase { $this->assertPattern('/this is the test element/', $result); $Controller->view = null; - $Controller = new TestController($request); + $Controller = new TestController($request, new CakeResponse()); $Controller->helpers = array('Html'); $Controller->constructClasses(); $Controller->ControllerComment->validationErrors = array('title' => 'tooShort'); @@ -668,7 +669,7 @@ class ControllerTest extends CakeTestCase { CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS ) ), true); - $Controller = new Controller($this->getMock('CakeRequest')); + $Controller = new Controller($this->getMock('CakeRequest'), new CakeResponse()); $Controller->uses = array(); $Controller->components = array('Test'); $Controller->constructClasses(); @@ -689,7 +690,7 @@ class ControllerTest extends CakeTestCase { public function testToBeInheritedGuardmethods() { $request = new CakeRequest('controller_posts/index'); - $Controller = new Controller($request); + $Controller = new Controller($request, $this->getMock('CakeResponse')); $this->assertTrue($Controller->_beforeScaffold('')); $this->assertTrue($Controller->_afterScaffoldSave('')); $this->assertTrue($Controller->_afterScaffoldSaveError('')); @@ -1119,7 +1120,7 @@ class ControllerTest extends CakeTestCase { $request = new CakeRequest('controller_posts/index'); - $Controller = new Controller($request); + $Controller = new Controller($request, $this->getMock('CakeResponse')); $Controller->components = array("RequestHandler"); $Controller->modelClass='ControllerPost'; @@ -1140,8 +1141,8 @@ class ControllerTest extends CakeTestCase { * @return void */ public function testControllerHttpCodes() { - $Controller = new Controller(null); - $Controller->response = $this->getMock('CakeResponse', array('httpCodes')); + $response = $this->getMock('CakeResponse', array('httpCodes')); + $Controller = new Controller(null, $response); $Controller->response->expects($this->at(0))->method('httpCodes')->with(null); $Controller->response->expects($this->at(1))->method('httpCodes')->with(100); $Controller->httpCodes(); @@ -1237,8 +1238,9 @@ class ControllerTest extends CakeTestCase { public function testPaginateBackwardsCompatibility() { $request = new CakeRequest('controller_posts/index'); $request->params['pass'] = $request->params['named'] = array(); + $response = $this->getMock('CakeResponse', array('httpCodes')); - $Controller = new Controller($request); + $Controller = new Controller($request, $response); $Controller->uses = array('ControllerPost', 'ControllerComment'); $Controller->passedArgs[] = '1'; $Controller->params['url'] = array(); From 2141b494cdd5d02a57164e5a53c76531adc892a3 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 3 Jul 2011 14:54:43 -0400 Subject: [PATCH 05/25] Adding charset as it was previously omitted. --- app/webroot/index.php | 2 +- lib/Cake/Console/Templates/skel/webroot/index.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/webroot/index.php b/app/webroot/index.php index 8f84d1883..943e310aa 100644 --- a/app/webroot/index.php +++ b/app/webroot/index.php @@ -78,4 +78,4 @@ App::uses('Dispatcher', 'Routing'); $Dispatcher = new Dispatcher(); - $Dispatcher->dispatch(new CakeRequest(), new CakeResponse()); + $Dispatcher->dispatch(new CakeRequest(), new CakeResponse(array('charset' => Configure::read('App.encoding')))); diff --git a/lib/Cake/Console/Templates/skel/webroot/index.php b/lib/Cake/Console/Templates/skel/webroot/index.php index f77a92665..7b67ae20b 100644 --- a/lib/Cake/Console/Templates/skel/webroot/index.php +++ b/lib/Cake/Console/Templates/skel/webroot/index.php @@ -77,4 +77,4 @@ App::uses('Dispatcher', 'Routing'); $Dispatcher = new Dispatcher(); - $Dispatcher->dispatch(new CakeRequest(), new CakeResponse()); + $Dispatcher->dispatch(new CakeRequest(), new CakeResponse(array('charset' => Configure::read('App.encoding')))); From 173e043eaffadc9c5a7c6b4dd7f0e560e8ada223 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 3 Jul 2011 15:02:46 -0400 Subject: [PATCH 06/25] Fixing more failing tests caused by requestAction and changes in Controller::__construct. --- lib/Cake/Controller/Controller.php | 3 --- lib/Cake/Core/Object.php | 2 +- .../Component/AuthComponentTest.php | 10 ++++---- .../Component/RequestHandlerComponentTest.php | 24 ------------------- .../Case/Controller/PagesControllerTest.php | 2 +- 5 files changed, 7 insertions(+), 34 deletions(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index 66619a31e..1a169b60b 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -520,9 +520,6 @@ class Controller extends Object { * @return CakeResponse */ public function getResponse() { - if (empty($this->response)) { - $this->response = new $this->_responseClass(array('charset' => Configure::read('App.encoding'))); - } return $this->response; } diff --git a/lib/Cake/Core/Object.php b/lib/Cake/Core/Object.php index 181a9baa4..35c5a8c38 100644 --- a/lib/Cake/Core/Object.php +++ b/lib/Cake/Core/Object.php @@ -87,7 +87,7 @@ class Object { } $dispatcher = new Dispatcher(); - return $dispatcher->dispatch($request, $extra); + return $dispatcher->dispatch($request, new CakeResponse(), $extra); } /** diff --git a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php index fac3ece78..abfb9059b 100644 --- a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php @@ -122,12 +122,12 @@ class AuthTestController extends Controller { * @access private * @return void */ - function __construct($request) { + function __construct($request, $response) { $request->addParams(Router::parse('/auth_test')); $request->here = '/auth_test'; $request->webroot = '/'; Router::setRequestInfo($request); - parent::__construct($request); + parent::__construct($request, $response); } /** @@ -339,7 +339,7 @@ class AuthTest extends CakeTestCase { $request = new CakeRequest(null, false); - $this->Controller = new AuthTestController($request); + $this->Controller = new AuthTestController($request, $this->getMock('CakeResponse')); $collection = new ComponentCollection(); $collection->init($this->Controller); @@ -960,7 +960,7 @@ class AuthTest extends CakeTestCase { ob_start(); $Dispatcher = new Dispatcher(); - $Dispatcher->dispatch(new CakeRequest('/ajax_auth/add'), array('return' => 1)); + $Dispatcher->dispatch(new CakeRequest('/ajax_auth/add'), new CakeResponse(), array('return' => 1)); $result = ob_get_clean(); $this->assertEqual("Ajax!\nthis is the test element", str_replace("\r\n", "\n", $result)); @@ -1024,7 +1024,7 @@ class AuthTest extends CakeTestCase { */ public function testComponentSettings() { $request = new CakeRequest(null, false); - $this->Controller = new AuthTestController($request); + $this->Controller = new AuthTestController($request, $this->getMock('CakeResponse')); $this->Controller->components = array( 'Auth' => array( diff --git a/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php b/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php index c4b7e6935..94b1da5f5 100644 --- a/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php @@ -77,30 +77,6 @@ class RequestHandlerTestController extends Controller { } } -/** - * RequestHandlerTestDisabledController class - * - * @package cake.tests.cases.libs.controller.components - */ -class RequestHandlerTestDisabledController extends Controller { - -/** - * uses property - * - * @var mixed null - * @access public - */ - public $uses = null; - -/** - * beforeFilter method - * - * @return void - */ - public function beforeFilter() { - $this->RequestHandler->enabled = false; - } -} /** * RequestHandlerComponentTest class diff --git a/lib/Cake/Test/Case/Controller/PagesControllerTest.php b/lib/Cake/Test/Case/Controller/PagesControllerTest.php index cfefc8eb1..c83e95c92 100644 --- a/lib/Cake/Test/Case/Controller/PagesControllerTest.php +++ b/lib/Cake/Test/Case/Controller/PagesControllerTest.php @@ -48,7 +48,7 @@ class PagesControllerTest extends CakeTestCase { CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS ) )); - $Pages = new PagesController(new CakeRequest(null, false)); + $Pages = new PagesController(new CakeRequest(null, false), new CakeResponse()); $Pages->viewPath = 'Posts'; $Pages->display('index'); From 04147caca881416016ebf81df78e6d8610c77244 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 3 Jul 2011 15:33:27 -0400 Subject: [PATCH 07/25] Updating ExceptionRenderer and CakeErrorHandler for Controller changes. --- lib/Cake/Controller/CakeErrorController.php | 4 ++-- lib/Cake/Error/ExceptionRenderer.php | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Controller/CakeErrorController.php b/lib/Cake/Controller/CakeErrorController.php index f75ec24a7..fbb777ea0 100644 --- a/lib/Cake/Controller/CakeErrorController.php +++ b/lib/Cake/Controller/CakeErrorController.php @@ -22,8 +22,8 @@ class CakeErrorController extends AppController { * @access public * @return void */ - public function __construct($request = null) { - parent::__construct($request); + public function __construct($request = null, $response = null) { + parent::__construct($request, $response); $this->constructClasses(); $this->Components->trigger('initialize', array(&$this)); $this->_set(array('cacheAction' => false, 'viewPath' => 'Errors')); diff --git a/lib/Cake/Error/ExceptionRenderer.php b/lib/Cake/Error/ExceptionRenderer.php index 1cadfc35e..db5d87358 100644 --- a/lib/Cake/Error/ExceptionRenderer.php +++ b/lib/Cake/Error/ExceptionRenderer.php @@ -22,6 +22,7 @@ App::uses('Sanitize', 'Utility'); App::uses('Router', 'Routing'); +App::uses('CakeResponse', 'Network'); /** * Exception Renderer. @@ -148,10 +149,11 @@ class ExceptionRenderer { if (!$request = Router::getRequest(false)) { $request = new CakeRequest(); } + $response = new CakeResponse(array('charset' => Configure::read('App.encoding'))); try { - $controller = new CakeErrorController($request); + $controller = new CakeErrorController($request, $response); } catch (Exception $e) { - $controller = new Controller($request); + $controller = new Controller($request, $response); $controller->viewPath = 'Errors'; } return $controller; From 65d28f4c73140f0bb5d1e9f8f2319372fe501f0f Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 3 Jul 2011 20:19:08 -0400 Subject: [PATCH 08/25] Fixing failing tests for ControllerTestCase. --- lib/Cake/TestSuite/ControllerTestCase.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/Cake/TestSuite/ControllerTestCase.php b/lib/Cake/TestSuite/ControllerTestCase.php index 40402d15c..077958087 100644 --- a/lib/Cake/TestSuite/ControllerTestCase.php +++ b/lib/Cake/TestSuite/ControllerTestCase.php @@ -52,9 +52,9 @@ class ControllerTestDispatcher extends Dispatcher { * * @return Controller */ - function _getController($request) { + function _getController($request, $response) { if ($this->testController === null) { - $this->testController = parent::_getController($request); + $this->testController = parent::_getController($request, $response); } $this->testController->helpers = array_merge(array('InterceptContent'), $this->testController->helpers); $this->testController->setRequest($request); @@ -224,7 +224,7 @@ class ControllerTestCase extends CakeTestCase { } $Dispatch->testController = $this->controller; $Dispatch->response = $this->getMock('CakeResponse', array('send')); - $this->result = $Dispatch->dispatch($request, $params); + $this->result = $Dispatch->dispatch($request, $Dispatch->response, $params); $this->controller = $Dispatch->testController; if ($options['return'] != 'result') { $this->vars = $this->controller->View->viewVars; @@ -275,7 +275,9 @@ class ControllerTestCase extends CakeTestCase { list($plugin, $name) = pluginSplit($controller); $_controller = $this->getMock($name.'Controller', $mocks['methods'], array(), '', false); $_controller->name = $name; - $_controller->__construct(); + $request = $this->getMock('CakeRequest'); + $response = $this->getMock('CakeResponse', array('_sendHeader')); + $_controller->__construct($request, $response); $config = ClassRegistry::config('Model'); foreach ($mocks['models'] as $model => $methods) { @@ -319,4 +321,4 @@ class ControllerTestCase extends CakeTestCase { $this->controller = $_controller; return $this->controller; } -} \ No newline at end of file +} From b0749acbb600a3d7e67567174a3e3e216ba58bd1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 6 Jul 2011 20:41:38 -0400 Subject: [PATCH 09/25] Starting to change how Controller::render() and response objects are handled. --- lib/Cake/Controller/Controller.php | 3 ++- lib/Cake/Routing/Dispatcher.php | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index 1a169b60b..319a5ac25 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -828,7 +828,8 @@ class Controller extends Object { $this->autoRender = false; $this->View = $View; - return $this->response->body($View->render($view, $layout)); + $this->response->body($View->render($view, $layout)); + return $this->response; } /** diff --git a/lib/Cake/Routing/Dispatcher.php b/lib/Cake/Routing/Dispatcher.php index 6403465b1..99791e7b4 100644 --- a/lib/Cake/Routing/Dispatcher.php +++ b/lib/Cake/Routing/Dispatcher.php @@ -151,8 +151,11 @@ class Dispatcher { } $result = call_user_func_array(array(&$controller, $request->params['action']), $request->params['pass']); + if ($result instanceof CakeResponse) { + $response = $result; + } if ($controller->autoRender) { - $controller->render(); + $response = $controller->render(); } elseif ($response->body() === null) { $response->body($result); } From 70744f3cb4d6ddbe5b061a868d28c6034eff8383 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 7 Jul 2011 21:31:28 -0400 Subject: [PATCH 10/25] Fixing failing tests for Controller. Adding a string cast for easier testing. --- lib/Cake/Controller/Controller.php | 4 ++-- lib/Cake/Network/CakeResponse.php | 14 ++++++++++++-- lib/Cake/Test/Case/Controller/ControllerTest.php | 11 +++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index 319a5ac25..8f68bf91c 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -790,7 +790,7 @@ class Controller extends Object { * * @param string $view View to use for rendering * @param string $layout Layout to use - * @return string Full output string of view contents + * @return CakeResponse A response object containing the rendered view. * @link http://book.cakephp.org/view/980/render */ public function render($view = null, $layout = null) { @@ -880,7 +880,7 @@ class Controller extends Object { $this->set('message', $message); $this->set('pause', $pause); $this->set('page_title', $message); - $this->response->body($this->render(false, $layout)); + $this->render(false, $layout); } /** diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index 9b91f5315..db97d0eb3 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -300,7 +300,7 @@ class CakeResponse { * * @var string */ - protected $_body = null; + protected $_body = ''; /** * The charset the response body is encoded with @@ -654,4 +654,14 @@ class CakeResponse { public function download($filename) { $this->header('Content-Disposition', 'attachment; filename="' . $filename . '"'); } -} \ No newline at end of file + +/** + * String conversion. Fetches the response body as a string. + * Does *not* send headers. + * + * @return string + */ + public function __toString() { + return $this->_body; + } +} diff --git a/lib/Cake/Test/Case/Controller/ControllerTest.php b/lib/Cake/Test/Case/Controller/ControllerTest.php index 185ea5252..e7ecf224d 100644 --- a/lib/Cake/Test/Case/Controller/ControllerTest.php +++ b/lib/Cake/Test/Case/Controller/ControllerTest.php @@ -525,8 +525,7 @@ class ControllerTest extends CakeTestCase { $request->webroot = '/'; $request->base = '/'; - $Controller = new Controller($request); - $Controller->response = $this->getMock('CakeResponse', array('_sendHeader')); + $Controller = new Controller($request, $this->getMock('CakeResponse', array('_sendHeader'))); $Controller->flash('this should work', '/flash'); $result = $Controller->response->body(); @@ -622,14 +621,14 @@ class ControllerTest extends CakeTestCase { $Controller->viewPath = 'Posts'; $result = $Controller->render('index'); - $this->assertPattern('/posts index/', $result); + $this->assertPattern('/posts index/', (string)$result); $Controller->view = 'index'; $result = $Controller->render(); - $this->assertPattern('/posts index/', $result); + $this->assertPattern('/posts index/', (string)$result); $result = $Controller->render('/Elements/test_element'); - $this->assertPattern('/this is the test element/', $result); + $this->assertPattern('/this is the test element/', (string)$result); $Controller->view = null; $Controller = new TestController($request, new CakeResponse()); @@ -677,7 +676,7 @@ class ControllerTest extends CakeTestCase { $Controller->viewPath = 'Posts'; $Controller->theme = 'TestTheme'; $result = $Controller->render('index'); - $this->assertPattern('/default test_theme layout/', $result); + $this->assertPattern('/default test_theme layout/', (string)$result); App::build(); } From 8bfc0a859d2223512b13fa0afc4301912e534300 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 8 Jul 2011 21:23:02 -0400 Subject: [PATCH 11/25] Reverting previous change that prevent entry into a special case. --- lib/Cake/Network/CakeResponse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index db97d0eb3..6a9b29023 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -300,7 +300,7 @@ class CakeResponse { * * @var string */ - protected $_body = ''; + protected $_body = null; /** * The charset the response body is encoded with @@ -662,6 +662,6 @@ class CakeResponse { * @return string */ public function __toString() { - return $this->_body; + return (string)$this->_body; } } From 177cd39abb26686cc8fe73292e89ed735079a9fb Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 9 Jul 2011 13:56:51 -0400 Subject: [PATCH 12/25] Moving private method detection into Controller. This fixes an issue where potected methods would not be called, and no exception would be raised. --- lib/Cake/Controller/Controller.php | 55 +++++++++++++++++++ lib/Cake/Routing/Dispatcher.php | 43 +-------------- lib/Cake/Test/Case/Routing/DispatcherTest.php | 14 ++--- 3 files changed, 62 insertions(+), 50 deletions(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index 8f68bf91c..c15548a17 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -442,6 +442,61 @@ class Controller extends Object { } } +/** + * Dispatches the controller action. Checks that the action + * exists and isn't private. + * + * @param CakeRequest $request + * @return The resulting response. + */ + public function invokeAction(CakeRequest $request) { + $reflection = new ReflectionClass($this); + try { + $method = $reflection->getMethod($request->params['action']); + + if ($this->_isPrivateAction($method, $request)) { + throw new PrivateActionException(array( + 'controller' => $this->name . "Controller", + 'action' => $request->params['action'] + )); + } + return $method->invokeArgs($this, $request->params['pass']); + + } catch (ReflectionException $e) { + if ($this->scaffold !== false) { + return new Scaffold($this, $request); + } + throw new MissingActionException(array( + 'controller' => $this->name . "Controller", + 'action' => $request->params['action'] + )); + } + } + +/** + * Check if the request's action is marked as private, with an underscore, of if the request is attempting to + * directly accessing a prefixed action. + * + * @param ReflectionMethod $method The method to be invoked. + * @param CakeRequest $request The request to check. + * @return boolean + */ + protected function _isPrivateAction(ReflectionMethod $method, CakeRequest $request) { + $privateAction = ( + $method->name[0] === '_' || + !$method->isPublic() || + !in_array($method->name, $this->methods) + ); + $prefixes = Router::prefixes(); + + 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); + } + } + return $privateAction; + } /** * Merge components, helpers, and uses vars from Controller::$_mergeParent and PluginAppController. * diff --git a/lib/Cake/Routing/Dispatcher.php b/lib/Cake/Routing/Dispatcher.php index 99791e7b4..90a70a039 100644 --- a/lib/Cake/Routing/Dispatcher.php +++ b/lib/Cake/Routing/Dispatcher.php @@ -93,37 +93,9 @@ class Dispatcher { )); } - if ($this->_isPrivateAction($request)) { - throw new PrivateActionException(array( - 'controller' => Inflector::camelize($request->params['controller']) . "Controller", - 'action' => $request->params['action'] - )); - } - return $this->_invoke($controller, $request, $response); } -/** - * Check if the request's action is marked as private, with an underscore, of if the request is attempting to - * directly accessing a prefixed action. - * - * @param CakeRequest $request The request to check - * @return boolean - */ - protected function _isPrivateAction($request) { - $privateAction = $request->params['action'][0] === '_'; - $prefixes = Router::prefixes(); - - 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); - } - } - - return $privateAction; - } - /** * Initializes the components and models a controller will be using. * Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output. @@ -138,22 +110,11 @@ class Dispatcher { $controller->constructClasses(); $controller->startupProcess(); - $methods = array_flip($controller->methods); - - if (!isset($methods[$request->params['action']])) { - if ($controller->scaffold !== false) { - return new Scaffold($controller, $request); - } - throw new MissingActionException(array( - 'controller' => Inflector::camelize($request->params['controller']) . "Controller", - 'action' => $request->params['action'] - )); - } - $result = call_user_func_array(array(&$controller, $request->params['action']), $request->params['pass']); - + $result = $controller->invokeAction($request); if ($result instanceof CakeResponse) { $response = $result; } + if ($controller->autoRender) { $response = $controller->render(); } elseif ($response->body() === null) { diff --git a/lib/Cake/Test/Case/Routing/DispatcherTest.php b/lib/Cake/Test/Case/Routing/DispatcherTest.php index a7c7ae527..46de1d30a 100644 --- a/lib/Cake/Test/Case/Routing/DispatcherTest.php +++ b/lib/Cake/Test/Case/Routing/DispatcherTest.php @@ -50,11 +50,7 @@ class TestDispatcher extends Dispatcher { * @return void */ protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response) { - if ($result = parent::_invoke($controller, $request, $response)) { - if ($result[0] === 'missingAction') { - return $result; - } - } + $result = parent::_invoke($controller, $request, $response); return $controller; } @@ -733,13 +729,13 @@ class DispatcherTest extends CakeTestCase { } /** - * test that methods declared in Controller are treated as missing methods. + * test that methods declared in Controller are treated as private methods. * - * @expectedException MissingActionException - * @expectedExceptionMessage Action SomePagesController::redirect() could not be found. + * @expectedException PrivateActionException + * @expectedExceptionMessage Private Action SomePagesController::redirect() is not directly accessible. * @return void */ - public function testMissingActionFromBaseClassMethods() { + public function testPrivateActionFromBaseClassMethods() { $Dispatcher = new TestDispatcher(); Configure::write('App.baseUrl','/index.php'); $url = new CakeRequest('some_pages/redirect/param:value/param2:value2'); From c25394278b6847e1d99052b9dd58ca8a4359b125 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 9 Jul 2011 14:21:32 -0400 Subject: [PATCH 13/25] Returning response objects from controllers wasn't working correctly. --- lib/Cake/Routing/Dispatcher.php | 4 ++- lib/Cake/Test/Case/Routing/DispatcherTest.php | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Routing/Dispatcher.php b/lib/Cake/Routing/Dispatcher.php index 90a70a039..0203b9ff1 100644 --- a/lib/Cake/Routing/Dispatcher.php +++ b/lib/Cake/Routing/Dispatcher.php @@ -110,12 +110,14 @@ class Dispatcher { $controller->constructClasses(); $controller->startupProcess(); + $render = true; $result = $controller->invokeAction($request); if ($result instanceof CakeResponse) { + $render = false; $response = $result; } - if ($controller->autoRender) { + if ($render && $controller->autoRender) { $response = $controller->render(); } elseif ($response->body() === null) { $response->body($result); diff --git a/lib/Cake/Test/Case/Routing/DispatcherTest.php b/lib/Cake/Test/Case/Routing/DispatcherTest.php index 46de1d30a..1a039aa12 100644 --- a/lib/Cake/Test/Case/Routing/DispatcherTest.php +++ b/lib/Cake/Test/Case/Routing/DispatcherTest.php @@ -167,6 +167,15 @@ class SomePagesController extends AppController { return true; } +/** + * Test method for returning responses. + * + * @return CakeResponse + */ + public function responseGenerator() { + return new CakeResponse(array('body' => 'new response')); + } + /** * redirect method overriding * @@ -806,6 +815,23 @@ class DispatcherTest extends CakeTestCase { $this->assertEqual($controller->params['pass'][0], 'something. .', 'Period was chopped off. %s'); } +/** + * Test that Dispatcher handles actions that return response objects. + * + * @return void + */ + public function testDispatchActionReturnsResponse() { + $Dispatcher = new Dispatcher(); + $request = new CakeRequest('some_pages/responseGenerator'); + $response = $this->getMock('CakeResponse', array('_sendHeader')); + + ob_start(); + $Dispatcher->dispatch($request, $response); + $result = ob_get_clean(); + + $this->assertEquals('new response', $result); + } + /** * testAdminDispatch method * From 61ab769f1c51f96c927ab35cde54aaf18df4d867 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 10 Jul 2011 10:52:54 -0400 Subject: [PATCH 14/25] Moving tests for private actions to ControllerTest. --- .../Test/Case/Controller/ControllerTest.php | 119 +++++++++++++++++- lib/Cake/Test/Case/Routing/DispatcherTest.php | 84 ------------- 2 files changed, 117 insertions(+), 86 deletions(-) diff --git a/lib/Cake/Test/Case/Controller/ControllerTest.php b/lib/Cake/Test/Case/Controller/ControllerTest.php index e7ecf224d..d917f5af3 100644 --- a/lib/Cake/Test/Case/Controller/ControllerTest.php +++ b/lib/Cake/Test/Case/Controller/ControllerTest.php @@ -253,7 +253,7 @@ class TestController extends ControllerTestAppController { * @var string 'Name' * @access public */ - public $name = 'TestController'; + public $name = 'Test'; /** * helpers property @@ -261,7 +261,7 @@ class TestController extends ControllerTestAppController { * @var array * @access public */ - public $helpers = array('Session', 'Xml'); + public $helpers = array('Session'); /** * components property @@ -295,6 +295,22 @@ class TestController extends ControllerTestAppController { 'test2Id' => $test2Id ); } + + protected function protected_m() { + + } + + private function private_m() { + + } + + public function _hidden() { + + } + + public function admin_add() { + + } } /** @@ -1259,4 +1275,103 @@ class ControllerTest extends CakeTestCase { $this->assertIdentical($Controller->params['paging']['ControllerPost']['prevPage'], false); $this->assertIdentical($Controller->params['paging']['ControllerPost']['nextPage'], true); } + +/** + * testMissingAction method + * + * @expectedException MissingActionException + * @expectedExceptionMessage Action TestController::missing() could not be found. + * @return void + */ + public function testInvokeActionMissingAction() { + $url = new CakeRequest('test/missing'); + $url->addParams(array('controller' => 'test_controller', 'action' => 'missing')); + $response = $this->getMock('CakeResponse'); + + $Controller = new TestController($url, $response); + $Controller->invokeAction($url); + } + +/** + * test invoking private methods. + * + * @expectedException PrivateActionException + * @expectedExceptionMessage Private Action TestController::private_m() is not directly accessible. + * @return void + */ + public function testInvokeActionPrivate() { + $url = new CakeRequest('test/private_m/'); + $url->addParams(array('controller' => 'test_controller', 'action' => 'private_m')); + $response = $this->getMock('CakeResponse'); + + $Controller = new TestController($url, $response); + $Controller->invokeAction($url); + } + +/** + * test invoking protected methods. + * + * @expectedException PrivateActionException + * @expectedExceptionMessage Private Action TestController::protected_m() is not directly accessible. + * @return void + */ + public function testInvokeActionProtected() { + $url = new CakeRequest('test/protected_m/'); + $url->addParams(array('controller' => 'test_controller', 'action' => 'protected_m')); + $response = $this->getMock('CakeResponse'); + + $Controller = new TestController($url, $response); + $Controller->invokeAction($url); + } + +/** + * test invoking hidden methods. + * + * @expectedException PrivateActionException + * @expectedExceptionMessage Private Action TestController::_hidden() is not directly accessible. + * @return void + */ + public function testInvokeActionHidden() { + $url = new CakeRequest('test/_hidden/'); + $url->addParams(array('controller' => 'test_controller', 'action' => '_hidden')); + $response = $this->getMock('CakeResponse'); + + $Controller = new TestController($url, $response); + $Controller->invokeAction($url); + } + +/** + * test invoking controller methods. + * + * @expectedException PrivateActionException + * @expectedExceptionMessage Private Action TestController::redirect() is not directly accessible. + * @return void + */ + public function testInvokeActionBaseMethods() { + $url = new CakeRequest('test/redirect/'); + $url->addParams(array('controller' => 'test_controller', 'action' => 'redirect')); + $response = $this->getMock('CakeResponse'); + + $Controller = new TestController($url, $response); + $Controller->invokeAction($url); + } + +/** + * test invoking controller methods. + * + * @expectedException PrivateActionException + * @expectedExceptionMessage Private Action TestController::admin_add() is not directly accessible. + * @return void + */ + public function testInvokeActionPrefixProtection() { + Router::reload(); + Router::connect('/admin/:controller/:action/*', array('prefix'=>'admin')); + + $url = new CakeRequest('test/admin_add/'); + $url->addParams(array('controller' => 'test_controller', 'action' => 'admin_add')); + $response = $this->getMock('CakeResponse'); + + $Controller = new TestController($url, $response); + $Controller->invokeAction($url); + } } diff --git a/lib/Cake/Test/Case/Routing/DispatcherTest.php b/lib/Cake/Test/Case/Routing/DispatcherTest.php index 1a039aa12..6e044e8af 100644 --- a/lib/Cake/Test/Case/Routing/DispatcherTest.php +++ b/lib/Cake/Test/Case/Routing/DispatcherTest.php @@ -158,15 +158,6 @@ class SomePagesController extends AppController { return true; } -/** - * protected method - * - * @return void - */ - protected function _protected() { - return true; - } - /** * Test method for returning responses. * @@ -176,14 +167,6 @@ class SomePagesController extends AppController { return new CakeResponse(array('body' => 'new response')); } -/** - * redirect method overriding - * - * @return void - */ - public function redirect($url, $status = null, $exit = true) { - echo 'this should not be accessible'; - } } /** @@ -705,54 +688,6 @@ class DispatcherTest extends CakeTestCase { $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); } -/** - * testPrivate method - * - * @expectedException PrivateActionException - * @expectedExceptionMessage Private Action SomePagesController::_protected() is not directly accessible. - * @return void - */ - public function testPrivate() { - $Dispatcher = new TestDispatcher(); - Configure::write('App.baseUrl','/index.php'); - $url = new CakeRequest('some_pages/_protected/param:value/param2:value2'); - $response = $this->getMock('CakeResponse'); - - $controller = $Dispatcher->dispatch($url, $response, array('return' => 1)); - } - -/** - * testMissingAction method - * - * @expectedException MissingActionException - * @expectedExceptionMessage Action SomePagesController::home() could not be found. - * @return void - */ - public function testMissingAction() { - $Dispatcher = new TestDispatcher(); - Configure::write('App.baseUrl', '/index.php'); - $url = new CakeRequest('some_pages/home/param:value/param2:value2'); - $response = $this->getMock('CakeResponse'); - - $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); - } - -/** - * test that methods declared in Controller are treated as private methods. - * - * @expectedException PrivateActionException - * @expectedExceptionMessage Private Action SomePagesController::redirect() is not directly accessible. - * @return void - */ - public function testPrivateActionFromBaseClassMethods() { - $Dispatcher = new TestDispatcher(); - Configure::write('App.baseUrl','/index.php'); - $url = new CakeRequest('some_pages/redirect/param:value/param2:value2'); - $response = $this->getMock('CakeResponse'); - - $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); - } - /** * testDispatch method * @@ -1127,25 +1062,6 @@ class DispatcherTest extends CakeTestCase { $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); } -/** - * testPrefixProtection method - * - * @expectedException PrivateActionException - * @expectedExceptionMessage Private Action TestDispatchPagesController::admin_index() is not directly accessible. - * @return void - */ - public function testPrefixProtection() { - Router::reload(); - Router::connect('/admin/:controller/:action/*', array('prefix'=>'admin'), array('controller', 'action')); - - $Dispatcher = new TestDispatcher(); - - $url = new CakeRequest('test_dispatch_pages/admin_index/param:value/param2:value2'); - $response = $this->getMock('CakeResponse'); - - $controller = $Dispatcher->dispatch($url, $response, array('return'=> 1)); - } - /** * Test dispatching into the TestPlugin in the test_app * From b56931383cb7976ed9d6464df299bd96d3269536 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 10 Jul 2011 11:02:16 -0400 Subject: [PATCH 15/25] Adding tests. --- .../Test/Case/Controller/ControllerTest.php | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Controller/ControllerTest.php b/lib/Cake/Test/Case/Controller/ControllerTest.php index d917f5af3..ad1f5a3d1 100644 --- a/lib/Cake/Test/Case/Controller/ControllerTest.php +++ b/lib/Cake/Test/Case/Controller/ControllerTest.php @@ -295,6 +295,10 @@ class TestController extends ControllerTestAppController { 'test2Id' => $test2Id ); } + + public function returner() { + return 'I am from the controller.'; + } protected function protected_m() { @@ -319,7 +323,6 @@ class TestController extends ControllerTestAppController { * @package cake.tests.cases.libs.controller */ class TestComponent extends Object { - /** * beforeRedirect method * @@ -1374,4 +1377,25 @@ class ControllerTest extends CakeTestCase { $Controller = new TestController($url, $response); $Controller->invokeAction($url); } + +/** + * test invoking controller methods. + * + * @return void + */ + public function testInvokeActionReturnValue() { + $url = new CakeRequest('test/returner/'); + $url->addParams(array( + 'controller' => 'test_controller', + 'action' => 'returner', + 'pass' => array() + )); + $response = $this->getMock('CakeResponse'); + + $Controller = new TestController($url, $response); + $result = $Controller->invokeAction($url); + $this->assertEquals('I am from the controller.', $result); + } + + } From f28b42de2fa7abc56e25f97d61b14f1dc78293cc Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 10 Jul 2011 11:07:49 -0400 Subject: [PATCH 16/25] Pulling construction of Scaffold into a method so its easier to allow plugins/user classes to replace the core Scaffold class. --- lib/Cake/Controller/Controller.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index c15548a17..c9742662e 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -464,7 +464,7 @@ class Controller extends Object { } catch (ReflectionException $e) { if ($this->scaffold !== false) { - return new Scaffold($this, $request); + return $this->_getScaffold($request); } throw new MissingActionException(array( 'controller' => $this->name . "Controller", @@ -474,8 +474,8 @@ class Controller extends Object { } /** - * Check if the request's action is marked as private, with an underscore, of if the request is attempting to - * directly accessing a prefixed action. + * Check if the request's action is marked as private, with an underscore, + * or if the request is attempting to directly accessing a prefixed action. * * @param ReflectionMethod $method The method to be invoked. * @param CakeRequest $request The request to check. @@ -497,6 +497,17 @@ class Controller extends Object { } return $privateAction; } + +/** + * Returns a scaffold object to use for dynamically scaffolded controllers. + * + * @param CakeRequest $request + * @return Scaffold + */ + protected function _getScaffold(CakeRequest $request) { + return new Scaffold($this, $request); + } + /** * Merge components, helpers, and uses vars from Controller::$_mergeParent and PluginAppController. * From 358d591e953af7321dd677d6e7bd942e7c749d86 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 13 Jul 2011 22:48:09 -0400 Subject: [PATCH 17/25] Making ApiShell test, which uses Controller pass. --- .../Case/Console/Command/ApiShellTest.php | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/Cake/Test/Case/Console/Command/ApiShellTest.php b/lib/Cake/Test/Case/Console/Command/ApiShellTest.php index 26ccfb8b7..87e92441d 100644 --- a/lib/Cake/Test/Case/Console/Command/ApiShellTest.php +++ b/lib/Cake/Test/Case/Console/Command/ApiShellTest.php @@ -65,19 +65,20 @@ class ApiShellTest extends CakeTestCase { '8. getResponse()', '9. header($status)', '10. httpCodes($code = NULL)', - '11. loadModel($modelClass = NULL, $id = NULL)', - '12. paginate($object = NULL, $scope = array (), $whitelist = array ())', - '13. postConditions($data = array (), $op = NULL, $bool = \'AND\', $exclusive = false)', - '14. redirect($url, $status = NULL, $exit = true)', - '15. referer($default = NULL, $local = false)', - '16. render($view = NULL, $layout = NULL)', - '17. set($one, $two = NULL)', - '18. setAction($action)', - '19. setRequest($request)', - '20. shutdownProcess()', - '21. startupProcess()', - '22. validate()', - '23. validateErrors()' + '11. invokeAction($request)', + '12. loadModel($modelClass = NULL, $id = NULL)', + '13. paginate($object = NULL, $scope = array (), $whitelist = array ())', + '14. postConditions($data = array (), $op = NULL, $bool = \'AND\', $exclusive = false)', + '15. redirect($url, $status = NULL, $exit = true)', + '16. referer($default = NULL, $local = false)', + '17. render($view = NULL, $layout = NULL)', + '18. set($one, $two = NULL)', + '19. setAction($action)', + '20. setRequest($request)', + '21. shutdownProcess()', + '22. startupProcess()', + '23. validate()', + '24. validateErrors()' ); $this->Shell->expects($this->at(2))->method('out')->with($expected); From cfb3e8a15be8fee61b7424ff8399295d0c423702 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 16 Jul 2011 23:36:30 -0400 Subject: [PATCH 18/25] Moving default routes into a separate file. Removing Router::defaults() as its not needed anymore. Removing default routes from inside router. Removing properties related to default routes. Removing dead tests and updating tests. --- app/Config/routes.php | 5 + lib/Cake/Config/routes.php | 83 ++++++++++++++ lib/Cake/Routing/Router.php | 105 +----------------- lib/Cake/Test/Case/Routing/RouterTest.php | 126 +++++----------------- 4 files changed, 113 insertions(+), 206 deletions(-) create mode 100644 lib/Cake/Config/routes.php diff --git a/app/Config/routes.php b/app/Config/routes.php index 72ef866d8..e41f4a667 100644 --- a/app/Config/routes.php +++ b/app/Config/routes.php @@ -30,3 +30,8 @@ * ...and connect the rest of 'Pages' controller's urls. */ Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); + +/** + * Load the CakePHP default routes. + */ + require CAKE . 'Config' . DS . 'routes.php'; diff --git a/lib/Cake/Config/routes.php b/lib/Cake/Config/routes.php new file mode 100644 index 000000000..da76d63e3 --- /dev/null +++ b/lib/Cake/Config/routes.php @@ -0,0 +1,83 @@ + $value) { + $plugins[$key] = Inflector::underscore($value); + } + $pluginPattern = implode('|', $plugins); + $match = array('plugin' => $pluginPattern); + $shortParams = array('routeClass' => 'PluginShortRoute', 'plugin' => $pluginPattern); + + foreach ($prefixes as $prefix) { + $params = array('prefix' => $prefix, $prefix => true); + $indexParams = $params + array('action' => 'index'); + Router::connect("/{$prefix}/:plugin", $indexParams, $shortParams); + Router::connect("/{$prefix}/:plugin/:controller", $indexParams, $match); + Router::connect("/{$prefix}/:plugin/:controller/:action/*", $params, $match); + } + Router::connect('/:plugin', array('action' => 'index'), $shortParams); + Router::connect('/:plugin/:controller', array('action' => 'index'), $match); + Router::connect('/:plugin/:controller/:action/*', array(), $match); + } + + foreach ($prefixes as $prefix) { + $params = array('prefix' => $prefix, $prefix => true); + $indexParams = $params + array('action' => 'index'); + Router::connect("/{$prefix}/:controller", $indexParams); + Router::connect("/{$prefix}/:controller/:action/*", $params); + } + Router::connect('/:controller', array('action' => 'index')); + Router::connect('/:controller/:action/*'); + + $namedConfig = Router::namedConfig(); + if ($namedConfig['rules'] === false) { + Router::connectNamed(true); + } diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php index 2106074e3..0747bdcb9 100644 --- a/lib/Cake/Routing/Router.php +++ b/lib/Cake/Routing/Router.php @@ -145,21 +145,6 @@ class Router { */ protected static $_requests = array(); -/** - * Keeps Router state to determine if default routes have already been connected - * - * @var boolean - * @access private - */ - protected static $_defaultsMapped = false; - -/** - * Keeps track of whether the connection of default routes is enabled or disabled. - * - * @var boolean - */ - protected static $_connectDefaults = true; - /** * Initial state is popualated the first time reload() is called which is at the bottom * of this file. This is a cheat as get_class_vars() returns the value of static vars even if they @@ -413,19 +398,6 @@ class Router { return self::$_namedConfig; } -/** - * Tell router to connect or not connect the default routes. - * - * If default routes are disabled all automatic route generation will be disabled - * and you will need to manually configure all the routes you want. - * - * @param boolean $connect Set to true or false depending on whether you want or don't want default routes. - * @return void - */ - public static function defaults($connect = true) { - self::$_connectDefaults = $connect; - } - /** * Creates REST resource routes for the given controller(s) * @@ -479,15 +451,8 @@ class Router { * @return array Parsed elements from URL */ public static function parse($url) { - if (!self::$_defaultsMapped && self::$_connectDefaults) { - self::__connectDefaultRoutes(); - } - $out = array( - 'pass' => array(), - 'named' => array() - ); - $ext = null; + $out = array(); if ($url && strpos($url, '/') !== 0) { $url = '/' . $url; @@ -547,74 +512,6 @@ class Router { return compact('ext', 'url'); } -/** - * Connects the default, built-in routes, including prefix and plugin routes. The following routes are created - * in the order below: - * - * For each of the Routing.prefixes the following routes are created. Routes containing `:plugin` are only - * created when your application has one or more plugins. - * - * - `/:prefix/:plugin` a plugin shortcut route. - * - `/:prefix/:plugin/:action/*` a plugin shortcut route. - * - `/:prefix/:plugin/:controller` - * - `/:prefix/:plugin/:controller/:action/*` - * - `/:prefix/:controller` - * - `/:prefix/:controller/:action/*` - * - * If plugins are found in your application the following routes are created: - * - * - `/:plugin` a plugin shortcut route. - * - `/:plugin/:action/*` a plugin shortcut route. - * - `/:plugin/:controller` - * - `/:plugin/:controller/:action/*` - * - * And lastly the following catch-all routes are connected. - * - * - `/:controller' - * - `/:controller/:action/*' - * - * You can disable the connection of default routes with Router::defaults(). - * - * @return void - * @access private - */ - private static function __connectDefaultRoutes() { - if ($plugins = CakePlugin::loaded()) { - App::uses('PluginShortRoute', 'Routing/Route'); - foreach ($plugins as $key => $value) { - $plugins[$key] = Inflector::underscore($value); - } - $pluginPattern = implode('|', $plugins); - $match = array('plugin' => $pluginPattern); - $shortParams = array('routeClass' => 'PluginShortRoute', 'plugin' => $pluginPattern); - - foreach (self::$_prefixes as $prefix) { - $params = array('prefix' => $prefix, $prefix => true); - $indexParams = $params + array('action' => 'index'); - self::connect("/{$prefix}/:plugin", $indexParams, $shortParams); - self::connect("/{$prefix}/:plugin/:controller", $indexParams, $match); - self::connect("/{$prefix}/:plugin/:controller/:action/*", $params, $match); - } - self::connect('/:plugin', array('action' => 'index'), $shortParams); - self::connect('/:plugin/:controller', array('action' => 'index'), $match); - self::connect('/:plugin/:controller/:action/*', array(), $match); - } - - foreach (self::$_prefixes as $prefix) { - $params = array('prefix' => $prefix, $prefix => true); - $indexParams = $params + array('action' => 'index'); - self::connect("/{$prefix}/:controller", $indexParams); - self::connect("/{$prefix}/:controller/:action/*", $params); - } - self::connect('/:controller', array('action' => 'index')); - self::connect('/:controller/:action/*'); - - if (self::$_namedConfig['rules'] === false) { - self::connectNamed(true); - } - self::$_defaultsMapped = true; - } - /** * Takes parameter and path information back from the Dispatcher, sets these * parameters as the current request parameters that are merged with url arrays diff --git a/lib/Cake/Test/Case/Routing/RouterTest.php b/lib/Cake/Test/Case/Routing/RouterTest.php index 49117693c..2a9236432 100644 --- a/lib/Cake/Test/Case/Routing/RouterTest.php +++ b/lib/Cake/Test/Case/Routing/RouterTest.php @@ -115,7 +115,7 @@ class RouterTest extends CakeTestCase { $_SERVER['REQUEST_METHOD'] = 'GET'; $result = Router::parse('/posts/add'); - $this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'add')); + $this->assertEquals(array(), $result); Router::reload(); $resources = Router::mapResources('Posts', array('id' => '[a-z0-9_]+')); @@ -446,58 +446,6 @@ class RouterTest extends CakeTestCase { ))); $expected = '/tests/index/namedParam[keyed]:is an array/namedParam[0]:test'; $this->assertEqual($expected, $result); - - //@todo Delete from here down, tests are in CakeRoute now. - $result = Router::parse('/tests/action/var[]:val1/var[]:val2'); - $expected = array( - 'controller' => 'tests', - 'action' => 'action', - 'named' => array( - 'var' => array( - 'val1', - 'val2' - ) - ), - 'pass' => array(), - 'plugin' => null - ); - $this->assertEqual($expected, $result); - - $result = Router::parse('/tests/action/theanswer[is]:42/var[]:val2/var[]:val3'); - $expected = array( - 'controller' => 'tests', - 'action' => 'action', - 'named' => array( - 'theanswer' => array( - 'is' => 42 - ), - 'var' => array( - 'val2', - 'val3' - ) - ), - 'pass' => array(), - 'plugin' => null - ); - $this->assertEqual($expected, $result); - - $result = Router::parse('/tests/action/theanswer[is][not]:42/theanswer[]:5/theanswer[is]:6'); - $expected = array( - 'controller' => 'tests', - 'action' => 'action', - 'named' => array( - 'theanswer' => array( - 5, - 'is' => array( - 6, - 'not' => 42 - ) - ), - ), - 'pass' => array(), - 'plugin' => null - ); - $this->assertEqual($expected, $result); } /** @@ -605,10 +553,6 @@ class RouterTest extends CakeTestCase { 'controller' => 'source|wiki|commits|tickets|comments|view', 'action' => 'branches|history|branch|logs|view|start|add|edit|modify' )); - Router::defaults(false); - $result = Router::parse('/foo/bar'); - $expected = array('pass' => array(), 'named' => array()); - $this->assertEqual($expected, $result); } /** @@ -956,6 +900,7 @@ class RouterTest extends CakeTestCase { $this->assertEqual($expected, $result); Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; $result = Router::parse('/pages/display/home'); $expected = array('plugin' => null, 'pass' => array('home'), 'controller' => 'pages', 'action' => 'display', 'named' => array()); $this->assertEqual($expected, $result); @@ -1192,6 +1137,7 @@ class RouterTest extends CakeTestCase { CakePlugin::loadAll(); Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; $request = new CakeRequest(); Router::setRequestInfo( $request->addParams(array( @@ -1210,7 +1156,7 @@ class RouterTest extends CakeTestCase { $this->assertEqual($expected, $result); Router::reload(); - Router::parse('/'); + require CAKE . 'Config' . DS . 'routes.php'; $request = new CakeRequest(); Router::setRequestInfo( $request->addParams(array( @@ -1261,6 +1207,7 @@ class RouterTest extends CakeTestCase { */ public function testExtensionParsing() { Router::parseExtensions(); + require CAKE . 'Config' . DS . 'routes.php'; $result = Router::parse('/posts.rss'); $expected = array('plugin' => null, 'controller' => 'posts', 'action' => 'index', 'url' => array('ext' => 'rss'), 'pass'=> array(), 'named' => array()); @@ -1278,6 +1225,8 @@ class RouterTest extends CakeTestCase { $this->assertEqual($expected, $result); Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; + Router::parseExtensions('rss', 'xml'); $result = Router::parse('/posts.xml'); @@ -1434,11 +1383,13 @@ class RouterTest extends CakeTestCase { */ public function testNamedArgsUrlParsing() { Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; $result = Router::parse('/controller/action/param1:value1:1/param2:value2:3/param:value'); $expected = array('pass' => array(), 'named' => array('param1' => 'value1:1', 'param2' => 'value2:3', 'param' => 'value'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null); $this->assertEqual($expected, $result); Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; $result = Router::connectNamed(false); $this->assertEqual(array_keys($result['rules']), array()); $this->assertFalse($result['greedyNamed']); @@ -1447,52 +1398,43 @@ class RouterTest extends CakeTestCase { $this->assertEqual($expected, $result); Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; $result = Router::connectNamed(true); $named = Router::namedConfig(); $this->assertEqual(array_keys($result['rules']), $named['default']); $this->assertTrue($result['greedyNamed']); + Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; Router::connectNamed(array('param1' => 'not-matching')); $result = Router::parse('/controller/action/param1:value1:1/param2:value2:3/param:value'); $expected = array('pass' => array('param1:value1:1'), 'named' => array('param2' => 'value2:3', 'param' => 'value'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null); $this->assertEqual($expected, $result); - //@todo delete this test. - Router::reload(); - Router::connect('/foo/:action/*', array('controller' => 'bar'), array('named' => array('param1' => array('action' => 'index')), 'greedyNamed' => true)); - $result = Router::parse('/foo/index/param1:value1:1/param2:value2:3/param:value'); - $expected = array('pass' => array(), 'named' => array('param1' => 'value1:1', 'param2' => 'value2:3', 'param' => 'value'), 'controller' => 'bar', 'action' => 'index', 'plugin' => null); - $this->assertEqual($expected, $result); - $result = Router::parse('/foo/view/param1:value1:1/param2:value2:3/param:value'); - $expected = array('pass' => array('param1:value1:1'), 'named' => array('param2' => 'value2:3', 'param' => 'value'), 'controller' => 'bar', 'action' => 'view', 'plugin' => null); + $expected = array('pass' => array('param1:value1:1'), 'named' => array('param2' => 'value2:3', 'param' => 'value'), 'controller' => 'foo', 'action' => 'view', 'plugin' => null); $this->assertEqual($expected, $result); Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; Router::connectNamed(array('param1' => '[\d]', 'param2' => '[a-z]', 'param3' => '[\d]')); $result = Router::parse('/controller/action/param1:1/param2:2/param3:3'); $expected = array('pass' => array('param2:2'), 'named' => array('param1' => '1', 'param3' => '3'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null); $this->assertEqual($expected, $result); Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; Router::connectNamed(array('param1' => '[\d]', 'param2' => true, 'param3' => '[\d]')); $result = Router::parse('/controller/action/param1:1/param2:2/param3:3'); $expected = array('pass' => array(), 'named' => array('param1' => '1', 'param2' => '2', 'param3' => '3'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null); $this->assertEqual($expected, $result); Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; Router::connectNamed(array('param1' => 'value[\d]+:[\d]+'), array('greedy' => false)); $result = Router::parse('/controller/action/param1:value1:1/param2:value2:3/param3:value'); $expected = array('pass' => array('param2:value2:3', 'param3:value'), 'named' => array('param1' => 'value1:1'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null); $this->assertEqual($expected, $result); - - //@todo delete this test. - Router::reload(); - Router::connect('/foo/*', array('controller' => 'bar', 'action' => 'fubar'), array('named' => array('param1' => 'value[\d]:[\d]'))); - Router::connectNamed(array(), array('greedy' => false)); - $result = Router::parse('/foo/param1:value1:1/param2:value2:3/param3:value'); - $expected = array('pass' => array('param2:value2:3', 'param3:value'), 'named' => array('param1' => 'value1:1'), 'controller' => 'bar', 'action' => 'fubar', 'plugin' => null); - $this->assertEqual($expected, $result); } /** @@ -1761,13 +1703,7 @@ class RouterTest extends CakeTestCase { $this->assertEqual($expected, $result); Router::reload(); - Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); - - $result = Router::parse('/pages/display/home/parameter:value'); - $expected = array('pass' => array('home'), 'named' => array('parameter' => 'value'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display'); - $this->assertEqual($expected, $result); - - Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); $result = Router::parse('/'); @@ -1802,6 +1738,7 @@ class RouterTest extends CakeTestCase { */ public function testParsingWithTrailingPeriod() { Router::reload(); + Router::connect('/:controller/:action/*'); $result = Router::parse('/posts/view/something.'); $this->assertEqual($result['pass'][0], 'something.', 'Period was chopped off %s'); @@ -1816,6 +1753,7 @@ class RouterTest extends CakeTestCase { */ public function testParsingWithTrailingPeriodAndParseExtensions() { Router::reload(); + Router::connect('/:controller/:action/*'); Router::parseExtensions('json'); $result = Router::parse('/posts/view/something.'); @@ -1848,20 +1786,13 @@ class RouterTest extends CakeTestCase { $this->assertEqual($expected, $result); $result = Router::parse('/blog/foobar'); - $expected = array( - 'plugin' => null, - 'controller' => 'blog', - 'action' => 'foobar', - 'pass' => array(), - 'named' => array() - ); - $this->assertEqual($expected, $result); + $this->assertEquals(array(), $result); $result = Router::url(array('controller' => 'blog_posts', 'action' => 'foo')); - $this->assertEqual('/blog_posts/foo', $result); + $this->assertEquals('/blog_posts/foo', $result); $result = Router::url(array('controller' => 'blog_posts', 'action' => 'actions')); - $this->assertEqual('/blog/actions', $result); + $this->assertEquals('/blog/actions', $result); } /** @@ -1932,10 +1863,6 @@ class RouterTest extends CakeTestCase { $result = Router::url(array('members' => true, 'controller' => 'users', 'action' => 'add')); $expected = '/base/members/users/add'; $this->assertEqual($expected, $result); - - $result = Router::parse('/posts/index'); - $expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'index'); - $this->assertEqual($expected, $result); } /** @@ -2068,17 +1995,12 @@ class RouterTest extends CakeTestCase { public function testRegexRouteMatching() { Router::connect('/:locale/:controller/:action/*', array(), array('locale' => 'dan|eng')); - $result = Router::parse('/test/test_action'); - $expected = array('pass' => array(), 'named' => array(), 'controller' => 'test', 'action' => 'test_action', 'plugin' => null); - $this->assertEqual($expected, $result); - $result = Router::parse('/eng/test/test_action'); $expected = array('pass' => array(), 'named' => array(), 'locale' => 'eng', 'controller' => 'test', 'action' => 'test_action', 'plugin' => null); $this->assertEqual($expected, $result); $result = Router::parse('/badness/test/test_action'); - $expected = array('pass' => array('test_action'), 'named' => array(), 'controller' => 'badness', 'action' => 'test', 'plugin' => null); - $this->assertEqual($expected, $result); + $this->assertEquals(array(), $result); Router::reload(); Router::connect('/:locale/:controller/:action/*', array(), array('locale' => 'dan|eng')); @@ -2196,7 +2118,6 @@ class RouterTest extends CakeTestCase { * @return void */ public function testDefaultsMethod() { - Router::defaults(false); Router::connect('/test/*', array('controller' => 'pages', 'action' => 'display', 2)); $result = Router::parse('/posts/edit/5'); $this->assertFalse(isset($result['controller'])); @@ -2216,6 +2137,7 @@ class RouterTest extends CakeTestCase { ), true); CakePlugin::loadAll(); Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; $result = Router::url(array('plugin' => 'plugin_js', 'controller' => 'js_file', 'action' => 'index')); $this->assertEqual($result, '/plugin_js/js_file'); From f0819d364cd525ac1f4f19303f165b73cf0af208 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 16 Jul 2011 23:42:46 -0400 Subject: [PATCH 19/25] Updating Dispatcher tests for changes in Router. --- lib/Cake/Test/Case/Routing/DispatcherTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/Cake/Test/Case/Routing/DispatcherTest.php b/lib/Cake/Test/Case/Routing/DispatcherTest.php index 6e044e8af..7ce9694a2 100644 --- a/lib/Cake/Test/Case/Routing/DispatcherTest.php +++ b/lib/Cake/Test/Case/Routing/DispatcherTest.php @@ -651,6 +651,7 @@ class DispatcherTest extends CakeTestCase { Router::reload(); Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); + Router::connect('/:controller/:action/*'); $_GET = array('coffee' => 'life', 'sleep' => 'sissies'); $Dispatcher = new Dispatcher(); @@ -680,6 +681,8 @@ class DispatcherTest extends CakeTestCase { * @return void */ public function testMissingController() { + Router::connect('/:controller/:action/*'); + $Dispatcher = new TestDispatcher(); Configure::write('App.baseUrl', '/index.php'); $url = new CakeRequest('some_controller/home/param:value/param2:value2'); @@ -726,6 +729,7 @@ class DispatcherTest extends CakeTestCase { unset($Dispatcher); + require CAKE . 'Config' . DS . 'routes.php'; $Dispatcher = new TestDispatcher(); Configure::write('App.baseUrl', '/timesheets/index.php'); @@ -756,6 +760,7 @@ class DispatcherTest extends CakeTestCase { * @return void */ public function testDispatchActionReturnsResponse() { + Router::connect('/:controller/:action'); $Dispatcher = new Dispatcher(); $request = new CakeRequest('some_pages/responseGenerator'); $response = $this->getMock('CakeResponse', array('_sendHeader')); @@ -892,6 +897,7 @@ class DispatcherTest extends CakeTestCase { Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; $Dispatcher = new TestDispatcher(); $Dispatcher->base = false; @@ -914,6 +920,7 @@ class DispatcherTest extends CakeTestCase { Configure::write('Routing.prefixes', array('admin')); Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; $Dispatcher = new TestDispatcher(); $url = new CakeRequest('admin/my_plugin/my_plugin/add/5/param:value/param2:value2'); @@ -936,6 +943,7 @@ class DispatcherTest extends CakeTestCase { Configure::write('Routing.prefixes', array('admin')); CakePlugin::load('ArticlesTest', array('path' => '/fake/path')); Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; $Dispatcher = new TestDispatcher(); @@ -1313,6 +1321,7 @@ class DispatcherTest extends CakeTestCase { Router::reload(); Router::connect('/', array('controller' => 'test_cached_pages', 'action' => 'index')); + Router::connect('/:controller/:action/*'); App::build(array( 'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS), From be98e0b962b5436f638eb3ba3ee17801149489ed Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 16 Jul 2011 23:47:12 -0400 Subject: [PATCH 20/25] Updating Folder tests for new file. Converting assertIdentical to assertSame. --- lib/Cake/Test/Case/Utility/FolderTest.php | 50 +++++++++++------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/FolderTest.php b/lib/Cake/Test/Case/Utility/FolderTest.php index 8818c0bb1..c090ca783 100644 --- a/lib/Cake/Test/Case/Utility/FolderTest.php +++ b/lib/Cake/Test/Case/Utility/FolderTest.php @@ -342,16 +342,16 @@ class FolderTest extends CakeTestCase { ); $result = $Folder->tree(CAKE . 'Config', false); - $this->assertIdentical(array_diff($expected[0], $result[0]), array()); - $this->assertIdentical(array_diff($result[0], $expected[0]), array()); + $this->assertSame(array_diff($expected[0], $result[0]), array()); + $this->assertSame(array_diff($result[0], $expected[0]), array()); $result = $Folder->tree(CAKE . 'Config', false, 'dir'); - $this->assertIdentical(array_diff($expected[0], $result), array()); - $this->assertIdentical(array_diff($expected[0], $result), array()); + $this->assertSame(array_diff($expected[0], $result), array()); + $this->assertSame(array_diff($expected[0], $result), array()); $result = $Folder->tree(CAKE . 'Config', false, 'files'); - $this->assertIdentical(array_diff($expected[1], $result), array()); - $this->assertIdentical(array_diff($expected[1], $result), array()); + $this->assertSame(array_diff($expected[1], $result), array()); + $this->assertSame(array_diff($expected[1], $result), array()); } /** @@ -488,29 +488,29 @@ class FolderTest extends CakeTestCase { $Folder->cd(CAKE . 'Config'); $result = $Folder->find(); $expected = array('config.php'); - $this->assertIdentical(array_diff($expected, $result), array()); - $this->assertIdentical(array_diff($expected, $result), array()); + $this->assertSame(array_diff($expected, $result), array()); + $this->assertSame(array_diff($expected, $result), array()); $result = $Folder->find('.*', true); - $expected = array('config.php'); - $this->assertIdentical($expected, $result); + $expected = array('config.php', 'routes.php'); + $this->assertSame($expected, $result); $result = $Folder->find('.*\.php'); $expected = array('config.php'); - $this->assertIdentical(array_diff($expected, $result), array()); - $this->assertIdentical(array_diff($expected, $result), array()); + $this->assertSame(array_diff($expected, $result), array()); + $this->assertSame(array_diff($expected, $result), array()); $result = $Folder->find('.*\.php', true); - $expected = array('config.php'); - $this->assertIdentical($expected, $result); + $expected = array('config.php', 'routes.php'); + $this->assertSame($expected, $result); $result = $Folder->find('.*ig\.php'); $expected = array('config.php'); - $this->assertIdentical($expected, $result); + $this->assertSame($expected, $result); $result = $Folder->find('config\.php'); $expected = array('config.php'); - $this->assertIdentical($expected, $result); + $this->assertSame($expected, $result); $Folder->cd(TMP); $file = new File($Folder->pwd() . DS . 'paths.php', true); @@ -518,12 +518,12 @@ class FolderTest extends CakeTestCase { $Folder->cd('testme'); $result = $Folder->find('paths\.php'); $expected = array(); - $this->assertIdentical($expected, $result); + $this->assertSame($expected, $result); $Folder->cd($Folder->pwd() . '/..'); $result = $Folder->find('paths\.php'); $expected = array('paths.php'); - $this->assertIdentical($expected, $result); + $this->assertSame($expected, $result); $Folder->cd(TMP); $Folder->delete($Folder->pwd() . DS . 'testme'); @@ -543,14 +543,14 @@ class FolderTest extends CakeTestCase { $expected = array( CAKE . 'Config' . DS . 'config.php' ); - $this->assertIdentical(array_diff($expected, $result), array()); - $this->assertIdentical(array_diff($expected, $result), array()); + $this->assertSame(array_diff($expected, $result), array()); + $this->assertSame(array_diff($expected, $result), array()); $result = $Folder->findRecursive('(config|paths)\.php', true); $expected = array( CAKE . 'Config' . DS . 'config.php' ); - $this->assertIdentical($expected, $result); + $this->assertSame($expected, $result); $Folder->cd(TMP); $Folder->create($Folder->pwd() . DS . 'testme'); @@ -560,7 +560,7 @@ class FolderTest extends CakeTestCase { $Folder->cd(TMP . 'sessions'); $result = $Folder->findRecursive('paths\.php'); $expected = array(); - $this->assertIdentical($expected, $result); + $this->assertSame($expected, $result); $Folder->cd(TMP . 'testme'); $File = new File($Folder->pwd() . DS . 'my.php'); @@ -572,15 +572,15 @@ class FolderTest extends CakeTestCase { TMP . 'testme' . DS . 'my.php', TMP . 'testme' . DS . 'paths.php' ); - $this->assertIdentical(array_diff($expected, $result), array()); - $this->assertIdentical(array_diff($expected, $result), array()); + $this->assertSame(array_diff($expected, $result), array()); + $this->assertSame(array_diff($expected, $result), array()); $result = $Folder->findRecursive('(paths|my)\.php', true); $expected = array( TMP . 'testme' . DS . 'my.php', TMP . 'testme' . DS . 'paths.php' ); - $this->assertIdentical($expected, $result); + $this->assertSame($expected, $result); $Folder->cd(CAKE . 'Config'); $Folder->cd(TMP); From 16073b4e44e17d8596f16c6998f20677558810d9 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 17 Jul 2011 20:31:21 -0400 Subject: [PATCH 21/25] Fixing notice errors in Router. Updating AuthComponent tests for changes in Router behavior. --- lib/Cake/Routing/Router.php | 4 ++-- .../Test/Case/Controller/Component/AuthComponentTest.php | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php index 0747bdcb9..3b74847e1 100644 --- a/lib/Cake/Routing/Router.php +++ b/lib/Cake/Routing/Router.php @@ -921,8 +921,8 @@ class Router { } else { $url = $params['url']; } - $pass = $params['pass']; - $named = $params['named']; + $pass = isset($params['pass']) ? $params['pass'] : array(); + $named = isset($params['named']) ? $params['named'] : array(); unset( $params['pass'], $params['named'], $params['paging'], $params['models'], $params['url'], $url['url'], diff --git a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php index abfb9059b..2626d1027 100644 --- a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php @@ -292,12 +292,12 @@ class AjaxAuthController extends Controller { } /** -* AuthTest class +* AuthComponentTest class * * @package cake * @package cake.tests.cases.libs.controller.components */ -class AuthTest extends CakeTestCase { +class AuthComponentTest extends CakeTestCase { /** * name property @@ -351,6 +351,7 @@ class AuthTest extends CakeTestCase { $this->initialized = true; Router::reload(); + Router::connect('/:controller/:action/*'); $User = ClassRegistry::init('AuthUser'); $User->updateAll(array('password' => $User->getDataSource()->value(Security::hash('cake', null, true)))); @@ -925,6 +926,7 @@ class AuthTest extends CakeTestCase { $prefixes = Configure::read('Routing.prefixes'); Configure::write('Routing.prefixes', array('admin')); Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; $url = '/admin/auth_test/add'; $this->Auth->request->addParams(Router::parse($url)); @@ -977,6 +979,7 @@ class AuthTest extends CakeTestCase { $admin = Configure::read('Routing.prefixes'); Configure::write('Routing.prefixes', array('admin')); Router::reload(); + require CAKE . 'Config' . DS . 'routes.php'; $url = '/admin/auth_test/login'; $this->Auth->request->addParams(Router::parse($url)); From c37c641b4a476c668e9ff9a2c5cdc89d534bc180 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 18 Jul 2011 07:33:16 -0400 Subject: [PATCH 22/25] Fixing failing tests because of core routes not being loaded. --- lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php b/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php index c0403141b..ad20fbaa7 100644 --- a/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php +++ b/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php @@ -273,7 +273,9 @@ class ControllerTestCaseTest extends CakeTestCase { * Tests using loaded routes during tests */ public function testUseRoutes() { + Router::connect('/:controller/:action/*'); include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php'; + $controller = $this->Case->generate('TestsApps'); $controller->Components->load('RequestHandler'); $result = $this->Case->testAction('/tests_apps/index.json', array('return' => 'view')); @@ -302,6 +304,7 @@ class ControllerTestCaseTest extends CakeTestCase { * @expectedException MissingActionException */ public function testSkipRoutes() { + Router::connect('/:controller/:action/*'); include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php'; $this->Case->loadRoutes = false; From c8647b227ac8193fd6bf05647f3306ebc1376289 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Mon, 18 Jul 2011 21:30:18 -0400 Subject: [PATCH 23/25] Moving plugin route loading to app/Config/routes.php Its old position would end up with plugin routes being loaded after the core fallback routes. --- app/Config/routes.php | 9 ++++++++- lib/Cake/Routing/Dispatcher.php | 1 - 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Config/routes.php b/app/Config/routes.php index e41f4a667..0a7a011b8 100644 --- a/app/Config/routes.php +++ b/app/Config/routes.php @@ -32,6 +32,13 @@ Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); /** - * Load the CakePHP default routes. + * Load all plugin routes. See the CakePlugin documentation on + * how to customize the loading of plugin routes. + */ + CakePlugin::routes(); + +/** + * Load the CakePHP default routes. Remove this if you do not want to use + * the built-in default routes. */ require CAKE . 'Config' . DS . 'routes.php'; diff --git a/lib/Cake/Routing/Dispatcher.php b/lib/Cake/Routing/Dispatcher.php index 0203b9ff1..0c32e2e7d 100644 --- a/lib/Cake/Routing/Dispatcher.php +++ b/lib/Cake/Routing/Dispatcher.php @@ -204,7 +204,6 @@ class Dispatcher { */ protected function _loadRoutes() { include APP . 'Config' . DS . 'routes.php'; - CakePlugin::routes(); } /** From 4101388069493e4d02f2a4e1c60bfe3c76689793 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Mon, 18 Jul 2011 21:33:14 -0400 Subject: [PATCH 24/25] Syncing skel directory with app/Config. --- .../Console/Templates/skel/Config/routes.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Console/Templates/skel/Config/routes.php b/lib/Cake/Console/Templates/skel/Config/routes.php index f2a360bf4..0a7a011b8 100644 --- a/lib/Cake/Console/Templates/skel/Config/routes.php +++ b/lib/Cake/Console/Templates/skel/Config/routes.php @@ -1,6 +1,6 @@ 'pages', 'action' => 'display', 'home')); - /** * ...and connect the rest of 'Pages' controller's urls. */ Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); + +/** + * Load all plugin routes. See the CakePlugin documentation on + * how to customize the loading of plugin routes. + */ + CakePlugin::routes(); + +/** + * Load the CakePHP default routes. Remove this if you do not want to use + * the built-in default routes. + */ + require CAKE . 'Config' . DS . 'routes.php'; From ec3de84c4e1357b1b80ee760b51d729d9afbb1a9 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 19 Jul 2011 22:51:49 -0400 Subject: [PATCH 25/25] Removing getResponse, its not used and it doesn't serve much purpose. --- lib/Cake/Controller/Controller.php | 9 ----- lib/Cake/Controller/Scaffold.php | 2 +- .../Case/Console/Command/ApiShellTest.php | 33 +++++++++---------- .../Case/Controller/PagesControllerTest.php | 4 +-- 4 files changed, 19 insertions(+), 29 deletions(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index c9742662e..0b7050d71 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -580,15 +580,6 @@ class Controller extends Object { return true; } -/** - * Gets the response object for this controller. Will construct the response if it has not already been built. - * - * @return CakeResponse - */ - public function getResponse() { - return $this->response; - } - /** * Perform the startup process for this controller. * Fire the Components and Controller callbacks in the correct order. diff --git a/lib/Cake/Controller/Scaffold.php b/lib/Cake/Controller/Scaffold.php index f1add0a3f..c3d7d05f6 100644 --- a/lib/Cake/Controller/Scaffold.php +++ b/lib/Cake/Controller/Scaffold.php @@ -159,7 +159,7 @@ class Scaffold { */ protected function _output() { $this->controller->afterFilter(); - $this->controller->getResponse()->send(); + $this->controller->response->send(); } /** diff --git a/lib/Cake/Test/Case/Console/Command/ApiShellTest.php b/lib/Cake/Test/Case/Console/Command/ApiShellTest.php index 87e92441d..8fd07ed4d 100644 --- a/lib/Cake/Test/Case/Console/Command/ApiShellTest.php +++ b/lib/Cake/Test/Case/Console/Command/ApiShellTest.php @@ -62,23 +62,22 @@ class ApiShellTest extends CakeTestCase { '5. constructClasses()', '6. disableCache()', '7. flash($message, $url, $pause = 1, $layout = \'flash\')', - '8. getResponse()', - '9. header($status)', - '10. httpCodes($code = NULL)', - '11. invokeAction($request)', - '12. loadModel($modelClass = NULL, $id = NULL)', - '13. paginate($object = NULL, $scope = array (), $whitelist = array ())', - '14. postConditions($data = array (), $op = NULL, $bool = \'AND\', $exclusive = false)', - '15. redirect($url, $status = NULL, $exit = true)', - '16. referer($default = NULL, $local = false)', - '17. render($view = NULL, $layout = NULL)', - '18. set($one, $two = NULL)', - '19. setAction($action)', - '20. setRequest($request)', - '21. shutdownProcess()', - '22. startupProcess()', - '23. validate()', - '24. validateErrors()' + '8. header($status)', + '9. httpCodes($code = NULL)', + '10. invokeAction($request)', + '11. loadModel($modelClass = NULL, $id = NULL)', + '12. paginate($object = NULL, $scope = array (), $whitelist = array ())', + '13. postConditions($data = array (), $op = NULL, $bool = \'AND\', $exclusive = false)', + '14. redirect($url, $status = NULL, $exit = true)', + '15. referer($default = NULL, $local = false)', + '16. render($view = NULL, $layout = NULL)', + '17. set($one, $two = NULL)', + '18. setAction($action)', + '19. setRequest($request)', + '20. shutdownProcess()', + '21. startupProcess()', + '22. validate()', + '23. validateErrors()' ); $this->Shell->expects($this->at(2))->method('out')->with($expected); diff --git a/lib/Cake/Test/Case/Controller/PagesControllerTest.php b/lib/Cake/Test/Case/Controller/PagesControllerTest.php index c83e95c92..d4815174c 100644 --- a/lib/Cake/Test/Case/Controller/PagesControllerTest.php +++ b/lib/Cake/Test/Case/Controller/PagesControllerTest.php @@ -52,12 +52,12 @@ class PagesControllerTest extends CakeTestCase { $Pages->viewPath = 'Posts'; $Pages->display('index'); - $this->assertPattern('/posts index/', $Pages->getResponse()->body()); + $this->assertPattern('/posts index/', $Pages->response->body()); $this->assertEqual($Pages->viewVars['page'], 'index'); $Pages->viewPath = 'Themed'; $Pages->display('TestTheme', 'Posts', 'index'); - $this->assertPattern('/posts index themed view/', $Pages->getResponse()->body()); + $this->assertPattern('/posts index themed view/', $Pages->response->body()); $this->assertEqual($Pages->viewVars['page'], 'TestTheme'); $this->assertEqual($Pages->viewVars['subpage'], 'Posts'); }