Browse Source

Use backslash in plugin name when loading.

ADmad 11 years ago
parent
commit
555d941a40
2 changed files with 11 additions and 12 deletions
  1. 2 3
      src/Core/Plugin.php
  2. 9 9
      tests/TestCase/Core/PluginTest.php

+ 2 - 3
src/Core/Plugin.php

@@ -97,7 +97,6 @@ class Plugin {
  *
  * - `bootstrap` - array - Whether or not you want the $plugin/config/bootstrap.php file loaded.
  * - `routes` - boolean - Whether or not you want to load the $plugin/config/routes.php file.
- * - `namespace` - string - A custom namespace for the plugin. It will default to the plugin name.
  * - `ignoreMissing` - boolean - Set to true to ignore missing bootstrap/routes files.
  * - `path` - string - The path the plugin can be found on. If empty the default plugin path (App.pluginPaths) will be used.
  * - `classBase` - The path relative to `path` which contains the folders with class files.
@@ -124,7 +123,7 @@ class Plugin {
 			'autoload' => false,
 			'bootstrap' => false,
 			'routes' => false,
-			'namespace' => str_replace('/', '\\', $plugin),
+			'namespace' => $plugin,
 			'classBase' => 'src',
 			'ignoreMissing' => false
 		];
@@ -132,7 +131,7 @@ class Plugin {
 			$paths = App::path('Plugin');
 			foreach ($paths as $path) {
 				$namespacePath = str_replace('\\', DS, $config['namespace']);
-				$pluginPath = str_replace('/', DS, $plugin);
+				$pluginPath = str_replace('\\', DS, $plugin);
 				if (is_dir($path . $pluginPath)) {
 					$config += ['path' => $path . $pluginPath . DS];
 					break;

+ 9 - 9
tests/TestCase/Core/PluginTest.php

@@ -55,8 +55,8 @@ class PluginTest extends TestCase {
 
 		$this->assertEquals('TestPluginTwo', Plugin::getNamespace('TestPluginTwo'));
 
-		Plugin::load('Company/TestPluginThree');
-		$this->assertEquals('Company\TestPluginThree', Plugin::getNamespace('Company/TestPluginThree'));
+		Plugin::load('Company\TestPluginThree');
+		$this->assertEquals('Company\TestPluginThree', Plugin::getNamespace('Company\TestPluginThree'));
 
 		Plugin::load('CustomPlugin', array('namespace' => 'Company\TestPluginThree'));
 		$this->assertEquals('Company\TestPluginThree', Plugin::getNamespace('CustomPlugin'));
@@ -102,7 +102,7 @@ class PluginTest extends TestCase {
  */
 	public function testLoadSingleWithAutoload() {
 		$this->assertFalse(class_exists('Company\TestPluginThree\Utility\Hello'));
-		Plugin::load('Company/TestPluginThree', [
+		Plugin::load('Company\TestPluginThree', [
 			'autoload' => true,
 		]);
 		$this->assertTrue(
@@ -121,8 +121,8 @@ class PluginTest extends TestCase {
 		$this->assertTrue(Plugin::loaded('TestPlugin'));
 		$this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
 
-		Plugin::load('Company/TestPluginThree', array('bootstrap' => true));
-		$this->assertTrue(Plugin::loaded('Company/TestPluginThree'));
+		Plugin::load('Company\TestPluginThree', array('bootstrap' => true));
+		$this->assertTrue(Plugin::loaded('Company\TestPluginThree'));
 		$this->assertEquals('loaded plugin three bootstrap', Configure::read('PluginTest.test_plugin_three.bootstrap'));
 
 		Configure::delete('PluginTest.test_plugin_three.bootstrap');
@@ -226,7 +226,7 @@ class PluginTest extends TestCase {
  * @return void
  */
 	public function testPath() {
-		Plugin::load(array('TestPlugin', 'TestPluginTwo', 'Company/TestPluginThree'));
+		Plugin::load(array('TestPlugin', 'TestPluginTwo', 'Company\TestPluginThree'));
 		$expected = TEST_APP . 'Plugin' . DS . 'TestPlugin' . DS;
 		$this->assertPathEquals(Plugin::path('TestPlugin'), $expected);
 
@@ -234,7 +234,7 @@ class PluginTest extends TestCase {
 		$this->assertPathEquals(Plugin::path('TestPluginTwo'), $expected);
 
 		$expected = TEST_APP . 'Plugin' . DS . 'Company' . DS . 'TestPluginThree' . DS;
-		$this->assertPathEquals(Plugin::path('Company/TestPluginThree'), $expected);
+		$this->assertPathEquals(Plugin::path('Company\TestPluginThree'), $expected);
 	}
 
 /**
@@ -253,7 +253,7 @@ class PluginTest extends TestCase {
  * @return void
  */
 	public function testClassPath() {
-		Plugin::load(array('TestPlugin', 'TestPluginTwo', 'Company/TestPluginThree'));
+		Plugin::load(array('TestPlugin', 'TestPluginTwo', 'Company\TestPluginThree'));
 		$expected = TEST_APP . 'Plugin' . DS . 'TestPlugin' . DS . 'src' . DS;
 		$this->assertPathEquals(Plugin::classPath('TestPlugin'), $expected);
 
@@ -261,7 +261,7 @@ class PluginTest extends TestCase {
 		$this->assertPathEquals(Plugin::classPath('TestPluginTwo'), $expected);
 
 		$expected = TEST_APP . 'Plugin' . DS . 'Company' . DS . 'TestPluginThree' . DS . 'src' . DS;
-		$this->assertPathEquals(Plugin::classPath('Company/TestPluginThree'), $expected);
+		$this->assertPathEquals(Plugin::classPath('Company\TestPluginThree'), $expected);
 	}
 
 /**