diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2017-06-01 07:58:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-01 07:58:17 +0200 |
commit | 2a0eec07a5630401a9ceb7add65604f79238f10c (patch) | |
tree | bab2f2f763d4dca9f273a8ec1848f5da6c03ed20 /tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | |
parent | 757ec837bea7f57dcefb71b3b90c66299ed6a922 (diff) | |
parent | 7ab5eb9508921d84b4b4ec84a59135d536da748e (diff) | |
download | wallabag-2a0eec07a5630401a9ceb7add65604f79238f10c.tar.gz wallabag-2a0eec07a5630401a9ceb7add65604f79238f10c.tar.zst wallabag-2a0eec07a5630401a9ceb7add65604f79238f10c.zip |
Merge pull request #3137 from aaa2000/isolated-tests
Isolated tests
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/TagControllerTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | 59 |
1 files changed, 22 insertions, 37 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 80611a87..f9bf7b87 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(4, 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(4, 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(4, count($newEntry->getTags())); | ||
76 | } | 66 | } |
77 | 67 | ||
78 | public function testAddMultipleTagToEntry() | 68 | public function testAddMultipleTagToEntry() |
@@ -116,15 +106,14 @@ 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); | ||
128 | 117 | ||
129 | // We make a first request to set an history and test redirection after tag deletion | 118 | // We make a first request to set an history and test redirection after tag deletion |
130 | $client->request('GET', '/view/'.$entry->getId()); | 119 | $client->request('GET', '/view/'.$entry->getId()); |
@@ -134,12 +123,8 @@ class TagControllerTest extends WallabagCoreTestCase | |||
134 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 123 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
135 | $this->assertEquals($entryUri, $client->getResponse()->getTargetUrl()); | 124 | $this->assertEquals($entryUri, $client->getResponse()->getTargetUrl()); |
136 | 125 | ||
137 | // re-retrieve the entry to be sure to get fresh data from database (mostly for tags) | 126 | // re-retrieve the entry to be sure to get fresh data from database (mostly for tags) |
138 | $entry = $client->getContainer() | 127 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); |
139 | ->get('doctrine.orm.entity_manager') | ||
140 | ->getRepository('WallabagCoreBundle:Entry') | ||
141 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | ||
142 | |||
143 | $this->assertNotContains($this->tagName, $entry->getTags()); | 128 | $this->assertNotContains($this->tagName, $entry->getTags()); |
144 | 129 | ||
145 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | 130 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); |