diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2015-03-06 21:48:33 +0100 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2015-03-06 21:48:33 +0100 |
commit | f37d1427a1b75f9d7a2e273b2e9fb0e895a769ab (patch) | |
tree | e6ea5fb4786e843b970b14d5a96da8c32548a315 /src/Wallabag/CoreBundle/Tests | |
parent | 73b774438395d0ed74d0fd863194d2ebfb68d9ce (diff) | |
parent | 6e22bd737b2e543c85487864a9a25b0f2d5cc3f2 (diff) | |
download | wallabag-f37d1427a1b75f9d7a2e273b2e9fb0e895a769ab.tar.gz wallabag-f37d1427a1b75f9d7a2e273b2e9fb0e895a769ab.tar.zst wallabag-f37d1427a1b75f9d7a2e273b2e9fb0e895a769ab.zip |
Merge pull request #1110 from wallabag/v2-api-hypermedia
[WIP] API : hypermedia & tags
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests')
-rw-r--r-- | src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php | 9 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php | 81 |
2 files changed, 76 insertions, 14 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 2634141e..99a3a945 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php | |||
@@ -161,18 +161,15 @@ class EntryControllerTest extends WallabagTestCase | |||
161 | $content = $client->getContainer() | 161 | $content = $client->getContainer() |
162 | ->get('doctrine.orm.entity_manager') | 162 | ->get('doctrine.orm.entity_manager') |
163 | ->getRepository('WallabagCoreBundle:Entry') | 163 | ->getRepository('WallabagCoreBundle:Entry') |
164 | ->findOneByIsDeleted(false); | 164 | ->findOneById(1); |
165 | 165 | ||
166 | $client->request('GET', '/delete/'.$content->getId()); | 166 | $client->request('GET', '/delete/'.$content->getId()); |
167 | 167 | ||
168 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 168 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
169 | 169 | ||
170 | $res = $client->getContainer() | 170 | $client->request('GET', '/delete/'.$content->getId()); |
171 | ->get('doctrine.orm.entity_manager') | ||
172 | ->getRepository('WallabagCoreBundle:Entry') | ||
173 | ->findOneById($content->getId()); | ||
174 | 171 | ||
175 | $this->assertEquals($res->isDeleted(), true); | 172 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
176 | } | 173 | } |
177 | 174 | ||
178 | public function testViewOtherUserEntry() | 175 | public function testViewOtherUserEntry() |
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index fcfa8ccf..0eca7cde 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php | |||
@@ -44,10 +44,6 @@ class WallabagRestControllerTest extends WallabagTestCase | |||
44 | public function testWithBadHeaders() | 44 | public function testWithBadHeaders() |
45 | { | 45 | { |
46 | $client = $this->createClient(); | 46 | $client = $this->createClient(); |
47 | $client->request('GET', '/api/salts/admin.json'); | ||
48 | $salt = json_decode($client->getResponse()->getContent()); | ||
49 | |||
50 | $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); | ||
51 | 47 | ||
52 | $entry = $client->getContainer() | 48 | $entry = $client->getContainer() |
53 | ->get('doctrine.orm.entity_manager') | 49 | ->get('doctrine.orm.entity_manager') |
@@ -130,7 +126,7 @@ class WallabagRestControllerTest extends WallabagTestCase | |||
130 | $entry = $client->getContainer() | 126 | $entry = $client->getContainer() |
131 | ->get('doctrine.orm.entity_manager') | 127 | ->get('doctrine.orm.entity_manager') |
132 | ->getRepository('WallabagCoreBundle:Entry') | 128 | ->getRepository('WallabagCoreBundle:Entry') |
133 | ->findOneByIsDeleted(false); | 129 | ->findOneByUser(1); |
134 | 130 | ||
135 | if (!$entry) { | 131 | if (!$entry) { |
136 | $this->markTestSkipped('No content found in db.'); | 132 | $this->markTestSkipped('No content found in db.'); |
@@ -140,10 +136,79 @@ class WallabagRestControllerTest extends WallabagTestCase | |||
140 | 136 | ||
141 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 137 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
142 | 138 | ||
143 | $res = $client->getContainer() | 139 | // We'll try to delete this entry again |
140 | $client->request('GET', '/api/salts/admin.json'); | ||
141 | $salt = json_decode($client->getResponse()->getContent()); | ||
142 | |||
143 | $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); | ||
144 | |||
145 | $client->request('DELETE', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); | ||
146 | |||
147 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | ||
148 | } | ||
149 | |||
150 | public function testGetTagsEntry() | ||
151 | { | ||
152 | $client = $this->createClient(); | ||
153 | $client->request('GET', '/api/salts/admin.json'); | ||
154 | $salt = json_decode($client->getResponse()->getContent()); | ||
155 | $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); | ||
156 | |||
157 | $entry = $client->getContainer() | ||
158 | ->get('doctrine.orm.entity_manager') | ||
159 | ->getRepository('WallabagCoreBundle:Entry') | ||
160 | ->findOneWithTags(1); | ||
161 | |||
162 | $entry = $entry[0]; | ||
163 | |||
164 | if (!$entry) { | ||
165 | $this->markTestSkipped('No content found in db.'); | ||
166 | } | ||
167 | |||
168 | $tags = array(); | ||
169 | foreach ($entry->getTags() as $tag) { | ||
170 | $tags[] = array('id' => $tag->getId(), 'label' => $tag->getLabel()); | ||
171 | } | ||
172 | |||
173 | $client->request('GET', '/api/entries/'.$entry->getId().'/tags', array(), array(), $headers); | ||
174 | |||
175 | $this->assertEquals(json_encode($tags, JSON_HEX_QUOT), $client->getResponse()->getContent()); | ||
176 | } | ||
177 | |||
178 | public function testPostTagsOnEntry() | ||
179 | { | ||
180 | $client = $this->createClient(); | ||
181 | $client->request('GET', '/api/salts/admin.json'); | ||
182 | $salt = json_decode($client->getResponse()->getContent()); | ||
183 | $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); | ||
184 | |||
185 | $entry = $client->getContainer() | ||
186 | ->get('doctrine.orm.entity_manager') | ||
187 | ->getRepository('WallabagCoreBundle:Entry') | ||
188 | ->findOneByUser(1); | ||
189 | |||
190 | if (!$entry) { | ||
191 | $this->markTestSkipped('No content found in db.'); | ||
192 | } | ||
193 | |||
194 | $newTags = 'tag1,tag2,tag3'; | ||
195 | |||
196 | $client->request('POST', '/api/entries/'.$entry->getId().'/tags', array('tags' => $newTags), array(), $headers); | ||
197 | |||
198 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
199 | |||
200 | $entryDB = $client->getContainer() | ||
144 | ->get('doctrine.orm.entity_manager') | 201 | ->get('doctrine.orm.entity_manager') |
145 | ->getRepository('WallabagCoreBundle:Entry') | 202 | ->getRepository('WallabagCoreBundle:Entry') |
146 | ->findOneById($entry->getId()); | 203 | ->find($entry->getId()); |
147 | $this->assertEquals($res->isDeleted(), true); | 204 | |
205 | $tagsInDB = array(); | ||
206 | foreach ($entryDB->getTags()->toArray() as $tag) { | ||
207 | $tagsInDB[$tag->getId()] = $tag->getLabel(); | ||
208 | } | ||
209 | |||
210 | foreach (explode(',', $newTags) as $tag) { | ||
211 | $this->assertContains($tag, $tagsInDB); | ||
212 | } | ||
148 | } | 213 | } |
149 | } | 214 | } |