Merge branch '1.3-behavior-error' into 1.3-misc

This commit is contained in:
mark_story 2009-08-30 19:33:43 -04:00
commit 81cb097959
5 changed files with 147 additions and 4 deletions

View file

@ -335,6 +335,40 @@ class ErrorHandler extends Object {
$this->_outputMessage('missingHelperClass');
}
/**
* Renders the Missing Behavior file web page.
*
* @param array $params Parameters for controller
* @access public
*/
function missingBehaviorFile($params) {
extract($params, EXTR_OVERWRITE);
$this->controller->set(array(
'behaviorClass' => Inflector::camelize($behavior) . "Behavior",
'file' => $file,
'title' => __('Missing Behavior File', true)
));
$this->_outputMessage('missingBehaviorFile');
}
/**
* Renders the Missing Behavior class web page.
*
* @param array $params Parameters for controller
* @access public
*/
function missingBehaviorClass($params) {
extract($params, EXTR_OVERWRITE);
$this->controller->set(array(
'behaviorClass' => Inflector::camelize($behavior) . "Behavior",
'file' => $file,
'title' => __('Missing Behavior Class', true)
));
$this->_outputMessage('missingBehaviorClass');
}
/**
* Renders the Missing Component file web page.
*

View file

@ -292,6 +292,21 @@ class BehaviorCollection extends Object {
$class = $name . 'Behavior';
if (!App::import('Behavior', $behavior)) {
$this->cakeError('missingBehaviorFile', array(array(
'behavior' => $behavior,
'file' => Inflector::underscore($behavior) . '.php',
'code' => 500,
'base' => '/'
)));
return false;
}
if (!class_exists($class)) {
$this->cakeError('missingBehaviorClass', array(array(
'behavior' => $class,
'file' => Inflector::underscore($class) . '.php',
'code' => 500,
'base' => '/'
)));
return false;
}

View file

@ -0,0 +1,40 @@
<?php
/**
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs.view.templates.errors
* @since CakePHP(tm) v 1.3
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
?>
<h2><?php __('Missing Behavior Class'); ?></h2>
<p class="error">
<strong><?php __('Error'); ?>: </strong>
<?php echo sprintf(__("The behavior class <em>%s</em> can not be found or does not exist.", true), $behaviorClass);?>
</p>
<p class="error">
<strong><?php __('Error'); ?>: </strong>
<?php echo sprintf(__('Create the class below in file: %s', true), APP_DIR . DS . "models" . DS . "behaviors" . DS . $file);?>
</p>
<pre>
&lt;?php
class <?php echo $behaviorClass;?> extends ModelBehavior {
}
?&gt;
</pre>
<p class="notice">
<strong><?php __('Notice'); ?>: </strong>
<?php echo sprintf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . "views" . DS . "errors" . DS . "missing_behavior_class.ctp");?>
</p>

View file

@ -0,0 +1,40 @@
<?php
/**
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs.view.templates.errors
* @since CakePHP(tm) v 1.3
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
?>
<h2><?php __('Missing Behavior File'); ?></h2>
<p class="error">
<strong><?php __('Error'); ?>: </strong>
<?php echo sprintf(__("The Behavior file %s can not be found or does not exist.", true), APP_DIR . DS . "models" . DS . "behaviors" . DS . $file);?>
</p>
<p class="error">
<strong><?php __('Error'); ?>: </strong>
<?php echo sprintf(__('Create the class below in file: %s', true), APP_DIR . DS . "models" . DS . "behaviors" . DS . $file);?>
</p>
<pre>
&lt;?php
class <?php echo $behaviorClass;?> extends ModelBehavior {
}
?&gt;
</pre>
<p class="notice">
<strong><?php __('Notice'); ?>: </strong>
<?php echo sprintf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . "views" . DS . "errors" . DS . "missing_behavior_file.ctp");?>
</p>

View file

@ -22,6 +22,8 @@
App::import('Model', 'AppModel');
require_once dirname(__FILE__) . DS . 'models.php';
Mock::generatePartial('BehaviorCollection', 'MockModelBehaviorCollection', array('cakeError', '_stop'));
/**
* TestBehavior class
*
@ -432,7 +434,7 @@ class BehaviorTest extends CakeTestCase {
* @access public
* @return void
*/
function tearDown() {
function endTest() {
ClassRegistry::flush();
}
@ -449,7 +451,8 @@ class BehaviorTest extends CakeTestCase {
$Apple->Behaviors->attach('Test', array('key' => 'value'));
$this->assertIdentical($Apple->Behaviors->attached(), array('Test'));
$this->assertEqual(strtolower(get_class($Apple->Behaviors->Test)), 'testbehavior');
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], array('beforeFind' => 'on', 'afterFind' => 'off', 'key' => 'value'));
$expected = array('beforeFind' => 'on', 'afterFind' => 'off', 'key' => 'value');
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected);
$this->assertEqual(array_keys($Apple->Behaviors->Test->settings), array('Apple'));
$this->assertIdentical($Apple->Sample->Behaviors->attached(), array());
@ -480,8 +483,6 @@ class BehaviorTest extends CakeTestCase {
$Apple->Parent->Behaviors->attach('Test', array('key' => 'value', 'key2' => 'value', 'key3' => 'value', 'beforeFind' => 'off'));
$this->assertNotEqual($Apple->Parent->Behaviors->Test->settings['Parent'], $Apple->Sample->Behaviors->Test->settings['Sample']);
$this->assertFalse($Apple->Behaviors->attach('NoSuchBehavior'));
$Apple->Behaviors->attach('Plugin.Test', array('key' => 'new value'));
$expected = array(
'beforeFind' => 'off', 'afterFind' => 'off', 'key' => 'new value',
@ -503,6 +504,19 @@ class BehaviorTest extends CakeTestCase {
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected);
}
/**
* test that attaching a non existant Behavior triggers a cake error.
*
* @return void
**/
function testInvalidBehaviorCausingCakeError() {
$Apple =& new Apple();
$Apple->Behaviors =& new MockModelBehaviorCollection();
$Apple->Behaviors->expectOnce('cakeError');
$Apple->Behaviors->expectAt(0, 'cakeError', array('missingBehaviorFile', '*'));
$this->assertFalse($Apple->Behaviors->attach('NoSuchBehavior'));
}
/**
* testBehaviorToggling method
*