diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-03-27 17:09:33 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-03-27 17:09:33 +0200 |
commit | 2baca964f38e658f60c8b9f81a9db289ba85bd0d (patch) | |
tree | f229054b676da315fba9e0ee35d90e838c5e37a5 | |
parent | 5a4ee4ae0fe7bed85fc68a9e96aee8bf5d1ee782 (diff) | |
download | wallabag-2baca964f38e658f60c8b9f81a9db289ba85bd0d.tar.gz wallabag-2baca964f38e658f60c8b9f81a9db289ba85bd0d.tar.zst wallabag-2baca964f38e658f60c8b9f81a9db289ba85bd0d.zip |
Simplify tag creation from entry
Testing that a tag exist or is assigned to the current entry isn't important in the tag controler since the `assignTagsToEntry` is already doing that job.
So it simplify the controller.
3 files changed, 40 insertions, 21 deletions
diff --git a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php index ccb72d23..04875f29 100644 --- a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php | |||
@@ -171,6 +171,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
171 | $this->client->request('POST', '/api/entries.json', array( | 171 | $this->client->request('POST', '/api/entries.json', array( |
172 | 'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', | 172 | 'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', |
173 | 'archive' => '1', | 173 | 'archive' => '1', |
174 | 'tags' => 'google, apple', | ||
174 | )); | 175 | )); |
175 | 176 | ||
176 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 177 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
@@ -181,7 +182,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
181 | $this->assertEquals('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); | 182 | $this->assertEquals('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); |
182 | $this->assertEquals(true, $content['is_archived']); | 183 | $this->assertEquals(true, $content['is_archived']); |
183 | $this->assertEquals(false, $content['is_starred']); | 184 | $this->assertEquals(false, $content['is_starred']); |
184 | $this->assertCount(1, $content['tags']); | 185 | $this->assertCount(2, $content['tags']); |
185 | } | 186 | } |
186 | 187 | ||
187 | public function testPostArchivedAndStarredEntry() | 188 | public function testPostArchivedAndStarredEntry() |
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index f31f4028..1a1f8c3d 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -20,31 +20,17 @@ class TagController extends Controller | |||
20 | */ | 20 | */ |
21 | public function addTagFormAction(Request $request, Entry $entry) | 21 | public function addTagFormAction(Request $request, Entry $entry) |
22 | { | 22 | { |
23 | $tag = new Tag(); | 23 | $form = $this->createForm(NewTagType::class, new Tag()); |
24 | $form = $this->createForm(NewTagType::class, $tag); | ||
25 | $form->handleRequest($request); | 24 | $form->handleRequest($request); |
26 | 25 | ||
27 | if ($form->isValid()) { | 26 | if ($form->isValid()) { |
28 | $existingTag = $this->getDoctrine() | 27 | $this->get('wallabag_core.content_proxy')->assignTagsToEntry( |
29 | ->getRepository('WallabagCoreBundle:Tag') | 28 | $entry, |
30 | ->findOneByLabel($tag->getLabel()); | 29 | $form->get('label')->getData() |
30 | ); | ||
31 | 31 | ||
32 | $em = $this->getDoctrine()->getManager(); | 32 | $em = $this->getDoctrine()->getManager(); |
33 | 33 | $em->persist($entry); | |
34 | if (is_null($existingTag)) { | ||
35 | $this->get('wallabag_core.content_proxy')->assignTagsToEntry( | ||
36 | $entry, | ||
37 | $tag | ||
38 | ); | ||
39 | $em->persist($tag); | ||
40 | } elseif (!$existingTag->hasEntry($entry)) { | ||
41 | $this->get('wallabag_core.content_proxy')->assignTagsToEntry( | ||
42 | $entry, | ||
43 | $existingTag | ||
44 | ); | ||
45 | $em->persist($existingTag); | ||
46 | } | ||
47 | |||
48 | $em->flush(); | 34 | $em->flush(); |
49 | 35 | ||
50 | $this->get('session')->getFlashBag()->add( | 36 | $this->get('session')->getFlashBag()->add( |
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php index 338121e7..1457c807 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php | |||
@@ -68,6 +68,38 @@ class TagControllerTest extends WallabagCoreTestCase | |||
68 | $this->assertEquals(2, count($newEntry->getTags())); | 68 | $this->assertEquals(2, count($newEntry->getTags())); |
69 | } | 69 | } |
70 | 70 | ||
71 | public function testAddMultipleTagToEntry() | ||
72 | { | ||
73 | $this->logInAs('admin'); | ||
74 | $client = $this->getClient(); | ||
75 | |||
76 | $entry = $client->getContainer() | ||
77 | ->get('doctrine.orm.entity_manager') | ||
78 | ->getRepository('WallabagCoreBundle:Entry') | ||
79 | ->findOneByUsernameAndNotArchived('admin'); | ||
80 | |||
81 | $crawler = $client->request('GET', '/view/'.$entry->getId()); | ||
82 | |||
83 | $form = $crawler->filter('form[name=tag]')->form(); | ||
84 | |||
85 | $data = array( | ||
86 | 'tag[label]' => 'foo2, bar2', | ||
87 | ); | ||
88 | |||
89 | $client->submit($form, $data); | ||
90 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
91 | |||
92 | $newEntry = $client->getContainer() | ||
93 | ->get('doctrine.orm.entity_manager') | ||
94 | ->getRepository('WallabagCoreBundle:Entry') | ||
95 | ->find($entry->getId()); | ||
96 | |||
97 | $tags = $newEntry->getTags()->toArray(); | ||
98 | $this->assertGreaterThanOrEqual(2, count($tags)); | ||
99 | $this->assertNotEquals(false, array_search('foo2', $tags), 'Tag foo2 is assigned to the entry'); | ||
100 | $this->assertNotEquals(false, array_search('bar2', $tags), 'Tag bar2 is assigned to the entry'); | ||
101 | } | ||
102 | |||
71 | public function testRemoveTagFromEntry() | 103 | public function testRemoveTagFromEntry() |
72 | { | 104 | { |
73 | $this->logInAs('admin'); | 105 | $this->logInAs('admin'); |