mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge branch '1.3-behavior-error' into 1.3-misc
This commit is contained in:
commit
81cb097959
5 changed files with 147 additions and 4 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
40
cake/libs/view/errors/missing_behavior_class.ctp
Normal file
40
cake/libs/view/errors/missing_behavior_class.ctp
Normal 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>
|
||||
<?php
|
||||
class <?php echo $behaviorClass;?> extends ModelBehavior {
|
||||
|
||||
}
|
||||
?>
|
||||
</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>
|
40
cake/libs/view/errors/missing_behavior_file.ctp
Normal file
40
cake/libs/view/errors/missing_behavior_file.ctp
Normal 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>
|
||||
<?php
|
||||
class <?php echo $behaviorClass;?> extends ModelBehavior {
|
||||
|
||||
}
|
||||
?>
|
||||
</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>
|
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue