diff options
author | ArthurHoaro <arthur@hoa.ro> | 2015-07-15 11:42:15 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2015-11-07 15:27:17 +0100 |
commit | 6fc14d530369740d27d6bd641369d4f5f5f04080 (patch) | |
tree | 2da553378e8f0ff367dcb677d6f519d1fb3e803c /tests/PluginManagerTest.php | |
parent | 38bedfbbcdd2a40e9f04f5753e0fd6f4fd513c21 (diff) | |
download | Shaarli-6fc14d530369740d27d6bd641369d4f5f5f04080.tar.gz Shaarli-6fc14d530369740d27d6bd641369d4f5f5f04080.tar.zst Shaarli-6fc14d530369740d27d6bd641369d4f5f5f04080.zip |
Plugin system - CORE
see shaarli/Shaarli#275
Diffstat (limited to 'tests/PluginManagerTest.php')
-rwxr-xr-x | tests/PluginManagerTest.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php new file mode 100755 index 00000000..749ce2b5 --- /dev/null +++ b/tests/PluginManagerTest.php | |||
@@ -0,0 +1,66 @@ | |||
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 $_PLUGIN_PATH | ||
17 | */ | ||
18 | private static $_PLUGIN_PATH = 'tests/plugins'; | ||
19 | |||
20 | /** | ||
21 | * Test plugin. | ||
22 | * @var string $_PLUGIN_NAME | ||
23 | */ | ||
24 | private static $_PLUGIN_NAME = '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::$_PLUGIN_PATH; | ||
36 | $pluginManager->load(array(self::$_PLUGIN_NAME)); | ||
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 | } \ No newline at end of file | ||