diff --git a/cake/libs/error.php b/cake/libs/error.php index 45c043bf4..e8d7a0d6a 100644 --- a/cake/libs/error.php +++ b/cake/libs/error.php @@ -106,6 +106,7 @@ class ErrorHandler extends Object { if (!in_array(strtolower($method), array_map('strtolower', get_class_methods($this)))) { $method = 'error'; } + if ($method !== 'error') { if (Configure::read('debug') == 0) { $parentClass = get_parent_class($this); @@ -116,7 +117,7 @@ class ErrorHandler extends Object { if (in_array(strtolower($method), $parentMethods)) { $method = 'error404'; } - if (isset($code) && $code == 500) { + if (isset($messages[0]['code']) && $messages[0]['code'] == 500) { $method = 'error500'; } } diff --git a/cake/libs/model/connection_manager.php b/cake/libs/model/connection_manager.php index 723ad0994..b9e599481 100644 --- a/cake/libs/model/connection_manager.php +++ b/cake/libs/model/connection_manager.php @@ -239,7 +239,7 @@ class ConnectionManager extends Object { $this->_connectionsEnum[$name] = $this->__connectionData($config); } } else { - $this->cakeError('missingConnection', array(array('className' => 'ConnectionManager'))); + $this->cakeError('missingConnection', array(array('code' => 500, 'className' => 'ConnectionManager'))); } } diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 32a19a717..9a663204e 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -769,7 +769,8 @@ class Model extends Overloadable { if (is_array($sources) && !in_array(strtolower($this->tablePrefix . $tableName), array_map('strtolower', $sources))) { return $this->cakeError('missingTable', array(array( 'className' => $this->alias, - 'table' => $this->tablePrefix . $tableName + 'table' => $this->tablePrefix . $tableName, + 'code' => 500 ))); } $this->_schema = null; @@ -2826,7 +2827,7 @@ class Model extends Overloadable { } if (empty($db) || !is_object($db)) { - return $this->cakeError('missingConnection', array(array('className' => $this->alias))); + return $this->cakeError('missingConnection', array(array('code' => 500, 'className' => $this->alias))); } } diff --git a/cake/tests/cases/libs/error.test.php b/cake/tests/cases/libs/error.test.php index 4b181c3e5..ec90a57e2 100644 --- a/cake/tests/cases/libs/error.test.php +++ b/cake/tests/cases/libs/error.test.php @@ -609,4 +609,22 @@ class ErrorHandlerTest extends CakeTestCase { $this->assertPattern('/Article<\/em> could not be found./', $result); $this->assertPattern('/(\/|\\\)article.php/', $result); } + +/** + * testing that having a code => 500 in the cakeError call makes an + * internal server error. + * + * @return void + */ + function testThatCode500Works() { + Configure::write('debug', 0); + ob_start(); + $TestErrorHandler = new TestErrorHandler('missingTable', array( + 'className' => 'Article', + 'table' => 'articles', + 'code' => 500 + )); + $result = ob_get_clean(); + $this->assertPattern('/

An Internal Error Has Occurred<\/h2>/', $result); + } }