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 testGetEntriesOnPageTwo()
162 $this->client
->request('GET', '/api/entries', [
167 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
169 $content = json_decode($this->client
->getResponse()->getContent(), true);
171 $this->assertGreaterThanOrEqual(0, $content['total']);
172 $this->assertEquals(2, $content['page']);
173 $this->assertEquals(2, $content['limit']);
176 public function testGetStarredEntries()
178 $this->client
->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);
180 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
182 $content = json_decode($this->client
->getResponse()->getContent(), true);
184 $this->assertGreaterThanOrEqual(1, count($content));
185 $this->assertNotEmpty($content['_embedded']['items']);
186 $this->assertGreaterThanOrEqual(1, $content['total']);
187 $this->assertEquals(1, $content['page']);
188 $this->assertGreaterThanOrEqual(1, $content['pages']);
190 $this->assertArrayHasKey('_links', $content);
191 $this->assertArrayHasKey('self', $content['_links']);
192 $this->assertArrayHasKey('first', $content['_links']);
193 $this->assertArrayHasKey('last', $content['_links']);
195 foreach (['self', 'first', 'last'] as $link) {
196 $this->assertArrayHasKey('href', $content['_links'][$link]);
197 $this->assertContains('starred=1', $content['_links'][$link]['href']);
198 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
201 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
204 public function testGetArchiveEntries()
206 $this->client
->request('GET', '/api/entries', ['archive' => 1]);
208 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
210 $content = json_decode($this->client
->getResponse()->getContent(), true);
212 $this->assertGreaterThanOrEqual(1, count($content));
213 $this->assertNotEmpty($content['_embedded']['items']);
214 $this->assertGreaterThanOrEqual(1, $content['total']);
215 $this->assertEquals(1, $content['page']);
216 $this->assertGreaterThanOrEqual(1, $content['pages']);
218 $this->assertArrayHasKey('_links', $content);
219 $this->assertArrayHasKey('self', $content['_links']);
220 $this->assertArrayHasKey('first', $content['_links']);
221 $this->assertArrayHasKey('last', $content['_links']);
223 foreach (['self', 'first', 'last'] as $link) {
224 $this->assertArrayHasKey('href', $content['_links'][$link]);
225 $this->assertContains('archive=1', $content['_links'][$link]['href']);
228 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
231 public function testGetTaggedEntries()
233 $this->client
->request('GET', '/api/entries', ['tags' => 'foo,bar']);
235 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
237 $content = json_decode($this->client
->getResponse()->getContent(), true);
239 $this->assertGreaterThanOrEqual(1, count($content));
240 $this->assertNotEmpty($content['_embedded']['items']);
241 $this->assertGreaterThanOrEqual(1, $content['total']);
242 $this->assertEquals(1, $content['page']);
243 $this->assertGreaterThanOrEqual(1, $content['pages']);
245 $this->assertArrayHasKey('_links', $content);
246 $this->assertArrayHasKey('self', $content['_links']);
247 $this->assertArrayHasKey('first', $content['_links']);
248 $this->assertArrayHasKey('last', $content['_links']);
250 foreach (['self', 'first', 'last'] as $link) {
251 $this->assertArrayHasKey('href', $content['_links'][$link]);
252 $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']);
255 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
258 public function testGetDatedEntries()
260 $this->client
->request('GET', '/api/entries', ['since' => 1443274283]);
262 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
264 $content = json_decode($this->client
->getResponse()->getContent(), true);
266 $this->assertGreaterThanOrEqual(1, count($content));
267 $this->assertNotEmpty($content['_embedded']['items']);
268 $this->assertGreaterThanOrEqual(1, $content['total']);
269 $this->assertEquals(1, $content['page']);
270 $this->assertGreaterThanOrEqual(1, $content['pages']);
272 $this->assertArrayHasKey('_links', $content);
273 $this->assertArrayHasKey('self', $content['_links']);
274 $this->assertArrayHasKey('first', $content['_links']);
275 $this->assertArrayHasKey('last', $content['_links']);
277 foreach (['self', 'first', 'last'] as $link) {
278 $this->assertArrayHasKey('href', $content['_links'][$link]);
279 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
282 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
285 public function testGetDatedSupEntries()
287 $future = new \
DateTime(date('Y-m-d H:i:s'));
288 $this->client
->request('GET', '/api/entries', ['since' => $future->getTimestamp() +
1000]);
290 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
292 $content = json_decode($this->client
->getResponse()->getContent(), true);
294 $this->assertGreaterThanOrEqual(1, count($content));
295 $this->assertEmpty($content['_embedded']['items']);
296 $this->assertEquals(0, $content['total']);
297 $this->assertEquals(1, $content['page']);
298 $this->assertEquals(1, $content['pages']);
300 $this->assertArrayHasKey('_links', $content);
301 $this->assertArrayHasKey('self', $content['_links']);
302 $this->assertArrayHasKey('first', $content['_links']);
303 $this->assertArrayHasKey('last', $content['_links']);
305 foreach (['self', 'first', 'last'] as $link) {
306 $this->assertArrayHasKey('href', $content['_links'][$link]);
307 $this->assertContains('since='.($future->getTimestamp() +
1000), $content['_links'][$link]['href']);
310 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
313 public function testDeleteEntry()
315 $entry = $this->client
->getContainer()
316 ->get('doctrine.orm.entity_manager')
317 ->getRepository('WallabagCoreBundle:Entry')
318 ->findOneByUser(1, ['id' => 'asc']);
321 $this->markTestSkipped('No content found in db.');
324 $this->client
->request('DELETE', '/api/entries/'.$entry->getId().'.json');
326 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
328 $content = json_decode($this->client
->getResponse()->getContent(), true);
330 $this->assertEquals($entry->getTitle(), $content['title']);
331 $this->assertEquals($entry->getUrl(), $content['url']);
333 // We'll try to delete this entry again
334 $this->client
->request('DELETE', '/api/entries/'.$entry->getId().'.json');
336 $this->assertEquals(404, $this->client
->getResponse()->getStatusCode());
339 public function testPostEntry()
341 $this->client
->request('POST', '/api/entries.json', [
342 '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',
344 'title' => 'New title for my article',
347 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
349 $content = json_decode($this->client
->getResponse()->getContent(), true);
351 $this->assertGreaterThan(0, $content['id']);
352 $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']);
353 $this->assertEquals(false, $content['is_archived']);
354 $this->assertEquals(false, $content['is_starred']);
355 $this->assertEquals('New title for my article', $content['title']);
356 $this->assertEquals(1, $content['user_id']);
357 $this->assertCount(2, $content['tags']);
360 public function testPostSameEntry()
362 $this->client
->request('POST', '/api/entries.json', [
363 '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',
365 'tags' => 'google, apple',
368 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
370 $content = json_decode($this->client
->getResponse()->getContent(), true);
372 $this->assertGreaterThan(0, $content['id']);
373 $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']);
374 $this->assertEquals(true, $content['is_archived']);
375 $this->assertEquals(false, $content['is_starred']);
376 $this->assertCount(3, $content['tags']);
379 public function testPostEntryWhenFetchContentFails()
381 /** @var \Symfony\Component\DependencyInjection\Container $container */
382 $container = $this->client
->getContainer();
383 $contentProxy = $this->getMockBuilder(ContentProxy
::class)
384 ->disableOriginalConstructor()
385 ->setMethods(['updateEntry'])
387 $contentProxy->expects($this->any())
388 ->method('updateEntry')
389 ->willThrowException(new \
Exception('Test Fetch content fails'));
390 $container->set('wallabag_core.content_proxy', $contentProxy);
393 $this->client
->request('POST', '/api/entries.json', [
394 'url' => 'http://www.example.com/',
397 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
398 $content = json_decode($this->client
->getResponse()->getContent(), true);
399 $this->assertGreaterThan(0, $content['id']);
400 $this->assertEquals('http://www.example.com/', $content['url']);
402 // Remove the created entry to avoid side effects on other tests
403 if (isset($content['id'])) {
404 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
405 $entry = $em->getReference('WallabagCoreBundle:Entry', $content['id']);
412 public function testPostArchivedAndStarredEntry()
414 $this->client
->request('POST', '/api/entries.json', [
415 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
420 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
422 $content = json_decode($this->client
->getResponse()->getContent(), true);
424 $this->assertGreaterThan(0, $content['id']);
425 $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']);
426 $this->assertEquals(true, $content['is_archived']);
427 $this->assertEquals(true, $content['is_starred']);
428 $this->assertEquals(1, $content['user_id']);
431 public function testPostArchivedAndStarredEntryWithoutQuotes()
433 $this->client
->request('POST', '/api/entries.json', [
434 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
439 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
441 $content = json_decode($this->client
->getResponse()->getContent(), true);
443 $this->assertGreaterThan(0, $content['id']);
444 $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']);
445 $this->assertEquals(false, $content['is_archived']);
446 $this->assertEquals(true, $content['is_starred']);
449 public function testPatchEntry()
451 $entry = $this->client
->getContainer()
452 ->get('doctrine.orm.entity_manager')
453 ->getRepository('WallabagCoreBundle:Entry')
457 $this->markTestSkipped('No content found in db.');
460 // hydrate the tags relations
461 $nbTags = count($entry->getTags());
463 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
464 'title' => 'New awesome title',
465 'tags' => 'new tag '.uniqid(),
470 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
472 $content = json_decode($this->client
->getResponse()->getContent(), true);
474 $this->assertEquals($entry->getId(), $content['id']);
475 $this->assertEquals($entry->getUrl(), $content['url']);
476 $this->assertEquals('New awesome title', $content['title']);
477 $this->assertGreaterThan($nbTags, count($content['tags']));
478 $this->assertEquals(1, $content['user_id']);
481 public function testPatchEntryWithoutQuotes()
483 $entry = $this->client
->getContainer()
484 ->get('doctrine.orm.entity_manager')
485 ->getRepository('WallabagCoreBundle:Entry')
489 $this->markTestSkipped('No content found in db.');
492 // hydrate the tags relations
493 $nbTags = count($entry->getTags());
495 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
496 'title' => 'New awesome title',
497 'tags' => 'new tag '.uniqid(),
502 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
504 $content = json_decode($this->client
->getResponse()->getContent(), true);
506 $this->assertEquals($entry->getId(), $content['id']);
507 $this->assertEquals($entry->getUrl(), $content['url']);
508 $this->assertEquals('New awesome title', $content['title']);
509 $this->assertGreaterThan($nbTags, count($content['tags']));
512 public function testGetTagsEntry()
514 $entry = $this->client
->getContainer()
515 ->get('doctrine.orm.entity_manager')
516 ->getRepository('WallabagCoreBundle:Entry')
517 ->findOneWithTags($this->user
->getId());
522 $this->markTestSkipped('No content found in db.');
526 foreach ($entry->getTags() as $tag) {
527 $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()];
530 $this->client
->request('GET', '/api/entries/'.$entry->getId().'/tags');
532 $this->assertEquals(json_encode($tags, JSON_HEX_QUOT
), $this->client
->getResponse()->getContent());
535 public function testPostTagsOnEntry()
537 $entry = $this->client
->getContainer()
538 ->get('doctrine.orm.entity_manager')
539 ->getRepository('WallabagCoreBundle:Entry')
543 $this->markTestSkipped('No content found in db.');
546 $nbTags = count($entry->getTags());
548 $newTags = 'tag1,tag2,tag3';
550 $this->client
->request('POST', '/api/entries/'.$entry->getId().'/tags', ['tags' => $newTags]);
552 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
554 $content = json_decode($this->client
->getResponse()->getContent(), true);
556 $this->assertArrayHasKey('tags', $content);
557 $this->assertEquals($nbTags +
3, count($content['tags']));
559 $entryDB = $this->client
->getContainer()
560 ->get('doctrine.orm.entity_manager')
561 ->getRepository('WallabagCoreBundle:Entry')
562 ->find($entry->getId());
565 foreach ($entryDB->getTags()->toArray() as $tag) {
566 $tagsInDB[$tag->getId()] = $tag->getLabel();
569 foreach (explode(',', $newTags) as $tag) {
570 $this->assertContains($tag, $tagsInDB);
574 public function testDeleteOneTagEntry()
576 $entry = $this->client
->getContainer()
577 ->get('doctrine.orm.entity_manager')
578 ->getRepository('WallabagCoreBundle:Entry')
579 ->findOneWithTags($this->user
->getId());
583 $this->markTestSkipped('No content found in db.');
586 // hydrate the tags relations
587 $nbTags = count($entry->getTags());
588 $tag = $entry->getTags()[0];
590 $this->client
->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json');
592 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
594 $content = json_decode($this->client
->getResponse()->getContent(), true);
596 $this->assertArrayHasKey('tags', $content);
597 $this->assertEquals($nbTags - 1, count($content['tags']));
600 public function testSaveIsArchivedAfterPost()
602 $entry = $this->client
->getContainer()
603 ->get('doctrine.orm.entity_manager')
604 ->getRepository('WallabagCoreBundle:Entry')
605 ->findOneBy(['user' => 1, 'isArchived' => true]);
608 $this->markTestSkipped('No content found in db.');
611 $this->client
->request('POST', '/api/entries.json', [
612 'url' => $entry->getUrl(),
615 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
617 $content = json_decode($this->client
->getResponse()->getContent(), true);
619 $this->assertEquals(true, $content['is_archived']);
622 public function testSaveIsStarredAfterPost()
624 $entry = $this->client
->getContainer()
625 ->get('doctrine.orm.entity_manager')
626 ->getRepository('WallabagCoreBundle:Entry')
627 ->findOneBy(['user' => 1, 'isStarred' => true]);
630 $this->markTestSkipped('No content found in db.');
633 $this->client
->request('POST', '/api/entries.json', [
634 'url' => $entry->getUrl(),
637 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
639 $content = json_decode($this->client
->getResponse()->getContent(), true);
641 $this->assertEquals(true, $content['is_starred']);
644 public function testSaveIsArchivedAfterPatch()
646 $entry = $this->client
->getContainer()
647 ->get('doctrine.orm.entity_manager')
648 ->getRepository('WallabagCoreBundle:Entry')
649 ->findOneBy(['user' => 1, 'isArchived' => true]);
652 $this->markTestSkipped('No content found in db.');
655 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
656 'title' => $entry->getTitle().'++',
659 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
661 $content = json_decode($this->client
->getResponse()->getContent(), true);
663 $this->assertEquals(true, $content['is_archived']);
666 public function testSaveIsStarredAfterPatch()
668 $entry = $this->client
->getContainer()
669 ->get('doctrine.orm.entity_manager')
670 ->getRepository('WallabagCoreBundle:Entry')
671 ->findOneBy(['user' => 1, 'isStarred' => true]);
674 $this->markTestSkipped('No content found in db.');
676 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
677 'title' => $entry->getTitle().'++',
680 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
682 $content = json_decode($this->client
->getResponse()->getContent(), true);
684 $this->assertEquals(true, $content['is_starred']);
687 public function testGetEntriesExists()
689 $this->client
->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
691 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
693 $content = json_decode($this->client
->getResponse()->getContent(), true);
695 $this->assertEquals(2, $content['exists']);
698 public function testGetEntriesExistsWithManyUrls()
700 $url1 = 'http://0.0.0.0/entry2';
701 $url2 = 'http://0.0.0.0/entry10';
702 $this->client
->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2);
704 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
706 $content = json_decode($this->client
->getResponse()->getContent(), true);
708 $this->assertArrayHasKey($url1, $content);
709 $this->assertArrayHasKey($url2, $content);
710 $this->assertEquals(2, $content[$url1]);
711 $this->assertEquals(false, $content[$url2]);
714 public function testGetEntriesExistsWhichDoesNotExists()
716 $this->client
->request('GET', '/api/entries/exists?url=http://google.com/entry2');
718 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
720 $content = json_decode($this->client
->getResponse()->getContent(), true);
722 $this->assertEquals(false, $content['exists']);
725 public function testGetEntriesExistsWithNoUrl()
727 $this->client
->request('GET', '/api/entries/exists?url=');
729 $this->assertEquals(403, $this->client
->getResponse()->getStatusCode());
732 public function testReloadEntryErrorWhileFetching()
734 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
735 ->getRepository('WallabagCoreBundle:Entry')
736 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
739 $this->markTestSkipped('No content found in db.');
742 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json');
743 $this->assertEquals(304, $this->client
->getResponse()->getStatusCode());
746 public function testReloadEntry()
748 $this->client
->request('POST', '/api/entries.json', [
749 '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',
751 'tags' => 'google, apple',
754 $json = json_decode($this->client
->getResponse()->getContent(), true);
758 $this->client
->request('PATCH', '/api/entries/'.$json['id'].'/reload.json');
759 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
761 $content = json_decode($this->client
->getResponse()->getContent(), true);
763 $this->assertNotEmpty($content['title']);
765 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
768 public function testPostEntriesTagsListAction()
770 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
771 ->getRepository('WallabagCoreBundle:Entry')
772 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
774 $tags = $entry->getTags();
776 $this->assertCount(2, $tags);
780 'url' => 'http://0.0.0.0/entry4',
781 'tags' => 'new tag 1, new tag 2',
785 $this->client
->request('POST', '/api/entries/tags/lists?list='.json_encode($list));
787 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
789 $content = json_decode($this->client
->getResponse()->getContent(), true);
791 $this->assertInternalType('int', $content[0]['entry']);
792 $this->assertEquals('http://0.0.0.0/entry4', $content[0]['url']);
794 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
795 ->getRepository('WallabagCoreBundle:Entry')
796 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
798 $tags = $entry->getTags();
799 $this->assertCount(4, $tags);
802 public function testDeleteEntriesTagsListAction()
804 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
805 ->getRepository('WallabagCoreBundle:Entry')
806 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
808 $tags = $entry->getTags();
810 $this->assertCount(4, $tags);
814 'url' => 'http://0.0.0.0/entry4',
815 'tags' => 'new tag 1, new tag 2',
819 $this->client
->request('DELETE', '/api/entries/tags/list?list='.json_encode($list));
822 public function testPostEntriesListAction()
825 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html',
826 'http://0.0.0.0/entry2',
829 $this->client
->request('POST', '/api/entries/lists?urls='.json_encode($list));
831 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
833 $content = json_decode($this->client
->getResponse()->getContent(), true);
835 $this->assertInternalType('int', $content[0]['entry']);
836 $this->assertEquals('http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', $content[0]['url']);
838 $this->assertInternalType('int', $content[1]['entry']);
839 $this->assertEquals('http://0.0.0.0/entry2', $content[1]['url']);
842 public function testDeleteEntriesListAction()
845 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html',
846 'http://0.0.0.0/entry3',
849 $this->client
->request('DELETE', '/api/entries/list?urls='.json_encode($list));
851 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
853 $content = json_decode($this->client
->getResponse()->getContent(), true);
855 $this->assertTrue($content[0]['entry']);
856 $this->assertEquals('http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', $content[0]['url']);
858 $this->assertFalse($content[1]['entry']);
859 $this->assertEquals('http://0.0.0.0/entry3', $content[1]['url']);
862 public function testLimitBulkAction()
865 'http://0.0.0.0/entry1',
866 'http://0.0.0.0/entry1',
867 'http://0.0.0.0/entry1',
868 'http://0.0.0.0/entry1',
869 'http://0.0.0.0/entry1',
870 'http://0.0.0.0/entry1',
871 'http://0.0.0.0/entry1',
872 'http://0.0.0.0/entry1',
873 'http://0.0.0.0/entry1',
874 'http://0.0.0.0/entry1',
875 'http://0.0.0.0/entry1',
878 $this->client
->request('POST', '/api/entries/lists?urls='.json_encode($list));
880 $this->assertEquals(400, $this->client
->getResponse()->getStatusCode());
881 $this->assertContains('API limit reached', $this->client
->getResponse()->getContent());