Make CakePlugin::loadAll behave correctly regarding merging of settings.

This commit is contained in:
euromark 2014-04-08 12:18:17 +02:00
parent debdc6bccc
commit 9058f0f6f1
2 changed files with 23 additions and 5 deletions

View file

@ -121,9 +121,9 @@ class CakePlugin {
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);
}

View file

@ -253,8 +253,8 @@ class CakePluginTest extends CakeTestCase {
}
/**
* 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 @@ class CakePluginTest extends CakeTestCase {
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'));