From 4478f82c1217fbac3e48290bec40dfe365ce4b78 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Sun, 24 Jun 2012 17:28:57 -0400 Subject: [PATCH] Fixed the load of plugins with custom namespace. Tests added --- lib/Cake/Core/Plugin.php | 5 +++ .../Company/TestPluginThree/Utility/Hello.php | 32 +++++++++++++++++++ lib/Cake/Test/TestCase/Core/PluginTest.php | 20 ++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 lib/Cake/Test/TestApp/Plugin2/Company/TestPluginThree/Utility/Hello.php diff --git a/lib/Cake/Core/Plugin.php b/lib/Cake/Core/Plugin.php index 79a41f41efd..990b630d8a0 100644 --- a/lib/Cake/Core/Plugin.php +++ b/lib/Cake/Core/Plugin.php @@ -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; diff --git a/lib/Cake/Test/TestApp/Plugin2/Company/TestPluginThree/Utility/Hello.php b/lib/Cake/Test/TestApp/Plugin2/Company/TestPluginThree/Utility/Hello.php new file mode 100644 index 00000000000..c3c820aea8d --- /dev/null +++ b/lib/Cake/Test/TestApp/Plugin2/Company/TestPluginThree/Utility/Hello.php @@ -0,0 +1,32 @@ + + * 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'; + } + +} diff --git a/lib/Cake/Test/TestCase/Core/PluginTest.php b/lib/Cake/Test/TestCase/Core/PluginTest.php index 7b61ae7c62e..1a4a1484395 100644 --- a/lib/Cake/Test/TestCase/Core/PluginTest.php +++ b/lib/Cake/Test/TestCase/Core/PluginTest.php @@ -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 *