mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Improving CakePlugin::loaded() to accept a plugin name as first parameter
This commit is contained in:
parent
2093b11296
commit
2fab0b0e1c
2 changed files with 12 additions and 11 deletions
|
@ -163,11 +163,16 @@ class CakePlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all loaded plugins
|
* Retruns true if the plugin $plugin is already loaded
|
||||||
|
* If plugin is null, it will return a list of all loaded plugins
|
||||||
*
|
*
|
||||||
* @return array list of plugins that have been loaded
|
* @return mixed boolean true if $plugin is already loaded.
|
||||||
|
* If $plugin is null, returns a list of plugins that have been loaded
|
||||||
*/
|
*/
|
||||||
public static function loaded() {
|
public static function loaded($plugin = null) {
|
||||||
|
if ($plugin) {
|
||||||
|
return isset(self::$_plugins[$plugin]);
|
||||||
|
}
|
||||||
return array_keys(self::$_plugins);
|
return array_keys(self::$_plugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,8 +69,7 @@ class CakePluginTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testLoadSingleWithBootstrap() {
|
public function testLoadSingleWithBootstrap() {
|
||||||
CakePlugin::load('TestPlugin', array('bootstrap' => true));
|
CakePlugin::load('TestPlugin', array('bootstrap' => true));
|
||||||
$expected = array('TestPlugin');
|
$this->assertTrue(CakePlugin::loaded('TestPlugin'));
|
||||||
$this->assertEquals($expected, CakePlugin::loaded());
|
|
||||||
$this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
|
$this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,8 +80,7 @@ class CakePluginTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testLoadSingleWithBootstrapAndRoutes() {
|
public function testLoadSingleWithBootstrapAndRoutes() {
|
||||||
CakePlugin::load('TestPlugin', array('bootstrap' => true, 'routes' => true));
|
CakePlugin::load('TestPlugin', array('bootstrap' => true, 'routes' => true));
|
||||||
$expected = array('TestPlugin');
|
$this->assertTrue(CakePlugin::loaded('TestPlugin'));
|
||||||
$this->assertEquals($expected, CakePlugin::loaded());
|
|
||||||
$this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
|
$this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
|
||||||
$this->assertEquals('loaded plugin routes', Configure::read('CakePluginTest.test_plugin.routes'));
|
$this->assertEquals('loaded plugin routes', Configure::read('CakePluginTest.test_plugin.routes'));
|
||||||
}
|
}
|
||||||
|
@ -134,8 +132,7 @@ class CakePluginTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testMultipleBootstrapFiles() {
|
public function testMultipleBootstrapFiles() {
|
||||||
CakePlugin::load('TestPlugin', array('bootstrap' => array('bootstrap', 'custom_config')));
|
CakePlugin::load('TestPlugin', array('bootstrap' => array('bootstrap', 'custom_config')));
|
||||||
$expected = array('TestPlugin');
|
$this->assertTrue(CakePlugin::loaded('TestPlugin'));
|
||||||
$this->assertEquals($expected, CakePlugin::loaded());
|
|
||||||
$this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
|
$this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,8 +144,7 @@ class CakePluginTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testCallbackBootstrap() {
|
public function testCallbackBootstrap() {
|
||||||
CakePlugin::load('TestPlugin', array('bootstrap' => array($this, 'pluginBootstrap')));
|
CakePlugin::load('TestPlugin', array('bootstrap' => array($this, 'pluginBootstrap')));
|
||||||
$expected = array('TestPlugin');
|
$this->assertTrue(CakePlugin::loaded('TestPlugin'));
|
||||||
$this->assertEquals($expected, CakePlugin::loaded());
|
|
||||||
$this->assertEquals('called plugin bootstrap callback', Configure::read('CakePluginTest.test_plugin.bootstrap'));
|
$this->assertEquals('called plugin bootstrap callback', Configure::read('CakePluginTest.test_plugin.bootstrap'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue