Missing Method in PostsController<\/h2>/', $result);
$this->assertPattern('/PostsController::<\/em>index\(\)<\/em>/', $result);
+ /* TODO: Integration test that needs to be moved
ob_start();
- $dispatcher = new BlueberryDispatcher('/blueberry/inexistent');
+ $dispatcher = new Dispatcher('/blueberry/inexistent');
$result = ob_get_clean();
$this->assertPattern('/Missing Method in BlueberryController<\/h2>/', $result);
$this->assertPattern('/BlueberryController::<\/em>inexistent\(\)<\/em>/', $result);
$this->assertNoPattern('/Location: (.*)\/users\/login/', $result);
$this->assertNoPattern('/Stopped with status: 0/', $result);
+ */
}
/**
@@ -476,10 +459,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testPrivateAction() {
- $this->markTestIncomplete('Not implemented now');
+ $exception = new PrivateActionException('PostsController::_secretSauce()');
+ $ErrorHandler = new ErrorHandler($exception);
+
ob_start();
- $ErrorHandler = new ErrorHandler('privateAction', array('className' => 'PostsController', 'action' => '_secretSauce'));
+ $ErrorHandler->render();
$result = ob_get_clean();
+
$this->assertPattern('/Private Method in PostsController<\/h2>/', $result);
$this->assertPattern('/PostsController::<\/em>_secretSauce\(\)<\/em>/', $result);
}
@@ -491,10 +477,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingTable() {
- $this->markTestIncomplete('Not implemented now');
+ $exception = new MissingTableException('Article', 'articles');
+ $ErrorHandler = new ErrorHandler($exception);
+
ob_start();
- $ErrorHandler = new ErrorHandler('missingTable', array('className' => 'Article', 'table' => 'articles'));
+ $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);
@@ -507,10 +496,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingDatabase() {
- $this->markTestIncomplete('Not implemented now');
+ $exception = new MissingDatabaseException('default');
+ $ErrorHandler = new ErrorHandler($exception);
+
ob_start();
- $ErrorHandler = new ErrorHandler('missingDatabase', array());
+ $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);
@@ -523,12 +515,14 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingView() {
- $this->markTestIncomplete('Not implemented now');
+ $exception = new MissingViewException('/posts/about.ctp');
+ $ErrorHandler = new ErrorHandler($exception);
+
ob_start();
- $ErrorHandler = new ErrorHandler('missingView', array('className' => 'Pages', 'action' => 'display', 'file' => 'pages/about.ctp', 'base' => ''));
- $expected = ob_get_clean();
- $this->assertPattern("/PagesController::/", $expected);
- $this->assertPattern("/pages\/about.ctp/", $expected);
+ $ErrorHandler->render();
+ $result = ob_get_clean();
+
+ $this->assertPattern("/posts\/about.ctp/", $result);
}
/**
@@ -538,12 +532,15 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingLayout() {
- $this->markTestIncomplete('Not implemented now');
+ $exception = new MissingLayoutException('layouts/my_layout.ctp');
+ $ErrorHandler = new ErrorHandler($exception);
+
ob_start();
- $ErrorHandler = new ErrorHandler('missingLayout', array( 'layout' => 'my_layout', 'file' => 'layouts/my_layout.ctp', 'base' => ''));
- $expected = ob_get_clean();
- $this->assertPattern("/Missing Layout/", $expected);
- $this->assertPattern("/layouts\/my_layout.ctp/", $expected);
+ $ErrorHandler->render();
+ $result = ob_get_clean();
+
+ $this->assertPattern("/Missing Layout/", $result);
+ $this->assertPattern("/layouts\/my_layout.ctp/", $result);
}
/**
From 7fb62e9b7e77b6b7a5d7832a900d6c5ef9cbfb0a Mon Sep 17 00:00:00 2001
From: mark_story
Date: Sun, 29 Aug 2010 01:26:21 -0400
Subject: [PATCH 051/166] Updating more error messages to use exceptions.
---
cake/libs/error_handler.php | 66 ++++++++-----------
.../view/errors/missing_behavior_class.ctp | 4 +-
.../view/errors/missing_behavior_file.ctp | 2 +-
.../view/errors/missing_component_class.ctp | 6 +-
.../view/errors/missing_component_file.ctp | 4 +-
.../libs/view/errors/missing_helper_class.ctp | 4 +-
cake/libs/view/errors/missing_helper_file.ctp | 2 +-
cake/tests/cases/libs/error_handler.test.php | 49 ++++++++++----
8 files changed, 72 insertions(+), 65 deletions(-)
diff --git a/cake/libs/error_handler.php b/cake/libs/error_handler.php
index 512a27c28..fa772e7e4 100644
--- a/cake/libs/error_handler.php
+++ b/cake/libs/error_handler.php
@@ -275,14 +275,11 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
- public function missingConnection($params) {
- extract($params, EXTR_OVERWRITE);
-
+ public function missingConnection($error) {
$this->controller->header("HTTP/1.0 500 Internal Server Error");
$this->controller->set(array(
'code' => '500',
- 'model' => $className,
- 'title' => __('Missing Database Connection')
+ 'model' => $error->getMessage(),
));
$this->_outputMessage('missingConnection');
}
@@ -292,13 +289,11 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
- public function missingHelperFile($params) {
- extract($params, EXTR_OVERWRITE);
-
+ public function missingHelperFile($error) {
+ list($class, $ext) = explode('.', $error->getMessage());
$this->controller->set(array(
- 'helperClass' => Inflector::camelize($helper) . "Helper",
- 'file' => $file,
- 'title' => __('Missing Helper File')
+ 'className' => Inflector::camelize($class),
+ 'file' => $error->getMessage()
));
$this->_outputMessage('missingHelperFile');
}
@@ -308,13 +303,12 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
- public function missingHelperClass($params) {
- extract($params, EXTR_OVERWRITE);
-
+ public function missingHelperClass($error) {
+ $class = $error->getMessage();
+ $file = Inflector::underscore(str_replace('Helper', '', $error->getMessage())) . '.php';
$this->controller->set(array(
- 'helperClass' => Inflector::camelize($helper) . "Helper",
+ 'className' => $class,
'file' => $file,
- 'title' => __('Missing Helper Class')
));
$this->_outputMessage('missingHelperClass');
}
@@ -324,13 +318,11 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
- public function missingBehaviorFile($params) {
- extract($params, EXTR_OVERWRITE);
-
+ public function missingBehaviorFile($error) {
+ list($class, $ext) = explode('.', $error->getMessage());
$this->controller->set(array(
- 'behaviorClass' => Inflector::camelize($behavior) . "Behavior",
- 'file' => $file,
- 'title' => __('Missing Behavior File')
+ 'className' => Inflector::camelize($class),
+ 'file' => $error->getMessage()
));
$this->_outputMessage('missingBehaviorFile');
}
@@ -340,13 +332,12 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
- public function missingBehaviorClass($params) {
- extract($params, EXTR_OVERWRITE);
-
+ public function missingBehaviorClass($error) {
+ $class = $error->getMessage();
+ $file = Inflector::underscore(str_replace('Behavior', '', $error->getMessage())) . '.php';
$this->controller->set(array(
- 'behaviorClass' => Inflector::camelize($behavior) . "Behavior",
+ 'className' => $class,
'file' => $file,
- 'title' => __('Missing Behavior Class')
));
$this->_outputMessage('missingBehaviorClass');
}
@@ -356,14 +347,11 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
- public function missingComponentFile($params) {
- extract($params, EXTR_OVERWRITE);
-
+ public function missingComponentFile($error) {
+ list($class, $ext) = explode('.', $error->getMessage());
$this->controller->set(array(
- 'controller' => $className,
- 'component' => $component,
- 'file' => $file,
- 'title' => __('Missing Component File')
+ 'className' => Inflector::camelize($class),
+ 'file' => $error->getMessage()
));
$this->_outputMessage('missingComponentFile');
}
@@ -373,14 +361,12 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
- public function missingComponentClass($params) {
- extract($params, EXTR_OVERWRITE);
-
+ public function missingComponentClass($error) {
+ $class = $error->getMessage();
+ $file = Inflector::underscore(str_replace('Component', '', $error->getMessage())) . '.php';
$this->controller->set(array(
- 'controller' => $className,
- 'component' => $component,
+ 'className' => $class,
'file' => $file,
- 'title' => __('Missing Component Class')
));
$this->_outputMessage('missingComponentClass');
}
diff --git a/cake/libs/view/errors/missing_behavior_class.ctp b/cake/libs/view/errors/missing_behavior_class.ctp
index e9bf56472..58f0aa2cb 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.'), $behaviorClass); ?>
+ %s can not be found or does not exist.'), $className); ?>
:
@@ -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 654537404..23ae88e17 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 e63440c00..9a35e113c 100644
--- a/cake/libs/view/errors/missing_component_class.ctp
+++ b/cake/libs/view/errors/missing_component_class.ctp
@@ -20,15 +20,15 @@
:
- ' . $component . 'Component
', '' . $controller . 'Controller'); ?>
+ ' . $className . ''); ?>
:
- ' . $component . 'Component
', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
+ ' . $className . '', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
<?php
-class Component extends Object {
+class extends Component {
}
?>
diff --git a/cake/libs/view/errors/missing_component_file.ctp b/cake/libs/view/errors/missing_component_file.ctp
index 44c607cd8..67f02cf08 100644
--- a/cake/libs/view/errors/missing_component_file.ctp
+++ b/cake/libs/view/errors/missing_component_file.ctp
@@ -24,11 +24,11 @@
:
- ' . $component . 'Component
', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
+ ' . $className . 'Component', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
<?php
-class Component extends Object {
+class Component extends Component {
}
?>
diff --git a/cake/libs/view/errors/missing_helper_class.ctp b/cake/libs/view/errors/missing_helper_class.ctp
index 7c8a79079..a79bf9eec 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.'), $helperClass); ?>
+ %s can not be found or does not exist.'), $className); ?>
:
@@ -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 1da5d577b..caa7ca119 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/tests/cases/libs/error_handler.test.php b/cake/tests/cases/libs/error_handler.test.php
index b4f3ede19..e8681eb66 100644
--- a/cake/tests/cases/libs/error_handler.test.php
+++ b/cake/tests/cases/libs/error_handler.test.php
@@ -550,10 +550,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingConnection() {
- $this->markTestIncomplete('Not implemented now');
+ $exception = new MissingConnectionException('Article');
+ $ErrorHandler = new ErrorHandler($exception);
+
ob_start();
- $ErrorHandler = new ErrorHandler('missingConnection', array('className' => 'Article'));
+ $ErrorHandler->render();
$result = ob_get_clean();
+
$this->assertPattern('/Missing Database Connection<\/h2>/', $result);
$this->assertPattern('/Article requires a database connection/', $result);
}
@@ -565,10 +568,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingHelperFile() {
- $this->markTestIncomplete('Not implemented now');
+ $exception = new MissingHelperFileException('my_custom.php');
+ $ErrorHandler = new ErrorHandler($exception);
+
ob_start();
- $ErrorHandler = new ErrorHandler('missingHelperFile', array('helper' => 'MyCustom', 'file' => 'my_custom.php'));
+ $ErrorHandler->render();
$result = ob_get_clean();
+
$this->assertPattern('/Missing Helper File<\/h2>/', $result);
$this->assertPattern('/Create the class below in file:/', $result);
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
@@ -581,10 +587,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingHelperClass() {
- $this->markTestIncomplete('Not implemented now');
+ $exception = new MissingHelperClassException('MyCustomHelper');
+ $ErrorHandler = new ErrorHandler($exception);
+
ob_start();
- $ErrorHandler = new ErrorHandler('missingHelperClass', array('helper' => 'MyCustom', 'file' => 'my_custom.php'));
+ $ErrorHandler->render();
$result = ob_get_clean();
+
$this->assertPattern('/Missing Helper Class<\/h2>/', $result);
$this->assertPattern('/The helper class MyCustomHelper<\/em> can not be found or does not exist./', $result);
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
@@ -597,10 +606,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingBehaviorFile() {
- $this->markTestIncomplete('Not implemented now');
+ $exception = new MissingBehaviorFileException('my_custom.php');
+ $ErrorHandler = new ErrorHandler($exception);
+
ob_start();
- $ErrorHandler = new ErrorHandler('missingBehaviorFile', array('behavior' => 'MyCustom', 'file' => 'my_custom.php'));
+ $ErrorHandler->render();
$result = ob_get_clean();
+
$this->assertPattern('/Missing Behavior File<\/h2>/', $result);
$this->assertPattern('/Create the class below in file:/', $result);
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
@@ -613,10 +625,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingBehaviorClass() {
- $this->markTestIncomplete('Not implemented now');
+ $exception = new MissingBehaviorClassException('MyCustomBehavior');
+ $ErrorHandler = new ErrorHandler($exception);
+
ob_start();
- $ErrorHandler = new ErrorHandler('missingBehaviorClass', array('behavior' => 'MyCustom', 'file' => 'my_custom.php'));
+ $ErrorHandler->render();
$result = ob_get_clean();
+
$this->assertPattern('/The behavior class MyCustomBehavior<\/em> can not be found or does not exist./', $result);
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
}
@@ -628,10 +643,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingComponentFile() {
- $this->markTestIncomplete('Not implemented now');
+ $exception = new MissingComponentFileException('sidebox.php');
+ $ErrorHandler = new ErrorHandler($exception);
+
ob_start();
- $ErrorHandler = new ErrorHandler('missingComponentFile', array('className' => 'PostsController', 'component' => 'Sidebox', 'file' => 'sidebox.php'));
+ $ErrorHandler->render();
$result = ob_get_clean();
+
$this->assertPattern('/Missing Component File<\/h2>/', $result);
$this->assertPattern('/Create the class SideboxComponent<\/em> in file:/', $result);
$this->assertPattern('/(\/|\\\)sidebox.php/', $result);
@@ -644,10 +662,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingComponentClass() {
- $this->markTestIncomplete('Not implemented now');
+ $exception = new MissingComponentClassException('SideboxComponent');
+ $ErrorHandler = new ErrorHandler($exception);
+
ob_start();
- $ErrorHandler = new ErrorHandler('missingComponentClass', array('className' => 'PostsController', 'component' => 'Sidebox', 'file' => 'sidebox.php'));
+ $ErrorHandler->render();
$result = ob_get_clean();
+
$this->assertPattern('/Missing Component Class<\/h2>/', $result);
$this->assertPattern('/Create the class SideboxComponent<\/em> in file:/', $result);
$this->assertPattern('/(\/|\\\)sidebox.php/', $result);
From 465b15c64e38d1e04db32c8e62702618a9e0725d Mon Sep 17 00:00:00 2001
From: predominant
Date: Sun, 29 Aug 2010 23:09:33 +1000
Subject: [PATCH 052/166] Removing reference assignments.
---
cake/libs/session/database_session.php | 19 +++++--------------
1 file changed, 5 insertions(+), 14 deletions(-)
diff --git a/cake/libs/session/database_session.php b/cake/libs/session/database_session.php
index 19c48dffe..31b136936 100644
--- a/cake/libs/session/database_session.php
+++ b/cake/libs/session/database_session.php
@@ -55,8 +55,7 @@ class DatabaseSession implements CakeSessionHandlerInterface {
* @access private
*/
public static function read($id) {
- $model =& ClassRegistry::getObject('Session');
-
+ $model = ClassRegistry::getObject('Session');
$row = $model->find('first', array(
'conditions' => array($model->primaryKey => $id)
));
@@ -78,9 +77,7 @@ class DatabaseSession implements CakeSessionHandlerInterface {
*/
public static function write($id, $data) {
$expires = time() + (Configure::read('Session.timeout') * 60);
- $model =& ClassRegistry::getObject('Session');
- $return = $model->save(compact('id', 'data', 'expires'));
- return $return;
+ return ClassRegistry::getObject('Session')->save(compact('id', 'data', 'expires'));
}
/**
@@ -91,10 +88,7 @@ class DatabaseSession implements CakeSessionHandlerInterface {
* @access private
*/
public static function destroy($id) {
- $model =& ClassRegistry::getObject('Session');
- $return = $model->delete($id);
-
- return $return;
+ return ClassRegistry::getObject('Session')->delete($id);
}
/**
@@ -105,13 +99,10 @@ class DatabaseSession implements CakeSessionHandlerInterface {
* @access private
*/
public static function gc($expires = null) {
- $model =& ClassRegistry::getObject('Session');
-
if (!$expires) {
$expires = time();
}
-
- $return = $model->deleteAll(array($model->alias . ".expires <" => $expires), false, false);
- return $return;
+ $model = ClassRegistry::getObject('Session');
+ return $model->deleteAll(array($model->alias . ".expires <" => $expires), false, false);
}
}
From 99cde14432c730ef63a90ccffc5958f709c2fd11 Mon Sep 17 00:00:00 2001
From: mark_story
Date: Sun, 29 Aug 2010 13:49:10 -0400
Subject: [PATCH 053/166] No more skipped tests for ErrorHandler. Removing
missing_model as it was never called.
---
cake/libs/error_handler.php | 43 ++-----
cake/libs/view/errors/missing_model.ctp | 41 -------
cake/tests/cases/libs/error_handler.test.php | 115 +++++++++----------
3 files changed, 68 insertions(+), 131 deletions(-)
delete mode 100644 cake/libs/view/errors/missing_model.ctp
diff --git a/cake/libs/error_handler.php b/cake/libs/error_handler.php
index fa772e7e4..1d0502ee1 100644
--- a/cake/libs/error_handler.php
+++ b/cake/libs/error_handler.php
@@ -139,11 +139,15 @@ class ErrorHandler {
* @param array $params Parameters for controller
*/
public function error404($error) {
+ $message = $error->getMessage();
+ if (Configure::read('debug') == 0) {
+ $message = __('Not Found');
+ }
$url = Router::normalize($this->controller->request->here);
$this->controller->response->statusCode(404);
$this->controller->set(array(
'code' => 404,
- 'name' => $error->getMessage(),
+ 'name' => $message,
'url' => h($url),
));
$this->_outputMessage('error404');
@@ -155,18 +159,11 @@ class ErrorHandler {
* @param array $params Parameters for controller
*/
public function error500($params) {
- extract($params, EXTR_OVERWRITE);
-
- if (!isset($url)) {
- $url = $this->controller->request->here;
- }
- $url = Router::normalize($url);
- $this->controller->header("HTTP/1.0 500 Internal Server Error");
+ $url = Router::normalize($this->controller->request->here);
+ $this->controller->response->statusCode(500);
$this->controller->set(array(
- 'code' => '500',
'name' => __('An Internal Error Has Occurred'),
'message' => h($url),
- 'base' => $this->controller->request->base
));
$this->_outputMessage('error500');
}
@@ -175,14 +172,11 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
- public function missingController($params) {
- extract($params, EXTR_OVERWRITE);
-
- $controllerName = str_replace('Controller', '', $className);
+ public function missingController($error) {
+ $controllerName = str_replace('Controller', '', $error->getMessage());
$this->controller->set(array(
- 'controller' => $className,
- 'controllerName' => $controllerName,
- 'title' => __('Missing Controller')
+ 'controller' => $error->getMessage(),
+ 'controllerName' => $controllerName
));
$this->_outputMessage('missingController');
}
@@ -371,21 +365,6 @@ class ErrorHandler {
$this->_outputMessage('missingComponentClass');
}
-/**
- * Renders the Missing Model class web page.
- *
- * @param unknown_type $params Parameters for controller
- */
- public function missingModel($params) {
- extract($params, EXTR_OVERWRITE);
-
- $this->controller->set(array(
- 'model' => $className,
- 'title' => __('Missing Model')
- ));
- $this->_outputMessage('missingModel');
- }
-
/**
* Output message
*
diff --git a/cake/libs/view/errors/missing_model.ctp b/cake/libs/view/errors/missing_model.ctp
deleted file mode 100644
index c3d7baa63..000000000
--- a/cake/libs/view/errors/missing_model.ctp
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-
- :
- %s
could not be found.'), $model); ?>
-
-
- :
- ' . $model . '
', APP_DIR . DS . 'models' . DS . Inflector::underscore($model) . '.php'); ?>
-
-
-<?php
-class extends AppModel {
-
- public $name = '';
-
-}
-?>
-
-
- :
-
-
\ No newline at end of file
diff --git a/cake/tests/cases/libs/error_handler.test.php b/cake/tests/cases/libs/error_handler.test.php
index e8681eb66..e7ebf9af1 100644
--- a/cake/tests/cases/libs/error_handler.test.php
+++ b/cake/tests/cases/libs/error_handler.test.php
@@ -188,25 +188,13 @@ class MyCustomErrorHandler extends ErrorHandler {
echo 'widget thing is missing';
}
}
-
/**
- * TestErrorHandler class
+ * Exception class for testing app error handlers and custom errors.
*
- * @package cake
- * @subpackage cake.tests.cases.libs
+ * @package cake.test.cases.libs
*/
-class TestErrorHandler extends ErrorHandler {
+class MissingWidgetThingException extends Error404Exception { }
-/**
- * stop method
- *
- * @access public
- * @return void
- */
- function _stop() {
- return;
- }
-}
/**
* ErrorHandlerTest class
@@ -257,34 +245,60 @@ class ErrorHandlerTest extends CakeTestCase {
/**
* test that methods declared in an ErrorHandler subclass are not converted
- * into error404 when debug == 0
+ * into error404 when debug > 0
*
* @return void
*/
function testSubclassMethodsNotBeingConvertedToError() {
- $this->markTestIncomplete('Not implemented now');
- $back = Configure::read('debug');
Configure::write('debug', 2);
+
+ $exception = new MissingWidgetThingException('Widget not found');
+ $ErrorHandler = new MyCustomErrorHandler($exception);
+
ob_start();
- $ErrorHandler = new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
+ $ErrorHandler->render();
$result = ob_get_clean();
+
$this->assertEqual($result, 'widget thing is missing');
+ }
+/**
+ * test that subclass methods are not converted when debug = 0
+ *
+ * @return void
+ */
+ function testSubclassMethodsNotBeingConvertedDebug0() {
Configure::write('debug', 0);
- ob_start();
- $ErrorHandler = new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
- $result = ob_get_clean();
- $this->assertEqual($result, 'widget thing is missing', 'Method declared in subclass converted to error404. %s');
+ $exception = new MissingWidgetThingException('Widget not found');
+ $ErrorHandler = new MyCustomErrorHandler($exception);
+
+ $this->assertEqual('missingWidgetThing', $ErrorHandler->method);
- Configure::write('debug', 0);
ob_start();
- $ErrorHandler = new MyCustomErrorHandler('missingController', array(
- 'className' => 'Missing', 'message' => 'Page not found'
- ));
+ $ErrorHandler->render();
$result = ob_get_clean();
+
+ $this->assertEqual($result, 'widget thing is missing', 'Method declared in subclass converted to error404');
+ }
+
+/**
+ * test that ErrorHandler subclasses properly convert framework errors.
+ *
+ * @return void
+ */
+ function testSubclassConvertingFrameworkErrors() {
+ Configure::write('debug', 0);
+
+ $exception = new MissingControllerException('PostsController');
+ $ErrorHandler = new MyCustomErrorHandler($exception);
+
+ $this->assertEqual('error404', $ErrorHandler->method);
+
+ ob_start();
+ $ErrorHandler->render();
+ $result = ob_get_clean();
+
$this->assertPattern('/Not Found/', $result, 'Method declared in error handler not converted to error404. %s');
-
- Configure::write('debug', $back);
}
/**
@@ -349,6 +363,8 @@ class ErrorHandlerTest extends CakeTestCase {
$exception = new Error404Exception('Custom message');
$ErrorHandler = new ErrorHandler($exception);
+ $ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
+ $ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(404);
ob_start();
$ErrorHandler->render();
@@ -388,21 +404,16 @@ class ErrorHandlerTest extends CakeTestCase {
* @access public
* @return void
*/
- function testError500() {
- $this->markTestIncomplete('Not implemented now');
- ob_start();
- $ErrorHandler = new ErrorHandler('error500', array(
- 'message' => 'An Internal Error Has Occurred'
- ));
- $result = ob_get_clean();
- $this->assertPattern('/An Internal Error Has Occurred<\/h2>/', $result);
+ function testError500Message() {
+ $exception = new Error500Exception('An Internal Error Has Occurred');
+ $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 = new ErrorHandler('error500', array(
- 'message' => 'An Internal Error Has Occurred',
- 'code' => '500'
- ));
+ $ErrorHandler->render();
$result = ob_get_clean();
+
$this->assertPattern('/An Internal Error Has Occurred<\/h2>/', $result);
}
@@ -413,12 +424,15 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingController() {
- $this->markTestIncomplete('Not implemented now');
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController');
+ $exception = new MissingControllerException('PostsController');
+ $ErrorHandler = new ErrorHandler($exception);
+
ob_start();
- $ErrorHandler = new ErrorHandler('missingController', array('className' => 'PostsController'));
+ $ErrorHandler->render();
$result = ob_get_clean();
+
$this->assertPattern('/Missing Controller<\/h2>/', $result);
$this->assertPattern('/PostsController<\/em>/', $result);
$this->assertPattern('/BlueberryComponent/', $result);
@@ -674,19 +688,4 @@ class ErrorHandlerTest extends CakeTestCase {
$this->assertPattern('/(\/|\\\)sidebox.php/', $result);
}
-/**
- * testMissingModel method
- *
- * @access public
- * @return void
- */
- function testMissingModel() {
- $this->markTestIncomplete('Not implemented now');
- ob_start();
- $ErrorHandler = new ErrorHandler('missingModel', array('className' => 'Article', 'file' => 'article.php'));
- $result = ob_get_clean();
- $this->assertPattern('/Missing Model<\/h2>/', $result);
- $this->assertPattern('/Article<\/em> could not be found./', $result);
- $this->assertPattern('/(\/|\\\)article.php/', $result);
- }
}
From 741f2972f9c6c1a22227483cc4e67ba185d8c825 Mon Sep 17 00:00:00 2001
From: mark_story
Date: Sun, 29 Aug 2010 15:12:50 -0400
Subject: [PATCH 054/166] Removing non required attribute from missing
controller error page.
---
cake/libs/view/errors/missing_controller.ctp | 1 -
1 file changed, 1 deletion(-)
diff --git a/cake/libs/view/errors/missing_controller.ctp b/cake/libs/view/errors/missing_controller.ctp
index 0c7dd798b..855f0011d 100644
--- a/cake/libs/view/errors/missing_controller.ctp
+++ b/cake/libs/view/errors/missing_controller.ctp
@@ -30,7 +30,6 @@
<?php
class extends AppController {
- public $name = '';
}
?>
From f1164c93d6b42c39b18aa3a308e7d8f597f14c28 Mon Sep 17 00:00:00 2001
From: mark_story
Date: Sun, 29 Aug 2010 21:37:25 -0400
Subject: [PATCH 055/166] Updating the various CakeExceptions to take arrays in
their constructors. This allows for the existing templates to continue
working, as well as generalize the way in which errors are handled. This
change also makes the messages coming out of exceptions more readable and
removes string hackery.
---
cake/dispatcher.php | 24 +-
cake/libs/controller/component_collection.php | 10 +-
cake/libs/controller/scaffold.php | 8 +-
cake/libs/error_handler.php | 273 ++++--------------
cake/libs/exceptions.php | 160 +++++-----
cake/libs/model/behavior_collection.php | 10 +-
cake/libs/model/connection_manager.php | 2 +-
cake/libs/model/model.php | 7 +-
cake/libs/view/errors/missing_action.ctp | 2 +-
.../view/errors/missing_behavior_class.ctp | 4 +-
.../view/errors/missing_behavior_file.ctp | 2 +-
.../view/errors/missing_component_class.ctp | 6 +-
.../view/errors/missing_component_file.ctp | 4 +-
cake/libs/view/errors/missing_connection.ctp | 2 +-
...ng_scaffolddb.ctp => missing_database.ctp} | 0
.../libs/view/errors/missing_helper_class.ctp | 4 +-
cake/libs/view/errors/missing_helper_file.ctp | 2 +-
cake/libs/view/errors/missing_table.ctp | 2 +-
cake/libs/view/errors/private_action.ctp | 2 +-
cake/libs/view/helper_collection.php | 18 +-
cake/libs/view/view.php | 4 +-
cake/tests/cases/libs/error_handler.test.php | 34 ++-
22 files changed, 233 insertions(+), 347 deletions(-)
rename cake/libs/view/errors/{missing_scaffolddb.ctp => missing_database.ctp} (100%)
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();
From efaa2e117746307c5be910a0b14f0434163e7ab9 Mon Sep 17 00:00:00 2001
From: mark_story
Date: Sun, 29 Aug 2010 21:53:44 -0400
Subject: [PATCH 056/166] Refactoring test case to use a dataprovider for the
uniform/copy paste test cases.
---
cake/tests/cases/libs/error_handler.test.php | 367 +++++++------------
1 file changed, 133 insertions(+), 234 deletions(-)
diff --git a/cake/tests/cases/libs/error_handler.test.php b/cake/tests/cases/libs/error_handler.test.php
index 9c5d8a22f..d36af6a9b 100644
--- a/cake/tests/cases/libs/error_handler.test.php
+++ b/cake/tests/cases/libs/error_handler.test.php
@@ -438,256 +438,155 @@ class ErrorHandlerTest extends CakeTestCase {
$this->assertPattern('/BlueberryComponent/', $result);
}
+
+ /* TODO: Integration test that needs to be moved
+ ob_start();
+ $dispatcher = new Dispatcher('/blueberry/inexistent');
+ $result = ob_get_clean();
+ $this->assertPattern('/Missing Method in BlueberryController<\/h2>/', $result);
+ $this->assertPattern('/BlueberryController::<\/em>inexistent\(\)<\/em>/', $result);
+ $this->assertNoPattern('/Location: (.*)\/users\/login/', $result);
+ $this->assertNoPattern('/Stopped with status: 0/', $result);
+ */
+
/**
- * testMissingAction method
+ * Returns an array of tests to run for the various CakeException classes.
*
- * @access public
* @return void
*/
- function testMissingAction() {
- $exception = new MissingActionException(array('controller' => 'PostsController', 'action' => 'index'));
- $ErrorHandler = new ErrorHandler($exception);
-
- ob_start();
- $ErrorHandler->render();
- $result = ob_get_clean();
-
- $this->assertPattern('/Missing Method in PostsController<\/h2>/', $result);
- $this->assertPattern('/PostsController::<\/em>index\(\)<\/em>/', $result);
-
- /* TODO: Integration test that needs to be moved
- ob_start();
- $dispatcher = new Dispatcher('/blueberry/inexistent');
- $result = ob_get_clean();
- $this->assertPattern('/Missing Method in BlueberryController<\/h2>/', $result);
- $this->assertPattern('/BlueberryController::<\/em>inexistent\(\)<\/em>/', $result);
- $this->assertNoPattern('/Location: (.*)\/users\/login/', $result);
- $this->assertNoPattern('/Stopped with status: 0/', $result);
- */
+ public static function testProvider() {
+ return array(
+ array(
+ new MissingActionException(array('controller' => 'PostsController', 'action' => 'index')),
+ array(
+ '/Missing Method in PostsController<\/h2>/',
+ '/PostsController::<\/em>index\(\)<\/em>/'
+ ),
+ 404
+ ),
+ array(
+ new PrivateActionException(array('controller' => 'PostsController' , 'action' => '_secretSauce')),
+ array(
+ '/Private Method in PostsController<\/h2>/',
+ '/PostsController::<\/em>_secretSauce\(\)<\/em>/'
+ ),
+ 404
+ ),
+ array(
+ new MissingTableException(array('table' => 'articles', 'class' => 'Article')),
+ array(
+ '/Missing Database Table<\/h2>/',
+ '/table articles<\/em> for model Article<\/em>/'
+ ),
+ 500
+ ),
+ array(
+ new MissingDatabaseException(array('connection' => 'default')),
+ array(
+ '/Missing Database Connection<\/h2>/',
+ '/Confirm you have created the file/'
+ ),
+ 500
+ ),
+ array(
+ new MissingViewException(array('file' => '/posts/about.ctp')),
+ array(
+ "/posts\/about.ctp/"
+ ),
+ 500
+ ),
+ array(
+ new MissingLayoutException(array('file' => 'layouts/my_layout.ctp')),
+ array(
+ "/Missing Layout/",
+ "/layouts\/my_layout.ctp/"
+ ),
+ 500
+ ),
+ array(
+ new MissingConnectionException(array('class' => 'Article')),
+ array(
+ '/Missing Database Connection<\/h2>/',
+ '/Article requires a database connection/'
+ ),
+ 500
+ ),
+ array(
+ new MissingHelperFileException(array('file' => 'my_custom.php', 'class' => 'MyCustomHelper')),
+ array(
+ '/Missing Helper File<\/h2>/',
+ '/Create the class below in file:/',
+ '/(\/|\\\)my_custom.php/'
+ ),
+ 500
+ ),
+ array(
+ new MissingHelperClassException(array('file' => 'my_custom.php', 'class' => 'MyCustomHelper')),
+ array(
+ '/Missing Helper Class<\/h2>/',
+ '/The helper class MyCustomHelper<\/em> can not be found or does not exist./',
+ '/(\/|\\\)my_custom.php/',
+ ),
+ 500
+ ),
+ array(
+ new MissingBehaviorFileException(array('file' => 'my_custom.php', 'class' => 'MyCustomBehavior')),
+ array(
+ '/Missing Behavior File<\/h2>/',
+ '/Create the class below in file:/',
+ '/(\/|\\\)my_custom.php/',
+ ),
+ 500
+ ),
+ array(
+ new MissingBehaviorClassException(array('file' => 'my_custom.php', 'class' => 'MyCustomBehavior')),
+ array(
+ '/The behavior class MyCustomBehavior<\/em> can not be found or does not exist./',
+ '/(\/|\\\)my_custom.php/'
+ ),
+ 500
+ ),
+ array(
+ new MissingComponentFileException(array('file' => 'sidebox.php', 'class' => 'SideboxComponent')),
+ array(
+ '/Missing Component File<\/h2>/',
+ '/Create the class SideboxComponent<\/em> in file:/',
+ '/(\/|\\\)sidebox.php/'
+ ),
+ 500
+ ),
+ array(
+ new MissingComponentClassException(array('file' => 'sidebox.php', 'class' => 'SideboxComponent')),
+ array(
+ '/Missing Component Class<\/h2>/',
+ '/Create the class SideboxComponent<\/em> in file:/',
+ '/(\/|\\\)sidebox.php/'
+ ),
+ 500
+ )
+
+ );
}
/**
- * testPrivateAction method
+ * Test the various CakeException sub classes
*
- * @access public
+ * @dataProvider testProvider
* @return void
*/
- function testPrivateAction() {
- $exception = new PrivateActionException(array('controller' => 'PostsController' , 'action' => '_secretSauce'));
- $ErrorHandler = new ErrorHandler($exception);
-
- ob_start();
- $ErrorHandler->render();
- $result = ob_get_clean();
-
- $this->assertPattern('/Private Method in PostsController<\/h2>/', $result);
- $this->assertPattern('/PostsController::<\/em>_secretSauce\(\)<\/em>/', $result);
- }
-
-/**
- * testMissingTable method
- *
- * @access public
- * @return void
- */
- function testMissingTable() {
- $exception = new MissingTableException(array('table' => 'articles', 'class' => 'Article'));
+ function testCakeExceptionHandling($exception, $patterns, $code) {
$ErrorHandler = new ErrorHandler($exception);
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
- $ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(500);
+ $ErrorHandler->controller->response->expects($this->once())
+ ->method('statusCode')
+ ->with($code);
ob_start();
$ErrorHandler->render();
$result = ob_get_clean();
- $this->assertPattern('/Missing Database Table<\/h2>/', $result);
- $this->assertPattern('/table articles<\/em> for model Article<\/em>/', $result);
+ foreach ($patterns as $pattern) {
+ $this->assertPattern($pattern, $result);
+ }
}
-
-/**
- * testMissingDatabase method
- *
- * @access public
- * @return void
- */
- function testMissingDatabase() {
- $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('/Missing Database Connection<\/h2>/', $result);
- $this->assertPattern('/Confirm you have created the file/', $result);
- }
-
-/**
- * testMissingView method
- *
- * @access public
- * @return void
- */
- function testMissingView() {
- $exception = new MissingViewException(array('file' => '/posts/about.ctp'));
- $ErrorHandler = new ErrorHandler($exception);
-
- ob_start();
- $ErrorHandler->render();
- $result = ob_get_clean();
-
- $this->assertPattern("/posts\/about.ctp/", $result);
- }
-
-/**
- * testMissingLayout method
- *
- * @access public
- * @return void
- */
- function testMissingLayout() {
- $exception = new MissingLayoutException(array('file' => 'layouts/my_layout.ctp'));
- $ErrorHandler = new ErrorHandler($exception);
-
- ob_start();
- $ErrorHandler->render();
- $result = ob_get_clean();
-
- $this->assertPattern("/Missing Layout/", $result);
- $this->assertPattern("/layouts\/my_layout.ctp/", $result);
- }
-
-/**
- * testMissingConnection method
- *
- * @access public
- * @return void
- */
- function testMissingConnection() {
- $exception = new MissingConnectionException(array('class' => 'Article'));
- $ErrorHandler = new ErrorHandler($exception);
-
- ob_start();
- $ErrorHandler->render();
- $result = ob_get_clean();
-
- $this->assertPattern('/Missing Database Connection<\/h2>/', $result);
- $this->assertPattern('/Article requires a database connection/', $result);
- }
-
-/**
- * testMissingHelperFile method
- *
- * @access public
- * @return void
- */
- function testMissingHelperFile() {
- $exception = new MissingHelperFileException(array('file' => 'my_custom.php', 'class' => 'MyCustomHelper'));
- $ErrorHandler = new ErrorHandler($exception);
-
- ob_start();
- $ErrorHandler->render();
- $result = ob_get_clean();
-
- $this->assertPattern('/Missing Helper File<\/h2>/', $result);
- $this->assertPattern('/Create the class below in file:/', $result);
- $this->assertPattern('/(\/|\\\)my_custom.php/', $result);
- }
-
-/**
- * testMissingHelperClass method
- *
- * @access public
- * @return void
- */
- function testMissingHelperClass() {
- $exception = new MissingHelperClassException(array('file' => 'my_custom.php', 'class' => 'MyCustomHelper'));
- $ErrorHandler = new ErrorHandler($exception);
-
- ob_start();
- $ErrorHandler->render();
- $result = ob_get_clean();
-
- $this->assertPattern('/Missing Helper Class<\/h2>/', $result);
- $this->assertPattern('/The helper class MyCustomHelper<\/em> can not be found or does not exist./', $result);
- $this->assertPattern('/(\/|\\\)my_custom.php/', $result);
- }
-
-/**
- * test missingBehaviorFile method
- *
- * @access public
- * @return void
- */
- function testMissingBehaviorFile() {
- $exception = new MissingBehaviorFileException(array('file' => 'my_custom.php', 'class' => 'MyCustomBehavior'));
- $ErrorHandler = new ErrorHandler($exception);
-
- ob_start();
- $ErrorHandler->render();
- $result = ob_get_clean();
-
- $this->assertPattern('/Missing Behavior File<\/h2>/', $result);
- $this->assertPattern('/Create the class below in file:/', $result);
- $this->assertPattern('/(\/|\\\)my_custom.php/', $result);
- }
-
-/**
- * test MissingBehaviorClass method
- *
- * @access public
- * @return void
- */
- function testMissingBehaviorClass() {
- $exception = new MissingBehaviorClassException(array('file' => 'my_custom.php', 'class' => 'MyCustomBehavior'));
- $ErrorHandler = new ErrorHandler($exception);
-
- ob_start();
- $ErrorHandler->render();
- $result = ob_get_clean();
-
- $this->assertPattern('/The behavior class MyCustomBehavior<\/em> can not be found or does not exist./', $result);
- $this->assertPattern('/(\/|\\\)my_custom.php/', $result);
- }
-
-/**
- * testMissingComponentFile method
- *
- * @access public
- * @return void
- */
- function testMissingComponentFile() {
- $exception = new MissingComponentFileException(array('file' => 'sidebox.php', 'class' => 'SideboxComponent'));
- $ErrorHandler = new ErrorHandler($exception);
-
- ob_start();
- $ErrorHandler->render();
- $result = ob_get_clean();
-
- $this->assertPattern('/Missing Component File<\/h2>/', $result);
- $this->assertPattern('/Create the class SideboxComponent<\/em> in file:/', $result);
- $this->assertPattern('/(\/|\\\)sidebox.php/', $result);
- }
-
-/**
- * testMissingComponentClass method
- *
- * @access public
- * @return void
- */
- function testMissingComponentClass() {
- $exception = new MissingComponentClassException(array('file' => 'sidebox.php', 'class' => 'SideboxComponent'));
- $ErrorHandler = new ErrorHandler($exception);
-
- ob_start();
- $ErrorHandler->render();
- $result = ob_get_clean();
-
- $this->assertPattern('/Missing Component Class<\/h2>/', $result);
- $this->assertPattern('/Create the class SideboxComponent<\/em> in file:/', $result);
- $this->assertPattern('/(\/|\\\)sidebox.php/', $result);
- }
-
}
From 78ac5bd20fb8273d91882f9cd86a64a8dd89b6c9 Mon Sep 17 00:00:00 2001
From: mark_story
Date: Sun, 29 Aug 2010 23:28:54 -0400
Subject: [PATCH 057/166] Removing sprintf() placeholders that don't work.
---
cake/tests/cases/libs/cake_request.test.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/cake/tests/cases/libs/cake_request.test.php b/cake/tests/cases/libs/cake_request.test.php
index e21450daf..8bded114f 100644
--- a/cake/tests/cases/libs/cake_request.test.php
+++ b/cake/tests/cases/libs/cake_request.test.php
@@ -678,10 +678,10 @@ class CakeRequestTestCase extends CakeTestCase {
$request->addDetector('compare', array('env' => 'TEST_VAR', 'value' => 'something'));
$_SERVER['TEST_VAR'] = 'something';
- $this->assertTrue($request->is('compare'), 'Value match failed %s.');
+ $this->assertTrue($request->is('compare'), 'Value match failed.');
$_SERVER['TEST_VAR'] = 'wrong';
- $this->assertFalse($request->is('compare'), 'Value mis-match failed %s.');
+ $this->assertFalse($request->is('compare'), 'Value mis-match failed.');
$request->addDetector('banana', array('env' => 'TEST_VAR', 'pattern' => '/^ban.*$/'));
$_SERVER['TEST_VAR'] = 'banana';
From 612c52bb8b98506fc80e8c31ba0153e21a126f1f Mon Sep 17 00:00:00 2001
From: mark_story
Date: Sun, 29 Aug 2010 23:31:20 -0400
Subject: [PATCH 058/166] Adding a beforeRender() that automatically escapes
all the content sent to errors handled by CakeErrorController.
---
cake/libs/controller/cake_error_controller.php | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/cake/libs/controller/cake_error_controller.php b/cake/libs/controller/cake_error_controller.php
index aafa76b6d..eb60e02b6 100644
--- a/cake/libs/controller/cake_error_controller.php
+++ b/cake/libs/controller/cake_error_controller.php
@@ -31,4 +31,15 @@ class CakeErrorController extends AppController {
$this->Components->trigger('initialize', array(&$this));
$this->_set(array('cacheAction' => false, 'viewPath' => 'errors'));
}
+
+/**
+ * Escapes the viewVars.
+ *
+ * @return void
+ */
+ function beforeRender() {
+ foreach ($this->viewVars as $key => $value) {
+ $this->viewVars[$key] = h($value);
+ }
+ }
}
\ No newline at end of file
From 534f6006f83f5593863784364909249d94f6dd2b Mon Sep 17 00:00:00 2001
From: mark_story
Date: Sun, 29 Aug 2010 23:38:46 -0400
Subject: [PATCH 059/166] Adding omitted parent call.
---
cake/libs/controller/cake_error_controller.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/cake/libs/controller/cake_error_controller.php b/cake/libs/controller/cake_error_controller.php
index eb60e02b6..a5293d276 100644
--- a/cake/libs/controller/cake_error_controller.php
+++ b/cake/libs/controller/cake_error_controller.php
@@ -38,6 +38,7 @@ class CakeErrorController extends AppController {
* @return void
*/
function beforeRender() {
+ parent::beforeRender();
foreach ($this->viewVars as $key => $value) {
$this->viewVars[$key] = h($value);
}
From 1f30c06695911ea10543140abe4667155d573aae Mon Sep 17 00:00:00 2001
From: mark_story
Date: Sun, 29 Aug 2010 23:39:28 -0400
Subject: [PATCH 060/166] Fixing method coercion in error404 so it only coerces
CakeExceptions. Test Added.
---
cake/libs/error_handler.php | 2 +-
cake/tests/cases/libs/error_handler.test.php | 24 ++++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/cake/libs/error_handler.php b/cake/libs/error_handler.php
index 7b3235a51..75b9efa10 100644
--- a/cake/libs/error_handler.php
+++ b/cake/libs/error_handler.php
@@ -179,7 +179,7 @@ class ErrorHandler {
*/
public function error404($error) {
$message = $error->getMessage();
- if (Configure::read('debug') == 0) {
+ if (Configure::read('debug') == 0 && $error instanceof CakeException) {
$message = __('Not Found');
}
$url = Router::normalize($this->controller->request->here);
diff --git a/cake/tests/cases/libs/error_handler.test.php b/cake/tests/cases/libs/error_handler.test.php
index d36af6a9b..c38795999 100644
--- a/cake/tests/cases/libs/error_handler.test.php
+++ b/cake/tests/cases/libs/error_handler.test.php
@@ -376,6 +376,30 @@ class ErrorHandlerTest extends CakeTestCase {
App::build();
}
+/**
+ * test that error404 only modifies the messages on CakeExceptions.
+ *
+ * @return void
+ */
+ function testError404OnlyChangingCakeException() {
+ Configure::write('debug', 0);
+
+ $exception = new Error404Exception('Custom message');
+ $ErrorHandler = new ErrorHandler($exception);
+
+ ob_start();
+ $ErrorHandler->render();
+ $result = ob_get_clean();
+ $this->assertContains('Custom message', $result);
+
+ $exception = new MissingActionException(array('controller' => 'PostsController', 'action' => 'index'));
+ $ErrorHandler = new ErrorHandler($exception);
+
+ ob_start();
+ $ErrorHandler->render();
+ $result = ob_get_clean();
+ $this->assertContains('Not Found', $result);
+ }
/**
* test that error404 doesn't expose XSS
*
From a8d4015f47d31cff254bf6e9fce961cdd4c4598c Mon Sep 17 00:00:00 2001
From: mark_story
Date: Mon, 30 Aug 2010 22:59:10 -0400
Subject: [PATCH 061/166] Updating bootstrap process in CLI to match the one in
web. Updating all_libs to use new file. Updating error_handler test to run in
cli. Updating Controller so it imports required classes.
---
cake/console/cake.php | 1 +
cake/libs/controller/controller.php | 1 +
cake/tests/cases/libs/all_libs.test.php | 2 +-
cake/tests/cases/libs/error_handler.test.php | 2 +-
4 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/cake/console/cake.php b/cake/console/cake.php
index 4e4673cfc..0b94cb888 100644
--- a/cake/console/cake.php
+++ b/cake/console/cake.php
@@ -260,6 +260,7 @@ class ShellDispatcher {
$includes = array(
CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php',
+ CORE_PATH . 'cake' . DS . 'libs' . DS . 'exceptions.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'object.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'inflector.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'configure.php',
diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php
index db1636ec0..97cfa8a4d 100644
--- a/cake/libs/controller/controller.php
+++ b/cake/libs/controller/controller.php
@@ -22,6 +22,7 @@
* Include files
*/
App::import('Controller', 'Component', false);
+App::import('Core', 'CakeResponse', false);
App::import('View', 'View', false);
/**
diff --git a/cake/tests/cases/libs/all_libs.test.php b/cake/tests/cases/libs/all_libs.test.php
index 905c23c1e..32a196953 100644
--- a/cake/tests/cases/libs/all_libs.test.php
+++ b/cake/tests/cases/libs/all_libs.test.php
@@ -39,7 +39,7 @@ class AllLibsTest extends PHPUnit_Framework_TestSuite {
$suite->addTestFile(CORE_TEST_CASES . DS . 'basics.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_session.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'debugger.test.php');
- $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'error.test.php');
+ $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'error_handler.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'file.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'folder.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'log' . DS . 'file_log.test.php');
diff --git a/cake/tests/cases/libs/error_handler.test.php b/cake/tests/cases/libs/error_handler.test.php
index c38795999..de2d82662 100644
--- a/cake/tests/cases/libs/error_handler.test.php
+++ b/cake/tests/cases/libs/error_handler.test.php
@@ -18,6 +18,7 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
+App::import('Core', array('ErrorHandler', 'Controller', 'Component'));
/**
* Short description for class.
@@ -89,7 +90,6 @@ if (!class_exists('AppController')) {
} elseif (!defined('APP_CONTROLLER_EXISTS')){
define('APP_CONTROLLER_EXISTS', true);
}
-App::import('Core', array('ErrorHandler', 'Controller', 'Component'));
/**
* BlueberryComponent class
From 08d6c19ab6aa65f68226d7dafd0a3ab27bd7ea26 Mon Sep 17 00:00:00 2001
From: mark_story
Date: Tue, 31 Aug 2010 21:21:05 -0400
Subject: [PATCH 062/166] Adding test for themes in app/webroot dir. Closes
#1061
---
.../cases/libs/view/helpers/html.test.php | 28 +++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/cake/tests/cases/libs/view/helpers/html.test.php b/cake/tests/cases/libs/view/helpers/html.test.php
index 5b98a6d33..05bd540db 100644
--- a/cake/tests/cases/libs/view/helpers/html.test.php
+++ b/cake/tests/cases/libs/view/helpers/html.test.php
@@ -626,6 +626,34 @@ class HtmlHelperTest extends CakeTestCase {
$this->assertNull($result);
}
+/**
+ * test a script file in the webroot/theme dir.
+ *
+ * @return void
+ */
+ function testScriptInTheme() {
+ if ($this->skipIf(!is_writable(WWW_ROOT . 'theme'), 'Cannot write to webroot/theme')) {
+ return;
+ }
+ App::import('Core', 'File');
+
+ $testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'js' . DS . '__test_js.js';
+ $file =& new File($testfile, true);
+
+ App::build(array(
+ 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
+ ));
+
+ $this->Html->webroot = '/';
+ $this->Html->theme = 'test_theme';
+ $result = $this->Html->script('__test_js.js');
+ $expected = array(
+ 'script' => array('src' => '/theme/test_theme/js/__test_js.js', 'type' => 'text/javascript')
+ );
+ $this->assertTags($result, $expected);
+ App::build();
+ }
+
/**
* test Script block generation
*
From 063fcf557d31b6e5af382b367f96257d5b89a973 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Wed, 1 Sep 2010 20:29:55 -0400
Subject: [PATCH 063/166] Moving error handler inclusion to before
Configure::bootstrap() so app error handlers can be created. Fixing issue
where unknown exception types would not be handled spewing out errors.
Unknown exception types are interpreted as 500 errors.
---
cake/bootstrap.php | 3 ++-
cake/libs/error_handler.php | 6 +++++-
cake/tests/cases/libs/error_handler.test.php | 13 +++++++++++++
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/cake/bootstrap.php b/cake/bootstrap.php
index 5499ed029..d9149d8f7 100644
--- a/cake/bootstrap.php
+++ b/cake/bootstrap.php
@@ -33,7 +33,8 @@ require LIBS . 'inflector.php';
require LIBS . 'configure.php';
require LIBS . 'set.php';
require LIBS . 'cache.php';
-Configure::bootstrap();
require LIBS . 'error_handler.php';
set_exception_handler(array('ErrorHandler', 'handleException'));
+
+Configure::bootstrap();
require CAKE . 'dispatcher.php';
diff --git a/cake/libs/error_handler.php b/cake/libs/error_handler.php
index 75b9efa10..a586c6812 100644
--- a/cake/libs/error_handler.php
+++ b/cake/libs/error_handler.php
@@ -62,7 +62,9 @@ class ErrorHandler {
public $error = null;
/**
- * Class constructor.
+ * Creates the controller to perform rendering on the error response.
+ * If the error is a CakeException it will be converted to either a 404 or a 500
+ * type error depending on the code used to construct the error.
*
* @param string $method Method producing the error
* @param array $messages Error messages
@@ -79,6 +81,8 @@ class ErrorHandler {
if ($exception instanceof CakeException && !in_array($method, get_class_methods($this))) {
$method = '_cakeError';
+ } elseif (!method_exists($this, $method)) {
+ $method = 'error500';
}
if ($method !== 'error' && Configure::read('debug') == 0) {
diff --git a/cake/tests/cases/libs/error_handler.test.php b/cake/tests/cases/libs/error_handler.test.php
index de2d82662..9030e6c21 100644
--- a/cake/tests/cases/libs/error_handler.test.php
+++ b/cake/tests/cases/libs/error_handler.test.php
@@ -330,6 +330,19 @@ class ErrorHandlerTest extends CakeTestCase {
$this->assertEquals($exception, $ErrorHandler->error);
}
+/**
+ * test that unknown exception types are captured and converted to 500
+ *
+ * @return void
+ */
+ function testUnknownExceptionType() {
+ $exception = new MissingWidgetThingException('coding fail.');
+ $ErrorHandler = new ErrorHandler($exception);
+
+ $this->assertFalse(method_exists($ErrorHandler, 'missingWidgetThing'), 'no method should exist.');
+ $this->assertEquals('error500', $ErrorHandler->method, 'incorrect method coercion.');
+ }
+
/**
* testError method
*
From 3e5e52d52e5775d8836342a4623b0dc1a6ca3fda Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Thu, 2 Sep 2010 00:29:04 -0400
Subject: [PATCH 064/166] Fixing doc block for Form::create(). Fixes #1058
---
cake/libs/view/helpers/form.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php
index 29dc58116..3a9c60815 100644
--- a/cake/libs/view/helpers/form.php
+++ b/cake/libs/view/helpers/form.php
@@ -172,7 +172,7 @@ class FormHelper extends AppHelper {
* ### Options:
*
* - `type` Form method defaults to POST
- * - `action` The Action the form submits to. Can be a string or array,
+ * - `action` The controller action the form submits to, (optional).
* - `url` The url the form submits to. Can be a string or a url array,
* - `default` Allows for the creation of Ajax forms.
* - `onsubmit` Used in conjunction with 'default' to create ajax forms.
From dbdd17f51ad26e27cae5c61e6938284f5f1a6267 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Thu, 2 Sep 2010 11:16:10 -0400
Subject: [PATCH 065/166] Adding test cases from 'euromark' and updating how
email addresses are parsed so they are slightly more conformant to RFC 5322.
Fixes #1066
---
cake/libs/controller/components/email.php | 13 ++++-----
.../libs/controller/components/email.test.php | 28 +++++++++++++++++++
2 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php
index aae446593..53d642b0f 100755
--- a/cake/libs/controller/components/email.php
+++ b/cake/libs/controller/components/email.php
@@ -743,19 +743,16 @@ class EmailComponent extends Object{
* @access private
*/
function _formatAddress($string, $smtp = false) {
- if (strpos($string, '<') !== false) {
- $value = explode('<', $string);
- if ($smtp) {
- $string = '<' . $value[1];
- } else {
- $string = $this->_encode($value[0]) . ' <' . $value[1];
- }
+ $hasAlias = preg_match('/(.+)\s<(.+)>/', $string, $matches);
+ if ($hasAlias) {
+ return $this->_strip($matches[1] . ' <' . $matches[2] . '>');
}
return $this->_strip($string);
}
/**
- * Remove certain elements (such as bcc:, to:, %0a) from given value
+ * Remove certain elements (such as bcc:, to:, %0a) from given value.
+ * Helps prevent header injection / mainipulation on user content.
*
* @param string $value Value to strip
* @param boolean $message Set to true to indicate main message content
diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php
index 6d19c77f0..4684d88df 100755
--- a/cake/tests/cases/libs/controller/components/email.test.php
+++ b/cake/tests/cases/libs/controller/components/email.test.php
@@ -128,6 +128,15 @@ class EmailTestComponent extends EmailComponent {
function strip($content, $message = false) {
return parent::_strip($content, $message);
}
+
+/**
+ * Wrapper for testing.
+ *
+ * @return void
+ */
+ function formatAddress($string, $smtp = false) {
+ return parent::_formatAddress($string, $smtp);
+ }
}
/**
@@ -1151,4 +1160,23 @@ HTMLBLOC;
);
$this->assertEqual($expected, $result);
}
+
+/**
+ * Test that _formatName doesn't jack up email addresses with alias parts.
+ *
+ * @return void
+ */
+ function testFormatAddressAliases() {
+ $result = $this->Controller->EmailTest->formatAddress('email@example.com');
+ $this->assertEqual($result, 'email@example.com');
+
+ $result = $this->Controller->EmailTest->formatAddress('alias ');
+ $this->assertEqual($result, 'alias ');
+
+ $result = $this->Controller->EmailTest->formatAddress('email@example.com');
+ $this->assertEqual($result, 'email@example.com');
+
+ $result = $this->Controller->EmailTest->formatAddress('');
+ $this->assertEqual($result, '');
+ }
}
From 2e8a60f93244c08db65de0cc3ef3b47aaaefa417 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Thu, 2 Sep 2010 16:38:19 -0400
Subject: [PATCH 066/166] Removing some mentions of cakeError as its been
removed. Also adding information about exceptions that can be raised.
---
cake/libs/controller/controller.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php
index 97cfa8a4d..88be76e90 100644
--- a/cake/libs/controller/controller.php
+++ b/cake/libs/controller/controller.php
@@ -491,9 +491,10 @@ class Controller extends Object {
* see Controller::loadModel(); for more info.
* Loads Components and prepares them for initialization.
*
- * @return mixed true if models found and instance created, or cakeError if models not found.
+ * @return mixed true if models found and instance created.
* @see Controller::loadModel()
* @link http://book.cakephp.org/view/977/Controller-Methods#constructClasses-986
+ * @throws MissingModelException
*/
public function constructClasses() {
$this->__mergeVars();
From 3940b059a370f854daa8d8fd93b310a6638be295 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Thu, 2 Sep 2010 16:39:09 -0400
Subject: [PATCH 067/166] Adding a big docblock to explain how to setup
application exception handling.
---
cake/libs/error_handler.php | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/cake/libs/error_handler.php b/cake/libs/error_handler.php
index a586c6812..966d2108c 100644
--- a/cake/libs/error_handler.php
+++ b/cake/libs/error_handler.php
@@ -23,9 +23,31 @@
/**
* Error Handler.
*
- * Captures and handles all cakeError() calls.
- * Displays helpful framework errors when debug > 1.
- * When debug < 1 cakeError() will render 404 or 500 errors.
+ * Captures and handles all unhandled exceptions. Displays helpful framework errors when debug > 1.
+ * When debug < 1 cakeError() will render 404 or 500 errors. If an uncaught exception is thrown
+ * and it is a type that ErrorHandler does not know about it will be treated as a 500 error.
+ *
+ * ### Implementing application specific exception handling
+ *
+ * You can implement application specific exception handling in one of a few ways:
+ *
+ * - Create a AppController::appError();
+ * - Create an AppError class.
+ *
+ * #### Using AppController::appError();
+ *
+ * This controller method is called instead of the default exception handling. It receives the
+ * thrown exception as its only argument. You should implement your error handling in that method.
+ *
+ * #### Using an AppError class
+ *
+ * This approach gives more flexibility and power in how you handle exceptions. You can create
+ * `app/libs/app_error.php` and create a class called `AppError`. The core ErrorHandler class
+ * will attempt to construct this class and let it handle the exception. This provides a more
+ * flexible way to handle exceptions in your application.
+ *
+ * Finally, in your `app/config/bootstrap.php` you can configure use `set_exception_handler()`
+ * to take total control over application exception handling.
*
* @package cake
* @subpackage cake.cake.libs
From ffa8b959e483cb2fdd0feb069f65de092d357c21 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Thu, 2 Sep 2010 16:47:06 -0400
Subject: [PATCH 068/166] Changing classname and importing base class.
---
cake/console/error.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/cake/console/error.php b/cake/console/error.php
index 21860ef0d..1df183b12 100644
--- a/cake/console/error.php
+++ b/cake/console/error.php
@@ -18,13 +18,14 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
+App::import('Core', 'ErrorHandler');
/**
* Error Handler for Cake console.
*
* @package cake
* @subpackage cake.cake.console
*/
-class ErrorHandler extends Object {
+class ConsoleErrorHandler extends ErrorHandler {
/**
* Standard output stream.
From d6b43c0e2935acd67e0ba125a4c7c2982892d41c Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Thu, 2 Sep 2010 16:55:42 -0400
Subject: [PATCH 069/166] Removing TIME_START global, use
$_SERVER['REQUEST_TIME'] instead.
---
cake/bootstrap.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/cake/bootstrap.php b/cake/bootstrap.php
index d9149d8f7..f6288ee01 100644
--- a/cake/bootstrap.php
+++ b/cake/bootstrap.php
@@ -25,7 +25,6 @@ if (!defined('E_DEPRECATED')) {
error_reporting(E_ALL & ~E_DEPRECATED);
require CORE_PATH . 'cake' . DS . 'basics.php';
-$TIME_START = microtime(true);
require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
require LIBS . 'exceptions.php';
require LIBS . 'object.php';
From 81e6ca22490a2b4b560f2e1a0b160b83d5fee20d Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Thu, 2 Sep 2010 17:00:52 -0400
Subject: [PATCH 070/166] Moving dispatcher include so that cake/bootstrap.php
is only bootstrapping the framework. This should allow reusing the bootstrap
file for console and web once console error handler is fixed.
---
app/webroot/index.php | 1 +
cake/bootstrap.php | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/app/webroot/index.php b/app/webroot/index.php
index 396775b73..f6984a448 100644
--- a/app/webroot/index.php
+++ b/app/webroot/index.php
@@ -79,6 +79,7 @@
if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') {
return;
} else {
+ require CAKE . 'dispatcher.php';
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch();
}
diff --git a/cake/bootstrap.php b/cake/bootstrap.php
index f6288ee01..33b29eeea 100644
--- a/cake/bootstrap.php
+++ b/cake/bootstrap.php
@@ -36,4 +36,4 @@ require LIBS . 'error_handler.php';
set_exception_handler(array('ErrorHandler', 'handleException'));
Configure::bootstrap();
-require CAKE . 'dispatcher.php';
+
From 034aaa7462ce0225620621b726ddf1c01d0e1d5a Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Thu, 2 Sep 2010 17:16:57 -0400
Subject: [PATCH 071/166] Creating optional boot variable that informs
Configure if it should bootstrap the app. Changing how ShellDispatcher
checks for app existence it sets the $boot var now and reuses the framework
bootstrap file instead of a second custom one.
---
cake/bootstrap.php | 2 +-
cake/console/cake.php | 28 +++-------------------------
2 files changed, 4 insertions(+), 26 deletions(-)
diff --git a/cake/bootstrap.php b/cake/bootstrap.php
index 33b29eeea..413ef9931 100644
--- a/cake/bootstrap.php
+++ b/cake/bootstrap.php
@@ -35,5 +35,5 @@ require LIBS . 'cache.php';
require LIBS . 'error_handler.php';
set_exception_handler(array('ErrorHandler', 'handleException'));
-Configure::bootstrap();
+Configure::bootstrap(isset($boot) ? $boot : true);
diff --git a/cake/console/cake.php b/cake/console/cake.php
index 0b94cb888..149247d04 100644
--- a/cake/console/cake.php
+++ b/cake/console/cake.php
@@ -20,9 +20,7 @@
* @since CakePHP(tm) v 1.2.0.5012
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-if (!defined('E_DEPRECATED')) {
- define('E_DEPRECATED', 8192);
-}
+
/**
* Shell dispatcher
*
@@ -172,7 +170,6 @@ class ShellDispatcher {
}
}
}
- require_once(CORE_PATH . 'cake' . DS . 'basics.php');
}
/**
@@ -258,27 +255,8 @@ class ShellDispatcher {
define('TMP', CORE_PATH . 'cake' . DS . 'console' . DS . 'templates' . DS . 'skel' . DS . 'tmp' . DS);
}
- $includes = array(
- CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php',
- CORE_PATH . 'cake' . DS . 'libs' . DS . 'exceptions.php',
- CORE_PATH . 'cake' . DS . 'libs' . DS . 'object.php',
- CORE_PATH . 'cake' . DS . 'libs' . DS . 'inflector.php',
- CORE_PATH . 'cake' . DS . 'libs' . DS . 'configure.php',
- CORE_PATH . 'cake' . DS . 'libs' . DS . 'file.php',
- CORE_PATH . 'cake' . DS . 'libs' . DS . 'cache.php',
- CORE_PATH . 'cake' . DS . 'libs' . DS . 'string.php',
- CORE_PATH . 'cake' . DS . 'libs' . DS . 'class_registry.php',
- CORE_PATH . 'cake' . DS . 'console' . DS . 'error.php'
- );
-
- foreach ($includes as $inc) {
- if (!require($inc)) {
- $this->stderr("Failed to load Cake core file {$inc}");
- return false;
- }
- }
-
- Configure::bootstrap(file_exists(CONFIGS . 'bootstrap.php'));
+ $boot = file_exists(ROOT . DS . APP_DIR . DS . 'config' . DS . 'bootstrap.php');
+ require CORE_PATH . 'cake' . DS . 'bootstrap.php';
if (!file_exists(APP_PATH . 'config' . DS . 'core.php')) {
include_once CORE_PATH . 'cake' . DS . 'console' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
From 60e44660c3f4d0fdd8c75d0e2394d6eeb837369e Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Thu, 2 Sep 2010 17:49:00 -0400
Subject: [PATCH 072/166] Moving ErrorHandler to ConsoleErrorHandler so it
doesn't have classname conflicts. Making the console use a subclass of
ErrorHandler.
---
cake/console/console_error_handler.php | 99 ++++++++++
cake/console/error.php | 249 -------------------------
2 files changed, 99 insertions(+), 249 deletions(-)
create mode 100644 cake/console/console_error_handler.php
delete mode 100644 cake/console/error.php
diff --git a/cake/console/console_error_handler.php b/cake/console/console_error_handler.php
new file mode 100644
index 000000000..ed7f49710
--- /dev/null
+++ b/cake/console/console_error_handler.php
@@ -0,0 +1,99 @@
+stderr = fopen('php://stderr', 'w');
+ parent::__construct($error);
+ }
+
+/**
+ * Handle a exception in the console environment.
+ *
+ * @return void
+ */
+ public static function handleException($exception) {
+ $error = new ConsoleErrorHandler($exception);
+ $error->render();
+ }
+
+/**
+ * Do nothing, no controllers are needed in the console.
+ *
+ * @return void
+ */
+ protected function _getController($exception) {
+ return null;
+ }
+
+/**
+ * Overwrite how _cakeError behaves for console. There is no reason
+ * to prepare urls as they are not relevant for this.
+ *
+ * @param $error Exception Exception being handled.
+ * @return void
+ */
+ protected function _cakeError($error) {
+ $this->_outputMessage('');
+ }
+
+/**
+ * Outputs the exception to STDERR.
+ *
+ * @param string $template The name of the template to render.
+ * @return void
+ */
+ public function _outputMessage($template) {
+ $this->stderr($this->error->getMessage());
+ }
+
+/**
+ * Outputs to the stderr filehandle.
+ *
+ * @param string $string Error text to output.
+ */
+ public function stderr($string) {
+ fwrite($this->stderr, "Error: ". $string . "\n");
+ }
+}
diff --git a/cake/console/error.php b/cake/console/error.php
deleted file mode 100644
index 1df183b12..000000000
--- a/cake/console/error.php
+++ /dev/null
@@ -1,249 +0,0 @@
-stdout = fopen('php://stdout', 'w');
- $this->stderr = fopen('php://stderr', 'w');
- call_user_func_array(array(&$this, $method), $messages);
- }
-
-/**
- * Displays an error page (e.g. 404 Not found).
- *
- * @param array $params Parameters (code, name, and message)
- */
- public function error($params) {
- extract($params, EXTR_OVERWRITE);
- $this->stderr($code . $name . $message."\n");
- $this->_stop();
- }
-
-/**
- * Convenience method to display a 404 page.
- *
- * @param array $params Parameters (url, message)
- */
- public function error404($params) {
- extract($params, EXTR_OVERWRITE);
- $this->error(array(
- 'code' => '404',
- 'name' => 'Not found',
- 'message' => sprintf(__('The requested address %s was not found on this server.'), $url, $message)
- ));
- $this->_stop();
- }
-
-/**
- * Renders the Missing Controller web page.
- *
- * @param array $params Parameters (className)
- */
- public function missingController($params) {
- extract($params, EXTR_OVERWRITE);
- $controllerName = str_replace('Controller', '', $className);
- $this->stderr(sprintf(__("Missing Controller '%s'"), $controllerName));
- $this->_stop();
- }
-
-/**
- * Renders the Missing Action web page.
- *
- * @param array $params Parameters (action, className)
- */
- public function missingAction($params) {
- extract($params, EXTR_OVERWRITE);
- $this->stderr(sprintf(__("Missing Method '%s' in '%s'"), $action, $className));
- $this->_stop();
- }
-
-/**
- * Renders the Private Action web page.
- *
- * @param array $params Parameters (action, className)
- */
- public function privateAction($params) {
- extract($params, EXTR_OVERWRITE);
- $this->stderr(sprintf(__("Trying to access private method '%s' in '%s'"), $action, $className));
- $this->_stop();
- }
-
-/**
- * Renders the Missing Table web page.
- *
- * @param array $params Parameters (table, className)
- */
- public function missingTable($params) {
- extract($params, EXTR_OVERWRITE);
- $this->stderr(sprintf(__("Missing database table '%s' for model '%s'"), $table, $className));
- $this->_stop();
- }
-
-/**
- * Renders the Missing Database web page.
- *
- * @param array $params Parameters
- */
- public function missingDatabase($params = array()) {
- $this->stderr(__('Missing Database'));
- $this->_stop();
- }
-
-/**
- * Renders the Missing View web page.
- *
- * @param array $params Parameters (file, action, className)
- */
- public function missingView($params) {
- extract($params, EXTR_OVERWRITE);
- $this->stderr(sprintf(__("Missing View '%s' for '%s' in '%s'"), $file, $action, $className));
- $this->_stop();
- }
-
-/**
- * Renders the Missing Layout web page.
- *
- * @param array $params Parameters (file)
- */
- public function missingLayout($params) {
- extract($params, EXTR_OVERWRITE);
- $this->stderr(sprintf(__("Missing Layout '%s'"), $file));
- $this->_stop();
- }
-
-/**
- * Renders the Database Connection web page.
- *
- * @param array $params Parameters
- */
- public function missingConnection($params) {
- extract($params, EXTR_OVERWRITE);
- $this->stderr(__("Missing Database Connection. Try 'cake bake'"));
- $this->_stop();
- }
-
-/**
- * Renders the Missing Helper file web page.
- *
- * @param array $params Parameters (file, helper)
- */
- public function missingHelperFile($params) {
- extract($params, EXTR_OVERWRITE);
- $this->stderr(sprintf(__("Missing Helper file '%s' for '%s'"), $file, Inflector::camelize($helper)));
- $this->_stop();
- }
-
-/**
- * Renders the Missing Helper class web page.
- *
- * @param array $params Parameters (file, helper)
- */
- public function missingHelperClass($params) {
- extract($params, EXTR_OVERWRITE);
- $this->stderr(sprintf(__("Missing Helper class '%s' in '%s'"), Inflector::camelize($helper), $file));
- $this->_stop();
- }
-
-/**
- * Renders the Missing Component file web page.
- *
- * @param array $params Parameters (file, component)
- */
- public function missingComponentFile($params) {
- extract($params, EXTR_OVERWRITE);
- $this->stderr(sprintf(__("Missing Component file '%s' for '%s'"), $file, Inflector::camelize($component)));
- $this->_stop();
- }
-
-/**
- * Renders the Missing Component class web page.
- *
- * @param array $params Parameters (file, component)
- */
- public function missingComponentClass($params) {
- extract($params, EXTR_OVERWRITE);
- $this->stderr(sprintf(__("Missing Component class '%s' in '%s'"), Inflector::camelize($component), $file));
- $this->_stop();
- }
-
-/**
- * Renders the Missing Model class web page.
- *
- * @param array $params Parameters (className)
- */
- public function missingModel($params) {
- extract($params, EXTR_OVERWRITE);
- $this->stderr(sprintf(__("Missing model '%s'"), $className));
- $this->_stop();
- }
-
-/**
- * Outputs to the stdout filehandle.
- *
- * @param string $string String to output.
- * @param boolean $newline If true, the outputs gets an added newline.
- */
- public function stdout($string, $newline = true) {
- if ($newline) {
- fwrite($this->stdout, $string . "\n");
- } else {
- fwrite($this->stdout, $string);
- }
- }
-
-/**
- * Outputs to the stderr filehandle.
- *
- * @param string $string Error text to output.
- */
- public function stderr($string) {
- fwrite($this->stderr, "Error: ". $string . "\n");
- }
-}
From a44b35311d1817d8c99b2133029d5c399eaf129b Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Thu, 2 Sep 2010 17:49:43 -0400
Subject: [PATCH 073/166] Integrating the ConsoleErrorHandler into the console
environment.
---
cake/console/cake.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/cake/console/cake.php b/cake/console/cake.php
index 149247d04..1ec1e9088 100644
--- a/cake/console/cake.php
+++ b/cake/console/cake.php
@@ -257,6 +257,8 @@ class ShellDispatcher {
$boot = file_exists(ROOT . DS . APP_DIR . DS . 'config' . DS . 'bootstrap.php');
require CORE_PATH . 'cake' . DS . 'bootstrap.php';
+ require CORE_PATH . 'cake' . DS . 'console' . DS . 'console_error_handler.php';
+ set_exception_handler(array('ConsoleErrorHandler', 'handleException'));
if (!file_exists(APP_PATH . 'config' . DS . 'core.php')) {
include_once CORE_PATH . 'cake' . DS . 'console' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
From a1e01e414b665e6b192bbb0e916ec3ebdb2fab62 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Thu, 2 Sep 2010 18:02:58 -0400
Subject: [PATCH 074/166] Adding a tests for CakeExceptions and non
CakeExceptions
---
cake/console/console_error_handler.php | 23 +++++-
.../console/console_error_handler.test.php | 73 +++++++++++++++++++
2 files changed, 94 insertions(+), 2 deletions(-)
create mode 100644 cake/tests/cases/console/console_error_handler.test.php
diff --git a/cake/console/console_error_handler.php b/cake/console/console_error_handler.php
index ed7f49710..0883b8b7f 100644
--- a/cake/console/console_error_handler.php
+++ b/cake/console/console_error_handler.php
@@ -75,16 +75,35 @@ class ConsoleErrorHandler extends ErrorHandler {
* @return void
*/
protected function _cakeError($error) {
- $this->_outputMessage('');
+ $this->_outputMessage();
}
+/**
+ * Override error404 method
+ *
+ * @param Exception $error Exception
+ * @return void
+ */
+ public function error404($error) {
+ $this->_outputMessage();
+ }
+
+/**
+ * Override error500 method
+ *
+ * @param Exception $error Exception
+ * @return void
+ */
+ public function error500($error) {
+ $this->_outputMessage();
+ }
/**
* Outputs the exception to STDERR.
*
* @param string $template The name of the template to render.
* @return void
*/
- public function _outputMessage($template) {
+ public function _outputMessage($template = null) {
$this->stderr($this->error->getMessage());
}
diff --git a/cake/tests/cases/console/console_error_handler.test.php b/cake/tests/cases/console/console_error_handler.test.php
new file mode 100644
index 000000000..42b1a88ce
--- /dev/null
+++ b/cake/tests/cases/console/console_error_handler.test.php
@@ -0,0 +1,73 @@
+output[] = $line;
+ }
+}
+
+
+/**
+ * ConsoleErrorHandler Test case.
+ *
+ * @package cake.tests.cases.console
+ */
+class ConsoleErrorHandlerTest extends CakeTestCase {
+
+/**
+ * test that the console error handler can deal with CakeExceptions.
+ *
+ * @return void
+ */
+ function testCakeErrors() {
+ $exception = new MissingActionException('Missing action');
+ $error = new TestConsoleErrorHandler($exception);
+ $error->render();
+
+ $result = $error->output;
+ $this->assertEquals(1, count($result));
+ $this->assertEquals('Missing action', $result[0]);
+ }
+
+/**
+ * test a non CakeException exception.
+ *
+ * @return void
+ */
+ function testNonCakeExceptions() {
+ $exception = new InvalidArgumentException('Too many parameters.');
+ $error = new TestConsoleErrorHandler($exception);
+ $error->render();
+
+ $result = $error->output;
+ $this->assertEquals(1, count($result));
+ $this->assertEquals('Too many parameters.', $result[0]);
+ }
+}
\ No newline at end of file
From 29ade860b117f55d3e72f183ea6b597dd79e03ff Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Thu, 2 Sep 2010 18:04:50 -0400
Subject: [PATCH 075/166] Adding cases for Error404 and Error500 exceptions.
---
.../console/console_error_handler.test.php | 30 +++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/cake/tests/cases/console/console_error_handler.test.php b/cake/tests/cases/console/console_error_handler.test.php
index 42b1a88ce..eba6d24f6 100644
--- a/cake/tests/cases/console/console_error_handler.test.php
+++ b/cake/tests/cases/console/console_error_handler.test.php
@@ -70,4 +70,34 @@ class ConsoleErrorHandlerTest extends CakeTestCase {
$this->assertEquals(1, count($result));
$this->assertEquals('Too many parameters.', $result[0]);
}
+
+/**
+ * test a Error404 exception.
+ *
+ * @return void
+ */
+ function testError404Exception() {
+ $exception = new Error404Exception('dont use me in cli.');
+ $error = new TestConsoleErrorHandler($exception);
+ $error->render();
+
+ $result = $error->output;
+ $this->assertEquals(1, count($result));
+ $this->assertEquals('dont use me in cli.', $result[0]);
+ }
+
+/**
+ * test a Error500 exception.
+ *
+ * @return void
+ */
+ function testError500Exception() {
+ $exception = new Error500Exception('dont use me in cli.');
+ $error = new TestConsoleErrorHandler($exception);
+ $error->render();
+
+ $result = $error->output;
+ $this->assertEquals(1, count($result));
+ $this->assertEquals('dont use me in cli.', $result[0]);
+ }
}
\ No newline at end of file
From 2c7ef67e977528a17b6fe593bd0ab22a1d030ad2 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Fri, 3 Sep 2010 10:22:58 -0400
Subject: [PATCH 076/166] Fixing stupid output buffering error.
---
cake/tests/lib/reporter/cake_html_reporter.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/cake/tests/lib/reporter/cake_html_reporter.php b/cake/tests/lib/reporter/cake_html_reporter.php
index fb4840fef..a61366060 100755
--- a/cake/tests/lib/reporter/cake_html_reporter.php
+++ b/cake/tests/lib/reporter/cake_html_reporter.php
@@ -216,7 +216,9 @@ class CakeHtmlReporter extends CakeBaseReporter {
public function paintDocumentEnd() {
$baseDir = $this->params['baseDir'];
include CAKE_TESTS_LIB . 'templates/footer.php';
- ob_end_flush();
+ if (ob_get_length()) {
+ ob_end_flush();
+ }
}
/**
From f2db19767d55eeed646a12d1cd0673caa96ce891 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Fri, 3 Sep 2010 10:30:35 -0400
Subject: [PATCH 077/166] Adding in support for AppError.
---
cake/libs/error_handler.php | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/cake/libs/error_handler.php b/cake/libs/error_handler.php
index 966d2108c..5d147f476 100644
--- a/cake/libs/error_handler.php
+++ b/cake/libs/error_handler.php
@@ -4,7 +4,7 @@
*
* Provides Error Capturing for Framework errors.
*
- * PHP versions 4 and 5
+ * PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
@@ -99,6 +99,10 @@ class ErrorHandler {
if (method_exists($this->controller, 'apperror')) {
return $this->controller->appError($exception);
}
+ if (file_exists(APP . 'app_error.php') && class_exists('AppError')) {
+ $AppError = new AppError($exception);
+ return $AppError->render();
+ }
$method = $template = Inflector::variable(str_replace('Exception', '', get_class($exception)));
if ($exception instanceof CakeException && !in_array($method, get_class_methods($this))) {
From 5c0fe1b16e1635d7a3bdf60b43c90aae20665060 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Fri, 3 Sep 2010 12:33:59 -0400
Subject: [PATCH 078/166] Applying patch from 'majna'. Adding plugin to the
list of template variables exposed in the controller task. Test added Fixes
#1077
---
cake/console/libs/tasks/controller.php | 7 ++++---
cake/tests/cases/console/libs/tasks/controller.test.php | 2 ++
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/cake/console/libs/tasks/controller.php b/cake/console/libs/tasks/controller.php
index 36fd91600..b7f04bb18 100644
--- a/cake/console/libs/tasks/controller.php
+++ b/cake/console/libs/tasks/controller.php
@@ -275,8 +275,9 @@ class ControllerTask extends BakeTask {
*/
function bakeActions($controllerName, $admin = null, $wannaUseSession = true) {
$currentModelName = $modelImport = $this->_modelName($controllerName);
- if ($this->plugin) {
- $modelImport = $this->plugin . '.' . $modelImport;
+ $plugin = $this->plugin;
+ if ($plugin) {
+ $modelImport = $plugin . '.' . $modelImport;
}
if (!App::import('Model', $modelImport)) {
$this->err(__('You must have a model for this class to build basic methods. Please try again.', true));
@@ -290,7 +291,7 @@ class ControllerTask extends BakeTask {
$singularHumanName = $this->_singularHumanName($controllerName);
$pluralHumanName = $this->_pluralName($controllerName);
- $this->Template->set(compact('admin', 'controllerPath', 'pluralName', 'singularName', 'singularHumanName',
+ $this->Template->set(compact('plugin', 'admin', 'controllerPath', 'pluralName', 'singularName', 'singularHumanName',
'pluralHumanName', 'modelObj', 'wannaUseSession', 'currentModelName'));
$actions = $this->Template->generate('actions', 'controller_actions');
return $actions;
diff --git a/cake/tests/cases/console/libs/tasks/controller.test.php b/cake/tests/cases/console/libs/tasks/controller.test.php
index 0fbc888ff..618b0dfd3 100644
--- a/cake/tests/cases/console/libs/tasks/controller.test.php
+++ b/cake/tests/cases/console/libs/tasks/controller.test.php
@@ -299,6 +299,8 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->expectAt(1, 'createFile', array(
$path, new PatternExpectation('/ArticlesController extends ControllerTestAppController/')));
$this->Task->bake('Articles', '--actions--', array(), array(), array());
+
+ $this->assertEqual($this->Task->Template->templateVars['plugin'], 'ControllerTest');
}
/**
From 8c428ff8a89a33c4165026cd58e38b7e8b537c39 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Fri, 3 Sep 2010 15:03:33 -0400
Subject: [PATCH 079/166] Moving where AppError is used, as infinite recursion
is no fun.
---
cake/libs/error_handler.php | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/cake/libs/error_handler.php b/cake/libs/error_handler.php
index 5d147f476..3b59f55da 100644
--- a/cake/libs/error_handler.php
+++ b/cake/libs/error_handler.php
@@ -99,10 +99,6 @@ class ErrorHandler {
if (method_exists($this->controller, 'apperror')) {
return $this->controller->appError($exception);
}
- if (file_exists(APP . 'app_error.php') && class_exists('AppError')) {
- $AppError = new AppError($exception);
- return $AppError->render();
- }
$method = $template = Inflector::variable(str_replace('Exception', '', get_class($exception)));
if ($exception instanceof CakeException && !in_array($method, get_class_methods($this))) {
@@ -155,13 +151,21 @@ class ErrorHandler {
/**
* Set as the default exception handler by the CakePHP bootstrap process.
- * If you wish you use a custom default exception handler use set_exception_handler()
- * in your app/config/bootstrap.php.
+ *
+ * This will either use an AppError class if your application has one,
+ * or use the default ErrorHandler.
*
* @return void
* @see http://php.net/manual/en/function.set-exception-handler.php
*/
public static function handleException(Exception $exception) {
+ if (file_exists(APP . 'app_error.php') || class_exists('AppError')) {
+ if (!class_exists('AppError')) {
+ require(APP . 'app_error.php');
+ }
+ $AppError = new AppError($exception);
+ return $AppError->render();
+ }
$error = new ErrorHandler($exception);
$error->render();
}
From af87e5d5bc45866a75ae416a472fc4900f07c642 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Fri, 3 Sep 2010 15:35:11 -0400
Subject: [PATCH 080/166] Adding a skip when AppError is present, as its
behaviour is unknown.
---
cake/tests/cases/libs/error_handler.test.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/cake/tests/cases/libs/error_handler.test.php b/cake/tests/cases/libs/error_handler.test.php
index 9030e6c21..61d77dda1 100644
--- a/cake/tests/cases/libs/error_handler.test.php
+++ b/cake/tests/cases/libs/error_handler.test.php
@@ -236,6 +236,9 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testHandleException() {
+ if ($this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.')) {
+ return;
+ }
$error = new Error404Exception('Kaboom!');
ob_start();
ErrorHandler::handleException($error);
From fa7549dc4cd8e99cfcc4f7ad4c0abb4b7fc7fe34 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Sat, 4 Sep 2010 01:34:45 -0400
Subject: [PATCH 081/166] Fixing comments and removing cakeError(). Instead
you should be throwing exceptions.
---
cake/libs/error_handler.php | 4 ++--
cake/libs/object.php | 30 +-----------------------------
2 files changed, 3 insertions(+), 31 deletions(-)
diff --git a/cake/libs/error_handler.php b/cake/libs/error_handler.php
index 3b59f55da..8ae834d46 100644
--- a/cake/libs/error_handler.php
+++ b/cake/libs/error_handler.php
@@ -24,8 +24,8 @@
* Error Handler.
*
* Captures and handles all unhandled exceptions. Displays helpful framework errors when debug > 1.
- * When debug < 1 cakeError() will render 404 or 500 errors. If an uncaught exception is thrown
- * and it is a type that ErrorHandler does not know about it will be treated as a 500 error.
+ * When debug < 1 a CakeException will render 404 or 500 errors. If an uncaught exception is thrown
+ * and it is a type that ErrorHandler does not know about it will be treated as a 500 error.
*
* ### Implementing application specific exception handling
*
diff --git a/cake/libs/object.php b/cake/libs/object.php
index b4da0bd68..987ba0154 100644
--- a/cake/libs/object.php
+++ b/cake/libs/object.php
@@ -22,7 +22,7 @@
*/
/**
- * Object class, allowing __construct and __destruct in PHP4.
+ * Object class provides a few generic methods used in several subclasses.
*
* Also includes methods for logging and the special method RequestAction,
* to call other Controllers' Actions from anywhere.
@@ -155,34 +155,6 @@ class Object {
}
}
-/**
- * Used to report user friendly errors.
- * If there is a file app/error.php or app/app_error.php this file will be loaded
- * error.php is the AppError class it should extend ErrorHandler class.
- *
- * @param string $method Method to be called in the error class (AppError or ErrorHandler classes)
- * @param array $messages Message that is to be displayed by the error class
- * @return error message
- */
- public function cakeError($method, $messages = array()) {
- if (!class_exists('ErrorHandler')) {
- App::import('Core', 'Error');
-
- if (file_exists(APP . 'error.php')) {
- include_once (APP . 'error.php');
- } elseif (file_exists(APP . 'app_error.php')) {
- include_once (APP . 'app_error.php');
- }
- }
-
- if (class_exists('AppError')) {
- $error = new AppError($method, $messages);
- } else {
- $error = new ErrorHandler($method, $messages);
- }
- return $error;
- }
-
/**
* Checks for a persistent class file, if found file is opened and true returned
* If file is not found a file is created and false returned
From 42d998ca3bae7ed4494fde1c50e9004ca446eb44 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Sat, 4 Sep 2010 10:46:04 -0400
Subject: [PATCH 082/166] Fixing up the include for the console error handler,
and adding a test for stderr handle.
---
.../cases/console/console_error_handler.test.php | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/cake/tests/cases/console/console_error_handler.test.php b/cake/tests/cases/console/console_error_handler.test.php
index eba6d24f6..6ad8c7659 100644
--- a/cake/tests/cases/console/console_error_handler.test.php
+++ b/cake/tests/cases/console/console_error_handler.test.php
@@ -17,7 +17,7 @@
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-App::import('Core', 'ConsoleErrorHandler');
+require CAKE . 'console' . DS . 'console_error_handler.php';
class TestConsoleErrorHandler extends ConsoleErrorHandler {
public $output = array();
@@ -100,4 +100,16 @@ class ConsoleErrorHandlerTest extends CakeTestCase {
$this->assertEquals(1, count($result));
$this->assertEquals('dont use me in cli.', $result[0]);
}
+
+/**
+ * test that ConsoleErrorHandler has a stderr file handle.
+ *
+ * @return void
+ */
+ function testStdErrFilehandle() {
+ $exception = new Error500Exception('dont use me in cli.');
+ $error = new TestConsoleErrorHandler($exception);
+
+ $this->assertTrue(is_resource($error->stderr), 'No handle.');
+ }
}
\ No newline at end of file
From 4980f42dc52833e26d1a7672726927ace1e320b1 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Sat, 4 Sep 2010 15:35:01 -0400
Subject: [PATCH 083/166] Renaming file.
---
cake/libs/view/errors/{error404.ctp => error400.ctp} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename cake/libs/view/errors/{error404.ctp => error400.ctp} (100%)
diff --git a/cake/libs/view/errors/error404.ctp b/cake/libs/view/errors/error400.ctp
similarity index 100%
rename from cake/libs/view/errors/error404.ctp
rename to cake/libs/view/errors/error400.ctp
From dbd34c75c715d128423f09b287756c81c19fc718 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Sat, 4 Sep 2010 15:36:57 -0400
Subject: [PATCH 084/166] Removing newlines and trailing space.
---
cake/tests/cases/console/console_error_handler.test.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cake/tests/cases/console/console_error_handler.test.php b/cake/tests/cases/console/console_error_handler.test.php
index 6ad8c7659..e17fec34e 100644
--- a/cake/tests/cases/console/console_error_handler.test.php
+++ b/cake/tests/cases/console/console_error_handler.test.php
@@ -109,7 +109,7 @@ class ConsoleErrorHandlerTest extends CakeTestCase {
function testStdErrFilehandle() {
$exception = new Error500Exception('dont use me in cli.');
$error = new TestConsoleErrorHandler($exception);
-
+
$this->assertTrue(is_resource($error->stderr), 'No handle.');
}
}
\ No newline at end of file
From 4d863618f560dd362c79e1c1b9652bdff8fae839 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Sat, 4 Sep 2010 15:38:10 -0400
Subject: [PATCH 085/166] Refactoring exception handling so codes are much more
flexible and easy to change. Made error404 and error500 more generic. Removed
error() as it didn't really make that much sense.
---
cake/libs/error_handler.php | 39 ++++++--------
cake/tests/cases/libs/error_handler.test.php | 56 +++++++++-----------
2 files changed, 43 insertions(+), 52 deletions(-)
diff --git a/cake/libs/error_handler.php b/cake/libs/error_handler.php
index 8ae834d46..611f08982 100644
--- a/cake/libs/error_handler.php
+++ b/cake/libs/error_handler.php
@@ -100,22 +100,27 @@ class ErrorHandler {
return $this->controller->appError($exception);
}
$method = $template = Inflector::variable(str_replace('Exception', '', get_class($exception)));
+ $code = $exception->getCode();
- if ($exception instanceof CakeException && !in_array($method, get_class_methods($this))) {
+ $methodExists = method_exists($this, $method);
+
+ if ($exception instanceof CakeException && !$methodExists) {
$method = '_cakeError';
- } elseif (!method_exists($this, $method)) {
+ } elseif (!$methodExists) {
$method = 'error500';
+ if ($code >= 400) {
+ $method = 'error400';
+ }
}
- if ($method !== 'error' && Configure::read('debug') == 0) {
- $code = $exception->getCode();
+ if (Configure::read('debug') == 0) {
$parentClass = get_parent_class($this);
if ($parentClass != 'ErrorHandler') {
- $method = 'error404';
+ $method = 'error400';
}
$parentMethods = (array)get_class_methods($parentClass);
if (in_array($method, $parentMethods)) {
- $method = 'error404';
+ $method = 'error400';
}
if ($code == 500) {
$method = 'error500';
@@ -179,15 +184,6 @@ class ErrorHandler {
call_user_func_array(array($this, $this->method), array($this->error));
}
-/**
- * Displays an error page (e.g. 404 Not found).
- *
- * @param array $params Parameters for controller
- */
- public function error(Exception $error) {
- $this->error404($error);
- }
-
/**
* Generic handler for the internal framework errors CakePHP can generate.
*
@@ -207,23 +203,22 @@ class ErrorHandler {
}
/**
- * Convenience method to display a 404 page.
+ * Convenience method to display a 400 series page.
*
* @param array $params Parameters for controller
*/
- public function error404($error) {
+ public function error400($error) {
$message = $error->getMessage();
if (Configure::read('debug') == 0 && $error instanceof CakeException) {
$message = __('Not Found');
}
$url = Router::normalize($this->controller->request->here);
- $this->controller->response->statusCode(404);
+ $this->controller->response->statusCode($error->getCode());
$this->controller->set(array(
- 'code' => 404,
'name' => $message,
'url' => h($url),
));
- $this->_outputMessage('error404');
+ $this->_outputMessage('error400');
}
/**
@@ -231,9 +226,9 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
- public function error500($params) {
+ public function error500($error) {
$url = Router::normalize($this->controller->request->here);
- $this->controller->response->statusCode(500);
+ $this->controller->response->statusCode($error->getCode());
$this->controller->set(array(
'name' => __('An Internal Error Has Occurred'),
'message' => h($url),
diff --git a/cake/tests/cases/libs/error_handler.test.php b/cake/tests/cases/libs/error_handler.test.php
index 61d77dda1..170d246c1 100644
--- a/cake/tests/cases/libs/error_handler.test.php
+++ b/cake/tests/cases/libs/error_handler.test.php
@@ -248,7 +248,7 @@ class ErrorHandlerTest extends CakeTestCase {
/**
* test that methods declared in an ErrorHandler subclass are not converted
- * into error404 when debug > 0
+ * into error400 when debug > 0
*
* @return void
*/
@@ -281,7 +281,7 @@ class ErrorHandlerTest extends CakeTestCase {
$ErrorHandler->render();
$result = ob_get_clean();
- $this->assertEqual($result, 'widget thing is missing', 'Method declared in subclass converted to error404');
+ $this->assertEqual($result, 'widget thing is missing', 'Method declared in subclass converted to error400');
}
/**
@@ -295,13 +295,13 @@ class ErrorHandlerTest extends CakeTestCase {
$exception = new MissingControllerException('PostsController');
$ErrorHandler = new MyCustomErrorHandler($exception);
- $this->assertEqual('error404', $ErrorHandler->method);
+ $this->assertEqual('error400', $ErrorHandler->method);
ob_start();
$ErrorHandler->render();
$result = ob_get_clean();
- $this->assertPattern('/Not Found/', $result, 'Method declared in error handler not converted to error404. %s');
+ $this->assertPattern('/Not Found/', $result, 'Method declared in error handler not converted to error400. %s');
}
/**
@@ -314,7 +314,7 @@ class ErrorHandlerTest extends CakeTestCase {
$ErrorHandler = new ErrorHandler($exception);
$this->assertType('CakeErrorController', $ErrorHandler->controller);
- $this->assertEquals('error404', $ErrorHandler->method);
+ $this->assertEquals('error400', $ErrorHandler->method);
$this->assertEquals($exception, $ErrorHandler->error);
}
@@ -329,46 +329,42 @@ class ErrorHandlerTest extends CakeTestCase {
$ErrorHandler = new ErrorHandler($exception);
$this->assertType('CakeErrorController', $ErrorHandler->controller);
- $this->assertEquals('error404', $ErrorHandler->method);
+ $this->assertEquals('error400', $ErrorHandler->method);
$this->assertEquals($exception, $ErrorHandler->error);
}
/**
- * test that unknown exception types are captured and converted to 500
+ * test that unknown exception types with valid status codes are treated correctly.
*
* @return void
*/
- function testUnknownExceptionType() {
+ function testUnknownExceptionTypeWithExceptionThatHasA400Code() {
$exception = new MissingWidgetThingException('coding fail.');
$ErrorHandler = new ErrorHandler($exception);
$this->assertFalse(method_exists($ErrorHandler, 'missingWidgetThing'), 'no method should exist.');
+ $this->assertEquals('error400', $ErrorHandler->method, 'incorrect method coercion.');
+ }
+
+/**
+ * test that unknown exception types with valid status codes are treated correctly.
+ *
+ * @return void
+ */
+ function testUnknownExceptionTypeWithNoCodeIsA500() {
+ $exception = new OutOfBoundsException('foul ball.');
+ $ErrorHandler = new ErrorHandler($exception);
+
$this->assertEquals('error500', $ErrorHandler->method, 'incorrect method coercion.');
}
/**
- * testError method
+ * testerror400 method
*
* @access public
* @return void
*/
- function testError() {
- $exception = new Exception('Page not found');
- $ErrorHandler = new ErrorHandler($exception);
-
- ob_start();
- $ErrorHandler->error($exception);
- $result = ob_get_clean();
- $this->assertPattern("/Page not found<\/h2>/", $result);
- }
-
-/**
- * testError404 method
- *
- * @access public
- * @return void
- */
- function testError404() {
+ function testerror400() {
App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS)
), true);
@@ -393,11 +389,11 @@ class ErrorHandlerTest extends CakeTestCase {
}
/**
- * test that error404 only modifies the messages on CakeExceptions.
+ * test that error400 only modifies the messages on CakeExceptions.
*
* @return void
*/
- function testError404OnlyChangingCakeException() {
+ function testerror400OnlyChangingCakeException() {
Configure::write('debug', 0);
$exception = new Error404Exception('Custom message');
@@ -417,11 +413,11 @@ class ErrorHandlerTest extends CakeTestCase {
$this->assertContains('Not Found', $result);
}
/**
- * test that error404 doesn't expose XSS
+ * test that error400 doesn't expose XSS
*
* @return void
*/
- function testError404NoInjection() {
+ function testerror400NoInjection() {
Router::reload();
$request = new CakeRequest('pages/pink', false);
From d198230e61b491587a4d29c69c915c9801cca5ae Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Sat, 4 Sep 2010 19:06:10 -0400
Subject: [PATCH 086/166] Fixing issue where errors that did not have a 500+
code would use the incorrect status code.
---
cake/libs/error_handler.php | 7 ++++---
cake/tests/cases/libs/error_handler.test.php | 12 ++++++++++++
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/cake/libs/error_handler.php b/cake/libs/error_handler.php
index 611f08982..2b2277521 100644
--- a/cake/libs/error_handler.php
+++ b/cake/libs/error_handler.php
@@ -85,8 +85,8 @@ class ErrorHandler {
/**
* Creates the controller to perform rendering on the error response.
- * If the error is a CakeException it will be converted to either a 404 or a 500
- * type error depending on the code used to construct the error.
+ * If the error is a CakeException it will be converted to either a 400 or a 500
+ * code error depending on the code used to construct the error.
*
* @param string $method Method producing the error
* @param array $messages Error messages
@@ -228,7 +228,8 @@ class ErrorHandler {
*/
public function error500($error) {
$url = Router::normalize($this->controller->request->here);
- $this->controller->response->statusCode($error->getCode());
+ $code = ($error->getCode() > 500) ? $error->getCode() : 500;
+ $this->controller->response->statusCode($code);
$this->controller->set(array(
'name' => __('An Internal Error Has Occurred'),
'message' => h($url),
diff --git a/cake/tests/cases/libs/error_handler.test.php b/cake/tests/cases/libs/error_handler.test.php
index 170d246c1..7915c14bc 100644
--- a/cake/tests/cases/libs/error_handler.test.php
+++ b/cake/tests/cases/libs/error_handler.test.php
@@ -341,6 +341,12 @@ class ErrorHandlerTest extends CakeTestCase {
function testUnknownExceptionTypeWithExceptionThatHasA400Code() {
$exception = new MissingWidgetThingException('coding fail.');
$ErrorHandler = new ErrorHandler($exception);
+ $ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
+ $ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(404);
+
+ ob_start();
+ $ErrorHandler->render();
+ $results = ob_get_clean();
$this->assertFalse(method_exists($ErrorHandler, 'missingWidgetThing'), 'no method should exist.');
$this->assertEquals('error400', $ErrorHandler->method, 'incorrect method coercion.');
@@ -354,6 +360,12 @@ class ErrorHandlerTest extends CakeTestCase {
function testUnknownExceptionTypeWithNoCodeIsA500() {
$exception = new OutOfBoundsException('foul ball.');
$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();
+ $results = ob_get_clean();
$this->assertEquals('error500', $ErrorHandler->method, 'incorrect method coercion.');
}
From 954676c9f693148cf5056b704295f4986158b7e5 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Sat, 4 Sep 2010 19:16:06 -0400
Subject: [PATCH 087/166] Adding doc blocks to the new exception classes.
---
cake/libs/exceptions.php | 106 +++++++++++++++++++++++++++++++++++----
1 file changed, 97 insertions(+), 9 deletions(-)
diff --git a/cake/libs/exceptions.php b/cake/libs/exceptions.php
index fcf324f6f..3f969c8a5 100644
--- a/cake/libs/exceptions.php
+++ b/cake/libs/exceptions.php
@@ -44,11 +44,31 @@ class Error500Exception extends CakeException {
* @package cake.libs
*/
class CakeException extends RuntimeException {
-
+/**
+ * Array of attributes that are passed in from the constructor, and
+ * made available in the view when a development error is displayed.
+ *
+ * @var array
+ */
protected $_attributes = array();
+/**
+ * Template string that has attributes sprintf()'ed into it.
+ *
+ * @var string
+ */
protected $_messageTemplate = '';
+/**
+ * Constructor.
+ *
+ * Allows you to create exceptions that are treated as framework errors and disabled
+ * when debug = 0.
+ *
+ * @param mixed $message Either the string of the error message, or an array of attributes
+ * that are made available in the view, and sprintf()'d into CakeException::$_messageTemplate
+ * @param string $code The code of the error, is also the HTTP status code for the error.
+ */
public function __construct($message, $code = 500) {
if (is_array($message)) {
$this->_attributes = $message;
@@ -56,14 +76,22 @@ class CakeException extends RuntimeException {
}
parent::__construct($message, $code);
}
-
+
+/**
+ * Get the passed in attributes
+ *
+ * @return array
+ */
public function getAttributes() {
return $this->_attributes;
}
}
-/*
- * Exceptions used by Dispatcher
+/**
+ * Missing Controller exception - used when a controller
+ * cannot be found.
+ *
+ * @package cake.libs
*/
class MissingControllerException extends CakeException {
protected $_messageTemplate = 'Controller class %s could not be found.';
@@ -72,6 +100,13 @@ class MissingControllerException extends CakeException {
parent::__construct($message, $code);
}
}
+
+/**
+ * Missing Action exception - used when a controller action
+ * cannot be found.
+ *
+ * @package cake.libs
+ */
class MissingActionException extends CakeException {
protected $_messageTemplate = 'Action %s::%s() could not be found.';
@@ -79,6 +114,12 @@ class MissingActionException extends CakeException {
parent::__construct($message, $code);
}
}
+/**
+ * Private Action exception - used when a controller action
+ * is protected, or starts with a `_`.
+ *
+ * @package cake.libs
+ */
class PrivateActionException extends CakeException {
protected $_messageTemplate = 'Private Action %s::%s() is not directly accessible.';
@@ -88,37 +129,69 @@ class PrivateActionException extends CakeException {
}
/**
- * Exceptions used by the ComponentCollection.
+ * Used when a Component file cannot be found.
+ *
+ * @package cake.libs
*/
class MissingComponentFileException extends CakeException {
protected $_messageTemplate = 'Component File "%s" is missing.';
}
+
+/**
+ * Used when a Component class cannot be found.
+ *
+ * @package cake.libs
+ */
class MissingComponentClassException extends CakeException {
protected $_messageTemplate = 'Component class "%s" is missing.';
}
/**
- * Runtime Exceptions for behaviors
+ * Used when a Behavior file cannot be found.
+ *
+ * @package cake.libs
*/
class MissingBehaviorFileException extends CakeException { }
+
+/**
+ * Used when a Behavior class cannot be found.
+ *
+ * @package cake.libs
+ */
class MissingBehaviorClassException extends CakeException { }
/**
- * Runtime Exceptions for Views
+ * Used when a view file cannot be found.
+ *
+ * @package cake.libs
*/
class MissingViewException extends CakeException {
protected $_messageTemplate = 'View file "%s" is missing.';
}
+
+/**
+ * Used when a layout file cannot be found.
+ *
+ * @package cake.libs
+ */
class MissingLayoutException extends CakeException {
protected $_messageTemplate = 'Layout file "%s" is missing.';
}
/**
- * Exceptions used by the HelperCollection.
+ * Used when a helper file cannot be found.
+ *
+ * @package cake.libs
*/
class MissingHelperFileException extends CakeException {
protected $_messageTemplate = 'Helper File "%s" is missing.';
}
+
+/**
+ * Used when a helper class cannot be found.
+ *
+ * @package cake.libs
+ */
class MissingHelperClassException extends CakeException {
protected $_messageTemplate = 'Helper class "%s" is missing.';
}
@@ -130,16 +203,30 @@ class MissingHelperClassException extends CakeException {
class MissingDatabaseException extends CakeException {
protected $_messageTemplate = 'Database connection "%s" could not be found.';
}
+
+/**
+ * Used when no connections can be found.
+ *
+ * @package cake.libs
+ */
class MissingConnectionException extends CakeException {
protected $_messageTemplate = 'Database connection "%s" is missing.';
}
/**
- * Exceptions used by the TaskCollection.
+ * Used when a Task file cannot be found.
+ *
+ * @package cake.libs
*/
class MissingTaskFileException extends CakeException {
protected $_messageTemplate = 'Task file "%s" is missing.';
}
+
+/**
+ * Used when a Task class cannot be found.
+ *
+ * @package cake.libs
+ */
class MissingTaskClassException extends CakeException {
protected $_messageTemplate = 'Task class "%s" is missing.';
}
@@ -147,6 +234,7 @@ class MissingTaskClassException extends CakeException {
/**
* Exception class to be thrown when a database table is not found in the datasource
*
+ * @package cake.libs
*/
class MissingTableException extends CakeException {
protected $_messageTemplate = 'Database table %s for model %s was not found.';
From cc17e1a85a8a27a39cab3fcda4e99f36fa00db57 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Sat, 4 Sep 2010 19:18:14 -0400
Subject: [PATCH 088/166] Adding more doc blocks to error classes.
---
cake/libs/exceptions.php | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/cake/libs/exceptions.php b/cake/libs/exceptions.php
index 3f969c8a5..817dc2d20 100644
--- a/cake/libs/exceptions.php
+++ b/cake/libs/exceptions.php
@@ -19,8 +19,18 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-
+/**
+ * Represents an HTTP 404 error.
+ *
+ * @package cake.libs
+ */
class Error404Exception extends RuntimeException {
+/**
+ * Constructor
+ *
+ * @param string $message If no message is given 'Not Found' will be the message
+ * @param string $code Status code, defaults to 404
+ */
public function __construct($message, $code = 404) {
if (empty($message)) {
$message = __('Not Found');
@@ -28,7 +38,19 @@ class Error404Exception extends RuntimeException {
parent::__construct($message, $code);
}
}
-class Error500Exception extends CakeException {
+
+/**
+ * Represents an HTTP 500 error.
+ *
+ * @package cake.libs
+ */
+class Error500Exception extends CakeException {
+/**
+ * Constructor
+ *
+ * @param string $message If no message is given 'Not Found' will be the message
+ * @param string $code Status code, defaults to 404
+ */
public function __construct($message, $code = 500) {
if (empty($message)) {
$message = __('Internal Server Error');
From 82fffe6914429ad8b2cc8b1ee4cc34b657e574f5 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Sun, 5 Sep 2010 01:28:13 -0400
Subject: [PATCH 089/166] Fixing issue where FormHelper::select() with multiple
= checkbox and a custom name attribute would not work correctly. Fixes #1078
---
cake/libs/view/helpers/form.php | 7 +--
.../cases/libs/view/helpers/form.test.php | 52 +++++++++++++++++--
2 files changed, 52 insertions(+), 7 deletions(-)
diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php
index 3a9c60815..1e29d0461 100644
--- a/cake/libs/view/helpers/form.php
+++ b/cake/libs/view/helpers/form.php
@@ -1461,7 +1461,8 @@ class FormHelper extends AppHelper {
$hiddenAttributes = array(
'value' => '',
'id' => $attributes['id'] . ($style ? '' : '_'),
- 'secure' => false
+ 'secure' => false,
+ 'name' => $attributes['name']
);
$select[] = $this->hidden(null, $hiddenAttributes);
} else {
@@ -1495,7 +1496,7 @@ class FormHelper extends AppHelper {
$selected,
array(),
$showParents,
- array('escape' => $escapeOptions, 'style' => $style)
+ array('escape' => $escapeOptions, 'style' => $style, 'name' => $attributes['name'])
));
$template = ($style == 'checkbox') ? 'checkboxmultipleend' : 'selectend';
@@ -2041,7 +2042,7 @@ class FormHelper extends AppHelper {
$label['class'] = 'selected';
}
- list($name) = array_values($this->_name());
+ $name = $attributes['name'];
if (empty($attributes['class'])) {
$attributes['class'] = 'checkbox';
diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php
index 51b2b5803..10f1e4b4b 100644
--- a/cake/tests/cases/libs/view/helpers/form.test.php
+++ b/cake/tests/cases/libs/view/helpers/form.test.php
@@ -3448,7 +3448,10 @@ class FormHelperTest extends CakeTestCase {
* @return void
*/
function testInputMultipleCheckboxes() {
- $result = $this->Form->input('Model.multi_field', array('options' => array('first', 'second', 'third'), 'multiple' => 'checkbox'));
+ $result = $this->Form->input('Model.multi_field', array(
+ 'options' => array('first', 'second', 'third'),
+ 'multiple' => 'checkbox'
+ ));
$expected = array(
array('div' => array('class' => 'input select')),
array('label' => array('for' => 'ModelMultiField')),
@@ -3477,7 +3480,10 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
- $result = $this->Form->input('Model.multi_field', array('options' => array('a' => 'first', 'b' => 'second', 'c' => 'third'), 'multiple' => 'checkbox'));
+ $result = $this->Form->input('Model.multi_field', array(
+ 'options' => array('a' => 'first', 'b' => 'second', 'c' => 'third'),
+ 'multiple' => 'checkbox'
+ ));
$expected = array(
array('div' => array('class' => 'input select')),
array('label' => array('for' => 'ModelMultiField')),
@@ -3506,7 +3512,12 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
- $result = $this->Form->input('Model.multi_field', array('options' => array('1' => 'first'), 'multiple' => 'checkbox', 'label' => false, 'div' => false));
+ $result = $this->Form->input('Model.multi_field', array(
+ 'options' => array('1' => 'first'),
+ 'multiple' => 'checkbox',
+ 'label' => false,
+ 'div' => false
+ ));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
array('div' => array('class' => 'checkbox')),
@@ -3518,7 +3529,12 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
- $result = $this->Form->input('Model.multi_field', array('options' => array('2' => 'second'), 'multiple' => 'checkbox', 'label' => false, 'div' => false));
+ $result = $this->Form->input('Model.multi_field', array(
+ 'options' => array('2' => 'second'),
+ 'multiple' => 'checkbox',
+ 'label' => false,
+ 'div' => false
+ ));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
array('div' => array('class' => 'checkbox')),
@@ -3531,6 +3547,34 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
}
+/**
+ * test that select() with multiple = checkbox works with overriding name attribute.
+ *
+ * @return void
+ */
+ function testSelectCheckboxMultipleOverrideName() {
+ $result = $this->Form->input('category', array(
+ 'type' => 'select',
+ 'multiple' => 'checkbox',
+ 'name' => 'data[fish]',
+ 'options' => array('1', '2'),
+ 'div' => false,
+ 'label' => false,
+ ));
+ $expected = array(
+ 'input' => array('type' => 'hidden', 'name' => 'data[fish]', 'value' => '', 'id' => 'category'),
+ array('div' => array('class' => 'checkbox')),
+ array('input' => array('type' => 'checkbox', 'name' => 'data[fish][]', 'value' => '0', 'id' => 'Category0')),
+ array('label' => array('for' => 'Category0')), '1', '/label',
+ '/div',
+ array('div' => array('class' => 'checkbox')),
+ array('input' => array('type' => 'checkbox', 'name' => 'data[fish][]', 'value' => '1', 'id' => 'Category1')),
+ array('label' => array('for' => 'Category1')), '2', '/label',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
+ }
+
/**
* testCheckbox method
*
From b7791dd94fbc5784e29839bf3a770d1f3616e140 Mon Sep 17 00:00:00 2001
From: Mark Story
Date: Sun, 5 Sep 2010 02:04:08 -0400
Subject: [PATCH 090/166] Removing variable that wasn't provided by the
exception.
---
cake/libs/view/errors/error500.ctp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/cake/libs/view/errors/error500.ctp b/cake/libs/view/errors/error500.ctp
index fbd5a64bd..acc6a42c4 100644
--- a/cake/libs/view/errors/error500.ctp
+++ b/cake/libs/view/errors/error500.ctp
@@ -19,6 +19,6 @@
?>
- :
- '{$message}'