Fixed bug in BehaviorCollection::trigger, closes #4520

Added basic test coverage for BehaviorCollection::trigger

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6828 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
the_undefined 2008-05-13 02:33:44 +00:00
parent 6f64efb342
commit 425dbf363d
2 changed files with 36 additions and 1 deletions

View file

@ -431,7 +431,7 @@ class BehaviorCollection extends Object {
}
$result = $this->{$name}->dispatchMethod($model, $callback, $params);
if ($options['break'] && ($result === $options['breakOn'] || is_array($options['breakOn'] && in_array($result, $options['breakOn'], true)))) {
if ($options['break'] && ($result === $options['breakOn'] || (is_array($options['breakOn']) && in_array($result, $options['breakOn'], true)))) {
return $result;
} elseif ($options['modParams'] && is_array($result)) {
$params[0] = $result;

View file

@ -81,6 +81,11 @@ class TestBehavior extends ModelBehavior {
}
}
function beforeTest(&$model) {
$model->beforeTestResult[] = get_class($this);
return get_class($this);
}
function testMethod(&$model, $param = true) {
if ($param === true) {
return 'working';
@ -106,6 +111,14 @@ class TestBehavior extends ModelBehavior {
}
}
class Test2Behavior extends TestBehavior{
}
class Test3Behavior extends TestBehavior{
}
class BehaviorTest extends CakeTestCase {
var $fixtures = array('core.apple', 'core.sample');
@ -271,6 +284,28 @@ class BehaviorTest extends CakeTestCase {
$this->assertTrue($this->model->data['Apple']['field_2']);
}
function testBehaviorTrigger() {
$this->model = new Apple();
$this->model->Behaviors->attach('Test');
$this->model->Behaviors->attach('Test2');
$this->model->Behaviors->attach('Test3');
$this->model->beforeTestResult = array();
$this->model->Behaviors->trigger($this->model, 'beforeTest');
$expected = array('TestBehavior', 'Test2Behavior', 'Test3Behavior');
$this->assertIdentical($this->model->beforeTestResult, $expected);
$this->model->beforeTestResult = array();
$this->model->Behaviors->trigger($this->model, 'beforeTest', array(), array('break' => true, 'breakOn' => 'Test2Behavior'));
$expected = array('TestBehavior', 'Test2Behavior');
$this->assertIdentical($this->model->beforeTestResult, $expected);
$this->model->beforeTestResult = array();
$this->model->Behaviors->trigger($this->model, 'beforeTest', array(), array('break' => true, 'breakOn' => array('Test2Behavior', 'Test3Behavior')));
$expected = array('TestBehavior', 'Test2Behavior');
$this->assertIdentical($this->model->beforeTestResult, $expected);
}
function tearDown() {
unset($this->model);
ClassRegistry::flush();