3 namespace Tests\Wallabag\ApiBundle\Controller
;
5 use Tests\Wallabag\ApiBundle\WallabagApiTestCase
;
6 use Wallabag\CoreBundle\Entity\Tag
;
8 class WallabagRestControllerTest
extends WallabagApiTestCase
10 protected static $salt;
12 public function testGetOneEntry()
14 $entry = $this->client
->getContainer()
15 ->get('doctrine.orm.entity_manager')
16 ->getRepository('WallabagCoreBundle:Entry')
17 ->findOneBy(['user' => 1, 'isArchived' => false]);
20 $this->markTestSkipped('No content found in db.');
23 $this->client
->request('GET', '/api/entries/'.$entry->getId().'.json');
24 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
26 $content = json_decode($this->client
->getResponse()->getContent(), true);
28 $this->assertEquals($entry->getTitle(), $content['title']);
29 $this->assertEquals($entry->getUrl(), $content['url']);
30 $this->assertCount(count($entry->getTags()), $content['tags']);
31 $this->assertEquals($entry->getUserName(), $content['user_name']);
32 $this->assertEquals($entry->getUserEmail(), $content['user_email']);
33 $this->assertEquals($entry->getUserId(), $content['user_id']);
35 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
38 public function testExportEntry()
40 $entry = $this->client
->getContainer()
41 ->get('doctrine.orm.entity_manager')
42 ->getRepository('WallabagCoreBundle:Entry')
43 ->findOneBy(['user' => 1, 'isArchived' => false]);
46 $this->markTestSkipped('No content found in db.');
49 $this->client
->request('GET', '/api/entries/'.$entry->getId().'/export.epub');
50 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
52 // epub format got the content type in the content
53 $this->assertContains('application/epub', $this->client
->getResponse()->getContent());
54 $this->assertEquals('application/epub+zip', $this->client
->getResponse()->headers
->get('Content-Type'));
56 // re-auth client for mobi
57 $client = $this->createAuthorizedClient();
58 $client->request('GET', '/api/entries/'.$entry->getId().'/export.mobi');
59 $this->assertEquals(200, $client->getResponse()->getStatusCode());
61 $this->assertEquals('application/x-mobipocket-ebook', $client->getResponse()->headers
->get('Content-Type'));
63 // re-auth client for pdf
64 $client = $this->createAuthorizedClient();
65 $client->request('GET', '/api/entries/'.$entry->getId().'/export.pdf');
66 $this->assertEquals(200, $client->getResponse()->getStatusCode());
68 $this->assertContains('PDF-', $client->getResponse()->getContent());
69 $this->assertEquals('application/pdf', $client->getResponse()->headers
->get('Content-Type'));
71 // re-auth client for pdf
72 $client = $this->createAuthorizedClient();
73 $client->request('GET', '/api/entries/'.$entry->getId().'/export.txt');
74 $this->assertEquals(200, $client->getResponse()->getStatusCode());
76 $this->assertContains('text/plain', $client->getResponse()->headers
->get('Content-Type'));
78 // re-auth client for pdf
79 $client = $this->createAuthorizedClient();
80 $client->request('GET', '/api/entries/'.$entry->getId().'/export.csv');
81 $this->assertEquals(200, $client->getResponse()->getStatusCode());
83 $this->assertContains('application/csv', $client->getResponse()->headers
->get('Content-Type'));
86 public function testGetOneEntryWrongUser()
88 $entry = $this->client
->getContainer()
89 ->get('doctrine.orm.entity_manager')
90 ->getRepository('WallabagCoreBundle:Entry')
91 ->findOneBy(['user' => 2, 'isArchived' => false]);
94 $this->markTestSkipped('No content found in db.');
97 $this->client
->request('GET', '/api/entries/'.$entry->getId().'.json');
99 $this->assertEquals(403, $this->client
->getResponse()->getStatusCode());
102 public function testGetEntries()
104 $this->client
->request('GET', '/api/entries');
106 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
108 $content = json_decode($this->client
->getResponse()->getContent(), true);
110 $this->assertGreaterThanOrEqual(1, count($content));
111 $this->assertNotEmpty($content['_embedded']['items']);
112 $this->assertGreaterThanOrEqual(1, $content['total']);
113 $this->assertEquals(1, $content['page']);
114 $this->assertGreaterThanOrEqual(1, $content['pages']);
116 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
119 public function testGetEntriesWithFullOptions()
121 $this->client
->request('GET', '/api/entries', [
129 'since' => 1443274283,
132 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
134 $content = json_decode($this->client
->getResponse()->getContent(), true);
136 $this->assertGreaterThanOrEqual(1, count($content));
137 $this->assertArrayHasKey('items', $content['_embedded']);
138 $this->assertGreaterThanOrEqual(0, $content['total']);
139 $this->assertEquals(1, $content['page']);
140 $this->assertEquals(2, $content['limit']);
141 $this->assertGreaterThanOrEqual(1, $content['pages']);
143 $this->assertArrayHasKey('_links', $content);
144 $this->assertArrayHasKey('self', $content['_links']);
145 $this->assertArrayHasKey('first', $content['_links']);
146 $this->assertArrayHasKey('last', $content['_links']);
148 foreach (['self', 'first', 'last'] as $link) {
149 $this->assertArrayHasKey('href', $content['_links'][$link]);
150 $this->assertContains('archive=1', $content['_links'][$link]['href']);
151 $this->assertContains('starred=1', $content['_links'][$link]['href']);
152 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
153 $this->assertContains('order=asc', $content['_links'][$link]['href']);
154 $this->assertContains('tags=foo', $content['_links'][$link]['href']);
155 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
158 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
161 public function testGetStarredEntries()
163 $this->client
->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);
165 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
167 $content = json_decode($this->client
->getResponse()->getContent(), true);
169 $this->assertGreaterThanOrEqual(1, count($content));
170 $this->assertNotEmpty($content['_embedded']['items']);
171 $this->assertGreaterThanOrEqual(1, $content['total']);
172 $this->assertEquals(1, $content['page']);
173 $this->assertGreaterThanOrEqual(1, $content['pages']);
175 $this->assertArrayHasKey('_links', $content);
176 $this->assertArrayHasKey('self', $content['_links']);
177 $this->assertArrayHasKey('first', $content['_links']);
178 $this->assertArrayHasKey('last', $content['_links']);
180 foreach (['self', 'first', 'last'] as $link) {
181 $this->assertArrayHasKey('href', $content['_links'][$link]);
182 $this->assertContains('starred=1', $content['_links'][$link]['href']);
183 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
186 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
189 public function testGetArchiveEntries()
191 $this->client
->request('GET', '/api/entries', ['archive' => 1]);
193 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
195 $content = json_decode($this->client
->getResponse()->getContent(), true);
197 $this->assertGreaterThanOrEqual(1, count($content));
198 $this->assertNotEmpty($content['_embedded']['items']);
199 $this->assertGreaterThanOrEqual(1, $content['total']);
200 $this->assertEquals(1, $content['page']);
201 $this->assertGreaterThanOrEqual(1, $content['pages']);
203 $this->assertArrayHasKey('_links', $content);
204 $this->assertArrayHasKey('self', $content['_links']);
205 $this->assertArrayHasKey('first', $content['_links']);
206 $this->assertArrayHasKey('last', $content['_links']);
208 foreach (['self', 'first', 'last'] as $link) {
209 $this->assertArrayHasKey('href', $content['_links'][$link]);
210 $this->assertContains('archive=1', $content['_links'][$link]['href']);
213 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
216 public function testGetTaggedEntries()
218 $this->client
->request('GET', '/api/entries', ['tags' => 'foo,bar']);
220 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
222 $content = json_decode($this->client
->getResponse()->getContent(), true);
224 $this->assertGreaterThanOrEqual(1, count($content));
225 $this->assertNotEmpty($content['_embedded']['items']);
226 $this->assertGreaterThanOrEqual(1, $content['total']);
227 $this->assertEquals(1, $content['page']);
228 $this->assertGreaterThanOrEqual(1, $content['pages']);
230 $this->assertArrayHasKey('_links', $content);
231 $this->assertArrayHasKey('self', $content['_links']);
232 $this->assertArrayHasKey('first', $content['_links']);
233 $this->assertArrayHasKey('last', $content['_links']);
235 foreach (['self', 'first', 'last'] as $link) {
236 $this->assertArrayHasKey('href', $content['_links'][$link]);
237 $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']);
240 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
243 public function testGetDatedEntries()
245 $this->client
->request('GET', '/api/entries', ['since' => 1443274283]);
247 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
249 $content = json_decode($this->client
->getResponse()->getContent(), true);
251 $this->assertGreaterThanOrEqual(1, count($content));
252 $this->assertNotEmpty($content['_embedded']['items']);
253 $this->assertGreaterThanOrEqual(1, $content['total']);
254 $this->assertEquals(1, $content['page']);
255 $this->assertGreaterThanOrEqual(1, $content['pages']);
257 $this->assertArrayHasKey('_links', $content);
258 $this->assertArrayHasKey('self', $content['_links']);
259 $this->assertArrayHasKey('first', $content['_links']);
260 $this->assertArrayHasKey('last', $content['_links']);
262 foreach (['self', 'first', 'last'] as $link) {
263 $this->assertArrayHasKey('href', $content['_links'][$link]);
264 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
267 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
270 public function testGetDatedSupEntries()
272 $future = new \
DateTime(date('Y-m-d H:i:s'));
273 $this->client
->request('GET', '/api/entries', ['since' => $future->getTimestamp() +
1000]);
275 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
277 $content = json_decode($this->client
->getResponse()->getContent(), true);
279 $this->assertGreaterThanOrEqual(1, count($content));
280 $this->assertEmpty($content['_embedded']['items']);
281 $this->assertEquals(0, $content['total']);
282 $this->assertEquals(1, $content['page']);
283 $this->assertEquals(1, $content['pages']);
285 $this->assertArrayHasKey('_links', $content);
286 $this->assertArrayHasKey('self', $content['_links']);
287 $this->assertArrayHasKey('first', $content['_links']);
288 $this->assertArrayHasKey('last', $content['_links']);
290 foreach (['self', 'first', 'last'] as $link) {
291 $this->assertArrayHasKey('href', $content['_links'][$link]);
292 $this->assertContains('since='.($future->getTimestamp() +
1000), $content['_links'][$link]['href']);
295 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
298 public function testDeleteEntry()
300 $entry = $this->client
->getContainer()
301 ->get('doctrine.orm.entity_manager')
302 ->getRepository('WallabagCoreBundle:Entry')
306 $this->markTestSkipped('No content found in db.');
309 $this->client
->request('DELETE', '/api/entries/'.$entry->getId().'.json');
311 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
313 $content = json_decode($this->client
->getResponse()->getContent(), true);
315 $this->assertEquals($entry->getTitle(), $content['title']);
316 $this->assertEquals($entry->getUrl(), $content['url']);
318 // We'll try to delete this entry again
319 $this->client
->request('DELETE', '/api/entries/'.$entry->getId().'.json');
321 $this->assertEquals(404, $this->client
->getResponse()->getStatusCode());
324 public function testPostEntry()
326 $this->client
->request('POST', '/api/entries.json', [
327 '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',
329 'title' => 'New title for my article',
332 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
334 $content = json_decode($this->client
->getResponse()->getContent(), true);
336 $this->assertGreaterThan(0, $content['id']);
337 $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']);
338 $this->assertEquals(false, $content['is_archived']);
339 $this->assertEquals(false, $content['is_starred']);
340 $this->assertEquals('New title for my article', $content['title']);
341 $this->assertEquals(1, $content['user_id']);
342 $this->assertCount(1, $content['tags']);
345 public function testPostSameEntry()
347 $this->client
->request('POST', '/api/entries.json', [
348 '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',
350 'tags' => 'google, apple',
353 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
355 $content = json_decode($this->client
->getResponse()->getContent(), true);
357 $this->assertGreaterThan(0, $content['id']);
358 $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']);
359 $this->assertEquals(true, $content['is_archived']);
360 $this->assertEquals(false, $content['is_starred']);
361 $this->assertCount(2, $content['tags']);
364 public function testPostArchivedAndStarredEntry()
366 $this->client
->request('POST', '/api/entries.json', [
367 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
372 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
374 $content = json_decode($this->client
->getResponse()->getContent(), true);
376 $this->assertGreaterThan(0, $content['id']);
377 $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']);
378 $this->assertEquals(true, $content['is_archived']);
379 $this->assertEquals(true, $content['is_starred']);
380 $this->assertEquals(1, $content['user_id']);
383 public function testPostArchivedAndStarredEntryWithoutQuotes()
385 $this->client
->request('POST', '/api/entries.json', [
386 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
391 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
393 $content = json_decode($this->client
->getResponse()->getContent(), true);
395 $this->assertGreaterThan(0, $content['id']);
396 $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']);
397 $this->assertEquals(false, $content['is_archived']);
398 $this->assertEquals(true, $content['is_starred']);
401 public function testPatchEntry()
403 $entry = $this->client
->getContainer()
404 ->get('doctrine.orm.entity_manager')
405 ->getRepository('WallabagCoreBundle:Entry')
409 $this->markTestSkipped('No content found in db.');
412 // hydrate the tags relations
413 $nbTags = count($entry->getTags());
415 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
416 'title' => 'New awesome title',
417 'tags' => 'new tag '.uniqid(),
422 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
424 $content = json_decode($this->client
->getResponse()->getContent(), true);
426 $this->assertEquals($entry->getId(), $content['id']);
427 $this->assertEquals($entry->getUrl(), $content['url']);
428 $this->assertEquals('New awesome title', $content['title']);
429 $this->assertGreaterThan($nbTags, count($content['tags']));
430 $this->assertEquals(1, $content['user_id']);
433 public function testPatchEntryWithoutQuotes()
435 $entry = $this->client
->getContainer()
436 ->get('doctrine.orm.entity_manager')
437 ->getRepository('WallabagCoreBundle:Entry')
441 $this->markTestSkipped('No content found in db.');
444 // hydrate the tags relations
445 $nbTags = count($entry->getTags());
447 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
448 'title' => 'New awesome title',
449 'tags' => 'new tag '.uniqid(),
454 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
456 $content = json_decode($this->client
->getResponse()->getContent(), true);
458 $this->assertEquals($entry->getId(), $content['id']);
459 $this->assertEquals($entry->getUrl(), $content['url']);
460 $this->assertEquals('New awesome title', $content['title']);
461 $this->assertGreaterThan($nbTags, count($content['tags']));
464 public function testGetTagsEntry()
466 $entry = $this->client
->getContainer()
467 ->get('doctrine.orm.entity_manager')
468 ->getRepository('WallabagCoreBundle:Entry')
469 ->findOneWithTags($this->user
->getId());
474 $this->markTestSkipped('No content found in db.');
478 foreach ($entry->getTags() as $tag) {
479 $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()];
482 $this->client
->request('GET', '/api/entries/'.$entry->getId().'/tags');
484 $this->assertEquals(json_encode($tags, JSON_HEX_QUOT
), $this->client
->getResponse()->getContent());
487 public function testPostTagsOnEntry()
489 $entry = $this->client
->getContainer()
490 ->get('doctrine.orm.entity_manager')
491 ->getRepository('WallabagCoreBundle:Entry')
495 $this->markTestSkipped('No content found in db.');
498 $nbTags = count($entry->getTags());
500 $newTags = 'tag1,tag2,tag3';
502 $this->client
->request('POST', '/api/entries/'.$entry->getId().'/tags', ['tags' => $newTags]);
504 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
506 $content = json_decode($this->client
->getResponse()->getContent(), true);
508 $this->assertArrayHasKey('tags', $content);
509 $this->assertEquals($nbTags +
3, count($content['tags']));
511 $entryDB = $this->client
->getContainer()
512 ->get('doctrine.orm.entity_manager')
513 ->getRepository('WallabagCoreBundle:Entry')
514 ->find($entry->getId());
517 foreach ($entryDB->getTags()->toArray() as $tag) {
518 $tagsInDB[$tag->getId()] = $tag->getLabel();
521 foreach (explode(',', $newTags) as $tag) {
522 $this->assertContains($tag, $tagsInDB);
526 public function testDeleteOneTagEntry()
528 $entry = $this->client
->getContainer()
529 ->get('doctrine.orm.entity_manager')
530 ->getRepository('WallabagCoreBundle:Entry')
531 ->findOneWithTags($this->user
->getId());
535 $this->markTestSkipped('No content found in db.');
538 // hydrate the tags relations
539 $nbTags = count($entry->getTags());
540 $tag = $entry->getTags()[0];
542 $this->client
->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json');
544 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
546 $content = json_decode($this->client
->getResponse()->getContent(), true);
548 $this->assertArrayHasKey('tags', $content);
549 $this->assertEquals($nbTags - 1, count($content['tags']));
552 public function testGetUserTags()
554 $this->client
->request('GET', '/api/tags.json');
556 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
558 $content = json_decode($this->client
->getResponse()->getContent(), true);
560 $this->assertGreaterThan(0, $content);
561 $this->assertArrayHasKey('id', $content[0]);
562 $this->assertArrayHasKey('label', $content[0]);
564 return end($content);
568 * @depends testGetUserTags
570 public function testDeleteUserTag($tag)
572 $tagName = $tag['label'];
574 $this->client
->request('DELETE', '/api/tags/'.$tag['id'].'.json');
576 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
578 $content = json_decode($this->client
->getResponse()->getContent(), true);
580 $this->assertArrayHasKey('label', $content);
581 $this->assertEquals($tag['label'], $content['label']);
582 $this->assertEquals($tag['slug'], $content['slug']);
584 $entries = $this->client
->getContainer()
585 ->get('doctrine.orm.entity_manager')
586 ->getRepository('WallabagCoreBundle:Entry')
587 ->findAllByTagId($this->user
->getId(), $tag['id']);
589 $this->assertCount(0, $entries);
591 $tag = $this->client
->getContainer()
592 ->get('doctrine.orm.entity_manager')
593 ->getRepository('WallabagCoreBundle:Tag')
594 ->findOneByLabel($tagName);
596 $this->assertNull($tag, $tagName.' was removed because it begun an orphan tag');
599 public function testDeleteTagByLabel()
601 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
602 $entry = $this->client
->getContainer()
603 ->get('doctrine.orm.entity_manager')
604 ->getRepository('WallabagCoreBundle:Entry')
605 ->findOneWithTags($this->user
->getId());
610 $tag->setLabel('Awesome tag for test');
613 $entry->addTag($tag);
615 $em->persist($entry);
618 $this->client
->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]);
620 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
622 $content = json_decode($this->client
->getResponse()->getContent(), true);
624 $this->assertArrayHasKey('label', $content);
625 $this->assertEquals($tag->getLabel(), $content['label']);
626 $this->assertEquals($tag->getSlug(), $content['slug']);
628 $entries = $this->client
->getContainer()
629 ->get('doctrine.orm.entity_manager')
630 ->getRepository('WallabagCoreBundle:Entry')
631 ->findAllByTagId($this->user
->getId(), $tag->getId());
633 $this->assertCount(0, $entries);
636 public function testDeleteTagByLabelNotFound()
638 $this->client
->request('DELETE', '/api/tag/label.json', ['tag' => 'does not exist']);
640 $this->assertEquals(404, $this->client
->getResponse()->getStatusCode());
643 public function testDeleteTagsByLabel()
645 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
646 $entry = $this->client
->getContainer()
647 ->get('doctrine.orm.entity_manager')
648 ->getRepository('WallabagCoreBundle:Entry')
649 ->findOneWithTags($this->user
->getId());
654 $tag->setLabel('Awesome tag for tagsLabel');
658 $tag2->setLabel('Awesome tag for tagsLabel 2');
661 $entry->addTag($tag);
662 $entry->addTag($tag2);
664 $em->persist($entry);
667 $this->client
->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]);
669 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
671 $content = json_decode($this->client
->getResponse()->getContent(), true);
673 $this->assertCount(2, $content);
675 $this->assertArrayHasKey('label', $content[0]);
676 $this->assertEquals($tag->getLabel(), $content[0]['label']);
677 $this->assertEquals($tag->getSlug(), $content[0]['slug']);
679 $this->assertArrayHasKey('label', $content[1]);
680 $this->assertEquals($tag2->getLabel(), $content[1]['label']);
681 $this->assertEquals($tag2->getSlug(), $content[1]['slug']);
683 $entries = $this->client
->getContainer()
684 ->get('doctrine.orm.entity_manager')
685 ->getRepository('WallabagCoreBundle:Entry')
686 ->findAllByTagId($this->user
->getId(), $tag->getId());
688 $this->assertCount(0, $entries);
690 $entries = $this->client
->getContainer()
691 ->get('doctrine.orm.entity_manager')
692 ->getRepository('WallabagCoreBundle:Entry')
693 ->findAllByTagId($this->user
->getId(), $tag2->getId());
695 $this->assertCount(0, $entries);
698 public function testDeleteTagsByLabelNotFound()
700 $this->client
->request('DELETE', '/api/tags/label.json', ['tags' => 'does not exist']);
702 $this->assertEquals(404, $this->client
->getResponse()->getStatusCode());
705 public function testGetVersion()
707 $this->client
->request('GET', '/api/version');
709 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
711 $content = json_decode($this->client
->getResponse()->getContent(), true);
713 $this->assertEquals($this->client
->getContainer()->getParameter('wallabag_core.version'), $content);
716 public function testSaveIsArchivedAfterPost()
718 $entry = $this->client
->getContainer()
719 ->get('doctrine.orm.entity_manager')
720 ->getRepository('WallabagCoreBundle:Entry')
721 ->findOneBy(['user' => 1, 'isArchived' => true]);
724 $this->markTestSkipped('No content found in db.');
727 $this->client
->request('POST', '/api/entries.json', [
728 'url' => $entry->getUrl(),
731 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
733 $content = json_decode($this->client
->getResponse()->getContent(), true);
735 $this->assertEquals(true, $content['is_archived']);
738 public function testSaveIsStarredAfterPost()
740 $entry = $this->client
->getContainer()
741 ->get('doctrine.orm.entity_manager')
742 ->getRepository('WallabagCoreBundle:Entry')
743 ->findOneBy(['user' => 1, 'isStarred' => true]);
746 $this->markTestSkipped('No content found in db.');
749 $this->client
->request('POST', '/api/entries.json', [
750 'url' => $entry->getUrl(),
753 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
755 $content = json_decode($this->client
->getResponse()->getContent(), true);
757 $this->assertEquals(true, $content['is_starred']);
760 public function testSaveIsArchivedAfterPatch()
762 $entry = $this->client
->getContainer()
763 ->get('doctrine.orm.entity_manager')
764 ->getRepository('WallabagCoreBundle:Entry')
765 ->findOneBy(['user' => 1, 'isArchived' => true]);
768 $this->markTestSkipped('No content found in db.');
771 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
772 'title' => $entry->getTitle().'++',
775 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
777 $content = json_decode($this->client
->getResponse()->getContent(), true);
779 $this->assertEquals(true, $content['is_archived']);
782 public function testSaveIsStarredAfterPatch()
784 $entry = $this->client
->getContainer()
785 ->get('doctrine.orm.entity_manager')
786 ->getRepository('WallabagCoreBundle:Entry')
787 ->findOneBy(['user' => 1, 'isStarred' => true]);
790 $this->markTestSkipped('No content found in db.');
792 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
793 'title' => $entry->getTitle().'++',
796 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
798 $content = json_decode($this->client
->getResponse()->getContent(), true);
800 $this->assertEquals(true, $content['is_starred']);
803 public function testGetEntriesExists()
805 $this->client
->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
807 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
809 $content = json_decode($this->client
->getResponse()->getContent(), true);
811 $this->assertEquals(true, $content['exists']);
814 public function testGetEntriesExistsWithManyUrls()
816 $url1 = 'http://0.0.0.0/entry2';
817 $url2 = 'http://0.0.0.0/entry10';
818 $this->client
->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2);
820 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
822 $content = json_decode($this->client
->getResponse()->getContent(), true);
824 $this->assertArrayHasKey($url1, $content);
825 $this->assertArrayHasKey($url2, $content);
826 $this->assertEquals(true, $content[$url1]);
827 $this->assertEquals(false, $content[$url2]);
830 public function testGetEntriesExistsWhichDoesNotExists()
832 $this->client
->request('GET', '/api/entries/exists?url=http://google.com/entry2');
834 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
836 $content = json_decode($this->client
->getResponse()->getContent(), true);
838 $this->assertEquals(false, $content['exists']);
841 public function testGetEntriesExistsWithNoUrl()
843 $this->client
->request('GET', '/api/entries/exists?url=');
845 $this->assertEquals(403, $this->client
->getResponse()->getStatusCode());