2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* ErrorHandlerTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5432
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
if (class_exists('TestErrorHandler')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
|
|
|
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-06-11 09:02:54 +00:00
|
|
|
* BlueberryComponent class
|
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-06-11 09:02:54 +00:00
|
|
|
class BlueberryComponent extends Object {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-06-04 19:04:58 +00:00
|
|
|
* testName property
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
2008-06-11 09:02:54 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $testName = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-06-04 19:04:58 +00:00
|
|
|
* initialize method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
2008-06-11 09:02:54 +00:00
|
|
|
*/
|
2008-06-04 19:04:58 +00:00
|
|
|
function initialize(&$controller) {
|
2008-06-11 09:02:54 +00:00
|
|
|
$this->testName = 'BlueberryComponent';
|
2008-06-04 19:04:58 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-04 19:04:58 +00:00
|
|
|
/**
|
2008-11-08 01:00:05 +00:00
|
|
|
* BlueberryDispatcher class
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-11-08 01:00:05 +00:00
|
|
|
class BlueberryDispatcher extends Dispatcher {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-08 01:00:05 +00:00
|
|
|
/**
|
|
|
|
* cakeError method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function cakeError($method, $messages = array()) {
|
|
|
|
$error = new TestErrorHandler($method, $messages);
|
|
|
|
return $error;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-08 01:00:05 +00:00
|
|
|
/**
|
|
|
|
* Short description for class.
|
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-11-08 01:00:05 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
*/
|
|
|
|
class AuthBlueberryUser extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-08 01:00:05 +00:00
|
|
|
/**
|
|
|
|
* name property
|
|
|
|
*
|
|
|
|
* @var string 'AuthBlueberryUser'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'AuthBlueberryUser';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-08 01:00:05 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = false;
|
2008-11-08 01:00:05 +00:00
|
|
|
}
|
2008-06-04 19:04:58 +00:00
|
|
|
if (!class_exists('AppController')) {
|
2009-03-21 23:55:39 +00:00
|
|
|
/**
|
|
|
|
* AppController class
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
*/
|
|
|
|
class AppController extends Controller {
|
|
|
|
/**
|
|
|
|
* components property
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $components = array('Blueberry');
|
2009-03-21 23:55:39 +00:00
|
|
|
/**
|
|
|
|
* beforeRender method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function beforeRender() {
|
|
|
|
echo $this->Blueberry->testName;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* header method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function header($header) {
|
|
|
|
echo $header;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* _stop method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function _stop($status = 0) {
|
|
|
|
echo 'Stopped with status: ' . $status;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-03-21 23:55:39 +00:00
|
|
|
} elseif (!defined('APP_CONTROLLER_EXISTS')){
|
|
|
|
define('APP_CONTROLLER_EXISTS', true);
|
2008-06-11 09:02:54 +00:00
|
|
|
}
|
2008-06-11 16:01:11 +00:00
|
|
|
App::import('Core', array('Error', 'Controller'));
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestErrorController class
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-06-04 19:04:58 +00:00
|
|
|
class TestErrorController extends AppController {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* index method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function index() {
|
|
|
|
$this->autoRender = false;
|
|
|
|
return 'what up';
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-08 01:00:05 +00:00
|
|
|
/**
|
|
|
|
* BlueberryController class
|
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-11-08 01:00:05 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
*/
|
|
|
|
class BlueberryController extends AppController {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-08 01:00:05 +00:00
|
|
|
/**
|
|
|
|
* name property
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'BlueberryController';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-08 01:00:05 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-06-09 04:46:18 +00:00
|
|
|
public $uses = array();
|
2008-11-08 01:00:05 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-10-09 04:13:08 +00:00
|
|
|
/**
|
|
|
|
* MyCustomErrorHandler class
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
*/
|
|
|
|
class MyCustomErrorHandler extends ErrorHandler {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* custom error message type.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-10-09 04:13:08 +00:00
|
|
|
function missingWidgetThing() {
|
|
|
|
echo 'widget thing is missing';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* stop method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function _stop() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestErrorHandler class
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestErrorHandler extends ErrorHandler {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* stop method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-04 19:04:58 +00:00
|
|
|
function _stop() {
|
2008-05-30 11:40:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* ErrorHandlerTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-03-18 17:55:58 +00:00
|
|
|
class ErrorHandlerTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* skip method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function skip() {
|
2009-03-21 23:55:39 +00:00
|
|
|
$this->skipIf(PHP_SAPI === 'cli', '%s Cannot be run from console');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-10-09 04:13:08 +00:00
|
|
|
/**
|
|
|
|
* test that methods declared in an ErrorHandler subclass are not converted
|
|
|
|
* into error404 when debug == 0
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-10-09 04:13:08 +00:00
|
|
|
function testSubclassMethodsNotBeingConvertedToError() {
|
|
|
|
$back = Configure::read('debug');
|
|
|
|
Configure::write('debug', 2);
|
|
|
|
ob_start();
|
2010-06-09 04:46:18 +00:00
|
|
|
$ErrorHandler = new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
|
2009-10-09 04:13:08 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertEqual($result, 'widget thing is missing');
|
|
|
|
|
|
|
|
Configure::write('debug', 0);
|
|
|
|
ob_start();
|
2010-06-09 04:46:18 +00:00
|
|
|
$ErrorHandler = new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
|
2009-10-09 04:13:08 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertEqual($result, 'widget thing is missing', 'Method declared in subclass converted to error404. %s');
|
2009-12-13 20:35:51 +00:00
|
|
|
|
2009-10-09 04:13:08 +00:00
|
|
|
Configure::write('debug', 0);
|
|
|
|
ob_start();
|
2010-06-09 04:46:18 +00:00
|
|
|
$ErrorHandler = new MyCustomErrorHandler('missingController', array(
|
2010-01-15 04:17:24 +00:00
|
|
|
'className' => 'Missing', 'message' => 'Page not found'
|
|
|
|
));
|
2009-10-09 04:13:08 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/Not Found/', $result, 'Method declared in error handler not converted to error404. %s');
|
|
|
|
|
|
|
|
Configure::write('debug', $back);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testError method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testError() {
|
|
|
|
ob_start();
|
|
|
|
$TestErrorHandler = new TestErrorHandler('error404', array('message' => 'Page not found'));
|
|
|
|
ob_clean();
|
|
|
|
ob_start();
|
|
|
|
$TestErrorHandler->error(array(
|
2009-10-09 03:46:05 +00:00
|
|
|
'code' => 404,
|
|
|
|
'message' => 'Page not Found',
|
|
|
|
'name' => "Couldn't find what you were looking for"
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern("/<h2>Couldn't find what you were looking for<\/h2>/", $result);
|
|
|
|
$this->assertPattern('/Page not Found/', $result);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testError404 method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testError404() {
|
2010-02-28 18:44:04 +00:00
|
|
|
App::build(array(
|
|
|
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS)
|
|
|
|
), true);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
ob_start();
|
2008-06-11 09:02:54 +00:00
|
|
|
$TestErrorHandler = new TestErrorHandler('error404', array('message' => 'Page not found', 'url' => '/test_error'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/<h2>Not Found<\/h2>/', $result);
|
2009-02-13 14:56:00 +00:00
|
|
|
$this->assertPattern("/<strong>'\/test_error'<\/strong>/", $result);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2009-02-13 14:56:00 +00:00
|
|
|
ob_start();
|
2010-06-09 04:46:18 +00:00
|
|
|
$TestErrorHandler = new TestErrorHandler('error404', array('message' => 'Page not found'));
|
2009-02-13 14:56:00 +00:00
|
|
|
ob_get_clean();
|
|
|
|
ob_start();
|
|
|
|
$TestErrorHandler->error404(array(
|
|
|
|
'url' => 'pages/<span id=333>pink</span></id><script>document.body.style.background = t=document.getElementById(333).innerHTML;window.alert(t);</script>',
|
|
|
|
'message' => 'Page not found'
|
|
|
|
));
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertNoPattern('#<script>#', $result);
|
|
|
|
$this->assertNoPattern('#</script>#', $result);
|
2010-02-28 18:44:04 +00:00
|
|
|
|
|
|
|
App::build();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-12-13 20:35:51 +00:00
|
|
|
/**
|
|
|
|
* testError500 method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testError500() {
|
|
|
|
ob_start();
|
|
|
|
$TestErrorHandler = new TestErrorHandler('error500', array(
|
|
|
|
'message' => 'An Internal Error Has Occurred'
|
|
|
|
));
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/<h2>An Internal Error Has Occurred<\/h2>/', $result);
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$TestErrorHandler = new TestErrorHandler('error500', array(
|
|
|
|
'message' => 'An Internal Error Has Occurred',
|
|
|
|
'code' => '500'
|
|
|
|
));
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/<h2>An Internal Error Has Occurred<\/h2>/', $result);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testMissingController method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingController() {
|
2009-03-21 23:55:39 +00:00
|
|
|
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController');
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
ob_start();
|
2008-06-11 09:02:54 +00:00
|
|
|
$TestErrorHandler = new TestErrorHandler('missingController', array('className' => 'PostsController'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/<h2>Missing Controller<\/h2>/', $result);
|
|
|
|
$this->assertPattern('/<em>PostsController<\/em>/', $result);
|
2008-06-11 09:02:54 +00:00
|
|
|
$this->assertPattern('/BlueberryComponent/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testMissingAction method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingAction() {
|
|
|
|
ob_start();
|
2008-06-11 09:02:54 +00:00
|
|
|
$TestErrorHandler = new TestErrorHandler('missingAction', array('className' => 'PostsController', 'action' => 'index'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/<h2>Missing Method in PostsController<\/h2>/', $result);
|
|
|
|
$this->assertPattern('/<em>PostsController::<\/em><em>index\(\)<\/em>/', $result);
|
2008-11-08 01:00:05 +00:00
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$dispatcher = new BlueberryDispatcher('/blueberry/inexistent');
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/<h2>Missing Method in BlueberryController<\/h2>/', $result);
|
|
|
|
$this->assertPattern('/<em>BlueberryController::<\/em><em>inexistent\(\)<\/em>/', $result);
|
|
|
|
$this->assertNoPattern('/Location: (.*)\/users\/login/', $result);
|
|
|
|
$this->assertNoPattern('/Stopped with status: 0/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testPrivateAction method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testPrivateAction() {
|
|
|
|
ob_start();
|
2008-06-11 09:02:54 +00:00
|
|
|
$TestErrorHandler = new TestErrorHandler('privateAction', array('className' => 'PostsController', 'action' => '_secretSauce'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/<h2>Private Method in PostsController<\/h2>/', $result);
|
|
|
|
$this->assertPattern('/<em>PostsController::<\/em><em>_secretSauce\(\)<\/em>/', $result);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testMissingTable method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingTable() {
|
|
|
|
ob_start();
|
2008-06-11 09:02:54 +00:00
|
|
|
$TestErrorHandler = new TestErrorHandler('missingTable', array('className' => 'Article', 'table' => 'articles'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = ob_get_clean();
|
2009-12-13 20:35:51 +00:00
|
|
|
$this->assertPattern('/HTTP\/1\.0 500 Internal Server Error/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertPattern('/<h2>Missing Database Table<\/h2>/', $result);
|
|
|
|
$this->assertPattern('/table <em>articles<\/em> for model <em>Article<\/em>/', $result);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testMissingDatabase method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingDatabase() {
|
|
|
|
ob_start();
|
|
|
|
$TestErrorHandler = new TestErrorHandler('missingDatabase', array());
|
|
|
|
$result = ob_get_clean();
|
2009-12-13 20:35:51 +00:00
|
|
|
$this->assertPattern('/HTTP\/1\.0 500 Internal Server Error/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertPattern('/<h2>Missing Database Connection<\/h2>/', $result);
|
|
|
|
$this->assertPattern('/Confirm you have created the file/', $result);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testMissingView method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingView() {
|
|
|
|
ob_start();
|
2008-06-11 09:02:54 +00:00
|
|
|
$TestErrorHandler = new TestErrorHandler('missingView', array('className' => 'Pages', 'action' => 'display', 'file' => 'pages/about.ctp', 'base' => ''));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = ob_get_clean();
|
|
|
|
$this->assertPattern("/PagesController::/", $expected);
|
|
|
|
$this->assertPattern("/pages\/about.ctp/", $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testMissingLayout method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingLayout() {
|
|
|
|
ob_start();
|
2008-06-11 09:02:54 +00:00
|
|
|
$TestErrorHandler = new TestErrorHandler('missingLayout', array( 'layout' => 'my_layout', 'file' => 'layouts/my_layout.ctp', 'base' => ''));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = ob_get_clean();
|
|
|
|
$this->assertPattern("/Missing Layout/", $expected);
|
|
|
|
$this->assertPattern("/layouts\/my_layout.ctp/", $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testMissingConnection method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingConnection() {
|
|
|
|
ob_start();
|
2008-06-11 09:02:54 +00:00
|
|
|
$TestErrorHandler = new TestErrorHandler('missingConnection', array('className' => 'Article'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/<h2>Missing Database Connection<\/h2>/', $result);
|
|
|
|
$this->assertPattern('/Article requires a database connection/', $result);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testMissingHelperFile method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingHelperFile() {
|
|
|
|
ob_start();
|
2008-06-11 09:02:54 +00:00
|
|
|
$TestErrorHandler = new TestErrorHandler('missingHelperFile', array('helper' => 'MyCustom', 'file' => 'my_custom.php'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/<h2>Missing Helper File<\/h2>/', $result);
|
|
|
|
$this->assertPattern('/Create the class below in file:/', $result);
|
2008-11-08 01:00:05 +00:00
|
|
|
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testMissingHelperClass method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingHelperClass() {
|
|
|
|
ob_start();
|
2008-06-11 09:02:54 +00:00
|
|
|
$TestErrorHandler = new TestErrorHandler('missingHelperClass', array('helper' => 'MyCustom', 'file' => 'my_custom.php'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/<h2>Missing Helper Class<\/h2>/', $result);
|
|
|
|
$this->assertPattern('/The helper class <em>MyCustomHelper<\/em> can not be found or does not exist./', $result);
|
2008-11-08 01:00:05 +00:00
|
|
|
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-08-30 23:38:17 +00:00
|
|
|
/**
|
|
|
|
* test missingBehaviorFile method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testMissingBehaviorFile() {
|
|
|
|
ob_start();
|
|
|
|
$TestErrorHandler = new TestErrorHandler('missingBehaviorFile', array('behavior' => 'MyCustom', 'file' => 'my_custom.php'));
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/<h2>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() {
|
|
|
|
ob_start();
|
|
|
|
$TestErrorHandler = new TestErrorHandler('missingBehaviorClass', array('behavior' => 'MyCustom', 'file' => 'my_custom.php'));
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/The behavior class <em>MyCustomBehavior<\/em> can not be found or does not exist./', $result);
|
|
|
|
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testMissingComponentFile method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingComponentFile() {
|
|
|
|
ob_start();
|
2008-06-11 09:02:54 +00:00
|
|
|
$TestErrorHandler = new TestErrorHandler('missingComponentFile', array('className' => 'PostsController', 'component' => 'Sidebox', 'file' => 'sidebox.php'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/<h2>Missing Component File<\/h2>/', $result);
|
|
|
|
$this->assertPattern('/Create the class <em>SideboxComponent<\/em> in file:/', $result);
|
2008-11-08 01:00:05 +00:00
|
|
|
$this->assertPattern('/(\/|\\\)sidebox.php/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testMissingComponentClass method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingComponentClass() {
|
|
|
|
ob_start();
|
2008-06-11 09:02:54 +00:00
|
|
|
$TestErrorHandler = new TestErrorHandler('missingComponentClass', array('className' => 'PostsController', 'component' => 'Sidebox', 'file' => 'sidebox.php'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/<h2>Missing Component Class<\/h2>/', $result);
|
|
|
|
$this->assertPattern('/Create the class <em>SideboxComponent<\/em> in file:/', $result);
|
2008-11-08 01:00:05 +00:00
|
|
|
$this->assertPattern('/(\/|\\\)sidebox.php/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testMissingModel method
|
2008-06-11 09:02:54 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingModel() {
|
|
|
|
ob_start();
|
2008-06-11 09:02:54 +00:00
|
|
|
$TestErrorHandler = new TestErrorHandler('missingModel', array('className' => 'Article', 'file' => 'article.php'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/<h2>Missing Model<\/h2>/', $result);
|
|
|
|
$this->assertPattern('/<em>Article<\/em> could not be found./', $result);
|
2008-11-08 01:00:05 +00:00
|
|
|
$this->assertPattern('/(\/|\\\)article.php/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|