Merge branch 'request-response' into 2.0

This commit is contained in:
mark_story 2011-07-23 14:23:06 -04:00
commit 3589a17321
23 changed files with 594 additions and 572 deletions

View file

@ -30,3 +30,15 @@
* ...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';

View file

@ -76,5 +76,6 @@
}
App::uses('Dispatcher', 'Routing');
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest());
$Dispatcher->dispatch(new CakeRequest(), new CakeResponse(array('charset' => Configure::read('App.encoding'))));

View file

@ -0,0 +1,83 @@
<?php
/**
* Default routes that CakePHP provides as catch all routes.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake.config
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* 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 by deleting the require inside APP/Config/routes.php.
*/
$prefixes = Router::prefixes();
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 ($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);
}

View file

@ -1,6 +1,6 @@
<?php
/**
* Routes Configuration
* Routes configuration
*
* In this file, you set up routes to your controllers and their actions.
* Routes are very important mechanism that allows you to freely connect
@ -20,15 +20,25 @@
* @since CakePHP(tm) v 0.2.9
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Here, we are connecting '/' (base path) to controller called 'Pages',
* its action called 'display', and we pass a param to select the view file
* to use (in this case, /app/View/Pages/home.ctp)...
*/
Router::connect('/', array('controller' => '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';

View file

@ -77,4 +77,4 @@
App::uses('Dispatcher', 'Routing');
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest());
$Dispatcher->dispatch(new CakeRequest(), new CakeResponse(array('charset' => Configure::read('App.encoding'))));

View file

@ -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'));

View file

@ -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();
}
@ -439,6 +442,72 @@ 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 $this->_getScaffold($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,
* 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.
* @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;
}
/**
* 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.
*
@ -511,18 +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() {
if (empty($this->response)) {
$this->response = new $this->_responseClass(array('charset' => Configure::read('App.encoding')));
}
return $this->response;
}
/**
* Perform the startup process for this controller.
* Fire the Components and Controller callbacks in the correct order.
@ -790,7 +847,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) {
@ -828,7 +885,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;
}
/**
@ -879,7 +937,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);
}
/**

View file

@ -159,7 +159,7 @@ class Scaffold {
*/
protected function _output() {
$this->controller->afterFilter();
$this->controller->getResponse()->send();
$this->controller->response->send();
}
/**

View file

@ -87,7 +87,7 @@ class Object {
}
$dispatcher = new Dispatcher();
return $dispatcher->dispatch($request, $extra);
return $dispatcher->dispatch($request, new CakeResponse(), $extra);
}
/**

View file

@ -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;

View file

@ -654,4 +654,14 @@ class CakeResponse {
public function download($filename) {
$this->header('Content-Disposition', 'attachment; filename="' . $filename . '"');
}
}
/**
* String conversion. Fetches the response body as a string.
* Does *not* send headers.
*
* @return string
*/
public function __toString() {
return (string)$this->_body;
}
}

View file

@ -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(
@ -92,35 +93,7 @@ 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);
}
/**
* 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;
return $this->_invoke($controller, $request, $response);
}
/**
@ -133,26 +106,19 @@ 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();
$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']
));
$render = true;
$result = $controller->invokeAction($request);
if ($result instanceof CakeResponse) {
$render = false;
$response = $result;
}
$result = call_user_func_array(array(&$controller, $request->params['action']), $request->params['pass']);
$response = $controller->getResponse();
if ($controller->autoRender) {
$controller->render();
if ($render && $controller->autoRender) {
$response = $controller->render();
} elseif ($response->body() === null) {
$response->body($result);
}
@ -192,15 +158,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);
}
/**
@ -237,7 +204,6 @@ class Dispatcher {
*/
protected function _loadRoutes() {
include APP . 'Config' . DS . 'routes.php';
CakePlugin::routes();
}
/**
@ -270,10 +236,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 +253,9 @@ class Dispatcher {
strpos($url, 'cjs/') === 0 ||
preg_match('#^/((theme/[^/]+)/cjs/)|(([^/]+)(?<!js)/cjs)/#i', $url)
);
if (!$this->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 +290,7 @@ class Dispatcher {
}
if ($assetFile !== null) {
$this->_deliverAsset($assetFile, $ext);
$this->_deliverAsset($response, $assetFile, $ext);
return true;
}
return false;
@ -335,23 +299,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);

View file

@ -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
@ -1024,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'],

View file

@ -62,9 +62,9 @@ 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)',
'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)',

View file

@ -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);
}
/**
@ -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
@ -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);
@ -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));
@ -960,7 +962,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));
@ -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));
@ -1024,7 +1027,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(

View file

@ -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

View file

@ -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,26 @@ class TestController extends ControllerTestAppController {
'test2Id' => $test2Id
);
}
public function returner() {
return 'I am from the controller.';
}
protected function protected_m() {
}
private function private_m() {
}
public function _hidden() {
}
public function admin_add() {
}
}
/**
@ -303,7 +323,6 @@ class TestController extends ControllerTestAppController {
* @package cake.tests.cases.libs.controller
*/
class TestComponent extends Object {
/**
* beforeRedirect method
*
@ -418,7 +437,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));
@ -524,8 +544,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();
@ -617,21 +636,21 @@ 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');
$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);
$Controller = new TestController($request, new CakeResponse());
$Controller->helpers = array('Html');
$Controller->constructClasses();
$Controller->ControllerComment->validationErrors = array('title' => 'tooShort');
@ -668,7 +687,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();
@ -676,7 +695,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();
}
@ -689,7 +708,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 +1138,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 +1159,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 +1256,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();
@ -1258,4 +1278,124 @@ 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);
}
/**
* 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);
}
}

View file

@ -48,16 +48,16 @@ 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');
$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');
}

View file

@ -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,12 +49,8 @@ class TestDispatcher extends Dispatcher {
* @param mixed $request
* @return void
*/
protected function _invoke(Controller $controller, CakeRequest $request) {
if ($result = parent::_invoke($controller, $request)) {
if ($result[0] === 'missingAction') {
return $result;
}
}
protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response) {
$result = parent::_invoke($controller, $request, $response);
return $controller;
}
@ -164,22 +159,14 @@ class SomePagesController extends AppController {
}
/**
* protected method
* Test method for returning responses.
*
* @return void
* @return CakeResponse
*/
protected function _protected() {
return true;
public function responseGenerator() {
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';
}
}
/**
@ -664,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();
@ -688,74 +676,19 @@ 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');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->fail('No exception thrown');
} catch (MissingControllerException $e) {
$this->assertEquals('Controller class SomeControllerController could not be found.', $e->getMessage());
}
}
Router::connect('/:controller/:action/*');
/**
* testPrivate method
*
* @return void
*/
public function testPrivate() {
$Dispatcher = new TestDispatcher();
Configure::write('App.baseUrl','/index.php');
$url = new CakeRequest('some_pages/_protected/param:value/param2:value2');
try {
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->fail('No exception thrown');
} catch (PrivateActionException $e) {
$this->assertEquals(
'Private Action SomePagesController::_protected() is not directly accessible.', $e->getMessage()
);
}
}
/**
* testMissingAction method
*
* @return void
*/
public function testMissingAction() {
$Dispatcher = new TestDispatcher();
Configure::write('App.baseUrl', '/index.php');
$url = new CakeRequest('some_pages/home/param:value/param2:value2');
$url = new CakeRequest('some_controller/home/param:value/param2:value2');
$response = $this->getMock('CakeResponse');
try {
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
$this->fail('No exception thrown');
} catch (MissingActionException $e) {
$this->assertEquals('Action SomePagesController::home() could not be found.', $e->getMessage());
}
}
/**
* test that methods declared in Controller are treated as missing methods.
*
* @return void
*/
public function testMissingActionFromBaseClassMethods() {
$Dispatcher = new TestDispatcher();
Configure::write('App.baseUrl','/index.php');
$url = new CakeRequest('some_pages/redirect/param:value/param2:value2');
try {
$controller = $Dispatcher->dispatch($url, 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));
}
/**
@ -770,8 +703,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 +715,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';
@ -795,30 +729,49 @@ class DispatcherTest extends CakeTestCase {
unset($Dispatcher);
require CAKE . 'Config' . DS . 'routes.php';
$Dispatcher = new TestDispatcher();
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');
}
/**
* Test that Dispatcher handles actions that return response objects.
*
* @return void
*/
public function testDispatchActionReturnsResponse() {
Router::connect('/:controller/:action');
$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
*
@ -830,9 +783,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 +816,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 +854,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 +863,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);
}
/**
@ -919,9 +875,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';
@ -933,8 +886,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');
@ -943,6 +897,7 @@ class DispatcherTest extends CakeTestCase {
Router::reload();
require CAKE . 'Config' . DS . 'routes.php';
$Dispatcher = new TestDispatcher();
$Dispatcher->base = false;
@ -953,7 +908,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');
@ -965,10 +920,13 @@ 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');
$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');
@ -985,10 +943,11 @@ 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();
$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 +981,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 +1010,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');
@ -1075,62 +1038,36 @@ 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, array('return'=> 1));
$this->fail('No exception.');
} catch (MissingActionException $e) {
$this->assertEquals('Action MyPluginController::not_here() could not be found.', $e->getMessage());
}
Router::reload();
$Dispatcher = new TestDispatcher();
$Dispatcher->base = false;
$url = new CakeRequest('my_plugin/param:value/param2:value2');
try {
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
$this->fail('No exception.');
} catch (MissingActionException $e) {
$this->assertEquals('Action MyPluginController::param:value() could not be found.', $e->getMessage());
}
$controller = $Dispatcher->dispatch($url, $response, array('return'=> 1));
}
/**
* testPrefixProtection method
* testAutomaticPluginControllerMissingActionDispatch method
*
* @expectedException MissingActionException
* @expectedExceptionMessage Action MyPluginController::param:value() could not be found.
* @return void
*/
public function testPrefixProtection() {
$_POST = array();
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
public function testAutomaticPluginControllerIndexMissingAction() {
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');
try {
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
$this->fail('No exception.');
} catch (PrivateActionException $e) {
$this->assertEquals(
'Private Action TestDispatchPagesController::admin_index() is not directly accessible.',
$e->getMessage()
);
}
$url = new CakeRequest('my_plugin/param:value/param2:value2');
$response = $this->getMock('CakeResponse');
$controller = $Dispatcher->dispatch($url, $response, array('return'=> 1));
}
/**
@ -1148,7 +1085,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'));
@ -1166,19 +1104,19 @@ 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');
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 +1144,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 +1169,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 +1272,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 +1291,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
@ -1380,11 +1318,10 @@ 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'));
Router::connect('/:controller/:action/*');
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS),
@ -1392,9 +1329,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 +1354,7 @@ class DispatcherTest extends CakeTestCase {
);
ob_start();
$dispatcher->dispatch($request);
$dispatcher->dispatch($request, $response);
$out = ob_get_clean();
ob_start();
@ -1434,7 +1372,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 +1390,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 +1408,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 +1426,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();

View file

@ -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');

View file

@ -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;

View file

@ -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);

View file

@ -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;
}
}
}