]>
Commit | Line | Data |
---|---|---|
6fc14d53 A |
1 | <?php |
2 | ||
3 | /** | |
4 | * Plugin Manager tests | |
5 | */ | |
6 | ||
7 | require_once 'application/PluginManager.php'; | |
8 | ||
9 | /** | |
10 | * Unit tests for Plugins | |
11 | */ | |
12 | class PluginManagerTest extends PHPUnit_Framework_TestCase | |
13 | { | |
14 | /** | |
15 | * Path to tests plugin. | |
d06265fb | 16 | * @var string $pluginPath |
6fc14d53 | 17 | */ |
d06265fb | 18 | private static $pluginPath = 'tests/plugins'; |
6fc14d53 A |
19 | |
20 | /** | |
21 | * Test plugin. | |
d06265fb | 22 | * @var string $pluginName |
6fc14d53 | 23 | */ |
d06265fb | 24 | private static $pluginName = 'test'; |
6fc14d53 | 25 | |
51def0d8 A |
26 | /** |
27 | * @var PluginManager $pluginManager Plugin Mananger instance. | |
28 | */ | |
29 | protected $pluginManager; | |
30 | ||
31 | public function setUp() | |
32 | { | |
33 | $conf = new ConfigManager(''); | |
34 | $this->pluginManager = new PluginManager($conf); | |
35 | } | |
36 | ||
6fc14d53 A |
37 | /** |
38 | * Test plugin loading and hook execution. | |
39 | * | |
40 | * @return void | |
41 | */ | |
42 | public function testPlugin() | |
43 | { | |
d06265fb | 44 | PluginManager::$PLUGINS_PATH = self::$pluginPath; |
51def0d8 | 45 | $this->pluginManager->load(array(self::$pluginName)); |
6fc14d53 A |
46 | |
47 | $this->assertTrue(function_exists('hook_test_random')); | |
48 | ||
49 | $data = array(0 => 'woot'); | |
51def0d8 | 50 | $this->pluginManager->executeHooks('random', $data); |
6fc14d53 A |
51 | $this->assertEquals('woot', $data[1]); |
52 | ||
53 | $data = array(0 => 'woot'); | |
51def0d8 | 54 | $this->pluginManager->executeHooks('random', $data, array('target' => 'test')); |
6fc14d53 A |
55 | $this->assertEquals('page test', $data[1]); |
56 | ||
57 | $data = array(0 => 'woot'); | |
51def0d8 | 58 | $this->pluginManager->executeHooks('random', $data, array('loggedin' => true)); |
6fc14d53 A |
59 | $this->assertEquals('loggedin', $data[1]); |
60 | } | |
61 | ||
62 | /** | |
63 | * Test missing plugin loading. | |
64 | * | |
65 | * @return void | |
66 | */ | |
67 | public function testPluginNotFound() | |
68 | { | |
51def0d8 A |
69 | $this->pluginManager->load(array()); |
70 | $this->pluginManager->load(array('nope', 'renope')); | |
6fc14d53 | 71 | } |
dea0ba28 A |
72 | |
73 | /** | |
74 | * Test plugin metadata loading. | |
75 | */ | |
76 | public function testGetPluginsMeta() | |
77 | { | |
dea0ba28 | 78 | PluginManager::$PLUGINS_PATH = self::$pluginPath; |
51def0d8 | 79 | $this->pluginManager->load(array(self::$pluginName)); |
dea0ba28 A |
80 | |
81 | $expectedParameters = array( | |
15170b51 A |
82 | 'pop' => array( |
83 | 'value' => '', | |
84 | 'desc' => 'pop description', | |
85 | ), | |
86 | 'hip' => array( | |
87 | 'value' => '', | |
88 | 'desc' => '', | |
89 | ), | |
dea0ba28 | 90 | ); |
51def0d8 | 91 | $meta = $this->pluginManager->getPluginsMeta(); |
dea0ba28 A |
92 | $this->assertEquals('test plugin', $meta[self::$pluginName]['description']); |
93 | $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']); | |
94 | } | |
db6dec0d | 95 | } |