]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Initialize admin Slim controllers
authorArthurHoaro <arthur@hoa.ro>
Fri, 22 May 2020 11:20:31 +0000 (13:20 +0200)
committerArthurHoaro <arthur@hoa.ro>
Thu, 23 Jul 2020 19:19:21 +0000 (21:19 +0200)
  - Reorganize visitor controllers
  - Fix redirection with Slim's requests base path
  - Fix daily links

35 files changed:
application/front/ShaarliMiddleware.php
application/front/controller/admin/LogoutController.php [moved from application/front/controllers/LogoutController.php with 86% similarity]
application/front/controller/admin/SessionFilterController.php [moved from application/front/controllers/SessionFilterController.php with 84% similarity]
application/front/controller/admin/ShaarliAdminController.php [new file with mode: 0644]
application/front/controller/visitor/DailyController.php [moved from application/front/controllers/DailyController.php with 98% similarity]
application/front/controller/visitor/FeedController.php [moved from application/front/controllers/FeedController.php with 95% similarity]
application/front/controller/visitor/LoginController.php [moved from application/front/controllers/LoginController.php with 92% similarity]
application/front/controller/visitor/OpenSearchController.php [moved from application/front/controllers/OpenSearchController.php with 83% similarity]
application/front/controller/visitor/PictureWallController.php [moved from application/front/controllers/PictureWallController.php with 94% similarity]
application/front/controller/visitor/ShaarliVisitorController.php [moved from application/front/controllers/ShaarliController.php with 91% similarity]
application/front/controller/visitor/TagCloudController.php [moved from application/front/controllers/TagCloudController.php with 97% similarity]
application/front/controller/visitor/TagController.php [moved from application/front/controllers/TagController.php with 97% similarity]
application/front/exceptions/LoginBannedException.php
application/front/exceptions/ShaarliFrontException.php [moved from application/front/exceptions/ShaarliException.php with 90% similarity]
application/front/exceptions/ThumbnailsDisabledException.php
application/front/exceptions/UnauthorizedException.php [new file with mode: 0644]
composer.json
doc/md/Translations.md
index.php
tests/bootstrap.php
tests/front/controller/admin/FrontAdminControllerMockHelper.php [new file with mode: 0644]
tests/front/controller/admin/LogoutControllerTest.php [moved from tests/front/controller/LogoutControllerTest.php with 95% similarity]
tests/front/controller/admin/SessionFilterControllerTest.php [moved from tests/front/controller/SessionFilterControllerTest.php with 79% similarity]
tests/front/controller/visitor/DailyControllerTest.php [moved from tests/front/controller/DailyControllerTest.php with 99% similarity]
tests/front/controller/visitor/FeedControllerTest.php [moved from tests/front/controller/FeedControllerTest.php with 99% similarity]
tests/front/controller/visitor/FrontControllerMockHelper.php [moved from tests/front/controller/FrontControllerMockHelper.php with 98% similarity]
tests/front/controller/visitor/LoginControllerTest.php [moved from tests/front/controller/LoginControllerTest.php with 99% similarity]
tests/front/controller/visitor/OpenSearchControllerTest.php [moved from tests/front/controller/OpenSearchControllerTest.php with 89% similarity]
tests/front/controller/visitor/PictureWallControllerTest.php [moved from tests/front/controller/PictureWallControllerTest.php with 99% similarity]
tests/front/controller/visitor/ShaarliPublicControllerTest.php [moved from tests/front/controller/ShaarliControllerTest.php with 82% similarity]
tests/front/controller/visitor/TagCloudControllerTest.php [moved from tests/front/controller/TagCloudControllerTest.php with 99% similarity]
tests/front/controller/visitor/TagControllerTest.php [moved from tests/front/controller/TagControllerTest.php with 98% similarity]
tpl/default/page.header.html
tpl/vintage/daily.html
tpl/vintage/page.header.html

index fa6c64671d56b9db1ee43cd4c13f71ef15f30958..f8992e0b333fa8e3ebeb853c5ceb8ea8e423625c 100644 (file)
@@ -3,7 +3,8 @@
 namespace Shaarli\Front;
 
 use Shaarli\Container\ShaarliContainer;
-use Shaarli\Front\Exception\ShaarliException;
+use Shaarli\Front\Exception\ShaarliFrontException;
+use Shaarli\Front\Exception\UnauthorizedException;
 use Slim\Http\Request;
 use Slim\Http\Response;
 
@@ -39,7 +40,7 @@ class ShaarliMiddleware
     {
         try {
             $response = $next($request, $response);
-        } catch (ShaarliException $e) {
+        } catch (ShaarliFrontException $e) {
             $this->container->pageBuilder->assign('message', $e->getMessage());
             if ($this->container->conf->get('dev.debug', false)) {
                 $this->container->pageBuilder->assign(
@@ -50,6 +51,8 @@ class ShaarliMiddleware
 
             $response = $response->withStatus($e->getCode());
             $response = $response->write($this->container->pageBuilder->render('error'));
+        } catch (UnauthorizedException $e) {
+            return $response->withRedirect($request->getUri()->getBasePath() . '/login');
         }
 
         return $response;
similarity index 86%
rename from application/front/controllers/LogoutController.php
rename to application/front/controller/admin/LogoutController.php
index aba078c33d20b0df4902baa3c45c229bbda61af7..41e81984a4c89ef6407e3e0c3463dfe0e649a473 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Admin;
 
 use Shaarli\Security\LoginManager;
 use Slim\Http\Request;
@@ -13,10 +13,8 @@ use Slim\Http\Response;
  *
  * Slim controller used to logout the user.
  * It invalidates page cache and terminate the user session. Then it redirects to the homepage.
- *
- * @package Front\Controller
  */
-class LogoutController extends ShaarliController
+class LogoutController extends ShaarliAdminController
 {
     public function index(Request $request, Response $response): Response
     {
similarity index 84%
rename from application/front/controllers/SessionFilterController.php
rename to application/front/controller/admin/SessionFilterController.php
index a021dc37397571c487aa7026b68eb6cbdc3208b3..69a16ec3a5f45b39410f3d2d49acb74cf1e741f3 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Admin;
 
 use Shaarli\Bookmark\BookmarkFilter;
 use Shaarli\Security\SessionManager;
@@ -13,10 +13,8 @@ use Slim\Http\Response;
  * Class SessionFilterController
  *
  * Slim controller used to handle filters stored in the user session, such as visibility, links per page, etc.
- *
- * @package Shaarli\Front\Controller
  */
-class SessionFilterController extends ShaarliController
+class SessionFilterController extends ShaarliAdminController
 {
     /**
      * GET /links-per-page: set the number of bookmarks to display per page in homepage
@@ -33,7 +31,7 @@ class SessionFilterController extends ShaarliController
             abs(intval($linksPerPage))
         );
 
-        return $this->redirectFromReferer($response, ['linksperpage'], ['nb']);
+        return $this->redirectFromReferer($request, $response, ['linksperpage'], ['nb']);
     }
 
     /**
@@ -42,7 +40,7 @@ class SessionFilterController extends ShaarliController
     public function visibility(Request $request, Response $response, array $args): Response
     {
         if (false === $this->container->loginManager->isLoggedIn()) {
-            return $this->redirectFromReferer($response, ['visibility']);
+            return $this->redirectFromReferer($request, $response, ['visibility']);
         }
 
         $newVisibility = $args['visibility'] ?? null;
@@ -63,7 +61,7 @@ class SessionFilterController extends ShaarliController
             $this->container->sessionManager->deleteSessionParameter(SessionManager::KEY_VISIBILITY);
         }
 
-        return $this->redirectFromReferer($response, ['visibility']);
+        return $this->redirectFromReferer($request, $response, ['visibility']);
     }
 
     /**
@@ -76,6 +74,6 @@ class SessionFilterController extends ShaarliController
             empty($this->container->sessionManager->getSessionParameter(SessionManager::KEY_UNTAGGED_ONLY))
         );
 
-        return $this->redirectFromReferer($response, ['untaggedonly', 'untagged-only']);
+        return $this->redirectFromReferer($request, $response, ['untaggedonly', 'untagged-only']);
     }
 }
diff --git a/application/front/controller/admin/ShaarliAdminController.php b/application/front/controller/admin/ShaarliAdminController.php
new file mode 100644 (file)
index 0000000..ea703f6
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Shaarli\Front\Controller\Admin;
+
+use Shaarli\Container\ShaarliContainer;
+use Shaarli\Front\Controller\Visitor\ShaarliVisitorController;
+use Shaarli\Front\Exception\UnauthorizedException;
+
+abstract class ShaarliAdminController extends ShaarliVisitorController
+{
+    public function __construct(ShaarliContainer $container)
+    {
+        parent::__construct($container);
+
+        if (true !== $this->container->loginManager->isLoggedIn()) {
+            throw new UnauthorizedException();
+        }
+    }
+}
similarity index 98%
rename from application/front/controllers/DailyController.php
rename to application/front/controller/visitor/DailyController.php
index 4a0735aa60e42929204cef4a81aff6b640607df6..47e2503a677093011c2fb542ee484e8781b89c85 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use DateTime;
 use DateTimeImmutable;
@@ -14,10 +14,8 @@ use Slim\Http\Response;
  * Class DailyController
  *
  * Slim controller used to render the daily page.
- *
- * @package Front\Controller
  */
-class DailyController extends ShaarliController
+class DailyController extends ShaarliVisitorController
 {
     public static $DAILY_RSS_NB_DAYS = 8;
 
similarity index 95%
rename from application/front/controllers/FeedController.php
rename to application/front/controller/visitor/FeedController.php
index 78d826d96b1c141c0fbb2c63fe62a5368683f801..70664635b454976e0875ecbba381308e13b74a78 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use Shaarli\Feed\FeedBuilder;
 use Slim\Http\Request;
@@ -12,10 +12,8 @@ use Slim\Http\Response;
  * Class FeedController
  *
  * Slim controller handling ATOM and RSS feed.
- *
- * @package Front\Controller
  */
-class FeedController extends ShaarliController
+class FeedController extends ShaarliVisitorController
 {
     public function atom(Request $request, Response $response): Response
     {
similarity index 92%
rename from application/front/controllers/LoginController.php
rename to application/front/controller/visitor/LoginController.php
index ae3599e0452d93d3edd6b13941b4c48cf47e0222..4de2f55db0fce3e991bd1f380720a2c852725f95 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use Shaarli\Front\Exception\LoginBannedException;
 use Slim\Http\Request;
@@ -15,10 +15,8 @@ use Slim\Http\Response;
  *
  * The login page is not available if the user is banned
  * or if open shaarli setting is enabled.
- *
- * @package Front\Controller
  */
-class LoginController extends ShaarliController
+class LoginController extends ShaarliVisitorController
 {
     public function index(Request $request, Response $response): Response
     {
similarity index 83%
rename from application/front/controllers/OpenSearchController.php
rename to application/front/controller/visitor/OpenSearchController.php
index fa32c5f11094eecde632abdf1dc5087f886f371d..0fd68db66ac55ce0b2e69361afe3aa1038c3e23e 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use Slim\Http\Request;
 use Slim\Http\Response;
@@ -12,10 +12,8 @@ use Slim\Http\Response;
  *
  * Slim controller used to render open search template.
  * This allows to add Shaarli as a search engine within the browser.
- *
- * @package front\controllers
  */
-class OpenSearchController extends ShaarliController
+class OpenSearchController extends ShaarliVisitorController
 {
     public function index(Request $request, Response $response): Response
     {
similarity index 94%
rename from application/front/controllers/PictureWallController.php
rename to application/front/controller/visitor/PictureWallController.php
index 08d31b291889df2cc0d12023c1ce6e221725aee6..4e1dce8c9b31411cadcd0b1a4fe72ffb540c6e19 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use Shaarli\Front\Exception\ThumbnailsDisabledException;
 use Shaarli\Thumbnailer;
@@ -14,10 +14,8 @@ use Slim\Http\Response;
  *
  * Slim controller used to render the pictures wall page.
  * If thumbnails mode is set to NONE, we just render the template without any image.
- *
- * @package Front\Controller
  */
-class PictureWallController extends ShaarliController
+class PictureWallController extends ShaarliVisitorController
 {
     public function index(Request $request, Response $response): Response
     {
similarity index 91%
rename from application/front/controllers/ShaarliController.php
rename to application/front/controller/visitor/ShaarliVisitorController.php
index bfff5fcf636ccd64942176655293e346ce702fa3..655b3baa294ce2f639163e6ab9a820b744ae4cf7 100644 (file)
@@ -2,13 +2,14 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use Shaarli\Bookmark\BookmarkFilter;
 use Shaarli\Container\ShaarliContainer;
+use Slim\Http\Request;
 use Slim\Http\Response;
 
-abstract class ShaarliController
+abstract class ShaarliVisitorController
 {
     /** @var ShaarliContainer */
     protected $container;
@@ -89,9 +90,13 @@ abstract class ShaarliController
      * @param array $loopTerms   Terms to remove from path and query string to prevent direction loop.
      * @param array $clearParams List of parameter to remove from the query string of the referrer.
      */
-    protected function redirectFromReferer(Response $response, array $loopTerms = [], array $clearParams = []): Response
-    {
-        $defaultPath = './';
+    protected function redirectFromReferer(
+        Request $request,
+        Response $response,
+        array $loopTerms = [],
+        array $clearParams = []
+    ): Response {
+        $defaultPath = $request->getUri()->getBasePath();
         $referer = $this->container->environment['HTTP_REFERER'] ?? null;
 
         if (null !== $referer) {
similarity index 97%
rename from application/front/controllers/TagCloudController.php
rename to application/front/controller/visitor/TagCloudController.php
index 1ff7c2e696792d4442388900a5eac0aeadf3a5b0..15b6d7b78b65565c2b166bb30635cbe80d4227fa 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use Slim\Http\Request;
 use Slim\Http\Response;
@@ -11,10 +11,8 @@ use Slim\Http\Response;
  * Class TagCloud
  *
  * Slim controller used to render the tag cloud and tag list pages.
- *
- * @package Front\Controller
  */
-class TagCloudController extends ShaarliController
+class TagCloudController extends ShaarliVisitorController
 {
     protected const TYPE_CLOUD = 'cloud';
     protected const TYPE_LIST = 'list';
similarity index 97%
rename from application/front/controllers/TagController.php
rename to application/front/controller/visitor/TagController.php
index a1d5ad5b0150a176ed320b658953cdec5016425e..a0bc1d1b633db4151758e18dddc2a1d0947fc9e7 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use Slim\Http\Request;
 use Slim\Http\Response;
@@ -11,10 +11,8 @@ use Slim\Http\Response;
  * Class TagController
  *
  * Slim controller handle tags.
- *
- * @package Front\Controller
  */
-class TagController extends ShaarliController
+class TagController extends ShaarliVisitorController
 {
     /**
      * Add another tag in the current search through an HTTP redirection.
index b31a4a14ead0015f49195b11c0e584193abfa24c..79d0ea152ad21428102cc99a9ee2117cac4509cc 100644 (file)
@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace Shaarli\Front\Exception;
 
-class LoginBannedException extends ShaarliException
+class LoginBannedException extends ShaarliFrontException
 {
     public function __construct()
     {
similarity index 90%
rename from application/front/exceptions/ShaarliException.php
rename to application/front/exceptions/ShaarliFrontException.php
index 800bfbec34c619c09eb7d653aca58303758896d1..fc8eb92be5d2c0f041fd0ed8814708017e6f0585 100644 (file)
@@ -13,7 +13,7 @@ use Throwable;
  *
  * @package Front\Exception
  */
-abstract class ShaarliException extends \Exception
+abstract class ShaarliFrontException extends \Exception
 {
     /** Override parent constructor to force $message and $httpCode parameters to be set. */
     public function __construct(string $message, int $httpCode, Throwable $previous = null)
index 1b9cf5b71f9b8854bd8fa06564395207f7a2a024..0ed337f5cfa912bec85411e571d249e82a793877 100644 (file)
@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace Shaarli\Front\Exception;
 
-class ThumbnailsDisabledException extends ShaarliException
+class ThumbnailsDisabledException extends ShaarliFrontException
 {
     public function __construct()
     {
diff --git a/application/front/exceptions/UnauthorizedException.php b/application/front/exceptions/UnauthorizedException.php
new file mode 100644 (file)
index 0000000..4231094
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Shaarli\Front\Exception;
+
+/**
+ * Class UnauthorizedException
+ *
+ * Exception raised if the user tries to access a ShaarliAdminController while logged out.
+ */
+class UnauthorizedException extends \Exception
+{
+
+}
index 6b670fa21636af4c395ddf5fbd5c09b388371bb4..738d9f5887f1a72b5b5b538ec6e03a7687db05df 100644 (file)
@@ -53,7 +53,8 @@
             "Shaarli\\Feed\\": "application/feed",
             "Shaarli\\Formatter\\": "application/formatter",
             "Shaarli\\Front\\": "application/front",
-            "Shaarli\\Front\\Controller\\": "application/front/controllers",
+            "Shaarli\\Front\\Controller\\Admin\\": "application/front/controller/admin",
+            "Shaarli\\Front\\Controller\\Visitor\\": "application/front/controller/visitor",
             "Shaarli\\Front\\Exception\\": "application/front/exceptions",
             "Shaarli\\Http\\": "application/http",
             "Shaarli\\Legacy\\": "application/legacy",
index c1a2885d9877f3e4c96595a2b67156db93ed5624..e0e411bb2b8e24848b02b09fa12020ed7ca90b1a 100644 (file)
@@ -37,7 +37,7 @@ http://<replace_domain>/?do=changepasswd
 http://<replace_domain>/?do=changetag
 http://<replace_domain>/?do=configure
 http://<replace_domain>/?do=tools
-http://<replace_domain>/?do=daily
+http://<replace_domain>/daily
 http://<replace_domain>/?post
 http://<replace_domain>/?do=export
 http://<replace_domain>/?do=import
index a31cbeab68106756d929b056d71b3b1377bf17db..4cd6d5f45675b63579935752a2c12b0cfb01e228 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1498,30 +1498,33 @@ $app->group('/api/v1', function () {
 })->add('\Shaarli\Api\ApiMiddleware');
 
 $app->group('', function () {
-    $this->get('/login', '\Shaarli\Front\Controller\LoginController:index')->setName('login');
-    $this->get('/logout', '\Shaarli\Front\Controller\LogoutController:index')->setName('logout');
-    $this->get('/picture-wall', '\Shaarli\Front\Controller\PictureWallController:index')->setName('picwall');
-    $this->get('/tag-cloud', '\Shaarli\Front\Controller\TagCloudController:cloud')->setName('tagcloud');
-    $this->get('/tag-list', '\Shaarli\Front\Controller\TagCloudController:list')->setName('taglist');
-    $this->get('/daily', '\Shaarli\Front\Controller\DailyController:index')->setName('daily');
-    $this->get('/daily-rss', '\Shaarli\Front\Controller\DailyController:rss')->setName('dailyrss');
-    $this->get('/feed-atom', '\Shaarli\Front\Controller\FeedController:atom')->setName('feedatom');
-    $this->get('/feed-rss', '\Shaarli\Front\Controller\FeedController:rss')->setName('feedrss');
-    $this->get('/open-search', '\Shaarli\Front\Controller\OpenSearchController:index')->setName('opensearch');
-
-    $this->get('/add-tag/{newTag}', '\Shaarli\Front\Controller\TagController:addTag')->setName('add-tag');
-    $this->get('/remove-tag/{tag}', '\Shaarli\Front\Controller\TagController:removeTag')->setName('remove-tag');
+    /* -- PUBLIC --*/
+    $this->get('/login', '\Shaarli\Front\Controller\Visitor\LoginController:index')->setName('login');
+    $this->get('/picture-wall', '\Shaarli\Front\Controller\Visitor\PictureWallController:index')->setName('picwall');
+    $this->get('/tag-cloud', '\Shaarli\Front\Controller\Visitor\TagCloudController:cloud')->setName('tagcloud');
+    $this->get('/tag-list', '\Shaarli\Front\Controller\Visitor\TagCloudController:list')->setName('taglist');
+    $this->get('/daily', '\Shaarli\Front\Controller\Visitor\DailyController:index')->setName('daily');
+    $this->get('/daily-rss', '\Shaarli\Front\Controller\Visitor\DailyController:rss')->setName('dailyrss');
+    $this->get('/feed-atom', '\Shaarli\Front\Controller\Visitor\FeedController:atom')->setName('feedatom');
+    $this->get('/feed-rss', '\Shaarli\Front\Controller\Visitor\FeedController:rss')->setName('feedrss');
+    $this->get('/open-search', '\Shaarli\Front\Controller\Visitor\OpenSearchController:index')->setName('opensearch');
+
+    $this->get('/add-tag/{newTag}', '\Shaarli\Front\Controller\Visitor\TagController:addTag')->setName('add-tag');
+    $this->get('/remove-tag/{tag}', '\Shaarli\Front\Controller\Visitor\TagController:removeTag')->setName('remove-tag');
+
+    /* -- LOGGED IN -- */
+    $this->get('/logout', '\Shaarli\Front\Controller\Admin\LogoutController:index')->setName('logout');
 
     $this
-        ->get('/links-per-page', '\Shaarli\Front\Controller\SessionFilterController:linksPerPage')
+        ->get('/links-per-page', '\Shaarli\Front\Controller\Admin\SessionFilterController:linksPerPage')
         ->setName('filter-links-per-page')
     ;
     $this
-        ->get('/visibility/{visibility}', '\Shaarli\Front\Controller\SessionFilterController:visibility')
+        ->get('/visibility/{visibility}', '\Shaarli\Front\Controller\Admin\SessionFilterController:visibility')
         ->setName('visibility')
     ;
     $this
-        ->get('/untagged-only', '\Shaarli\Front\Controller\SessionFilterController:untaggedOnly')
+        ->get('/untagged-only', '\Shaarli\Front\Controller\Admin\SessionFilterController:untaggedOnly')
         ->setName('untagged-only')
     ;
 })->add('\Shaarli\Front\ShaarliMiddleware');
index 6bb345c20847b59f56f79aaf457a7e455c22d784..511698ff085e27bab7e14092e01e7e2f7a6dced7 100644 (file)
@@ -22,4 +22,5 @@ require_once 'tests/utils/ReferenceLinkDB.php';
 require_once 'tests/utils/ReferenceHistory.php';
 require_once 'tests/utils/FakeBookmarkService.php';
 require_once 'tests/container/ShaarliTestContainer.php';
-require_once 'tests/front/controller/FrontControllerMockHelper.php';
+require_once 'tests/front/controller/visitor/FrontControllerMockHelper.php';
+require_once 'tests/front/controller/admin/FrontAdminControllerMockHelper.php';
diff --git a/tests/front/controller/admin/FrontAdminControllerMockHelper.php b/tests/front/controller/admin/FrontAdminControllerMockHelper.php
new file mode 100644 (file)
index 0000000..94581c0
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Shaarli\Front\Controller\Admin;
+
+use Shaarli\Container\ShaarliTestContainer;
+use Shaarli\Front\Controller\Visitor\FrontControllerMockHelper;
+use Shaarli\Security\LoginManager;
+
+/**
+ * Trait FrontControllerMockHelper
+ *
+ * Helper trait used to initialize the ShaarliContainer and mock its services for admin controller tests.
+ *
+ * @property ShaarliTestContainer $container
+ */
+trait FrontAdminControllerMockHelper
+{
+    use FrontControllerMockHelper {
+        FrontControllerMockHelper::createContainer as parentCreateContainer;
+    }
+
+    /**
+     * Mock the container instance
+     */
+    protected function createContainer(): void
+    {
+        $this->parentCreateContainer();
+
+        $this->container->loginManager = $this->createMock(LoginManager::class);
+        $this->container->loginManager->method('isLoggedIn')->willReturn(true);
+    }
+}
similarity index 95%
rename from tests/front/controller/LogoutControllerTest.php
rename to tests/front/controller/admin/LogoutControllerTest.php
index 8e01c367aff8e744df0ec757a8c99e46bb501c60..239e39b2dd50067720ee80baff4bf5339842b9ea 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Admin;
 
 /** Override PHP builtin setcookie function in the local namespace to mock it... more or less */
 if (!function_exists('Shaarli\Front\Controller\setcookie')) {
@@ -19,7 +19,7 @@ use Slim\Http\Response;
 
 class LogoutControllerTest extends TestCase
 {
-    use FrontControllerMockHelper;
+    use FrontAdminControllerMockHelper;
 
     /** @var LogoutController */
     protected $controller;
similarity index 79%
rename from tests/front/controller/SessionFilterControllerTest.php
rename to tests/front/controller/admin/SessionFilterControllerTest.php
index f541de0342ce1f80d668346c9c32a1d18958e012..f50f2fc2fbaa348c9ee675efb171b657ced25a42 100644 (file)
@@ -2,16 +2,18 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Admin;
 
 use PHPUnit\Framework\TestCase;
+use Shaarli\Security\LoginManager;
 use Shaarli\Security\SessionManager;
 use Slim\Http\Request;
 use Slim\Http\Response;
+use Slim\Http\Uri;
 
 class SessionFilterControllerTest extends TestCase
 {
-    use FrontControllerMockHelper;
+    use FrontAdminControllerMockHelper;
 
     /** @var SessionFilterController */
     protected $controller;
@@ -33,6 +35,12 @@ class SessionFilterControllerTest extends TestCase
         $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc'];
 
         $request = $this->createMock(Request::class);
+        $request->method('getUri')->willReturnCallback(function (): Uri {
+            $uri = $this->createMock(Uri::class);
+            $uri->method('getBasePath')->willReturn('/subfolder');
+
+            return $uri;
+        });
         $request->method('getParam')->with('nb')->willReturn('8');
         $response = new Response();
 
@@ -57,6 +65,12 @@ class SessionFilterControllerTest extends TestCase
         $this->createValidContainerMockSet();
 
         $request = $this->createMock(Request::class);
+        $request->method('getUri')->willReturnCallback(function (): Uri {
+            $uri = $this->createMock(Uri::class);
+            $uri->method('getBasePath')->willReturn('/subfolder');
+
+            return $uri;
+        });
         $request->method('getParam')->with('nb')->willReturn('test');
         $response = new Response();
 
@@ -70,7 +84,7 @@ class SessionFilterControllerTest extends TestCase
 
         static::assertInstanceOf(Response::class, $result);
         static::assertSame(302, $result->getStatusCode());
-        static::assertSame(['./'], $result->getHeader('location'));
+        static::assertSame(['/subfolder'], $result->getHeader('location'));
     }
 
     /**
@@ -92,6 +106,12 @@ class SessionFilterControllerTest extends TestCase
         ;
 
         $request = $this->createMock(Request::class);
+        $request->method('getUri')->willReturnCallback(function (): Uri {
+            $uri = $this->createMock(Uri::class);
+            $uri->method('getBasePath')->willReturn('/subfolder');
+
+            return $uri;
+        });
         $response = new Response();
 
         $result = $this->controller->visibility($request, $response, $arg);
@@ -129,6 +149,12 @@ class SessionFilterControllerTest extends TestCase
         ;
 
         $request = $this->createMock(Request::class);
+        $request->method('getUri')->willReturnCallback(function (): Uri {
+            $uri = $this->createMock(Uri::class);
+            $uri->method('getBasePath')->willReturn('/subfolder');
+
+            return $uri;
+        });
         $response = new Response();
 
         $result = $this->controller->visibility($request, $response, $arg);
@@ -160,13 +186,19 @@ class SessionFilterControllerTest extends TestCase
         ;
 
         $request = $this->createMock(Request::class);
+        $request->method('getUri')->willReturnCallback(function (): Uri {
+            $uri = $this->createMock(Uri::class);
+            $uri->method('getBasePath')->willReturn('/subfolder');
+
+            return $uri;
+        });
         $response = new Response();
 
         $result = $this->controller->visibility($request, $response, $arg);
 
         static::assertInstanceOf(Response::class, $result);
         static::assertSame(302, $result->getStatusCode());
-        static::assertSame(['./'], $result->getHeader('location'));
+        static::assertSame(['/subfolder'], $result->getHeader('location'));
     }
 
     /**
@@ -192,6 +224,12 @@ class SessionFilterControllerTest extends TestCase
         ;
 
         $request = $this->createMock(Request::class);
+        $request->method('getUri')->willReturnCallback(function (): Uri {
+            $uri = $this->createMock(Uri::class);
+            $uri->method('getBasePath')->willReturn('/subfolder');
+
+            return $uri;
+        });
         $response = new Response();
 
         $result = $this->controller->visibility($request, $response, $arg);
@@ -212,6 +250,7 @@ class SessionFilterControllerTest extends TestCase
 
         $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc'];
 
+        $this->container->loginManager = $this->createMock(LoginManager::class);
         $this->container->loginManager->method('isLoggedIn')->willReturn(false);
         $this->container->sessionManager
             ->expects(static::never())
@@ -224,6 +263,12 @@ class SessionFilterControllerTest extends TestCase
         ;
 
         $request = $this->createMock(Request::class);
+        $request->method('getUri')->willReturnCallback(function (): Uri {
+            $uri = $this->createMock(Uri::class);
+            $uri->method('getBasePath')->willReturn('/subfolder');
+
+            return $uri;
+        });
         $response = new Response();
 
         $result = $this->controller->visibility($request, $response, $arg);
@@ -243,6 +288,12 @@ class SessionFilterControllerTest extends TestCase
         $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc'];
 
         $request = $this->createMock(Request::class);
+        $request->method('getUri')->willReturnCallback(function (): Uri {
+            $uri = $this->createMock(Uri::class);
+            $uri->method('getBasePath')->willReturn('/subfolder');
+
+            return $uri;
+        });
         $response = new Response();
 
         $this->container->sessionManager
@@ -268,6 +319,13 @@ class SessionFilterControllerTest extends TestCase
         $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc'];
 
         $request = $this->createMock(Request::class);
+        $request->method('getUri')->willReturnCallback(function (): Uri {
+            $uri = $this->createMock(Uri::class);
+            $uri->method('getBasePath')->willReturn('/subfolder');
+
+            return $uri;
+        });
+
         $response = new Response();
 
         $this->container->sessionManager
similarity index 99%
rename from tests/front/controller/DailyControllerTest.php
rename to tests/front/controller/visitor/DailyControllerTest.php
index 7ec99030c8e838e15c7943f651b4572ae320bfb6..6ff769fce57c74c1864f68cfd1f2612c04d6c967 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use PHPUnit\Framework\TestCase;
 use Shaarli\Bookmark\Bookmark;
similarity index 99%
rename from tests/front/controller/FeedControllerTest.php
rename to tests/front/controller/visitor/FeedControllerTest.php
index 7e8657e2cce69a3e772fff4505ed8095f2128416..fd4679ea0816db16c33a7801996dbee21823bb2e 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use PHPUnit\Framework\TestCase;
 use Shaarli\Feed\FeedBuilder;
similarity index 98%
rename from tests/front/controller/FrontControllerMockHelper.php
rename to tests/front/controller/visitor/FrontControllerMockHelper.php
index b65607e74a34862b06d8dcd08f95173d69b5d0f1..bc3266b5ce2409ee80bbc072ef88877e3052d16c 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use PHPUnit\Framework\MockObject\MockObject;
 use Shaarli\Bookmark\BookmarkServiceInterface;
similarity index 99%
rename from tests/front/controller/LoginControllerTest.php
rename to tests/front/controller/visitor/LoginControllerTest.php
index 21937f3c6605254eeec9c813547fe87b74b0601f..9d2233169690cb1521854acd53b732108b1d82ac 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use PHPUnit\Framework\TestCase;
 use Shaarli\Config\ConfigManager;
similarity index 89%
rename from tests/front/controller/OpenSearchControllerTest.php
rename to tests/front/controller/visitor/OpenSearchControllerTest.php
index f3b6f4396b59154faa635ec63079af8d6bb37154..52475318f6f5c2ea0b961936e4151c306903e19d 100644 (file)
@@ -2,11 +2,9 @@
 
 declare(strict_types=1);
 
-namespace front\controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use PHPUnit\Framework\TestCase;
-use Shaarli\Front\Controller\FrontControllerMockHelper;
-use Shaarli\Front\Controller\OpenSearchController;
 use Slim\Http\Request;
 use Slim\Http\Response;
 
similarity index 99%
rename from tests/front/controller/PictureWallControllerTest.php
rename to tests/front/controller/visitor/PictureWallControllerTest.php
index 8160bb38e12a32cbb7cb7f4410240ba86a1be842..7ac842cb2486f6968e171b9124ea4dd545912eac 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use PHPUnit\Framework\TestCase;
 use Shaarli\Bookmark\Bookmark;
similarity index 82%
rename from tests/front/controller/ShaarliControllerTest.php
rename to tests/front/controller/visitor/ShaarliPublicControllerTest.php
index a6011b4981cd1dbb3abb2ac25cc8eba5528c2112..e2e88da3f64d9d0372b49c2978c9d8deddca1d82 100644 (file)
@@ -2,11 +2,13 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use PHPUnit\Framework\TestCase;
 use Shaarli\Bookmark\BookmarkFilter;
+use Slim\Http\Request;
 use Slim\Http\Response;
+use Slim\Http\Uri;
 
 /**
  * Class ShaarliControllerTest
@@ -24,13 +26,16 @@ class ShaarliControllerTest extends TestCase
     /** @var mixed[] List of variable assigned to the template */
     protected $assignedValues;
 
+    /** @var Request */
+    protected $request;
+
     public function setUp(): void
     {
         $this->createContainer();
 
-        $this->controller = new class($this->container) extends ShaarliController
+        $this->controller = new class($this->container) extends ShaarliVisitorController
         {
-            public function assignView(string $key, $value): ShaarliController
+            public function assignView(string $key, $value): ShaarliVisitorController
             {
                 return parent::assignView($key, $value);
             }
@@ -41,14 +46,23 @@ class ShaarliControllerTest extends TestCase
             }
 
             public function redirectFromReferer(
+                Request $request,
                 Response $response,
                 array $loopTerms = [],
                 array $clearParams = []
             ): Response {
-                return parent::redirectFromReferer($response, $loopTerms, $clearParams);
+                return parent::redirectFromReferer($request, $response, $loopTerms, $clearParams);
             }
         };
         $this->assignedValues = [];
+
+        $this->request = $this->createMock(Request::class);
+        $this->request->method('getUri')->willReturnCallback(function (): Uri {
+            $uri = $this->createMock(Uri::class);
+            $uri->method('getBasePath')->willReturn('/subfolder');
+
+            return $uri;
+        });
     }
 
     public function testAssignView(): void
@@ -59,7 +73,7 @@ class ShaarliControllerTest extends TestCase
 
         $self = $this->controller->assignView('variableName', 'variableValue');
 
-        static::assertInstanceOf(ShaarliController::class, $self);
+        static::assertInstanceOf(ShaarliVisitorController::class, $self);
         static::assertSame('variableValue', $this->assignedValues['variableName']);
     }
 
@@ -112,7 +126,7 @@ class ShaarliControllerTest extends TestCase
 
         $response = new Response();
 
-        $result = $this->controller->redirectFromReferer($response);
+        $result = $this->controller->redirectFromReferer($this->request, $response);
 
         static::assertSame(302, $result->getStatusCode());
         static::assertSame(['/subfolder/controller?query=param&other=2'], $result->getHeader('location'));
@@ -129,7 +143,7 @@ class ShaarliControllerTest extends TestCase
 
         $response = new Response();
 
-        $result = $this->controller->redirectFromReferer($response, ['nope']);
+        $result = $this->controller->redirectFromReferer($this->request, $response, ['nope']);
 
         static::assertSame(302, $result->getStatusCode());
         static::assertSame(['/subfolder/controller?query=param&other=2'], $result->getHeader('location'));
@@ -146,10 +160,10 @@ class ShaarliControllerTest extends TestCase
 
         $response = new Response();
 
-        $result = $this->controller->redirectFromReferer($response, ['nope', 'controller']);
+        $result = $this->controller->redirectFromReferer($this->request, $response, ['nope', 'controller']);
 
         static::assertSame(302, $result->getStatusCode());
-        static::assertSame(['./'], $result->getHeader('location'));
+        static::assertSame(['/subfolder'], $result->getHeader('location'));
     }
 
     /**
@@ -163,10 +177,10 @@ class ShaarliControllerTest extends TestCase
 
         $response = new Response();
 
-        $result = $this->controller->redirectFromReferer($response, ['nope', 'other']);
+        $result = $this->controller->redirectFromReferer($this->request, $response, ['nope', 'other']);
 
         static::assertSame(302, $result->getStatusCode());
-        static::assertSame(['./'], $result->getHeader('location'));
+        static::assertSame(['/subfolder'], $result->getHeader('location'));
     }
 
     /**
@@ -181,7 +195,7 @@ class ShaarliControllerTest extends TestCase
 
         $response = new Response();
 
-        $result = $this->controller->redirectFromReferer($response, ['nope', 'param']);
+        $result = $this->controller->redirectFromReferer($this->request, $response, ['nope', 'param']);
 
         static::assertSame(302, $result->getStatusCode());
         static::assertSame(['/subfolder/controller?query=param&other=2'], $result->getHeader('location'));
@@ -199,7 +213,7 @@ class ShaarliControllerTest extends TestCase
 
         $response = new Response();
 
-        $result = $this->controller->redirectFromReferer($response, ['shaarli']);
+        $result = $this->controller->redirectFromReferer($this->request, $response, ['shaarli']);
 
         static::assertSame(302, $result->getStatusCode());
         static::assertSame(['/subfolder/controller?query=param&other=2'], $result->getHeader('location'));
@@ -217,7 +231,7 @@ class ShaarliControllerTest extends TestCase
 
         $response = new Response();
 
-        $result = $this->controller->redirectFromReferer($response, ['query'], ['query']);
+        $result = $this->controller->redirectFromReferer($this->request, $response, ['query'], ['query']);
 
         static::assertSame(302, $result->getStatusCode());
         static::assertSame(['/subfolder/controller?other=2'], $result->getHeader('location'));
similarity index 99%
rename from tests/front/controller/TagCloudControllerTest.php
rename to tests/front/controller/visitor/TagCloudControllerTest.php
index 8c27900d5d0d4384acbcb2e096c6ce976f17f58d..e636d496a6689e7efde2c257f6d9e65c696ce3eb 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use PHPUnit\Framework\TestCase;
 use Shaarli\Bookmark\BookmarkFilter;
similarity index 98%
rename from tests/front/controller/TagControllerTest.php
rename to tests/front/controller/visitor/TagControllerTest.php
index 2184cb11f9ba1bbd757e7b8b617c26de4f9d890e..9a2b1f71efe352feddc840a554fba5b78f6e88a2 100644 (file)
@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace Shaarli\Front\Controller;
+namespace Shaarli\Front\Controller\Visitor;
 
 use PHPUnit\Framework\TestCase;
 use Slim\Http\Request;
@@ -12,8 +12,7 @@ class TagControllerTest extends TestCase
 {
     use FrontControllerMockHelper;
 
-    /** @var TagController */
-    protected $controller;
+    /** @var TagController */    protected $controller;
 
     public function setUp(): void
     {
index 2d015b264253b966399bbe35b896d29d5c6fc95d..624367e48050412cf14f22057ad710b064048638 100644 (file)
@@ -38,7 +38,7 @@
           </li>
         {/if}
         <li class="pure-menu-item" id="shaarli-menu-daily">
-          <a href="./?do=daily" class="pure-menu-link">{'Daily'|t}</a>
+          <a href="./daily" class="pure-menu-link">{'Daily'|t}</a>
         </li>
         {loop="$plugins_header.buttons_toolbar"}
           <li class="pure-menu-item shaarli-menu-plugin">
index adcdf6abc6cdbc7f03401a0b25a911b0be667b7a..a459e21afe662c2c02e92f8df771d332e6b3c807 100644 (file)
@@ -14,9 +14,9 @@
 
     <div class="dailyAbout">
         All links of one day<br>in a single page.<br>
-        {if="$previousday"} <a href="./?do=daily&amp;day={$previousday}"><b>&lt;</b>Previous day</a>{else}<b>&lt;</b>Previous day{/if}
+        {if="$previousday"} <a href="./daily&amp;day={$previousday}"><b>&lt;</b>Previous day</a>{else}<b>&lt;</b>Previous day{/if}
         -
-        {if="$nextday"}<a href="./?do=daily&amp;day={$nextday}">Next day<b>&gt;</b></a>{else}Next day<b>&gt;</b>{/if}
+        {if="$nextday"}<a href="./daily&amp;day={$nextday}">Next day<b>&gt;</b></a>{else}Next day<b>&gt;</b>{/if}
         <br>
 
         {loop="$daily_about_plugin"}
index 0a8392b64a3537a1d7703dfee7174698cf977ea9..9268ced967cdd89126435001f6eac405aa06761e 100644 (file)
@@ -33,7 +33,7 @@
     {/if}
     <li><a href="./tag-cloud">Tag cloud</a></li>
     <li><a href="./picture-wall{function="ltrim($searchcrits, '&')"}">Picture wall</a></li>
-    <li><a href="./?do=daily">Daily</a></li>
+    <li><a href="./daily">Daily</a></li>
     {loop="$plugins_header.buttons_toolbar"}
         <li><a
             {loop="$value.attr"}