diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-10-28 14:46:30 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-10-28 14:46:30 +0200 |
commit | 900c844861eac95fc41afbbbc121584b8f9e6c32 (patch) | |
tree | c207074320d3c42d571413e0233320c8da125b50 /tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | |
parent | eca4d030bf90cdf6ca0b6a86b18bd8f66a36db08 (diff) | |
download | wallabag-900c844861eac95fc41afbbbc121584b8f9e6c32.tar.gz wallabag-900c844861eac95fc41afbbbc121584b8f9e6c32.tar.zst wallabag-900c844861eac95fc41afbbbc121584b8f9e6c32.zip |
Exploded WallabagRestController into many controllers
Fix #2503
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php')
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 673 |
1 files changed, 673 insertions, 0 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php new file mode 100644 index 00000000..825f8f7a --- /dev/null +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | |||
@@ -0,0 +1,673 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ApiBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\ApiBundle\WallabagApiTestCase; | ||
6 | use Wallabag\CoreBundle\Entity\Tag; | ||
7 | |||
8 | class EntryRestControllerTest extends WallabagApiTestCase | ||
9 | { | ||
10 | public function testGetOneEntry() | ||
11 | { | ||
12 | $entry = $this->client->getContainer() | ||
13 | ->get('doctrine.orm.entity_manager') | ||
14 | ->getRepository('WallabagCoreBundle:Entry') | ||
15 | ->findOneBy(['user' => 1, 'isArchived' => false]); | ||
16 | |||
17 | if (!$entry) { | ||
18 | $this->markTestSkipped('No content found in db.'); | ||
19 | } | ||
20 | |||
21 | $this->client->request('GET', '/api/entries/'.$entry->getId().'.json'); | ||
22 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
23 | |||
24 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
25 | |||
26 | $this->assertEquals($entry->getTitle(), $content['title']); | ||
27 | $this->assertEquals($entry->getUrl(), $content['url']); | ||
28 | $this->assertCount(count($entry->getTags()), $content['tags']); | ||
29 | $this->assertEquals($entry->getUserName(), $content['user_name']); | ||
30 | $this->assertEquals($entry->getUserEmail(), $content['user_email']); | ||
31 | $this->assertEquals($entry->getUserId(), $content['user_id']); | ||
32 | |||
33 | $this->assertTrue( | ||
34 | $this->client->getResponse()->headers->contains( | ||
35 | 'Content-Type', | ||
36 | 'application/json' | ||
37 | ) | ||
38 | ); | ||
39 | } | ||
40 | |||
41 | public function testGetOneEntryWrongUser() | ||
42 | { | ||
43 | $entry = $this->client->getContainer() | ||
44 | ->get('doctrine.orm.entity_manager') | ||
45 | ->getRepository('WallabagCoreBundle:Entry') | ||
46 | ->findOneBy(['user' => 2, 'isArchived' => false]); | ||
47 | |||
48 | if (!$entry) { | ||
49 | $this->markTestSkipped('No content found in db.'); | ||
50 | } | ||
51 | |||
52 | $this->client->request('GET', '/api/entries/'.$entry->getId().'.json'); | ||
53 | |||
54 | $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); | ||
55 | } | ||
56 | |||
57 | public function testGetEntries() | ||
58 | { | ||
59 | $this->client->request('GET', '/api/entries'); | ||
60 | |||
61 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
62 | |||
63 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
64 | |||
65 | $this->assertGreaterThanOrEqual(1, count($content)); | ||
66 | $this->assertNotEmpty($content['_embedded']['items']); | ||
67 | $this->assertGreaterThanOrEqual(1, $content['total']); | ||
68 | $this->assertEquals(1, $content['page']); | ||
69 | $this->assertGreaterThanOrEqual(1, $content['pages']); | ||
70 | |||
71 | $this->assertTrue( | ||
72 | $this->client->getResponse()->headers->contains( | ||
73 | 'Content-Type', | ||
74 | 'application/json' | ||
75 | ) | ||
76 | ); | ||
77 | } | ||
78 | |||
79 | public function testGetEntriesWithFullOptions() | ||
80 | { | ||
81 | $this->client->request('GET', '/api/entries', [ | ||
82 | 'archive' => 1, | ||
83 | 'starred' => 1, | ||
84 | 'sort' => 'updated', | ||
85 | 'order' => 'asc', | ||
86 | 'page' => 1, | ||
87 | 'perPage' => 2, | ||
88 | 'tags' => 'foo', | ||
89 | 'since' => 1443274283, | ||
90 | ]); | ||
91 | |||
92 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
93 | |||
94 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
95 | |||
96 | $this->assertGreaterThanOrEqual(1, count($content)); | ||
97 | $this->assertArrayHasKey('items', $content['_embedded']); | ||
98 | $this->assertGreaterThanOrEqual(0, $content['total']); | ||
99 | $this->assertEquals(1, $content['page']); | ||
100 | $this->assertEquals(2, $content['limit']); | ||
101 | $this->assertGreaterThanOrEqual(1, $content['pages']); | ||
102 | |||
103 | $this->assertArrayHasKey('_links', $content); | ||
104 | $this->assertArrayHasKey('self', $content['_links']); | ||
105 | $this->assertArrayHasKey('first', $content['_links']); | ||
106 | $this->assertArrayHasKey('last', $content['_links']); | ||
107 | |||
108 | foreach (['self', 'first', 'last'] as $link) { | ||
109 | $this->assertArrayHasKey('href', $content['_links'][$link]); | ||
110 | $this->assertContains('archive=1', $content['_links'][$link]['href']); | ||
111 | $this->assertContains('starred=1', $content['_links'][$link]['href']); | ||
112 | $this->assertContains('sort=updated', $content['_links'][$link]['href']); | ||
113 | $this->assertContains('order=asc', $content['_links'][$link]['href']); | ||
114 | $this->assertContains('tags=foo', $content['_links'][$link]['href']); | ||
115 | $this->assertContains('since=1443274283', $content['_links'][$link]['href']); | ||
116 | } | ||
117 | |||
118 | $this->assertTrue( | ||
119 | $this->client->getResponse()->headers->contains( | ||
120 | 'Content-Type', | ||
121 | 'application/json' | ||
122 | ) | ||
123 | ); | ||
124 | } | ||
125 | |||
126 | public function testGetStarredEntries() | ||
127 | { | ||
128 | $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']); | ||
129 | |||
130 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
131 | |||
132 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
133 | |||
134 | $this->assertGreaterThanOrEqual(1, count($content)); | ||
135 | $this->assertNotEmpty($content['_embedded']['items']); | ||
136 | $this->assertGreaterThanOrEqual(1, $content['total']); | ||
137 | $this->assertEquals(1, $content['page']); | ||
138 | $this->assertGreaterThanOrEqual(1, $content['pages']); | ||
139 | |||
140 | $this->assertArrayHasKey('_links', $content); | ||
141 | $this->assertArrayHasKey('self', $content['_links']); | ||
142 | $this->assertArrayHasKey('first', $content['_links']); | ||
143 | $this->assertArrayHasKey('last', $content['_links']); | ||
144 | |||
145 | foreach (['self', 'first', 'last'] as $link) { | ||
146 | $this->assertArrayHasKey('href', $content['_links'][$link]); | ||
147 | $this->assertContains('starred=1', $content['_links'][$link]['href']); | ||
148 | $this->assertContains('sort=updated', $content['_links'][$link]['href']); | ||
149 | } | ||
150 | |||
151 | $this->assertTrue( | ||
152 | $this->client->getResponse()->headers->contains( | ||
153 | 'Content-Type', | ||
154 | 'application/json' | ||
155 | ) | ||
156 | ); | ||
157 | } | ||
158 | |||
159 | public function testGetArchiveEntries() | ||
160 | { | ||
161 | $this->client->request('GET', '/api/entries', ['archive' => 1]); | ||
162 | |||
163 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
164 | |||
165 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
166 | |||
167 | $this->assertGreaterThanOrEqual(1, count($content)); | ||
168 | $this->assertNotEmpty($content['_embedded']['items']); | ||
169 | $this->assertGreaterThanOrEqual(1, $content['total']); | ||
170 | $this->assertEquals(1, $content['page']); | ||
171 | $this->assertGreaterThanOrEqual(1, $content['pages']); | ||
172 | |||
173 | $this->assertArrayHasKey('_links', $content); | ||
174 | $this->assertArrayHasKey('self', $content['_links']); | ||
175 | $this->assertArrayHasKey('first', $content['_links']); | ||
176 | $this->assertArrayHasKey('last', $content['_links']); | ||
177 | |||
178 | foreach (['self', 'first', 'last'] as $link) { | ||
179 | $this->assertArrayHasKey('href', $content['_links'][$link]); | ||
180 | $this->assertContains('archive=1', $content['_links'][$link]['href']); | ||
181 | } | ||
182 | |||
183 | $this->assertTrue( | ||
184 | $this->client->getResponse()->headers->contains( | ||
185 | 'Content-Type', | ||
186 | 'application/json' | ||
187 | ) | ||
188 | ); | ||
189 | } | ||
190 | |||
191 | public function testGetTaggedEntries() | ||
192 | { | ||
193 | $this->client->request('GET', '/api/entries', ['tags' => 'foo,bar']); | ||
194 | |||
195 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
196 | |||
197 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
198 | |||
199 | $this->assertGreaterThanOrEqual(1, count($content)); | ||
200 | $this->assertNotEmpty($content['_embedded']['items']); | ||
201 | $this->assertGreaterThanOrEqual(1, $content['total']); | ||
202 | $this->assertEquals(1, $content['page']); | ||
203 | $this->assertGreaterThanOrEqual(1, $content['pages']); | ||
204 | |||
205 | $this->assertArrayHasKey('_links', $content); | ||
206 | $this->assertArrayHasKey('self', $content['_links']); | ||
207 | $this->assertArrayHasKey('first', $content['_links']); | ||
208 | $this->assertArrayHasKey('last', $content['_links']); | ||
209 | |||
210 | foreach (['self', 'first', 'last'] as $link) { | ||
211 | $this->assertArrayHasKey('href', $content['_links'][$link]); | ||
212 | $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']); | ||
213 | } | ||
214 | |||
215 | $this->assertTrue( | ||
216 | $this->client->getResponse()->headers->contains( | ||
217 | 'Content-Type', | ||
218 | 'application/json' | ||
219 | ) | ||
220 | ); | ||
221 | } | ||
222 | |||
223 | public function testGetDatedEntries() | ||
224 | { | ||
225 | $this->client->request('GET', '/api/entries', ['since' => 1443274283]); | ||
226 | |||
227 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
228 | |||
229 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
230 | |||
231 | $this->assertGreaterThanOrEqual(1, count($content)); | ||
232 | $this->assertNotEmpty($content['_embedded']['items']); | ||
233 | $this->assertGreaterThanOrEqual(1, $content['total']); | ||
234 | $this->assertEquals(1, $content['page']); | ||
235 | $this->assertGreaterThanOrEqual(1, $content['pages']); | ||
236 | |||
237 | $this->assertArrayHasKey('_links', $content); | ||
238 | $this->assertArrayHasKey('self', $content['_links']); | ||
239 | $this->assertArrayHasKey('first', $content['_links']); | ||
240 | $this->assertArrayHasKey('last', $content['_links']); | ||
241 | |||
242 | foreach (['self', 'first', 'last'] as $link) { | ||
243 | $this->assertArrayHasKey('href', $content['_links'][$link]); | ||
244 | $this->assertContains('since=1443274283', $content['_links'][$link]['href']); | ||
245 | } | ||
246 | |||
247 | $this->assertTrue( | ||
248 | $this->client->getResponse()->headers->contains( | ||
249 | 'Content-Type', | ||
250 | 'application/json' | ||
251 | ) | ||
252 | ); | ||
253 | } | ||
254 | |||
255 | public function testGetDatedSupEntries() | ||
256 | { | ||
257 | $future = new \DateTime(date('Y-m-d H:i:s')); | ||
258 | $this->client->request('GET', '/api/entries', ['since' => $future->getTimestamp() + 1000]); | ||
259 | |||
260 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
261 | |||
262 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
263 | |||
264 | $this->assertGreaterThanOrEqual(1, count($content)); | ||
265 | $this->assertEmpty($content['_embedded']['items']); | ||
266 | $this->assertEquals(0, $content['total']); | ||
267 | $this->assertEquals(1, $content['page']); | ||
268 | $this->assertEquals(1, $content['pages']); | ||
269 | |||
270 | $this->assertArrayHasKey('_links', $content); | ||
271 | $this->assertArrayHasKey('self', $content['_links']); | ||
272 | $this->assertArrayHasKey('first', $content['_links']); | ||
273 | $this->assertArrayHasKey('last', $content['_links']); | ||
274 | |||
275 | foreach (['self', 'first', 'last'] as $link) { | ||
276 | $this->assertArrayHasKey('href', $content['_links'][$link]); | ||
277 | $this->assertContains('since='.($future->getTimestamp() + 1000), $content['_links'][$link]['href']); | ||
278 | } | ||
279 | |||
280 | $this->assertTrue( | ||
281 | $this->client->getResponse()->headers->contains( | ||
282 | 'Content-Type', | ||
283 | 'application/json' | ||
284 | ) | ||
285 | ); | ||
286 | } | ||
287 | |||
288 | public function testDeleteEntry() | ||
289 | { | ||
290 | $entry = $this->client->getContainer() | ||
291 | ->get('doctrine.orm.entity_manager') | ||
292 | ->getRepository('WallabagCoreBundle:Entry') | ||
293 | ->findOneByUser(1); | ||
294 | |||
295 | if (!$entry) { | ||
296 | $this->markTestSkipped('No content found in db.'); | ||
297 | } | ||
298 | |||
299 | $this->client->request('DELETE', '/api/entries/'.$entry->getId().'.json'); | ||
300 | |||
301 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
302 | |||
303 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
304 | |||
305 | $this->assertEquals($entry->getTitle(), $content['title']); | ||
306 | $this->assertEquals($entry->getUrl(), $content['url']); | ||
307 | |||
308 | // We'll try to delete this entry again | ||
309 | $this->client->request('DELETE', '/api/entries/'.$entry->getId().'.json'); | ||
310 | |||
311 | $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); | ||
312 | } | ||
313 | |||
314 | public function testPostEntry() | ||
315 | { | ||
316 | $this->client->request('POST', '/api/entries.json', [ | ||
317 | 'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', | ||
318 | 'tags' => 'google', | ||
319 | 'title' => 'New title for my article', | ||
320 | ]); | ||
321 | |||
322 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
323 | |||
324 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
325 | |||
326 | $this->assertGreaterThan(0, $content['id']); | ||
327 | $this->assertEquals('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); | ||
328 | $this->assertEquals(false, $content['is_archived']); | ||
329 | $this->assertEquals(false, $content['is_starred']); | ||
330 | $this->assertEquals('New title for my article', $content['title']); | ||
331 | $this->assertEquals(1, $content['user_id']); | ||
332 | $this->assertCount(1, $content['tags']); | ||
333 | } | ||
334 | |||
335 | public function testPostSameEntry() | ||
336 | { | ||
337 | $this->client->request('POST', '/api/entries.json', [ | ||
338 | 'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', | ||
339 | 'archive' => '1', | ||
340 | 'tags' => 'google, apple', | ||
341 | ]); | ||
342 | |||
343 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
344 | |||
345 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
346 | |||
347 | $this->assertGreaterThan(0, $content['id']); | ||
348 | $this->assertEquals('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); | ||
349 | $this->assertEquals(true, $content['is_archived']); | ||
350 | $this->assertEquals(false, $content['is_starred']); | ||
351 | $this->assertCount(2, $content['tags']); | ||
352 | } | ||
353 | |||
354 | public function testPostArchivedAndStarredEntry() | ||
355 | { | ||
356 | $this->client->request('POST', '/api/entries.json', [ | ||
357 | 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', | ||
358 | 'archive' => '1', | ||
359 | 'starred' => '1', | ||
360 | ]); | ||
361 | |||
362 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
363 | |||
364 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
365 | |||
366 | $this->assertGreaterThan(0, $content['id']); | ||
367 | $this->assertEquals('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); | ||
368 | $this->assertEquals(true, $content['is_archived']); | ||
369 | $this->assertEquals(true, $content['is_starred']); | ||
370 | $this->assertEquals(1, $content['user_id']); | ||
371 | } | ||
372 | |||
373 | public function testPostArchivedAndStarredEntryWithoutQuotes() | ||
374 | { | ||
375 | $this->client->request('POST', '/api/entries.json', [ | ||
376 | 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', | ||
377 | 'archive' => 0, | ||
378 | 'starred' => 1, | ||
379 | ]); | ||
380 | |||
381 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
382 | |||
383 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
384 | |||
385 | $this->assertGreaterThan(0, $content['id']); | ||
386 | $this->assertEquals('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); | ||
387 | $this->assertEquals(false, $content['is_archived']); | ||
388 | $this->assertEquals(true, $content['is_starred']); | ||
389 | } | ||
390 | |||
391 | public function testPatchEntry() | ||
392 | { | ||
393 | $entry = $this->client->getContainer() | ||
394 | ->get('doctrine.orm.entity_manager') | ||
395 | ->getRepository('WallabagCoreBundle:Entry') | ||
396 | ->findOneByUser(1); | ||
397 | |||
398 | if (!$entry) { | ||
399 | $this->markTestSkipped('No content found in db.'); | ||
400 | } | ||
401 | |||
402 | // hydrate the tags relations | ||
403 | $nbTags = count($entry->getTags()); | ||
404 | |||
405 | $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ | ||
406 | 'title' => 'New awesome title', | ||
407 | 'tags' => 'new tag '.uniqid(), | ||
408 | 'starred' => '1', | ||
409 | 'archive' => '0', | ||
410 | ]); | ||
411 | |||
412 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
413 | |||
414 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
415 | |||
416 | $this->assertEquals($entry->getId(), $content['id']); | ||
417 | $this->assertEquals($entry->getUrl(), $content['url']); | ||
418 | $this->assertEquals('New awesome title', $content['title']); | ||
419 | $this->assertGreaterThan($nbTags, count($content['tags'])); | ||
420 | $this->assertEquals(1, $content['user_id']); | ||
421 | } | ||
422 | |||
423 | public function testPatchEntryWithoutQuotes() | ||
424 | { | ||
425 | $entry = $this->client->getContainer() | ||
426 | ->get('doctrine.orm.entity_manager') | ||
427 | ->getRepository('WallabagCoreBundle:Entry') | ||
428 | ->findOneByUser(1); | ||
429 | |||
430 | if (!$entry) { | ||
431 | $this->markTestSkipped('No content found in db.'); | ||
432 | } | ||
433 | |||
434 | // hydrate the tags relations | ||
435 | $nbTags = count($entry->getTags()); | ||
436 | |||
437 | $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ | ||
438 | 'title' => 'New awesome title', | ||
439 | 'tags' => 'new tag '.uniqid(), | ||
440 | 'starred' => 1, | ||
441 | 'archive' => 0, | ||
442 | ]); | ||
443 | |||
444 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
445 | |||
446 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
447 | |||
448 | $this->assertEquals($entry->getId(), $content['id']); | ||
449 | $this->assertEquals($entry->getUrl(), $content['url']); | ||
450 | $this->assertEquals('New awesome title', $content['title']); | ||
451 | $this->assertGreaterThan($nbTags, count($content['tags'])); | ||
452 | } | ||
453 | |||
454 | public function testGetTagsEntry() | ||
455 | { | ||
456 | $entry = $this->client->getContainer() | ||
457 | ->get('doctrine.orm.entity_manager') | ||
458 | ->getRepository('WallabagCoreBundle:Entry') | ||
459 | ->findOneWithTags($this->user->getId()); | ||
460 | |||
461 | $entry = $entry[0]; | ||
462 | |||
463 | if (!$entry) { | ||
464 | $this->markTestSkipped('No content found in db.'); | ||
465 | } | ||
466 | |||
467 | $tags = []; | ||
468 | foreach ($entry->getTags() as $tag) { | ||
469 | $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()]; | ||
470 | } | ||
471 | |||
472 | $this->client->request('GET', '/api/entries/'.$entry->getId().'/tags'); | ||
473 | |||
474 | $this->assertEquals(json_encode($tags, JSON_HEX_QUOT), $this->client->getResponse()->getContent()); | ||
475 | } | ||
476 | |||
477 | public function testPostTagsOnEntry() | ||
478 | { | ||
479 | $entry = $this->client->getContainer() | ||
480 | ->get('doctrine.orm.entity_manager') | ||
481 | ->getRepository('WallabagCoreBundle:Entry') | ||
482 | ->findOneByUser(1); | ||
483 | |||
484 | if (!$entry) { | ||
485 | $this->markTestSkipped('No content found in db.'); | ||
486 | } | ||
487 | |||
488 | $nbTags = count($entry->getTags()); | ||
489 | |||
490 | $newTags = 'tag1,tag2,tag3'; | ||
491 | |||
492 | $this->client->request('POST', '/api/entries/'.$entry->getId().'/tags', ['tags' => $newTags]); | ||
493 | |||
494 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
495 | |||
496 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
497 | |||
498 | $this->assertArrayHasKey('tags', $content); | ||
499 | $this->assertEquals($nbTags + 3, count($content['tags'])); | ||
500 | |||
501 | $entryDB = $this->client->getContainer() | ||
502 | ->get('doctrine.orm.entity_manager') | ||
503 | ->getRepository('WallabagCoreBundle:Entry') | ||
504 | ->find($entry->getId()); | ||
505 | |||
506 | $tagsInDB = []; | ||
507 | foreach ($entryDB->getTags()->toArray() as $tag) { | ||
508 | $tagsInDB[$tag->getId()] = $tag->getLabel(); | ||
509 | } | ||
510 | |||
511 | foreach (explode(',', $newTags) as $tag) { | ||
512 | $this->assertContains($tag, $tagsInDB); | ||
513 | } | ||
514 | } | ||
515 | |||
516 | public function testDeleteOneTagEntry() | ||
517 | { | ||
518 | $entry = $this->client->getContainer() | ||
519 | ->get('doctrine.orm.entity_manager') | ||
520 | ->getRepository('WallabagCoreBundle:Entry') | ||
521 | ->findOneWithTags($this->user->getId()); | ||
522 | $entry = $entry[0]; | ||
523 | |||
524 | if (!$entry) { | ||
525 | $this->markTestSkipped('No content found in db.'); | ||
526 | } | ||
527 | |||
528 | // hydrate the tags relations | ||
529 | $nbTags = count($entry->getTags()); | ||
530 | $tag = $entry->getTags()[0]; | ||
531 | |||
532 | $this->client->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json'); | ||
533 | |||
534 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
535 | |||
536 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
537 | |||
538 | $this->assertArrayHasKey('tags', $content); | ||
539 | $this->assertEquals($nbTags - 1, count($content['tags'])); | ||
540 | } | ||
541 | |||
542 | public function testSaveIsArchivedAfterPost() | ||
543 | { | ||
544 | $entry = $this->client->getContainer() | ||
545 | ->get('doctrine.orm.entity_manager') | ||
546 | ->getRepository('WallabagCoreBundle:Entry') | ||
547 | ->findOneBy(['user' => 1, 'isArchived' => true]); | ||
548 | |||
549 | if (!$entry) { | ||
550 | $this->markTestSkipped('No content found in db.'); | ||
551 | } | ||
552 | |||
553 | $this->client->request('POST', '/api/entries.json', [ | ||
554 | 'url' => $entry->getUrl(), | ||
555 | ]); | ||
556 | |||
557 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
558 | |||
559 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
560 | |||
561 | $this->assertEquals(true, $content['is_archived']); | ||
562 | } | ||
563 | |||
564 | public function testSaveIsStarredAfterPost() | ||
565 | { | ||
566 | $entry = $this->client->getContainer() | ||
567 | ->get('doctrine.orm.entity_manager') | ||
568 | ->getRepository('WallabagCoreBundle:Entry') | ||
569 | ->findOneBy(['user' => 1, 'isStarred' => true]); | ||
570 | |||
571 | if (!$entry) { | ||
572 | $this->markTestSkipped('No content found in db.'); | ||
573 | } | ||
574 | |||
575 | $this->client->request('POST', '/api/entries.json', [ | ||
576 | 'url' => $entry->getUrl(), | ||
577 | ]); | ||
578 | |||
579 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
580 | |||
581 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
582 | |||
583 | $this->assertEquals(true, $content['is_starred']); | ||
584 | } | ||
585 | |||
586 | public function testSaveIsArchivedAfterPatch() | ||
587 | { | ||
588 | $entry = $this->client->getContainer() | ||
589 | ->get('doctrine.orm.entity_manager') | ||
590 | ->getRepository('WallabagCoreBundle:Entry') | ||
591 | ->findOneBy(['user' => 1, 'isArchived' => true]); | ||
592 | |||
593 | if (!$entry) { | ||
594 | $this->markTestSkipped('No content found in db.'); | ||
595 | } | ||
596 | |||
597 | $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ | ||
598 | 'title' => $entry->getTitle().'++', | ||
599 | ]); | ||
600 | |||
601 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
602 | |||
603 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
604 | |||
605 | $this->assertEquals(true, $content['is_archived']); | ||
606 | } | ||
607 | |||
608 | public function testSaveIsStarredAfterPatch() | ||
609 | { | ||
610 | $entry = $this->client->getContainer() | ||
611 | ->get('doctrine.orm.entity_manager') | ||
612 | ->getRepository('WallabagCoreBundle:Entry') | ||
613 | ->findOneBy(['user' => 1, 'isStarred' => true]); | ||
614 | |||
615 | if (!$entry) { | ||
616 | $this->markTestSkipped('No content found in db.'); | ||
617 | } | ||
618 | $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ | ||
619 | 'title' => $entry->getTitle().'++', | ||
620 | ]); | ||
621 | |||
622 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
623 | |||
624 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
625 | |||
626 | $this->assertEquals(true, $content['is_starred']); | ||
627 | } | ||
628 | |||
629 | public function testGetEntriesExists() | ||
630 | { | ||
631 | $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2'); | ||
632 | |||
633 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
634 | |||
635 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
636 | |||
637 | $this->assertEquals(true, $content['exists']); | ||
638 | } | ||
639 | |||
640 | public function testGetEntriesExistsWithManyUrls() | ||
641 | { | ||
642 | $url1 = 'http://0.0.0.0/entry2'; | ||
643 | $url2 = 'http://0.0.0.0/entry10'; | ||
644 | $this->client->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2); | ||
645 | |||
646 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
647 | |||
648 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
649 | |||
650 | $this->assertArrayHasKey($url1, $content); | ||
651 | $this->assertArrayHasKey($url2, $content); | ||
652 | $this->assertEquals(true, $content[$url1]); | ||
653 | $this->assertEquals(false, $content[$url2]); | ||
654 | } | ||
655 | |||
656 | public function testGetEntriesExistsWhichDoesNotExists() | ||
657 | { | ||
658 | $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); | ||
659 | |||
660 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
661 | |||
662 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
663 | |||
664 | $this->assertEquals(false, $content['exists']); | ||
665 | } | ||
666 | |||
667 | public function testGetEntriesExistsWithNoUrl() | ||
668 | { | ||
669 | $this->client->request('GET', '/api/entries/exists?url='); | ||
670 | |||
671 | $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); | ||
672 | } | ||
673 | } | ||