From e42b13bcff41161ecdb4322dce1ef98a401482ca Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 30 May 2016 14:34:11 +0200 Subject: Change ManyToMany between entry & tag Following https://gist.github.com/Ocramius/3121916 Be sure to remove the related entity when removing an entity. Let say you have Entry -> EntryTag -> Tag. If you remove the entry: - before that commit, the EntryTag will stay (at least using SQLite). - with that commit, the related entity is removed --- .../Tests/Controller/EntryControllerTest.php | 34 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php') diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index c7087a71..5ce893c1 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -163,7 +163,7 @@ class EntryControllerTest extends WallabagCoreTestCase /** * This test will require an internet connection. */ - public function testPostNewThatWillBeTaggued() + public function testPostNewThatWillBeTagged() { $this->logInAs('admin'); $client = $this->getClient(); @@ -181,8 +181,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client->submit($form, $data); $this->assertEquals(302, $client->getResponse()->getStatusCode()); - - $client->followRedirect(); + $this->assertContains('/', $client->getResponse()->getTargetUrl()); $em = $client->getContainer() ->get('doctrine.orm.entity_manager'); @@ -196,6 +195,35 @@ class EntryControllerTest extends WallabagCoreTestCase $em->remove($entry); $em->flush(); + + // and now re-submit it to test the cascade persistence for tags after entry removal + // related https://github.com/wallabag/wallabag/issues/2121 + $crawler = $client->request('GET', '/new'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('form[name=entry]')->form(); + + $data = [ + 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master', + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertContains('/', $client->getResponse()->getTargetUrl()); + + $entry = $em + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUrl($url); + + $tags = $entry->getTags(); + + $this->assertCount(1, $tags); + $this->assertEquals('wallabag', $tags[0]->getLabel()); + + $em->remove($entry); + $em->flush(); } public function testArchive() -- cgit v1.2.3