Fixing ModelBehavior::detach() when non 0 index behaviors are detatched. Tests Added.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7862 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2008-11-11 00:17:37 +00:00
parent 6285f0cb6d
commit eccfea3429
2 changed files with 17 additions and 1 deletions

View file

@ -329,7 +329,7 @@ class BehaviorCollection extends Object {
unset($this->__methods[$m]);
}
}
$this->_attached = array_diff($this->_attached, (array)$name);
$this->_attached = array_values(array_diff($this->_attached, (array)$name));
}
/**
* Enables callbacks on a behavior or array of behaviors

View file

@ -932,6 +932,22 @@ class BehaviorTest extends CakeTestCase {
$expected = array('TestBehavior', 'Test2Behavior');
$this->assertIdentical($Apple->beforeTestResult, $expected);
}
/**
* Test attach and detaching
*
* @return void
**/
function testBehaviorAttachAndDetach() {
$Sample =& new Sample();
$Sample->actsAs = array('Test3' => array('bar'), 'Test2' => array('foo', 'bar'));
$Sample->Behaviors->init($Sample->alias, $Sample->actsAs);
$Sample->Behaviors->attach('Test2');
$Sample->Behaviors->detach('Test3');
$Sample->Behaviors->trigger($Apple, 'beforeTest');
}
/**
* tearDown method
*