Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Making subclassing of ErrorHandler much easier.

Test cases added.
  • Loading branch information...
commit d59a2c8de159b70758f191504e2bcb8472762ecc 1 parent 955bd33
Mark Story markstory authored
Showing with 62 additions and 2 deletions.
  1. +5 −2 cake/libs/error.php
  2. +57 −0 cake/tests/cases/libs/error.test.php
7 cake/libs/error.php
View
@@ -110,8 +110,11 @@ function __construct($method, $messages) {
}
if ($method !== 'error') {
- if (Configure::read() == 0) {
- $method = 'error404';
+ if (Configure::read('debug') == 0) {
+ $parentMethods = get_class_methods(get_parent_class($this));
+ if (in_array($method, $parentMethods)) {
+ $method = 'error404';
+ }
if (isset($code) && $code == 500) {
$method = 'error500';
}
57 cake/tests/cases/libs/error.test.php
View
@@ -208,6 +208,34 @@ class BlueberryController extends AppController {
}
/**
+ * MyCustomErrorHandler class
+ *
+ * @package cake
+ * @subpackage cake.tests.cases.libs
+ */
+class MyCustomErrorHandler extends ErrorHandler {
+
+/**
+ * custom error message type.
+ *
+ * @return void
+ **/
+ function missingWidgetThing() {
+ echo 'widget thing is missing';
+ }
+
+/**
+ * stop method
+ *
+ * @access public
+ * @return void
+ */
+ function _stop() {
+ return;
+ }
+}
+
+/**
* TestErrorHandler class
*
* @package cake
@@ -245,6 +273,35 @@ function skip() {
}
/**
+ * test that methods declared in an ErrorHandler subclass are not converted
+ * into error404 when debug == 0
+ *
+ * @return void
+ **/
+ function testSubclassMethodsNotBeingConvertedToError() {
+ $back = Configure::read('debug');
+ Configure::write('debug', 2);
+ ob_start();
+ $ErrorHandler = new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
+ $result = ob_get_clean();
+ $this->assertEqual($result, 'widget thing is missing');
+
+ 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');
+
+ Configure::write('debug', 0);
+ ob_start();
+ $ErrorHandler = new MyCustomErrorHandler('missingController', array('message' => 'Page not found'));
+ $result = ob_get_clean();
+ $this->assertPattern('/Not Found/', $result, 'Method declared in error handler not converted to error404. %s');
+
+ Configure::write('debug', $back);
+ }
+
+/**
* testError method
*
* @access public
Please sign in to comment.
Something went wrong with that request. Please try again.