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);
376 $this->client
->request('POST', '/api/entries.json', [
377 'url' => 'http://www.example.com/',
380 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
381 $content = json_decode($this->client
->getResponse()->getContent(), true);
382 $this->assertGreaterThan(0, $content['id']);
383 $this->assertEquals('http://www.example.com/', $content['url']);
386 public function testPostArchivedAndStarredEntry()
388 $this->client
->request('POST', '/api/entries.json', [
389 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
394 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
396 $content = json_decode($this->client
->getResponse()->getContent(), true);
398 $this->assertGreaterThan(0, $content['id']);
399 $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']);
400 $this->assertEquals(true, $content['is_archived']);
401 $this->assertEquals(true, $content['is_starred']);
402 $this->assertEquals(1, $content['user_id']);
405 public function testPostArchivedAndStarredEntryWithoutQuotes()
407 $this->client
->request('POST', '/api/entries.json', [
408 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
413 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
415 $content = json_decode($this->client
->getResponse()->getContent(), true);
417 $this->assertGreaterThan(0, $content['id']);
418 $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']);
419 $this->assertEquals(false, $content['is_archived']);
420 $this->assertEquals(true, $content['is_starred']);
423 public function testPatchEntry()
425 $entry = $this->client
->getContainer()
426 ->get('doctrine.orm.entity_manager')
427 ->getRepository('WallabagCoreBundle:Entry')
431 $this->markTestSkipped('No content found in db.');
434 // hydrate the tags relations
435 $nbTags = count($entry->getTags());
437 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
438 'title' => 'New awesome title',
439 'tags' => 'new tag '.uniqid(),
444 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
446 $content = json_decode($this->client
->getResponse()->getContent(), true);
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 $this->assertEquals(1, $content['user_id']);
455 public function testPatchEntryWithoutQuotes()
457 $entry = $this->client
->getContainer()
458 ->get('doctrine.orm.entity_manager')
459 ->getRepository('WallabagCoreBundle:Entry')
463 $this->markTestSkipped('No content found in db.');
466 // hydrate the tags relations
467 $nbTags = count($entry->getTags());
469 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
470 'title' => 'New awesome title',
471 'tags' => 'new tag '.uniqid(),
476 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
478 $content = json_decode($this->client
->getResponse()->getContent(), true);
480 $this->assertEquals($entry->getId(), $content['id']);
481 $this->assertEquals($entry->getUrl(), $content['url']);
482 $this->assertEquals('New awesome title', $content['title']);
483 $this->assertGreaterThan($nbTags, count($content['tags']));
486 public function testGetTagsEntry()
488 $entry = $this->client
->getContainer()
489 ->get('doctrine.orm.entity_manager')
490 ->getRepository('WallabagCoreBundle:Entry')
491 ->findOneWithTags($this->user
->getId());
496 $this->markTestSkipped('No content found in db.');
500 foreach ($entry->getTags() as $tag) {
501 $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()];
504 $this->client
->request('GET', '/api/entries/'.$entry->getId().'/tags');
506 $this->assertEquals(json_encode($tags, JSON_HEX_QUOT
), $this->client
->getResponse()->getContent());
509 public function testPostTagsOnEntry()
511 $entry = $this->client
->getContainer()
512 ->get('doctrine.orm.entity_manager')
513 ->getRepository('WallabagCoreBundle:Entry')
517 $this->markTestSkipped('No content found in db.');
520 $nbTags = count($entry->getTags());
522 $newTags = 'tag1,tag2,tag3';
524 $this->client
->request('POST', '/api/entries/'.$entry->getId().'/tags', ['tags' => $newTags]);
526 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
528 $content = json_decode($this->client
->getResponse()->getContent(), true);
530 $this->assertArrayHasKey('tags', $content);
531 $this->assertEquals($nbTags +
3, count($content['tags']));
533 $entryDB = $this->client
->getContainer()
534 ->get('doctrine.orm.entity_manager')
535 ->getRepository('WallabagCoreBundle:Entry')
536 ->find($entry->getId());
539 foreach ($entryDB->getTags()->toArray() as $tag) {
540 $tagsInDB[$tag->getId()] = $tag->getLabel();
543 foreach (explode(',', $newTags) as $tag) {
544 $this->assertContains($tag, $tagsInDB);
548 public function testDeleteOneTagEntry()
550 $entry = $this->client
->getContainer()
551 ->get('doctrine.orm.entity_manager')
552 ->getRepository('WallabagCoreBundle:Entry')
553 ->findOneWithTags($this->user
->getId());
557 $this->markTestSkipped('No content found in db.');
560 // hydrate the tags relations
561 $nbTags = count($entry->getTags());
562 $tag = $entry->getTags()[0];
564 $this->client
->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json');
566 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
568 $content = json_decode($this->client
->getResponse()->getContent(), true);
570 $this->assertArrayHasKey('tags', $content);
571 $this->assertEquals($nbTags - 1, count($content['tags']));
574 public function testSaveIsArchivedAfterPost()
576 $entry = $this->client
->getContainer()
577 ->get('doctrine.orm.entity_manager')
578 ->getRepository('WallabagCoreBundle:Entry')
579 ->findOneBy(['user' => 1, 'isArchived' => true]);
582 $this->markTestSkipped('No content found in db.');
585 $this->client
->request('POST', '/api/entries.json', [
586 'url' => $entry->getUrl(),
589 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
591 $content = json_decode($this->client
->getResponse()->getContent(), true);
593 $this->assertEquals(true, $content['is_archived']);
596 public function testSaveIsStarredAfterPost()
598 $entry = $this->client
->getContainer()
599 ->get('doctrine.orm.entity_manager')
600 ->getRepository('WallabagCoreBundle:Entry')
601 ->findOneBy(['user' => 1, 'isStarred' => true]);
604 $this->markTestSkipped('No content found in db.');
607 $this->client
->request('POST', '/api/entries.json', [
608 'url' => $entry->getUrl(),
611 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
613 $content = json_decode($this->client
->getResponse()->getContent(), true);
615 $this->assertEquals(true, $content['is_starred']);
618 public function testSaveIsArchivedAfterPatch()
620 $entry = $this->client
->getContainer()
621 ->get('doctrine.orm.entity_manager')
622 ->getRepository('WallabagCoreBundle:Entry')
623 ->findOneBy(['user' => 1, 'isArchived' => true]);
626 $this->markTestSkipped('No content found in db.');
629 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
630 'title' => $entry->getTitle().'++',
633 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
635 $content = json_decode($this->client
->getResponse()->getContent(), true);
637 $this->assertEquals(true, $content['is_archived']);
640 public function testSaveIsStarredAfterPatch()
642 $entry = $this->client
->getContainer()
643 ->get('doctrine.orm.entity_manager')
644 ->getRepository('WallabagCoreBundle:Entry')
645 ->findOneBy(['user' => 1, 'isStarred' => true]);
648 $this->markTestSkipped('No content found in db.');
650 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
651 'title' => $entry->getTitle().'++',
654 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
656 $content = json_decode($this->client
->getResponse()->getContent(), true);
658 $this->assertEquals(true, $content['is_starred']);
661 public function testGetEntriesExists()
663 $this->client
->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
665 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
667 $content = json_decode($this->client
->getResponse()->getContent(), true);
669 $this->assertEquals(true, $content['exists']);
672 public function testGetEntriesExistsWithManyUrls()
674 $url1 = 'http://0.0.0.0/entry2';
675 $url2 = 'http://0.0.0.0/entry10';
676 $this->client
->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2);
678 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
680 $content = json_decode($this->client
->getResponse()->getContent(), true);
682 $this->assertArrayHasKey($url1, $content);
683 $this->assertArrayHasKey($url2, $content);
684 $this->assertEquals(true, $content[$url1]);
685 $this->assertEquals(false, $content[$url2]);
688 public function testGetEntriesExistsWhichDoesNotExists()
690 $this->client
->request('GET', '/api/entries/exists?url=http://google.com/entry2');
692 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
694 $content = json_decode($this->client
->getResponse()->getContent(), true);
696 $this->assertEquals(false, $content['exists']);
699 public function testGetEntriesExistsWithNoUrl()
701 $this->client
->request('GET', '/api/entries/exists?url=');
703 $this->assertEquals(403, $this->client
->getResponse()->getStatusCode());
706 public function testReloadEntryErrorWhileFetching()
708 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
709 ->getRepository('WallabagCoreBundle:Entry')
710 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
713 $this->markTestSkipped('No content found in db.');
716 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json');
717 $this->assertEquals(304, $this->client
->getResponse()->getStatusCode());
720 public function testReloadEntry()
722 $this->client
->request('POST', '/api/entries.json', [
723 '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',
725 'tags' => 'google, apple',
728 $json = json_decode($this->client
->getResponse()->getContent(), true);
732 $this->client
->request('PATCH', '/api/entries/'.$json['id'].'/reload.json');
733 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
735 $content = json_decode($this->client
->getResponse()->getContent(), true);
737 $this->assertNotEmpty($content['title']);
739 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));