Skip to content

Commit

Permalink
Renaming test case file to match class file.
Browse files Browse the repository at this point in the history
Updating tests and methods for missing_action, missing_view, private_action.
  • Loading branch information
markstory committed Aug 29, 2010
1 parent 88c66c0 commit 041aeec
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 76 deletions.
2 changes: 1 addition & 1 deletion cake/libs/exceptions.php
Expand Up @@ -102,7 +102,7 @@ class MissingTableException extends CakeException {
*/
public function __construct($model, $table) {
$this->model = $model;
$this->$table = $table;
$this->table = $table;
$message = sprintf(__('Database table %s for model %s was not found.'), $table, $model);
parent::__construct($message);
}
Expand Down
6 changes: 2 additions & 4 deletions cake/libs/view/errors/missing_action.ctp
Expand Up @@ -24,16 +24,14 @@
</p>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
<?php printf(__('Create %1$s%2$s in file: %3$s.'), '<em>' . $controller . '::</em>', '<em>' . $action . '()</em>', APP_DIR . DS . 'controllers' . DS . Inflector::underscore($controller) . '.php'); ?>
<?php printf(__('Create %1$s%2$s in file: %3$s.'), '<em>' . $controller . '::</em>', '<em>' . $action . '</em>', APP_DIR . DS . 'controllers' . DS . Inflector::underscore($controller) . '.php'); ?>
</p>
<pre>
&lt;?php
class <?php echo $controller;?> extends AppController {

public $name = '<?php echo $controllerName;?>';

<strong>
function <?php echo $action;?>() {
function <?php echo $action;?> {

}
</strong>
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/view/errors/missing_view.ctp
Expand Up @@ -20,7 +20,7 @@
<h2><?php echo __('Missing View'); ?></h2>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
<?php printf(__('The view for %1$s%2$s was not found.'), '<em>' . $controller . 'Controller::</em>', '<em>' . $action . '()</em>'); ?>
<?php printf(__('The view for %1$s%2$s was not found.'), '<em>' . Inflector::camelize($this->request->controller) . 'Controller::</em>', '<em>' . $this->request->action . '()</em>'); ?>
</p>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/view/errors/private_action.ctp
Expand Up @@ -20,7 +20,7 @@
<h2><?php printf(__('Private Method in %s'), $controller); ?></h2>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
<?php printf(__('%s%s cannot be accessed directly.'), '<em>' . $controller . '::</em>', '<em>' . $action . '()</em>'); ?>
<?php printf(__('%s%s cannot be accessed directly.'), '<em>' . $controller . '::</em>', '<em>' . $action . '</em>'); ?>
</p>
<p class="notice">
<strong><?php echo __('Notice'); ?>: </strong>
Expand Down
Expand Up @@ -17,56 +17,7 @@
* @since CakePHP(tm) v 1.2.0.5432
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
if (class_exists('TestErrorHandler')) {
return;
}

/**
* BlueberryComponent class
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class BlueberryComponent extends Object {

/**
* testName property
*
* @access public
* @return void
*/
public $testName = null;

/**
* initialize method
*
* @access public
* @return void
*/
function initialize(&$controller) {
$this->testName = 'BlueberryComponent';
}
}

/**
* BlueberryDispatcher class
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class BlueberryDispatcher extends Dispatcher {

/**
* cakeError method
*
* @access public
* @return void
*/
function cakeError($method, $messages = array()) {
$error = new TestErrorHandler($method, $messages);
return $error;
}
}

/**
* Short description for class.
Expand Down Expand Up @@ -138,7 +89,34 @@ function _stop($status = 0) {
} elseif (!defined('APP_CONTROLLER_EXISTS')){
define('APP_CONTROLLER_EXISTS', true);
}
App::import('Core', array('Error', 'Controller'));
App::import('Core', array('ErrorHandler', 'Controller', 'Component'));

/**
* BlueberryComponent class
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class BlueberryComponent extends Component {

/**
* testName property
*
* @access public
* @return void
*/
public $testName = null;

/**
* initialize method
*
* @access public
* @return void
*/
function initialize(&$controller) {
$this->testName = 'BlueberryComponent';
}
}

/**
* TestErrorController class
Expand Down Expand Up @@ -453,20 +431,25 @@ function testMissingController() {
* @return void
*/
function testMissingAction() {
$this->markTestIncomplete('Not implemented now');
$exception = new MissingActionException('PostsController::index()');
$ErrorHandler = new ErrorHandler($exception);

ob_start();
$ErrorHandler = new ErrorHandler('missingAction', array('className' => 'PostsController', 'action' => 'index'));
$ErrorHandler->render();
$result = ob_get_clean();

$this->assertPattern('/<h2>Missing Method in PostsController<\/h2>/', $result);
$this->assertPattern('/<em>PostsController::<\/em><em>index\(\)<\/em>/', $result);

/* TODO: Integration test that needs to be moved
ob_start();
$dispatcher = new BlueberryDispatcher('/blueberry/inexistent');
$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);
*/
}

/**
Expand All @@ -476,10 +459,13 @@ function testMissingAction() {
* @return void
*/
function testPrivateAction() {
$this->markTestIncomplete('Not implemented now');
$exception = new PrivateActionException('PostsController::_secretSauce()');
$ErrorHandler = new ErrorHandler($exception);

ob_start();
$ErrorHandler = new ErrorHandler('privateAction', array('className' => 'PostsController', 'action' => '_secretSauce'));
$ErrorHandler->render();
$result = ob_get_clean();

$this->assertPattern('/<h2>Private Method in PostsController<\/h2>/', $result);
$this->assertPattern('/<em>PostsController::<\/em><em>_secretSauce\(\)<\/em>/', $result);
}
Expand All @@ -491,10 +477,13 @@ function testPrivateAction() {
* @return void
*/
function testMissingTable() {
$this->markTestIncomplete('Not implemented now');
$exception = new MissingTableException('Article', 'articles');
$ErrorHandler = new ErrorHandler($exception);

ob_start();
$ErrorHandler = new ErrorHandler('missingTable', array('className' => 'Article', 'table' => 'articles'));
$ErrorHandler->render();
$result = ob_get_clean();

$this->assertPattern('/HTTP\/1\.0 500 Internal Server Error/', $result);
$this->assertPattern('/<h2>Missing Database Table<\/h2>/', $result);
$this->assertPattern('/table <em>articles<\/em> for model <em>Article<\/em>/', $result);
Expand All @@ -507,10 +496,13 @@ function testMissingTable() {
* @return void
*/
function testMissingDatabase() {
$this->markTestIncomplete('Not implemented now');
$exception = new MissingDatabaseException('default');
$ErrorHandler = new ErrorHandler($exception);

ob_start();
$ErrorHandler = new ErrorHandler('missingDatabase', array());
$ErrorHandler->render();
$result = ob_get_clean();

$this->assertPattern('/HTTP\/1\.0 500 Internal Server Error/', $result);
$this->assertPattern('/<h2>Missing Database Connection<\/h2>/', $result);
$this->assertPattern('/Confirm you have created the file/', $result);
Expand All @@ -523,12 +515,14 @@ function testMissingDatabase() {
* @return void
*/
function testMissingView() {
$this->markTestIncomplete('Not implemented now');
$exception = new MissingViewException('/posts/about.ctp');
$ErrorHandler = new ErrorHandler($exception);

ob_start();
$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);
$ErrorHandler->render();
$result = ob_get_clean();

$this->assertPattern("/posts\/about.ctp/", $result);
}

/**
Expand All @@ -538,12 +532,15 @@ function testMissingView() {
* @return void
*/
function testMissingLayout() {
$this->markTestIncomplete('Not implemented now');
$exception = new MissingLayoutException('layouts/my_layout.ctp');
$ErrorHandler = new ErrorHandler($exception);

ob_start();
$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);
$ErrorHandler->render();
$result = ob_get_clean();

$this->assertPattern("/Missing Layout/", $result);
$this->assertPattern("/layouts\/my_layout.ctp/", $result);
}

/**
Expand Down

0 comments on commit 041aeec

Please sign in to comment.