diff --git a/cake/libs/model/behavior.php b/cake/libs/model/behavior.php index 3d72279d3..0bdf51127 100644 --- a/cake/libs/model/behavior.php +++ b/cake/libs/model/behavior.php @@ -273,13 +273,23 @@ class BehaviorCollection extends Object { } if (!isset($this->{$name})) { - if (PHP5) { - $this->{$name} = new $class; + if (ClassRegistry::isKeySet($class)) { + if (PHP5) { + $this->{$name} = ClassRegistry::getObject($class); + } else { + $this->{$name} =& ClassRegistry::getObject($class); + } } else { - $this->{$name} =& new $class; + if (PHP5) { + $this->{$name} = new $class; + } else { + $this->{$name} =& new $class; + } + ClassRegistry::addObject($class, $this->{$name}); } } elseif (isset($this->{$name}->settings) && isset($this->{$name}->settings[$this->modelName])) { - if (!empty($config)) { + if ($config !== null && $config !== false) { + // if (!empty($config)) { $config = array_merge($this->{$name}->settings[$this->modelName], $config); } else { $config = array(); @@ -295,11 +305,18 @@ class BehaviorCollection extends Object { } $methods = get_class_methods($this->{$name}); $parentMethods = array_flip(get_class_methods('ModelBehavior')); - $callbacks = array('setup' => true, 'cleanup' => true, 'beforeFind' => true, 'afterFind' => true, 'beforeSave' => true, 'afterSave' => true, 'beforeDelete' => true, 'afterDelete' => true, 'afterError' => true); + $callbacks = array( + 'setup', 'cleanup', 'beforeFind', 'afterFind', 'beforeSave', 'afterSave', + 'beforeDelete', 'afterDelete', 'afterError' + ); foreach ($methods as $m) { if (!isset($parentMethods[$m])) { - if ($m[0] != '_' && !array_key_exists($m, $this->__methods) && !isset($callbacks[$m])) { + $methodAllowed = ( + $m[0] != '_' && !array_key_exists($m, $this->__methods) && + !in_array($m, $callbacks) + ); + if ($methodAllowed) { $this->__methods[$m] = array($m, $name); } } diff --git a/cake/tests/cases/libs/model/behavior.test.php b/cake/tests/cases/libs/model/behavior.test.php index 914c5ce1c..628397fa3 100644 --- a/cake/tests/cases/libs/model/behavior.test.php +++ b/cake/tests/cases/libs/model/behavior.test.php @@ -375,8 +375,11 @@ class BehaviorTest extends CakeTestCase { $this->assertIdentical($Apple->Sample->Behaviors->attached(), array('Test')); $this->assertEqual($Apple->Sample->Behaviors->Test->settings['Sample'], array('beforeFind' => 'on', 'afterFind' => 'off', 'key2' => 'value2')); - $this->assertEqual(array_keys($Apple->Behaviors->Test->settings), array('Apple')); - $this->assertEqual(array_keys($Apple->Sample->Behaviors->Test->settings), array('Sample')); + $this->assertEqual(array_keys($Apple->Behaviors->Test->settings), array('Apple', 'Sample')); + $this->assertIdentical( + $Apple->Sample->Behaviors->Test->settings, + $Apple->Behaviors->Test->settings + ); $this->assertNotIdentical($Apple->Behaviors->Test->settings['Apple'], $Apple->Sample->Behaviors->Test->settings['Sample']); $Apple->Behaviors->attach('Test', array('key2' => 'value2', 'key3' => 'value3', 'beforeFind' => 'off')); @@ -398,14 +401,20 @@ class BehaviorTest extends CakeTestCase { $this->assertFalse($Apple->Behaviors->attach('NoSuchBehavior')); $Apple->Behaviors->attach('Plugin.Test', array('key' => 'new value')); - $this->assertEqual($Apple->Behaviors->Test->settings['Apple'], array('beforeFind' => 'off', 'afterFind' => 'off', 'key' => 'new value', 'key2' => 'value2', 'key3' => 'value3')); + $expected = array( + 'beforeFind' => 'off', 'afterFind' => 'off', 'key' => 'new value', + 'key2' => 'value2', 'key3' => 'value3' + ); + $this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected); $current = $Apple->Behaviors->Test->settings['Apple']; $expected = array_merge($current, array('mangle' => 'trigger mangled')); $Apple->Behaviors->attach('Test', array('mangle' => 'trigger')); $this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected); + $Apple->Behaviors->attach('Test'); $expected = array_merge($current, array('mangle' => 'trigger mangled mangled')); + $this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected); $Apple->Behaviors->attach('Test', array('mangle' => 'trigger')); $expected = array_merge($current, array('mangle' => 'trigger mangled')); diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 742b002d2..51d3d2f5f 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -1571,8 +1571,6 @@ class ModelTest extends CakeTestCase { * @return void */ function testUpdateWithCalculation() { - Configure::write('foo', true); - $this->loadFixtures('DataTest'); $model =& new DataTest(); $result = $model->saveAll(array(