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