From 9058f0f6f1387d03a7b38d5d3cd15468250deea6 Mon Sep 17 00:00:00 2001 From: euromark Date: Tue, 8 Apr 2014 12:18:17 +0200 Subject: [PATCH] Make CakePlugin::loadAll behave correctly regarding merging of settings. --- lib/Cake/Core/CakePlugin.php | 6 +++--- lib/Cake/Test/Case/Core/CakePluginTest.php | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Core/CakePlugin.php b/lib/Cake/Core/CakePlugin.php index f96c11708d7..f0b1ebdca6c 100644 --- a/lib/Cake/Core/CakePlugin.php +++ b/lib/Cake/Core/CakePlugin.php @@ -121,9 +121,9 @@ public static function load($plugin, $config = array()) { public static function loadAll($options = array()) { $plugins = App::objects('plugins'); foreach ($plugins as $p) { - $opts = isset($options[$p]) ? $options[$p] : null; - if ($opts === null && isset($options[0])) { - $opts = $options[0]; + $opts = isset($options[$p]) ? $options[$p] : array(); + if (isset($options[0])) { + $opts += $options[0]; } self::load($p, (array)$opts); } diff --git a/lib/Cake/Test/Case/Core/CakePluginTest.php b/lib/Cake/Test/Case/Core/CakePluginTest.php index 73221b8dc40..94bc3c5acf7 100644 --- a/lib/Cake/Test/Case/Core/CakePluginTest.php +++ b/lib/Cake/Test/Case/Core/CakePluginTest.php @@ -253,8 +253,8 @@ public function testLoadAllWithDefaults() { } /** - * Tests that CakePlugin::loadAll() will load all plugins in the configured folder wit defaults - * and overrides for a plugin + * Tests that CakePlugin::loadAll() will load all plugins in the configured folder with defaults + * and merges in global defaults. * * @return void */ @@ -262,6 +262,24 @@ public function testLoadAllWithDefaultsAndOverride() { CakePlugin::loadAll(array(array('bootstrap' => true), 'TestPlugin' => array('routes' => true))); CakePlugin::routes(); + $expected = array('PluginJs', 'TestPlugin', 'TestPluginTwo'); + $this->assertEquals($expected, CakePlugin::loaded()); + $this->assertEquals('loaded js plugin bootstrap', Configure::read('CakePluginTest.js_plugin.bootstrap')); + $this->assertEquals('loaded plugin routes', Configure::read('CakePluginTest.test_plugin.routes')); + $this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap')); + $this->assertEquals('loaded plugin two bootstrap', Configure::read('CakePluginTest.test_plugin_two.bootstrap')); + } + +/** + * Tests that CakePlugin::loadAll() will load all plugins in the configured folder with defaults + * and overrides for a plugin + * + * @return void + */ + public function testLoadAllWithDefaultsAndOverrideComplex() { + CakePlugin::loadAll(array(array('bootstrap' => true), 'TestPlugin' => array('routes' => true, 'bootstrap' => false))); + CakePlugin::routes(); + $expected = array('PluginJs', 'TestPlugin', 'TestPluginTwo'); $this->assertEquals($expected, CakePlugin::loaded()); $this->assertEquals('loaded js plugin bootstrap', Configure::read('CakePluginTest.js_plugin.bootstrap'));