aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/PluginManagerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/PluginManagerTest.php')
-rw-r--r--tests/PluginManagerTest.php51
1 files changed, 33 insertions, 18 deletions
diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php
index a5d5dbe9..efef5e87 100644
--- a/tests/PluginManagerTest.php
+++ b/tests/PluginManagerTest.php
@@ -1,4 +1,5 @@
1<?php 1<?php
2
2namespace Shaarli\Plugin; 3namespace Shaarli\Plugin;
3 4
4use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
@@ -6,7 +7,7 @@ use Shaarli\Config\ConfigManager;
6/** 7/**
7 * Unit tests for Plugins 8 * Unit tests for Plugins
8 */ 9 */
9class PluginManagerTest extends \PHPUnit\Framework\TestCase 10class PluginManagerTest extends \Shaarli\TestCase
10{ 11{
11 /** 12 /**
12 * Path to tests plugin. 13 * Path to tests plugin.
@@ -41,17 +42,31 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase
41 42
42 $this->assertTrue(function_exists('hook_test_random')); 43 $this->assertTrue(function_exists('hook_test_random'));
43 44
44 $data = array(0 => 'woot'); 45 $data = [0 => 'woot'];
45 $this->pluginManager->executeHooks('random', $data); 46 $this->pluginManager->executeHooks('random', $data);
46 $this->assertEquals('woot', $data[1]);
47 47
48 $data = array(0 => 'woot'); 48 static::assertCount(2, $data);
49 static::assertSame('woot', $data[1]);
50
51 $data = [0 => 'woot'];
49 $this->pluginManager->executeHooks('random', $data, array('target' => 'test')); 52 $this->pluginManager->executeHooks('random', $data, array('target' => 'test'));
50 $this->assertEquals('page test', $data[1]);
51 53
52 $data = array(0 => 'woot'); 54 static::assertCount(2, $data);
55 static::assertSame('page test', $data[1]);
56
57 $data = [0 => 'woot'];
53 $this->pluginManager->executeHooks('random', $data, array('loggedin' => true)); 58 $this->pluginManager->executeHooks('random', $data, array('loggedin' => true));
54 $this->assertEquals('loggedin', $data[1]); 59
60 static::assertCount(2, $data);
61 static::assertEquals('loggedin', $data[1]);
62
63 $data = [0 => 'woot'];
64 $this->pluginManager->executeHooks('random', $data, array('loggedin' => null));
65
66 static::assertCount(3, $data);
67 static::assertEquals('loggedin', $data[1]);
68 static::assertArrayHasKey(2, $data);
69 static::assertNull($data[2]);
55 } 70 }
56 71
57 /** 72 /**
@@ -67,8 +82,8 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase
67 $data = []; 82 $data = [];
68 $this->pluginManager->executeHooks('error', $data); 83 $this->pluginManager->executeHooks('error', $data);
69 84
70 $this->assertSame( 85 $this->assertRegExp(
71 'test [plugin incompatibility]: Class \'Unknown\' not found', 86 '/test \[plugin incompatibility\]: Class [\'"]Unknown[\'"] not found/',
72 $this->pluginManager->getErrors()[0] 87 $this->pluginManager->getErrors()[0]
73 ); 88 );
74 } 89 }
@@ -78,8 +93,8 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase
78 */ 93 */
79 public function testPluginNotFound(): void 94 public function testPluginNotFound(): void
80 { 95 {
81 $this->pluginManager->load(array()); 96 $this->pluginManager->load([]);
82 $this->pluginManager->load(array('nope', 'renope')); 97 $this->pluginManager->load(['nope', 'renope']);
83 $this->addToAssertionCount(1); 98 $this->addToAssertionCount(1);
84 } 99 }
85 100
@@ -89,18 +104,18 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase
89 public function testGetPluginsMeta(): void 104 public function testGetPluginsMeta(): void
90 { 105 {
91 PluginManager::$PLUGINS_PATH = self::$pluginPath; 106 PluginManager::$PLUGINS_PATH = self::$pluginPath;
92 $this->pluginManager->load(array(self::$pluginName)); 107 $this->pluginManager->load([self::$pluginName]);
93 108
94 $expectedParameters = array( 109 $expectedParameters = [
95 'pop' => array( 110 'pop' => [
96 'value' => '', 111 'value' => '',
97 'desc' => 'pop description', 112 'desc' => 'pop description',
98 ), 113 ],
99 'hip' => array( 114 'hip' => [
100 'value' => '', 115 'value' => '',
101 'desc' => '', 116 'desc' => '',
102 ), 117 ],
103 ); 118 ];
104 $meta = $this->pluginManager->getPluginsMeta(); 119 $meta = $this->pluginManager->getPluginsMeta();
105 $this->assertEquals('test plugin', $meta[self::$pluginName]['description']); 120 $this->assertEquals('test plugin', $meta[self::$pluginName]['description']);
106 $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']); 121 $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']);