diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-08-27 12:04:36 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-08-27 12:04:36 +0200 |
commit | 7e3dc0ba98bf019c2804e5c74fb6061b16fb712f (patch) | |
tree | f0a333e9e009d78d59c1e4823f766625bc2bb255 /tests | |
parent | af41d5ab5d2bd3ba64d052c997bc6afa6966a63c (diff) | |
download | Shaarli-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')
-rw-r--r-- | tests/PluginManagerTest.php | 29 | ||||
-rw-r--r-- | tests/container/ContainerBuilderTest.php | 23 | ||||
-rw-r--r-- | tests/plugins/test/test.php | 5 |
3 files changed, 42 insertions, 15 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)); |
diff --git a/tests/container/ContainerBuilderTest.php b/tests/container/ContainerBuilderTest.php index fa77bf31..c08010ae 100644 --- a/tests/container/ContainerBuilderTest.php +++ b/tests/container/ContainerBuilderTest.php | |||
@@ -9,6 +9,7 @@ use Shaarli\Bookmark\BookmarkServiceInterface; | |||
9 | use Shaarli\Config\ConfigManager; | 9 | use Shaarli\Config\ConfigManager; |
10 | use Shaarli\Feed\FeedBuilder; | 10 | use Shaarli\Feed\FeedBuilder; |
11 | use Shaarli\Formatter\FormatterFactory; | 11 | use Shaarli\Formatter\FormatterFactory; |
12 | use Shaarli\Front\Controller\Visitor\ErrorController; | ||
12 | use Shaarli\History; | 13 | use Shaarli\History; |
13 | use Shaarli\Http\HttpAccess; | 14 | use Shaarli\Http\HttpAccess; |
14 | use Shaarli\Netscape\NetscapeBookmarkUtils; | 15 | use Shaarli\Netscape\NetscapeBookmarkUtils; |
@@ -20,6 +21,7 @@ use Shaarli\Security\LoginManager; | |||
20 | use Shaarli\Security\SessionManager; | 21 | use Shaarli\Security\SessionManager; |
21 | use Shaarli\Thumbnailer; | 22 | use Shaarli\Thumbnailer; |
22 | use Shaarli\Updater\Updater; | 23 | use Shaarli\Updater\Updater; |
24 | use Slim\Http\Environment; | ||
23 | 25 | ||
24 | class ContainerBuilderTest extends TestCase | 26 | class ContainerBuilderTest extends TestCase |
25 | { | 27 | { |
@@ -59,20 +61,23 @@ class ContainerBuilderTest extends TestCase | |||
59 | { | 61 | { |
60 | $container = $this->containerBuilder->build(); | 62 | $container = $this->containerBuilder->build(); |
61 | 63 | ||
62 | static::assertInstanceOf(ConfigManager::class, $container->conf); | 64 | static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService); |
63 | static::assertInstanceOf(SessionManager::class, $container->sessionManager); | ||
64 | static::assertInstanceOf(CookieManager::class, $container->cookieManager); | 65 | static::assertInstanceOf(CookieManager::class, $container->cookieManager); |
65 | static::assertInstanceOf(LoginManager::class, $container->loginManager); | 66 | static::assertInstanceOf(ConfigManager::class, $container->conf); |
67 | static::assertInstanceOf(ErrorController::class, $container->errorHandler); | ||
68 | static::assertInstanceOf(Environment::class, $container->environment); | ||
69 | static::assertInstanceOf(FeedBuilder::class, $container->feedBuilder); | ||
70 | static::assertInstanceOf(FormatterFactory::class, $container->formatterFactory); | ||
66 | static::assertInstanceOf(History::class, $container->history); | 71 | static::assertInstanceOf(History::class, $container->history); |
67 | static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService); | 72 | static::assertInstanceOf(HttpAccess::class, $container->httpAccess); |
73 | static::assertInstanceOf(LoginManager::class, $container->loginManager); | ||
74 | static::assertInstanceOf(NetscapeBookmarkUtils::class, $container->netscapeBookmarkUtils); | ||
68 | static::assertInstanceOf(PageBuilder::class, $container->pageBuilder); | 75 | static::assertInstanceOf(PageBuilder::class, $container->pageBuilder); |
69 | static::assertInstanceOf(PluginManager::class, $container->pluginManager); | ||
70 | static::assertInstanceOf(FormatterFactory::class, $container->formatterFactory); | ||
71 | static::assertInstanceOf(PageCacheManager::class, $container->pageCacheManager); | 76 | static::assertInstanceOf(PageCacheManager::class, $container->pageCacheManager); |
72 | static::assertInstanceOf(FeedBuilder::class, $container->feedBuilder); | 77 | static::assertInstanceOf(ErrorController::class, $container->phpErrorHandler); |
78 | static::assertInstanceOf(PluginManager::class, $container->pluginManager); | ||
79 | static::assertInstanceOf(SessionManager::class, $container->sessionManager); | ||
73 | static::assertInstanceOf(Thumbnailer::class, $container->thumbnailer); | 80 | static::assertInstanceOf(Thumbnailer::class, $container->thumbnailer); |
74 | static::assertInstanceOf(HttpAccess::class, $container->httpAccess); | ||
75 | static::assertInstanceOf(NetscapeBookmarkUtils::class, $container->netscapeBookmarkUtils); | ||
76 | static::assertInstanceOf(Updater::class, $container->updater); | 81 | static::assertInstanceOf(Updater::class, $container->updater); |
77 | 82 | ||
78 | // Set by the middleware | 83 | // Set by the middleware |
diff --git a/tests/plugins/test/test.php b/tests/plugins/test/test.php index 2aaf5122..ae5032dd 100644 --- a/tests/plugins/test/test.php +++ b/tests/plugins/test/test.php | |||
@@ -19,3 +19,8 @@ function hook_test_random($data) | |||
19 | 19 | ||
20 | return $data; | 20 | return $data; |
21 | } | 21 | } |
22 | |||
23 | function hook_test_error() | ||
24 | { | ||
25 | new Unknown(); | ||
26 | } | ||