]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - tests/PluginManagerTest.php
Optimize and cleanup imports
[github/shaarli/Shaarli.git] / tests / PluginManagerTest.php
CommitLineData
6fc14d53 1<?php
e1850388 2namespace Shaarli\Plugin;
6fc14d53 3
e1850388 4use Shaarli\Config\ConfigManager;
6fc14d53
A
5
6/**
7 * Unit tests for Plugins
8 */
e1850388 9class PluginManagerTest extends \PHPUnit\Framework\TestCase
6fc14d53
A
10{
11 /**
12 * Path to tests plugin.
d06265fb 13 * @var string $pluginPath
6fc14d53 14 */
d06265fb 15 private static $pluginPath = 'tests/plugins';
6fc14d53
A
16
17 /**
18 * Test plugin.
d06265fb 19 * @var string $pluginName
6fc14d53 20 */
d06265fb 21 private static $pluginName = 'test';
6fc14d53 22
51def0d8
A
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
6fc14d53
A
34 /**
35 * Test plugin loading and hook execution.
36 *
37 * @return void
38 */
39 public function testPlugin()
40 {
d06265fb 41 PluginManager::$PLUGINS_PATH = self::$pluginPath;
51def0d8 42 $this->pluginManager->load(array(self::$pluginName));
6fc14d53
A
43
44 $this->assertTrue(function_exists('hook_test_random'));
45
46 $data = array(0 => 'woot');
51def0d8 47 $this->pluginManager->executeHooks('random', $data);
6fc14d53
A
48 $this->assertEquals('woot', $data[1]);
49
50 $data = array(0 => 'woot');
51def0d8 51 $this->pluginManager->executeHooks('random', $data, array('target' => 'test'));
6fc14d53
A
52 $this->assertEquals('page test', $data[1]);
53
54 $data = array(0 => 'woot');
51def0d8 55 $this->pluginManager->executeHooks('random', $data, array('loggedin' => true));
6fc14d53
A
56 $this->assertEquals('loggedin', $data[1]);
57 }
58
59 /**
60 * Test missing plugin loading.
61 *
62 * @return void
63 */
64 public function testPluginNotFound()
65 {
51def0d8
A
66 $this->pluginManager->load(array());
67 $this->pluginManager->load(array('nope', 'renope'));
6fc14d53 68 }
dea0ba28
A
69
70 /**
71 * Test plugin metadata loading.
72 */
73 public function testGetPluginsMeta()
74 {
dea0ba28 75 PluginManager::$PLUGINS_PATH = self::$pluginPath;
51def0d8 76 $this->pluginManager->load(array(self::$pluginName));
dea0ba28
A
77
78 $expectedParameters = array(
15170b51
A
79 'pop' => array(
80 'value' => '',
81 'desc' => 'pop description',
82 ),
83 'hip' => array(
84 'value' => '',
85 'desc' => '',
86 ),
dea0ba28 87 );
51def0d8 88 $meta = $this->pluginManager->getPluginsMeta();
dea0ba28
A
89 $this->assertEquals('test plugin', $meta[self::$pluginName]['description']);
90 $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']);
91 }
db6dec0d 92}