Skip to content

Commit

Permalink
Adding some tests for construction.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Aug 29, 2010
1 parent a30721b commit 8712a90
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cake/libs/error.php
Expand Up @@ -65,7 +65,7 @@ function __construct(Exception $exception) {
if ($parentClass != 'ErrorHandler') {
$method = 'error404';
}
$parentMethods = get_class_methods($parentClass);
$parentMethods = (array)get_class_methods($parentClass);
if (in_array($method, $parentMethods)) {
$method = 'error404';
}
Expand Down
95 changes: 57 additions & 38 deletions cake/tests/cases/libs/error.test.php
Expand Up @@ -209,16 +209,6 @@ class MyCustomErrorHandler extends ErrorHandler {
function missingWidgetThing() {
echo 'widget thing is missing';
}

/**
* stop method
*
* @access public
* @return void
*/
function _stop() {
return;
}
}

/**
Expand Down Expand Up @@ -267,8 +257,13 @@ function setUp() {
$request = new CakeRequest(null, false);
$request->base = '';
Router::setRequestInfo($request);
$this->_debug = Configure::read('debug');
}

function teardown() {
Configure::write('debug', $this->_debug);
}

/**
* test handleException generating a page.
*
Expand Down Expand Up @@ -314,24 +309,48 @@ function testSubclassMethodsNotBeingConvertedToError() {
Configure::write('debug', $back);
}

/**
* test things in the constructor.
*
* @return void
*/
function testConstruction() {
$exception = new Error404Exception('Page not found');
$ErrorHandler = new ErrorHandler($exception);

$this->assertType('CakeErrorController', $ErrorHandler->controller);
$this->assertEquals('error404', $ErrorHandler->method);
$this->assertEquals($exception, $ErrorHandler->error);
}

/**
* test that method gets coerced when debug = 0
*
* @return void
*/
function testErrorMethodCoercion() {
Configure::write('debug', 0);
$exception = new MissingActionException('Page not found');
$ErrorHandler = new ErrorHandler($exception);

$this->assertType('CakeErrorController', $ErrorHandler->controller);
$this->assertEquals('error404', $ErrorHandler->method);
$this->assertEquals($exception, $ErrorHandler->error);
}

/**
* testError method
*
* @access public
* @return void
*/
function testError() {
$this->markTestIncomplete('Not done');
$exception = new Error404Exception('Page not found');
ob_start();
$TestErrorHandler = new TestErrorHandler($exception);
ob_clean();
$ErrorHandler = new ErrorHandler($exception);

ob_start();
$TestErrorHandler->error(array(
'code' => 404,
'message' => 'Page not Found',
'name' => "Couldn't find what you were looking for"
));
$ErrorHandler->error($excpetion);
$result = ob_get_clean();
$this->assertPattern("/<h2>Couldn't find what you were looking for<\/h2>/", $result);
$this->assertPattern('/Page not Found/', $result);
Expand All @@ -350,16 +369,16 @@ function testError404() {
), true);

ob_start();
$TestErrorHandler = new TestErrorHandler('error404', array('message' => 'Page not found', 'url' => '/test_error'));
$ErrorHandler = new ErrorHandler('error404', array('message' => 'Page not found', 'url' => '/test_error'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Not Found<\/h2>/', $result);
$this->assertPattern("/<strong>'\/test_error'<\/strong>/", $result);

ob_start();
$TestErrorHandler = new TestErrorHandler('error404', array('message' => 'Page not found'));
$ErrorHandler = new ErrorHandler('error404', array('message' => 'Page not found'));
ob_get_clean();
ob_start();
$TestErrorHandler->error404(array(
$ErrorHandler->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'
));
Expand All @@ -379,14 +398,14 @@ function testError404() {
function testError500() {
$this->markTestIncomplete('Not implemented now');
ob_start();
$TestErrorHandler = new TestErrorHandler('error500', array(
$ErrorHandler = new ErrorHandler('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(
$ErrorHandler = new ErrorHandler('error500', array(
'message' => 'An Internal Error Has Occurred',
'code' => '500'
));
Expand All @@ -405,7 +424,7 @@ function testMissingController() {
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController');

ob_start();
$TestErrorHandler = new TestErrorHandler('missingController', array('className' => 'PostsController'));
$ErrorHandler = new ErrorHandler('missingController', array('className' => 'PostsController'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Controller<\/h2>/', $result);
$this->assertPattern('/<em>PostsController<\/em>/', $result);
Expand All @@ -421,7 +440,7 @@ function testMissingController() {
function testMissingAction() {
$this->markTestIncomplete('Not implemented now');
ob_start();
$TestErrorHandler = new TestErrorHandler('missingAction', array('className' => 'PostsController', 'action' => 'index'));
$ErrorHandler = new ErrorHandler('missingAction', array('className' => 'PostsController', 'action' => 'index'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Method in PostsController<\/h2>/', $result);
$this->assertPattern('/<em>PostsController::<\/em><em>index\(\)<\/em>/', $result);
Expand All @@ -444,7 +463,7 @@ function testMissingAction() {
function testPrivateAction() {
$this->markTestIncomplete('Not implemented now');
ob_start();
$TestErrorHandler = new TestErrorHandler('privateAction', array('className' => 'PostsController', 'action' => '_secretSauce'));
$ErrorHandler = new ErrorHandler('privateAction', array('className' => 'PostsController', 'action' => '_secretSauce'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Private Method in PostsController<\/h2>/', $result);
$this->assertPattern('/<em>PostsController::<\/em><em>_secretSauce\(\)<\/em>/', $result);
Expand All @@ -459,7 +478,7 @@ function testPrivateAction() {
function testMissingTable() {
$this->markTestIncomplete('Not implemented now');
ob_start();
$TestErrorHandler = new TestErrorHandler('missingTable', array('className' => 'Article', 'table' => 'articles'));
$ErrorHandler = new ErrorHandler('missingTable', array('className' => 'Article', 'table' => 'articles'));
$result = ob_get_clean();
$this->assertPattern('/HTTP\/1\.0 500 Internal Server Error/', $result);
$this->assertPattern('/<h2>Missing Database Table<\/h2>/', $result);
Expand All @@ -475,7 +494,7 @@ function testMissingTable() {
function testMissingDatabase() {
$this->markTestIncomplete('Not implemented now');
ob_start();
$TestErrorHandler = new TestErrorHandler('missingDatabase', array());
$ErrorHandler = new ErrorHandler('missingDatabase', array());
$result = ob_get_clean();
$this->assertPattern('/HTTP\/1\.0 500 Internal Server Error/', $result);
$this->assertPattern('/<h2>Missing Database Connection<\/h2>/', $result);
Expand All @@ -491,7 +510,7 @@ function testMissingDatabase() {
function testMissingView() {
$this->markTestIncomplete('Not implemented now');
ob_start();
$TestErrorHandler = new TestErrorHandler('missingView', array('className' => 'Pages', 'action' => 'display', 'file' => 'pages/about.ctp', 'base' => ''));
$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);
Expand All @@ -506,7 +525,7 @@ function testMissingView() {
function testMissingLayout() {
$this->markTestIncomplete('Not implemented now');
ob_start();
$TestErrorHandler = new TestErrorHandler('missingLayout', array( 'layout' => 'my_layout', 'file' => 'layouts/my_layout.ctp', 'base' => ''));
$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);
Expand All @@ -521,7 +540,7 @@ function testMissingLayout() {
function testMissingConnection() {
$this->markTestIncomplete('Not implemented now');
ob_start();
$TestErrorHandler = new TestErrorHandler('missingConnection', array('className' => 'Article'));
$ErrorHandler = new ErrorHandler('missingConnection', array('className' => 'Article'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Database Connection<\/h2>/', $result);
$this->assertPattern('/Article requires a database connection/', $result);
Expand All @@ -536,7 +555,7 @@ function testMissingConnection() {
function testMissingHelperFile() {
$this->markTestIncomplete('Not implemented now');
ob_start();
$TestErrorHandler = new TestErrorHandler('missingHelperFile', array('helper' => 'MyCustom', 'file' => 'my_custom.php'));
$ErrorHandler = new ErrorHandler('missingHelperFile', array('helper' => 'MyCustom', 'file' => 'my_custom.php'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Helper File<\/h2>/', $result);
$this->assertPattern('/Create the class below in file:/', $result);
Expand All @@ -552,7 +571,7 @@ function testMissingHelperFile() {
function testMissingHelperClass() {
$this->markTestIncomplete('Not implemented now');
ob_start();
$TestErrorHandler = new TestErrorHandler('missingHelperClass', array('helper' => 'MyCustom', 'file' => 'my_custom.php'));
$ErrorHandler = new ErrorHandler('missingHelperClass', array('helper' => 'MyCustom', 'file' => 'my_custom.php'));
$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);
Expand All @@ -568,7 +587,7 @@ function testMissingHelperClass() {
function testMissingBehaviorFile() {
$this->markTestIncomplete('Not implemented now');
ob_start();
$TestErrorHandler = new TestErrorHandler('missingBehaviorFile', array('behavior' => 'MyCustom', 'file' => 'my_custom.php'));
$ErrorHandler = new ErrorHandler('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);
Expand All @@ -584,7 +603,7 @@ function testMissingBehaviorFile() {
function testMissingBehaviorClass() {
$this->markTestIncomplete('Not implemented now');
ob_start();
$TestErrorHandler = new TestErrorHandler('missingBehaviorClass', array('behavior' => 'MyCustom', 'file' => 'my_custom.php'));
$ErrorHandler = new ErrorHandler('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);
Expand All @@ -599,7 +618,7 @@ function testMissingBehaviorClass() {
function testMissingComponentFile() {
$this->markTestIncomplete('Not implemented now');
ob_start();
$TestErrorHandler = new TestErrorHandler('missingComponentFile', array('className' => 'PostsController', 'component' => 'Sidebox', 'file' => 'sidebox.php'));
$ErrorHandler = new ErrorHandler('missingComponentFile', array('className' => 'PostsController', 'component' => 'Sidebox', 'file' => 'sidebox.php'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Component File<\/h2>/', $result);
$this->assertPattern('/Create the class <em>SideboxComponent<\/em> in file:/', $result);
Expand All @@ -615,7 +634,7 @@ function testMissingComponentFile() {
function testMissingComponentClass() {
$this->markTestIncomplete('Not implemented now');
ob_start();
$TestErrorHandler = new TestErrorHandler('missingComponentClass', array('className' => 'PostsController', 'component' => 'Sidebox', 'file' => 'sidebox.php'));
$ErrorHandler = new ErrorHandler('missingComponentClass', array('className' => 'PostsController', 'component' => 'Sidebox', 'file' => 'sidebox.php'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Component Class<\/h2>/', $result);
$this->assertPattern('/Create the class <em>SideboxComponent<\/em> in file:/', $result);
Expand All @@ -631,7 +650,7 @@ function testMissingComponentClass() {
function testMissingModel() {
$this->markTestIncomplete('Not implemented now');
ob_start();
$TestErrorHandler = new TestErrorHandler('missingModel', array('className' => 'Article', 'file' => 'article.php'));
$ErrorHandler = new ErrorHandler('missingModel', array('className' => 'Article', 'file' => 'article.php'));
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Model<\/h2>/', $result);
$this->assertPattern('/<em>Article<\/em> could not be found./', $result);
Expand Down

0 comments on commit 8712a90

Please sign in to comment.