mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
87924414fc
commit
beced84d2d
2 changed files with 17 additions and 2 deletions
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue