diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 54cf20dc7..cd5ae451a 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -134,7 +134,9 @@ class Dispatcher { if (!is_object($controller)) { Router::setRequestInfo($request); - throw new MissingControllerException(Inflector::camelize($request->params['controller']) . 'Controller'); + throw new MissingControllerException(array( + 'controller' => Inflector::camelize($request->params['controller']) . 'Controller' + )); } $privateAction = $request->params['action'][0] === '_'; $prefixes = Router::prefixes(); @@ -151,12 +153,10 @@ class Dispatcher { Router::setRequestInfo($request); if ($privateAction) { - $message = sprintf( - '%s::%s()', - Inflector::camelize($request->params['controller']) . "Controller", - $request->params['action'] - ); - throw new PrivateActionException($message); + throw new PrivateActionException(array( + 'controller' => Inflector::camelize($request->params['controller']) . "Controller", + 'action' => $request->params['action'] + )); } return $this->_invoke($controller, $request); @@ -184,12 +184,10 @@ class Dispatcher { App::import('Controller', 'Scaffold', false); return new Scaffold($controller, $request); } - $message = sprintf( - '%s::%s()', - Inflector::camelize($request->params['controller']) . "Controller", - $request->params['action'] - ); - throw new MissingActionException($message); + 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']); $response = $controller->getResponse(); diff --git a/cake/libs/controller/component_collection.php b/cake/libs/controller/component_collection.php index f0fc314e8..a4aea463b 100644 --- a/cake/libs/controller/component_collection.php +++ b/cake/libs/controller/component_collection.php @@ -54,10 +54,16 @@ class ComponentCollection extends ObjectCollection { $componentClass = $name . 'Component'; if (!class_exists($componentClass)) { if (!App::import('Component', $component)) { - throw new MissingComponentFileException(Inflector::underscore($component) . '.php'); + throw new MissingComponentFileException(array( + 'file' => Inflector::underscore($component) . '.php', + 'class' => $componentClass + )); } if (!class_exists($componentClass)) { - throw new MissingComponentFileException($component); + throw new MissingComponentFileException(array( + 'file' => Inflector::underscore($component) . '.php', + 'class' => $componentClass + )); } } $this->_loaded[$name] = new $componentClass($this, $settings); diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 9d5779746..a5c3d7551 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -414,11 +414,13 @@ class Scaffold { break; } } else { - $message = sprintf('%s::%s()', $this->controller->name . "Controller", $request->action); - throw new MissingActionException($message); + throw new MissingActionException(array( + 'controller' => $this->controller->name, + 'action' => $request->action + )); } } else { - throw new MissingDatabaseException($this->ScaffoldModel->useDbConfig); + throw new MissingDatabaseException(array('connection' => $this->ScaffoldModel->useDbConfig)); } } diff --git a/cake/libs/error_handler.php b/cake/libs/error_handler.php index 1d0502ee1..7b3235a51 100644 --- a/cake/libs/error_handler.php +++ b/cake/libs/error_handler.php @@ -40,6 +40,27 @@ class ErrorHandler { */ public $controller = null; +/** + * template to render for CakeException + * + * @var string + */ + public $template = ''; + +/** + * The method corresponding to the Exception this object is for. + * + * @var string + */ + public $method = ''; + +/** + * The exception being handled. + * + * @var Exception + */ + public $error = null; + /** * Class constructor. * @@ -54,27 +75,27 @@ class ErrorHandler { if (method_exists($this->controller, 'apperror')) { return $this->controller->appError($exception); } - $method = Inflector::variable(str_replace('Exception', '', get_class($exception))); + $method = $template = Inflector::variable(str_replace('Exception', '', get_class($exception))); - if (!in_array($method, get_class_methods($this))) { - $method = 'error'; + if ($exception instanceof CakeException && !in_array($method, get_class_methods($this))) { + $method = '_cakeError'; } - if ($method !== 'error') { - if (Configure::read('debug') == 0) { - $code = $exception->getCode(); - $parentClass = get_parent_class($this); - if ($parentClass != 'ErrorHandler') { - $method = 'error404'; - } - $parentMethods = (array)get_class_methods($parentClass); - if (in_array($method, $parentMethods)) { - $method = 'error404'; - } - if ($code == 500) { - $method = 'error500'; - } + + if ($method !== 'error' && Configure::read('debug') == 0) { + $code = $exception->getCode(); + $parentClass = get_parent_class($this); + if ($parentClass != 'ErrorHandler') { + $method = 'error404'; + } + $parentMethods = (array)get_class_methods($parentClass); + if (in_array($method, $parentMethods)) { + $method = 'error404'; + } + if ($code == 500) { + $method = 'error500'; } } + $this->template = $template; $this->method = $method; $this->error = $exception; } @@ -133,6 +154,24 @@ class ErrorHandler { $this->error404($error); } +/** + * Generic handler for the internal framework errors CakePHP can generate. + * + * @param CakeExeption $error + * @return void + */ + protected function _cakeError(CakeException $error) { + $url = Router::normalize($this->controller->request->here); + $code = $error->getCode(); + $this->controller->response->statusCode($code); + $this->controller->set(array( + 'code' => $code, + 'url' => h($url), + )); + $this->controller->set($error->getAttributes()); + $this->_outputMessage($this->template); + } + /** * Convenience method to display a 404 page. * @@ -167,207 +206,11 @@ class ErrorHandler { )); $this->_outputMessage('error500'); } -/** - * Renders the Missing Controller web page. - * - * @param array $params Parameters for controller - */ - public function missingController($error) { - $controllerName = str_replace('Controller', '', $error->getMessage()); - $this->controller->set(array( - 'controller' => $error->getMessage(), - 'controllerName' => $controllerName - )); - $this->_outputMessage('missingController'); - } /** - * Renders the Missing Action web page. - * - * @param array $params Parameters for controller - */ - public function missingAction($error) { - $message = $error->getMessage(); - list($controllerName, $action) = explode('::', $message); - $this->controller->set(array( - 'controller' => $controllerName, - 'action' => $action, - )); - $this->_outputMessage('missingAction'); - } - -/** - * Renders the Private Action web page. - * - * @param array $params Parameters for controller - */ - public function privateAction($error) { - $message = $error->getMessage(); - list($controllerName, $action) = explode('::', $message); - $this->controller->set(array( - 'controller' => $controllerName, - 'action' => $action - )); - $this->_outputMessage('privateAction'); - } - -/** - * Renders the Missing Table web page. - * - * @param array $params Parameters for controller - */ - public function missingTable($error) { - $this->controller->header("HTTP/1.0 500 Internal Server Error"); - $this->controller->set(array( - 'model' => $error->getModel(), - 'table' => $error->getTable(), - )); - $this->_outputMessage('missingTable'); - } - -/** - * Renders the Missing Database web page. - * - * @param array $params Parameters for controller - */ - public function missingDatabase($exception) { - $this->controller->header("HTTP/1.0 500 Internal Server Error"); - $this->controller->set(array( - 'code' => '500', - 'title' => __('Scaffold Missing Database Connection') - )); - $this->_outputMessage('missingScaffolddb'); - } - -/** - * Renders the Missing View web page. - * - * @param array $params Parameters for controller - */ - public function missingView($error) { - $this->controller->set(array( - 'file' => $error->getMessage(), - )); - $this->_outputMessage('missingView'); - } - -/** - * Renders the Missing Layout web page. - * - * @param array $params Parameters for controller - */ - public function missingLayout($error) { - $this->controller->layout = 'default'; - $this->controller->set(array( - 'file' => $error->getMessage(), - )); - $this->_outputMessage('missingLayout'); - } - -/** - * Renders the Database Connection web page. - * - * @param array $params Parameters for controller - */ - public function missingConnection($error) { - $this->controller->header("HTTP/1.0 500 Internal Server Error"); - $this->controller->set(array( - 'code' => '500', - 'model' => $error->getMessage(), - )); - $this->_outputMessage('missingConnection'); - } - -/** - * Renders the Missing Helper file web page. - * - * @param array $params Parameters for controller - */ - public function missingHelperFile($error) { - list($class, $ext) = explode('.', $error->getMessage()); - $this->controller->set(array( - 'className' => Inflector::camelize($class), - 'file' => $error->getMessage() - )); - $this->_outputMessage('missingHelperFile'); - } - -/** - * Renders the Missing Helper class web page. - * - * @param array $params Parameters for controller - */ - public function missingHelperClass($error) { - $class = $error->getMessage(); - $file = Inflector::underscore(str_replace('Helper', '', $error->getMessage())) . '.php'; - $this->controller->set(array( - 'className' => $class, - 'file' => $file, - )); - $this->_outputMessage('missingHelperClass'); - } - -/** - * Renders the Missing Behavior file web page. - * - * @param array $params Parameters for controller - */ - public function missingBehaviorFile($error) { - list($class, $ext) = explode('.', $error->getMessage()); - $this->controller->set(array( - 'className' => Inflector::camelize($class), - 'file' => $error->getMessage() - )); - $this->_outputMessage('missingBehaviorFile'); - } - -/** - * Renders the Missing Behavior class web page. - * - * @param array $params Parameters for controller - */ - public function missingBehaviorClass($error) { - $class = $error->getMessage(); - $file = Inflector::underscore(str_replace('Behavior', '', $error->getMessage())) . '.php'; - $this->controller->set(array( - 'className' => $class, - 'file' => $file, - )); - $this->_outputMessage('missingBehaviorClass'); - } - -/** - * Renders the Missing Component file web page. - * - * @param array $params Parameters for controller - */ - public function missingComponentFile($error) { - list($class, $ext) = explode('.', $error->getMessage()); - $this->controller->set(array( - 'className' => Inflector::camelize($class), - 'file' => $error->getMessage() - )); - $this->_outputMessage('missingComponentFile'); - } - -/** - * Renders the Missing Component class web page. - * - * @param array $params Parameters for controller - */ - public function missingComponentClass($error) { - $class = $error->getMessage(); - $file = Inflector::underscore(str_replace('Component', '', $error->getMessage())) . '.php'; - $this->controller->set(array( - 'className' => $class, - 'file' => $file, - )); - $this->_outputMessage('missingComponentClass'); - } - -/** - * Output message + * Generate the response using the controller object. * + * @param string $template The template to render. */ protected function _outputMessage($template) { $this->controller->render($template); diff --git a/cake/libs/exceptions.php b/cake/libs/exceptions.php index 51361d6c3..fcf324f6f 100644 --- a/cake/libs/exceptions.php +++ b/cake/libs/exceptions.php @@ -18,38 +18,84 @@ * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ + + +class Error404Exception extends RuntimeException { + public function __construct($message, $code = 404) { + if (empty($message)) { + $message = __('Not Found'); + } + parent::__construct($message, $code); + } +} +class Error500Exception extends CakeException { + public function __construct($message, $code = 500) { + if (empty($message)) { + $message = __('Internal Server Error'); + } + parent::__construct($message, $code); + } +} + /** * CakeException is used a base class for CakePHP's internal exceptions. * In general framework errors are interpreted as 500 code errors. * * @package cake.libs */ -class CakeException extends RuntimeException { - public function __construct($message, $code = 500, Exception $previous = null) { - parent::__construct($message, $code, $previous); +class CakeException extends RuntimeException { + + protected $_attributes = array(); + + protected $_messageTemplate = ''; + + public function __construct($message, $code = 500) { + if (is_array($message)) { + $this->_attributes = $message; + $message = vsprintf(__($this->_messageTemplate), $message); + } + parent::__construct($message, $code); + } + + public function getAttributes() { + return $this->_attributes; } } - -class Error404Exception extends RuntimeException { - public function __construct($message, $code = 404, Exception $previous = null) { - parent::__construct($message, $code, $previous); - } -} -class Error500Exception extends CakeException { } - /* * Exceptions used by Dispatcher */ -class MissingControllerException extends Error404Exception { } -class MissingActionException extends Error404Exception { } -class PrivateActionException extends Error404Exception { } +class MissingControllerException extends CakeException { + protected $_messageTemplate = 'Controller class %s could not be found.'; + + public function __construct($message, $code = 404) { + parent::__construct($message, $code); + } +} +class MissingActionException extends CakeException { + protected $_messageTemplate = 'Action %s::%s() could not be found.'; + + public function __construct($message, $code = 404) { + parent::__construct($message, $code); + } +} +class PrivateActionException extends CakeException { + protected $_messageTemplate = 'Private Action %s::%s() is not directly accessible.'; + + public function __construct($message, $code = 404, Exception $previous = null) { + parent::__construct($message, $code, $previous); + } +} /** * Exceptions used by the ComponentCollection. */ -class MissingComponentFileException extends CakeException { } -class MissingComponentClassException extends CakeException { } +class MissingComponentFileException extends CakeException { + protected $_messageTemplate = 'Component File "%s" is missing.'; +} +class MissingComponentClassException extends CakeException { + protected $_messageTemplate = 'Component class "%s" is missing.'; +} /** * Runtime Exceptions for behaviors @@ -60,68 +106,48 @@ class MissingBehaviorClassException extends CakeException { } /** * Runtime Exceptions for Views */ -class MissingViewException extends CakeException { } -class MissingLayoutException extends CakeException { } +class MissingViewException extends CakeException { + protected $_messageTemplate = 'View file "%s" is missing.'; +} +class MissingLayoutException extends CakeException { + protected $_messageTemplate = 'Layout file "%s" is missing.'; +} + +/** + * Exceptions used by the HelperCollection. + */ +class MissingHelperFileException extends CakeException { + protected $_messageTemplate = 'Helper File "%s" is missing.'; +} +class MissingHelperClassException extends CakeException { + protected $_messageTemplate = 'Helper class "%s" is missing.'; +} + /** * Runtime Exceptions for ConnectionManager */ -class MissingDatabaseException extends CakeException {} -class MissingConnectionException extends CakeException {} +class MissingDatabaseException extends CakeException { + protected $_messageTemplate = 'Database connection "%s" could not be found.'; +} +class MissingConnectionException extends CakeException { + protected $_messageTemplate = 'Database connection "%s" is missing.'; +} /** * Exceptions used by the TaskCollection. */ -class MissingTaskFileException extends CakeException { } -class MissingTaskClassException extends CakeException { } +class MissingTaskFileException extends CakeException { + protected $_messageTemplate = 'Task file "%s" is missing.'; +} +class MissingTaskClassException extends CakeException { + protected $_messageTemplate = 'Task class "%s" is missing.'; +} /** * Exception class to be thrown when a database table is not found in the datasource * */ class MissingTableException extends CakeException { -/** - * The name of the model wanting to load the database table - * - * @var string - */ - protected $model; -/** - * The name of the missing table - * - * @var string - */ - protected $table; - -/** - * Exception costructor - * - * @param string $model The name of the model wanting to load the database table - * @param string $table The name of the missing table - * @return void - */ - public function __construct($model, $table) { - $this->model = $model; - $this->table = $table; - $message = sprintf(__('Database table %s for model %s was not found.'), $table, $model); - parent::__construct($message); - } - -/** - * Returns the name of the model wanting to load the database table - * - * @return string - */ - public function getModel() { - return $this->model; - } - -/** - * Returns the name of the missing table - * - * @return string - */ - public function getTable() { - return $this->table; - } -} \ No newline at end of file + protected $_messageTemplate = 'Database table %s for model %s was not found.'; +} diff --git a/cake/libs/model/behavior_collection.php b/cake/libs/model/behavior_collection.php index 8895a798a..71c6cbf75 100644 --- a/cake/libs/model/behavior_collection.php +++ b/cake/libs/model/behavior_collection.php @@ -94,10 +94,16 @@ class BehaviorCollection extends ObjectCollection { $class = $name . 'Behavior'; if (!App::import('Behavior', $behavior)) { - throw new MissingBehaviorFileException(Inflector::underscore($behavior) . '.php'); + throw new MissingBehaviorFileException(array( + 'file' => Inflector::underscore($behavior) . '.php', + 'class' => $class + )); } if (!class_exists($class)) { - throw new MissingBehaviorClassException(Inflector::underscore($class)); + throw new MissingBehaviorClassException(array( + 'file' => Inflector::underscore($behavior) . '.php', + 'class' => $class + )); } if (!isset($this->{$name})) { diff --git a/cake/libs/model/connection_manager.php b/cake/libs/model/connection_manager.php index 1937663ff..143a16f3a 100644 --- a/cake/libs/model/connection_manager.php +++ b/cake/libs/model/connection_manager.php @@ -222,7 +222,7 @@ class ConnectionManager { $this->_connectionsEnum[$name] = $this->__connectionData($config); } } else { - throw new MissingConnectionException('ConnectionManager'); + throw new MissingConnectionException(array('class' => 'ConnectionManager')); } } diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 43fec9794..a1dc31420 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -799,7 +799,10 @@ class Model extends Object { if ($db->isInterfaceSupported('listSources')) { $sources = $db->listSources(); if (is_array($sources) && !in_array(strtolower($this->tablePrefix . $tableName), array_map('strtolower', $sources))) { - throw new MissingTableException($this->alias, $this->tablePrefix . $tableName); + throw new MissingTableException(array( + 'table' => $this->tablePrefix . $tableName, + 'class' => $this->alias + )); } $this->_schema = null; } @@ -2825,7 +2828,7 @@ class Model extends Object { } if (empty($db) || !is_object($db)) { - throw new MissingConnectionException($this->useDbConfig); + throw new MissingConnectionException(array('class' => $this->name)); } } diff --git a/cake/libs/view/errors/missing_action.ctp b/cake/libs/view/errors/missing_action.ctp index 3bb14ceac..fcaf5e5bf 100644 --- a/cake/libs/view/errors/missing_action.ctp +++ b/cake/libs/view/errors/missing_action.ctp @@ -24,7 +24,7 @@
: - ' . $controller . '::', '' . $action . '', APP_DIR . DS . 'controllers' . DS . Inflector::underscore($controller) . '.php'); ?> + ' . $controller . '::', '' . $action . '()', APP_DIR . DS . 'controllers' . DS . Inflector::underscore($controller) . '.php'); ?>
<?php diff --git a/cake/libs/view/errors/missing_behavior_class.ctp b/cake/libs/view/errors/missing_behavior_class.ctp index 58f0aa2cb..09dd42cbd 100644 --- a/cake/libs/view/errors/missing_behavior_class.ctp +++ b/cake/libs/view/errors/missing_behavior_class.ctp @@ -20,7 +20,7 @@: - %s can not be found or does not exist.'), $className); ?> + %s can not be found or does not exist.'), $class); ?>
: @@ -28,7 +28,7 @@
<?php -class extends ModelBehavior { +class extends ModelBehavior { } ?> diff --git a/cake/libs/view/errors/missing_behavior_file.ctp b/cake/libs/view/errors/missing_behavior_file.ctp index 23ae88e17..aba397885 100644 --- a/cake/libs/view/errors/missing_behavior_file.ctp +++ b/cake/libs/view/errors/missing_behavior_file.ctp @@ -28,7 +28,7 @@<?php -class extends ModelBehavior { +class extends ModelBehavior { } ?> diff --git a/cake/libs/view/errors/missing_component_class.ctp b/cake/libs/view/errors/missing_component_class.ctp index 9a35e113c..6829c781d 100644 --- a/cake/libs/view/errors/missing_component_class.ctp +++ b/cake/libs/view/errors/missing_component_class.ctp @@ -20,15 +20,15 @@: - ' . $className . ''); ?> + ' . $class . ''); ?>
: - ' . $className . '', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?> + ' . $class . '', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
<?php -class extends Component {
+class extends Component {
} ?> diff --git a/cake/libs/view/errors/missing_component_file.ctp b/cake/libs/view/errors/missing_component_file.ctp index 67f02cf08..ff57d432b 100644 --- a/cake/libs/view/errors/missing_component_file.ctp +++ b/cake/libs/view/errors/missing_component_file.ctp @@ -24,11 +24,11 @@: - ' . $className . 'Component', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?> + ' . $class . '', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
<?php -class Component extends Component {
+class extends Component {
} ?> diff --git a/cake/libs/view/errors/missing_connection.ctp b/cake/libs/view/errors/missing_connection.ctp index 51d082d31..633997e7e 100644 --- a/cake/libs/view/errors/missing_connection.ctp +++ b/cake/libs/view/errors/missing_connection.ctp @@ -20,7 +20,7 @@: - +
: diff --git a/cake/libs/view/errors/missing_scaffolddb.ctp b/cake/libs/view/errors/missing_database.ctp similarity index 100% rename from cake/libs/view/errors/missing_scaffolddb.ctp rename to cake/libs/view/errors/missing_database.ctp diff --git a/cake/libs/view/errors/missing_helper_class.ctp b/cake/libs/view/errors/missing_helper_class.ctp index a79bf9eec..9de192c14 100644 --- a/cake/libs/view/errors/missing_helper_class.ctp +++ b/cake/libs/view/errors/missing_helper_class.ctp @@ -20,7 +20,7 @@
: - %s can not be found or does not exist.'), $className); ?> + %s can not be found or does not exist.'), $class); ?>
: @@ -28,7 +28,7 @@
<?php -class extends AppHelper { +class extends AppHelper { } ?> diff --git a/cake/libs/view/errors/missing_helper_file.ctp b/cake/libs/view/errors/missing_helper_file.ctp index caa7ca119..537ca3ad0 100644 --- a/cake/libs/view/errors/missing_helper_file.ctp +++ b/cake/libs/view/errors/missing_helper_file.ctp @@ -28,7 +28,7 @@<?php -class extends AppHelper { +class extends AppHelper { } ?> diff --git a/cake/libs/view/errors/missing_table.ctp b/cake/libs/view/errors/missing_table.ctp index 3f0594e26..33d009293 100644 --- a/cake/libs/view/errors/missing_table.ctp +++ b/cake/libs/view/errors/missing_table.ctp @@ -20,7 +20,7 @@: - ' . $table . '', '' . $model . ''); ?> + ' . $table . '', '' . $class . ''); ?>
: diff --git a/cake/libs/view/errors/private_action.ctp b/cake/libs/view/errors/private_action.ctp index 20236e31f..ab9f13cdc 100644 --- a/cake/libs/view/errors/private_action.ctp +++ b/cake/libs/view/errors/private_action.ctp @@ -20,7 +20,7 @@
: - ' . $controller . '::', '' . $action . ''); ?> + ' . $controller . '::', '' . $action . '()'); ?>
: diff --git a/cake/libs/view/helper_collection.php b/cake/libs/view/helper_collection.php index 74683db93..faa63b14a 100644 --- a/cake/libs/view/helper_collection.php +++ b/cake/libs/view/helper_collection.php @@ -54,10 +54,16 @@ class HelperCollection extends ObjectCollection { $helperClass = $name . 'Helper'; if (!class_exists($helperClass)) { if (!App::import('Helper', $helper)) { - throw new MissingHelperFileException(Inflector::underscore($name) . '.php'); + throw new MissingHelperFileException(array( + 'class' => $helperClass, + 'file' => Inflector::underscore($name) . '.php' + )); } if (!class_exists($helperClass)) { - throw new MissingHelperClassException($helperClass); + throw new MissingHelperClassException(array( + 'class' => $helperClass, + 'file' => Inflector::underscore($name) . '.php' + )); } } $this->_loaded[$name] = new $helperClass($this->_View, $settings); @@ -73,10 +79,4 @@ class HelperCollection extends ObjectCollection { return $this->_loaded[$name]; } -} -/** - * Exceptions used by the HelperCollection. - */ -class MissingHelperFileException extends RuntimeException { } - -class MissingHelperClassException extends RuntimeException { } \ No newline at end of file +} \ No newline at end of file diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 622f6f3e6..be32b3a20 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -791,7 +791,7 @@ class View extends Object { } } } - throw new MissingViewException($defaultPath . $name . $this->ext); + throw new MissingViewException(array('file' => $defaultPath . $name . $this->ext)); } /** @@ -824,7 +824,7 @@ class View extends Object { } } } - throw new MissingLayoutException($paths[0] . $file . $this->ext); + throw new MissingLayoutException(array('file' => $paths[0] . $file . $this->ext)); } /** diff --git a/cake/tests/cases/libs/error_handler.test.php b/cake/tests/cases/libs/error_handler.test.php index e7ebf9af1..9c5d8a22f 100644 --- a/cake/tests/cases/libs/error_handler.test.php +++ b/cake/tests/cases/libs/error_handler.test.php @@ -426,7 +426,7 @@ class ErrorHandlerTest extends CakeTestCase { function testMissingController() { $this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController'); - $exception = new MissingControllerException('PostsController'); + $exception = new MissingControllerException(array('controller' => 'PostsController')); $ErrorHandler = new ErrorHandler($exception); ob_start(); @@ -445,7 +445,7 @@ class ErrorHandlerTest extends CakeTestCase { * @return void */ function testMissingAction() { - $exception = new MissingActionException('PostsController::index()'); + $exception = new MissingActionException(array('controller' => 'PostsController', 'action' => 'index')); $ErrorHandler = new ErrorHandler($exception); ob_start(); @@ -473,7 +473,7 @@ class ErrorHandlerTest extends CakeTestCase { * @return void */ function testPrivateAction() { - $exception = new PrivateActionException('PostsController::_secretSauce()'); + $exception = new PrivateActionException(array('controller' => 'PostsController' , 'action' => '_secretSauce')); $ErrorHandler = new ErrorHandler($exception); ob_start(); @@ -491,14 +491,15 @@ class ErrorHandlerTest extends CakeTestCase { * @return void */ function testMissingTable() { - $exception = new MissingTableException('Article', 'articles'); + $exception = new MissingTableException(array('table' => 'articles', 'class' => 'Article')); $ErrorHandler = new ErrorHandler($exception); + $ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode')); + $ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(500); ob_start(); $ErrorHandler->render(); $result = ob_get_clean(); - $this->assertPattern('/HTTP\/1\.0 500 Internal Server Error/', $result); $this->assertPattern('/
Missing Database Table<\/h2>/', $result); $this->assertPattern('/table articles<\/em> for model Article<\/em>/', $result); } @@ -510,14 +511,15 @@ class ErrorHandlerTest extends CakeTestCase { * @return void */ function testMissingDatabase() { - $exception = new MissingDatabaseException('default'); + $exception = new MissingDatabaseException(array('connection' => 'default')); $ErrorHandler = new ErrorHandler($exception); + $ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode')); + $ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(500); ob_start(); $ErrorHandler->render(); $result = ob_get_clean(); - $this->assertPattern('/HTTP\/1\.0 500 Internal Server Error/', $result); $this->assertPattern('/
Missing Database Connection<\/h2>/', $result); $this->assertPattern('/Confirm you have created the file/', $result); } @@ -529,7 +531,7 @@ class ErrorHandlerTest extends CakeTestCase { * @return void */ function testMissingView() { - $exception = new MissingViewException('/posts/about.ctp'); + $exception = new MissingViewException(array('file' => '/posts/about.ctp')); $ErrorHandler = new ErrorHandler($exception); ob_start(); @@ -546,7 +548,7 @@ class ErrorHandlerTest extends CakeTestCase { * @return void */ function testMissingLayout() { - $exception = new MissingLayoutException('layouts/my_layout.ctp'); + $exception = new MissingLayoutException(array('file' => 'layouts/my_layout.ctp')); $ErrorHandler = new ErrorHandler($exception); ob_start(); @@ -564,7 +566,7 @@ class ErrorHandlerTest extends CakeTestCase { * @return void */ function testMissingConnection() { - $exception = new MissingConnectionException('Article'); + $exception = new MissingConnectionException(array('class' => 'Article')); $ErrorHandler = new ErrorHandler($exception); ob_start(); @@ -582,7 +584,7 @@ class ErrorHandlerTest extends CakeTestCase { * @return void */ function testMissingHelperFile() { - $exception = new MissingHelperFileException('my_custom.php'); + $exception = new MissingHelperFileException(array('file' => 'my_custom.php', 'class' => 'MyCustomHelper')); $ErrorHandler = new ErrorHandler($exception); ob_start(); @@ -601,7 +603,7 @@ class ErrorHandlerTest extends CakeTestCase { * @return void */ function testMissingHelperClass() { - $exception = new MissingHelperClassException('MyCustomHelper'); + $exception = new MissingHelperClassException(array('file' => 'my_custom.php', 'class' => 'MyCustomHelper')); $ErrorHandler = new ErrorHandler($exception); ob_start(); @@ -620,7 +622,7 @@ class ErrorHandlerTest extends CakeTestCase { * @return void */ function testMissingBehaviorFile() { - $exception = new MissingBehaviorFileException('my_custom.php'); + $exception = new MissingBehaviorFileException(array('file' => 'my_custom.php', 'class' => 'MyCustomBehavior')); $ErrorHandler = new ErrorHandler($exception); ob_start(); @@ -639,7 +641,7 @@ class ErrorHandlerTest extends CakeTestCase { * @return void */ function testMissingBehaviorClass() { - $exception = new MissingBehaviorClassException('MyCustomBehavior'); + $exception = new MissingBehaviorClassException(array('file' => 'my_custom.php', 'class' => 'MyCustomBehavior')); $ErrorHandler = new ErrorHandler($exception); ob_start(); @@ -657,7 +659,7 @@ class ErrorHandlerTest extends CakeTestCase { * @return void */ function testMissingComponentFile() { - $exception = new MissingComponentFileException('sidebox.php'); + $exception = new MissingComponentFileException(array('file' => 'sidebox.php', 'class' => 'SideboxComponent')); $ErrorHandler = new ErrorHandler($exception); ob_start(); @@ -676,7 +678,7 @@ class ErrorHandlerTest extends CakeTestCase { * @return void */ function testMissingComponentClass() { - $exception = new MissingComponentClassException('SideboxComponent'); + $exception = new MissingComponentClassException(array('file' => 'sidebox.php', 'class' => 'SideboxComponent')); $ErrorHandler = new ErrorHandler($exception); ob_start();