]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - tests/PluginManagerTest.php
Run Unit Tests against PHP 7.4
[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.
6fc14d53
A
61 */
62 public function testPluginNotFound()
63 {
51def0d8
A
64 $this->pluginManager->load(array());
65 $this->pluginManager->load(array('nope', 'renope'));
def39d0d 66 $this->addToAssertionCount(1);
6fc14d53 67 }
dea0ba28
A
68
69 /**
70 * Test plugin metadata loading.
71 */
72 public function testGetPluginsMeta()
73 {
dea0ba28 74 PluginManager::$PLUGINS_PATH = self::$pluginPath;
51def0d8 75 $this->pluginManager->load(array(self::$pluginName));
dea0ba28
A
76
77 $expectedParameters = array(
15170b51
A
78 'pop' => array(
79 'value' => '',
80 'desc' => 'pop description',
81 ),
82 'hip' => array(
83 'value' => '',
84 'desc' => '',
85 ),
dea0ba28 86 );
51def0d8 87 $meta = $this->pluginManager->getPluginsMeta();
dea0ba28
A
88 $this->assertEquals('test plugin', $meta[self::$pluginName]['description']);
89 $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']);
90 }
db6dec0d 91}