]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #2218 from wallabag/api-delete-tags-1982
authorNicolas Lœuillet <nicolas@loeuillet.org>
Tue, 23 Aug 2016 09:51:13 +0000 (11:51 +0200)
committerGitHub <noreply@github.com>
Tue, 23 Aug 2016 09:51:13 +0000 (11:51 +0200)
Delete tag or tags by label

24 files changed:
src/Wallabag/ApiBundle/Controller/WallabagRestController.php
src/Wallabag/CoreBundle/Controller/EntryController.php
src/Wallabag/CoreBundle/Controller/ExportController.php
src/Wallabag/CoreBundle/Controller/TagController.php
src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php
src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php [new file with mode: 0644]
src/Wallabag/CoreBundle/Repository/EntryRepository.php
src/Wallabag/CoreBundle/Resources/config/services.yml
src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/baggy/Tag/tags.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig
tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
tests/Wallabag/CoreBundle/Controller/TagControllerTest.php

index 03eb9b0848272381bfbc3dd550c476068d55dcd3..869fdc56ab1ba54dbf787d3f281fc357a180fa44 100644 (file)
@@ -329,6 +329,77 @@ class WallabagRestController extends FOSRestController
         return $this->renderJsonResponse($json);
     }
 
+    /**
+     * Permanently remove one tag from **every** entry.
+     *
+     * @ApiDoc(
+     *      requirements={
+     *          {"name"="tag", "dataType"="string", "required"=true, "requirement"="\w+", "description"="Tag as a string"}
+     *      }
+     * )
+     *
+     * @return Response
+     */
+    public function deleteTagLabelAction(Request $request)
+    {
+        $this->validateAuthentication();
+        $label = $request->request->get('tag', '');
+
+        $tag = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($label);
+
+        if (empty($tag)) {
+            throw $this->createNotFoundException('Tag not found');
+        }
+
+        $this->getDoctrine()
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->removeTag($this->getUser()->getId(), $tag);
+
+        $json = $this->get('serializer')->serialize($tag, 'json');
+
+        return $this->renderJsonResponse($json);
+    }
+
+    /**
+     * Permanently remove some tags from **every** entry.
+     *
+     * @ApiDoc(
+     *      requirements={
+     *          {"name"="tags", "dataType"="string", "required"=true, "format"="tag1,tag2", "description"="Tags as strings (comma splitted)"}
+     *      }
+     * )
+     *
+     * @return Response
+     */
+    public function deleteTagsLabelAction(Request $request)
+    {
+        $this->validateAuthentication();
+
+        $tagsLabels = $request->request->get('tags', '');
+
+        $tags = [];
+
+        foreach (explode(',', $tagsLabels) as $tagLabel) {
+            $tagEntity = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($tagLabel);
+
+            if (!empty($tagEntity)) {
+                $tags[] = $tagEntity;
+            }
+        }
+
+        if (empty($tags)) {
+            throw $this->createNotFoundException('Tags not found');
+        }
+
+        $this->getDoctrine()
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->removeTags($this->getUser()->getId(), $tags);
+
+        $json = $this->get('serializer')->serialize($tags, 'json');
+
+        return $this->renderJsonResponse($json);
+    }
+
     /**
      * Permanently remove one tag from **every** entry.
      *
@@ -352,6 +423,7 @@ class WallabagRestController extends FOSRestController
 
         return $this->renderJsonResponse($json);
     }
+
     /**
      * Retrieve version number.
      *
index ccdf940669bde3d5aa00073256c5607e8ba1805c..93db0d6caa117d1d0ba9442c8b4a3ea66ace11c8 100644 (file)
@@ -4,7 +4,6 @@ namespace Wallabag\CoreBundle\Controller;
 
 use Pagerfanta\Adapter\DoctrineORMAdapter;
 use Pagerfanta\Exception\OutOfRangeCurrentPageException;
-use Pagerfanta\Pagerfanta;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;
@@ -257,9 +256,10 @@ class EntryController extends Controller
         }
 
         $pagerAdapter = new DoctrineORMAdapter($qb->getQuery());
-        $entries = new Pagerfanta($pagerAdapter);
 
-        $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage());
+        $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')
+            ->prepare($pagerAdapter, $page);
+
         try {
             $entries->setCurrentPage($page);
         } catch (OutOfRangeCurrentPageException $e) {
index 944c755def342a0a8b1b99484df7776212d5ed25..959b308d8bc0e5cff8bfce213b9e8f50c2970e19 100644 (file)
@@ -46,7 +46,7 @@ class ExportController extends Controller
      *
      * @Route("/export/{category}.{format}", name="export_entries", requirements={
      *     "format": "epub|mobi|pdf|json|xml|txt|csv",
-     *     "category": "all|unread|starred|archive"
+     *     "category": "all|unread|starred|archive|tag_entries"
      * })
      *
      * @return \Symfony\Component\HttpFoundation\Response
index 8645fb442621b933a10df0d127c5919b4cecd3d6..1cbc413d644e616727ce0dca82af9b6f5582cd15 100644 (file)
@@ -2,12 +2,15 @@
 
 namespace Wallabag\CoreBundle\Controller;
 
+use Pagerfanta\Adapter\ArrayAdapter;
+use Pagerfanta\Exception\OutOfRangeCurrentPageException;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;
 use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\CoreBundle\Entity\Tag;
 use Wallabag\CoreBundle\Form\Type\NewTagType;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
 
 class TagController extends Controller
 {
@@ -90,4 +93,45 @@ class TagController extends Controller
             ]
         );
     }
+
+    /**
+     * @param Tag $tag
+     * @param int $page
+     *
+     * @Route("/tag/list/{slug}/{page}", name="tag_entries", defaults={"page" = "1"})
+     * @ParamConverter("tag", options={"mapping": {"slug": "slug"}})
+     *
+     * @return \Symfony\Component\HttpFoundation\Response
+     */
+    public function showEntriesForTagAction(Tag $tag, $page, Request $request)
+    {
+        $entriesByTag = $this->getDoctrine()
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findAllByTagId($this->getUser()->getId(), $tag->getId());
+
+        $pagerAdapter = new ArrayAdapter($entriesByTag);
+
+        $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')
+            ->prepare($pagerAdapter, $page);
+
+        try {
+            $entries->setCurrentPage($page);
+        } catch (OutOfRangeCurrentPageException $e) {
+            if ($page > 1) {
+                return $this->redirect($this->generateUrl($request->get('_route'), [
+                    'slug' => $tag->getSlug(),
+                    'page' => $entries->getNbPages(),
+                ]), 302);
+            }
+        }
+
+        return $this->render(
+            'WallabagCoreBundle:Entry:entries.html.twig',
+            [
+                'form' => null,
+                'entries' => $entries,
+                'currentPage' => $page,
+            ]
+        );
+    }
 }
index 8553dced4596c36abe852aaaabc6b58666a563d0..09e99f36bb46b222544d6cfe11484e270231ccac 100644 (file)
@@ -28,6 +28,13 @@ class LoadTagData extends AbstractFixture implements OrderedFixtureInterface
 
         $this->addReference('bar-tag', $tag2);
 
+        $tag3 = new Tag();
+        $tag3->setLabel('baz');
+
+        $manager->persist($tag3);
+
+        $this->addReference('baz-tag', $tag3);
+
         $manager->flush();
     }
 
diff --git a/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php b/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php
new file mode 100644 (file)
index 0000000..f9066be
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+
+namespace Wallabag\CoreBundle\Helper;
+
+use Pagerfanta\Adapter\AdapterInterface;
+use Pagerfanta\Pagerfanta;
+use Symfony\Component\Routing\Router;
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
+
+class PreparePagerForEntries
+{
+    private $user;
+    private $router;
+
+    public function __construct(TokenStorage $token, Router $router)
+    {
+        $this->user = $token->getToken()->getUser();
+        $this->router = $router;
+    }
+
+    /**
+     * @param AdapterInterface $adapter
+     * @param int              $page
+     *
+     * @return null|Pagerfanta
+     */
+    public function prepare(AdapterInterface $adapter, $page = 1)
+    {
+        $entries = new Pagerfanta($adapter);
+        $entries->setMaxPerPage($this->user->getConfig()->getItemsPerPage());
+
+        return $entries;
+    }
+}
index e9351d85ef439451584a7b2315c5a1fbc56854b9..fada40bbd4c5c8e24010c0b2140e23a6b03ecb35 100644 (file)
@@ -222,6 +222,19 @@ class EntryRepository extends EntityRepository
         $this->getEntityManager()->flush();
     }
 
+    /**
+     * Remove tags from all user entries.
+     *
+     * @param int        $userId
+     * @param Array<Tag> $tags
+     */
+    public function removeTags($userId, $tags)
+    {
+        foreach ($tags as $tag) {
+            $this->removeTag($userId, $tag);
+        }
+    }
+
     /**
      * Find all entries that are attached to a give tag id.
      *
index f8835198caff7d55ffa12a9a5bf1bf64aef0be8f..e95ef4520f990cf174765179eda7dc197d53cd21 100644 (file)
@@ -119,3 +119,9 @@ services:
         class: Wallabag\CoreBundle\Helper\Redirect
         arguments:
             - "@router"
+
+    wallabag_core.helper.prepare_pager_for_entries:
+        class: Wallabag\CoreBundle\Helper\PreparePagerForEntries
+        arguments:
+            - "@security.token_storage"
+            - "@router"
index c24475d2688b1780bd4e78a124d5a264f67e048b..8798853968948a1a1481565975c8b69a8e65759f 100644 (file)
@@ -139,6 +139,7 @@ entry:
         # starred: 'Starred entries'
         # archived: 'Archived entries'
         # filtered: 'Filtered entries'
+        # filtered_tags: 'Filtered by tags'
     list:
         # number_on_the_page: '{0} There is no entry.|{1} There is one entry.|]1,Inf[ There are %count% entries.'
         reading_time: 'estimeret læsetid'
index 384ec09a15eeda9ad4a312f2aa5332508bae6923..461967d612783d3c14587c6d16be2387488d7776 100644 (file)
@@ -139,6 +139,7 @@ entry:
         starred: 'Favorisierte Einträge'
         archived: 'Archivierte Einträge'
         filtered: 'Gefilterte Einträge'
+        # filtered_tags: 'Filtered by tags'
     list:
         number_on_the_page: '{0} Es gibt keine Einträge.|{1} Es gibt einen Eintrag.|]1,Inf[ Es gibt %count% Einträge.'
         reading_time: 'geschätzte Lesezeit'
index ea860564b9eabf177b824bd59d6dfc241d15104e..600b74724e3c05b549d8cca0ef59a5c3fbe1e7bd 100644 (file)
@@ -139,6 +139,7 @@ entry:
         starred: 'Starred entries'
         archived: 'Archived entries'
         filtered: 'Filtered entries'
+        filtered_tags: 'Filtered by tags'
     list:
         number_on_the_page: '{0} There are no entries.|{1} There is one entry.|]1,Inf[ There are %count% entries.'
         reading_time: 'estimated reading time'
index f64e95d5acac8bf3943db45d55f841169e93f8d4..6da8a593162483e62ee4883000d50484f89d15ec 100644 (file)
@@ -139,6 +139,7 @@ entry:
         starred: 'Artículos favoritos'
         archived: 'Artículos archivados'
         filtered: 'Artículos filtrados'
+        # filtered_tags: 'Filtered by tags'
     list:
         number_on_the_page: '{0} No hay artículos.|{1} Hay un artículo.|]1,Inf[ Hay %count% artículos.'
         reading_time: 'tiempo estimado de lectura'
index e3592a782865c8bb0f0a6acfa7d7f116325e2086..4684b08b7489ae018bf229bdd1136d2c13c48b7c 100644 (file)
@@ -139,6 +139,7 @@ entry:
         starred: 'مقاله‌های برگزیده'
         archived: 'مقاله‌های بایگانی‌شده'
         filtered: 'مقاله‌های فیلترشده'
+        # filtered_tags: 'Filtered by tags'
     list:
         number_on_the_page: '{0} هیج مقاله‌ای نیست.|{1} یک مقاله هست.|]1,Inf[ %count% مقاله هست.'
         reading_time: 'زمان تخمینی برای خواندن'
index 9e47d600a005af84c7b2faae6441c7514cfe659b..2b6e419465e8b46b130f2db8e9c25ec94a842296 100644 (file)
@@ -139,6 +139,7 @@ entry:
         starred: 'Articles favoris'
         archived: 'Articles lus'
         filtered: 'Articles filtrés'
+        filtered_tags: 'Articles filtrés par tags'
     list:
         number_on_the_page: "{0} Il n'y a pas d'articles.|{1} Il y a un article.|]1,Inf[ Il y a %count% articles."
         reading_time: 'durée de lecture'
index 1e23168bf7ff8c49e20837ef0f741037f4f98b45..954356067cb2e9af0e154ae943269f6083358729 100644 (file)
@@ -139,6 +139,7 @@ entry:
         starred: 'Articles favorits'
         archived: 'Articles legits'
         filtered: 'Articles filtrats'
+        # filtered_tags: 'Filtered by tags'
     list:
         number_on_the_page: "{0} I a pas cap d'article.|{1} I a un article.|]1,Inf[ I a %count% articles."
         reading_time: 'durada de lectura'
index 0a325c574ff68e3857247c7bf13a9f6437071f9e..b0b7e49b71a62a401860285763060b0f95570511 100644 (file)
@@ -139,6 +139,7 @@ entry:
         starred: 'Wpisy oznaczone gwiazdką'
         archived: 'Zarchiwizowane wpisy'
         filtered: 'Odfiltrowane wpisy'
+        # filtered_tags: 'Filtered by tags'
     list:
         number_on_the_page: '{0} Nie ma wpisów.|{1} Jest jeden wpis.|]1,Inf[ Są %count% wpisy.'
         reading_time: 'szacunkowy czas czytania'
index 42ad28eec58f04dd45edd9ac0cf5c9c3ff7fb7fa..d735df4c0e504bc7f74673ed109d9ed362759873 100644 (file)
@@ -139,6 +139,7 @@ entry:
         # starred: 'Starred entries'
         # archived: 'Archived entries'
         # filtered: 'Filtered entries'
+        # filtered_tags: 'Filtered by tags'
     list:
         # number_on_the_page: '{0} There is no entry.|{1} There is one entry.|]1,Inf[ There are %count% entries.'
         reading_time: 'timp estimat de citire'
index a60dfc86105c9b226c4d58c485979711fd56a85b..77bfa0f080bafd9eb417f63c12e56081e6bf99ba 100644 (file)
@@ -139,6 +139,7 @@ entry:
         # starred: 'Starred entries'
         # archived: 'Archived entries'
         # filtered: 'Filtered entries'
+        # filtered_tags: 'Filtered by tags'
     list:
         number_on_the_page: '{0} Herhangi bir makale yok.|{1} Burada bir adet makale var.|]1,Inf[ Burada %count% adet makale var.'
         reading_time: 'tahmini okuma süresi'
index 92eecb9be2053fab0ac7a4d0ddf5289a9386e2ac..9380e67afbf38ba548a6014bb00946be39898107 100644 (file)
@@ -1,6 +1,20 @@
 {% extends "WallabagCoreBundle::layout.html.twig" %}
 
-{% block title %}{{ 'entry.page_titles.unread'|trans }}{% endblock %}
+{% block title %}
+    {% set currentRoute = app.request.attributes.get('_route') %}
+
+    {% if currentRoute == 'starred' %}
+        {{ 'entry.page_titles.starred'|trans }}
+    {% elseif currentRoute == 'archive' %}
+        {{ 'entry.page_titles.archived'|trans }}
+    {% elseif currentRoute == 'all' %}
+        {{ 'entry.page_titles.filtered'|trans }}
+    {% elseif currentRoute == 'tag_entries' %}
+        {{ 'entry.page_titles.filtered_tags'|trans }}
+    {% else %}
+        {{ 'entry.page_titles.unread'|trans }}
+    {% endif %}
+{% endblock %}
 
 {% block content %}
     {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %}
@@ -44,7 +58,6 @@
         </div>
     {% endfor %}
 
-
     <!-- Export -->
     <aside id="download-form">
     {% set currentRoute = app.request.attributes.get('_route') %}
             {% if craue_setting('export_xml') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'xml' }) }}">XML</a></li>{% endif %}
         </ul>
     </aside>
+
     <!-- Filter -->
-    <aside id="filter-form">
+    {% if form is not null %}
+    <aside id="filter-form" class="">
         <form method="get" action="{{ path('all') }}">
             <h2>{{ 'entry.filters.title'|trans }}</h2>
             <a href="javascript: void(null);" id="filter-form-close" class="close-button--popup close-button">&times;</a>
             </div>
         </form>
     </aside>
-
-    {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %}
+    {% endif %}
 {% endblock %}
index 524a1d237bd818dfe3749854acd6fa7debdbcb80..739e14864e1ab79b06165e55858f5a8b3ceae45a 100644 (file)
@@ -9,7 +9,7 @@
 
     <ul>
     {% for tag in tags %}
-        <li id="tag-{{ tag.id|e }}">{{tag.label}} ({{ tag.getEntriesByUserId(app.user.id) | length }})</li>
+        <li id="tag-{{ tag.id|e }}"><a href="{{ path('tag_entries', {'slug': tag.slug}) }}">{{tag.label}} ({{ tag.entries.getValues | length }})</a></li>
     {% endfor %}
     </ul>
 {% endblock %}
index eca8924ec6149845bbc473a5f0e0f56d14c4a365..2a972e1cf17edb9707b572a03611b6a5a239439e 100644 (file)
@@ -9,10 +9,11 @@
     {{ 'entry.page_titles.archived'|trans }}
   {% elseif currentRoute == 'all' %}
     {{ 'entry.page_titles.filtered'|trans }}
+  {% elseif currentRoute == 'tag_entries' %}
+      {{ 'entry.page_titles.filtered_tags'|trans }}
   {% else %}
     {{ 'entry.page_titles.unread'|trans }}
   {% endif %}
-
 {% endblock %}
 
 {% block content %}
     </div>
 
     <!-- Filters -->
+    {% if form is not null %}
     <div id="filters" class="side-nav fixed right-aligned">
         <form action="{{ path('all') }}">
 
 
         </form>
     </div>
-    {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %}
+    {% endif %}
+
 {% endblock %}
index d958c4b85e51aaf3067791b13ce925a11ee2ca72..9495f5436d2f996f1ceee825fb75fd2f83d4fde4 100644 (file)
@@ -9,7 +9,7 @@
     <br />
     <ul class="row data">
     {% for tag in tags %}
-        <li id="tag-{{ tag.id|e }}" class="col l4 m6 s12">{{tag.label}} ({{ tag.getEntriesByUserId(app.user.id) | length }})</li>
+        <li id="tag-{{ tag.id|e }}" class="col l4 m6 s12"><a href="{{ path('tag_entries', {'slug': tag.slug}) }}">{{tag.label}} ({{ tag.entries.getValues | length }})</a></li>
     {% endfor %}
     </ul>
 {% endblock %}
index 528366afa08517c6a88d0cde45743286778f0882..ee5b2ab7c94b196041875be53bc2bd91670b8d6e 100644 (file)
@@ -3,6 +3,7 @@
 namespace Tests\Wallabag\ApiBundle\Controller;
 
 use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
+use Wallabag\CoreBundle\Entity\Tag;
 
 class WallabagRestControllerTest extends WallabagApiTestCase
 {
@@ -359,7 +360,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
         $entry = $this->client->getContainer()
             ->get('doctrine.orm.entity_manager')
             ->getRepository('WallabagCoreBundle:Entry')
-            ->findOneWithTags(1);
+            ->findOneWithTags($this->user->getId());
 
         $entry = $entry[0];
 
@@ -421,7 +422,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
         $entry = $this->client->getContainer()
             ->get('doctrine.orm.entity_manager')
             ->getRepository('WallabagCoreBundle:Entry')
-            ->findOneWithTags(1);
+            ->findOneWithTags($this->user->getId());
         $entry = $entry[0];
 
         if (!$entry) {
@@ -472,7 +473,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
         $this->assertEquals($tag['label'], $content['label']);
         $this->assertEquals($tag['slug'], $content['slug']);
 
-        $entries = $entry = $this->client->getContainer()
+        $entries = $this->client->getContainer()
             ->get('doctrine.orm.entity_manager')
             ->getRepository('WallabagCoreBundle:Entry')
             ->findAllByTagId($this->user->getId(), $tag['id']);
@@ -480,6 +481,112 @@ class WallabagRestControllerTest extends WallabagApiTestCase
         $this->assertCount(0, $entries);
     }
 
+    public function testDeleteTagByLabel()
+    {
+        $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
+        $entry = $this->client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findOneWithTags($this->user->getId());
+
+        $entry = $entry[0];
+
+        $tag = new Tag();
+        $tag->setLabel('Awesome tag for test');
+        $em->persist($tag);
+
+        $entry->addTag($tag);
+
+        $em->persist($entry);
+        $em->flush();
+
+        $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]);
+
+        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
+
+        $content = json_decode($this->client->getResponse()->getContent(), true);
+
+        $this->assertArrayHasKey('label', $content);
+        $this->assertEquals($tag->getLabel(), $content['label']);
+        $this->assertEquals($tag->getSlug(), $content['slug']);
+
+        $entries = $this->client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findAllByTagId($this->user->getId(), $tag->getId());
+
+        $this->assertCount(0, $entries);
+    }
+
+    public function testDeleteTagByLabelNotFound()
+    {
+        $this->client->request('DELETE', '/api/tag/label.json', ['tag' => 'does not exist']);
+
+        $this->assertEquals(404, $this->client->getResponse()->getStatusCode());
+    }
+
+    public function testDeleteTagsByLabel()
+    {
+        $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
+        $entry = $this->client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findOneWithTags($this->user->getId());
+
+        $entry = $entry[0];
+
+        $tag = new Tag();
+        $tag->setLabel('Awesome tag for tagsLabel');
+        $em->persist($tag);
+
+        $tag2 = new Tag();
+        $tag2->setLabel('Awesome tag for tagsLabel 2');
+        $em->persist($tag2);
+
+        $entry->addTag($tag);
+        $entry->addTag($tag2);
+
+        $em->persist($entry);
+        $em->flush();
+
+        $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]);
+
+        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
+
+        $content = json_decode($this->client->getResponse()->getContent(), true);
+
+        $this->assertCount(2, $content);
+
+        $this->assertArrayHasKey('label', $content[0]);
+        $this->assertEquals($tag->getLabel(), $content[0]['label']);
+        $this->assertEquals($tag->getSlug(), $content[0]['slug']);
+
+        $this->assertArrayHasKey('label', $content[1]);
+        $this->assertEquals($tag2->getLabel(), $content[1]['label']);
+        $this->assertEquals($tag2->getSlug(), $content[1]['slug']);
+
+        $entries = $this->client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findAllByTagId($this->user->getId(), $tag->getId());
+
+        $this->assertCount(0, $entries);
+
+        $entries = $this->client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findAllByTagId($this->user->getId(), $tag2->getId());
+
+        $this->assertCount(0, $entries);
+    }
+
+    public function testDeleteTagsByLabelNotFound()
+    {
+        $this->client->request('DELETE', '/api/tags/label.json', ['tags' => 'does not exist']);
+
+        $this->assertEquals(404, $this->client->getResponse()->getStatusCode());
+    }
+
     public function testGetVersion()
     {
         $this->client->request('GET', '/api/version');
index 58450e5fb0933632480e8a7c60e6c30a20efc7a3..71652760d8a592c2729147ff4691527d1c819d3b 100644 (file)
@@ -131,4 +131,35 @@ class TagControllerTest extends WallabagCoreTestCase
 
         $this->assertEquals(404, $client->getResponse()->getStatusCode());
     }
+
+    public function testShowEntriesForTagAction()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $entry = $client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findOneByUsernameAndNotArchived('admin');
+
+        $tag = $client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Tag')
+            ->findOneByEntryAndTagLabel($entry, 'foo');
+
+        $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
+
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());
+        $this->assertCount(2, $crawler->filter('div[class=entry]'));
+
+        $tag = $client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Tag')
+            ->findOneByLabel('baz');
+
+        $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
+
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());
+        $this->assertCount(0, $crawler->filter('div[class=entry]'));
+    }
 }