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 | |
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.:
-rw-r--r-- | application/container/ContainerBuilder.php | 3 | ||||
-rw-r--r-- | application/container/ShaarliContainer.php | 4 | ||||
-rw-r--r-- | application/front/controller/visitor/ShaarliVisitorController.php | 3 | ||||
-rw-r--r-- | application/plugin/PluginManager.php | 7 | ||||
-rw-r--r-- | inc/languages/fr/LC_MESSAGES/shaarli.po | 66 | ||||
-rw-r--r-- | tests/PluginManagerTest.php | 29 | ||||
-rw-r--r-- | tests/container/ContainerBuilderTest.php | 23 | ||||
-rw-r--r-- | tests/plugins/test/test.php | 5 |
8 files changed, 90 insertions, 50 deletions
diff --git a/application/container/ContainerBuilder.php b/application/container/ContainerBuilder.php index 4a1a6ea7..58067c99 100644 --- a/application/container/ContainerBuilder.php +++ b/application/container/ContainerBuilder.php | |||
@@ -152,6 +152,9 @@ class ContainerBuilder | |||
152 | $container['errorHandler'] = function (ShaarliContainer $container): ErrorController { | 152 | $container['errorHandler'] = function (ShaarliContainer $container): ErrorController { |
153 | return new ErrorController($container); | 153 | return new ErrorController($container); |
154 | }; | 154 | }; |
155 | $container['phpErrorHandler'] = function (ShaarliContainer $container): ErrorController { | ||
156 | return new ErrorController($container); | ||
157 | }; | ||
155 | 158 | ||
156 | return $container; | 159 | return $container; |
157 | } | 160 | } |
diff --git a/application/container/ShaarliContainer.php b/application/container/ShaarliContainer.php index c4fe753e..9a9a974a 100644 --- a/application/container/ShaarliContainer.php +++ b/application/container/ShaarliContainer.php | |||
@@ -4,7 +4,6 @@ declare(strict_types=1); | |||
4 | 4 | ||
5 | namespace Shaarli\Container; | 5 | namespace Shaarli\Container; |
6 | 6 | ||
7 | use http\Cookie; | ||
8 | use Shaarli\Bookmark\BookmarkServiceInterface; | 7 | use Shaarli\Bookmark\BookmarkServiceInterface; |
9 | use Shaarli\Config\ConfigManager; | 8 | use Shaarli\Config\ConfigManager; |
10 | use Shaarli\Feed\FeedBuilder; | 9 | use Shaarli\Feed\FeedBuilder; |
@@ -30,7 +29,7 @@ use Slim\Container; | |||
30 | * @property CookieManager $cookieManager | 29 | * @property CookieManager $cookieManager |
31 | * @property ConfigManager $conf | 30 | * @property ConfigManager $conf |
32 | * @property mixed[] $environment $_SERVER automatically injected by Slim | 31 | * @property mixed[] $environment $_SERVER automatically injected by Slim |
33 | * @property callable $errorHandler Overrides default Slim error display | 32 | * @property callable $errorHandler Overrides default Slim exception display |
34 | * @property FeedBuilder $feedBuilder | 33 | * @property FeedBuilder $feedBuilder |
35 | * @property FormatterFactory $formatterFactory | 34 | * @property FormatterFactory $formatterFactory |
36 | * @property History $history | 35 | * @property History $history |
@@ -39,6 +38,7 @@ use Slim\Container; | |||
39 | * @property NetscapeBookmarkUtils $netscapeBookmarkUtils | 38 | * @property NetscapeBookmarkUtils $netscapeBookmarkUtils |
40 | * @property PageBuilder $pageBuilder | 39 | * @property PageBuilder $pageBuilder |
41 | * @property PageCacheManager $pageCacheManager | 40 | * @property PageCacheManager $pageCacheManager |
41 | * @property callable $phpErrorHandler Overrides default Slim PHP error display | ||
42 | * @property PluginManager $pluginManager | 42 | * @property PluginManager $pluginManager |
43 | * @property SessionManager $sessionManager | 43 | * @property SessionManager $sessionManager |
44 | * @property Thumbnailer $thumbnailer | 44 | * @property Thumbnailer $thumbnailer |
diff --git a/application/front/controller/visitor/ShaarliVisitorController.php b/application/front/controller/visitor/ShaarliVisitorController.php index 47057d97..f17c8ed3 100644 --- a/application/front/controller/visitor/ShaarliVisitorController.php +++ b/application/front/controller/visitor/ShaarliVisitorController.php | |||
@@ -58,10 +58,11 @@ abstract class ShaarliVisitorController | |||
58 | { | 58 | { |
59 | $this->assignView('linkcount', $this->container->bookmarkService->count(BookmarkFilter::$ALL)); | 59 | $this->assignView('linkcount', $this->container->bookmarkService->count(BookmarkFilter::$ALL)); |
60 | $this->assignView('privateLinkcount', $this->container->bookmarkService->count(BookmarkFilter::$PRIVATE)); | 60 | $this->assignView('privateLinkcount', $this->container->bookmarkService->count(BookmarkFilter::$PRIVATE)); |
61 | $this->assignView('plugin_errors', $this->container->pluginManager->getErrors()); | ||
62 | 61 | ||
63 | $this->executeDefaultHooks($template); | 62 | $this->executeDefaultHooks($template); |
64 | 63 | ||
64 | $this->assignView('plugin_errors', $this->container->pluginManager->getErrors()); | ||
65 | |||
65 | return $this->container->pageBuilder->render($template, $this->container->basePath); | 66 | return $this->container->pageBuilder->render($template, $this->container->basePath); |
66 | } | 67 | } |
67 | 68 | ||
diff --git a/application/plugin/PluginManager.php b/application/plugin/PluginManager.php index b3e8b2f8..2d93cb3a 100644 --- a/application/plugin/PluginManager.php +++ b/application/plugin/PluginManager.php | |||
@@ -116,7 +116,12 @@ class PluginManager | |||
116 | $hookFunction = $this->buildHookName($hook, $plugin); | 116 | $hookFunction = $this->buildHookName($hook, $plugin); |
117 | 117 | ||
118 | if (function_exists($hookFunction)) { | 118 | if (function_exists($hookFunction)) { |
119 | $data = call_user_func($hookFunction, $data, $this->conf); | 119 | try { |
120 | $data = call_user_func($hookFunction, $data, $this->conf); | ||
121 | } catch (\Throwable $e) { | ||
122 | $error = $plugin . t(' [plugin incompatibility]: ') . $e->getMessage(); | ||
123 | $this->errors = array_unique(array_merge($this->errors, [$error])); | ||
124 | } | ||
120 | } | 125 | } |
121 | } | 126 | } |
122 | } | 127 | } |
diff --git a/inc/languages/fr/LC_MESSAGES/shaarli.po b/inc/languages/fr/LC_MESSAGES/shaarli.po index fda0e62f..fbb2fe64 100644 --- a/inc/languages/fr/LC_MESSAGES/shaarli.po +++ b/inc/languages/fr/LC_MESSAGES/shaarli.po | |||
@@ -1,15 +1,15 @@ | |||
1 | msgid "" | 1 | msgid "" |
2 | msgstr "" | 2 | msgstr "" |
3 | "Project-Id-Version: Shaarli\n" | 3 | "Project-Id-Version: Shaarli\n" |
4 | "POT-Creation-Date: 2020-07-23 17:11+0200\n" | 4 | "POT-Creation-Date: 2020-08-27 12:01+0200\n" |
5 | "PO-Revision-Date: 2020-07-23 17:12+0200\n" | 5 | "PO-Revision-Date: 2020-08-27 12:02+0200\n" |
6 | "Last-Translator: \n" | 6 | "Last-Translator: \n" |
7 | "Language-Team: Shaarli\n" | 7 | "Language-Team: Shaarli\n" |
8 | "Language: fr_FR\n" | 8 | "Language: fr_FR\n" |
9 | "MIME-Version: 1.0\n" | 9 | "MIME-Version: 1.0\n" |
10 | "Content-Type: text/plain; charset=UTF-8\n" | 10 | "Content-Type: text/plain; charset=UTF-8\n" |
11 | "Content-Transfer-Encoding: 8bit\n" | 11 | "Content-Transfer-Encoding: 8bit\n" |
12 | "X-Generator: Poedit 2.0.6\n" | 12 | "X-Generator: Poedit 2.3\n" |
13 | "X-Poedit-Basepath: ../../../..\n" | 13 | "X-Poedit-Basepath: ../../../..\n" |
14 | "Plural-Forms: nplurals=2; plural=(n > 1);\n" | 14 | "Plural-Forms: nplurals=2; plural=(n > 1);\n" |
15 | "X-Poedit-SourceCharset: UTF-8\n" | 15 | "X-Poedit-SourceCharset: UTF-8\n" |
@@ -103,36 +103,36 @@ msgstr "Mo" | |||
103 | msgid "GiB" | 103 | msgid "GiB" |
104 | msgstr "Go" | 104 | msgstr "Go" |
105 | 105 | ||
106 | #: application/bookmark/BookmarkFileService.php:161 | 106 | #: application/bookmark/BookmarkFileService.php:165 |
107 | #: application/bookmark/BookmarkFileService.php:186 | 107 | #: application/bookmark/BookmarkFileService.php:190 |
108 | #: application/bookmark/BookmarkFileService.php:211 | 108 | #: application/bookmark/BookmarkFileService.php:215 |
109 | #: application/bookmark/BookmarkFileService.php:228 | 109 | #: application/bookmark/BookmarkFileService.php:232 |
110 | msgid "You're not authorized to alter the datastore" | 110 | msgid "You're not authorized to alter the datastore" |
111 | msgstr "Vous n'êtes pas autorisé à modifier les données" | 111 | msgstr "Vous n'êtes pas autorisé à modifier les données" |
112 | 112 | ||
113 | #: application/bookmark/BookmarkFileService.php:164 | 113 | #: application/bookmark/BookmarkFileService.php:168 |
114 | #: application/bookmark/BookmarkFileService.php:189 | 114 | #: application/bookmark/BookmarkFileService.php:193 |
115 | #: application/bookmark/BookmarkFileService.php:231 | 115 | #: application/bookmark/BookmarkFileService.php:235 |
116 | msgid "Provided data is invalid" | 116 | msgid "Provided data is invalid" |
117 | msgstr "Les informations fournies ne sont pas valides" | 117 | msgstr "Les informations fournies ne sont pas valides" |
118 | 118 | ||
119 | #: application/bookmark/BookmarkFileService.php:192 | 119 | #: application/bookmark/BookmarkFileService.php:196 |
120 | msgid "This bookmarks already exists" | 120 | msgid "This bookmarks already exists" |
121 | msgstr "Ce marque-page existe déjà." | 121 | msgstr "Ce marque-page existe déjà." |
122 | 122 | ||
123 | #: application/bookmark/BookmarkInitializer.php:40 | 123 | #: application/bookmark/BookmarkInitializer.php:37 |
124 | #: application/legacy/LegacyLinkDB.php:266 | 124 | #: application/legacy/LegacyLinkDB.php:266 |
125 | msgid "My secret stuff... - Pastebin.com" | 125 | msgid "My secret stuff... - Pastebin.com" |
126 | msgstr "Mes trucs secrets... - Pastebin.com" | 126 | msgstr "Mes trucs secrets... - Pastebin.com" |
127 | 127 | ||
128 | #: application/bookmark/BookmarkInitializer.php:42 | 128 | #: application/bookmark/BookmarkInitializer.php:39 |
129 | #: application/legacy/LegacyLinkDB.php:268 | 129 | #: application/legacy/LegacyLinkDB.php:268 |
130 | msgid "Shhhh! I'm a private link only YOU can see. You can delete me too." | 130 | msgid "Shhhh! I'm a private link only YOU can see. You can delete me too." |
131 | msgstr "" | 131 | msgstr "" |
132 | "Pssst ! Je suis un lien privé que VOUS êtes le seul à voir. Vous pouvez me " | 132 | "Pssst ! Je suis un lien privé que VOUS êtes le seul à voir. Vous pouvez me " |
133 | "supprimer aussi." | 133 | "supprimer aussi." |
134 | 134 | ||
135 | #: application/bookmark/BookmarkInitializer.php:48 | 135 | #: application/bookmark/BookmarkInitializer.php:45 |
136 | #: application/legacy/LegacyLinkDB.php:246 | 136 | #: application/legacy/LegacyLinkDB.php:246 |
137 | #: tmp/page.footer.b91ef64efc3688266305ea9b42e5017e.rtpl.php:15 | 137 | #: tmp/page.footer.b91ef64efc3688266305ea9b42e5017e.rtpl.php:15 |
138 | #: tmp/page.footer.b91ef64efc3688266305ea9b42e5017e.rtpl.php:49 | 138 | #: tmp/page.footer.b91ef64efc3688266305ea9b42e5017e.rtpl.php:49 |
@@ -144,7 +144,7 @@ msgstr "" | |||
144 | "Le gestionnaire de marque-pages personnel, minimaliste, et sans base de " | 144 | "Le gestionnaire de marque-pages personnel, minimaliste, et sans base de " |
145 | "données" | 145 | "données" |
146 | 146 | ||
147 | #: application/bookmark/BookmarkInitializer.php:51 | 147 | #: application/bookmark/BookmarkInitializer.php:48 |
148 | #: application/legacy/LegacyLinkDB.php:249 | 148 | #: application/legacy/LegacyLinkDB.php:249 |
149 | msgid "" | 149 | msgid "" |
150 | "Welcome to Shaarli! This is your first public bookmark. To edit or delete " | 150 | "Welcome to Shaarli! This is your first public bookmark. To edit or delete " |
@@ -210,10 +210,6 @@ msgstr "Liens directs" | |||
210 | msgid "Permalink" | 210 | msgid "Permalink" |
211 | msgstr "Permalien" | 211 | msgstr "Permalien" |
212 | 212 | ||
213 | #: application/front/ShaarliMiddleware.php:78 | ||
214 | msgid "An unexpected error occurred." | ||
215 | msgstr "Une erreur inattendue s'est produite." | ||
216 | |||
217 | #: application/front/controller/admin/ConfigureController.php:54 | 213 | #: application/front/controller/admin/ConfigureController.php:54 |
218 | #: tmp/configure.b91ef64efc3688266305ea9b42e5017e.rtpl.php:24 | 214 | #: tmp/configure.b91ef64efc3688266305ea9b42e5017e.rtpl.php:24 |
219 | msgid "Configure" | 215 | msgid "Configure" |
@@ -230,7 +226,7 @@ msgid "Please synchronize them." | |||
230 | msgstr "Merci de les synchroniser." | 226 | msgstr "Merci de les synchroniser." |
231 | 227 | ||
232 | #: application/front/controller/admin/ConfigureController.php:113 | 228 | #: application/front/controller/admin/ConfigureController.php:113 |
233 | #: application/front/controller/visitor/InstallController.php:137 | 229 | #: application/front/controller/visitor/InstallController.php:136 |
234 | msgid "Error while writing config file after configuration update." | 230 | msgid "Error while writing config file after configuration update." |
235 | msgstr "" | 231 | msgstr "" |
236 | "Une erreur s'est produite lors de la sauvegarde du fichier de configuration." | 232 | "Une erreur s'est produite lors de la sauvegarde du fichier de configuration." |
@@ -373,7 +369,7 @@ msgstr "Mise à jour des miniatures" | |||
373 | msgid "Tools" | 369 | msgid "Tools" |
374 | msgstr "Outils" | 370 | msgstr "Outils" |
375 | 371 | ||
376 | #: application/front/controller/visitor/BookmarkListController.php:114 | 372 | #: application/front/controller/visitor/BookmarkListController.php:115 |
377 | msgid "Search: " | 373 | msgid "Search: " |
378 | msgstr "Recherche : " | 374 | msgstr "Recherche : " |
379 | 375 | ||
@@ -385,13 +381,17 @@ msgstr "Aujourd'hui" | |||
385 | msgid "Yesterday" | 381 | msgid "Yesterday" |
386 | msgstr "Hier" | 382 | msgstr "Hier" |
387 | 383 | ||
388 | #: application/front/controller/visitor/DailyController.php:86 | 384 | #: application/front/controller/visitor/DailyController.php:85 |
389 | #: tmp/page.header.b91ef64efc3688266305ea9b42e5017e.rtpl.php:48 | 385 | #: tmp/page.header.b91ef64efc3688266305ea9b42e5017e.rtpl.php:48 |
390 | #: tmp/page.header.cedf684561d925457130839629000a81.rtpl.php:48 | 386 | #: tmp/page.header.cedf684561d925457130839629000a81.rtpl.php:48 |
391 | msgid "Daily" | 387 | msgid "Daily" |
392 | msgstr "Quotidien" | 388 | msgstr "Quotidien" |
393 | 389 | ||
394 | #: application/front/controller/visitor/InstallController.php:74 | 390 | #: application/front/controller/visitor/ErrorController.php:36 |
391 | msgid "An unexpected error occurred." | ||
392 | msgstr "Une erreur inattendue s'est produite." | ||
393 | |||
394 | #: application/front/controller/visitor/InstallController.php:73 | ||
395 | #, php-format | 395 | #, php-format |
396 | msgid "" | 396 | msgid "" |
397 | "<pre>Sessions do not seem to work correctly on your server.<br>Make sure the " | 397 | "<pre>Sessions do not seem to work correctly on your server.<br>Make sure the " |
@@ -410,14 +410,14 @@ msgstr "" | |||
410 | "des cookies. Nous vous recommandons d'accéder à votre serveur depuis son " | 410 | "des cookies. Nous vous recommandons d'accéder à votre serveur depuis son " |
411 | "adresse IP ou un <em>Fully Qualified Domain Name</em>.<br>" | 411 | "adresse IP ou un <em>Fully Qualified Domain Name</em>.<br>" |
412 | 412 | ||
413 | #: application/front/controller/visitor/InstallController.php:149 | 413 | #: application/front/controller/visitor/InstallController.php:144 |
414 | msgid "" | 414 | msgid "" |
415 | "Shaarli is now configured. Please login and start shaaring your bookmarks!" | 415 | "Shaarli is now configured. Please login and start shaaring your bookmarks!" |
416 | msgstr "" | 416 | msgstr "" |
417 | "Shaarli est maintenant configuré. Vous pouvez vous connecter et commencez à " | 417 | "Shaarli est maintenant configuré. Vous pouvez vous connecter et commencez à " |
418 | "shaare vos liens !" | 418 | "shaare vos liens !" |
419 | 419 | ||
420 | #: application/front/controller/visitor/InstallController.php:163 | 420 | #: application/front/controller/visitor/InstallController.php:158 |
421 | msgid "Insufficient permissions:" | 421 | msgid "Insufficient permissions:" |
422 | msgstr "Permissions insuffisantes :" | 422 | msgstr "Permissions insuffisantes :" |
423 | 423 | ||
@@ -441,7 +441,7 @@ msgstr "Nom d'utilisateur ou mot de passe incorrect(s)." | |||
441 | msgid "Picture wall" | 441 | msgid "Picture wall" |
442 | msgstr "Mur d'images" | 442 | msgstr "Mur d'images" |
443 | 443 | ||
444 | #: application/front/controller/visitor/TagCloudController.php:82 | 444 | #: application/front/controller/visitor/TagCloudController.php:80 |
445 | #, fuzzy | 445 | #, fuzzy |
446 | #| msgid "Tag list" | 446 | #| msgid "Tag list" |
447 | msgid "Tag " | 447 | msgid "Tag " |
@@ -519,6 +519,10 @@ msgstr "" | |||
519 | "a été importé avec succès en %d secondes : %d liens importés, %d liens " | 519 | "a été importé avec succès en %d secondes : %d liens importés, %d liens " |
520 | "écrasés, %d liens ignorés." | 520 | "écrasés, %d liens ignorés." |
521 | 521 | ||
522 | #: application/plugin/PluginManager.php:122 | ||
523 | msgid " [plugin incompatibility]: " | ||
524 | msgstr " [incompatibilité de l'extension] : " | ||
525 | |||
522 | #: application/plugin/exception/PluginFileNotFoundException.php:21 | 526 | #: application/plugin/exception/PluginFileNotFoundException.php:21 |
523 | #, php-format | 527 | #, php-format |
524 | msgid "Plugin \"%s\" files not found." | 528 | msgid "Plugin \"%s\" files not found." |
@@ -550,11 +554,11 @@ msgstr "Shaare" | |||
550 | msgid "Adds the addlink input on the linklist page." | 554 | msgid "Adds the addlink input on the linklist page." |
551 | msgstr "Ajoute le formulaire d'ajout de liens sur la page principale." | 555 | msgstr "Ajoute le formulaire d'ajout de liens sur la page principale." |
552 | 556 | ||
553 | #: plugins/archiveorg/archiveorg.php:25 | 557 | #: plugins/archiveorg/archiveorg.php:26 |
554 | msgid "View on archive.org" | 558 | msgid "View on archive.org" |
555 | msgstr "Voir sur archive.org" | 559 | msgstr "Voir sur archive.org" |
556 | 560 | ||
557 | #: plugins/archiveorg/archiveorg.php:38 | 561 | #: plugins/archiveorg/archiveorg.php:39 |
558 | msgid "For each link, add an Archive.org icon." | 562 | msgid "For each link, add an Archive.org icon." |
559 | msgstr "Pour chaque lien, ajoute une icône pour Archive.org." | 563 | msgstr "Pour chaque lien, ajoute une icône pour Archive.org." |
560 | 564 | ||
@@ -674,7 +678,7 @@ msgstr "Mauvaise réponse du hub %s" | |||
674 | msgid "Enable PubSubHubbub feed publishing." | 678 | msgid "Enable PubSubHubbub feed publishing." |
675 | msgstr "Active la publication de flux vers PubSubHubbub." | 679 | msgstr "Active la publication de flux vers PubSubHubbub." |
676 | 680 | ||
677 | #: plugins/qrcode/qrcode.php:72 plugins/wallabag/wallabag.php:68 | 681 | #: plugins/qrcode/qrcode.php:73 plugins/wallabag/wallabag.php:70 |
678 | msgid "For each link, add a QRCode icon." | 682 | msgid "For each link, add a QRCode icon." |
679 | msgstr "Pour chaque lien, ajouter une icône de QRCode." | 683 | msgstr "Pour chaque lien, ajouter une icône de QRCode." |
680 | 684 | ||
@@ -690,11 +694,11 @@ msgstr "" | |||
690 | msgid "Save to wallabag" | 694 | msgid "Save to wallabag" |
691 | msgstr "Sauvegarder dans Wallabag" | 695 | msgstr "Sauvegarder dans Wallabag" |
692 | 696 | ||
693 | #: plugins/wallabag/wallabag.php:69 | 697 | #: plugins/wallabag/wallabag.php:71 |
694 | msgid "Wallabag API URL" | 698 | msgid "Wallabag API URL" |
695 | msgstr "URL de l'API Wallabag" | 699 | msgstr "URL de l'API Wallabag" |
696 | 700 | ||
697 | #: plugins/wallabag/wallabag.php:70 | 701 | #: plugins/wallabag/wallabag.php:72 |
698 | msgid "Wallabag API version (1 or 2)" | 702 | msgid "Wallabag API version (1 or 2)" |
699 | msgstr "Version de l'API Wallabag (1 ou 2)" | 703 | msgstr "Version de l'API Wallabag (1 ou 2)" |
700 | 704 | ||
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 | } | ||