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',
350 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
352 $content = json_decode($this->client
->getResponse()->getContent(), true);
354 $this->assertGreaterThan(0, $content['id']);
355 $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']);
356 $this->assertEquals(false, $content['is_archived']);
357 $this->assertEquals(false, $content['is_starred']);
358 $this->assertEquals('New title for my article', $content['title']);
359 $this->assertEquals(1, $content['user_id']);
360 $this->assertCount(2, $content['tags']);
361 $this->assertSame('my content', $content['content']);
362 $this->assertSame('de_DE', $content['language']);
363 $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']);
366 public function testPostSameEntry()
368 $this->client
->request('POST', '/api/entries.json', [
369 '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',
371 'tags' => 'google, apple',
374 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
376 $content = json_decode($this->client
->getResponse()->getContent(), true);
378 $this->assertGreaterThan(0, $content['id']);
379 $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']);
380 $this->assertEquals(true, $content['is_archived']);
381 $this->assertEquals(false, $content['is_starred']);
382 $this->assertCount(3, $content['tags']);
385 public function testPostEntryWhenFetchContentFails()
387 /** @var \Symfony\Component\DependencyInjection\Container $container */
388 $container = $this->client
->getContainer();
389 $contentProxy = $this->getMockBuilder(ContentProxy
::class)
390 ->disableOriginalConstructor()
391 ->setMethods(['updateEntry'])
393 $contentProxy->expects($this->any())
394 ->method('updateEntry')
395 ->willThrowException(new \
Exception('Test Fetch content fails'));
396 $container->set('wallabag_core.content_proxy', $contentProxy);
399 $this->client
->request('POST', '/api/entries.json', [
400 'url' => 'http://www.example.com/',
403 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
404 $content = json_decode($this->client
->getResponse()->getContent(), true);
405 $this->assertGreaterThan(0, $content['id']);
406 $this->assertEquals('http://www.example.com/', $content['url']);
408 // Remove the created entry to avoid side effects on other tests
409 if (isset($content['id'])) {
410 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
411 $entry = $em->getReference('WallabagCoreBundle:Entry', $content['id']);
418 public function testPostArchivedAndStarredEntry()
420 $this->client
->request('POST', '/api/entries.json', [
421 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
426 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
428 $content = json_decode($this->client
->getResponse()->getContent(), true);
430 $this->assertGreaterThan(0, $content['id']);
431 $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']);
432 $this->assertEquals(true, $content['is_archived']);
433 $this->assertEquals(true, $content['is_starred']);
434 $this->assertEquals(1, $content['user_id']);
437 public function testPostArchivedAndStarredEntryWithoutQuotes()
439 $this->client
->request('POST', '/api/entries.json', [
440 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
445 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
447 $content = json_decode($this->client
->getResponse()->getContent(), true);
449 $this->assertGreaterThan(0, $content['id']);
450 $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']);
451 $this->assertEquals(false, $content['is_archived']);
452 $this->assertEquals(true, $content['is_starred']);
455 public function testPatchEntry()
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']));
484 $this->assertEquals(1, $content['user_id']);
487 public function testPatchEntryWithoutQuotes()
489 $entry = $this->client
->getContainer()
490 ->get('doctrine.orm.entity_manager')
491 ->getRepository('WallabagCoreBundle:Entry')
495 $this->markTestSkipped('No content found in db.');
498 // hydrate the tags relations
499 $nbTags = count($entry->getTags());
501 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
502 'title' => 'New awesome title',
503 'tags' => 'new tag '.uniqid(),
508 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
510 $content = json_decode($this->client
->getResponse()->getContent(), true);
512 $this->assertEquals($entry->getId(), $content['id']);
513 $this->assertEquals($entry->getUrl(), $content['url']);
514 $this->assertEquals('New awesome title', $content['title']);
515 $this->assertGreaterThan($nbTags, count($content['tags']));
518 public function testGetTagsEntry()
520 $entry = $this->client
->getContainer()
521 ->get('doctrine.orm.entity_manager')
522 ->getRepository('WallabagCoreBundle:Entry')
523 ->findOneWithTags($this->user
->getId());
528 $this->markTestSkipped('No content found in db.');
532 foreach ($entry->getTags() as $tag) {
533 $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()];
536 $this->client
->request('GET', '/api/entries/'.$entry->getId().'/tags');
538 $this->assertEquals(json_encode($tags, JSON_HEX_QUOT
), $this->client
->getResponse()->getContent());
541 public function testPostTagsOnEntry()
543 $entry = $this->client
->getContainer()
544 ->get('doctrine.orm.entity_manager')
545 ->getRepository('WallabagCoreBundle:Entry')
549 $this->markTestSkipped('No content found in db.');
552 $nbTags = count($entry->getTags());
554 $newTags = 'tag1,tag2,tag3';
556 $this->client
->request('POST', '/api/entries/'.$entry->getId().'/tags', ['tags' => $newTags]);
558 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
560 $content = json_decode($this->client
->getResponse()->getContent(), true);
562 $this->assertArrayHasKey('tags', $content);
563 $this->assertEquals($nbTags +
3, count($content['tags']));
565 $entryDB = $this->client
->getContainer()
566 ->get('doctrine.orm.entity_manager')
567 ->getRepository('WallabagCoreBundle:Entry')
568 ->find($entry->getId());
571 foreach ($entryDB->getTags()->toArray() as $tag) {
572 $tagsInDB[$tag->getId()] = $tag->getLabel();
575 foreach (explode(',', $newTags) as $tag) {
576 $this->assertContains($tag, $tagsInDB);
580 public function testDeleteOneTagEntry()
582 $entry = $this->client
->getContainer()
583 ->get('doctrine.orm.entity_manager')
584 ->getRepository('WallabagCoreBundle:Entry')
585 ->findOneWithTags($this->user
->getId());
589 $this->markTestSkipped('No content found in db.');
592 // hydrate the tags relations
593 $nbTags = count($entry->getTags());
594 $tag = $entry->getTags()[0];
596 $this->client
->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json');
598 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
600 $content = json_decode($this->client
->getResponse()->getContent(), true);
602 $this->assertArrayHasKey('tags', $content);
603 $this->assertEquals($nbTags - 1, count($content['tags']));
606 public function testSaveIsArchivedAfterPost()
608 $entry = $this->client
->getContainer()
609 ->get('doctrine.orm.entity_manager')
610 ->getRepository('WallabagCoreBundle:Entry')
611 ->findOneBy(['user' => 1, 'isArchived' => 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_archived']);
628 public function testSaveIsStarredAfterPost()
630 $entry = $this->client
->getContainer()
631 ->get('doctrine.orm.entity_manager')
632 ->getRepository('WallabagCoreBundle:Entry')
633 ->findOneBy(['user' => 1, 'isStarred' => true]);
636 $this->markTestSkipped('No content found in db.');
639 $this->client
->request('POST', '/api/entries.json', [
640 'url' => $entry->getUrl(),
643 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
645 $content = json_decode($this->client
->getResponse()->getContent(), true);
647 $this->assertEquals(true, $content['is_starred']);
650 public function testSaveIsArchivedAfterPatch()
652 $entry = $this->client
->getContainer()
653 ->get('doctrine.orm.entity_manager')
654 ->getRepository('WallabagCoreBundle:Entry')
655 ->findOneBy(['user' => 1, 'isArchived' => true]);
658 $this->markTestSkipped('No content found in db.');
661 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
662 'title' => $entry->getTitle().'++',
665 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
667 $content = json_decode($this->client
->getResponse()->getContent(), true);
669 $this->assertEquals(true, $content['is_archived']);
672 public function testSaveIsStarredAfterPatch()
674 $entry = $this->client
->getContainer()
675 ->get('doctrine.orm.entity_manager')
676 ->getRepository('WallabagCoreBundle:Entry')
677 ->findOneBy(['user' => 1, 'isStarred' => true]);
680 $this->markTestSkipped('No content found in db.');
682 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
683 'title' => $entry->getTitle().'++',
686 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
688 $content = json_decode($this->client
->getResponse()->getContent(), true);
690 $this->assertEquals(true, $content['is_starred']);
693 public function testGetEntriesExists()
695 $this->client
->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
697 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
699 $content = json_decode($this->client
->getResponse()->getContent(), true);
701 $this->assertEquals(2, $content['exists']);
704 public function testGetEntriesExistsWithManyUrls()
706 $url1 = 'http://0.0.0.0/entry2';
707 $url2 = 'http://0.0.0.0/entry10';
708 $this->client
->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2);
710 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
712 $content = json_decode($this->client
->getResponse()->getContent(), true);
714 $this->assertArrayHasKey($url1, $content);
715 $this->assertArrayHasKey($url2, $content);
716 $this->assertEquals(2, $content[$url1]);
717 $this->assertEquals(false, $content[$url2]);
720 public function testGetEntriesExistsWhichDoesNotExists()
722 $this->client
->request('GET', '/api/entries/exists?url=http://google.com/entry2');
724 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
726 $content = json_decode($this->client
->getResponse()->getContent(), true);
728 $this->assertEquals(false, $content['exists']);
731 public function testGetEntriesExistsWithNoUrl()
733 $this->client
->request('GET', '/api/entries/exists?url=');
735 $this->assertEquals(403, $this->client
->getResponse()->getStatusCode());
738 public function testReloadEntryErrorWhileFetching()
740 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
741 ->getRepository('WallabagCoreBundle:Entry')
742 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
745 $this->markTestSkipped('No content found in db.');
748 $this->client
->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json');
749 $this->assertEquals(304, $this->client
->getResponse()->getStatusCode());
752 public function testReloadEntry()
754 $this->client
->request('POST', '/api/entries.json', [
755 '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',
757 'tags' => 'google, apple',
760 $json = json_decode($this->client
->getResponse()->getContent(), true);
764 $this->client
->request('PATCH', '/api/entries/'.$json['id'].'/reload.json');
765 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
767 $content = json_decode($this->client
->getResponse()->getContent(), true);
769 $this->assertNotEmpty($content['title']);
771 $this->assertEquals('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
774 public function testPostEntriesTagsListAction()
776 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
777 ->getRepository('WallabagCoreBundle:Entry')
778 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
780 $tags = $entry->getTags();
782 $this->assertCount(2, $tags);
786 'url' => 'http://0.0.0.0/entry4',
787 'tags' => 'new tag 1, new tag 2',
791 $this->client
->request('POST', '/api/entries/tags/lists?list='.json_encode($list));
793 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
795 $content = json_decode($this->client
->getResponse()->getContent(), true);
797 $this->assertInternalType('int', $content[0]['entry']);
798 $this->assertEquals('http://0.0.0.0/entry4', $content[0]['url']);
800 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
801 ->getRepository('WallabagCoreBundle:Entry')
802 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
804 $tags = $entry->getTags();
805 $this->assertCount(4, $tags);
808 public function testDeleteEntriesTagsListAction()
810 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
811 ->getRepository('WallabagCoreBundle:Entry')
812 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
814 $tags = $entry->getTags();
816 $this->assertCount(4, $tags);
820 'url' => 'http://0.0.0.0/entry4',
821 'tags' => 'new tag 1, new tag 2',
825 $this->client
->request('DELETE', '/api/entries/tags/list?list='.json_encode($list));
828 public function testPostEntriesListAction()
831 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html',
832 'http://0.0.0.0/entry2',
835 $this->client
->request('POST', '/api/entries/lists?urls='.json_encode($list));
837 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
839 $content = json_decode($this->client
->getResponse()->getContent(), true);
841 $this->assertInternalType('int', $content[0]['entry']);
842 $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']);
844 $this->assertInternalType('int', $content[1]['entry']);
845 $this->assertEquals('http://0.0.0.0/entry2', $content[1]['url']);
848 public function testDeleteEntriesListAction()
851 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html',
852 'http://0.0.0.0/entry3',
855 $this->client
->request('DELETE', '/api/entries/list?urls='.json_encode($list));
857 $this->assertEquals(200, $this->client
->getResponse()->getStatusCode());
859 $content = json_decode($this->client
->getResponse()->getContent(), true);
861 $this->assertTrue($content[0]['entry']);
862 $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']);
864 $this->assertFalse($content[1]['entry']);
865 $this->assertEquals('http://0.0.0.0/entry3', $content[1]['url']);
868 public function testLimitBulkAction()
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',
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',
884 $this->client
->request('POST', '/api/entries/lists?urls='.json_encode($list));
886 $this->assertEquals(400, $this->client
->getResponse()->getStatusCode());
887 $this->assertContains('API limit reached', $this->client
->getResponse()->getContent());