Skip to content

Commit

Permalink
Fixed the load of plugins with custom namespace. Tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Jun 24, 2012
1 parent 40be3df commit 4478f82
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Cake/Core/Plugin.php
Expand Up @@ -80,11 +80,16 @@ public static function load($plugin, $config = array()) {
}
$config += array('bootstrap' => false, 'routes' => false, 'namespace' => $plugin);
if (empty($config['path'])) {
$namespacePath = str_replace('\\', DS, $config['namespace']);
foreach (App::path('Plugin') as $path) {
if (is_dir($path . $plugin)) {
static::$_plugins[$plugin] = $config + array('path' => $path . $plugin . DS);
break;
}
if ($plugin !== $config['namespace'] && is_dir($path . $namespacePath)) {
static::$_plugins[$plugin] = $config + array('path' => $path . $namespacePath . DS);
break;
}
}
} else {
static::$_plugins[$plugin] = $config;
Expand Down
@@ -0,0 +1,32 @@
<?php
/**
* Test class for plugins with multiple namespace levels
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.TestApp.Plugin.TestPlugin.Lib.Cache.Engine
* @since CakePHP(tm) v 3.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Company\TestPluginThree\Utility;

class Hello {

/**
* foo method
*
* @return string
*/
public function foo() {
return 'bar';
}

}
20 changes: 20 additions & 0 deletions lib/Cake/Test/TestCase/Core/PluginTest.php
Expand Up @@ -51,6 +51,26 @@ public function tearDown() {
Plugin::unload();
}

/**
* Test the plugin namespace
*
* @return void
*/
public function testGetNamespace() {
Plugin::load('TestPlugin');
$this->assertEquals('TestPlugin', Plugin::getNamespace('TestPlugin'));

App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'TestApp' . DS . 'Plugin2' . DS)
), App::RESET);

Plugin::load('TestPluginThree', array('namespace' => 'Company\TestPluginThree'));
$this->assertEquals('Company\TestPluginThree', Plugin::getNamespace('TestPluginThree'));

Plugin::load('CustomPlugin', array('namespace' => 'Company\TestPluginThree'));
$this->assertEquals('Company\TestPluginThree', Plugin::getNamespace('CustomPlugin'));
}

/**
* Tests loading a single plugin
*
Expand Down

0 comments on commit 4478f82

Please sign in to comment.