Initialize admin Slim controllers
- Reorganize visitor controllers - Fix redirection with Slim's requests base path - Fix daily links
This commit is contained in:
parent
af290059d1
commit
2899ebb5b5
35 changed files with 238 additions and 104 deletions
|
@ -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 @@ public function __invoke(Request $request, Response $response, callable $next)
|
|||
{
|
||||
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 @@ public function __invoke(Request $request, Response $response, callable $next)
|
|||
|
||||
$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;
|
||||
|
|
|
@ -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 @@
|
|||
*
|
||||
* 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
|
||||
{
|
|
@ -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 @@
|
|||
* 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 @@ public function linksPerPage(Request $request, Response $response): Response
|
|||
abs(intval($linksPerPage))
|
||||
);
|
||||
|
||||
return $this->redirectFromReferer($response, ['linksperpage'], ['nb']);
|
||||
return $this->redirectFromReferer($request, $response, ['linksperpage'], ['nb']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,7 +40,7 @@ public function linksPerPage(Request $request, Response $response): Response
|
|||
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 @@ public function visibility(Request $request, Response $response, array $args): R
|
|||
$this->container->sessionManager->deleteSessionParameter(SessionManager::KEY_VISIBILITY);
|
||||
}
|
||||
|
||||
return $this->redirectFromReferer($response, ['visibility']);
|
||||
return $this->redirectFromReferer($request, $response, ['visibility']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,6 +74,6 @@ public function untaggedOnly(Request $request, Response $response): Response
|
|||
empty($this->container->sessionManager->getSessionParameter(SessionManager::KEY_UNTAGGED_ONLY))
|
||||
);
|
||||
|
||||
return $this->redirectFromReferer($response, ['untaggedonly', 'untagged-only']);
|
||||
return $this->redirectFromReferer($request, $response, ['untaggedonly', 'untagged-only']);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 @@
|
|||
* 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;
|
||||
|
|
@ -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 @@
|
|||
* 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
|
||||
{
|
|
@ -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 @@
|
|||
*
|
||||
* 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
|
||||
{
|
|
@ -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 @@
|
|||
*
|
||||
* 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
|
||||
{
|
|
@ -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 @@
|
|||
*
|
||||
* 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
|
||||
{
|
|
@ -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 @@ protected function executeDefaultHooks(string $template): void
|
|||
* @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) {
|
|
@ -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 @@
|
|||
* 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';
|
|
@ -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 @@
|
|||
* 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.
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Shaarli\Front\Exception;
|
||||
|
||||
class LoginBannedException extends ShaarliException
|
||||
class LoginBannedException extends ShaarliFrontException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @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)
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Shaarli\Front\Exception;
|
||||
|
||||
class ThumbnailsDisabledException extends ShaarliException
|
||||
class ThumbnailsDisabledException extends ShaarliFrontException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
|
15
application/front/exceptions/UnauthorizedException.php
Normal file
15
application/front/exceptions/UnauthorizedException.php
Normal file
|
@ -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
|
||||
{
|
||||
|
||||
}
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
|
33
index.php
33
index.php
|
@ -1498,30 +1498,33 @@ function install($conf, $sessionManager, $loginManager)
|
|||
})->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');
|
||||
/* -- 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\TagController:addTag')->setName('add-tag');
|
||||
$this->get('/remove-tag/{tag}', '\Shaarli\Front\Controller\TagController:removeTag')->setName('remove-tag');
|
||||
$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');
|
||||
|
|
|
@ -22,4 +22,5 @@ function is_iterable($var)
|
|||
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';
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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 @@ function setcookie(string $name, string $value): void {
|
|||
|
||||
class LogoutControllerTest extends TestCase
|
||||
{
|
||||
use FrontControllerMockHelper;
|
||||
use FrontAdminControllerMockHelper;
|
||||
|
||||
/** @var LogoutController */
|
||||
protected $controller;
|
|
@ -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 @@ public function testLinksPerPage(): void
|
|||
$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 @@ public function testLinksPerPageNotValid(): void
|
|||
$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 @@ public function testLinksPerPageNotValid(): void
|
|||
|
||||
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 @@ public function testVisibility(): void
|
|||
;
|
||||
|
||||
$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 @@ public function testVisibilityToggleOff(): void
|
|||
;
|
||||
|
||||
$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 @@ public function testVisibilitySwitch(): void
|
|||
;
|
||||
|
||||
$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 @@ public function testVisibilityInvalidValue(): void
|
|||
;
|
||||
|
||||
$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 @@ public function testVisibilityLoggedOut(): void
|
|||
|
||||
$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 @@ public function testVisibilityLoggedOut(): void
|
|||
;
|
||||
|
||||
$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 @@ public function testUntaggedOnly(): void
|
|||
$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 @@ public function testUntaggedOnlyToggleOff(): void
|
|||
$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
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
||||
|
|
@ -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;
|
|
@ -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 @@ public function render(string $template): string
|
|||
}
|
||||
|
||||
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 @@ public function testAssignView(): void
|
|||
|
||||
$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 @@ public function testRedirectFromRefererDefault(): void
|
|||
|
||||
$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 @@ public function testRedirectFromRefererWithUnmatchedLoopTerm(): void
|
|||
|
||||
$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 @@ public function testRedirectFromRefererWithMatchingLoopTermInPath(): void
|
|||
|
||||
$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 @@ public function testRedirectFromRefererWithMatchingLoopTermInQueryParam(): void
|
|||
|
||||
$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 @@ public function testRedirectFromRefererWithMatchingLoopTermInQueryValue(): void
|
|||
|
||||
$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 @@ public function testRedirectFromRefererWithLoopTermInDomain(): void
|
|||
|
||||
$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 @@ public function testRedirectFromRefererWithMatchingClearedParam(): void
|
|||
|
||||
$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'));
|
|
@ -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;
|
|
@ -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
|
||||
{
|
|
@ -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">
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
|
||||
<div class="dailyAbout">
|
||||
All links of one day<br>in a single page.<br>
|
||||
{if="$previousday"} <a href="./?do=daily&day={$previousday}"><b><</b>Previous day</a>{else}<b><</b>Previous day{/if}
|
||||
{if="$previousday"} <a href="./daily&day={$previousday}"><b><</b>Previous day</a>{else}<b><</b>Previous day{/if}
|
||||
-
|
||||
{if="$nextday"}<a href="./?do=daily&day={$nextday}">Next day<b>></b></a>{else}Next day<b>></b>{/if}
|
||||
{if="$nextday"}<a href="./daily&day={$nextday}">Next day<b>></b></a>{else}Next day<b>></b>{/if}
|
||||
<br>
|
||||
|
||||
{loop="$daily_about_plugin"}
|
||||
|
|
|
@ -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"}
|
||||
|
|
Loading…
Reference in a new issue