mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-06 11:32:40 +00:00
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
This commit is contained in:
parent
0648c6604b
commit
79839c07d2
2 changed files with 23 additions and 0 deletions
|
@ -372,6 +372,7 @@ class BehaviorCollection extends Object {
|
|||
* @access public
|
||||
*/
|
||||
function detach($name) {
|
||||
list($plugin, $name) = pluginSplit($name);
|
||||
if (isset($this->{$name})) {
|
||||
$this->{$name}->cleanup(ClassRegistry::getObject($this->modelName));
|
||||
unset($this->{$name});
|
||||
|
|
|
@ -504,6 +504,28 @@ class BehaviorTest extends CakeTestCase {
|
|||
$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.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue