3 namespace Tests\Wallabag\ApiBundle\Controller
;
5 use Tests\Wallabag\ApiBundle\WallabagApiTestCase
;
6 use Wallabag\CoreBundle\Entity\Tag
;
8 class EntryRestControllerTest
extends WallabagApiTestCase
10 public function testGetOneEntry()
12 $entry = $this->client
->getContainer()
13 ->get('doctrine.orm.entity_manager')
14 ->getRepository('WallabagCoreBundle:Entry')
15 ->findOneBy(['user' => 1, 'isArchived' => false]);
18 $this->markTestSkipped('No content found in db.');
21 $this->client
->request('GET', '/api/entries/'.$entry->getId().'.json');
22 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
24 $content = json_decode($this->client
->getResponse()->getContent(), true);
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']);
33 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
36 public function testExportEntry()
38 $entry = $this->client
->getContainer()
39 ->get('doctrine.orm.entity_manager')
40 ->getRepository('WallabagCoreBundle:Entry')
41 ->findOneBy(['user' => 1, 'isArchived' => false]);
44 $this->markTestSkipped('No content found in db.');
47 $this->client
->request('GET', '/api/entries/'.$entry->getId().'/export.epub');
48 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
50 // epub format got the content type in the content
51 $this->assertContains('application/epub', $this->client
->getResponse()->getContent());
52 $this->assertEquals('application/epub+zip', $this->client
->getResponse()->headers
->get('Content-Type'));
54 // re-auth client for mobi
55 $client = $this->createAuthorizedClient();
56 $client->request('GET', '/api/entries/'.$entry->getId().'/export.mobi');
57 $this->assertEquals(200, $client->getResponse()->getStatusCode());
59 $this->assertEquals('application/x-mobipocket-ebook', $client->getResponse()->headers
->get('Content-Type'));
61 // re-auth client for pdf
62 $client = $this->createAuthorizedClient();
63 $client->request('GET', '/api/entries/'.$entry->getId().'/export.pdf');
64 $this->assertEquals(200, $client->getResponse()->getStatusCode());
66 $this->assertContains('PDF-', $client->getResponse()->getContent());
67 $this->assertEquals('application/pdf', $client->getResponse()->headers
->get('Content-Type'));
69 // re-auth client for pdf
70 $client = $this->createAuthorizedClient();
71 $client->request('GET', '/api/entries/'.$entry->getId().'/export.txt');
72 $this->assertEquals(200, $client->getResponse()->getStatusCode());
74 $this->assertContains('text/plain', $client->getResponse()->headers
->get('Content-Type'));
76 // re-auth client for pdf
77 $client = $this->createAuthorizedClient();
78 $client->request('GET', '/api/entries/'.$entry->getId().'/export.csv');
79 $this->assertEquals(200, $client->getResponse()->getStatusCode());
81 $this->assertContains('application/csv', $client->getResponse()->headers
->get('Content-Type'));
84 public function testGetOneEntryWrongUser()
86 $entry = $this->client
->getContainer()
87 ->get('doctrine.orm.entity_manager')
88 ->getRepository('WallabagCoreBundle:Entry')
89 ->findOneBy(['user' => 2, 'isArchived' => false]);
92 $this->markTestSkipped('No content found in db.');
95 $this->client
->request('GET', '/api/entries/'.$entry->getId().'.json');
97 $this->assertEquals(403, $this->client
->getResponse()->getStatusCode());
100 public function testGetEntries()
102 $this->client
->request('GET', '/api/entries');
104 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
106 $content = json_decode($this->client
->getResponse()->getContent(), true);
108 $this->assertGreaterThanOrEqual(1, count($content));
109 $this->assertNotEmpty($content['_embedded']['items']);
110 $this->assertGreaterThanOrEqual(1, $content['total']);
111 $this->assertEquals(1, $content['page']);
112 $this->assertGreaterThanOrEqual(1, $content['pages']);
114 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
117 public function testGetEntriesWithFullOptions()
119 $this->client
->request('GET', '/api/entries', [
127 'since' => 1443274283,
130 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
132 $content = json_decode($this->client
->getResponse()->getContent(), true);
134 $this->assertGreaterThanOrEqual(1, count($content));
135 $this->assertArrayHasKey('items', $content['_embedded']);
136 $this->assertGreaterThanOrEqual(0, $content['total']);
137 $this->assertEquals(1, $content['page']);
138 $this->assertEquals(2, $content['limit']);
139 $this->assertGreaterThanOrEqual(1, $content['pages']);
141 $this->assertArrayHasKey('_links', $content);
142 $this->assertArrayHasKey('self', $content['_links']);
143 $this->assertArrayHasKey('first', $content['_links']);
144 $this->assertArrayHasKey('last', $content['_links']);
146 foreach (['self', 'first', 'last'] as $link) {
147 $this->assertArrayHasKey('href', $content['_links'][$link]);
148 $this->assertContains('archive=1', $content['_links'][$link]['href']);
149 $this->assertContains('starred=1', $content['_links'][$link]['href']);
150 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
151 $this->assertContains('order=asc', $content['_links'][$link]['href']);
152 $this->assertContains('tags=foo', $content['_links'][$link]['href']);
153 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
156 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
159 public function testGetEntriesOnPageTwo()
161 $this->client
->request('GET', '/api/entries', [
166 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
168 $content = json_decode($this->client
->getResponse()->getContent(), true);
170 $this->assertGreaterThanOrEqual(0, $content['total']);
171 $this->assertEquals(2, $content['page']);
172 $this->assertEquals(2, $content['limit']);
175 public function testGetStarredEntries()
177 $this->client
->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);
179 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
181 $content = json_decode($this->client
->getResponse()->getContent(), true);
183 $this->assertGreaterThanOrEqual(1, count($content));
184 $this->assertNotEmpty($content['_embedded']['items']);
185 $this->assertGreaterThanOrEqual(1, $content['total']);
186 $this->assertEquals(1, $content['page']);
187 $this->assertGreaterThanOrEqual(1, $content['pages']);
189 $this->assertArrayHasKey('_links', $content);
190 $this->assertArrayHasKey('self', $content['_links']);
191 $this->assertArrayHasKey('first', $content['_links']);
192 $this->assertArrayHasKey('last', $content['_links']);
194 foreach (['self', 'first', 'last'] as $link) {
195 $this->assertArrayHasKey('href', $content['_links'][$link]);
196 $this->assertContains('starred=1', $content['_links'][$link]['href']);
197 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
200 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
203 public function testGetArchiveEntries()
205 $this->client
->request('GET', '/api/entries', ['archive' => 1]);
207 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
209 $content = json_decode($this->client
->getResponse()->getContent(), true);
211 $this->assertGreaterThanOrEqual(1, count($content));
212 $this->assertNotEmpty($content['_embedded']['items']);
213 $this->assertGreaterThanOrEqual(1, $content['total']);
214 $this->assertEquals(1, $content['page']);
215 $this->assertGreaterThanOrEqual(1, $content['pages']);
217 $this->assertArrayHasKey('_links', $content);
218 $this->assertArrayHasKey('self', $content['_links']);
219 $this->assertArrayHasKey('first', $content['_links']);
220 $this->assertArrayHasKey('last', $content['_links']);
222 foreach (['self', 'first', 'last'] as $link) {
223 $this->assertArrayHasKey('href', $content['_links'][$link]);
224 $this->assertContains('archive=1', $content['_links'][$link]['href']);
227 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
230 public function testGetTaggedEntries()
232 $this->client
->request('GET', '/api/entries', ['tags' => 'foo,bar']);
234 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
236 $content = json_decode($this->client
->getResponse()->getContent(), true);
238 $this->assertGreaterThanOrEqual(1, count($content));
239 $this->assertNotEmpty($content['_embedded']['items']);
240 $this->assertGreaterThanOrEqual(1, $content['total']);
241 $this->assertEquals(1, $content['page']);
242 $this->assertGreaterThanOrEqual(1, $content['pages']);
244 $this->assertArrayHasKey('_links', $content);
245 $this->assertArrayHasKey('self', $content['_links']);
246 $this->assertArrayHasKey('first', $content['_links']);
247 $this->assertArrayHasKey('last', $content['_links']);
249 foreach (['self', 'first', 'last'] as $link) {
250 $this->assertArrayHasKey('href', $content['_links'][$link]);
251 $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']);
254 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
257 public function testGetDatedEntries()
259 $this->client
->request('GET', '/api/entries', ['since' => 1443274283]);
261 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
263 $content = json_decode($this->client
->getResponse()->getContent(), true);
265 $this->assertGreaterThanOrEqual(1, count($content));
266 $this->assertNotEmpty($content['_embedded']['items']);
267 $this->assertGreaterThanOrEqual(1, $content['total']);
268 $this->assertEquals(1, $content['page']);
269 $this->assertGreaterThanOrEqual(1, $content['pages']);
271 $this->assertArrayHasKey('_links', $content);
272 $this->assertArrayHasKey('self', $content['_links']);
273 $this->assertArrayHasKey('first', $content['_links']);
274 $this->assertArrayHasKey('last', $content['_links']);
276 foreach (['self', 'first', 'last'] as $link) {
277 $this->assertArrayHasKey('href', $content['_links'][$link]);
278 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
281 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
284 public function testGetDatedSupEntries()
286 $future = new \
DateTime(date('Y-m-d H:i:s'));
287 $this->client
->request('GET', '/api/entries', ['since' => $future->getTimestamp() +
1000]);
289 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
291 $content = json_decode($this->client
->getResponse()->getContent(), true);
293 $this->assertGreaterThanOrEqual(1, count($content));
294 $this->assertEmpty($content['_embedded']['items']);
295 $this->assertEquals(0, $content['total']);
296 $this->assertEquals(1, $content['page']);
297 $this->assertEquals(1, $content['pages']);
299 $this->assertArrayHasKey('_links', $content);
300 $this->assertArrayHasKey('self', $content['_links']);
301 $this->assertArrayHasKey('first', $content['_links']);
302 $this->assertArrayHasKey('last', $content['_links']);
304 foreach (['self', 'first', 'last'] as $link) {
305 $this->assertArrayHasKey('href', $content['_links'][$link]);
306 $this->assertContains('since='.($future->getTimestamp() +
1000), $content['_links'][$link]['href']);
309 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
312 public function testDeleteEntry()
314 $entry = $this->client
->getContainer()
315 ->get('doctrine.orm.entity_manager')
316 ->getRepository('WallabagCoreBundle:Entry')
320 $this->markTestSkipped('No content found in db.');
323 $this->client
->request('DELETE', '/api/entries/'.$entry->getId().'.json');
325 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
327 $content = json_decode($this->client
->getResponse()->getContent(), true);
329 $this->assertEquals($entry->getTitle(), $content['title']);
330 $this->assertEquals($entry->getUrl(), $content['url']);
332 // We'll try to delete this entry again
333 $this->client
->request('DELETE', '/api/entries/'.$entry->getId().'.json');
335 $this->assertEquals(404, $this->client
->getResponse()->getStatusCode());
338 public function testPostEntry()
340 $this->client
->request('POST', '/api/entries.json', [
341 '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',
343 'title' => 'New title for my article',
346 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
348 $content = json_decode($this->client
->getResponse()->getContent(), true);
350 $this->assertGreaterThan(0, $content['id']);
351 $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']);
352 $this->assertEquals(false, $content['is_archived']);
353 $this->assertEquals(false, $content['is_starred']);
354 $this->assertEquals('New title for my article', $content['title']);
355 $this->assertEquals(1, $content['user_id']);
356 $this->assertCount(1, $content['tags']);
359 public function testPostSameEntry()
361 $this->client
->request('POST', '/api/entries.json', [
362 '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',
364 'tags' => 'google, apple',
367 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
369 $content = json_decode($this->client
->getResponse()->getContent(), true);
371 $this->assertGreaterThan(0, $content['id']);
372 $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']);
373 $this->assertEquals(true, $content['is_archived']);
374 $this->assertEquals(false, $content['is_starred']);
375 $this->assertCount(2, $content['tags']);
378 public function testPostArchivedAndStarredEntry()
380 $this->client
->request('POST', '/api/entries.json', [
381 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
386 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
388 $content = json_decode($this->client
->getResponse()->getContent(), true);
390 $this->assertGreaterThan(0, $content['id']);
391 $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']);
392 $this->assertEquals(true, $content['is_archived']);
393 $this->assertEquals(true, $content['is_starred']);
394 $this->assertEquals(1, $content['user_id']);
397 public function testPostArchivedAndStarredEntryWithoutQuotes()
399 $this->client
->request('POST', '/api/entries.json', [
400 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
405 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
407 $content = json_decode($this->client
->getResponse()->getContent(), true);
409 $this->assertGreaterThan(0, $content['id']);
410 $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']);
411 $this->assertEquals(false, $content['is_archived']);
412 $this->assertEquals(true, $content['is_starred']);
415 public function testPatchEntry()
417 $entry = $this->client
->getContainer()
418 ->get('doctrine.orm.entity_manager')
419 ->getRepository('WallabagCoreBundle:Entry')
423 $this->markTestSkipped('No content found in db.');
426 // hydrate the tags relations
427 $nbTags = count($entry->getTags());
429 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
430 'title' => 'New awesome title',
431 'tags' => 'new tag '.uniqid(),
436 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
438 $content = json_decode($this->client
->getResponse()->getContent(), true);
440 $this->assertEquals($entry->getId(), $content['id']);
441 $this->assertEquals($entry->getUrl(), $content['url']);
442 $this->assertEquals('New awesome title', $content['title']);
443 $this->assertGreaterThan($nbTags, count($content['tags']));
444 $this->assertEquals(1, $content['user_id']);
447 public function testPatchEntryWithoutQuotes()
449 $entry = $this->client
->getContainer()
450 ->get('doctrine.orm.entity_manager')
451 ->getRepository('WallabagCoreBundle:Entry')
455 $this->markTestSkipped('No content found in db.');
458 // hydrate the tags relations
459 $nbTags = count($entry->getTags());
461 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
462 'title' => 'New awesome title',
463 'tags' => 'new tag '.uniqid(),
468 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
470 $content = json_decode($this->client
->getResponse()->getContent(), true);
472 $this->assertEquals($entry->getId(), $content['id']);
473 $this->assertEquals($entry->getUrl(), $content['url']);
474 $this->assertEquals('New awesome title', $content['title']);
475 $this->assertGreaterThan($nbTags, count($content['tags']));
478 public function testGetTagsEntry()
480 $entry = $this->client
->getContainer()
481 ->get('doctrine.orm.entity_manager')
482 ->getRepository('WallabagCoreBundle:Entry')
483 ->findOneWithTags($this->user
->getId());
488 $this->markTestSkipped('No content found in db.');
492 foreach ($entry->getTags() as $tag) {
493 $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()];
496 $this->client
->request('GET', '/api/entries/'.$entry->getId().'/tags');
498 $this->assertEquals(json_encode($tags, JSON_HEX_QUOT
), $this->client
->getResponse()->getContent());
501 public function testPostTagsOnEntry()
503 $entry = $this->client
->getContainer()
504 ->get('doctrine.orm.entity_manager')
505 ->getRepository('WallabagCoreBundle:Entry')
509 $this->markTestSkipped('No content found in db.');
512 $nbTags = count($entry->getTags());
514 $newTags = 'tag1,tag2,tag3';
516 $this->client
->request('POST', '/api/entries/'.$entry->getId().'/tags', ['tags' => $newTags]);
518 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
520 $content = json_decode($this->client
->getResponse()->getContent(), true);
522 $this->assertArrayHasKey('tags', $content);
523 $this->assertEquals($nbTags +
3, count($content['tags']));
525 $entryDB = $this->client
->getContainer()
526 ->get('doctrine.orm.entity_manager')
527 ->getRepository('WallabagCoreBundle:Entry')
528 ->find($entry->getId());
531 foreach ($entryDB->getTags()->toArray() as $tag) {
532 $tagsInDB[$tag->getId()] = $tag->getLabel();
535 foreach (explode(',', $newTags) as $tag) {
536 $this->assertContains($tag, $tagsInDB);
540 public function testDeleteOneTagEntry()
542 $entry = $this->client
->getContainer()
543 ->get('doctrine.orm.entity_manager')
544 ->getRepository('WallabagCoreBundle:Entry')
545 ->findOneWithTags($this->user
->getId());
549 $this->markTestSkipped('No content found in db.');
552 // hydrate the tags relations
553 $nbTags = count($entry->getTags());
554 $tag = $entry->getTags()[0];
556 $this->client
->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json');
558 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
560 $content = json_decode($this->client
->getResponse()->getContent(), true);
562 $this->assertArrayHasKey('tags', $content);
563 $this->assertEquals($nbTags - 1, count($content['tags']));
566 public function testSaveIsArchivedAfterPost()
568 $entry = $this->client
->getContainer()
569 ->get('doctrine.orm.entity_manager')
570 ->getRepository('WallabagCoreBundle:Entry')
571 ->findOneBy(['user' => 1, 'isArchived' => true]);
574 $this->markTestSkipped('No content found in db.');
577 $this->client
->request('POST', '/api/entries.json', [
578 'url' => $entry->getUrl(),
581 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
583 $content = json_decode($this->client
->getResponse()->getContent(), true);
585 $this->assertEquals(true, $content['is_archived']);
588 public function testSaveIsStarredAfterPost()
590 $entry = $this->client
->getContainer()
591 ->get('doctrine.orm.entity_manager')
592 ->getRepository('WallabagCoreBundle:Entry')
593 ->findOneBy(['user' => 1, 'isStarred' => true]);
596 $this->markTestSkipped('No content found in db.');
599 $this->client
->request('POST', '/api/entries.json', [
600 'url' => $entry->getUrl(),
603 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
605 $content = json_decode($this->client
->getResponse()->getContent(), true);
607 $this->assertEquals(true, $content['is_starred']);
610 public function testSaveIsArchivedAfterPatch()
612 $entry = $this->client
->getContainer()
613 ->get('doctrine.orm.entity_manager')
614 ->getRepository('WallabagCoreBundle:Entry')
615 ->findOneBy(['user' => 1, 'isArchived' => true]);
618 $this->markTestSkipped('No content found in db.');
621 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
622 'title' => $entry->getTitle().'++',
625 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
627 $content = json_decode($this->client
->getResponse()->getContent(), true);
629 $this->assertEquals(true, $content['is_archived']);
632 public function testSaveIsStarredAfterPatch()
634 $entry = $this->client
->getContainer()
635 ->get('doctrine.orm.entity_manager')
636 ->getRepository('WallabagCoreBundle:Entry')
637 ->findOneBy(['user' => 1, 'isStarred' => true]);
640 $this->markTestSkipped('No content found in db.');
642 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
643 'title' => $entry->getTitle().'++',
646 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
648 $content = json_decode($this->client
->getResponse()->getContent(), true);
650 $this->assertEquals(true, $content['is_starred']);
653 public function testGetEntriesExists()
655 $this->client
->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
657 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
659 $content = json_decode($this->client
->getResponse()->getContent(), true);
661 $this->assertEquals(true, $content['exists']);
664 public function testGetEntriesExistsWithManyUrls()
666 $url1 = 'http://0.0.0.0/entry2';
667 $url2 = 'http://0.0.0.0/entry10';
668 $this->client
->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2);
670 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
672 $content = json_decode($this->client
->getResponse()->getContent(), true);
674 $this->assertArrayHasKey($url1, $content);
675 $this->assertArrayHasKey($url2, $content);
676 $this->assertEquals(true, $content[$url1]);
677 $this->assertEquals(false, $content[$url2]);
680 public function testGetEntriesExistsWhichDoesNotExists()
682 $this->client
->request('GET', '/api/entries/exists?url=http://google.com/entry2');
684 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
686 $content = json_decode($this->client
->getResponse()->getContent(), true);
688 $this->assertEquals(false, $content['exists']);
691 public function testGetEntriesExistsWithNoUrl()
693 $this->client
->request('GET', '/api/entries/exists?url=');
695 $this->assertEquals(403, $this->client
->getResponse()->getStatusCode());
698 public function testReloadEntryErrorWhileFetching()
700 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
701 ->getRepository('WallabagCoreBundle:Entry')
702 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
705 $this->markTestSkipped('No content found in db.');
708 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json');
709 $this->assertEquals(304, $this->client
->getResponse()->getStatusCode());
712 public function testReloadEntry()
714 $this->client
->request('POST', '/api/entries.json', [
715 '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',
717 'tags' => 'google, apple',
720 $json = json_decode($this->client
->getResponse()->getContent(), true);
724 $this->client
->request('PATCH', '/api/entries/'.$json['id'].'/reload.json');
725 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
727 $content = json_decode($this->client
->getResponse()->getContent(), true);
729 $this->assertNotEmpty($content['title']);
731 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));