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