2 namespace Shaarli\Plugin
;
4 use Shaarli\Config\ConfigManager
;
7 * Unit tests for Plugins
9 class PluginManagerTest
extends \PHPUnit\Framework\TestCase
12 * Path to tests plugin.
13 * @var string $pluginPath
15 private static $pluginPath = 'tests/plugins';
19 * @var string $pluginName
21 private static $pluginName = 'test';
24 * @var PluginManager $pluginManager Plugin Mananger instance.
26 protected $pluginManager;
28 public function setUp()
30 $conf = new ConfigManager('');
31 $this->pluginManager
= new PluginManager($conf);
35 * Test plugin loading and hook execution.
39 public function testPlugin()
41 PluginManager
::$PLUGINS_PATH = self
::$pluginPath;
42 $this->pluginManager
->load(array(self
::$pluginName));
44 $this->assertTrue(function_exists('hook_test_random'));
46 $data = array(0 => 'woot');
47 $this->pluginManager
->executeHooks('random', $data);
48 $this->assertEquals('woot', $data[1]);
50 $data = array(0 => 'woot');
51 $this->pluginManager
->executeHooks('random', $data, array('target' => 'test'));
52 $this->assertEquals('page test', $data[1]);
54 $data = array(0 => 'woot');
55 $this->pluginManager
->executeHooks('random', $data, array('loggedin' => true));
56 $this->assertEquals('loggedin', $data[1]);
60 * Test missing plugin loading.
62 public function testPluginNotFound()
64 $this->pluginManager
->load(array());
65 $this->pluginManager
->load(array('nope', 'renope'));
66 $this->addToAssertionCount(1);
70 * Test plugin metadata loading.
72 public function testGetPluginsMeta()
74 PluginManager
::$PLUGINS_PATH = self
::$pluginPath;
75 $this->pluginManager
->load(array(self
::$pluginName));
77 $expectedParameters = array(
80 'desc' => 'pop description',
87 $meta = $this->pluginManager
->getPluginsMeta();
88 $this->assertEquals('test plugin', $meta[self
::$pluginName]['description']);
89 $this->assertEquals($expectedParameters, $meta[self
::$pluginName]['parameters']);