mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Implementing CakePlugin::loadAll()
This commit is contained in:
parent
f6a5df913a
commit
27a134de4f
2 changed files with 66 additions and 0 deletions
|
@ -79,6 +79,31 @@ class CakePlugin {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Will load all the plugins located in the configured plugins folders
|
||||
* If passed an options array, it will be used as a common default for all plugins to be loaded
|
||||
* It is possible to set specific defaults for each plugins in the options array. Examples:
|
||||
*
|
||||
* {{{
|
||||
* CakePlugin::loadAll(array(
|
||||
* array('bootstrap' => true),
|
||||
* 'DebugKit' => array('routes' => true),
|
||||
* ))
|
||||
* }}}
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
public function loadAll($options = array()) {
|
||||
$plugins = App::objects('plugins');
|
||||
foreach ($plugins as $p) {
|
||||
$opts = isset($options[$p]) ? $options[$p] : $options;
|
||||
self::load($p, $opts);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filesystem path for a plugin
|
||||
|
|
|
@ -198,6 +198,47 @@ class CakePluginTest extends CakeTestCase {
|
|||
CakePlugin::path('TestPlugin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that CakePlugin::loadAll() will load all plgins in the configured folder
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadAll() {
|
||||
CakePlugin::loadAll();
|
||||
$expected = array('PluginJs', 'TestPlugin', 'TestPluginTwo');
|
||||
$this->assertEquals($expected, CakePlugin::loaded());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that CakePlugin::loadAll() will load all plgins in the configured folder with bootstrap loading
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadAllWithDefaults() {
|
||||
CakePlugin::loadAll(array('bootstrap' => true));
|
||||
$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 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 plgins in the configured folder wit defaults
|
||||
* and overrides for a plugin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadAllWithDefaultsAndOverride() {
|
||||
CakePlugin::loadAll(array('bootstrap' => true, 'TestPlugin' => array('routes' => true)));
|
||||
$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(null, Configure::read('CakePluginTest.test_plugin.bootstrap'));
|
||||
$this->assertEquals('loaded plugin two bootstrap', Configure::read('CakePluginTest.test_plugin_two.bootstrap'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Auxiliary function to test plugin bootstrap callbacks
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue