diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/TagControllerTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | 59 |
1 files changed, 27 insertions, 32 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index fa1a3539..af1ad7af 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Wallabag\CoreBundle\Entity\Entry; | ||
6 | use Wallabag\CoreBundle\Entity\Tag; | 7 | use Wallabag\CoreBundle\Entity\Tag; |
7 | 8 | ||
8 | class TagControllerTest extends WallabagCoreTestCase | 9 | class TagControllerTest extends WallabagCoreTestCase |
@@ -24,10 +25,11 @@ class TagControllerTest extends WallabagCoreTestCase | |||
24 | $this->logInAs('admin'); | 25 | $this->logInAs('admin'); |
25 | $client = $this->getClient(); | 26 | $client = $this->getClient(); |
26 | 27 | ||
27 | $entry = $client->getContainer() | 28 | $entry = new Entry($this->getLoggedInUser()); |
28 | ->get('doctrine.orm.entity_manager') | 29 | $entry->setUrl('http://0.0.0.0/foo'); |
29 | ->getRepository('WallabagCoreBundle:Entry') | 30 | $this->getEntityManager()->persist($entry); |
30 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | 31 | $this->getEntityManager()->flush(); |
32 | $this->getEntityManager()->clear(); | ||
31 | 33 | ||
32 | $crawler = $client->request('GET', '/view/'.$entry->getId()); | 34 | $crawler = $client->request('GET', '/view/'.$entry->getId()); |
33 | 35 | ||
@@ -41,23 +43,15 @@ class TagControllerTest extends WallabagCoreTestCase | |||
41 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 43 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
42 | 44 | ||
43 | // be sure to reload the entry | 45 | // be sure to reload the entry |
44 | $entry = $client->getContainer() | 46 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); |
45 | ->get('doctrine.orm.entity_manager') | 47 | $this->assertCount(1, $entry->getTags()); |
46 | ->getRepository('WallabagCoreBundle:Entry') | ||
47 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | ||
48 | |||
49 | $this->assertEquals(3, count($entry->getTags())); | ||
50 | 48 | ||
51 | // tag already exists and already assigned | 49 | // tag already exists and already assigned |
52 | $client->submit($form, $data); | 50 | $client->submit($form, $data); |
53 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 51 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
54 | 52 | ||
55 | $newEntry = $client->getContainer() | 53 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); |
56 | ->get('doctrine.orm.entity_manager') | 54 | $this->assertCount(1, $entry->getTags()); |
57 | ->getRepository('WallabagCoreBundle:Entry') | ||
58 | ->find($entry->getId()); | ||
59 | |||
60 | $this->assertEquals(3, count($newEntry->getTags())); | ||
61 | 55 | ||
62 | // tag already exists but still not assigned to this entry | 56 | // tag already exists but still not assigned to this entry |
63 | $data = [ | 57 | $data = [ |
@@ -67,12 +61,8 @@ class TagControllerTest extends WallabagCoreTestCase | |||
67 | $client->submit($form, $data); | 61 | $client->submit($form, $data); |
68 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 62 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
69 | 63 | ||
70 | $newEntry = $client->getContainer() | 64 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); |
71 | ->get('doctrine.orm.entity_manager') | 65 | $this->assertCount(2, $entry->getTags()); |
72 | ->getRepository('WallabagCoreBundle:Entry') | ||
73 | ->find($entry->getId()); | ||
74 | |||
75 | $this->assertEquals(3, count($newEntry->getTags())); | ||
76 | } | 66 | } |
77 | 67 | ||
78 | public function testAddMultipleTagToEntry() | 68 | public function testAddMultipleTagToEntry() |
@@ -116,20 +106,25 @@ class TagControllerTest extends WallabagCoreTestCase | |||
116 | $this->logInAs('admin'); | 106 | $this->logInAs('admin'); |
117 | $client = $this->getClient(); | 107 | $client = $this->getClient(); |
118 | 108 | ||
119 | $entry = $client->getContainer() | 109 | $tag = new Tag(); |
120 | ->get('doctrine.orm.entity_manager') | 110 | $tag->setLabel($this->tagName); |
121 | ->getRepository('WallabagCoreBundle:Entry') | 111 | $entry = new Entry($this->getLoggedInUser()); |
122 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | 112 | $entry->setUrl('http://0.0.0.0/foo'); |
123 | 113 | $entry->addTag($tag); | |
124 | $tag = $client->getContainer() | 114 | $this->getEntityManager()->persist($entry); |
125 | ->get('doctrine.orm.entity_manager') | 115 | $this->getEntityManager()->flush(); |
126 | ->getRepository('WallabagCoreBundle:Tag') | 116 | $this->getEntityManager()->clear(); |
127 | ->findOneByEntryAndTagLabel($entry, $this->tagName); | 117 | |
128 | 118 | // We make a first request to set an history and test redirection after tag deletion | |
119 | $client->request('GET', '/view/'.$entry->getId()); | ||
120 | $entryUri = $client->getRequest()->getUri(); | ||
129 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | 121 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); |
130 | 122 | ||
131 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 123 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
124 | $this->assertEquals($entryUri, $client->getResponse()->getTargetUrl()); | ||
132 | 125 | ||
126 | // re-retrieve the entry to be sure to get fresh data from database (mostly for tags) | ||
127 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); | ||
133 | $this->assertNotContains($this->tagName, $entry->getTags()); | 128 | $this->assertNotContains($this->tagName, $entry->getTags()); |
134 | 129 | ||
135 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | 130 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); |