]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #1552 from ArthurHoaro/feature/better-initializer
authorArthurHoaro <arthur@hoa.ro>
Sat, 12 Sep 2020 10:14:18 +0000 (12:14 +0200)
committerGitHub <noreply@github.com>
Sat, 12 Sep 2020 10:14:18 +0000 (12:14 +0200)
16 files changed:
application/bookmark/BookmarkFileService.php
application/bookmark/BookmarkFilter.php
application/front/controller/admin/ShaarliAdminController.php
application/front/controller/visitor/FeedController.php
application/front/controller/visitor/ShaarliVisitorController.php
application/legacy/LegacyController.php
application/legacy/LegacyRouter.php
application/plugin/PluginManager.php
doc/md/Plugin-System.md
package.json
plugins/qrcode/qrcode.php
tests/bookmark/BookmarkFileServiceTest.php
tests/bookmark/BookmarkFilterTest.php
tests/front/controller/visitor/FeedControllerTest.php
tests/legacy/LegacyRouterTest.php [deleted file]
yarn.lock

index e3a611461a7aae9ecd3f0070a3341aa872aa737d..c9ec260930d159f8603f1f5c796fbec5612c08c2 100644 (file)
@@ -362,7 +362,9 @@ class BookmarkFileService implements BookmarkServiceInterface
      */
     public function filterDay($request)
     {
-        return $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_DAY, $request);
+        $visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC;
+
+        return $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_DAY, $request, false, $visibility);
     }
 
     /**
index 797a36b8ecd54c34a7aaea1ac63d3db0c2496bc8..6636bbfeec63e6e759154eda8bde4c377337d26c 100644 (file)
@@ -115,7 +115,7 @@ class BookmarkFilter
                     return $this->filterTags($request, $casesensitive, $visibility);
                 }
             case self::$FILTER_DAY:
-                return $this->filterDay($request);
+                return $this->filterDay($request, $visibility);
             default:
                 return $this->noFilter($visibility);
         }
@@ -425,21 +425,26 @@ class BookmarkFilter
      *  print_r($mydb->filterDay('20120125'));
      *
      * @param string $day day to filter.
-     *
+     * @param string $visibility return only all/private/public bookmarks.
+
      * @return array all link matching given day.
      *
      * @throws Exception if date format is invalid.
      */
-    public function filterDay($day)
+    public function filterDay($day, $visibility)
     {
         if (!checkDateFormat('Ymd', $day)) {
             throw new Exception('Invalid date format');
         }
 
         $filtered = [];
-        foreach ($this->bookmarks as $key => $l) {
-            if ($l->getCreated()->format('Ymd') == $day) {
-                $filtered[$key] = $l;
+        foreach ($this->bookmarks as $key => $bookmark) {
+            if ($visibility === static::$PUBLIC && $bookmark->isPrivate()) {
+                continue;
+            }
+
+            if ($bookmark->getCreated()->format('Ymd') == $day) {
+                $filtered[$key] = $bookmark;
             }
         }
 
index 3b5939bb6e73df4a7e9ab2083e966f06a3fdd3aa..c26c9cbe2e5050f42fa3da07f72e3d59d63939c0 100644 (file)
@@ -4,9 +4,7 @@ declare(strict_types=1);
 
 namespace Shaarli\Front\Controller\Admin;
 
-use Shaarli\Container\ShaarliContainer;
 use Shaarli\Front\Controller\Visitor\ShaarliVisitorController;
-use Shaarli\Front\Exception\UnauthorizedException;
 use Shaarli\Front\Exception\WrongTokenException;
 use Shaarli\Security\SessionManager;
 use Slim\Http\Request;
index da2848c2b0151b115d5d3427236a7f039c96265b..8d8b546aad35cc58573e0083b3ed9d283c0b71a7 100644 (file)
@@ -46,10 +46,10 @@ class FeedController extends ShaarliVisitorController
 
         $data = $this->container->feedBuilder->buildData($feedType, $request->getParams());
 
-        $this->executePageHooks('render_feed', $data, $feedType);
+        $this->executePageHooks('render_feed', $data, 'feed.' . $feedType);
         $this->assignAllView($data);
 
-        $content = $this->render('feed.'. $feedType);
+        $content = $this->render('feed.' . $feedType);
 
         $cache->cache($content);
 
index f17c8ed37936550304cfdfbe59735e98e677c4e4..cd27455bbf8d8810054e469fd564f89804c4c959 100644 (file)
@@ -78,16 +78,14 @@ abstract class ShaarliVisitorController
             'footer',
         ];
 
+        $parameters = $this->buildPluginParameters($template);
+
         foreach ($common_hooks as $name) {
             $pluginData = [];
             $this->container->pluginManager->executeHooks(
                 'render_' . $name,
                 $pluginData,
-                [
-                    'target' => $template,
-                    'loggedin' => $this->container->loginManager->isLoggedIn(),
-                    'basePath' => $this->container->basePath,
-                ]
+                $parameters
             );
             $this->assignView('plugins_' . $name, $pluginData);
         }
@@ -95,19 +93,23 @@ abstract class ShaarliVisitorController
 
     protected function executePageHooks(string $hook, array &$data, string $template = null): void
     {
-        $params = [
-            'target' => $template,
-            'loggedin' => $this->container->loginManager->isLoggedIn(),
-            'basePath' => $this->container->basePath,
-        ];
-
         $this->container->pluginManager->executeHooks(
             $hook,
             $data,
-            $params
+            $this->buildPluginParameters($template)
         );
     }
 
+    protected function buildPluginParameters(?string $template): array
+    {
+        return [
+            'target' => $template,
+            'loggedin' => $this->container->loginManager->isLoggedIn(),
+            'basePath' => $this->container->basePath,
+            'bookmarkService' => $this->container->bookmarkService
+        ];
+    }
+
     /**
      * Simple helper which prepend the base path to redirect path.
      *
index e16dd0f43effa6921b6238f0546e7357c9cea188..826604e77204f3726862890d0478ad5b448f7199 100644 (file)
@@ -39,13 +39,23 @@ class LegacyController extends ShaarliVisitorController
     /** Legacy route: ?post= */
     public function post(Request $request, Response $response): Response
     {
-        $parameters = count($request->getQueryParams()) > 0 ? '?' . http_build_query($request->getQueryParams()) : '';
         $route = '/admin/shaare';
+        $buildParameters = function (?array $parameters, bool $encode) {
+            if ($encode) {
+                $parameters = array_map('urlencode', $parameters);
+            }
+
+            return count($parameters) > 0 ? '?' . http_build_query($parameters) : '';
+        };
+
 
         if (!$this->container->loginManager->isLoggedIn()) {
+            $parameters = $buildParameters($request->getQueryParams(), true);
             return $this->redirect($response, '/login?returnurl='. $this->getBasePath() . $route . $parameters);
         }
 
+        $parameters = $buildParameters($request->getQueryParams(), false);
+
         return $this->redirect($response, $route . $parameters);
     }
 
index cea99154cd5885ad495156fd8cfcf68c746f89a5..0449c7e11db4e062ee75352958bd646363e7e4dd 100644 (file)
@@ -17,15 +17,15 @@ class LegacyRouter
 
     public static $PAGE_PICWALL = 'picwall';
 
-    public static $PAGE_TAGCLOUD = 'tagcloud';
+    public static $PAGE_TAGCLOUD = 'tag.cloud';
 
-    public static $PAGE_TAGLIST = 'taglist';
+    public static $PAGE_TAGLIST = 'tag.list';
 
     public static $PAGE_DAILY = 'daily';
 
-    public static $PAGE_FEED_ATOM = 'atom';
+    public static $PAGE_FEED_ATOM = 'feed.atom';
 
-    public static $PAGE_FEED_RSS = 'rss';
+    public static $PAGE_FEED_RSS = 'feed.rss';
 
     public static $PAGE_TOOLS = 'tools';
 
@@ -37,7 +37,7 @@ class LegacyRouter
 
     public static $PAGE_ADDLINK = 'addlink';
 
-    public static $PAGE_EDITLINK = 'edit_link';
+    public static $PAGE_EDITLINK = 'editlink';
 
     public static $PAGE_DELETELINK = 'delete_link';
 
@@ -60,128 +60,4 @@ class LegacyRouter
     public static $PAGE_THUMBS_UPDATE = 'thumbs_update';
 
     public static $GET_TOKEN = 'token';
-
-    /**
-     * Reproducing renderPage() if hell, to avoid regression.
-     *
-     * This highlights how bad this needs to be rewrite,
-     * but let's focus on plugins for now.
-     *
-     * @param string $query    $_SERVER['QUERY_STRING'].
-     * @param array  $get      $_SERVER['GET'].
-     * @param bool   $loggedIn true if authenticated user.
-     *
-     * @return string page found.
-     */
-    public static function findPage($query, $get, $loggedIn)
-    {
-        $loggedIn = ($loggedIn === true) ? true : false;
-
-        if (empty($query) && !isset($get['edit_link']) && !isset($get['post'])) {
-            return self::$PAGE_LINKLIST;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_LOGIN) && $loggedIn === false) {
-            return self::$PAGE_LOGIN;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_PICWALL)) {
-            return self::$PAGE_PICWALL;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_TAGCLOUD)) {
-            return self::$PAGE_TAGCLOUD;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_TAGLIST)) {
-            return self::$PAGE_TAGLIST;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_OPENSEARCH)) {
-            return self::$PAGE_OPENSEARCH;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_DAILY)) {
-            return self::$PAGE_DAILY;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_FEED_ATOM)) {
-            return self::$PAGE_FEED_ATOM;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_FEED_RSS)) {
-            return self::$PAGE_FEED_RSS;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_THUMBS_UPDATE)) {
-            return self::$PAGE_THUMBS_UPDATE;
-        }
-
-        if (startsWith($query, 'do=' . self::$AJAX_THUMB_UPDATE)) {
-            return self::$AJAX_THUMB_UPDATE;
-        }
-
-        // At this point, only loggedin pages.
-        if (!$loggedIn) {
-            return self::$PAGE_LINKLIST;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_TOOLS)) {
-            return self::$PAGE_TOOLS;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_CHANGEPASSWORD)) {
-            return self::$PAGE_CHANGEPASSWORD;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_CONFIGURE)) {
-            return self::$PAGE_CONFIGURE;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_CHANGETAG)) {
-            return self::$PAGE_CHANGETAG;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_ADDLINK)) {
-            return self::$PAGE_ADDLINK;
-        }
-
-        if (isset($get['edit_link']) || isset($get['post'])) {
-            return self::$PAGE_EDITLINK;
-        }
-
-        if (isset($get['delete_link'])) {
-            return self::$PAGE_DELETELINK;
-        }
-
-        if (isset($get[self::$PAGE_CHANGE_VISIBILITY])) {
-            return self::$PAGE_CHANGE_VISIBILITY;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_PINLINK)) {
-            return self::$PAGE_PINLINK;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_EXPORT)) {
-            return self::$PAGE_EXPORT;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_IMPORT)) {
-            return self::$PAGE_IMPORT;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_PLUGINSADMIN)) {
-            return self::$PAGE_PLUGINSADMIN;
-        }
-
-        if (startsWith($query, 'do=' . self::$PAGE_SAVE_PLUGINSADMIN)) {
-            return self::$PAGE_SAVE_PLUGINSADMIN;
-        }
-
-        if (startsWith($query, 'do=' . self::$GET_TOKEN)) {
-            return self::$GET_TOKEN;
-        }
-
-        return self::$PAGE_LINKLIST;
-    }
 }
index 2d93cb3a2173c58bada5803b8ca4fd522819991f..7881e3bea1675ad02b5d255fca316792cdd81f00 100644 (file)
@@ -112,6 +112,10 @@ class PluginManager
             $data['_BASE_PATH_'] = $params['basePath'];
         }
 
+        if (isset($params['bookmarkService'])) {
+            $data['_BOOKMARK_SERVICE_'] = $params['bookmarkService'];
+        }
+
         foreach ($this->loadedPlugins as $plugin) {
             $hookFunction = $this->buildHookName($hook, $plugin);
 
index f264e8735d79042506678327f1ae4e503b2a5738..87a2638dbea73fc3ef9262ccf7bd208af3ea8d81 100644 (file)
@@ -73,6 +73,26 @@ Every hook function has a `$data` parameter. Its content differs for each hooks.
 
     return $data;
 
+#### Special data
+
+Special additional data are passed to every hook through the
+`$data` parameter to give you access to additional context, and services.
+
+Complete list:
+
+  * `_PAGE_` (string): if the current hook is used to render a template, its name is passed through this additional parameter.
+  * `_LOGGEDIN_` (bool): whether the user is logged in or not.
+  * `_BASE_PATH_` (string): if Shaarli instance is hosted under a subfolder, contains the subfolder path to `index.php` (e.g. `https://domain.tld/shaarli/` -> `/shaarli/`).
+  * `_BOOKMARK_SERVICE_` (`BookmarkServiceInterface`): bookmark service instance, for advanced usage.
+
+Example:
+
+```php
+if ($data['_PAGE_'] === TemplatePage::LINKLIST && $data['LOGGEDIN'] === true) {
+    // Do something for logged in users when the link list is rendered
+}
+```
+
 #### Filling templates placeholder
 
 Template placeholders are displayed in template in specific places.
@@ -95,7 +115,7 @@ When a page is displayed, every variable send to the template engine is passed t
 
 The data contained by this array can be altered before template rendering.
 
-For exemple, in linklist, it is possible to alter every title:
+For example, in linklist, it is possible to alter every title:
 
 ```php
 // mind the reference if you want $data to be altered
@@ -156,8 +176,7 @@ Allow plugin to add content in page headers.
 
 `$data` is an array containing:
 
-- `_PAGE_`: current target page (eg: `linklist`, `picwall`, etc.).
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
+  - [Special data](#special-data)
 
 ##### Template placeholders
 
@@ -185,8 +204,7 @@ Allow plugin to include their own CSS files.
 
 `$data` is an array containing:
 
-- `_PAGE_`: current target page (eg: `linklist`, `picwall`, etc.).
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
+  - [Special data](#special-data)
 
 ##### Template placeholders
 
@@ -208,8 +226,7 @@ Allow plugin to add content in page footer and include their own JS files.
 
 `$data` is an array containing:
 
-- `_PAGE_`: current target page (eg: `linklist`, `picwall`, etc.).
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
+  - [Special data](#special-data)
 
 ##### Template placeholders
 
@@ -236,8 +253,8 @@ It allows to add content at the begining and end of the page, after every link d
 
 `$data` is an array containing:
 
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
-- All templates data, including links.
+  - All templates data, including links.
+  - [Special data](#special-data)
 
 ##### Template placeholders
 
@@ -271,7 +288,8 @@ Allow to add fields in the form, or display elements.
 
 `$data` is an array containing:
 
-- All templates data.
+  - All templates data.
+  - [Special data](#special-data)
 
 ##### Template placeholders
 
@@ -293,7 +311,8 @@ Allow to add content at the end of the page.
 
 `$data` is an array containing:
 
-- All templates data.
+  - All templates data.
+  - [Special data](#special-data)
 
 ##### Template placeholders
 
@@ -315,8 +334,8 @@ Allow to add content at the top and bottom of the page.
 
 `$data` is an array containing:
 
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
-- All templates data.
+  - All templates data.
+  - [Special data](#special-data)
 
 ##### Template placeholders
 
@@ -339,8 +358,8 @@ Allow to add content at the top and bottom of the page.
 
 `$data` is an array containing:
 
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
-- All templates data.
+  - All templates data.
+  - [Special data](#special-data)
 
 ##### Template placeholders
 
@@ -368,8 +387,8 @@ Allow to add content at the top and bottom of the page.
 
 `$data` is an array containing:
 
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
-- All templates data.
+  - All templates data.
+  - [Special data](#special-data)
 
 ##### Template placeholders
 
@@ -394,8 +413,8 @@ Allow to add content at the top and bottom of the page, the bottom of each link
 
 `$data` is an array containing:
 
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
-- All templates data, including links.
+  - All templates data, including links.
+  - [Special data](#special-data)
 
 ##### Template placeholders
 
@@ -420,9 +439,8 @@ Allow to add tags in the feed, either in the header or for each items. Items (li
 
 `$data` is an array containing:
 
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
-- `_PAGE_`: containing either `rss` or `atom`.
-- All templates data, including links.
+  - All templates data, including links.
+  - [Special data](#special-data)
 
 ##### Template placeholders
 
@@ -456,6 +474,8 @@ Allow to alter the link being saved in the datastore.
 - created
 - updated
 
+Also [special data](#special-data).
+
 
 #### delete_link
 
@@ -465,7 +485,7 @@ Allow to execute any action before the link is actually removed from the datasto
 
 ##### Data
 
-`$data` is an array containing the link being saved:
+`$data` is an array containing the link being deleted:
 
 - id
 - title
@@ -477,6 +497,7 @@ Allow to execute any action before the link is actually removed from the datasto
 - created
 - updated
 
+Also [special data](#special-data).
 
 #### save_plugin_parameters
 
@@ -492,6 +513,7 @@ For example it is used to update the CSS file of the `default_colors` plugins.
 So if the plugin has a parameter called `MYPLUGIN_PARAMETER`,
 the array will contain an entry with `MYPLUGIN_PARAMETER` as a key.
 
+Also [special data](#special-data).
 
 ## Guide for template designer
 
index f3d9b51eb2271002df8c617636dab110b011401d..dc2b287280b41593854aa31705a7a78d436b2f5c 100644 (file)
@@ -21,7 +21,7 @@
     "eslint-plugin-import": "^2.8.0",
     "extract-text-webpack-plugin": "^3.0.2",
     "file-loader": "^1.1.6",
-    "node-sass": "^4.12.0",
+    "node-sass": "^4.13.1",
     "sass-lint": "^1.12.1",
     "sass-loader": "^6.0.6",
     "style-loader": "^0.19.1",
index 3b5dae344dd63c3b688fc2d40ee8ff2af99e8f09..56ae47b30ad29b9ff46e085108b7e06c8638d61b 100644 (file)
@@ -42,7 +42,7 @@ function hook_qrcode_render_linklist($data)
 function hook_qrcode_render_footer($data)
 {
     if ($data['_PAGE_'] == TemplatePage::LINKLIST) {
-        $data['js_files'][] =  PluginManager::$PLUGINS_PATH . '/qrcode/shaarli-qrcode.js';
+        $data['js_files'][] =  ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH . '/qrcode/shaarli-qrcode.js';
     }
 
     return $data;
@@ -58,7 +58,7 @@ function hook_qrcode_render_footer($data)
 function hook_qrcode_render_includes($data)
 {
     if ($data['_PAGE_'] == TemplatePage::LINKLIST) {
-        $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.css';
+        $data['css_files'][] = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.css';
     }
 
     return $data;
index a91f374f0f984f9f3a2357a962192945e9c588b4..a4ec10138b75c30bfb6a78c9726f3dc9f49229bf 100644 (file)
@@ -1065,6 +1065,36 @@ class BookmarkFileServiceTest extends TestCase
         $this->assertEquals($expected, $tags, var_export($tags, true));
     }
 
+    /**
+     * Test filterDay while logged in
+     */
+    public function testFilterDayLoggedIn(): void
+    {
+        $bookmarks = $this->privateLinkDB->filterDay('20121206');
+        $expectedIds = [4, 9, 1, 0];
+
+        static::assertCount(4, $bookmarks);
+        foreach ($bookmarks as $bookmark) {
+            $i = ($i ?? -1) + 1;
+            static::assertSame($expectedIds[$i], $bookmark->getId());
+        }
+    }
+
+    /**
+     * Test filterDay while logged out
+     */
+    public function testFilterDayLoggedOut(): void
+    {
+        $bookmarks = $this->publicLinkDB->filterDay('20121206');
+        $expectedIds = [4, 9, 1];
+
+        static::assertCount(3, $bookmarks);
+        foreach ($bookmarks as $bookmark) {
+            $i = ($i ?? -1) + 1;
+            static::assertSame($expectedIds[$i], $bookmark->getId());
+        }
+    }
+
     /**
      * Allows to test LinkDB's private methods
      *
index d4c71cb94388ca86dede43b8c9054ce96f4e8261..91e139c20e283ad59982001ce04064fcfcccaa41 100644 (file)
@@ -6,7 +6,6 @@ use Exception;
 use PHPUnit\Framework\TestCase;
 use ReferenceLinkDB;
 use Shaarli\Config\ConfigManager;
-use Shaarli\Formatter\FormatterFactory;
 use Shaarli\History;
 
 /**
@@ -36,7 +35,7 @@ class BookmarkFilterTest extends TestCase
     /**
      * Instantiate linkFilter with ReferenceLinkDB data.
      */
-    public static function setUpBeforeClass()
+    public static function setUpBeforeClass(): void
     {
         $conf = new ConfigManager('tests/utils/config/configJson');
         $conf->set('resource.datastore', self::$testDatastore);
@@ -189,6 +188,17 @@ class BookmarkFilterTest extends TestCase
         );
     }
 
+    /**
+     * 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
      */
index fb417e2a2b152f1a6c52e166c275afda7ab1e190..0a6b577f4dd2f3d19ce1383a641852f2fd6766f1 100644 (file)
@@ -52,7 +52,7 @@ class FeedControllerTest extends TestCase
                 static::assertSame('data', $data['content']);
 
                 static::assertArrayHasKey('loggedin', $param);
-                static::assertSame('rss', $param['target']);
+                static::assertSame('feed.rss', $param['target']);
             })
         ;
 
@@ -91,7 +91,7 @@ class FeedControllerTest extends TestCase
                 static::assertSame('data', $data['content']);
 
                 static::assertArrayHasKey('loggedin', $param);
-                static::assertSame('atom', $param['target']);
+                static::assertSame('feed.atom', $param['target']);
             })
         ;
 
@@ -131,7 +131,7 @@ class FeedControllerTest extends TestCase
                 static::assertSame('data', $data['content']);
 
                 static::assertArrayHasKey('loggedin', $param);
-                static::assertSame('atom', $param['target']);
+                static::assertSame('feed.atom', $param['target']);
             })
         ;
 
diff --git a/tests/legacy/LegacyRouterTest.php b/tests/legacy/LegacyRouterTest.php
deleted file mode 100644 (file)
index c2019ca..0000000
+++ /dev/null
@@ -1,512 +0,0 @@
-<?php
-
-namespace Shaarli\Legacy;
-
-use PHPUnit\Framework\TestCase;
-
-/**
- * Unit tests for Router
- */
-class LegacyRouterTest extends TestCase
-{
-    /**
-     * Test findPage: login page output.
-     * Valid: page should be return.
-     *
-     * @return void
-     */
-    public function testFindPageLoginValid()
-    {
-        $this->assertEquals(
-            LegacyRouter::$PAGE_LOGIN,
-            LegacyRouter::findPage('do=login', array(), false)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_LOGIN,
-            LegacyRouter::findPage('do=login', array(), 1)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_LOGIN,
-            LegacyRouter::findPage('do=login&stuff', array(), false)
-        );
-    }
-
-    /**
-     * Test findPage: login page output.
-     * Invalid: page shouldn't be return.
-     *
-     * @return void
-     */
-    public function testFindPageLoginInvalid()
-    {
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_LOGIN,
-            LegacyRouter::findPage('do=login', array(), true)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_LOGIN,
-            LegacyRouter::findPage('do=other', array(), false)
-        );
-    }
-
-    /**
-     * Test findPage: picwall page output.
-     * Valid: page should be return.
-     *
-     * @return void
-     */
-    public function testFindPagePicwallValid()
-    {
-        $this->assertEquals(
-            LegacyRouter::$PAGE_PICWALL,
-            LegacyRouter::findPage('do=picwall', array(), false)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_PICWALL,
-            LegacyRouter::findPage('do=picwall', array(), true)
-        );
-    }
-
-    /**
-     * Test findPage: picwall page output.
-     * Invalid: page shouldn't be return.
-     *
-     * @return void
-     */
-    public function testFindPagePicwallInvalid()
-    {
-        $this->assertEquals(
-            LegacyRouter::$PAGE_PICWALL,
-            LegacyRouter::findPage('do=picwall&stuff', array(), false)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_PICWALL,
-            LegacyRouter::findPage('do=other', array(), false)
-        );
-    }
-
-    /**
-     * Test findPage: tagcloud page output.
-     * Valid: page should be return.
-     *
-     * @return void
-     */
-    public function testFindPageTagcloudValid()
-    {
-        $this->assertEquals(
-            LegacyRouter::$PAGE_TAGCLOUD,
-            LegacyRouter::findPage('do=tagcloud', array(), false)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_TAGCLOUD,
-            LegacyRouter::findPage('do=tagcloud', array(), true)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_TAGCLOUD,
-            LegacyRouter::findPage('do=tagcloud&stuff', array(), false)
-        );
-    }
-
-    /**
-     * Test findPage: tagcloud page output.
-     * Invalid: page shouldn't be return.
-     *
-     * @return void
-     */
-    public function testFindPageTagcloudInvalid()
-    {
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_TAGCLOUD,
-            LegacyRouter::findPage('do=other', array(), false)
-        );
-    }
-
-    /**
-     * Test findPage: linklist page output.
-     * Valid: page should be return.
-     *
-     * @return void
-     */
-    public function testFindPageLinklistValid()
-    {
-        $this->assertEquals(
-            LegacyRouter::$PAGE_LINKLIST,
-            LegacyRouter::findPage('', array(), true)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_LINKLIST,
-            LegacyRouter::findPage('whatever', array(), true)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_LINKLIST,
-            LegacyRouter::findPage('whatever', array(), false)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_LINKLIST,
-            LegacyRouter::findPage('do=tools', array(), false)
-        );
-    }
-
-    /**
-     * Test findPage: tools page output.
-     * Valid: page should be return.
-     *
-     * @return void
-     */
-    public function testFindPageToolsValid()
-    {
-        $this->assertEquals(
-            LegacyRouter::$PAGE_TOOLS,
-            LegacyRouter::findPage('do=tools', array(), true)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_TOOLS,
-            LegacyRouter::findPage('do=tools&stuff', array(), true)
-        );
-    }
-
-    /**
-     * Test findPage: tools page output.
-     * Invalid: page shouldn't be return.
-     *
-     * @return void
-     */
-    public function testFindPageToolsInvalid()
-    {
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_TOOLS,
-            LegacyRouter::findPage('do=tools', array(), 1)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_TOOLS,
-            LegacyRouter::findPage('do=tools', array(), false)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_TOOLS,
-            LegacyRouter::findPage('do=other', array(), true)
-        );
-    }
-
-    /**
-     * Test findPage: changepasswd page output.
-     * Valid: page should be return.
-     *
-     * @return void
-     */
-    public function testFindPageChangepasswdValid()
-    {
-        $this->assertEquals(
-            LegacyRouter::$PAGE_CHANGEPASSWORD,
-            LegacyRouter::findPage('do=changepasswd', array(), true)
-        );
-        $this->assertEquals(
-            LegacyRouter::$PAGE_CHANGEPASSWORD,
-            LegacyRouter::findPage('do=changepasswd&stuff', array(), true)
-        );
-    }
-
-    /**
-     * Test findPage: changepasswd page output.
-     * Invalid: page shouldn't be return.
-     *
-     * @return void
-     */
-    public function testFindPageChangepasswdInvalid()
-    {
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_CHANGEPASSWORD,
-            LegacyRouter::findPage('do=changepasswd', array(), 1)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_CHANGEPASSWORD,
-            LegacyRouter::findPage('do=changepasswd', array(), false)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_CHANGEPASSWORD,
-            LegacyRouter::findPage('do=other', array(), true)
-        );
-    }
-    /**
-     * Test findPage: configure page output.
-     * Valid: page should be return.
-     *
-     * @return void
-     */
-    public function testFindPageConfigureValid()
-    {
-        $this->assertEquals(
-            LegacyRouter::$PAGE_CONFIGURE,
-            LegacyRouter::findPage('do=configure', array(), true)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_CONFIGURE,
-            LegacyRouter::findPage('do=configure&stuff', array(), true)
-        );
-    }
-
-    /**
-     * Test findPage: configure page output.
-     * Invalid: page shouldn't be return.
-     *
-     * @return void
-     */
-    public function testFindPageConfigureInvalid()
-    {
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_CONFIGURE,
-            LegacyRouter::findPage('do=configure', array(), 1)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_CONFIGURE,
-            LegacyRouter::findPage('do=configure', array(), false)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_CONFIGURE,
-            LegacyRouter::findPage('do=other', array(), true)
-        );
-    }
-
-    /**
-     * Test findPage: changetag page output.
-     * Valid: page should be return.
-     *
-     * @return void
-     */
-    public function testFindPageChangetagValid()
-    {
-        $this->assertEquals(
-            LegacyRouter::$PAGE_CHANGETAG,
-            LegacyRouter::findPage('do=changetag', array(), true)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_CHANGETAG,
-            LegacyRouter::findPage('do=changetag&stuff', array(), true)
-        );
-    }
-
-    /**
-     * Test findPage: changetag page output.
-     * Invalid: page shouldn't be return.
-     *
-     * @return void
-     */
-    public function testFindPageChangetagInvalid()
-    {
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_CHANGETAG,
-            LegacyRouter::findPage('do=changetag', array(), 1)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_CHANGETAG,
-            LegacyRouter::findPage('do=changetag', array(), false)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_CHANGETAG,
-            LegacyRouter::findPage('do=other', array(), true)
-        );
-    }
-
-    /**
-     * Test findPage: addlink page output.
-     * Valid: page should be return.
-     *
-     * @return void
-     */
-    public function testFindPageAddlinkValid()
-    {
-        $this->assertEquals(
-            LegacyRouter::$PAGE_ADDLINK,
-            LegacyRouter::findPage('do=addlink', array(), true)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_ADDLINK,
-            LegacyRouter::findPage('do=addlink&stuff', array(), true)
-        );
-    }
-
-    /**
-     * Test findPage: addlink page output.
-     * Invalid: page shouldn't be return.
-     *
-     * @return void
-     */
-    public function testFindPageAddlinkInvalid()
-    {
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_ADDLINK,
-            LegacyRouter::findPage('do=addlink', array(), 1)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_ADDLINK,
-            LegacyRouter::findPage('do=addlink', array(), false)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_ADDLINK,
-            LegacyRouter::findPage('do=other', array(), true)
-        );
-    }
-
-    /**
-     * Test findPage: export page output.
-     * Valid: page should be return.
-     *
-     * @return void
-     */
-    public function testFindPageExportValid()
-    {
-        $this->assertEquals(
-            LegacyRouter::$PAGE_EXPORT,
-            LegacyRouter::findPage('do=export', array(), true)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_EXPORT,
-            LegacyRouter::findPage('do=export&stuff', array(), true)
-        );
-    }
-
-    /**
-     * Test findPage: export page output.
-     * Invalid: page shouldn't be return.
-     *
-     * @return void
-     */
-    public function testFindPageExportInvalid()
-    {
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_EXPORT,
-            LegacyRouter::findPage('do=export', array(), 1)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_EXPORT,
-            LegacyRouter::findPage('do=export', array(), false)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_EXPORT,
-            LegacyRouter::findPage('do=other', array(), true)
-        );
-    }
-
-    /**
-     * Test findPage: import page output.
-     * Valid: page should be return.
-     *
-     * @return void
-     */
-    public function testFindPageImportValid()
-    {
-        $this->assertEquals(
-            LegacyRouter::$PAGE_IMPORT,
-            LegacyRouter::findPage('do=import', array(), true)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_IMPORT,
-            LegacyRouter::findPage('do=import&stuff', array(), true)
-        );
-    }
-
-    /**
-     * Test findPage: import page output.
-     * Invalid: page shouldn't be return.
-     *
-     * @return void
-     */
-    public function testFindPageImportInvalid()
-    {
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_IMPORT,
-            LegacyRouter::findPage('do=import', array(), 1)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_IMPORT,
-            LegacyRouter::findPage('do=import', array(), false)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_IMPORT,
-            LegacyRouter::findPage('do=other', array(), true)
-        );
-    }
-
-    /**
-     * Test findPage: editlink page output.
-     * Valid: page should be return.
-     *
-     * @return void
-     */
-    public function testFindPageEditlinkValid()
-    {
-        $this->assertEquals(
-            LegacyRouter::$PAGE_EDITLINK,
-            LegacyRouter::findPage('whatever', array('edit_link' => 1), true)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_EDITLINK,
-            LegacyRouter::findPage('', array('edit_link' => 1), true)
-        );
-
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_EDITLINK,
-            LegacyRouter::findPage('whatever', array('post' => 1), true)
-        );
-
-        $this->assertEquals(
-            LegacyRouter::$PAGE_EDITLINK,
-            LegacyRouter::findPage('whatever', array('post' => 1, 'edit_link' => 1), true)
-        );
-    }
-
-    /**
-     * Test findPage: editlink page output.
-     * Invalid: page shouldn't be return.
-     *
-     * @return void
-     */
-    public function testFindPageEditlinkInvalid()
-    {
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_EDITLINK,
-            LegacyRouter::findPage('whatever', array('edit_link' => 1), false)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_EDITLINK,
-            LegacyRouter::findPage('whatever', array('edit_link' => 1), 1)
-        );
-
-        $this->assertNotEquals(
-            LegacyRouter::$PAGE_EDITLINK,
-            LegacyRouter::findPage('whatever', array(), true)
-        );
-    }
-}
index df6479505770634460f8b5c5ddc6e12eba09f3af..a7ddcfd3dd176c29e6bd19800e339cfc69a6576d 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -3432,10 +3432,10 @@ lodash.uniq@^4.5.0:
   resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
   integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=
 
-lodash@^4.0.0, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.3.0, lodash@~4.17.10:
-  version "4.17.19"
-  resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b"
-  integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==
+lodash@^4.0.0, lodash@^4.17.11, lodash@^4.17.15, lodash@^4.17.4, lodash@^4.3.0, lodash@~4.17.10:
+  version "4.17.20"
+  resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52"
+  integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==
 
 longest@^1.0.1:
   version "1.0.1"
@@ -3787,10 +3787,10 @@ node-pre-gyp@^0.12.0:
     semver "^5.3.0"
     tar "^4"
 
-node-sass@^4.12.0:
-  version "4.12.0"
-  resolved "https://registry.yarnpkg.com/node-sass/-/node-sass-4.12.0.tgz#0914f531932380114a30cc5fa4fa63233a25f017"
-  integrity sha512-A1Iv4oN+Iel6EPv77/HddXErL2a+gZ4uBeZUy+a8O35CFYTXhgA8MgLCWBtwpGZdCvTvQ9d+bQxX/QC36GDPpQ==
+node-sass@^4.13.1:
+  version "4.13.1"
+  resolved "https://registry.yarnpkg.com/node-sass/-/node-sass-4.13.1.tgz#9db5689696bb2eec2c32b98bfea4c7a2e992d0a3"
+  integrity sha512-TTWFx+ZhyDx1Biiez2nB0L3YrCZ/8oHagaDalbuBSlqXgUPsdkUSzJsVxeDO9LtPB49+Fh3WQl3slABo6AotNw==
   dependencies:
     async-foreach "^0.1.3"
     chalk "^1.1.1"
@@ -3799,7 +3799,7 @@ node-sass@^4.12.0:
     get-stdin "^4.0.1"
     glob "^7.0.3"
     in-publish "^2.0.0"
-    lodash "^4.17.11"
+    lodash "^4.17.15"
     meow "^3.7.0"
     mkdirp "^0.5.1"
     nan "^2.13.2"