Browse Source

Make CakePlugin::loadAll behave correctly regarding merging of settings.

euromark 12 years ago
parent
commit
9058f0f6f1
2 changed files with 23 additions and 5 deletions
  1. 3 3
      lib/Cake/Core/CakePlugin.php
  2. 20 2
      lib/Cake/Test/Case/Core/CakePluginTest.php

+ 3 - 3
lib/Cake/Core/CakePlugin.php

@@ -121,9 +121,9 @@ class CakePlugin {
 	public static function loadAll($options = array()) {
 		$plugins = App::objects('plugins');
 		foreach ($plugins as $p) {
-			$opts = isset($options[$p]) ? $options[$p] : null;
-			if ($opts === null && isset($options[0])) {
-				$opts = $options[0];
+			$opts = isset($options[$p]) ? $options[$p] : array();
+			if (isset($options[0])) {
+				$opts += $options[0];
 			}
 			self::load($p, (array)$opts);
 		}

+ 20 - 2
lib/Cake/Test/Case/Core/CakePluginTest.php

@@ -253,8 +253,8 @@ class CakePluginTest extends CakeTestCase {
 	}
 
 /**
- * Tests that CakePlugin::loadAll() will load all plugins in the configured folder wit defaults
- * and overrides for a plugin
+ * Tests that CakePlugin::loadAll() will load all plugins in the configured folder with defaults
+ * and merges in global defaults.
  *
  * @return void
  */
@@ -266,6 +266,24 @@ class CakePluginTest extends CakeTestCase {
 		$this->assertEquals($expected, CakePlugin::loaded());
 		$this->assertEquals('loaded js plugin bootstrap', Configure::read('CakePluginTest.js_plugin.bootstrap'));
 		$this->assertEquals('loaded plugin routes', Configure::read('CakePluginTest.test_plugin.routes'));
+		$this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
+		$this->assertEquals('loaded plugin two bootstrap', Configure::read('CakePluginTest.test_plugin_two.bootstrap'));
+	}
+
+/**
+ * Tests that CakePlugin::loadAll() will load all plugins in the configured folder with defaults
+ * and overrides for a plugin
+ *
+ * @return void
+ */
+	public function testLoadAllWithDefaultsAndOverrideComplex() {
+		CakePlugin::loadAll(array(array('bootstrap' => true), 'TestPlugin' => array('routes' => true, 'bootstrap' => false)));
+		CakePlugin::routes();
+
+		$expected = array('PluginJs', 'TestPlugin', 'TestPluginTwo');
+		$this->assertEquals($expected, CakePlugin::loaded());
+		$this->assertEquals('loaded js plugin bootstrap', Configure::read('CakePluginTest.js_plugin.bootstrap'));
+		$this->assertEquals('loaded plugin routes', Configure::read('CakePluginTest.test_plugin.routes'));
 		$this->assertEquals(null, Configure::read('CakePluginTest.test_plugin.bootstrap'));
 		$this->assertEquals('loaded plugin two bootstrap', Configure::read('CakePluginTest.test_plugin_two.bootstrap'));
 	}