Skip to content

Commit

Permalink
Fixing issues where ModelBehavior::detach() would not detach behavior…
Browse files Browse the repository at this point in the history
…s when a plugin.name was provided. This change makes detach() work like attach(). Tests added. Fixes #711
  • Loading branch information
markstory committed May 12, 2010
1 parent 0648c66 commit 79839c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions cake/libs/model/model_behavior.php
Expand Up @@ -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});
Expand Down
22 changes: 22 additions & 0 deletions cake/tests/cases/libs/model/model_behavior.test.php
Expand Up @@ -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.
*
Expand Down

0 comments on commit 79839c0

Please sign in to comment.