Browse Source

Plugin::loadAll() should also read the config file.

When using loadAll() to load plugins, plugins defined in the path config
file should be loaded.
Mark Story 11 years ago
parent
commit
7eea3893e1
2 changed files with 29 additions and 6 deletions
  1. 17 6
      src/Core/Plugin.php
  2. 12 0
      tests/TestCase/Core/PluginTest.php

+ 17 - 6
src/Core/Plugin.php

@@ -120,12 +120,7 @@ class Plugin
             return;
         }
 
-        if (!Configure::check('plugins')) {
-            try {
-                Configure::load('plugins');
-            } catch (\Exception $e) {
-            }
-        }
+        static::_loadConfig();
 
         $config += [
             'autoload' => false,
@@ -181,6 +176,17 @@ class Plugin
         }
     }
 
+    protected static function _loadConfig()
+    {
+        if (Configure::check('plugins')) {
+            return;
+        }
+        try {
+            Configure::load('plugins');
+        } catch (\Exception $e) {
+        }
+    }
+
     /**
      * Will load all the plugins located in the default plugin folder.
      *
@@ -204,6 +210,7 @@ class Plugin
      */
     public static function loadAll(array $options = [])
     {
+        static::_loadConfig();
         $plugins = [];
         foreach (App::path('Plugin') as $path) {
             if (!is_dir($path)) {
@@ -216,6 +223,10 @@ class Plugin
                 }
             }
         }
+        if (Configure::check('plugins')) {
+            $plugins = array_merge($plugins, array_keys(Configure::read('plugins')));
+            $plugins = array_unique($plugins);
+        }
 
         foreach ($plugins as $p) {
             $opts = isset($options[$p]) ? $options[$p] : null;

+ 12 - 0
tests/TestCase/Core/PluginTest.php

@@ -283,6 +283,18 @@ class PluginTest extends TestCase
     }
 
     /**
+     * Test loadAll() with path configuration data
+     *
+     * @return void
+     */
+    public function testLoadAllWithPathConfig()
+    {
+        Configure::write('plugins.FakePlugin', APP);
+        Plugin::loadAll();
+        $this->assertContains('FakePlugin', Plugin::loaded());
+    }
+
+    /**
      * Test that plugins don't reload using loadAll();
      *
      * @return void