From: Kevin Decherf Date: Sun, 21 May 2017 14:35:06 +0000 (+0200) Subject: TagController: ignore ActionMarkAsRead when removing tag from entry X-Git-Tag: 2.3.0~31^2~81^2~1 X-Git-Url: https://git.immae.eu/?p=github%2Fwallabag%2Fwallabag.git;a=commitdiff_plain;h=5dbf3f2326c4054782304b9a41d773a1100acf48 TagController: ignore ActionMarkAsRead when removing tag from entry Fixes #2835 Signed-off-by: Kevin Decherf --- diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index fb6a720b..736eb1dc 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -70,7 +70,7 @@ class TagController extends Controller $em->flush(); } - $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer')); + $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true); return $this->redirect($redirectUrl); } diff --git a/src/Wallabag/CoreBundle/Helper/Redirect.php b/src/Wallabag/CoreBundle/Helper/Redirect.php index f78b7fe0..abc84d08 100644 --- a/src/Wallabag/CoreBundle/Helper/Redirect.php +++ b/src/Wallabag/CoreBundle/Helper/Redirect.php @@ -21,12 +21,13 @@ class Redirect } /** - * @param string $url URL to redirect - * @param string $fallback Fallback URL if $url is null + * @param string $url URL to redirect + * @param string $fallback Fallback URL if $url is null + * @param bool $ignoreActionMarkAsRead Ignore configured action when mark as read * * @return string */ - public function to($url, $fallback = '') + public function to($url, $fallback = '', $ignoreActionMarkAsRead = false) { $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; @@ -34,7 +35,8 @@ class Redirect return $url; } - if (Config::REDIRECT_TO_HOMEPAGE === $user->getConfig()->getActionMarkAsRead()) { + if (!$ignoreActionMarkAsRead && + Config::REDIRECT_TO_HOMEPAGE === $user->getConfig()->getActionMarkAsRead()) { return $this->router->generate('homepage'); } diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index c3b22dcd..e36d3924 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -126,9 +126,13 @@ class TagControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Tag') ->findOneByEntryAndTagLabel($entry, $this->tagName); + // We make a first request to set an history and test redirection after tag deletion + $client->request('GET', '/view/'.$entry->getId()); + $entryUri = $client->getRequest()->getUri(); $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertEquals($entryUri, $client->getResponse()->getTargetUrl()); $this->assertNotContains($this->tagName, $entry->getTags()); diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index 0539f20a..f420d06a 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php @@ -89,4 +89,22 @@ class RedirectTest extends \PHPUnit_Framework_TestCase $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); } + + public function testUserForRedirectWithIgnoreActionMarkAsRead() + { + $this->token->getUser()->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); + + $redirectUrl = $this->redirect->to('/unread/list', '', true); + + $this->assertEquals('/unread/list', $redirectUrl); + } + + public function testUserForRedirectNullWithFallbackWithIgnoreActionMarkAsRead() + { + $this->token->getUser()->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); + + $redirectUrl = $this->redirect->to(null, 'fallback', true); + + $this->assertEquals('fallback', $redirectUrl); + } }