Skip to content
Permalink
Browse files

Fixing issues with cakeError call.

Adding tests for cakeError being called with non-existant Behaviors.
  • Loading branch information...
markstory committed Aug 30, 2009
1 parent 7ca1ef2 commit c19c1a782895249dc0c33a59e5a39c0f4373ded5
Showing with 21 additions and 7 deletions.
  1. +3 −3 cake/libs/model/model_behavior.php
  2. +18 −4 cake/tests/cases/libs/model/model_behavior.test.php
@@ -300,10 +300,10 @@ function attach($behavior, $config = array()) {
)));
return false;
}
if (!class_exists($behavior . 'Behavior')) {
if (!class_exists($class)) {
$this->cakeError('missingBehaviorClass', array(array(
'behavior' => $behavior,
'file' => Inflector::underscore($behavior) . '.php',
'behavior' => $class,
'file' => Inflector::underscore($class) . '.php',
'code' => 500,
'base' => '/'
)));
@@ -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 @@ function testBehaviorBinding() {
$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 @@ function testBehaviorBinding() {
$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 @@ function testBehaviorBinding() {
$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
*

0 comments on commit c19c1a7

Please sign in to comment.
You can’t perform that action at this time.