Skip to content

Commit

Permalink
Removing AppController from ErrorHandler test as it can make testing …
Browse files Browse the repository at this point in the history
…harder.

Removing broken buffering from tests that trigger errors / exceptions.
Adding a loadHelper() to the test_app layout so the layout always has the required helper.
  • Loading branch information
markstory committed Sep 25, 2010
1 parent 714d829 commit 843ada2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 90 deletions.
105 changes: 27 additions & 78 deletions cake/tests/cases/libs/error_handler.test.php
Expand Up @@ -45,35 +45,6 @@ class AuthBlueberryUser extends CakeTestModel {
public $useTable = false;
}

if (!class_exists('AppController')) {
/**
* AppController class
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class AppController extends Controller {
/**
* components property
*
* @access public
* @return void
*/
public $components = array('Blueberry');
/**
* beforeRender method
*
* @access public
* @return void
*/
function beforeRender() {
echo $this->Blueberry->testName;
}
}
} elseif (!defined('APP_CONTROLLER_EXISTS')){
define('APP_CONTROLLER_EXISTS', true);
}

/**
* BlueberryComponent class
*
Expand Down Expand Up @@ -107,7 +78,7 @@ function initialize(&$controller) {
* @package cake
* @subpackage cake.tests.cases.libs
*/
class TestErrorController extends AppController {
class TestErrorController extends Controller {

/**
* uses property
Expand All @@ -118,40 +89,33 @@ class TestErrorController extends AppController {
public $uses = array();

/**
* index method
* components property
*
* @access public
* @return void
*/
function index() {
$this->autoRender = false;
return 'what up';
}
}
public $components = array('Blueberry');

/**
* BlueberryController class
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class BlueberryController extends AppController {

/**
* name property
* beforeRender method
*
* @access public
* @return void
*/
public $name = 'BlueberryController';
function beforeRender() {
echo $this->Blueberry->testName;
}

/**
* uses property
* index method
*
* @access public
* @return void
*/
public $uses = array();
function index() {
$this->autoRender = false;
return 'what up';
}
}

/**
Expand Down Expand Up @@ -187,30 +151,34 @@ class MissingWidgetThingException extends NotFoundException { }
*/
class ErrorHandlerTest extends CakeTestCase {

/**
* skip method
*
* @access public
* @return void
*/
function skip() {
$this->skipIf(PHP_SAPI === 'cli', '%s Cannot be run from console');
}

/**
* setup create a request object to get out of router later.
*
* @return void
*/
function setUp() {
App::build(array(
'views' => array(
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS,
TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS
)
), true);
Router::reload();

$request = new CakeRequest(null, false);
$request->base = '';
Router::setRequestInfo($request);
$this->_debug = Configure::read('debug');
}

/**
* teardown
*
* @return void
*/
function teardown() {
Configure::write('debug', $this->_debug);
App::build();
}

/**
Expand Down Expand Up @@ -372,10 +340,7 @@ function testUnknownExceptionTypeWithNoCodeIsA500() {
* @access public
* @return void
*/
function testerror400() {
App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS)
), true);
function testError400() {
Router::reload();

$request = new CakeRequest('posts/view/1000', false);
Expand All @@ -392,8 +357,6 @@ function testerror400() {

$this->assertPattern('/<h2>Custom message<\/h2>/', $result);
$this->assertPattern("/<strong>'\/posts\/view\/1000'<\/strong>/", $result);

App::build();
}

/**
Expand Down Expand Up @@ -468,8 +431,6 @@ function testError500Message() {
* @return void
*/
function testMissingController() {
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController');

$exception = new MissingControllerException(array('controller' => 'PostsController'));
$ErrorHandler = $this->_mockResponse(new ErrorHandler($exception));

Expand All @@ -479,20 +440,8 @@ function testMissingController() {

$this->assertPattern('/<h2>Missing Controller<\/h2>/', $result);
$this->assertPattern('/<em>PostsController<\/em>/', $result);
$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('/<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);
*/

/**
* Returns an array of tests to run for the various CakeException classes.
*
Expand Down
10 changes: 0 additions & 10 deletions cake/tests/cases/libs/model/datasources/dbo_source.test.php
Expand Up @@ -4243,16 +4243,6 @@ function testShowQuery() {
$this->assertPattern('/Aff:/s', $contents);
$this->assertPattern('/Num:/s', $contents);
$this->assertPattern('/Took:/s', $contents);

$this->expectError();
$this->testDb->error = true;
ob_start();
$this->testDb->showQuery('Another Query');
$contents = ob_get_clean();
$this->assertPattern('/Another Query/s', $contents);
$this->assertNoPattern('/Aff:/s', $contents);
$this->assertNoPattern('/Num:/s', $contents);
$this->assertNoPattern('/Took:/s', $contents);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions cake/tests/test_app/views/layouts/default.ctp
Expand Up @@ -16,6 +16,7 @@
* @since CakePHP(tm) v 0.10.0.1076
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
$this->loadHelper('Html');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
Expand All @@ -26,8 +27,6 @@
<?php echo $title_for_layout;?>
</title>

<link rel="icon" href="<?php echo $this->webroot;?>favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="<?php echo $this->webroot;?>favicon.ico" type="image/x-icon" />
<?php echo $this->Html->css('cake.generic');?>
<?php echo $scripts_for_layout;?>
</head>
Expand Down

0 comments on commit 843ada2

Please sign in to comment.