From 041aeecce4ef83382312453f46e34c3fa9f48264 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 29 Aug 2010 01:01:36 -0400 Subject: [PATCH] Renaming test case file to match class file. Updating tests and methods for missing_action, missing_view, private_action. --- cake/libs/exceptions.php | 2 +- cake/libs/view/errors/missing_action.ctp | 6 +- cake/libs/view/errors/missing_view.ctp | 2 +- cake/libs/view/errors/private_action.ctp | 2 +- ...{error.test.php => error_handler.test.php} | 135 +++++++++--------- 5 files changed, 71 insertions(+), 76 deletions(-) rename cake/tests/cases/libs/{error.test.php => error_handler.test.php} (89%) diff --git a/cake/libs/exceptions.php b/cake/libs/exceptions.php index b18c77fc3ca..51361d6c336 100644 --- a/cake/libs/exceptions.php +++ b/cake/libs/exceptions.php @@ -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); } diff --git a/cake/libs/view/errors/missing_action.ctp b/cake/libs/view/errors/missing_action.ctp index 1a5872388b7..3bb14ceac8a 100644 --- a/cake/libs/view/errors/missing_action.ctp +++ b/cake/libs/view/errors/missing_action.ctp @@ -24,16 +24,14 @@

: - ' . $controller . '::', '' . $action . '()', APP_DIR . DS . 'controllers' . DS . Inflector::underscore($controller) . '.php'); ?> + ' . $controller . '::', '' . $action . '', APP_DIR . DS . 'controllers' . DS . Inflector::underscore($controller) . '.php'); ?>

 <?php
 class  extends AppController {
 
-	public $name = '';
-
 
-	function () {
+	function  {
 
 	}
 
diff --git a/cake/libs/view/errors/missing_view.ctp b/cake/libs/view/errors/missing_view.ctp
index 121d97f9a66..55aef34ce14 100644
--- a/cake/libs/view/errors/missing_view.ctp
+++ b/cake/libs/view/errors/missing_view.ctp
@@ -20,7 +20,7 @@
 

: - ' . $controller . 'Controller::', '' . $action . '()'); ?> + ' . Inflector::camelize($this->request->controller) . 'Controller::', '' . $this->request->action . '()'); ?>

: diff --git a/cake/libs/view/errors/private_action.ctp b/cake/libs/view/errors/private_action.ctp index ab9f13cdc98..20236e31f8c 100644 --- a/cake/libs/view/errors/private_action.ctp +++ b/cake/libs/view/errors/private_action.ctp @@ -20,7 +20,7 @@

: - ' . $controller . '::', '' . $action . '()'); ?> + ' . $controller . '::', '' . $action . ''); ?>

: diff --git a/cake/tests/cases/libs/error.test.php b/cake/tests/cases/libs/error_handler.test.php similarity index 89% rename from cake/tests/cases/libs/error.test.php rename to cake/tests/cases/libs/error_handler.test.php index 4d069ded455..b4f3ede19f1 100644 --- a/cake/tests/cases/libs/error.test.php +++ b/cake/tests/cases/libs/error_handler.test.php @@ -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. @@ -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 @@ -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('/

Missing Method in PostsController<\/h2>/', $result); $this->assertPattern('/PostsController::<\/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('/

Missing Method in BlueberryController<\/h2>/', $result); $this->assertPattern('/BlueberryController::<\/em>inexistent\(\)<\/em>/', $result); $this->assertNoPattern('/Location: (.*)\/users\/login/', $result); $this->assertNoPattern('/Stopped with status: 0/', $result); + */ } /** @@ -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('/

Private Method in PostsController<\/h2>/', $result); $this->assertPattern('/PostsController::<\/em>_secretSauce\(\)<\/em>/', $result); } @@ -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('/

Missing Database Table<\/h2>/', $result); $this->assertPattern('/table articles<\/em> for model Article<\/em>/', $result); @@ -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('/

Missing Database Connection<\/h2>/', $result); $this->assertPattern('/Confirm you have created the file/', $result); @@ -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); } /** @@ -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); } /**