mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
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:
parent
6f64efb342
commit
425dbf363d
2 changed files with 36 additions and 1 deletions
|
@ -431,7 +431,7 @@ class BehaviorCollection extends Object {
|
||||||
}
|
}
|
||||||
$result = $this->{$name}->dispatchMethod($model, $callback, $params);
|
$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;
|
return $result;
|
||||||
} elseif ($options['modParams'] && is_array($result)) {
|
} elseif ($options['modParams'] && is_array($result)) {
|
||||||
$params[0] = $result;
|
$params[0] = $result;
|
||||||
|
|
|
@ -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) {
|
function testMethod(&$model, $param = true) {
|
||||||
if ($param === true) {
|
if ($param === true) {
|
||||||
return 'working';
|
return 'working';
|
||||||
|
@ -106,6 +111,14 @@ class TestBehavior extends ModelBehavior {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Test2Behavior extends TestBehavior{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Test3Behavior extends TestBehavior{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
class BehaviorTest extends CakeTestCase {
|
class BehaviorTest extends CakeTestCase {
|
||||||
|
|
||||||
var $fixtures = array('core.apple', 'core.sample');
|
var $fixtures = array('core.apple', 'core.sample');
|
||||||
|
@ -271,6 +284,28 @@ class BehaviorTest extends CakeTestCase {
|
||||||
$this->assertTrue($this->model->data['Apple']['field_2']);
|
$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() {
|
function tearDown() {
|
||||||
unset($this->model);
|
unset($this->model);
|
||||||
ClassRegistry::flush();
|
ClassRegistry::flush();
|
||||||
|
|
Loading…
Reference in a new issue