Skip to content

Commit

Permalink
Make CakePlugin::loadAll behave correctly regarding merging of settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Apr 8, 2014
1 parent debdc6b commit 9058f0f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/Cake/Core/CakePlugin.php
Expand Up @@ -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);
}
Expand Down
22 changes: 20 additions & 2 deletions lib/Cake/Test/Case/Core/CakePluginTest.php
Expand Up @@ -253,15 +253,33 @@ 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
*/
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'));
Expand Down

0 comments on commit 9058f0f

Please sign in to comment.