Fix illegal offset caused by TranslateBehavior.

If you load TranslateBehavior at runtime in a disabled state, the enabled
flag would be interpreted as an association and cause errors.

Fixes #2443
This commit is contained in:
mark_story 2012-01-07 11:58:35 -05:00
parent 87924414fc
commit beced84d2d
2 changed files with 17 additions and 2 deletions

View file

@ -106,6 +106,9 @@ class BehaviorCollection extends ObjectCollection {
$alias = $behavior;
$behavior = $config['className'];
}
$configDisabled = isset($config['enabled']) && $config['enabled'] === false;
unset($config['enabled'], $config['className']);
list($plugin, $name) = pluginSplit($behavior, true);
if (!isset($alias)) {
$alias = $name;
@ -165,7 +168,6 @@ class BehaviorCollection extends ObjectCollection {
}
}
$configDisabled = isset($config['enabled']) && $config['enabled'] === false;
if (!in_array($alias, $this->_enabled) && !$configDisabled) {
$this->enable($alias);
} elseif ($configDisabled) {

View file

@ -419,9 +419,22 @@ class BehaviorCollectionTest extends CakeTestCase {
*/
public $fixtures = array(
'core.apple', 'core.sample', 'core.article', 'core.user', 'core.comment',
'core.attachment', 'core.tag', 'core.articles_tag'
'core.attachment', 'core.tag', 'core.articles_tag', 'core.translate'
);
/**
* Test load() with enabled => false
*
*/
public function testLoadDisabled() {
$Apple = new Apple();
$this->assertSame($Apple->Behaviors->attached(), array());
$Apple->Behaviors->load('Translate', array('enabled' => false));
$this->assertTrue($Apple->Behaviors->attached('Translate'));
$this->assertFalse($Apple->Behaviors->enabled('Translate'));
}
/**
* Tests loading aliased behaviors
*/