Skip to content

Commit

Permalink
Improving CakePlugin::loaded() to accept a plugin name as first param…
Browse files Browse the repository at this point in the history
…eter
  • Loading branch information
lorenzo committed May 9, 2011
1 parent 2093b11 commit 2fab0b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 8 additions & 3 deletions lib/Cake/Core/CakePlugin.php
Expand Up @@ -163,11 +163,16 @@ public static function routes($plugin) {
}

/**
* 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);
}

Expand Down
12 changes: 4 additions & 8 deletions lib/Cake/tests/Case/Core/CakePluginTest.php
Expand Up @@ -69,8 +69,7 @@ public function testUnload() {
*/
public function testLoadSingleWithBootstrap() {
CakePlugin::load('TestPlugin', array('bootstrap' => true));
$expected = array('TestPlugin');
$this->assertEquals($expected, CakePlugin::loaded());
$this->assertTrue(CakePlugin::loaded('TestPlugin'));
$this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
}

Expand All @@ -81,8 +80,7 @@ public function testLoadSingleWithBootstrap() {
*/
public function testLoadSingleWithBootstrapAndRoutes() {
CakePlugin::load('TestPlugin', array('bootstrap' => true, 'routes' => true));
$expected = array('TestPlugin');
$this->assertEquals($expected, CakePlugin::loaded());
$this->assertTrue(CakePlugin::loaded('TestPlugin'));
$this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
$this->assertEquals('loaded plugin routes', Configure::read('CakePluginTest.test_plugin.routes'));
}
Expand Down Expand Up @@ -134,8 +132,7 @@ public function testLoadMultipleWithDefaultsAndOverride() {
*/
public function testMultipleBootstrapFiles() {
CakePlugin::load('TestPlugin', array('bootstrap' => array('bootstrap', 'custom_config')));
$expected = array('TestPlugin');
$this->assertEquals($expected, CakePlugin::loaded());
$this->assertTrue(CakePlugin::loaded('TestPlugin'));
$this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
}

Expand All @@ -147,8 +144,7 @@ public function testMultipleBootstrapFiles() {
*/
public function testCallbackBootstrap() {
CakePlugin::load('TestPlugin', array('bootstrap' => array($this, 'pluginBootstrap')));
$expected = array('TestPlugin');
$this->assertEquals($expected, CakePlugin::loaded());
$this->assertTrue(CakePlugin::loaded('TestPlugin'));
$this->assertEquals('called plugin bootstrap callback', Configure::read('CakePluginTest.test_plugin.bootstrap'));
}

Expand Down

0 comments on commit 2fab0b0

Please sign in to comment.