From: ArthurHoaro Date: Fri, 22 May 2020 11:20:31 +0000 (+0200) Subject: Initialize admin Slim controllers X-Git-Tag: v0.12.0-beta~4^2~38 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=2899ebb5b5e82890c877151f5c02045266ac9973;p=github%2Fshaarli%2FShaarli.git Initialize admin Slim controllers - Reorganize visitor controllers - Fix redirection with Slim's requests base path - Fix daily links --- diff --git a/application/front/ShaarliMiddleware.php b/application/front/ShaarliMiddleware.php index fa6c6467..f8992e0b 100644 --- a/application/front/ShaarliMiddleware.php +++ b/application/front/ShaarliMiddleware.php @@ -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; diff --git a/application/front/controllers/LogoutController.php b/application/front/controller/admin/LogoutController.php similarity index 86% rename from application/front/controllers/LogoutController.php rename to application/front/controller/admin/LogoutController.php index aba078c3..41e81984 100644 --- a/application/front/controllers/LogoutController.php +++ b/application/front/controller/admin/LogoutController.php @@ -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 { diff --git a/application/front/controllers/SessionFilterController.php b/application/front/controller/admin/SessionFilterController.php similarity index 84% rename from application/front/controllers/SessionFilterController.php rename to application/front/controller/admin/SessionFilterController.php index a021dc37..69a16ec3 100644 --- a/application/front/controllers/SessionFilterController.php +++ b/application/front/controller/admin/SessionFilterController.php @@ -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 index 00000000..ea703f62 --- /dev/null +++ b/application/front/controller/admin/ShaarliAdminController.php @@ -0,0 +1,21 @@ +container->loginManager->isLoggedIn()) { + throw new UnauthorizedException(); + } + } +} diff --git a/application/front/controllers/DailyController.php b/application/front/controller/visitor/DailyController.php similarity index 98% rename from application/front/controllers/DailyController.php rename to application/front/controller/visitor/DailyController.php index 4a0735aa..47e2503a 100644 --- a/application/front/controllers/DailyController.php +++ b/application/front/controller/visitor/DailyController.php @@ -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; diff --git a/application/front/controllers/FeedController.php b/application/front/controller/visitor/FeedController.php similarity index 95% rename from application/front/controllers/FeedController.php rename to application/front/controller/visitor/FeedController.php index 78d826d9..70664635 100644 --- a/application/front/controllers/FeedController.php +++ b/application/front/controller/visitor/FeedController.php @@ -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 { diff --git a/application/front/controllers/LoginController.php b/application/front/controller/visitor/LoginController.php similarity index 92% rename from application/front/controllers/LoginController.php rename to application/front/controller/visitor/LoginController.php index ae3599e0..4de2f55d 100644 --- a/application/front/controllers/LoginController.php +++ b/application/front/controller/visitor/LoginController.php @@ -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 { diff --git a/application/front/controllers/OpenSearchController.php b/application/front/controller/visitor/OpenSearchController.php similarity index 83% rename from application/front/controllers/OpenSearchController.php rename to application/front/controller/visitor/OpenSearchController.php index fa32c5f1..0fd68db6 100644 --- a/application/front/controllers/OpenSearchController.php +++ b/application/front/controller/visitor/OpenSearchController.php @@ -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 { diff --git a/application/front/controllers/PictureWallController.php b/application/front/controller/visitor/PictureWallController.php similarity index 94% rename from application/front/controllers/PictureWallController.php rename to application/front/controller/visitor/PictureWallController.php index 08d31b29..4e1dce8c 100644 --- a/application/front/controllers/PictureWallController.php +++ b/application/front/controller/visitor/PictureWallController.php @@ -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 { diff --git a/application/front/controllers/ShaarliController.php b/application/front/controller/visitor/ShaarliVisitorController.php similarity index 91% rename from application/front/controllers/ShaarliController.php rename to application/front/controller/visitor/ShaarliVisitorController.php index bfff5fcf..655b3baa 100644 --- a/application/front/controllers/ShaarliController.php +++ b/application/front/controller/visitor/ShaarliVisitorController.php @@ -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) { diff --git a/application/front/controllers/TagCloudController.php b/application/front/controller/visitor/TagCloudController.php similarity index 97% rename from application/front/controllers/TagCloudController.php rename to application/front/controller/visitor/TagCloudController.php index 1ff7c2e6..15b6d7b7 100644 --- a/application/front/controllers/TagCloudController.php +++ b/application/front/controller/visitor/TagCloudController.php @@ -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'; diff --git a/application/front/controllers/TagController.php b/application/front/controller/visitor/TagController.php similarity index 97% rename from application/front/controllers/TagController.php rename to application/front/controller/visitor/TagController.php index a1d5ad5b..a0bc1d1b 100644 --- a/application/front/controllers/TagController.php +++ b/application/front/controller/visitor/TagController.php @@ -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. diff --git a/application/front/exceptions/LoginBannedException.php b/application/front/exceptions/LoginBannedException.php index b31a4a14..79d0ea15 100644 --- a/application/front/exceptions/LoginBannedException.php +++ b/application/front/exceptions/LoginBannedException.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shaarli\Front\Exception; -class LoginBannedException extends ShaarliException +class LoginBannedException extends ShaarliFrontException { public function __construct() { diff --git a/application/front/exceptions/ShaarliException.php b/application/front/exceptions/ShaarliFrontException.php similarity index 90% rename from application/front/exceptions/ShaarliException.php rename to application/front/exceptions/ShaarliFrontException.php index 800bfbec..fc8eb92b 100644 --- a/application/front/exceptions/ShaarliException.php +++ b/application/front/exceptions/ShaarliFrontException.php @@ -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) diff --git a/application/front/exceptions/ThumbnailsDisabledException.php b/application/front/exceptions/ThumbnailsDisabledException.php index 1b9cf5b7..0ed337f5 100644 --- a/application/front/exceptions/ThumbnailsDisabledException.php +++ b/application/front/exceptions/ThumbnailsDisabledException.php @@ -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 index 00000000..4231094a --- /dev/null +++ b/application/front/exceptions/UnauthorizedException.php @@ -0,0 +1,15 @@ +/?do=changepasswd http:///?do=changetag http:///?do=configure http:///?do=tools -http:///?do=daily +http:///daily http:///?post http:///?do=export http:///?do=import diff --git a/index.php b/index.php index a31cbeab..4cd6d5f4 100644 --- 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'); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6bb345c2..511698ff 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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 index 00000000..94581c09 --- /dev/null +++ b/tests/front/controller/admin/FrontAdminControllerMockHelper.php @@ -0,0 +1,34 @@ +parentCreateContainer(); + + $this->container->loginManager = $this->createMock(LoginManager::class); + $this->container->loginManager->method('isLoggedIn')->willReturn(true); + } +} diff --git a/tests/front/controller/LogoutControllerTest.php b/tests/front/controller/admin/LogoutControllerTest.php similarity index 95% rename from tests/front/controller/LogoutControllerTest.php rename to tests/front/controller/admin/LogoutControllerTest.php index 8e01c367..239e39b2 100644 --- a/tests/front/controller/LogoutControllerTest.php +++ b/tests/front/controller/admin/LogoutControllerTest.php @@ -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; diff --git a/tests/front/controller/SessionFilterControllerTest.php b/tests/front/controller/admin/SessionFilterControllerTest.php similarity index 79% rename from tests/front/controller/SessionFilterControllerTest.php rename to tests/front/controller/admin/SessionFilterControllerTest.php index f541de03..f50f2fc2 100644 --- a/tests/front/controller/SessionFilterControllerTest.php +++ b/tests/front/controller/admin/SessionFilterControllerTest.php @@ -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 diff --git a/tests/front/controller/DailyControllerTest.php b/tests/front/controller/visitor/DailyControllerTest.php similarity index 99% rename from tests/front/controller/DailyControllerTest.php rename to tests/front/controller/visitor/DailyControllerTest.php index 7ec99030..6ff769fc 100644 --- a/tests/front/controller/DailyControllerTest.php +++ b/tests/front/controller/visitor/DailyControllerTest.php @@ -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; diff --git a/tests/front/controller/FeedControllerTest.php b/tests/front/controller/visitor/FeedControllerTest.php similarity index 99% rename from tests/front/controller/FeedControllerTest.php rename to tests/front/controller/visitor/FeedControllerTest.php index 7e8657e2..fd4679ea 100644 --- a/tests/front/controller/FeedControllerTest.php +++ b/tests/front/controller/visitor/FeedControllerTest.php @@ -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; diff --git a/tests/front/controller/FrontControllerMockHelper.php b/tests/front/controller/visitor/FrontControllerMockHelper.php similarity index 98% rename from tests/front/controller/FrontControllerMockHelper.php rename to tests/front/controller/visitor/FrontControllerMockHelper.php index b65607e7..bc3266b5 100644 --- a/tests/front/controller/FrontControllerMockHelper.php +++ b/tests/front/controller/visitor/FrontControllerMockHelper.php @@ -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; diff --git a/tests/front/controller/LoginControllerTest.php b/tests/front/controller/visitor/LoginControllerTest.php similarity index 99% rename from tests/front/controller/LoginControllerTest.php rename to tests/front/controller/visitor/LoginControllerTest.php index 21937f3c..9d223316 100644 --- a/tests/front/controller/LoginControllerTest.php +++ b/tests/front/controller/visitor/LoginControllerTest.php @@ -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; diff --git a/tests/front/controller/OpenSearchControllerTest.php b/tests/front/controller/visitor/OpenSearchControllerTest.php similarity index 89% rename from tests/front/controller/OpenSearchControllerTest.php rename to tests/front/controller/visitor/OpenSearchControllerTest.php index f3b6f439..52475318 100644 --- a/tests/front/controller/OpenSearchControllerTest.php +++ b/tests/front/controller/visitor/OpenSearchControllerTest.php @@ -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; diff --git a/tests/front/controller/PictureWallControllerTest.php b/tests/front/controller/visitor/PictureWallControllerTest.php similarity index 99% rename from tests/front/controller/PictureWallControllerTest.php rename to tests/front/controller/visitor/PictureWallControllerTest.php index 8160bb38..7ac842cb 100644 --- a/tests/front/controller/PictureWallControllerTest.php +++ b/tests/front/controller/visitor/PictureWallControllerTest.php @@ -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; diff --git a/tests/front/controller/ShaarliControllerTest.php b/tests/front/controller/visitor/ShaarliPublicControllerTest.php similarity index 82% rename from tests/front/controller/ShaarliControllerTest.php rename to tests/front/controller/visitor/ShaarliPublicControllerTest.php index a6011b49..e2e88da3 100644 --- a/tests/front/controller/ShaarliControllerTest.php +++ b/tests/front/controller/visitor/ShaarliPublicControllerTest.php @@ -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')); diff --git a/tests/front/controller/TagCloudControllerTest.php b/tests/front/controller/visitor/TagCloudControllerTest.php similarity index 99% rename from tests/front/controller/TagCloudControllerTest.php rename to tests/front/controller/visitor/TagCloudControllerTest.php index 8c27900d..e636d496 100644 --- a/tests/front/controller/TagCloudControllerTest.php +++ b/tests/front/controller/visitor/TagCloudControllerTest.php @@ -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; diff --git a/tests/front/controller/TagControllerTest.php b/tests/front/controller/visitor/TagControllerTest.php similarity index 98% rename from tests/front/controller/TagControllerTest.php rename to tests/front/controller/visitor/TagControllerTest.php index 2184cb11..9a2b1f71 100644 --- a/tests/front/controller/TagControllerTest.php +++ b/tests/front/controller/visitor/TagControllerTest.php @@ -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 { diff --git a/tpl/default/page.header.html b/tpl/default/page.header.html index 2d015b26..624367e4 100644 --- a/tpl/default/page.header.html +++ b/tpl/default/page.header.html @@ -38,7 +38,7 @@ {/if}
  • - {'Daily'|t} + {'Daily'|t}
  • {loop="$plugins_header.buttons_toolbar"}
  • diff --git a/tpl/vintage/daily.html b/tpl/vintage/daily.html index adcdf6ab..a459e21a 100644 --- a/tpl/vintage/daily.html +++ b/tpl/vintage/daily.html @@ -14,9 +14,9 @@
    All links of one day
    in a single page.
    - {if="$previousday"} <Previous day{else}<Previous day{/if} + {if="$previousday"} <Previous day{else}<Previous day{/if} - - {if="$nextday"}Next day>{else}Next day>{/if} + {if="$nextday"}Next day>{else}Next day>{/if}
    {loop="$daily_about_plugin"} diff --git a/tpl/vintage/page.header.html b/tpl/vintage/page.header.html index 0a8392b6..9268ced9 100644 --- a/tpl/vintage/page.header.html +++ b/tpl/vintage/page.header.html @@ -33,7 +33,7 @@ {/if}
  • Tag cloud
  • Picture wall
  • -
  • Daily
  • +
  • Daily
  • {loop="$plugins_header.buttons_toolbar"}