diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2017-10-23 11:09:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-23 11:09:17 +0200 |
commit | 1953a872932a63792293b4aec087880265ba89f7 (patch) | |
tree | fd16599e737fcdaf193c933ef3ec4a4ee248b117 /tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php | |
parent | d83d25dadec2c38460a32d96f5d2903426fec9d3 (diff) | |
parent | 702f2d67d60ca963492b90dad74cb5f8dcc84e51 (diff) | |
download | wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.gz wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.zst wallabag-1953a872932a63792293b4aec087880265ba89f7.zip |
Merge pull request #3011 from wallabag/2.3
wallabag 2.3.0
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php')
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php | 87 |
1 files changed, 54 insertions, 33 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php index bde5251f..430e548d 100644 --- a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php | |||
@@ -11,7 +11,7 @@ class TagRestControllerTest extends WallabagApiTestCase | |||
11 | { | 11 | { |
12 | $this->client->request('GET', '/api/tags.json'); | 12 | $this->client->request('GET', '/api/tags.json'); |
13 | 13 | ||
14 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 14 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
15 | 15 | ||
16 | $content = json_decode($this->client->getResponse()->getContent(), true); | 16 | $content = json_decode($this->client->getResponse()->getContent(), true); |
17 | 17 | ||
@@ -22,39 +22,49 @@ class TagRestControllerTest extends WallabagApiTestCase | |||
22 | return end($content); | 22 | return end($content); |
23 | } | 23 | } |
24 | 24 | ||
25 | /** | 25 | public function testDeleteUserTag() |
26 | * @depends testGetUserTags | ||
27 | */ | ||
28 | public function testDeleteUserTag($tag) | ||
29 | { | 26 | { |
30 | $tagName = $tag['label']; | 27 | $tagLabel = 'tagtest'; |
28 | $tag = new Tag(); | ||
29 | $tag->setLabel($tagLabel); | ||
30 | |||
31 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
32 | $em->persist($tag); | ||
33 | $em->flush(); | ||
34 | $em->clear(); | ||
31 | 35 | ||
32 | $this->client->request('DELETE', '/api/tags/'.$tag['id'].'.json'); | 36 | $this->client->request('DELETE', '/api/tags/' . $tag->getId() . '.json'); |
33 | 37 | ||
34 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 38 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
35 | 39 | ||
36 | $content = json_decode($this->client->getResponse()->getContent(), true); | 40 | $content = json_decode($this->client->getResponse()->getContent(), true); |
37 | 41 | ||
38 | $this->assertArrayHasKey('label', $content); | 42 | $this->assertArrayHasKey('label', $content); |
39 | $this->assertEquals($tag['label'], $content['label']); | 43 | $this->assertSame($tag->getLabel(), $content['label']); |
40 | $this->assertEquals($tag['slug'], $content['slug']); | 44 | $this->assertSame($tag->getSlug(), $content['slug']); |
41 | 45 | ||
42 | $entries = $this->client->getContainer() | 46 | $entries = $em->getRepository('WallabagCoreBundle:Entry') |
43 | ->get('doctrine.orm.entity_manager') | 47 | ->findAllByTagId($this->user->getId(), $tag->getId()); |
44 | ->getRepository('WallabagCoreBundle:Entry') | ||
45 | ->findAllByTagId($this->user->getId(), $tag['id']); | ||
46 | 48 | ||
47 | $this->assertCount(0, $entries); | 49 | $this->assertCount(0, $entries); |
48 | 50 | ||
49 | $tag = $this->client->getContainer() | 51 | $tag = $em->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($tagLabel); |
50 | ->get('doctrine.orm.entity_manager') | ||
51 | ->getRepository('WallabagCoreBundle:Tag') | ||
52 | ->findOneByLabel($tagName); | ||
53 | 52 | ||
54 | $this->assertNull($tag, $tagName.' was removed because it begun an orphan tag'); | 53 | $this->assertNull($tag, $tagLabel . ' was removed because it begun an orphan tag'); |
55 | } | 54 | } |
56 | 55 | ||
57 | public function testDeleteTagByLabel() | 56 | public function dataForDeletingTagByLabel() |
57 | { | ||
58 | return [ | ||
59 | 'by_query' => [true], | ||
60 | 'by_body' => [false], | ||
61 | ]; | ||
62 | } | ||
63 | |||
64 | /** | ||
65 | * @dataProvider dataForDeletingTagByLabel | ||
66 | */ | ||
67 | public function testDeleteTagByLabel($useQueryString) | ||
58 | { | 68 | { |
59 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 69 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
60 | $entry = $this->client->getContainer() | 70 | $entry = $this->client->getContainer() |
@@ -73,15 +83,19 @@ class TagRestControllerTest extends WallabagApiTestCase | |||
73 | $em->persist($entry); | 83 | $em->persist($entry); |
74 | $em->flush(); | 84 | $em->flush(); |
75 | 85 | ||
76 | $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]); | 86 | if ($useQueryString) { |
87 | $this->client->request('DELETE', '/api/tag/label.json?tag=' . $tag->getLabel()); | ||
88 | } else { | ||
89 | $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]); | ||
90 | } | ||
77 | 91 | ||
78 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 92 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
79 | 93 | ||
80 | $content = json_decode($this->client->getResponse()->getContent(), true); | 94 | $content = json_decode($this->client->getResponse()->getContent(), true); |
81 | 95 | ||
82 | $this->assertArrayHasKey('label', $content); | 96 | $this->assertArrayHasKey('label', $content); |
83 | $this->assertEquals($tag->getLabel(), $content['label']); | 97 | $this->assertSame($tag->getLabel(), $content['label']); |
84 | $this->assertEquals($tag->getSlug(), $content['slug']); | 98 | $this->assertSame($tag->getSlug(), $content['slug']); |
85 | 99 | ||
86 | $entries = $this->client->getContainer() | 100 | $entries = $this->client->getContainer() |
87 | ->get('doctrine.orm.entity_manager') | 101 | ->get('doctrine.orm.entity_manager') |
@@ -95,10 +109,13 @@ class TagRestControllerTest extends WallabagApiTestCase | |||
95 | { | 109 | { |
96 | $this->client->request('DELETE', '/api/tag/label.json', ['tag' => 'does not exist']); | 110 | $this->client->request('DELETE', '/api/tag/label.json', ['tag' => 'does not exist']); |
97 | 111 | ||
98 | $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); | 112 | $this->assertSame(404, $this->client->getResponse()->getStatusCode()); |
99 | } | 113 | } |
100 | 114 | ||
101 | public function testDeleteTagsByLabel() | 115 | /** |
116 | * @dataProvider dataForDeletingTagByLabel | ||
117 | */ | ||
118 | public function testDeleteTagsByLabel($useQueryString) | ||
102 | { | 119 | { |
103 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 120 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
104 | $entry = $this->client->getContainer() | 121 | $entry = $this->client->getContainer() |
@@ -122,21 +139,25 @@ class TagRestControllerTest extends WallabagApiTestCase | |||
122 | $em->persist($entry); | 139 | $em->persist($entry); |
123 | $em->flush(); | 140 | $em->flush(); |
124 | 141 | ||
125 | $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]); | 142 | if ($useQueryString) { |
143 | $this->client->request('DELETE', '/api/tags/label.json?tags=' . $tag->getLabel() . ',' . $tag2->getLabel()); | ||
144 | } else { | ||
145 | $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel() . ',' . $tag2->getLabel()]); | ||
146 | } | ||
126 | 147 | ||
127 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 148 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
128 | 149 | ||
129 | $content = json_decode($this->client->getResponse()->getContent(), true); | 150 | $content = json_decode($this->client->getResponse()->getContent(), true); |
130 | 151 | ||
131 | $this->assertCount(2, $content); | 152 | $this->assertCount(2, $content); |
132 | 153 | ||
133 | $this->assertArrayHasKey('label', $content[0]); | 154 | $this->assertArrayHasKey('label', $content[0]); |
134 | $this->assertEquals($tag->getLabel(), $content[0]['label']); | 155 | $this->assertSame($tag->getLabel(), $content[0]['label']); |
135 | $this->assertEquals($tag->getSlug(), $content[0]['slug']); | 156 | $this->assertSame($tag->getSlug(), $content[0]['slug']); |
136 | 157 | ||
137 | $this->assertArrayHasKey('label', $content[1]); | 158 | $this->assertArrayHasKey('label', $content[1]); |
138 | $this->assertEquals($tag2->getLabel(), $content[1]['label']); | 159 | $this->assertSame($tag2->getLabel(), $content[1]['label']); |
139 | $this->assertEquals($tag2->getSlug(), $content[1]['slug']); | 160 | $this->assertSame($tag2->getSlug(), $content[1]['slug']); |
140 | 161 | ||
141 | $entries = $this->client->getContainer() | 162 | $entries = $this->client->getContainer() |
142 | ->get('doctrine.orm.entity_manager') | 163 | ->get('doctrine.orm.entity_manager') |
@@ -157,6 +178,6 @@ class TagRestControllerTest extends WallabagApiTestCase | |||
157 | { | 178 | { |
158 | $this->client->request('DELETE', '/api/tags/label.json', ['tags' => 'does not exist']); | 179 | $this->client->request('DELETE', '/api/tags/label.json', ['tags' => 'does not exist']); |
159 | 180 | ||
160 | $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); | 181 | $this->assertSame(404, $this->client->getResponse()->getStatusCode()); |
161 | } | 182 | } |
162 | } | 183 | } |