]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/PluginManagerTest.php
Unit tests for Router and PluginManager.
[github/shaarli/Shaarli.git] / tests / PluginManagerTest.php
1 <?php
2
3 /**
4 * Plugin Manager tests
5 */
6
7 require_once 'application/PluginManager.php';
8
9 /**
10 * Unit tests for Plugins
11 */
12 class PluginManagerTest extends PHPUnit_Framework_TestCase
13 {
14 /**
15 * Path to tests plugin.
16 * @var string $pluginPath
17 */
18 private static $pluginPath = 'tests/plugins';
19
20 /**
21 * Test plugin.
22 * @var string $pluginName
23 */
24 private static $pluginName = 'test';
25
26 /**
27 * Test plugin loading and hook execution.
28 *
29 * @return void
30 */
31 public function testPlugin()
32 {
33 $pluginManager = PluginManager::getInstance();
34
35 PluginManager::$PLUGINS_PATH = self::$pluginPath;
36 $pluginManager->load(array(self::$pluginName));
37
38 $this->assertTrue(function_exists('hook_test_random'));
39
40 $data = array(0 => 'woot');
41 $pluginManager->executeHooks('random', $data);
42 $this->assertEquals('woot', $data[1]);
43
44 $data = array(0 => 'woot');
45 $pluginManager->executeHooks('random', $data, array('target' => 'test'));
46 $this->assertEquals('page test', $data[1]);
47
48 $data = array(0 => 'woot');
49 $pluginManager->executeHooks('random', $data, array('loggedin' => true));
50 $this->assertEquals('loggedin', $data[1]);
51 }
52
53 /**
54 * Test missing plugin loading.
55 *
56 * @return void
57 */
58 public function testPluginNotFound()
59 {
60 $pluginManager = PluginManager::getInstance();
61
62 $pluginManager->load(array());
63
64 $pluginManager->load(array('nope', 'renope'));
65 }
66 }