From 5077c46e4e53838fb2a833b8682cdfcee74d3c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 3 Aug 2021 14:35:45 +0200 Subject: [PATCH 1/2] Added action to tag search results --- .../CoreBundle/Controller/TagController.php | 32 +++++++++++++++++ .../Resources/translations/messages.en.yml | 1 + .../themes/material/Entry/entries.html.twig | 1 + .../Controller/TagControllerTest.php | 35 +++++++++++++++++++ 4 files changed, 69 insertions(+) diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 16ded948e..85f4c87ce 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -2,6 +2,7 @@ namespace Wallabag\CoreBundle\Controller; +use Doctrine\ORM\QueryBuilder; use Pagerfanta\Adapter\ArrayAdapter; use Pagerfanta\Exception\OutOfRangeCurrentPageException; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; @@ -190,4 +191,35 @@ class TagController extends Controller return $this->redirect($redirectUrl); } + + /** + * Tag search results with the current search term + * + * @Route("/tag/search/{filter}", name="tag_this_search") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function tagThisSearchAction($filter, Request $request) + { + $currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : ''); + + /** @var QueryBuilder $qb */ + $qb = $this->get('wallabag_core.entry_repository')->getBuilderForSearchByUser($this->getUser()->getId(), $filter, $currentRoute); + $em = $this->getDoctrine()->getManager(); + + $entries = $qb->getQuery()->getResult(); + + foreach ($entries as $entry) { + $this->get('wallabag_core.tags_assigner')->assignTagsToEntry( + $entry, + $filter + ); + + $em->persist($entry); + } + + $em->flush(); + + return $this->redirect($this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true)); + } } diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index a0d5fb23b..822ef72bc 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -237,6 +237,7 @@ entry: toogle_as_star: Toggle starred delete: Delete export_title: Export + assign_search_tag: Assign this search to results filters: title: Filters status_label: Status diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig index 9d6f39977..c5dc97e01 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig @@ -34,6 +34,7 @@ {% include "@WallabagCore/themes/common/Entry/_feed_link.html.twig" %} {% endif %} + {% if currentRoute == 'search' %}
{{ 'entry.list.assign_search_tag'|trans }}
{% endif %} {% if entries.getNbPages > 1 %} {{ pagerfanta(entries, 'twitter_bootstrap_translated', {'proximity': 1}) }} {% endif %} diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 20796f776..aaa0c7e4d 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -476,4 +476,39 @@ class TagControllerTest extends WallabagCoreTestCase $this->assertNotFalse(array_search('cache', $tags, true), 'Tag cache is assigned to the entry'); $this->assertNotFalse(array_search('caché', $tags, true), 'Tag caché is assigned to the entry'); } + + public function testAssignTagsOnSearchResults() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl('https://wallabag/'); + $entry->setTitle('title'); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + + // Search on unread list + $crawler = $client->request('GET', '/unread/list'); + + $form = $crawler->filter('form[name=search]')->form(); + $data = [ + 'search_entry[term]' => 'title', + ]; + + $crawler = $client->submit($form, $data); + + $crawler = $client->click($crawler->selectLink('entry.list.assign_search_tag')->link()); + $crawler = $client->followRedirect(); + + $entries = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->getBuilderForSearchByUser($this->getLoggedInUserId(), 'title', 'unread'); + + foreach ($entries as $entry) { + $tags = $entry->getTags()->toArray(); + $this->assertStringContainsString('title', $tags); + } + } } From 9f6414785c1cc39b4c8e64dbd81ea2b8fc88cb1d Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 20 Apr 2022 23:13:17 +0200 Subject: [PATCH 2/2] Fix tests --- .../CoreBundle/Controller/TagController.php | 4 ++-- .../Resources/translations/messages.en.yml | 2 +- .../Controller/TagControllerTest.php | 18 +++++++----------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 85f4c87ce..7df73e8c7 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -193,7 +193,7 @@ class TagController extends Controller } /** - * Tag search results with the current search term + * Tag search results with the current search term. * * @Route("/tag/search/{filter}", name="tag_this_search") * @@ -201,7 +201,7 @@ class TagController extends Controller */ public function tagThisSearchAction($filter, Request $request) { - $currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : ''); + $currentRoute = $request->query->has('currentRoute') ? $request->query->get('currentRoute') : ''; /** @var QueryBuilder $qb */ $qb = $this->get('wallabag_core.entry_repository')->getBuilderForSearchByUser($this->getUser()->getId(), $filter, $currentRoute); diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 822ef72bc..81d4c615d 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -237,7 +237,7 @@ entry: toogle_as_star: Toggle starred delete: Delete export_title: Export - assign_search_tag: Assign this search to results + assign_search_tag: Assign this search as a tag to each result filters: title: Filters status_label: Status diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index aaa0c7e4d..e3d3ff5e0 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -482,12 +482,6 @@ class TagControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $entry = new Entry($this->getLoggedInUser()); - $entry->setUrl('https://wallabag/'); - $entry->setTitle('title'); - $this->getEntityManager()->persist($entry); - $this->getEntityManager()->flush(); - // Search on unread list $crawler = $client->request('GET', '/unread/list'); @@ -498,17 +492,19 @@ class TagControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $crawler = $client->click($crawler->selectLink('entry.list.assign_search_tag')->link()); - $crawler = $client->followRedirect(); + $client->click($crawler->selectLink('entry.list.assign_search_tag')->link()); + $client->followRedirect(); $entries = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->getBuilderForSearchByUser($this->getLoggedInUserId(), 'title', 'unread'); + ->getBuilderForSearchByUser($this->getLoggedInUserId(), 'title', 'unread') + ->getQuery()->getResult(); foreach ($entries as $entry) { - $tags = $entry->getTags()->toArray(); - $this->assertStringContainsString('title', $tags); + $tags = $entry->getTagsLabel(); + + $this->assertContains('title', $tags); } } }