From 79839c07d2e9689dbcaaf12a979690c3f1824361 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 11 May 2010 23:08:14 -0400 Subject: [PATCH] Fixing issues where ModelBehavior::detach() would not detach behaviors when a plugin.name was provided. This change makes detach() work like attach(). Tests added. Fixes #711 --- cake/libs/model/model_behavior.php | 1 + .../cases/libs/model/model_behavior.test.php | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/cake/libs/model/model_behavior.php b/cake/libs/model/model_behavior.php index deb397c7509..77a4157ffcc 100644 --- a/cake/libs/model/model_behavior.php +++ b/cake/libs/model/model_behavior.php @@ -372,6 +372,7 @@ function attach($behavior, $config = array()) { * @access public */ function detach($name) { + list($plugin, $name) = pluginSplit($name); if (isset($this->{$name})) { $this->{$name}->cleanup(ClassRegistry::getObject($this->modelName)); unset($this->{$name}); diff --git a/cake/tests/cases/libs/model/model_behavior.test.php b/cake/tests/cases/libs/model/model_behavior.test.php index d87bfbef1d8..f0a641c7a0f 100644 --- a/cake/tests/cases/libs/model/model_behavior.test.php +++ b/cake/tests/cases/libs/model/model_behavior.test.php @@ -504,6 +504,28 @@ function testBehaviorBinding() { $this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected); } +/** + * test that attach()/detach() works with plugin.banana + * + * @return void + */ + function testDetachWithPluginNames() { + $Apple = new Apple(); + $Apple->Behaviors->attach('Plugin.Test'); + $this->assertTrue(isset($Apple->Behaviors->Test), 'Missing behavior'); + $this->assertEqual($Apple->Behaviors->attached(), array('Test')); + + $Apple->Behaviors->detach('Plugin.Test'); + $this->assertEqual($Apple->Behaviors->attached(), array()); + + $Apple->Behaviors->attach('Plugin.Test'); + $this->assertTrue(isset($Apple->Behaviors->Test), 'Missing behavior'); + $this->assertEqual($Apple->Behaviors->attached(), array('Test')); + + $Apple->Behaviors->detach('Test'); + $this->assertEqual($Apple->Behaviors->attached(), array()); + } + /** * test that attaching a non existant Behavior triggers a cake error. *