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