2 use Shaarli\Config\ConfigManager
;
8 require_once 'application/PluginManager.php';
11 * Unit tests for Plugins
13 class PluginManagerTest
extends PHPUnit_Framework_TestCase
16 * Path to tests plugin.
17 * @var string $pluginPath
19 private static $pluginPath = 'tests/plugins';
23 * @var string $pluginName
25 private static $pluginName = 'test';
28 * @var PluginManager $pluginManager Plugin Mananger instance.
30 protected $pluginManager;
32 public function setUp()
34 $conf = new ConfigManager('');
35 $this->pluginManager
= new PluginManager($conf);
39 * Test plugin loading and hook execution.
43 public function testPlugin()
45 PluginManager
::$PLUGINS_PATH = self
::$pluginPath;
46 $this->pluginManager
->load(array(self
::$pluginName));
48 $this->assertTrue(function_exists('hook_test_random'));
50 $data = array(0 => 'woot');
51 $this->pluginManager
->executeHooks('random', $data);
52 $this->assertEquals('woot', $data[1]);
54 $data = array(0 => 'woot');
55 $this->pluginManager
->executeHooks('random', $data, array('target' => 'test'));
56 $this->assertEquals('page test', $data[1]);
58 $data = array(0 => 'woot');
59 $this->pluginManager
->executeHooks('random', $data, array('loggedin' => true));
60 $this->assertEquals('loggedin', $data[1]);
64 * Test missing plugin loading.
68 public function testPluginNotFound()
70 $this->pluginManager
->load(array());
71 $this->pluginManager
->load(array('nope', 'renope'));
75 * Test plugin metadata loading.
77 public function testGetPluginsMeta()
79 PluginManager
::$PLUGINS_PATH = self
::$pluginPath;
80 $this->pluginManager
->load(array(self
::$pluginName));
82 $expectedParameters = array(
85 'desc' => 'pop description',
92 $meta = $this->pluginManager
->getPluginsMeta();
93 $this->assertEquals('test plugin', $meta[self
::$pluginName]['description']);
94 $this->assertEquals($expectedParameters, $meta[self
::$pluginName]['parameters']);