diff options
author | Kevin Decherf <kevin@kdecherf.com> | 2020-04-15 22:41:03 +0200 |
---|---|---|
committer | Kevin Decherf <kevin@kdecherf.com> | 2020-04-18 18:12:33 +0200 |
commit | 48f9a9632d2823be38883628ddfe62344cc282b1 (patch) | |
tree | f1b2ae4caaaaed72e1a739b0712518d2728bb7c5 /tests | |
parent | a19caf8a37dfd59a4e270507ec08e9fc259e3e1e (diff) | |
download | wallabag-48f9a9632d2823be38883628ddfe62344cc282b1.tar.gz wallabag-48f9a9632d2823be38883628ddfe62344cc282b1.tar.zst wallabag-48f9a9632d2823be38883628ddfe62344cc282b1.zip |
TagController: support merging labels when renaming one with label of another
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 80903b95..fb066632 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | |||
@@ -304,6 +304,133 @@ class TagControllerTest extends WallabagCoreTestCase | |||
304 | $this->assertTrue($newTag[0]->hasEntry($freshEntry), 'Tag is still assigned to the entry.'); | 304 | $this->assertTrue($newTag[0]->hasEntry($freshEntry), 'Tag is still assigned to the entry.'); |
305 | } | 305 | } |
306 | 306 | ||
307 | public function testRenameTagWithSameLabelDifferentCase() | ||
308 | { | ||
309 | $tagLabel = 'same label'; | ||
310 | $newTagLabel = 'saMe labEl'; | ||
311 | $this->logInAs('admin'); | ||
312 | $client = $this->getClient(); | ||
313 | |||
314 | $tag = new Tag(); | ||
315 | $tag->setLabel($tagLabel); | ||
316 | |||
317 | $entry = new Entry($this->getLoggedInUser()); | ||
318 | $entry->setUrl('http://0.0.0.0/foobar'); | ||
319 | $entry->addTag($tag); | ||
320 | $this->getEntityManager()->persist($entry); | ||
321 | |||
322 | $this->getEntityManager()->flush(); | ||
323 | $this->getEntityManager()->clear(); | ||
324 | |||
325 | // We make a first request to set an history and test redirection after tag deletion | ||
326 | $crawler = $client->request('GET', '/tag/list'); | ||
327 | $form = $crawler->filter('#tag-' . $tag->getId() . ' form')->form(); | ||
328 | |||
329 | $data = [ | ||
330 | 'tag[label]' => $newTagLabel, | ||
331 | ]; | ||
332 | |||
333 | $client->submit($form, $data); | ||
334 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
335 | $this->assertNotContains('flashes.tag.notice.tag_renamed', $crawler->filter('body')->extract(['_text'])[0]); | ||
336 | |||
337 | $freshEntry = $client->getContainer() | ||
338 | ->get('doctrine.orm.entity_manager') | ||
339 | ->getRepository('WallabagCoreBundle:Entry') | ||
340 | ->find($entry->getId()); | ||
341 | |||
342 | $tags = []; | ||
343 | |||
344 | $tagsFromEntry = $freshEntry->getTags()->toArray(); | ||
345 | foreach ($tagsFromEntry as $key => $item) { | ||
346 | $tags[$key] = $item->getLabel(); | ||
347 | } | ||
348 | |||
349 | $this->assertFalse(array_search($newTagLabel, $tags, true)); | ||
350 | |||
351 | $tagFromRepo = $client->getContainer() | ||
352 | ->get('doctrine.orm.entity_manager') | ||
353 | ->getRepository('WallabagCoreBundle:Tag') | ||
354 | ->findByLabel($tagLabel); | ||
355 | |||
356 | $newTagFromRepo = $client->getContainer() | ||
357 | ->get('doctrine.orm.entity_manager') | ||
358 | ->getRepository('WallabagCoreBundle:Tag') | ||
359 | ->findByLabel($newTagLabel); | ||
360 | |||
361 | $this->assertCount(0, $newTagFromRepo); | ||
362 | $this->assertCount(1, $tagFromRepo); | ||
363 | |||
364 | $this->assertSame($tag->getId(), $tagFromRepo[0]->getId(), 'Tag is unchanged.'); | ||
365 | |||
366 | $this->assertTrue($tagFromRepo[0]->hasEntry($freshEntry), 'Tag is still assigned to the entry.'); | ||
367 | } | ||
368 | |||
369 | public function testRenameTagWithExistingLabel() | ||
370 | { | ||
371 | $tagLabel = 'existing label'; | ||
372 | $previousTagLabel = 'previous label'; | ||
373 | $this->logInAs('admin'); | ||
374 | $client = $this->getClient(); | ||
375 | |||
376 | $tag = new Tag(); | ||
377 | $tag->setLabel($tagLabel); | ||
378 | |||
379 | $previousTag = new Tag(); | ||
380 | $previousTag->setLabel($previousTagLabel); | ||
381 | |||
382 | $entry1 = new Entry($this->getLoggedInUser()); | ||
383 | $entry1->setUrl('http://0.0.0.0/foobar'); | ||
384 | $entry1->addTag($previousTag); | ||
385 | $this->getEntityManager()->persist($entry1); | ||
386 | |||
387 | $entry2 = new Entry($this->getLoggedInUser()); | ||
388 | $entry2->setUrl('http://0.0.0.0/baz'); | ||
389 | $entry2->addTag($tag); | ||
390 | $this->getEntityManager()->persist($entry2); | ||
391 | |||
392 | $this->getEntityManager()->flush(); | ||
393 | $this->getEntityManager()->clear(); | ||
394 | |||
395 | // We make a first request to set an history and test redirection after tag deletion | ||
396 | $crawler = $client->request('GET', '/tag/list'); | ||
397 | $form = $crawler->filter('#tag-' . $previousTag->getId() . ' form')->form(); | ||
398 | |||
399 | $data = [ | ||
400 | 'tag[label]' => $tagLabel, | ||
401 | ]; | ||
402 | |||
403 | $client->submit($form, $data); | ||
404 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
405 | $this->assertNotContains('flashes.tag.notice.tag_renamed', $crawler->filter('body')->extract(['_text'])[0]); | ||
406 | |||
407 | $freshEntry1 = $client->getContainer() | ||
408 | ->get('doctrine.orm.entity_manager') | ||
409 | ->getRepository('WallabagCoreBundle:Entry') | ||
410 | ->find($entry1->getId()); | ||
411 | |||
412 | $freshEntry2 = $client->getContainer() | ||
413 | ->get('doctrine.orm.entity_manager') | ||
414 | ->getRepository('WallabagCoreBundle:Entry') | ||
415 | ->find($entry2->getId()); | ||
416 | |||
417 | $tagFromRepo = $client->getContainer() | ||
418 | ->get('doctrine.orm.entity_manager') | ||
419 | ->getRepository('WallabagCoreBundle:Tag') | ||
420 | ->findByLabel($tagLabel); | ||
421 | |||
422 | $previousTagFromRepo = $client->getContainer() | ||
423 | ->get('doctrine.orm.entity_manager') | ||
424 | ->getRepository('WallabagCoreBundle:Tag') | ||
425 | ->findByLabel($previousTagLabel); | ||
426 | |||
427 | $this->assertCount(1, $tagFromRepo); | ||
428 | |||
429 | $this->assertTrue($tagFromRepo[0]->hasEntry($freshEntry1)); | ||
430 | $this->assertTrue($tagFromRepo[0]->hasEntry($freshEntry2), 'Tag is assigned to the entry.'); | ||
431 | $this->assertFalse($previousTagFromRepo[0]->hasEntry($freshEntry1)); | ||
432 | } | ||
433 | |||
307 | public function testAddUnicodeTagLabel() | 434 | public function testAddUnicodeTagLabel() |
308 | { | 435 | { |
309 | $this->logInAs('admin'); | 436 | $this->logInAs('admin'); |