3 namespace Tests\Wallabag\ApiBundle\Controller
;
5 use Tests\Wallabag\ApiBundle\WallabagApiTestCase
;
6 use Wallabag\CoreBundle\Entity\Tag
;
7 use Wallabag\CoreBundle\Helper\ContentProxy
;
9 class EntryRestControllerTest
extends WallabagApiTestCase
11 public function testGetOneEntry()
13 $entry = $this->client
->getContainer()
14 ->get('doctrine.orm.entity_manager')
15 ->getRepository('WallabagCoreBundle:Entry')
16 ->findOneBy(['user' => 1, 'isArchived' => false]);
19 $this->markTestSkipped('No content found in db.');
22 $this->client
->request('GET', '/api/entries/'.$entry->getId().'.json');
23 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
25 $content = json_decode($this->client
->getResponse()->getContent(), true);
27 $this->assertEquals($entry->getTitle(), $content['title']);
28 $this->assertEquals($entry->getUrl(), $content['url']);
29 $this->assertCount(count($entry->getTags()), $content['tags']);
30 $this->assertEquals($entry->getUserName(), $content['user_name']);
31 $this->assertEquals($entry->getUserEmail(), $content['user_email']);
32 $this->assertEquals($entry->getUserId(), $content['user_id']);
34 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
37 public function testExportEntry()
39 $entry = $this->client
->getContainer()
40 ->get('doctrine.orm.entity_manager')
41 ->getRepository('WallabagCoreBundle:Entry')
42 ->findOneBy(['user' => 1, 'isArchived' => false]);
45 $this->markTestSkipped('No content found in db.');
48 $this->client
->request('GET', '/api/entries/'.$entry->getId().'/export.epub');
49 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
51 // epub format got the content type in the content
52 $this->assertContains('application/epub', $this->client
->getResponse()->getContent());
53 $this->assertEquals('application/epub+zip', $this->client
->getResponse()->headers
->get('Content-Type'));
55 // re-auth client for mobi
56 $client = $this->createAuthorizedClient();
57 $client->request('GET', '/api/entries/'.$entry->getId().'/export.mobi');
58 $this->assertEquals(200, $client->getResponse()->getStatusCode());
60 $this->assertEquals('application/x-mobipocket-ebook', $client->getResponse()->headers
->get('Content-Type'));
62 // re-auth client for pdf
63 $client = $this->createAuthorizedClient();
64 $client->request('GET', '/api/entries/'.$entry->getId().'/export.pdf');
65 $this->assertEquals(200, $client->getResponse()->getStatusCode());
67 $this->assertContains('PDF-', $client->getResponse()->getContent());
68 $this->assertEquals('application/pdf', $client->getResponse()->headers
->get('Content-Type'));
70 // re-auth client for pdf
71 $client = $this->createAuthorizedClient();
72 $client->request('GET', '/api/entries/'.$entry->getId().'/export.txt');
73 $this->assertEquals(200, $client->getResponse()->getStatusCode());
75 $this->assertContains('text/plain', $client->getResponse()->headers
->get('Content-Type'));
77 // re-auth client for pdf
78 $client = $this->createAuthorizedClient();
79 $client->request('GET', '/api/entries/'.$entry->getId().'/export.csv');
80 $this->assertEquals(200, $client->getResponse()->getStatusCode());
82 $this->assertContains('application/csv', $client->getResponse()->headers
->get('Content-Type'));
85 public function testGetOneEntryWrongUser()
87 $entry = $this->client
->getContainer()
88 ->get('doctrine.orm.entity_manager')
89 ->getRepository('WallabagCoreBundle:Entry')
90 ->findOneBy(['user' => 2, 'isArchived' => false]);
93 $this->markTestSkipped('No content found in db.');
96 $this->client
->request('GET', '/api/entries/'.$entry->getId().'.json');
98 $this->assertEquals(403, $this->client
->getResponse()->getStatusCode());
101 public function testGetEntries()
103 $this->client
->request('GET', '/api/entries');
105 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
107 $content = json_decode($this->client
->getResponse()->getContent(), true);
109 $this->assertGreaterThanOrEqual(1, count($content));
110 $this->assertNotEmpty($content['_embedded']['items']);
111 $this->assertGreaterThanOrEqual(1, $content['total']);
112 $this->assertEquals(1, $content['page']);
113 $this->assertGreaterThanOrEqual(1, $content['pages']);
115 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
118 public function testGetEntriesWithFullOptions()
120 $this->client
->request('GET', '/api/entries', [
128 'since' => 1443274283,
131 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
133 $content = json_decode($this->client
->getResponse()->getContent(), true);
135 $this->assertGreaterThanOrEqual(1, count($content));
136 $this->assertArrayHasKey('items', $content['_embedded']);
137 $this->assertGreaterThanOrEqual(0, $content['total']);
138 $this->assertEquals(1, $content['page']);
139 $this->assertEquals(2, $content['limit']);
140 $this->assertGreaterThanOrEqual(1, $content['pages']);
142 $this->assertArrayHasKey('_links', $content);
143 $this->assertArrayHasKey('self', $content['_links']);
144 $this->assertArrayHasKey('first', $content['_links']);
145 $this->assertArrayHasKey('last', $content['_links']);
147 foreach (['self', 'first', 'last'] as $link) {
148 $this->assertArrayHasKey('href', $content['_links'][$link]);
149 $this->assertContains('archive=1', $content['_links'][$link]['href']);
150 $this->assertContains('starred=1', $content['_links'][$link]['href']);
151 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
152 $this->assertContains('order=asc', $content['_links'][$link]['href']);
153 $this->assertContains('tags=foo', $content['_links'][$link]['href']);
154 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
157 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
160 public function testGetStarredEntries()
162 $this->client
->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);
164 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
166 $content = json_decode($this->client
->getResponse()->getContent(), true);
168 $this->assertGreaterThanOrEqual(1, count($content));
169 $this->assertNotEmpty($content['_embedded']['items']);
170 $this->assertGreaterThanOrEqual(1, $content['total']);
171 $this->assertEquals(1, $content['page']);
172 $this->assertGreaterThanOrEqual(1, $content['pages']);
174 $this->assertArrayHasKey('_links', $content);
175 $this->assertArrayHasKey('self', $content['_links']);
176 $this->assertArrayHasKey('first', $content['_links']);
177 $this->assertArrayHasKey('last', $content['_links']);
179 foreach (['self', 'first', 'last'] as $link) {
180 $this->assertArrayHasKey('href', $content['_links'][$link]);
181 $this->assertContains('starred=1', $content['_links'][$link]['href']);
182 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
185 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
188 public function testGetArchiveEntries()
190 $this->client
->request('GET', '/api/entries', ['archive' => 1]);
192 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
194 $content = json_decode($this->client
->getResponse()->getContent(), true);
196 $this->assertGreaterThanOrEqual(1, count($content));
197 $this->assertNotEmpty($content['_embedded']['items']);
198 $this->assertGreaterThanOrEqual(1, $content['total']);
199 $this->assertEquals(1, $content['page']);
200 $this->assertGreaterThanOrEqual(1, $content['pages']);
202 $this->assertArrayHasKey('_links', $content);
203 $this->assertArrayHasKey('self', $content['_links']);
204 $this->assertArrayHasKey('first', $content['_links']);
205 $this->assertArrayHasKey('last', $content['_links']);
207 foreach (['self', 'first', 'last'] as $link) {
208 $this->assertArrayHasKey('href', $content['_links'][$link]);
209 $this->assertContains('archive=1', $content['_links'][$link]['href']);
212 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
215 public function testGetTaggedEntries()
217 $this->client
->request('GET', '/api/entries', ['tags' => 'foo,bar']);
219 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
221 $content = json_decode($this->client
->getResponse()->getContent(), true);
223 $this->assertGreaterThanOrEqual(1, count($content));
224 $this->assertNotEmpty($content['_embedded']['items']);
225 $this->assertGreaterThanOrEqual(1, $content['total']);
226 $this->assertEquals(1, $content['page']);
227 $this->assertGreaterThanOrEqual(1, $content['pages']);
229 $this->assertArrayHasKey('_links', $content);
230 $this->assertArrayHasKey('self', $content['_links']);
231 $this->assertArrayHasKey('first', $content['_links']);
232 $this->assertArrayHasKey('last', $content['_links']);
234 foreach (['self', 'first', 'last'] as $link) {
235 $this->assertArrayHasKey('href', $content['_links'][$link]);
236 $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']);
239 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
242 public function testGetDatedEntries()
244 $this->client
->request('GET', '/api/entries', ['since' => 1443274283]);
246 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
248 $content = json_decode($this->client
->getResponse()->getContent(), true);
250 $this->assertGreaterThanOrEqual(1, count($content));
251 $this->assertNotEmpty($content['_embedded']['items']);
252 $this->assertGreaterThanOrEqual(1, $content['total']);
253 $this->assertEquals(1, $content['page']);
254 $this->assertGreaterThanOrEqual(1, $content['pages']);
256 $this->assertArrayHasKey('_links', $content);
257 $this->assertArrayHasKey('self', $content['_links']);
258 $this->assertArrayHasKey('first', $content['_links']);
259 $this->assertArrayHasKey('last', $content['_links']);
261 foreach (['self', 'first', 'last'] as $link) {
262 $this->assertArrayHasKey('href', $content['_links'][$link]);
263 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
266 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
269 public function testGetDatedSupEntries()
271 $future = new \
DateTime(date('Y-m-d H:i:s'));
272 $this->client
->request('GET', '/api/entries', ['since' => $future->getTimestamp() +
1000]);
274 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
276 $content = json_decode($this->client
->getResponse()->getContent(), true);
278 $this->assertGreaterThanOrEqual(1, count($content));
279 $this->assertEmpty($content['_embedded']['items']);
280 $this->assertEquals(0, $content['total']);
281 $this->assertEquals(1, $content['page']);
282 $this->assertEquals(1, $content['pages']);
284 $this->assertArrayHasKey('_links', $content);
285 $this->assertArrayHasKey('self', $content['_links']);
286 $this->assertArrayHasKey('first', $content['_links']);
287 $this->assertArrayHasKey('last', $content['_links']);
289 foreach (['self', 'first', 'last'] as $link) {
290 $this->assertArrayHasKey('href', $content['_links'][$link]);
291 $this->assertContains('since='.($future->getTimestamp() +
1000), $content['_links'][$link]['href']);
294 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
297 public function testDeleteEntry()
299 $entry = $this->client
->getContainer()
300 ->get('doctrine.orm.entity_manager')
301 ->getRepository('WallabagCoreBundle:Entry')
305 $this->markTestSkipped('No content found in db.');
308 $this->client
->request('DELETE', '/api/entries/'.$entry->getId().'.json');
310 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
312 $content = json_decode($this->client
->getResponse()->getContent(), true);
314 $this->assertEquals($entry->getTitle(), $content['title']);
315 $this->assertEquals($entry->getUrl(), $content['url']);
317 // We'll try to delete this entry again
318 $this->client
->request('DELETE', '/api/entries/'.$entry->getId().'.json');
320 $this->assertEquals(404, $this->client
->getResponse()->getStatusCode());
323 public function testPostEntry()
325 $this->client
->request('POST', '/api/entries.json', [
326 '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',
328 'title' => 'New title for my article',
331 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
333 $content = json_decode($this->client
->getResponse()->getContent(), true);
335 $this->assertGreaterThan(0, $content['id']);
336 $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']);
337 $this->assertEquals(false, $content['is_archived']);
338 $this->assertEquals(false, $content['is_starred']);
339 $this->assertEquals('New title for my article', $content['title']);
340 $this->assertEquals(1, $content['user_id']);
341 $this->assertCount(1, $content['tags']);
344 public function testPostSameEntry()
346 $this->client
->request('POST', '/api/entries.json', [
347 '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',
349 'tags' => 'google, apple',
352 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
354 $content = json_decode($this->client
->getResponse()->getContent(), true);
356 $this->assertGreaterThan(0, $content['id']);
357 $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']);
358 $this->assertEquals(true, $content['is_archived']);
359 $this->assertEquals(false, $content['is_starred']);
360 $this->assertCount(2, $content['tags']);
363 public function testPostEntryWhenFetchContentFails()
365 /** @var \Symfony\Component\DependencyInjection\Container $container */
366 $container = $this->client
->getContainer();
367 $contentProxy = $this->getMockBuilder(ContentProxy
::class)
368 ->disableOriginalConstructor()
369 ->setMethods(['updateEntry'])
371 $contentProxy->expects($this->any())
372 ->method('updateEntry')
373 ->willThrowException(new \
Exception('Test Fetch content fails'));
374 $container->set('wallabag_core.content_proxy', $contentProxy);
377 $this->client
->request('POST', '/api/entries.json', [
378 'url' => 'http://www.example.com/',
381 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
382 $content = json_decode($this->client
->getResponse()->getContent(), true);
383 $this->assertGreaterThan(0, $content['id']);
384 $this->assertEquals('http://www.example.com/', $content['url']);
386 // Remove the created entry to avoid side effects on other tests
387 if (isset($content['id'])) {
388 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
389 $entry = $em->getReference('WallabagCoreBundle:Entry', $content['id']);
396 public function testPostArchivedAndStarredEntry()
398 $this->client
->request('POST', '/api/entries.json', [
399 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
404 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
406 $content = json_decode($this->client
->getResponse()->getContent(), true);
408 $this->assertGreaterThan(0, $content['id']);
409 $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']);
410 $this->assertEquals(true, $content['is_archived']);
411 $this->assertEquals(true, $content['is_starred']);
412 $this->assertEquals(1, $content['user_id']);
415 public function testPostArchivedAndStarredEntryWithoutQuotes()
417 $this->client
->request('POST', '/api/entries.json', [
418 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
423 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
425 $content = json_decode($this->client
->getResponse()->getContent(), true);
427 $this->assertGreaterThan(0, $content['id']);
428 $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']);
429 $this->assertEquals(false, $content['is_archived']);
430 $this->assertEquals(true, $content['is_starred']);
433 public function testPatchEntry()
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']));
462 $this->assertEquals(1, $content['user_id']);
465 public function testPatchEntryWithoutQuotes()
467 $entry = $this->client
->getContainer()
468 ->get('doctrine.orm.entity_manager')
469 ->getRepository('WallabagCoreBundle:Entry')
473 $this->markTestSkipped('No content found in db.');
476 // hydrate the tags relations
477 $nbTags = count($entry->getTags());
479 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
480 'title' => 'New awesome title',
481 'tags' => 'new tag '.uniqid(),
486 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
488 $content = json_decode($this->client
->getResponse()->getContent(), true);
490 $this->assertEquals($entry->getId(), $content['id']);
491 $this->assertEquals($entry->getUrl(), $content['url']);
492 $this->assertEquals('New awesome title', $content['title']);
493 $this->assertGreaterThan($nbTags, count($content['tags']));
496 public function testGetTagsEntry()
498 $entry = $this->client
->getContainer()
499 ->get('doctrine.orm.entity_manager')
500 ->getRepository('WallabagCoreBundle:Entry')
501 ->findOneWithTags($this->user
->getId());
506 $this->markTestSkipped('No content found in db.');
510 foreach ($entry->getTags() as $tag) {
511 $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()];
514 $this->client
->request('GET', '/api/entries/'.$entry->getId().'/tags');
516 $this->assertEquals(json_encode($tags, JSON_HEX_QUOT
), $this->client
->getResponse()->getContent());
519 public function testPostTagsOnEntry()
521 $entry = $this->client
->getContainer()
522 ->get('doctrine.orm.entity_manager')
523 ->getRepository('WallabagCoreBundle:Entry')
527 $this->markTestSkipped('No content found in db.');
530 $nbTags = count($entry->getTags());
532 $newTags = 'tag1,tag2,tag3';
534 $this->client
->request('POST', '/api/entries/'.$entry->getId().'/tags', ['tags' => $newTags]);
536 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
538 $content = json_decode($this->client
->getResponse()->getContent(), true);
540 $this->assertArrayHasKey('tags', $content);
541 $this->assertEquals($nbTags +
3, count($content['tags']));
543 $entryDB = $this->client
->getContainer()
544 ->get('doctrine.orm.entity_manager')
545 ->getRepository('WallabagCoreBundle:Entry')
546 ->find($entry->getId());
549 foreach ($entryDB->getTags()->toArray() as $tag) {
550 $tagsInDB[$tag->getId()] = $tag->getLabel();
553 foreach (explode(',', $newTags) as $tag) {
554 $this->assertContains($tag, $tagsInDB);
558 public function testDeleteOneTagEntry()
560 $entry = $this->client
->getContainer()
561 ->get('doctrine.orm.entity_manager')
562 ->getRepository('WallabagCoreBundle:Entry')
563 ->findOneWithTags($this->user
->getId());
567 $this->markTestSkipped('No content found in db.');
570 // hydrate the tags relations
571 $nbTags = count($entry->getTags());
572 $tag = $entry->getTags()[0];
574 $this->client
->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json');
576 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
578 $content = json_decode($this->client
->getResponse()->getContent(), true);
580 $this->assertArrayHasKey('tags', $content);
581 $this->assertEquals($nbTags - 1, count($content['tags']));
584 public function testSaveIsArchivedAfterPost()
586 $entry = $this->client
->getContainer()
587 ->get('doctrine.orm.entity_manager')
588 ->getRepository('WallabagCoreBundle:Entry')
589 ->findOneBy(['user' => 1, 'isArchived' => true]);
592 $this->markTestSkipped('No content found in db.');
595 $this->client
->request('POST', '/api/entries.json', [
596 'url' => $entry->getUrl(),
599 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
601 $content = json_decode($this->client
->getResponse()->getContent(), true);
603 $this->assertEquals(true, $content['is_archived']);
606 public function testSaveIsStarredAfterPost()
608 $entry = $this->client
->getContainer()
609 ->get('doctrine.orm.entity_manager')
610 ->getRepository('WallabagCoreBundle:Entry')
611 ->findOneBy(['user' => 1, 'isStarred' => true]);
614 $this->markTestSkipped('No content found in db.');
617 $this->client
->request('POST', '/api/entries.json', [
618 'url' => $entry->getUrl(),
621 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
623 $content = json_decode($this->client
->getResponse()->getContent(), true);
625 $this->assertEquals(true, $content['is_starred']);
628 public function testSaveIsArchivedAfterPatch()
630 $entry = $this->client
->getContainer()
631 ->get('doctrine.orm.entity_manager')
632 ->getRepository('WallabagCoreBundle:Entry')
633 ->findOneBy(['user' => 1, 'isArchived' => true]);
636 $this->markTestSkipped('No content found in db.');
639 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
640 'title' => $entry->getTitle().'++',
643 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
645 $content = json_decode($this->client
->getResponse()->getContent(), true);
647 $this->assertEquals(true, $content['is_archived']);
650 public function testSaveIsStarredAfterPatch()
652 $entry = $this->client
->getContainer()
653 ->get('doctrine.orm.entity_manager')
654 ->getRepository('WallabagCoreBundle:Entry')
655 ->findOneBy(['user' => 1, 'isStarred' => true]);
658 $this->markTestSkipped('No content found in db.');
660 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
661 'title' => $entry->getTitle().'++',
664 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
666 $content = json_decode($this->client
->getResponse()->getContent(), true);
668 $this->assertEquals(true, $content['is_starred']);
671 public function testGetEntriesExists()
673 $this->client
->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
675 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
677 $content = json_decode($this->client
->getResponse()->getContent(), true);
679 $this->assertEquals(true, $content['exists']);
682 public function testGetEntriesExistsWithManyUrls()
684 $url1 = 'http://0.0.0.0/entry2';
685 $url2 = 'http://0.0.0.0/entry10';
686 $this->client
->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2);
688 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
690 $content = json_decode($this->client
->getResponse()->getContent(), true);
692 $this->assertArrayHasKey($url1, $content);
693 $this->assertArrayHasKey($url2, $content);
694 $this->assertEquals(true, $content[$url1]);
695 $this->assertEquals(false, $content[$url2]);
698 public function testGetEntriesExistsWhichDoesNotExists()
700 $this->client
->request('GET', '/api/entries/exists?url=http://google.com/entry2');
702 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
704 $content = json_decode($this->client
->getResponse()->getContent(), true);
706 $this->assertEquals(false, $content['exists']);
709 public function testGetEntriesExistsWithNoUrl()
711 $this->client
->request('GET', '/api/entries/exists?url=');
713 $this->assertEquals(403, $this->client
->getResponse()->getStatusCode());
716 public function testReloadEntryErrorWhileFetching()
718 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
719 ->getRepository('WallabagCoreBundle:Entry')
720 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
723 $this->markTestSkipped('No content found in db.');
726 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json');
727 $this->assertEquals(304, $this->client
->getResponse()->getStatusCode());
730 public function testReloadEntry()
732 $this->client
->request('POST', '/api/entries.json', [
733 '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',
735 'tags' => 'google, apple',
738 $json = json_decode($this->client
->getResponse()->getContent(), true);
742 $this->client
->request('PATCH', '/api/entries/'.$json['id'].'/reload.json');
743 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
745 $content = json_decode($this->client
->getResponse()->getContent(), true);
747 $this->assertNotEmpty($content['title']);
749 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));