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',
345 'content' => 'my content',
346 'language' => 'de_DE',
347 'published_at' => '2016-09-08T11:55:58+0200',
348 'authors' => 'bob,helen',
351 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
353 $content = json_decode($this->client
->getResponse()->getContent(), true);
355 $this->assertGreaterThan(0, $content['id']);
356 $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']);
357 $this->assertEquals(false, $content['is_archived']);
358 $this->assertEquals(false, $content['is_starred']);
359 $this->assertEquals('New title for my article', $content['title']);
360 $this->assertEquals(1, $content['user_id']);
361 $this->assertCount(2, $content['tags']);
362 $this->assertSame('my content', $content['content']);
363 $this->assertSame('de_DE', $content['language']);
364 $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']);
365 $this->assertCount(2, $content['published_by']);
366 $this->assertContains('bob', $content['published_by']);
367 $this->assertContains('helen', $content['published_by']);
370 public function testPostSameEntry()
372 $this->client
->request('POST', '/api/entries.json', [
373 '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',
375 'tags' => 'google, apple',
378 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
380 $content = json_decode($this->client
->getResponse()->getContent(), true);
382 $this->assertGreaterThan(0, $content['id']);
383 $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']);
384 $this->assertEquals(true, $content['is_archived']);
385 $this->assertEquals(false, $content['is_starred']);
386 $this->assertCount(3, $content['tags']);
389 public function testPostEntryWhenFetchContentFails()
391 /** @var \Symfony\Component\DependencyInjection\Container $container */
392 $container = $this->client
->getContainer();
393 $contentProxy = $this->getMockBuilder(ContentProxy
::class)
394 ->disableOriginalConstructor()
395 ->setMethods(['updateEntry'])
397 $contentProxy->expects($this->any())
398 ->method('updateEntry')
399 ->willThrowException(new \
Exception('Test Fetch content fails'));
400 $container->set('wallabag_core.content_proxy', $contentProxy);
403 $this->client
->request('POST', '/api/entries.json', [
404 'url' => 'http://www.example.com/',
407 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
408 $content = json_decode($this->client
->getResponse()->getContent(), true);
409 $this->assertGreaterThan(0, $content['id']);
410 $this->assertEquals('http://www.example.com/', $content['url']);
412 // Remove the created entry to avoid side effects on other tests
413 if (isset($content['id'])) {
414 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
415 $entry = $em->getReference('WallabagCoreBundle:Entry', $content['id']);
422 public function testPostArchivedAndStarredEntry()
424 $this->client
->request('POST', '/api/entries.json', [
425 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
430 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
432 $content = json_decode($this->client
->getResponse()->getContent(), true);
434 $this->assertGreaterThan(0, $content['id']);
435 $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']);
436 $this->assertEquals(true, $content['is_archived']);
437 $this->assertEquals(true, $content['is_starred']);
438 $this->assertEquals(1, $content['user_id']);
441 public function testPostArchivedAndStarredEntryWithoutQuotes()
443 $this->client
->request('POST', '/api/entries.json', [
444 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
449 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
451 $content = json_decode($this->client
->getResponse()->getContent(), true);
453 $this->assertGreaterThan(0, $content['id']);
454 $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']);
455 $this->assertEquals(false, $content['is_archived']);
456 $this->assertEquals(true, $content['is_starred']);
459 public function testPatchEntry()
461 $entry = $this->client
->getContainer()
462 ->get('doctrine.orm.entity_manager')
463 ->getRepository('WallabagCoreBundle:Entry')
467 $this->markTestSkipped('No content found in db.');
470 // hydrate the tags relations
471 $nbTags = count($entry->getTags());
473 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
474 'title' => 'New awesome title',
475 'tags' => 'new tag '.uniqid(),
480 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
482 $content = json_decode($this->client
->getResponse()->getContent(), true);
484 $this->assertEquals($entry->getId(), $content['id']);
485 $this->assertEquals($entry->getUrl(), $content['url']);
486 $this->assertEquals('New awesome title', $content['title']);
487 $this->assertGreaterThan($nbTags, count($content['tags']));
488 $this->assertEquals(1, $content['user_id']);
491 public function testPatchEntryWithoutQuotes()
493 $entry = $this->client
->getContainer()
494 ->get('doctrine.orm.entity_manager')
495 ->getRepository('WallabagCoreBundle:Entry')
499 $this->markTestSkipped('No content found in db.');
502 // hydrate the tags relations
503 $nbTags = count($entry->getTags());
505 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
506 'title' => 'New awesome title',
507 'tags' => 'new tag '.uniqid(),
512 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
514 $content = json_decode($this->client
->getResponse()->getContent(), true);
516 $this->assertEquals($entry->getId(), $content['id']);
517 $this->assertEquals($entry->getUrl(), $content['url']);
518 $this->assertEquals('New awesome title', $content['title']);
519 $this->assertGreaterThan($nbTags, count($content['tags']));
522 public function testGetTagsEntry()
524 $entry = $this->client
->getContainer()
525 ->get('doctrine.orm.entity_manager')
526 ->getRepository('WallabagCoreBundle:Entry')
527 ->findOneWithTags($this->user
->getId());
532 $this->markTestSkipped('No content found in db.');
536 foreach ($entry->getTags() as $tag) {
537 $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()];
540 $this->client
->request('GET', '/api/entries/'.$entry->getId().'/tags');
542 $this->assertEquals(json_encode($tags, JSON_HEX_QUOT
), $this->client
->getResponse()->getContent());
545 public function testPostTagsOnEntry()
547 $entry = $this->client
->getContainer()
548 ->get('doctrine.orm.entity_manager')
549 ->getRepository('WallabagCoreBundle:Entry')
553 $this->markTestSkipped('No content found in db.');
556 $nbTags = count($entry->getTags());
558 $newTags = 'tag1,tag2,tag3';
560 $this->client
->request('POST', '/api/entries/'.$entry->getId().'/tags', ['tags' => $newTags]);
562 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
564 $content = json_decode($this->client
->getResponse()->getContent(), true);
566 $this->assertArrayHasKey('tags', $content);
567 $this->assertEquals($nbTags +
3, count($content['tags']));
569 $entryDB = $this->client
->getContainer()
570 ->get('doctrine.orm.entity_manager')
571 ->getRepository('WallabagCoreBundle:Entry')
572 ->find($entry->getId());
575 foreach ($entryDB->getTags()->toArray() as $tag) {
576 $tagsInDB[$tag->getId()] = $tag->getLabel();
579 foreach (explode(',', $newTags) as $tag) {
580 $this->assertContains($tag, $tagsInDB);
584 public function testDeleteOneTagEntry()
586 $entry = $this->client
->getContainer()
587 ->get('doctrine.orm.entity_manager')
588 ->getRepository('WallabagCoreBundle:Entry')
589 ->findOneWithTags($this->user
->getId());
593 $this->markTestSkipped('No content found in db.');
596 // hydrate the tags relations
597 $nbTags = count($entry->getTags());
598 $tag = $entry->getTags()[0];
600 $this->client
->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json');
602 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
604 $content = json_decode($this->client
->getResponse()->getContent(), true);
606 $this->assertArrayHasKey('tags', $content);
607 $this->assertEquals($nbTags - 1, count($content['tags']));
610 public function testSaveIsArchivedAfterPost()
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('POST', '/api/entries.json', [
622 'url' => $entry->getUrl(),
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 testSaveIsStarredAfterPost()
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.');
643 $this->client
->request('POST', '/api/entries.json', [
644 'url' => $entry->getUrl(),
647 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
649 $content = json_decode($this->client
->getResponse()->getContent(), true);
651 $this->assertEquals(true, $content['is_starred']);
654 public function testSaveIsArchivedAfterPatch()
656 $entry = $this->client
->getContainer()
657 ->get('doctrine.orm.entity_manager')
658 ->getRepository('WallabagCoreBundle:Entry')
659 ->findOneBy(['user' => 1, 'isArchived' => true]);
662 $this->markTestSkipped('No content found in db.');
665 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
666 'title' => $entry->getTitle().'++',
669 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
671 $content = json_decode($this->client
->getResponse()->getContent(), true);
673 $this->assertEquals(true, $content['is_archived']);
676 public function testSaveIsStarredAfterPatch()
678 $entry = $this->client
->getContainer()
679 ->get('doctrine.orm.entity_manager')
680 ->getRepository('WallabagCoreBundle:Entry')
681 ->findOneBy(['user' => 1, 'isStarred' => true]);
684 $this->markTestSkipped('No content found in db.');
686 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
687 'title' => $entry->getTitle().'++',
690 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
692 $content = json_decode($this->client
->getResponse()->getContent(), true);
694 $this->assertEquals(true, $content['is_starred']);
697 public function testGetEntriesExists()
699 $this->client
->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
701 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
703 $content = json_decode($this->client
->getResponse()->getContent(), true);
705 $this->assertEquals(2, $content['exists']);
708 public function testGetEntriesExistsWithManyUrls()
710 $url1 = 'http://0.0.0.0/entry2';
711 $url2 = 'http://0.0.0.0/entry10';
712 $this->client
->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2);
714 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
716 $content = json_decode($this->client
->getResponse()->getContent(), true);
718 $this->assertArrayHasKey($url1, $content);
719 $this->assertArrayHasKey($url2, $content);
720 $this->assertEquals(2, $content[$url1]);
721 $this->assertEquals(false, $content[$url2]);
724 public function testGetEntriesExistsWhichDoesNotExists()
726 $this->client
->request('GET', '/api/entries/exists?url=http://google.com/entry2');
728 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
730 $content = json_decode($this->client
->getResponse()->getContent(), true);
732 $this->assertEquals(false, $content['exists']);
735 public function testGetEntriesExistsWithNoUrl()
737 $this->client
->request('GET', '/api/entries/exists?url=');
739 $this->assertEquals(403, $this->client
->getResponse()->getStatusCode());
742 public function testReloadEntryErrorWhileFetching()
744 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
745 ->getRepository('WallabagCoreBundle:Entry')
746 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
749 $this->markTestSkipped('No content found in db.');
752 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json');
753 $this->assertEquals(304, $this->client
->getResponse()->getStatusCode());
756 public function testReloadEntry()
758 $this->client
->request('POST', '/api/entries.json', [
759 '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',
761 'tags' => 'google, apple',
764 $json = json_decode($this->client
->getResponse()->getContent(), true);
768 $this->client
->request('PATCH', '/api/entries/'.$json['id'].'/reload.json');
769 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
771 $content = json_decode($this->client
->getResponse()->getContent(), true);
773 $this->assertNotEmpty($content['title']);
775 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
778 public function testPostEntriesTagsListAction()
780 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
781 ->getRepository('WallabagCoreBundle:Entry')
782 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
784 $tags = $entry->getTags();
786 $this->assertCount(2, $tags);
790 'url' => 'http://0.0.0.0/entry4',
791 'tags' => 'new tag 1, new tag 2',
795 $this->client
->request('POST', '/api/entries/tags/lists?list='.json_encode($list));
797 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
799 $content = json_decode($this->client
->getResponse()->getContent(), true);
801 $this->assertInternalType('int', $content[0]['entry']);
802 $this->assertEquals('http://0.0.0.0/entry4', $content[0]['url']);
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();
809 $this->assertCount(4, $tags);
812 public function testDeleteEntriesTagsListAction()
814 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
815 ->getRepository('WallabagCoreBundle:Entry')
816 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
818 $tags = $entry->getTags();
820 $this->assertCount(4, $tags);
824 'url' => 'http://0.0.0.0/entry4',
825 'tags' => 'new tag 1, new tag 2',
829 $this->client
->request('DELETE', '/api/entries/tags/list?list='.json_encode($list));
832 public function testPostEntriesListAction()
835 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html',
836 'http://0.0.0.0/entry2',
839 $this->client
->request('POST', '/api/entries/lists?urls='.json_encode($list));
841 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
843 $content = json_decode($this->client
->getResponse()->getContent(), true);
845 $this->assertInternalType('int', $content[0]['entry']);
846 $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']);
848 $this->assertInternalType('int', $content[1]['entry']);
849 $this->assertEquals('http://0.0.0.0/entry2', $content[1]['url']);
852 public function testDeleteEntriesListAction()
855 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html',
856 'http://0.0.0.0/entry3',
859 $this->client
->request('DELETE', '/api/entries/list?urls='.json_encode($list));
861 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
863 $content = json_decode($this->client
->getResponse()->getContent(), true);
865 $this->assertTrue($content[0]['entry']);
866 $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']);
868 $this->assertFalse($content[1]['entry']);
869 $this->assertEquals('http://0.0.0.0/entry3', $content[1]['url']);
872 public function testLimitBulkAction()
875 'http://0.0.0.0/entry1',
876 'http://0.0.0.0/entry1',
877 'http://0.0.0.0/entry1',
878 'http://0.0.0.0/entry1',
879 'http://0.0.0.0/entry1',
880 'http://0.0.0.0/entry1',
881 'http://0.0.0.0/entry1',
882 'http://0.0.0.0/entry1',
883 'http://0.0.0.0/entry1',
884 'http://0.0.0.0/entry1',
885 'http://0.0.0.0/entry1',
888 $this->client
->request('POST', '/api/entries/lists?urls='.json_encode($list));
890 $this->assertEquals(400, $this->client
->getResponse()->getStatusCode());
891 $this->assertContains('API limit reached', $this->client
->getResponse()->getContent());