]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
New plugin hook: ability to add custom filters to Shaarli search engine 1698/head
authorArthurHoaro <arthur@hoa.ro>
Wed, 20 Jan 2021 14:59:00 +0000 (15:59 +0100)
committerArthurHoaro <arthur@hoa.ro>
Thu, 4 Feb 2021 10:02:50 +0000 (11:02 +0100)
A new plugin hook has been added: hook_test_filter_search_entry
This hook allows to filter out bookmark with custom plugin code when a search is performed.

Related to #143

27 files changed:
application/api/ApiMiddleware.php
application/bookmark/BookmarkFileService.php
application/bookmark/BookmarkFilter.php
application/container/ContainerBuilder.php
application/plugin/PluginManager.php
doc/md/dev/Plugin-system.md
plugins/demo_plugin/demo_plugin.php
tests/PluginManagerTest.php
tests/api/ApiMiddlewareTest.php
tests/api/controllers/info/InfoTest.php
tests/api/controllers/links/DeleteLinkTest.php
tests/api/controllers/links/GetLinkIdTest.php
tests/api/controllers/links/GetLinksTest.php
tests/api/controllers/links/PostLinkTest.php
tests/api/controllers/links/PutLinkTest.php
tests/api/controllers/tags/DeleteTagTest.php
tests/api/controllers/tags/GetTagNameTest.php
tests/api/controllers/tags/GetTagsTest.php
tests/api/controllers/tags/PutTagTest.php
tests/bookmark/BookmarkFileServiceTest.php
tests/bookmark/BookmarkFilterTest.php
tests/bookmark/BookmarkInitializerTest.php
tests/feed/FeedBuilderTest.php
tests/netscape/BookmarkExportTest.php
tests/netscape/BookmarkImportTest.php
tests/plugins/test/test.php
tests/updater/UpdaterTest.php

index 9fb883589d43a61aff1003882d0531ac8fda3979..cc7af18e962427405335f2f8c506934c6129762f 100644 (file)
@@ -145,6 +145,7 @@ class ApiMiddleware
     {
         $linkDb = new BookmarkFileService(
             $conf,
+            $this->container->get('pluginManager'),
             $this->container->get('history'),
             new FlockMutex(fopen(SHAARLI_MUTEX_FILE, 'r'), 2),
             true
index 8ea37427a02a6af364d6a1b79b0e5f921e2ebd0c..e64eeafbd98a30f2a0b50ace69357f268d9e2343 100644 (file)
@@ -15,6 +15,7 @@ use Shaarli\Formatter\BookmarkMarkdownFormatter;
 use Shaarli\History;
 use Shaarli\Legacy\LegacyLinkDB;
 use Shaarli\Legacy\LegacyUpdater;
+use Shaarli\Plugin\PluginManager;
 use Shaarli\Render\PageCacheManager;
 use Shaarli\Updater\UpdaterUtils;
 
@@ -40,6 +41,9 @@ class BookmarkFileService implements BookmarkServiceInterface
     /** @var ConfigManager instance */
     protected $conf;
 
+    /** @var PluginManager */
+    protected $pluginManager;
+
     /** @var History instance */
     protected $history;
 
@@ -57,6 +61,7 @@ class BookmarkFileService implements BookmarkServiceInterface
      */
     public function __construct(
         ConfigManager $conf,
+        PluginManager $pluginManager,
         History $history,
         Mutex $mutex,
         bool $isLoggedIn
@@ -95,7 +100,8 @@ class BookmarkFileService implements BookmarkServiceInterface
             }
         }
 
-        $this->bookmarkFilter = new BookmarkFilter($this->bookmarks, $this->conf);
+        $this->pluginManager = $pluginManager;
+        $this->bookmarkFilter = new BookmarkFilter($this->bookmarks, $this->conf, $this->pluginManager);
     }
 
     /**
index db83c51c135e012ce7c693a0ab6eee5f82070208..8b41dbb86766991dcc5a46ca665bfe605dc0c8c6 100644 (file)
@@ -4,9 +4,9 @@ declare(strict_types=1);
 
 namespace Shaarli\Bookmark;
 
-use Exception;
 use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
 use Shaarli\Config\ConfigManager;
+use Shaarli\Plugin\PluginManager;
 
 /**
  * Class LinkFilter.
@@ -30,11 +30,6 @@ class BookmarkFilter
      */
     public static $FILTER_TAG = 'tags';
 
-    /**
-     * @var string filter by day.
-     */
-    public static $FILTER_DAY = 'FILTER_DAY';
-
     /**
      * @var string filter by day.
      */
@@ -62,13 +57,17 @@ class BookmarkFilter
     /** @var ConfigManager */
     protected $conf;
 
+    /** @var PluginManager */
+    protected $pluginManager;
+
     /**
      * @param Bookmark[] $bookmarks initialization.
      */
-    public function __construct($bookmarks, ConfigManager $conf)
+    public function __construct($bookmarks, ConfigManager $conf, PluginManager $pluginManager)
     {
         $this->bookmarks = $bookmarks;
         $this->conf = $conf;
+        $this->pluginManager = $pluginManager;
     }
 
     /**
@@ -112,12 +111,12 @@ class BookmarkFilter
                     $filtered = $this->bookmarks;
                 }
                 if (!empty($request[0])) {
-                    $filtered = (new BookmarkFilter($filtered, $this->conf))
+                    $filtered = (new BookmarkFilter($filtered, $this->conf, $this->pluginManager))
                         ->filterTags($request[0], $casesensitive, $visibility)
                     ;
                 }
                 if (!empty($request[1])) {
-                    $filtered = (new BookmarkFilter($filtered, $this->conf))
+                    $filtered = (new BookmarkFilter($filtered, $this->conf, $this->pluginManager))
                         ->filterFulltext($request[1], $visibility)
                     ;
                 }
@@ -130,8 +129,6 @@ class BookmarkFilter
                 } else {
                     return $this->filterTags($request, $casesensitive, $visibility);
                 }
-            case self::$FILTER_DAY:
-                return $this->filterDay($request, $visibility);
             default:
                 return $this->noFilter($visibility);
         }
@@ -146,13 +143,20 @@ class BookmarkFilter
      */
     private function noFilter(string $visibility = 'all')
     {
-        if ($visibility === 'all') {
-            return $this->bookmarks;
-        }
-
         $out = [];
         foreach ($this->bookmarks as $key => $value) {
-            if ($value->isPrivate() && $visibility === 'private') {
+            if (
+                !$this->pluginManager->filterSearchEntry(
+                    $value,
+                    ['source' => 'no_filter', 'visibility' => $visibility]
+                )
+            ) {
+                continue;
+            }
+
+            if ($visibility === 'all') {
+                $out[$key] = $value;
+            } elseif ($value->isPrivate() && $visibility === 'private') {
                 $out[$key] = $value;
             } elseif (!$value->isPrivate() && $visibility === 'public') {
                 $out[$key] = $value;
@@ -233,18 +237,34 @@ class BookmarkFilter
         }
 
         // Iterate over every stored link.
-        foreach ($this->bookmarks as $id => $link) {
+        foreach ($this->bookmarks as $id => $bookmark) {
+            if (
+                !$this->pluginManager->filterSearchEntry(
+                    $bookmark,
+                    [
+                    'source' => 'fulltext',
+                    'searchterms' => $searchterms,
+                    'andSearch' => $andSearch,
+                    'exactSearch' => $exactSearch,
+                    'excludeSearch' => $excludeSearch,
+                    'visibility' => $visibility
+                    ]
+                )
+            ) {
+                continue;
+            }
+
             // ignore non private bookmarks when 'privatonly' is on.
             if ($visibility !== 'all') {
-                if (!$link->isPrivate() && $visibility === 'private') {
+                if (!$bookmark->isPrivate() && $visibility === 'private') {
                     continue;
-                } elseif ($link->isPrivate() && $visibility === 'public') {
+                } elseif ($bookmark->isPrivate() && $visibility === 'public') {
                     continue;
                 }
             }
 
             $lengths = [];
-            $content = $this->buildFullTextSearchableLink($link, $lengths);
+            $content = $this->buildFullTextSearchableLink($bookmark, $lengths);
 
             // Be optimistic
             $found = true;
@@ -270,68 +290,18 @@ class BookmarkFilter
             }
 
             if ($found !== false) {
-                $link->addAdditionalContentEntry(
+                $bookmark->addAdditionalContentEntry(
                     'search_highlight',
                     $this->postProcessFoundPositions($lengths, $foundPositions)
                 );
 
-                $filtered[$id] = $link;
+                $filtered[$id] = $bookmark;
             }
         }
 
         return $filtered;
     }
 
-    /**
-     * generate a regex fragment out of a tag
-     *
-     * @param string $tag to to generate regexs from. may start with '-' to negate, contain '*' as wildcard
-     *
-     * @return string generated regex fragment
-     */
-    protected function tag2regex(string $tag): string
-    {
-        $tagsSeparator = $this->conf->get('general.tags_separator', ' ');
-        $len = strlen($tag);
-        if (!$len || $tag === "-" || $tag === "*") {
-            // nothing to search, return empty regex
-            return '';
-        }
-        if ($tag[0] === "-") {
-            // query is negated
-            $i = 1; // use offset to start after '-' character
-            $regex = '(?!'; // create negative lookahead
-        } else {
-            $i = 0; // start at first character
-            $regex = '(?='; // use positive lookahead
-        }
-        // before tag may only be the separator or the beginning
-        $regex .= '.*(?:^|' . $tagsSeparator . ')';
-        // iterate over string, separating it into placeholder and content
-        for (; $i < $len; $i++) {
-            if ($tag[$i] === '*') {
-                // placeholder found
-                $regex .= '[^' . $tagsSeparator . ']*?';
-            } else {
-                // regular characters
-                $offset = strpos($tag, '*', $i);
-                if ($offset === false) {
-                    // no placeholder found, set offset to end of string
-                    $offset = $len;
-                }
-                // subtract one, as we want to get before the placeholder or end of string
-                $offset -= 1;
-                // we got a tag name that we want to search for. escape any regex characters to prevent conflicts.
-                $regex .= preg_quote(substr($tag, $i, $offset - $i + 1), '/');
-                // move $i on
-                $i = $offset;
-            }
-        }
-        // after the tag may only be the separator or the end
-        $regex .= '(?:$|' . $tagsSeparator . '))';
-        return $regex;
-    }
-
     /**
      * Returns the list of bookmarks associated with a given list of tags
      *
@@ -381,25 +351,39 @@ class BookmarkFilter
         $filtered = [];
 
         // iterate over each link
-        foreach ($this->bookmarks as $key => $link) {
+        foreach ($this->bookmarks as $key => $bookmark) {
+            if (
+                !$this->pluginManager->filterSearchEntry(
+                    $bookmark,
+                    [
+                    'source' => 'tags',
+                    'tags' => $tags,
+                    'casesensitive' => $casesensitive,
+                    'visibility' => $visibility
+                    ]
+                )
+            ) {
+                continue;
+            }
+
             // check level of visibility
             // ignore non private bookmarks when 'privateonly' is on.
             if ($visibility !== 'all') {
-                if (!$link->isPrivate() && $visibility === 'private') {
+                if (!$bookmark->isPrivate() && $visibility === 'private') {
                     continue;
-                } elseif ($link->isPrivate() && $visibility === 'public') {
+                } elseif ($bookmark->isPrivate() && $visibility === 'public') {
                     continue;
                 }
             }
             // build search string, start with tags of current link
-            $search = $link->getTagsString($tagsSeparator);
-            if (strlen(trim($link->getDescription())) && strpos($link->getDescription(), '#') !== false) {
+            $search = $bookmark->getTagsString($tagsSeparator);
+            if (strlen(trim($bookmark->getDescription())) && strpos($bookmark->getDescription(), '#') !== false) {
                 // description given and at least one possible tag found
                 $descTags = [];
                 // find all tags in the form of #tag in the description
                 preg_match_all(
                     '/(?<![' . self::$HASHTAG_CHARS . '])#([' . self::$HASHTAG_CHARS . ']+?)\b/sm',
-                    $link->getDescription(),
+                    $bookmark->getDescription(),
                     $descTags
                 );
                 if (count($descTags[1])) {
@@ -412,8 +396,9 @@ class BookmarkFilter
                 // this entry does _not_ match our regex
                 continue;
             }
-            $filtered[$key] = $link;
+            $filtered[$key] = $bookmark;
         }
+
         return $filtered;
     }
 
@@ -427,55 +412,30 @@ class BookmarkFilter
     public function filterUntagged(string $visibility)
     {
         $filtered = [];
-        foreach ($this->bookmarks as $key => $link) {
+        foreach ($this->bookmarks as $key => $bookmark) {
+            if (
+                !$this->pluginManager->filterSearchEntry(
+                    $bookmark,
+                    ['source' => 'untagged', 'visibility' => $visibility]
+                )
+            ) {
+                continue;
+            }
+
             if ($visibility !== 'all') {
-                if (!$link->isPrivate() && $visibility === 'private') {
+                if (!$bookmark->isPrivate() && $visibility === 'private') {
                     continue;
-                } elseif ($link->isPrivate() && $visibility === 'public') {
+                } elseif ($bookmark->isPrivate() && $visibility === 'public') {
                     continue;
                 }
             }
 
-            if (empty($link->getTags())) {
-                $filtered[$key] = $link;
-            }
-        }
-
-        return $filtered;
-    }
-
-    /**
-     * Returns the list of articles for a given day, chronologically sorted
-     *
-     * Day must be in the form 'YYYYMMDD' (e.g. '20120125'), e.g.
-     *  print_r($mydb->filterDay('20120125'));
-     *
-     * @param string $day day to filter.
-     * @param string $visibility return only all/private/public bookmarks.
-
-     * @return Bookmark[] all link matching given day.
-     *
-     * @throws Exception if date format is invalid.
-     */
-    public function filterDay(string $day, string $visibility)
-    {
-        if (!checkDateFormat('Ymd', $day)) {
-            throw new Exception('Invalid date format');
-        }
-
-        $filtered = [];
-        foreach ($this->bookmarks as $key => $bookmark) {
-            if ($visibility === static::$PUBLIC && $bookmark->isPrivate()) {
-                continue;
-            }
-
-            if ($bookmark->getCreated()->format('Ymd') == $day) {
+            if (empty($bookmark->getTags())) {
                 $filtered[$key] = $bookmark;
             }
         }
 
-        // sort by date ASC
-        return array_reverse($filtered, true);
+        return $filtered;
     }
 
     /**
@@ -497,6 +457,56 @@ class BookmarkFilter
         return preg_split('/\s+/', $tagsOut, -1, PREG_SPLIT_NO_EMPTY);
     }
 
+    /**
+     * generate a regex fragment out of a tag
+     *
+     * @param string $tag to to generate regexs from. may start with '-' to negate, contain '*' as wildcard
+     *
+     * @return string generated regex fragment
+     */
+    protected function tag2regex(string $tag): string
+    {
+        $tagsSeparator = $this->conf->get('general.tags_separator', ' ');
+        $len = strlen($tag);
+        if (!$len || $tag === "-" || $tag === "*") {
+            // nothing to search, return empty regex
+            return '';
+        }
+        if ($tag[0] === "-") {
+            // query is negated
+            $i = 1; // use offset to start after '-' character
+            $regex = '(?!'; // create negative lookahead
+        } else {
+            $i = 0; // start at first character
+            $regex = '(?='; // use positive lookahead
+        }
+        // before tag may only be the separator or the beginning
+        $regex .= '.*(?:^|' . $tagsSeparator . ')';
+        // iterate over string, separating it into placeholder and content
+        for (; $i < $len; $i++) {
+            if ($tag[$i] === '*') {
+                // placeholder found
+                $regex .= '[^' . $tagsSeparator . ']*?';
+            } else {
+                // regular characters
+                $offset = strpos($tag, '*', $i);
+                if ($offset === false) {
+                    // no placeholder found, set offset to end of string
+                    $offset = $len;
+                }
+                // subtract one, as we want to get before the placeholder or end of string
+                $offset -= 1;
+                // we got a tag name that we want to search for. escape any regex characters to prevent conflicts.
+                $regex .= preg_quote(substr($tag, $i, $offset - $i + 1), '/');
+                // move $i on
+                $i = $offset;
+            }
+        }
+        // after the tag may only be the separator or the end
+        $regex .= '(?:$|' . $tagsSeparator . '))';
+        return $regex;
+    }
+
     /**
      * This method finalize the content of the foundPositions array,
      * by associated all search results to their associated bookmark field,
index 6d69a880f4fb0694e762b42a38df432c445bca4a..f66d75bd0efdc906b584590b7340036163580e55 100644 (file)
@@ -95,6 +95,7 @@ class ContainerBuilder
         $container['bookmarkService'] = function (ShaarliContainer $container): BookmarkServiceInterface {
             return new BookmarkFileService(
                 $container->conf,
+                $container->pluginManager,
                 $container->history,
                 new FlockMutex(fopen(SHAARLI_MUTEX_FILE, 'r'), 2),
                 $container->loginManager->isLoggedIn()
index 7fc0cb047db70d1ca33d8f72529b57ff598b579e..939db1eaafa84acdb68915c4fdda659d1f416665 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Shaarli\Plugin;
 
+use Shaarli\Bookmark\Bookmark;
 use Shaarli\Config\ConfigManager;
 use Shaarli\Plugin\Exception\PluginFileNotFoundException;
 use Shaarli\Plugin\Exception\PluginInvalidRouteException;
@@ -45,6 +46,9 @@ class PluginManager
      */
     protected $errors;
 
+    /** @var callable[]|null Preloaded list of hook function for filterSearchEntry() */
+    protected $filterSearchEntryHooks = null;
+
     /**
      * Plugins subdirectory.
      *
@@ -273,6 +277,14 @@ class PluginManager
         return $this->registeredRoutes;
     }
 
+    /**
+     * @return array List of registered filter_search_entry hooks
+     */
+    public function getFilterSearchEntryHooks(): ?array
+    {
+        return $this->filterSearchEntryHooks;
+    }
+
     /**
      * Return the list of encountered errors.
      *
@@ -283,6 +295,50 @@ class PluginManager
         return $this->errors;
     }
 
+    /**
+     * Apply additional filter on every search result of BookmarkFilter calling plugins hooks.
+     *
+     * @param Bookmark $bookmark To check.
+     * @param array    $context  Additional info about search context, depends on the search source.
+     *
+     * @return bool True if the result must be kept in search results, false otherwise.
+     */
+    public function filterSearchEntry(Bookmark $bookmark, array $context): bool
+    {
+        if ($this->filterSearchEntryHooks === null) {
+            $this->loadFilterSearchEntryHooks();
+        }
+
+        if ($this->filterSearchEntryHooks === []) {
+            return true;
+        }
+
+        foreach ($this->filterSearchEntryHooks as $filterSearchEntryHook) {
+            if ($filterSearchEntryHook($bookmark, $context) === false) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * filterSearchEntry() method will be called for every search result,
+     * so for performances we preload existing functions to invoke them directly.
+     */
+    protected function loadFilterSearchEntryHooks(): void
+    {
+        $this->filterSearchEntryHooks = [];
+
+        foreach ($this->loadedPlugins as $plugin) {
+            $hookFunction = $this->buildHookName('filter_search_entry', $plugin);
+
+            if (function_exists($hookFunction)) {
+                $this->filterSearchEntryHooks[] = $hookFunction;
+            }
+        }
+    }
+
     /**
      * Checks whether provided input is valid to register a new route.
      * It must contain keys `method`, `route`, `callable` (all strings).
index 79654011b49f910aeb380a805736f812fd6e2490..0ada57ea5f3ef12046782c3000f329f282845ece 100644 (file)
@@ -27,7 +27,6 @@ You should have the following tree view:
 |   |---| demo_plugin.php
 ```
 
-
 ### Plugin initialization
 
 At the beginning of Shaarli execution, all enabled plugins are loaded. At this point, the plugin system looks for an `init()` function in the <plugin_name>.php to execute and run it if it exists. This function must be named this way, and takes the `ConfigManager` as parameter.
@@ -209,6 +208,7 @@ If it's still not working, please [open an issue](https://github.com/shaarli/Sha
 | [save_link](#save_link) | Allow to alter the link being saved in the datastore. |
 | [delete_link](#delete_link) | Allow to do an action before a link is deleted from the datastore. |
 | [save_plugin_parameters](#save_plugin_parameters) | Allow to manipulate plugin parameters before they're saved. |
+| [filter_search_entry](#filter_search_entry) | Add custom filters to Shaarli search engine |
 
 
 #### render_header
@@ -565,6 +565,23 @@ the array will contain an entry with `MYPLUGIN_PARAMETER` as a key.
 
 Also [special data](#special-data).
 
+#### filter_search_entry
+
+Triggered for *every* bookmark when Shaarli's BookmarkService method `search()` is used.
+Any custom filter can be added to filter out bookmarks from search results.
+
+The hook **must** return either:
+  - `true` to keep bookmark entry in search result set
+  - `false` to discard bookmark entry in result set
+
+> Note: custom filters are called *before* default filters are applied.
+
+##### Parameters
+
+- `Shaarli\Bookmark\Bookmark` object: entry to evaluate
+- $context `array`: additional information provided depending on what search is currently used,
+the user request, etc.
+
 ## Guide for template designers
 
 ### Plugin administration
index 15cfc2c51cd4889cc0d38f821e0ab856806a4167..d89765cfcb2ca20bfbf34a4cda8a592669b73524 100644 (file)
@@ -17,6 +17,7 @@ require_once __DIR__ . '/DemoPluginController.php';
  * and check user status with _LOGGEDIN_.
  */
 
+use Shaarli\Bookmark\Bookmark;
 use Shaarli\Config\ConfigManager;
 use Shaarli\Plugin\PluginManager;
 use Shaarli\Render\TemplatePage;
@@ -263,6 +264,17 @@ function hook_demo_plugin_render_linklist($data)
     }
     $data['action_plugin'][] = $action;
 
+    // Action to trigger custom filter hiding bookmarks not containing 'e' letter in their description
+    $action = [
+        'attr' => [
+            'href' => '?e',
+            'title' => 'Hide bookmarks without "e" in their description.',
+        ],
+        'html' => 'e',
+        'on' => isset($_GET['e'])
+    ];
+    $data['action_plugin'][] = $action;
+
     // link_plugin (for each link)
     foreach ($data['links'] as &$value) {
         $value['link_plugin'][] = ' DEMO \o/';
@@ -486,6 +498,27 @@ function hook_demo_plugin_save_plugin_parameters($data)
     return $data;
 }
 
+/**
+ * This hook is called when a search is performed, on every search entry.
+ * It allows to add custom filters, and filter out additional link.
+ *
+ * For exemple here, we hide all bookmarks not containing the letter 'e' in their description.
+ *
+ * @param Bookmark $bookmark Search entry. Note that this is a Bookmark object, and not a link array.
+ *                           It should NOT be altered.
+ * @param array    $context  Additional info on the search performed.
+ *
+ * @return bool True if the bookmark should be kept in the search result, false to discard it.
+ */
+function hook_demo_plugin_filter_search_entry(Bookmark $bookmark, array $context): bool
+{
+    if (isset($_GET['e'])) {
+        return strpos($bookmark->getDescription(), 'e') !== false;
+    }
+
+    return true;
+}
+
 /**
  * This function is never called, but contains translation calls for GNU gettext extraction.
  */
index 8947f6791831cec961c9c84a73e644a7c197ee7f..75b3ae0082138568d753b8b9ab5cfc75b2286be3 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Shaarli\Plugin;
 
+use Shaarli\Bookmark\Bookmark;
 use Shaarli\Config\ConfigManager;
 
 /**
@@ -159,4 +160,19 @@ class PluginManagerTest extends \Shaarli\TestCase
         $errors = $this->pluginManager->getErrors();
         static::assertSame(['test_route_invalid [plugin incompatibility]: trying to register invalid route.'], $errors);
     }
+
+    public function testSearchFilterPlugin(): void
+    {
+        PluginManager::$PLUGINS_PATH = self::$pluginPath;
+        $this->pluginManager->load([self::$pluginName]);
+
+        static::assertNull($this->pluginManager->getFilterSearchEntryHooks());
+
+        static::assertTrue($this->pluginManager->filterSearchEntry(new Bookmark(), ['_result' => true]));
+
+        static::assertCount(1, $this->pluginManager->getFilterSearchEntryHooks());
+        static::assertSame('hook_test_filter_search_entry', $this->pluginManager->getFilterSearchEntryHooks()[0]);
+
+        static::assertFalse($this->pluginManager->filterSearchEntry(new Bookmark(), ['_result' => false]));
+    }
 }
index 86700840b35dfc03ef75e052e0365b4e8ee89e29..2afac28bd121d1886211b0c1944afa0afec3d2cf 100644 (file)
@@ -3,6 +3,7 @@ namespace Shaarli\Api;
 
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
@@ -56,6 +57,7 @@ class ApiMiddlewareTest extends \Shaarli\TestCase
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
         $this->container['history'] = $history;
+        $this->container['pluginManager'] = new PluginManager($this->conf);
     }
 
     /**
index 10b29ab2530bdf9c9752aef9c149ba7c6feeebed..2428ca4307f2640765d4ab2493bf80e0382139d0 100644 (file)
@@ -5,6 +5,7 @@ use malkusch\lock\mutex\NoMutex;
 use Shaarli\Bookmark\BookmarkFileService;
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Shaarli\TestCase;
 use Slim\Container;
 use Slim\Http\Environment;
@@ -55,12 +56,18 @@ class InfoTest extends TestCase
         $this->conf->set('resource.datastore', self::$testDatastore);
         $this->refDB = new \ReferenceLinkDB();
         $this->refDB->write(self::$testDatastore);
-
+        $this->pluginManager = new PluginManager($this->conf);
         $history = new History('sandbox/history.php');
 
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
-        $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true);
+        $this->container['db'] = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $history,
+            $mutex,
+            true
+        );
         $this->container['history'] = null;
 
         $this->controller = new Info($this->container);
index 805c9be33be49c0523ef23311d930c356b252c11..dc2cf91728b8ce537036a8b19268cb79effe28f7 100644 (file)
@@ -7,6 +7,7 @@ use malkusch\lock\mutex\NoMutex;
 use Shaarli\Bookmark\BookmarkFileService;
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
@@ -57,6 +58,9 @@ class DeleteLinkTest extends \Shaarli\TestCase
     /** @var NoMutex */
     protected $mutex;
 
+    /** @var PluginManager */
+    protected $pluginManager;
+
     /**
      * Before each test, instantiate a new Api with its config, plugins and bookmarks.
      */
@@ -70,7 +74,14 @@ class DeleteLinkTest extends \Shaarli\TestCase
         $refHistory = new \ReferenceHistory();
         $refHistory->write(self::$testHistory);
         $this->history = new History(self::$testHistory);
-        $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->pluginManager = new PluginManager($this->conf);
+        $this->bookmarkService = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
 
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
@@ -105,7 +116,13 @@ class DeleteLinkTest extends \Shaarli\TestCase
         $this->assertEquals(204, $response->getStatusCode());
         $this->assertEmpty((string) $response->getBody());
 
-        $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->bookmarkService = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
         $this->assertFalse($this->bookmarkService->exists($id));
 
         $historyEntry = $this->history->getHistory()[0];
index 1ec56ef3cd97c870fc52b7bbb54875178c52a6ea..c93a3b4b3139949b7fd023108ee9519b27a7cee3 100644 (file)
@@ -7,6 +7,7 @@ use Shaarli\Bookmark\Bookmark;
 use Shaarli\Bookmark\BookmarkFileService;
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
@@ -67,7 +68,14 @@ class GetLinkIdTest extends \Shaarli\TestCase
 
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
-        $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true);
+        $pluginManager = new PluginManager($this->conf);
+        $this->container['db'] = new BookmarkFileService(
+            $this->conf,
+            $pluginManager,
+            $history,
+            $mutex,
+            true
+        );
         $this->container['history'] = null;
 
         $this->controller = new Links($this->container);
index b1c46ee2816853b45a5a8abfcac28f8c71f4b973..3c96673282d4b657c7866fea8f7509334db2b1ba 100644 (file)
@@ -7,6 +7,7 @@ use Shaarli\Bookmark\BookmarkFileService;
 use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
@@ -67,7 +68,14 @@ class GetLinksTest extends \Shaarli\TestCase
 
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
-        $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true);
+        $pluginManager = new PluginManager($this->conf);
+        $this->container['db'] = new BookmarkFileService(
+            $this->conf,
+            $pluginManager,
+            $history,
+            $mutex,
+            true
+        );
         $this->container['history'] = null;
 
         $this->controller = new Links($this->container);
index f755e2d2b9a9d6e0052b0a5e7875e8d539d2c03e..a54e4a16bb22052fd161e4a6f6e9253f88fd5c43 100644 (file)
@@ -7,6 +7,7 @@ use Shaarli\Bookmark\Bookmark;
 use Shaarli\Bookmark\BookmarkFileService;
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Shaarli\TestCase;
 use Slim\Container;
 use Slim\Http\Environment;
@@ -81,8 +82,14 @@ class PostLinkTest extends TestCase
         $refHistory = new \ReferenceHistory();
         $refHistory->write(self::$testHistory);
         $this->history = new History(self::$testHistory);
-        $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true);
-
+        $pluginManager = new PluginManager($this->conf);
+        $this->bookmarkService = new BookmarkFileService(
+            $this->conf,
+            $pluginManager,
+            $this->history,
+            $mutex,
+            true
+        );
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
         $this->container['db'] = $this->bookmarkService;
index fe24f2eb91a1ae1d27cd0032a45cced641442a95..ed14d5f804a4813b171aff953049913600a18be7 100644 (file)
@@ -8,6 +8,7 @@ use Shaarli\Bookmark\Bookmark;
 use Shaarli\Bookmark\BookmarkFileService;
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
@@ -73,8 +74,14 @@ class PutLinkTest extends \Shaarli\TestCase
         $refHistory = new \ReferenceHistory();
         $refHistory->write(self::$testHistory);
         $this->history = new History(self::$testHistory);
-        $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true);
-
+        $pluginManager = new PluginManager($this->conf);
+        $this->bookmarkService = new BookmarkFileService(
+            $this->conf,
+            $pluginManager,
+            $this->history,
+            $mutex,
+            true
+        );
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
         $this->container['db'] = $this->bookmarkService;
index 37f0722978c2e2ee4fc2a2a45589b4fd28f1ffe0..c0f8a6a997f6ae9aaea1a8df7219b1545ac76175 100644 (file)
@@ -8,6 +8,7 @@ use Shaarli\Bookmark\BookmarkFileService;
 use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
@@ -55,6 +56,9 @@ class DeleteTagTest extends \Shaarli\TestCase
      */
     protected $controller;
 
+    /** @var PluginManager */
+    protected $pluginManager;
+
     /** @var NoMutex */
     protected $mutex;
 
@@ -71,7 +75,14 @@ class DeleteTagTest extends \Shaarli\TestCase
         $refHistory = new \ReferenceHistory();
         $refHistory->write(self::$testHistory);
         $this->history = new History(self::$testHistory);
-        $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->pluginManager = new PluginManager($this->conf);
+        $this->bookmarkService = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
 
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
@@ -107,7 +118,13 @@ class DeleteTagTest extends \Shaarli\TestCase
         $this->assertEquals(204, $response->getStatusCode());
         $this->assertEmpty((string) $response->getBody());
 
-        $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->bookmarkService = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
         $tags = $this->bookmarkService->bookmarksCountPerTag();
         $this->assertFalse(isset($tags[$tagName]));
 
@@ -141,7 +158,13 @@ class DeleteTagTest extends \Shaarli\TestCase
         $this->assertEquals(204, $response->getStatusCode());
         $this->assertEmpty((string) $response->getBody());
 
-        $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->bookmarkService = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
         $tags = $this->bookmarkService->bookmarksCountPerTag();
         $this->assertFalse(isset($tags[$tagName]));
         $this->assertTrue($tags[strtolower($tagName)] > 0);
index 878de5a4202d2dbb5a2e54ec2f29a719cc8a5412..0ad71495e20040c1d949fbd0bc36606a62c5dfd9 100644 (file)
@@ -7,6 +7,7 @@ use Shaarli\Bookmark\BookmarkFileService;
 use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
@@ -46,6 +47,9 @@ class GetTagNameTest extends \Shaarli\TestCase
      */
     protected $controller;
 
+    /** @var PluginManager */
+    protected $pluginManager;
+
     /**
      * Number of JSON fields per link.
      */
@@ -65,7 +69,14 @@ class GetTagNameTest extends \Shaarli\TestCase
 
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
-        $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true);
+        $this->pluginManager = new PluginManager($this->conf);
+        $this->container['db'] = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $history,
+            $mutex,
+            true
+        );
         $this->container['history'] = null;
 
         $this->controller = new Tags($this->container);
index b565a8c4d3620eba8282d871c3c63b5094815d3b..a4b62c51b2c18e7b0fed1242fe9590f2a0abd9b9 100644 (file)
@@ -6,6 +6,7 @@ use Shaarli\Bookmark\BookmarkFileService;
 use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
@@ -50,6 +51,9 @@ class GetTagsTest extends \Shaarli\TestCase
      */
     protected $controller;
 
+    /** @var PluginManager */
+    protected $pluginManager;
+
     /**
      * Number of JSON field per link.
      */
@@ -66,9 +70,14 @@ class GetTagsTest extends \Shaarli\TestCase
         $this->refDB = new \ReferenceLinkDB();
         $this->refDB->write(self::$testDatastore);
         $history = new History('sandbox/history.php');
-
-        $this->bookmarkService = new BookmarkFileService($this->conf, $history, $mutex, true);
-
+        $this->pluginManager = new PluginManager($this->conf);
+        $this->bookmarkService = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $history,
+            $mutex,
+            true
+        );
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
         $this->container['db'] = $this->bookmarkService;
index c73f6d3beaec758d1318599c46b9b477bdd66189..045473e6a1d9a875dc26c6ddcfec23064d3c3966 100644 (file)
@@ -8,6 +8,7 @@ use Shaarli\Bookmark\BookmarkFileService;
 use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Slim\Container;
 use Slim\Http\Environment;
 use Slim\Http\Request;
@@ -55,6 +56,9 @@ class PutTagTest extends \Shaarli\TestCase
      */
     protected $controller;
 
+    /** @var PluginManager */
+    protected $pluginManager;
+
     /**
      * Number of JSON field per link.
      */
@@ -73,7 +77,14 @@ class PutTagTest extends \Shaarli\TestCase
         $refHistory = new \ReferenceHistory();
         $refHistory->write(self::$testHistory);
         $this->history = new History(self::$testHistory);
-        $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true);
+        $this->pluginManager = new PluginManager($this->conf);
+        $this->bookmarkService = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $mutex,
+            true
+        );
 
         $this->container = new Container();
         $this->container['conf'] = $this->conf;
index d1af3fb04f6fffa71813ab4161d02ea6a500d0eb..1d250719b27f3f4b406a1227de977435d5000fcc 100644 (file)
@@ -14,6 +14,7 @@ use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
 use Shaarli\Config\ConfigManager;
 use Shaarli\Formatter\BookmarkMarkdownFormatter;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Shaarli\TestCase;
 
 /**
@@ -56,6 +57,9 @@ class BookmarkFileServiceTest extends TestCase
     /** @var NoMutex */
     protected $mutex;
 
+    /** @var PluginManager */
+    protected $pluginManager;
+
     /**
      * Instantiates public and private LinkDBs with test data
      *
@@ -93,8 +97,21 @@ class BookmarkFileServiceTest extends TestCase
         $this->refDB = new \ReferenceLinkDB();
         $this->refDB->write(self::$testDatastore);
         $this->history = new History('sandbox/history.php');
-        $this->publicLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, false);
-        $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->pluginManager = new PluginManager($this->conf);
+        $this->publicLinkDB = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            false
+        );
+        $this->privateLinkDB = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
     }
 
     /**
@@ -111,7 +128,13 @@ class BookmarkFileServiceTest extends TestCase
         $db = self::getMethod('migrate');
         $db->invokeArgs($this->privateLinkDB, []);
 
-        $db = new \FakeBookmarkService($this->conf, $this->history, $this->mutex, true);
+        $db = new \FakeBookmarkService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
         $this->assertInstanceOf(BookmarkArray::class, $db->getBookmarks());
         $this->assertEquals($this->refDB->countLinks(), $db->count());
     }
@@ -180,7 +203,13 @@ class BookmarkFileServiceTest extends TestCase
         $this->assertEquals($updated, $bookmark->getUpdated());
 
         // reload from file
-        $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->privateLinkDB = new \FakeBookmarkService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
 
         $bookmark = $this->privateLinkDB->get(43);
         $this->assertEquals(43, $bookmark->getId());
@@ -218,7 +247,13 @@ class BookmarkFileServiceTest extends TestCase
         $this->assertNull($bookmark->getUpdated());
 
         // reload from file
-        $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->privateLinkDB = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
 
         $bookmark = $this->privateLinkDB->get(43);
         $this->assertEquals(43, $bookmark->getId());
@@ -248,7 +283,13 @@ class BookmarkFileServiceTest extends TestCase
         $this->assertEquals(43, $bookmark->getId());
 
         // reload from file
-        $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->privateLinkDB = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
 
         $this->privateLinkDB->get(43);
     }
@@ -309,7 +350,13 @@ class BookmarkFileServiceTest extends TestCase
         $this->assertTrue(new \DateTime('5 seconds ago') < $bookmark->getUpdated());
 
         // reload from file
-        $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->privateLinkDB = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
 
         $bookmark = $this->privateLinkDB->get(42);
         $this->assertEquals(42, $bookmark->getId());
@@ -350,7 +397,13 @@ class BookmarkFileServiceTest extends TestCase
         $this->assertTrue(new \DateTime('5 seconds ago') < $bookmark->getUpdated());
 
         // reload from file
-        $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->privateLinkDB = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
 
         $bookmark = $this->privateLinkDB->get(42);
         $this->assertEquals(42, $bookmark->getId());
@@ -383,7 +436,13 @@ class BookmarkFileServiceTest extends TestCase
         $this->assertEquals($title, $bookmark->getTitle());
 
         // reload from file
-        $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->privateLinkDB = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
 
         $bookmark = $this->privateLinkDB->get(42);
         $this->assertEquals(42, $bookmark->getId());
@@ -436,7 +495,13 @@ class BookmarkFileServiceTest extends TestCase
         $this->assertEquals(43, $bookmark->getId());
 
         // reload from file
-        $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->privateLinkDB = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
 
         $bookmark = $this->privateLinkDB->get(43);
         $this->assertEquals(43, $bookmark->getId());
@@ -456,7 +521,13 @@ class BookmarkFileServiceTest extends TestCase
         $this->assertEquals($title, $bookmark->getTitle());
 
         // reload from file
-        $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->privateLinkDB = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
 
         $bookmark = $this->privateLinkDB->get(42);
         $this->assertEquals(42, $bookmark->getId());
@@ -488,7 +559,13 @@ class BookmarkFileServiceTest extends TestCase
         $this->assertEquals($title, $bookmark->getTitle());
 
         // reload from file
-        $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->privateLinkDB = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
 
         $bookmark = $this->privateLinkDB->get(42);
         $this->assertEquals(42, $bookmark->getId());
@@ -514,7 +591,13 @@ class BookmarkFileServiceTest extends TestCase
         $this->assertInstanceOf(BookmarkNotFoundException::class, $exception);
 
         // reload from file
-        $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->privateLinkDB = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
 
         $this->privateLinkDB->get(42);
     }
@@ -607,7 +690,7 @@ class BookmarkFileServiceTest extends TestCase
 
         $conf = new ConfigManager('tests/utils/config/configJson');
         $conf->set('resource.datastore', 'null/store.db');
-        new BookmarkFileService($conf, $this->history, $this->mutex, true);
+        new BookmarkFileService($conf, $this->pluginManager, $this->history, $this->mutex, true);
     }
 
     /**
@@ -617,7 +700,7 @@ class BookmarkFileServiceTest extends TestCase
     {
         unlink(self::$testDatastore);
         $this->assertFileNotExists(self::$testDatastore);
-        new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        new BookmarkFileService($this->conf, $this->pluginManager, $this->history, $this->mutex, true);
         $this->assertFileExists(self::$testDatastore);
 
         // ensure the correct data has been written
@@ -631,7 +714,7 @@ class BookmarkFileServiceTest extends TestCase
     {
         unlink(self::$testDatastore);
         $this->assertFileNotExists(self::$testDatastore);
-        $db = new \FakeBookmarkService($this->conf, $this->history, $this->mutex, false);
+        $db = new \FakeBookmarkService($this->conf, $this->pluginManager, $this->history, $this->mutex, false);
         $this->assertFileNotExists(self::$testDatastore);
         $this->assertInstanceOf(BookmarkArray::class, $db->getBookmarks());
         $this->assertCount(0, $db->getBookmarks());
@@ -664,13 +747,13 @@ class BookmarkFileServiceTest extends TestCase
      */
     public function testSave()
     {
-        $testDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $testDB = new BookmarkFileService($this->conf, $this->pluginManager, $this->history, $this->mutex, true);
         $dbSize = $testDB->count();
 
         $bookmark = new Bookmark();
         $testDB->add($bookmark);
 
-        $testDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $testDB = new BookmarkFileService($this->conf, $this->pluginManager, $this->history, $this->mutex, true);
         $this->assertEquals($dbSize + 1, $testDB->count());
     }
 
@@ -680,7 +763,7 @@ class BookmarkFileServiceTest extends TestCase
     public function testCountHiddenPublic()
     {
         $this->conf->set('privacy.hide_public_links', true);
-        $linkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, false);
+        $linkDB = new BookmarkFileService($this->conf, $this->pluginManager, $this->history, $this->mutex, false);
 
         $this->assertEquals(0, $linkDB->count());
     }
@@ -906,7 +989,13 @@ class BookmarkFileServiceTest extends TestCase
         $bookmark->addAdditionalContentEntry('private_key', $privateKey);
         $this->privateLinkDB->save();
 
-        $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, false);
+        $this->privateLinkDB = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            false
+        );
         $bookmark = $this->privateLinkDB->findByHash($hash, $privateKey);
 
         static::assertSame(6, $bookmark->getId());
@@ -1152,7 +1241,13 @@ class BookmarkFileServiceTest extends TestCase
     public function testGetLatestEmptyDatastore(): void
     {
         unlink($this->conf->get('resource.datastore'));
-        $this->publicLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, false);
+        $this->publicLinkDB = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            false
+        );
 
         $bookmark = $this->publicLinkDB->getLatest();
 
index 835674f2d6df2900efeba0c4d8a1022fae2a95b9..79be807dc625767badc6752ac971b85e0652d8a2 100644 (file)
@@ -6,6 +6,7 @@ use malkusch\lock\mutex\NoMutex;
 use ReferenceLinkDB;
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Shaarli\TestCase;
 
 /**
@@ -32,19 +33,24 @@ class BookmarkFilterTest extends TestCase
      */
     protected static $bookmarkService;
 
+    /** @var PluginManager */
+    protected static $pluginManager;
+
     /**
      * Instantiate linkFilter with ReferenceLinkDB data.
      */
     public static function setUpBeforeClass(): void
     {
+
         $mutex = new NoMutex();
         $conf = new ConfigManager('tests/utils/config/configJson');
         $conf->set('resource.datastore', self::$testDatastore);
+        static::$pluginManager = new PluginManager($conf);
         self::$refDB = new \ReferenceLinkDB();
         self::$refDB->write(self::$testDatastore);
         $history = new History('sandbox/history.php');
-        self::$bookmarkService = new \FakeBookmarkService($conf, $history, $mutex, true);
-        self::$linkFilter = new BookmarkFilter(self::$bookmarkService->getBookmarks(), $conf);
+        self::$bookmarkService = new \FakeBookmarkService($conf, static::$pluginManager, $history, $mutex, true);
+        self::$linkFilter = new BookmarkFilter(self::$bookmarkService->getBookmarks(), $conf, static::$pluginManager);
     }
 
     /**
@@ -178,61 +184,6 @@ class BookmarkFilterTest extends TestCase
         );
     }
 
-    /**
-     * Return bookmarks for a given day
-     */
-    public function testFilterDay()
-    {
-        $this->assertEquals(
-            4,
-            count(self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20121206'))
-        );
-    }
-
-    /**
-     * Return bookmarks for a given day
-     */
-    public function testFilterDayRestrictedVisibility(): void
-    {
-        $this->assertEquals(
-            3,
-            count(self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20121206', false, BookmarkFilter::$PUBLIC))
-        );
-    }
-
-    /**
-     * 404 - day not found
-     */
-    public function testFilterUnknownDay()
-    {
-        $this->assertEquals(
-            0,
-            count(self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '19700101'))
-        );
-    }
-
-    /**
-     * Use an invalid date format
-     */
-    public function testFilterInvalidDayWithChars()
-    {
-        $this->expectException(\Exception::class);
-        $this->expectExceptionMessageRegExp('/Invalid date format/');
-
-        self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, 'Rainy day, dream away');
-    }
-
-    /**
-     * Use an invalid date format
-     */
-    public function testFilterInvalidDayDigits()
-    {
-        $this->expectException(\Exception::class);
-        $this->expectExceptionMessageRegExp('/Invalid date format/');
-
-        self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20');
-    }
-
     /**
      * Retrieve a link entry with its hash
      */
index 0c8420ce5ffceac84e4dd471cdc8f8fa567113d1..351807c16d5a5a574e0e4d6f92efba35bf07fe47 100644 (file)
@@ -5,6 +5,7 @@ namespace Shaarli\Bookmark;
 use malkusch\lock\mutex\NoMutex;
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Shaarli\TestCase;
 
 /**
@@ -38,6 +39,9 @@ class BookmarkInitializerTest extends TestCase
     /** @var NoMutex */
     protected $mutex;
 
+    /** @var PluginManager */
+    protected $pluginManager;
+
     /**
      * Initialize an empty BookmarkFileService
      */
@@ -51,8 +55,15 @@ class BookmarkInitializerTest extends TestCase
         copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
         $this->conf = new ConfigManager(self::$testConf);
         $this->conf->set('resource.datastore', self::$testDatastore);
+        $this->pluginManager = new PluginManager($this->conf);
         $this->history = new History('sandbox/history.php');
-        $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->bookmarkService = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
 
         $this->initializer = new BookmarkInitializer($this->bookmarkService);
     }
@@ -64,7 +75,13 @@ class BookmarkInitializerTest extends TestCase
     {
         $refDB = new \ReferenceLinkDB();
         $refDB->write(self::$testDatastore);
-        $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->bookmarkService = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
         $this->initializer = new BookmarkInitializer($this->bookmarkService);
 
         $this->initializer->initialize();
@@ -95,7 +112,13 @@ class BookmarkInitializerTest extends TestCase
         $this->bookmarkService->save();
 
         // Reload from file
-        $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->bookmarkService = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
         $this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count());
 
         $bookmark = $this->bookmarkService->get(43);
@@ -126,7 +149,13 @@ class BookmarkInitializerTest extends TestCase
     public function testInitializeNonExistentDataStore(): void
     {
         $this->conf->set('resource.datastore', static::$testDatastore . '_empty');
-        $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
+        $this->bookmarkService = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $this->mutex,
+            true
+        );
 
         $this->initializer->initialize();
 
index 6b9204eb64949cb17ada2c26bf605e7f9a3373a4..fe092f784a0591cba3073d8612ef8b655e659e54 100644 (file)
@@ -11,6 +11,7 @@ use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigManager;
 use Shaarli\Formatter\FormatterFactory;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Shaarli\TestCase;
 
 /**
@@ -55,8 +56,15 @@ class FeedBuilderTest extends TestCase
         $refLinkDB->write(self::$testDatastore);
         $history = new History('sandbox/history.php');
         $factory = new FormatterFactory($conf, true);
+        $pluginManager = new PluginManager($conf);
         self::$formatter = $factory->getFormatter();
-        self::$bookmarkService = new BookmarkFileService($conf, $history, $mutex, true);
+        self::$bookmarkService = new BookmarkFileService(
+            $conf,
+            $pluginManager,
+            $history,
+            $mutex,
+            true
+        );
 
         self::$serverInfo = array(
             'HTTPS' => 'Off',
index ad288f78ef802835f238e8d40f4c6c8d9bd2059d..b8a88cd83c235d2facc0acb57d8a2e3878a31c2b 100644 (file)
@@ -8,6 +8,7 @@ use Shaarli\Config\ConfigManager;
 use Shaarli\Formatter\BookmarkFormatter;
 use Shaarli\Formatter\FormatterFactory;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Shaarli\TestCase;
 
 require_once 'tests/utils/ReferenceLinkDB.php';
@@ -47,6 +48,9 @@ class BookmarkExportTest extends TestCase
      */
     protected static $history;
 
+    /** @var PluginManager */
+    protected static $pluginManager;
+
     /**
      * @var NetscapeBookmarkUtils
      */
@@ -63,7 +67,14 @@ class BookmarkExportTest extends TestCase
         static::$refDb = new \ReferenceLinkDB();
         static::$refDb->write(static::$testDatastore);
         static::$history = new History('sandbox/history.php');
-        static::$bookmarkService = new BookmarkFileService(static::$conf, static::$history, $mutex, true);
+        static::$pluginManager = new PluginManager(static::$conf);
+        static::$bookmarkService = new BookmarkFileService(
+            static::$conf,
+            static::$pluginManager,
+            static::$history,
+            $mutex,
+            true
+        );
         $factory = new FormatterFactory(static::$conf, true);
         static::$formatter = $factory->getFormatter('raw');
     }
index 6856ebcafebdecc18070638daa6430c6c71386da..ecd33ea1af16c1c212be81e0bd7a1aab062a03bb 100644 (file)
@@ -10,6 +10,7 @@ use Shaarli\Bookmark\BookmarkFileService;
 use Shaarli\Bookmark\BookmarkFilter;
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Shaarli\TestCase;
 use Slim\Http\UploadedFile;
 
@@ -71,6 +72,9 @@ class BookmarkImportTest extends TestCase
      */
     protected $netscapeBookmarkUtils;
 
+    /** @var PluginManager */
+    protected $pluginManager;
+
     /**
      * @var string Save the current timezone.
      */
@@ -99,7 +103,14 @@ class BookmarkImportTest extends TestCase
         $this->conf->set('resource.page_cache', $this->pagecache);
         $this->conf->set('resource.datastore', self::$testDatastore);
         $this->history = new History(self::$historyFilePath);
-        $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true);
+        $this->pluginManager = new PluginManager($this->conf);
+        $this->bookmarkService = new BookmarkFileService(
+            $this->conf,
+            $this->pluginManager,
+            $this->history,
+            $mutex,
+            true
+        );
         $this->netscapeBookmarkUtils = new NetscapeBookmarkUtils($this->bookmarkService, $this->conf, $this->history);
     }
 
index 34cd339e1a8cb84409f689d3a48f67dbb5124744..8dbb3f9464c8905fc5c5ed50f702102c1e3ec7a1 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Shaarli\Bookmark\Bookmark;
+
 /**
  * Hook for test.
  *
@@ -43,3 +45,8 @@ function test_register_routes(): array
         ],
     ];
 }
+
+function hook_test_filter_search_entry(Bookmark $bookmark, array $context): bool
+{
+    return $context['_result'];
+}
index cadd826538f2e76f08bffe27bb3d105abcf43375..a8539d63fc0262e05c3b361ead40195bd21d95d1 100644 (file)
@@ -7,6 +7,7 @@ use Shaarli\Bookmark\BookmarkFileService;
 use Shaarli\Bookmark\BookmarkServiceInterface;
 use Shaarli\Config\ConfigManager;
 use Shaarli\History;
+use Shaarli\Plugin\PluginManager;
 use Shaarli\TestCase;
 
 
@@ -51,7 +52,13 @@ class UpdaterTest extends TestCase
 
         copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php');
         $this->conf = new ConfigManager(self::$configFile);
-        $this->bookmarkService = new BookmarkFileService($this->conf, $this->createMock(History::class), $mutex, true);
+        $this->bookmarkService = new BookmarkFileService(
+            $this->conf,
+            $this->createMock(PluginManager::class),
+            $this->createMock(History::class),
+            $mutex,
+            true
+        );
         $this->updater = new Updater([], $this->bookmarkService, $this->conf, true);
     }