Merge pull request #3261 from dereuromark/2.5-load-all

2.5 load all
This commit is contained in:
Mark Story 2014-04-08 10:28:43 -04:00
commit 879d0d4369
2 changed files with 27 additions and 9 deletions

View file

@ -108,12 +108,12 @@ class CakePlugin {
* {{{
* CakePlugin::loadAll(array(
* array('bootstrap' => true),
* 'DebugKit' => array('routes' => true),
* 'DebugKit' => array('routes' => true, 'bootstrap' => false),
* ))
* }}}
*
* The above example will load the bootstrap file for all plugins, but for DebugKit it will only load the routes file
* and will not look for any bootstrap script.
* The above example will load the bootstrap file for all plugins, but for DebugKit it will only load
* the routes file and will not look for any bootstrap script.
*
* @param array $options
* @return void
@ -121,11 +121,11 @@ 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]) ? (array)$options[$p] : array();
if (isset($options[0])) {
$opts += $options[0];
}
self::load($p, (array)$opts);
self::load($p, $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'));