]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/PluginManagerTest.php
Merge pull request #619 from ArthurHoaro/plugins/param-desc
[github/shaarli/Shaarli.git] / tests / PluginManagerTest.php
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.
16 * @var string $pluginPath
17 */
18 private static $pluginPath = 'tests/plugins';
19
20 /**
21 * Test plugin.
22 * @var string $pluginName
23 */
24 private static $pluginName = 'test';
25
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
37 /**
38 * Test plugin loading and hook execution.
39 *
40 * @return void
41 */
42 public function testPlugin()
43 {
44 PluginManager::$PLUGINS_PATH = self::$pluginPath;
45 $this->pluginManager->load(array(self::$pluginName));
46
47 $this->assertTrue(function_exists('hook_test_random'));
48
49 $data = array(0 => 'woot');
50 $this->pluginManager->executeHooks('random', $data);
51 $this->assertEquals('woot', $data[1]);
52
53 $data = array(0 => 'woot');
54 $this->pluginManager->executeHooks('random', $data, array('target' => 'test'));
55 $this->assertEquals('page test', $data[1]);
56
57 $data = array(0 => 'woot');
58 $this->pluginManager->executeHooks('random', $data, array('loggedin' => true));
59 $this->assertEquals('loggedin', $data[1]);
60 }
61
62 /**
63 * Test missing plugin loading.
64 *
65 * @return void
66 */
67 public function testPluginNotFound()
68 {
69 $this->pluginManager->load(array());
70 $this->pluginManager->load(array('nope', 'renope'));
71 }
72
73 /**
74 * Test plugin metadata loading.
75 */
76 public function testGetPluginsMeta()
77 {
78 PluginManager::$PLUGINS_PATH = self::$pluginPath;
79 $this->pluginManager->load(array(self::$pluginName));
80
81 $expectedParameters = array(
82 'pop' => array(
83 'value' => '',
84 'desc' => 'pop description',
85 ),
86 'hip' => array(
87 'value' => '',
88 'desc' => '',
89 ),
90 );
91 $meta = $this->pluginManager->getPluginsMeta();
92 $this->assertEquals('test plugin', $meta[self::$pluginName]['description']);
93 $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']);
94 }
95 }