aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/PluginManagerTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-08-27 12:04:36 +0200
committerArthurHoaro <arthur@hoa.ro>2020-08-27 12:04:36 +0200
commit7e3dc0ba98bf019c2804e5c74fb6061b16fb712f (patch)
treef0a333e9e009d78d59c1e4823f766625bc2bb255 /tests/PluginManagerTest.php
parentaf41d5ab5d2bd3ba64d052c997bc6afa6966a63c (diff)
downloadShaarli-7e3dc0ba98bf019c2804e5c74fb6061b16fb712f.tar.gz
Shaarli-7e3dc0ba98bf019c2804e5c74fb6061b16fb712f.tar.zst
Shaarli-7e3dc0ba98bf019c2804e5c74fb6061b16fb712f.zip
Better handling of plugin incompatibility
If a PHP is raised while executing plugin hook, Shaarli will display an error instead of rendering the error page (or just ending in fatal error for default hooks). Also added phpErrorHandler which is handled differently that regular errorHandler by Slim.:
Diffstat (limited to 'tests/PluginManagerTest.php')
-rw-r--r--tests/PluginManagerTest.php29
1 files changed, 23 insertions, 6 deletions
diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php
index 195d959c..a5d5dbe9 100644
--- a/tests/PluginManagerTest.php
+++ b/tests/PluginManagerTest.php
@@ -25,7 +25,7 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase
25 */ 25 */
26 protected $pluginManager; 26 protected $pluginManager;
27 27
28 public function setUp() 28 public function setUp(): void
29 { 29 {
30 $conf = new ConfigManager(''); 30 $conf = new ConfigManager('');
31 $this->pluginManager = new PluginManager($conf); 31 $this->pluginManager = new PluginManager($conf);
@@ -33,10 +33,8 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase
33 33
34 /** 34 /**
35 * Test plugin loading and hook execution. 35 * Test plugin loading and hook execution.
36 *
37 * @return void
38 */ 36 */
39 public function testPlugin() 37 public function testPlugin(): void
40 { 38 {
41 PluginManager::$PLUGINS_PATH = self::$pluginPath; 39 PluginManager::$PLUGINS_PATH = self::$pluginPath;
42 $this->pluginManager->load(array(self::$pluginName)); 40 $this->pluginManager->load(array(self::$pluginName));
@@ -57,9 +55,28 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase
57 } 55 }
58 56
59 /** 57 /**
58 * Test plugin loading and hook execution with an error: raise an incompatibility error.
59 */
60 public function testPluginWithPhpError(): void
61 {
62 PluginManager::$PLUGINS_PATH = self::$pluginPath;
63 $this->pluginManager->load(array(self::$pluginName));
64
65 $this->assertTrue(function_exists('hook_test_error'));
66
67 $data = [];
68 $this->pluginManager->executeHooks('error', $data);
69
70 $this->assertSame(
71 'test [plugin incompatibility]: Class \'Unknown\' not found',
72 $this->pluginManager->getErrors()[0]
73 );
74 }
75
76 /**
60 * Test missing plugin loading. 77 * Test missing plugin loading.
61 */ 78 */
62 public function testPluginNotFound() 79 public function testPluginNotFound(): void
63 { 80 {
64 $this->pluginManager->load(array()); 81 $this->pluginManager->load(array());
65 $this->pluginManager->load(array('nope', 'renope')); 82 $this->pluginManager->load(array('nope', 'renope'));
@@ -69,7 +86,7 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase
69 /** 86 /**
70 * Test plugin metadata loading. 87 * Test plugin metadata loading.
71 */ 88 */
72 public function testGetPluginsMeta() 89 public function testGetPluginsMeta(): void
73 { 90 {
74 PluginManager::$PLUGINS_PATH = self::$pluginPath; 91 PluginManager::$PLUGINS_PATH = self::$pluginPath;
75 $this->pluginManager->load(array(self::$pluginName)); 92 $this->pluginManager->load(array(self::$pluginName));