- $entry = $client->getContainer()
- ->get('doctrine.orm.entity_manager')
- ->getRepository('WallabagCoreBundle:Entry')
- ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
-
- $tag = $client->getContainer()
- ->get('doctrine.orm.entity_manager')
- ->getRepository('WallabagCoreBundle:Tag')
- ->findOneByEntryAndTagLabel($entry, $this->tagName);
-
- $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId());
-
- $this->assertEquals(302, $client->getResponse()->getStatusCode());
-
+ $tag = new Tag();
+ $tag->setLabel($this->tagName);
+ $entry = new Entry($this->getLoggedInUser());
+ $entry->setUrl('http://0.0.0.0/foo');
+ $entry->addTag($tag);
+ $this->getEntityManager()->persist($entry);
+ $this->getEntityManager()->flush();
+ $this->getEntityManager()->clear();
+
+ // We make a first request to set an history and test redirection after tag deletion
+ $client->request('GET', '/view/' . $entry->getId());
+ $entryUri = $client->getRequest()->getUri();
+ $client->request('GET', '/remove-tag/' . $entry->getId() . '/' . $tag->getId());
+
+ $this->assertSame(302, $client->getResponse()->getStatusCode());
+ $this->assertSame($entryUri, $client->getResponse()->getTargetUrl());
+
+ // re-retrieve the entry to be sure to get fresh data from database (mostly for tags)
+ $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId());