diff --git a/cake/libs/model/behavior.php b/cake/libs/model/behavior.php index 7607be7f0..c8d446119 100644 --- a/cake/libs/model/behavior.php +++ b/cake/libs/model/behavior.php @@ -270,24 +270,14 @@ class BehaviorCollection extends Object { $class = $name . 'Behavior'; if (!App::import('Behavior', $behavior)) { - // Raise an error return false; } if (!isset($this->{$name})) { - if (ClassRegistry::isKeySet($class)) { - if (PHP5) { - $this->{$name} = ClassRegistry::getObject($class); - } else { - $this->{$name} =& ClassRegistry::getObject($class); - } + if (PHP5) { + $this->{$name} = new $class; } else { - if (PHP5) { - $this->{$name} = new $class; - } else { - $this->{$name} =& new $class; - } - ClassRegistry::addObject($class, $this->{$name}); + $this->{$name} =& new $class; } } elseif (isset($this->{$name}->settings) && isset($this->{$name}->settings[$this->modelName])) { $config = array_merge($this->{$name}->settings[$this->modelName], $config); @@ -297,7 +287,6 @@ class BehaviorCollection extends Object { foreach ($this->{$name}->mapMethods as $method => $alias) { $this->__mappedMethods[$method] = array($alias, $name); } - $methods = get_class_methods($this->{$name}); $parentMethods = get_class_methods('ModelBehavior'); $callbacks = array('setup', 'cleanup', 'beforeFind', 'afterFind', 'beforeSave', 'afterSave', 'beforeDelete', 'afterDelete', 'afterError'); @@ -478,5 +467,4 @@ class BehaviorCollection extends Object { return $this->_attached; } } - ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/model/behavior.test.php b/cake/tests/cases/libs/model/behavior.test.php index cd8ae4555..68b43b945 100644 --- a/cake/tests/cases/libs/model/behavior.test.php +++ b/cake/tests/cases/libs/model/behavior.test.php @@ -123,14 +123,27 @@ class BehaviorTest extends CakeTestCase { $this->assertIdentical($this->model->Sample->Behaviors->attached(), array()); $this->model->Sample->Behaviors->attach('Test', array('key2' => 'value2')); $this->assertIdentical($this->model->Sample->Behaviors->attached(), array('Test')); - $this->assertEqual($this->model->Behaviors->Test->settings['Sample'], array('before' => 'on', 'after' => 'off', 'key2' => 'value2')); + $this->assertEqual($this->model->Sample->Behaviors->Test->settings['Sample'], array('before' => 'on', 'after' => 'off', 'key2' => 'value2')); - $this->assertEqual(array_keys($this->model->Behaviors->Test->settings), array('Apple', 'Sample')); - $this->assertIdentical($this->model->Behaviors->Test->settings, $this->model->Sample->Behaviors->Test->settings); + $this->assertEqual(array_keys($this->model->Behaviors->Test->settings), array('Apple')); + $this->assertEqual(array_keys($this->model->Sample->Behaviors->Test->settings), array('Sample')); + $this->assertNotIdentical($this->model->Behaviors->Test->settings['Apple'], $this->model->Sample->Behaviors->Test->settings['Sample']); - $this->model->Behaviors->attach('Test', array('key3' => 'value3', 'before' => 'off')); - $this->assertEqual($this->model->Behaviors->Test->settings['Apple'], array('before' => 'off', 'after' => 'off', 'key' => 'value', 'key3' => 'value3')); - $this->assertIdentical($this->model->Behaviors->Test->settings, $this->model->Sample->Behaviors->Test->settings); + $this->model->Behaviors->attach('Test', array('key2' => 'value2', 'key3' => 'value3', 'before' => 'off')); + $this->model->Sample->Behaviors->attach('Test', array('key' => 'value', 'key3' => 'value3', 'before' => 'off')); + $this->assertEqual($this->model->Behaviors->Test->settings['Apple'], array('before' => 'off', 'after' => 'off', 'key' => 'value', 'key2' => 'value2', 'key3' => 'value3')); + $this->assertEqual($this->model->Behaviors->Test->settings['Apple'], $this->model->Sample->Behaviors->Test->settings['Sample']); + + $this->assertFalse(isset($this->model->Child->Behaviors->Test)); + $this->model->Child->Behaviors->attach('Test', array('key' => 'value', 'key2' => 'value2', 'key3' => 'value3', 'before' => 'off')); + $this->assertEqual($this->model->Child->Behaviors->Test->settings['Child'], $this->model->Sample->Behaviors->Test->settings['Sample']); + + $this->assertFalse(isset($this->model->Parent->Behaviors->Test)); + $this->model->Parent->Behaviors->attach('Test', array('key' => 'value', 'key2' => 'value2', 'key3' => 'value3', 'before' => 'off')); + $this->assertEqual($this->model->Parent->Behaviors->Test->settings['Parent'], $this->model->Sample->Behaviors->Test->settings['Sample']); + + $this->model->Parent->Behaviors->attach('Test', array('key' => 'value', 'key2' => 'value', 'key3' => 'value', 'before' => 'off')); + $this->assertNotEqual($this->model->Parent->Behaviors->Test->settings['Parent'], $this->model->Sample->Behaviors->Test->settings['Sample']); } function testBehaviorToggling() { diff --git a/cake/tests/cases/libs/model/behaviors/translate.test.php b/cake/tests/cases/libs/model/behaviors/translate.test.php index b2a74509d..0f601a05d 100644 --- a/cake/tests/cases/libs/model/behaviors/translate.test.php +++ b/cake/tests/cases/libs/model/behaviors/translate.test.php @@ -445,7 +445,7 @@ class TranslateTest extends CakeTestCase { } function testAttachDetach() { - $Behavior =& $this->Model->Behaviors->Translate; + $Behavior = $this->Model->Behaviors->Translate; $this->Model->unbindTranslation(); $translations = array('title' => 'Title', 'content' => 'Content'); @@ -478,6 +478,8 @@ class TranslateTest extends CakeTestCase { $result = isset($this->Model->Behaviors->Translate); $this->assertTrue($result); + $Behavior = $this->Model->Behaviors->Translate; + $result = isset($Behavior->settings[$this->Model->alias]); $this->assertTrue($result);