7 require_once 'application/PluginManager.php';
10 * Unit tests for Plugins
12 class PluginManagerTest
extends PHPUnit_Framework_TestCase
15 * Path to tests plugin.
16 * @var string $pluginPath
18 private static $pluginPath = 'tests/plugins';
22 * @var string $pluginName
24 private static $pluginName = 'test';
27 * @var PluginManager $pluginManager Plugin Mananger instance.
29 protected $pluginManager;
31 public function setUp()
33 $conf = new ConfigManager('');
34 $this->pluginManager
= new PluginManager($conf);
38 * Test plugin loading and hook execution.
42 public function testPlugin()
44 PluginManager
::$PLUGINS_PATH = self
::$pluginPath;
45 $this->pluginManager
->load(array(self
::$pluginName));
47 $this->assertTrue(function_exists('hook_test_random'));
49 $data = array(0 => 'woot');
50 $this->pluginManager
->executeHooks('random', $data);
51 $this->assertEquals('woot', $data[1]);
53 $data = array(0 => 'woot');
54 $this->pluginManager
->executeHooks('random', $data, array('target' => 'test'));
55 $this->assertEquals('page test', $data[1]);
57 $data = array(0 => 'woot');
58 $this->pluginManager
->executeHooks('random', $data, array('loggedin' => true));
59 $this->assertEquals('loggedin', $data[1]);
63 * Test missing plugin loading.
67 public function testPluginNotFound()
69 $this->pluginManager
->load(array());
70 $this->pluginManager
->load(array('nope', 'renope'));
74 * Test plugin metadata loading.
76 public function testGetPluginsMeta()
78 PluginManager
::$PLUGINS_PATH = self
::$pluginPath;
79 $this->pluginManager
->load(array(self
::$pluginName));
81 $expectedParameters = array(
85 $meta = $this->pluginManager
->getPluginsMeta();
86 $this->assertEquals('test plugin', $meta[self
::$pluginName]['description']);
87 $this->assertEquals($expectedParameters, $meta[self
::$pluginName]['parameters']);