From beced84d2d96b7580c78c1243255b683a670de29 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 7 Jan 2012 11:58:35 -0500 Subject: [PATCH] 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 --- lib/Cake/Model/BehaviorCollection.php | 4 +++- .../Test/Case/Model/BehaviorCollectionTest.php | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/BehaviorCollection.php b/lib/Cake/Model/BehaviorCollection.php index 323cc63f6..1e154eaab 100644 --- a/lib/Cake/Model/BehaviorCollection.php +++ b/lib/Cake/Model/BehaviorCollection.php @@ -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) { diff --git a/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php b/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php index f2cea74f8..b9022320b 100644 --- a/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php +++ b/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php @@ -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 */