diff options
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/TagController.php | 15 | ||||
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | 58 |
2 files changed, 67 insertions, 6 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index c228c27a..f7b78f5d 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -151,7 +151,10 @@ class TagController extends Controller | |||
151 | $form = $this->createForm(RenameTagType::class, new Tag()); | 151 | $form = $this->createForm(RenameTagType::class, new Tag()); |
152 | $form->handleRequest($request); | 152 | $form->handleRequest($request); |
153 | 153 | ||
154 | if ($form->isSubmitted() && $form->isValid()) { | 154 | if ($form->isSubmitted() |
155 | && $form->isValid() | ||
156 | && $form->get('label')->getData() !== $tag->getLabel() | ||
157 | ) { | ||
155 | $newTagLabel = $form->get('label')->getData(); | 158 | $newTagLabel = $form->get('label')->getData(); |
156 | $newTag = new Tag(); | 159 | $newTag = new Tag(); |
157 | $newTag->setLabel($newTagLabel); | 160 | $newTag->setLabel($newTagLabel); |
@@ -171,12 +174,12 @@ class TagController extends Controller | |||
171 | 174 | ||
172 | $em = $this->getDoctrine()->getManager(); | 175 | $em = $this->getDoctrine()->getManager(); |
173 | $em->flush(); | 176 | $em->flush(); |
174 | } | ||
175 | 177 | ||
176 | $this->get('session')->getFlashBag()->add( | 178 | $this->get('session')->getFlashBag()->add( |
177 | 'notice', | 179 | 'notice', |
178 | 'flashes.tag.notice.tag_renamed' | 180 | 'flashes.tag.notice.tag_renamed' |
179 | ); | 181 | ); |
182 | } | ||
180 | 183 | ||
181 | $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true); | 184 | $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true); |
182 | 185 | ||
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 20e60c32..80903b95 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | |||
@@ -211,6 +211,10 @@ class TagControllerTest extends WallabagCoreTestCase | |||
211 | $client->submit($form, $data); | 211 | $client->submit($form, $data); |
212 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | 212 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
213 | 213 | ||
214 | $crawler = $client->followRedirect(); | ||
215 | |||
216 | $this->assertContains('flashes.tag.notice.tag_renamed', $crawler->filter('body')->extract(['_text'])[0]); | ||
217 | |||
214 | $freshEntry = $client->getContainer() | 218 | $freshEntry = $client->getContainer() |
215 | ->get('doctrine.orm.entity_manager') | 219 | ->get('doctrine.orm.entity_manager') |
216 | ->getRepository('WallabagCoreBundle:Entry') | 220 | ->getRepository('WallabagCoreBundle:Entry') |
@@ -246,6 +250,60 @@ class TagControllerTest extends WallabagCoreTestCase | |||
246 | $this->assertTrue($newTag[0]->hasEntry($freshEntry2), 'New tag is assigned to the entry2.'); | 250 | $this->assertTrue($newTag[0]->hasEntry($freshEntry2), 'New tag is assigned to the entry2.'); |
247 | } | 251 | } |
248 | 252 | ||
253 | public function testRenameTagWithSameLabel() | ||
254 | { | ||
255 | $tagLabel = 'same label'; | ||
256 | $this->logInAs('admin'); | ||
257 | $client = $this->getClient(); | ||
258 | |||
259 | $tag = new Tag(); | ||
260 | $tag->setLabel($tagLabel); | ||
261 | |||
262 | $entry = new Entry($this->getLoggedInUser()); | ||
263 | $entry->setUrl('http://0.0.0.0/foobar'); | ||
264 | $entry->addTag($tag); | ||
265 | $this->getEntityManager()->persist($entry); | ||
266 | |||
267 | $this->getEntityManager()->flush(); | ||
268 | $this->getEntityManager()->clear(); | ||
269 | |||
270 | // We make a first request to set an history and test redirection after tag deletion | ||
271 | $crawler = $client->request('GET', '/tag/list'); | ||
272 | $form = $crawler->filter('#tag-' . $tag->getId() . ' form')->form(); | ||
273 | |||
274 | $data = [ | ||
275 | 'tag[label]' => $tagLabel, | ||
276 | ]; | ||
277 | |||
278 | $client->submit($form, $data); | ||
279 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
280 | $this->assertNotContains('flashes.tag.notice.tag_renamed', $crawler->filter('body')->extract(['_text'])[0]); | ||
281 | |||
282 | $freshEntry = $client->getContainer() | ||
283 | ->get('doctrine.orm.entity_manager') | ||
284 | ->getRepository('WallabagCoreBundle:Entry') | ||
285 | ->find($entry->getId()); | ||
286 | |||
287 | $tags = []; | ||
288 | |||
289 | $tagsFromEntry = $freshEntry->getTags()->toArray(); | ||
290 | foreach ($tagsFromEntry as $key => $item) { | ||
291 | $tags[$key] = $item->getLabel(); | ||
292 | } | ||
293 | |||
294 | $this->assertNotFalse(array_search($tag->getLabel(), $tags, true), 'Tag is still assigned to the entry.'); | ||
295 | |||
296 | $newTag = $client->getContainer() | ||
297 | ->get('doctrine.orm.entity_manager') | ||
298 | ->getRepository('WallabagCoreBundle:Tag') | ||
299 | ->findByLabel($tagLabel); | ||
300 | |||
301 | $this->assertCount(1, $newTag); | ||
302 | $this->assertSame($tag->getId(), $newTag[0]->getId(), 'Tag is unchanged.'); | ||
303 | |||
304 | $this->assertTrue($newTag[0]->hasEntry($freshEntry), 'Tag is still assigned to the entry.'); | ||
305 | } | ||
306 | |||
249 | public function testAddUnicodeTagLabel() | 307 | public function testAddUnicodeTagLabel() |
250 | { | 308 | { |
251 | $this->logInAs('admin'); | 309 | $this->logInAs('admin'); |