From 65cd8a4a9a1d15d962033f58276005a5f7716f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 7 Nov 2016 10:26:05 +0100 Subject: Added tests --- src/Wallabag/CoreBundle/Helper/Redirect.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Helper/Redirect.php b/src/Wallabag/CoreBundle/Helper/Redirect.php index 59172db4..82792aec 100644 --- a/src/Wallabag/CoreBundle/Helper/Redirect.php +++ b/src/Wallabag/CoreBundle/Helper/Redirect.php @@ -3,7 +3,7 @@ namespace Wallabag\CoreBundle\Helper; use Symfony\Component\Routing\Router; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Wallabag\CoreBundle\Entity\Config; /** @@ -12,12 +12,13 @@ use Wallabag\CoreBundle\Entity\Config; class Redirect { private $router; + private $tokenStorage; private $actionMarkAsRead; - public function __construct(Router $router, TokenStorage $token) + public function __construct(Router $router, TokenStorageInterface $tokenStorage) { $this->router = $router; - $this->actionMarkAsRead = $token->getToken()->getUser()->getConfig()->getActionMarkAsRead(); + $this->tokenStorage = $tokenStorage; } /** @@ -28,7 +29,13 @@ class Redirect */ public function to($url, $fallback = '') { - if (Config::REDIRECT_TO_HOMEPAGE === $this->actionMarkAsRead) { + $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; + + if (null === $user || !is_object($user)) { + return $url; + } + + if (Config::REDIRECT_TO_HOMEPAGE === $user->getConfig()->getActionMarkAsRead()) { return $this->router->generate('homepage'); } -- cgit v1.2.3