Merge pull request #3138 from Kdecherf/2835-tags

Ignore ActionMarkAsRead when removing tag from entry
This commit is contained in:
Nicolas Lœuillet 2017-05-31 11:48:42 +02:00 committed by GitHub
commit d61fd8be4f
4 changed files with 35 additions and 5 deletions

View File

@ -70,7 +70,7 @@ class TagController extends Controller
$em->flush(); $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); return $this->redirect($redirectUrl);
} }

View File

@ -21,12 +21,13 @@ class Redirect
} }
/** /**
* @param string $url URL to redirect * @param string $url URL to redirect
* @param string $fallback Fallback URL if $url is null * @param string $fallback Fallback URL if $url is null
* @param bool $ignoreActionMarkAsRead Ignore configured action when mark as read
* *
* @return string * @return string
*/ */
public function to($url, $fallback = '') public function to($url, $fallback = '', $ignoreActionMarkAsRead = false)
{ {
$user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
@ -34,7 +35,8 @@ class Redirect
return $url; return $url;
} }
if (Config::REDIRECT_TO_HOMEPAGE === $user->getConfig()->getActionMarkAsRead()) { if (!$ignoreActionMarkAsRead &&
Config::REDIRECT_TO_HOMEPAGE === $user->getConfig()->getActionMarkAsRead()) {
return $this->router->generate('homepage'); return $this->router->generate('homepage');
} }

View File

@ -126,9 +126,19 @@ class TagControllerTest extends WallabagCoreTestCase
->getRepository('WallabagCoreBundle:Tag') ->getRepository('WallabagCoreBundle:Tag')
->findOneByEntryAndTagLabel($entry, $this->tagName); ->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()); $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId());
$this->assertEquals(302, $client->getResponse()->getStatusCode()); $this->assertEquals(302, $client->getResponse()->getStatusCode());
$this->assertEquals($entryUri, $client->getResponse()->getTargetUrl());
// re-retrieve the entry to be sure to get fresh data from database (mostly for tags)
$entry = $client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
$this->assertNotContains($this->tagName, $entry->getTags()); $this->assertNotContains($this->tagName, $entry->getTags());

View File

@ -89,4 +89,22 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); $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);
}
} }