Skip to content
Permalink
Browse files

Added ControllerTestCase class for testing controllers. Fixes #1244

  • Loading branch information...
jeremyharris committed Dec 15, 2010
1 parent 10bf41a commit b9143dc7d451d6307aebbf1a74dbaf60248204dd
@@ -301,7 +301,7 @@ public function __construct($request = null) {
$this->methods = array_diff($childMethods, $parentMethods);
if ($request instanceof CakeRequest) {
$this->_setRequest($request);
$this->setRequest($request);
}
$this->getResponse();
parent::__construct();
@@ -377,7 +377,7 @@ public function __set($name, $value) {
* @param CakeRequest $request
* @return void
*/
protected function _setRequest(CakeRequest $request) {
public function setRequest(CakeRequest $request) {
$this->request = $request;
$this->plugin = isset($request->params['plugin']) ? $request->params['plugin'] : null;
@@ -99,8 +99,8 @@ public function dispatch(CakeRequest $request, $additionalParams = array()) {
return;
}
$request = $this->parseParams($request, $additionalParams);
$controller = $this->_getController($request);
$this->request = $this->parseParams($request, $additionalParams);
$controller = $this->_getController($this->request);
if (!is_object($controller)) {
Router::setRequestInfo($request);
@@ -198,7 +198,7 @@ public function parseParams(CakeRequest $request, $additionalParams = array()) {
if (count(Router::$routes) > 0) {
$namedExpressions = Router::getNamedExpressions();
extract($namedExpressions);
include CONFIGS . 'routes.php';
$this->__loadRoutes();
}
$params = Router::parse($request->url);
@@ -250,6 +250,16 @@ protected function _loadController($request) {
return false;
}
/**
* Loads route configuration
*
* @return void
* @access protected
*/
protected function __loadRoutes() {
include CONFIGS . 'routes.php';
}
/**
* Outputs cached dispatch view cache
*
@@ -221,6 +221,20 @@ public function unload($name) {
$this->_enabled = array_values(array_diff($this->_enabled, (array)$name));
}
/**
* Adds or overwrites an instatiated object to the collection
*
* @param string $name Name of the object
* @param Object $object The object to use
*/
public function set($name = null, $object = null) {
if (!empty($name) && !empty($object)) {
list($plugin, $name) = pluginSplit($name);
$this->_loaded[$name] = $object;
}
return $this->_loaded;
}
/**
* Normalizes an object array, creates an array that makes lazy loading
* easier
@@ -250,6 +250,9 @@ public static function connect($route, $defaults = array(), $options = array())
throw new RouterException(__('Route classes must extend CakeRoute'));
}
unset($options['routeClass']);
if ($routeClass == 'RedirectRoute' && isset($defaults['redirect'])) {
$defaults = $defaults['redirect'];
}
}
self::$routes[] = new $routeClass($route, $defaults, $options);
return self::$routes;
@@ -284,9 +287,12 @@ public static function connect($route, $defaults = array(), $options = array())
* @see routes
* @return array Array of routes
*/
public static function redirect($route, $url, $options) {
public static function redirect($route, $url, $options = array()) {
App::import('Core', 'route/RedirectRoute');
$options['routeClass'] = 'RedirectRoute';
if (is_string($url)) {
$url = array('redirect' => $url);
}
return self::connect($route, $url, $options);
}
@@ -40,6 +40,7 @@ public static function suite() {
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_test_case.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_test_fixture.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'html_coverage_report.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'controller_test_case.test.php');
return $suite;
}
}
Oops, something went wrong.

0 comments on commit b9143dc

Please sign in to comment.
You can’t perform that action at this time.