3 namespace Tests\Wallabag\ApiBundle\Controller
;
5 use Tests\Wallabag\ApiBundle\WallabagApiTestCase
;
6 use Wallabag\CoreBundle\Entity\Entry
;
7 use Wallabag\CoreBundle\Entity\Tag
;
8 use Wallabag\CoreBundle\Helper\ContentProxy
;
9 use Wallabag\UserBundle\Entity\User
;
11 class EntryRestControllerTest
extends WallabagApiTestCase
13 public function testGetOneEntry()
15 $entry = $this->client
->getContainer()
16 ->get('doctrine.orm.entity_manager')
17 ->getRepository('WallabagCoreBundle:Entry')
18 ->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]);
21 $this->markTestSkipped('No content found in db.');
24 $this->client
->request('GET', '/api/entries/' . $entry->getId() . '.json');
25 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
27 $content = json_decode($this->client
->getResponse()->getContent(), true);
29 $this->assertSame($entry->getTitle(), $content['title']);
30 $this->assertSame($entry->getUrl(), $content['url']);
31 $this->assertCount(\
count($entry->getTags()), $content['tags']);
32 $this->assertSame($entry->getUserName(), $content['user_name']);
33 $this->assertSame($entry->getUserEmail(), $content['user_email']);
34 $this->assertSame($entry->getUserId(), $content['user_id']);
36 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
39 public function testGetOneEntryWithOriginUrl()
41 $entry = $this->client
->getContainer()
42 ->get('doctrine.orm.entity_manager')
43 ->getRepository('WallabagCoreBundle:Entry')
44 ->findOneBy(['user' => $this->getUserId(), 'url' => 'http://0.0.0.0/entry2']);
47 $this->markTestSkipped('No content found in db.');
50 $this->client
->request('GET', '/api/entries/' . $entry->getId() . '.json');
51 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
53 $content = json_decode($this->client
->getResponse()->getContent(), true);
55 $this->assertSame($entry->getOriginUrl(), $content['origin_url']);
58 public function testExportEntry()
60 $entry = $this->client
->getContainer()
61 ->get('doctrine.orm.entity_manager')
62 ->getRepository('WallabagCoreBundle:Entry')
63 ->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]);
66 $this->markTestSkipped('No content found in db.');
69 $this->client
->request('GET', '/api/entries/' . $entry->getId() . '/export.epub');
70 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
72 // epub format got the content type in the content
73 $this->assertContains('application/epub', $this->client
->getResponse()->getContent());
74 $this->assertSame('application/epub+zip', $this->client
->getResponse()->headers
->get('Content-Type'));
76 // re-auth client for mobi
77 $client = $this->createAuthorizedClient();
78 $client->request('GET', '/api/entries/' . $entry->getId() . '/export.mobi');
79 $this->assertSame(200, $client->getResponse()->getStatusCode());
81 $this->assertSame('application/x-mobipocket-ebook', $client->getResponse()->headers
->get('Content-Type'));
83 // re-auth client for pdf
84 $client = $this->createAuthorizedClient();
85 $client->request('GET', '/api/entries/' . $entry->getId() . '/export.pdf');
86 $this->assertSame(200, $client->getResponse()->getStatusCode());
88 $this->assertContains('PDF-', $client->getResponse()->getContent());
89 $this->assertSame('application/pdf', $client->getResponse()->headers
->get('Content-Type'));
91 // re-auth client for pdf
92 $client = $this->createAuthorizedClient();
93 $client->request('GET', '/api/entries/' . $entry->getId() . '/export.txt');
94 $this->assertSame(200, $client->getResponse()->getStatusCode());
96 $this->assertContains('text/plain', $client->getResponse()->headers
->get('Content-Type'));
98 // re-auth client for pdf
99 $client = $this->createAuthorizedClient();
100 $client->request('GET', '/api/entries/' . $entry->getId() . '/export.csv');
101 $this->assertSame(200, $client->getResponse()->getStatusCode());
103 $this->assertContains('application/csv', $client->getResponse()->headers
->get('Content-Type'));
106 public function testGetOneEntryWrongUser()
108 $entry = $this->client
->getContainer()
109 ->get('doctrine.orm.entity_manager')
110 ->getRepository('WallabagCoreBundle:Entry')
111 ->findOneBy(['user' => $this->getUserId('bob'), 'isArchived' => false]);
114 $this->markTestSkipped('No content found in db.');
117 $this->client
->request('GET', '/api/entries/' . $entry->getId() . '.json');
119 $this->assertSame(403, $this->client
->getResponse()->getStatusCode());
122 public function testGetEntries()
124 $this->client
->request('GET', '/api/entries');
126 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
128 $content = json_decode($this->client
->getResponse()->getContent(), true);
130 $this->assertGreaterThanOrEqual(1, \
count($content));
131 $this->assertNotEmpty($content['_embedded']['items']);
132 $this->assertGreaterThanOrEqual(1, $content['total']);
133 $this->assertSame(1, $content['page']);
134 $this->assertGreaterThanOrEqual(1, $content['pages']);
136 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
139 public function testGetEntriesWithFullOptions()
141 $this->client
->request('GET', '/api/entries', [
149 'since' => 1443274283,
153 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
155 $content = json_decode($this->client
->getResponse()->getContent(), true);
157 $this->assertGreaterThanOrEqual(1, \
count($content));
158 $this->assertArrayHasKey('items', $content['_embedded']);
159 $this->assertGreaterThanOrEqual(0, $content['total']);
160 $this->assertSame(1, $content['page']);
161 $this->assertSame(2, $content['limit']);
162 $this->assertGreaterThanOrEqual(1, $content['pages']);
164 $this->assertArrayHasKey('_links', $content);
165 $this->assertArrayHasKey('self', $content['_links']);
166 $this->assertArrayHasKey('first', $content['_links']);
167 $this->assertArrayHasKey('last', $content['_links']);
169 foreach (['self', 'first', 'last'] as $link) {
170 $this->assertArrayHasKey('href', $content['_links'][$link]);
171 $this->assertContains('archive=1', $content['_links'][$link]['href']);
172 $this->assertContains('starred=1', $content['_links'][$link]['href']);
173 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
174 $this->assertContains('order=asc', $content['_links'][$link]['href']);
175 $this->assertContains('tags=foo', $content['_links'][$link]['href']);
176 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
177 $this->assertContains('public=0', $content['_links'][$link]['href']);
180 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
183 public function testGetEntriesPublicOnly()
185 $entry = $this->client
->getContainer()
186 ->get('doctrine.orm.entity_manager')
187 ->getRepository('WallabagCoreBundle:Entry')
188 ->findOneByUser($this->getUserId());
191 $this->markTestSkipped('No content found in db.');
194 // generate at least one public entry
195 $entry->generateUid();
197 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
198 $em->persist($entry);
201 $this->client
->request('GET', '/api/entries', [
205 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
207 $content = json_decode($this->client
->getResponse()->getContent(), true);
209 $this->assertGreaterThanOrEqual(1, \
count($content));
210 $this->assertArrayHasKey('items', $content['_embedded']);
211 $this->assertGreaterThanOrEqual(1, $content['total']);
212 $this->assertSame(1, $content['page']);
213 $this->assertSame(30, $content['limit']);
214 $this->assertGreaterThanOrEqual(1, $content['pages']);
216 $this->assertArrayHasKey('_links', $content);
217 $this->assertArrayHasKey('self', $content['_links']);
218 $this->assertArrayHasKey('first', $content['_links']);
219 $this->assertArrayHasKey('last', $content['_links']);
221 foreach (['self', 'first', 'last'] as $link) {
222 $this->assertArrayHasKey('href', $content['_links'][$link]);
223 $this->assertContains('public=1', $content['_links'][$link]['href']);
226 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
229 public function testGetEntriesOnPageTwo()
231 $this->client
->request('GET', '/api/entries', [
236 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
238 $content = json_decode($this->client
->getResponse()->getContent(), true);
240 $this->assertGreaterThanOrEqual(0, $content['total']);
241 $this->assertSame(2, $content['page']);
242 $this->assertSame(2, $content['limit']);
245 public function testGetStarredEntriesWithBadSort()
247 $this->client
->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated', 'order' => 'unknown']);
249 $this->assertSame(400, $this->client
->getResponse()->getStatusCode());
251 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
254 public function testGetStarredEntries()
256 $this->client
->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);
258 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
260 $content = json_decode($this->client
->getResponse()->getContent(), true);
262 $this->assertGreaterThanOrEqual(1, \
count($content));
263 $this->assertNotEmpty($content['_embedded']['items']);
264 $this->assertGreaterThanOrEqual(1, $content['total']);
265 $this->assertSame(1, $content['page']);
266 $this->assertGreaterThanOrEqual(1, $content['pages']);
268 $this->assertArrayHasKey('_links', $content);
269 $this->assertArrayHasKey('self', $content['_links']);
270 $this->assertArrayHasKey('first', $content['_links']);
271 $this->assertArrayHasKey('last', $content['_links']);
273 foreach (['self', 'first', 'last'] as $link) {
274 $this->assertArrayHasKey('href', $content['_links'][$link]);
275 $this->assertContains('starred=1', $content['_links'][$link]['href']);
276 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
279 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
282 public function testGetArchiveEntries()
284 $this->client
->request('GET', '/api/entries', ['archive' => 1]);
286 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
288 $content = json_decode($this->client
->getResponse()->getContent(), true);
290 $this->assertGreaterThanOrEqual(1, \
count($content));
291 $this->assertNotEmpty($content['_embedded']['items']);
292 $this->assertGreaterThanOrEqual(1, $content['total']);
293 $this->assertSame(1, $content['page']);
294 $this->assertGreaterThanOrEqual(1, $content['pages']);
296 $this->assertArrayHasKey('_links', $content);
297 $this->assertArrayHasKey('self', $content['_links']);
298 $this->assertArrayHasKey('first', $content['_links']);
299 $this->assertArrayHasKey('last', $content['_links']);
301 foreach (['self', 'first', 'last'] as $link) {
302 $this->assertArrayHasKey('href', $content['_links'][$link]);
303 $this->assertContains('archive=1', $content['_links'][$link]['href']);
306 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
309 public function testGetTaggedEntries()
311 $this->client
->request('GET', '/api/entries', ['tags' => 'foo,bar']);
313 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
315 $content = json_decode($this->client
->getResponse()->getContent(), true);
317 $this->assertGreaterThanOrEqual(1, \
count($content));
318 $this->assertNotEmpty($content['_embedded']['items']);
319 $this->assertGreaterThanOrEqual(1, $content['total']);
320 $this->assertSame(1, $content['page']);
321 $this->assertGreaterThanOrEqual(1, $content['pages']);
323 $this->assertContains('foo', array_column($content['_embedded']['items'][0]['tags'], 'label'), 'Entries tags should have "foo" tag');
324 $this->assertContains('bar', array_column($content['_embedded']['items'][0]['tags'], 'label'), 'Entries tags should have "bar" tag');
326 $this->assertArrayHasKey('_links', $content);
327 $this->assertArrayHasKey('self', $content['_links']);
328 $this->assertArrayHasKey('first', $content['_links']);
329 $this->assertArrayHasKey('last', $content['_links']);
331 foreach (['self', 'first', 'last'] as $link) {
332 $this->assertArrayHasKey('href', $content['_links'][$link]);
333 $this->assertContains('tags=' . urlencode('foo,bar'), $content['_links'][$link]['href']);
336 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
339 public function testGetTaggedEntriesWithBadParams()
341 $this->client
->request('GET', '/api/entries', ['tags' => ['foo', 'bar']]);
343 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
346 public function testGetDatedEntries()
348 $this->client
->request('GET', '/api/entries', ['since' => 1443274283]);
350 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
352 $content = json_decode($this->client
->getResponse()->getContent(), true);
354 $this->assertGreaterThanOrEqual(1, \
count($content));
355 $this->assertNotEmpty($content['_embedded']['items']);
356 $this->assertGreaterThanOrEqual(1, $content['total']);
357 $this->assertSame(1, $content['page']);
358 $this->assertGreaterThanOrEqual(1, $content['pages']);
360 $this->assertArrayHasKey('_links', $content);
361 $this->assertArrayHasKey('self', $content['_links']);
362 $this->assertArrayHasKey('first', $content['_links']);
363 $this->assertArrayHasKey('last', $content['_links']);
365 foreach (['self', 'first', 'last'] as $link) {
366 $this->assertArrayHasKey('href', $content['_links'][$link]);
367 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
370 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
373 public function testGetDatedSupEntries()
375 $future = new \
DateTime(date('Y-m-d H:i:s'));
376 $this->client
->request('GET', '/api/entries', ['since' => $future->getTimestamp() +
1000]);
378 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
380 $content = json_decode($this->client
->getResponse()->getContent(), true);
382 $this->assertGreaterThanOrEqual(1, \
count($content));
383 $this->assertEmpty($content['_embedded']['items']);
384 $this->assertSame(0, $content['total']);
385 $this->assertSame(1, $content['page']);
386 $this->assertSame(1, $content['pages']);
388 $this->assertArrayHasKey('_links', $content);
389 $this->assertArrayHasKey('self', $content['_links']);
390 $this->assertArrayHasKey('first', $content['_links']);
391 $this->assertArrayHasKey('last', $content['_links']);
393 foreach (['self', 'first', 'last'] as $link) {
394 $this->assertArrayHasKey('href', $content['_links'][$link]);
395 $this->assertContains('since=' . ($future->getTimestamp() +
1000), $content['_links'][$link]['href']);
398 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
401 public function testDeleteEntry()
403 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
404 $entry = new Entry($em->getReference(User
::class, 1));
405 $entry->setUrl('http://0.0.0.0/test-delete-entry');
406 $entry->setTitle('Test delete entry');
407 $em->persist($entry);
413 'title' => $entry->getTitle(),
414 'url' => $entry->getUrl(),
415 'id' => $entry->getId(),
418 $this->client
->request('DELETE', '/api/entries/' . $e['id'] . '.json');
420 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
422 $content = json_decode($this->client
->getResponse()->getContent(), true);
424 $this->assertSame($e['title'], $content['title']);
425 $this->assertSame($e['url'], $content['url']);
426 $this->assertSame($e['id'], $content['id']);
428 // We'll try to delete this entry again
429 $client = $this->createAuthorizedClient();
430 $client->request('DELETE', '/api/entries/' . $e['id'] . '.json');
432 $this->assertSame(404, $client->getResponse()->getStatusCode());
435 public function testDeleteEntryExpectId()
437 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
438 $entry = new Entry($em->getReference(User
::class, 1));
439 $entry->setUrl('http://0.0.0.0/test-delete-entry-id');
440 $em->persist($entry);
445 $id = $entry->getId();
447 $this->client
->request('DELETE', '/api/entries/' . $id . '.json?expect=id');
449 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
451 $content = json_decode($this->client
->getResponse()->getContent(), true);
453 $this->assertSame($id, $content['id']);
454 $this->assertArrayNotHasKey('url', $content);
456 // We'll try to delete this entry again
457 $client = $this->createAuthorizedClient();
458 $client->request('DELETE', '/api/entries/' . $id . '.json');
460 $this->assertSame(404, $client->getResponse()->getStatusCode());
463 public function testDeleteEntryExpectBadRequest()
465 $this->client
->request('DELETE', '/api/entries/1.json?expect=badrequest');
467 $this->assertSame(400, $this->client
->getResponse()->getStatusCode());
470 public function testPostEntry()
472 $this->client
->request('POST', '/api/entries.json', [
473 'url' => 'https://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',
475 'title' => 'New title for my article',
476 'content' => 'my content',
478 'published_at' => '2016-09-08T11:55:58+0200',
479 'authors' => 'bob,helen',
483 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
485 $content = json_decode($this->client
->getResponse()->getContent(), true);
487 $this->assertGreaterThan(0, $content['id']);
488 $this->assertSame('https://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']);
489 $this->assertSame(0, $content['is_archived']);
490 $this->assertSame(0, $content['is_starred']);
491 $this->assertNull($content['starred_at']);
492 $this->assertNull($content['archived_at']);
493 $this->assertSame('New title for my article', $content['title']);
494 $this->assertSame($this->getUserId(), $content['user_id']);
495 $this->assertCount(2, $content['tags']);
496 $this->assertNull($content['origin_url']);
497 $this->assertSame('my content', $content['content']);
498 $this->assertSame('de', $content['language']);
499 $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']);
500 $this->assertCount(2, $content['published_by']);
501 $this->assertContains('bob', $content['published_by']);
502 $this->assertContains('helen', $content['published_by']);
503 $this->assertTrue($content['is_public'], 'A public link has been generated for that entry');
506 public function testPostSameEntry()
508 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
509 $entry = new Entry($em->getReference(User
::class, $this->getUserId()));
510 $entry->setUrl('https://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');
511 $entry->setArchived(true);
512 $entry->addTag((new Tag())->setLabel('google'));
513 $entry->addTag((new Tag())->setLabel('apple'));
514 $em->persist($entry);
518 $this->client
->request('POST', '/api/entries.json', [
519 'url' => 'https://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',
521 'tags' => 'google, apple',
524 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
526 $content = json_decode($this->client
->getResponse()->getContent(), true);
528 $this->assertGreaterThan(0, $content['id']);
529 $this->assertSame('https://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']);
530 $this->assertSame(1, $content['is_archived']);
531 $this->assertSame(0, $content['is_starred']);
532 $this->assertCount(3, $content['tags']);
535 public function testPostEntryWhenFetchContentFails()
537 /** @var \Symfony\Component\DependencyInjection\Container $container */
538 $container = $this->client
->getContainer();
539 $contentProxy = $this->getMockBuilder(ContentProxy
::class)
540 ->disableOriginalConstructor()
541 ->setMethods(['updateEntry'])
543 $contentProxy->expects($this->any())
544 ->method('updateEntry')
545 ->willThrowException(new \
Exception('Test Fetch content fails'));
546 $container->set('wallabag_core.content_proxy', $contentProxy);
549 $this->client
->request('POST', '/api/entries.json', [
550 'url' => 'http://www.example.com/',
553 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
554 $content = json_decode($this->client
->getResponse()->getContent(), true);
555 $this->assertGreaterThan(0, $content['id']);
556 $this->assertSame('http://www.example.com/', $content['url']);
557 $this->assertSame('www.example.com', $content['domain_name']);
558 $this->assertSame('www.example.com', $content['title']);
560 // Remove the created entry to avoid side effects on other tests
561 if (isset($content['id'])) {
562 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
563 $entry = $em->getReference('WallabagCoreBundle:Entry', $content['id']);
570 public function testPostArchivedAndStarredEntry()
572 $now = new \
DateTime();
573 $this->client
->request('POST', '/api/entries.json', [
574 'url' => 'https://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
579 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
581 $content = json_decode($this->client
->getResponse()->getContent(), true);
583 $this->assertGreaterThan(0, $content['id']);
584 $this->assertSame('https://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']);
585 $this->assertSame(1, $content['is_archived']);
586 $this->assertSame(1, $content['is_starred']);
587 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \
DateTime($content['starred_at']))->getTimestamp());
588 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \
DateTime($content['archived_at']))->getTimestamp());
589 $this->assertSame($this->getUserId(), $content['user_id']);
592 public function testPostArchivedAndStarredEntryWithoutQuotes()
594 $this->client
->request('POST', '/api/entries.json', [
595 'url' => 'https://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
600 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
602 $content = json_decode($this->client
->getResponse()->getContent(), true);
604 $this->assertGreaterThan(0, $content['id']);
605 $this->assertSame('https://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']);
606 $this->assertSame(0, $content['is_archived']);
607 $this->assertSame(1, $content['is_starred']);
610 public function testPostEntryWithOriginUrl()
612 $this->client
->request('POST', '/api/entries.json', [
613 'url' => 'https://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',
615 'title' => 'New title for my article',
616 'content' => 'my content',
618 'published_at' => '2016-09-08T11:55:58+0200',
619 'authors' => 'bob,helen',
621 'origin_url' => 'http://mysource.tld',
624 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
626 $content = json_decode($this->client
->getResponse()->getContent(), true);
628 $this->assertGreaterThan(0, $content['id']);
629 $this->assertSame('https://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']);
630 $this->assertSame('http://mysource.tld', $content['origin_url']);
633 public function testPatchEntry()
635 $entry = $this->client
->getContainer()
636 ->get('doctrine.orm.entity_manager')
637 ->getRepository('WallabagCoreBundle:Entry')
638 ->findOneByUser($this->getUserId());
641 $this->markTestSkipped('No content found in db.');
644 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
645 'title' => 'New awesome title',
646 'tags' => 'new tag ' . uniqid(),
649 'language' => 'de_AT',
650 'preview_picture' => 'http://preview.io/picture.jpg',
651 'authors' => 'bob,sponge',
652 'content' => 'awesome',
654 'published_at' => 1488833381,
657 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
659 $content = json_decode($this->client
->getResponse()->getContent(), true);
661 $this->assertSame($entry->getId(), $content['id']);
662 $this->assertSame($entry->getUrl(), $content['url']);
663 $this->assertSame('New awesome title', $content['title']);
664 $this->assertGreaterThanOrEqual(1, \
count($content['tags']), 'We force only one tag');
665 $this->assertSame($this->getUserId(), $content['user_id']);
666 $this->assertSame('de_AT', $content['language']);
667 $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']);
668 $this->assertContains('sponge', $content['published_by']);
669 $this->assertContains('bob', $content['published_by']);
670 $this->assertSame('awesome', $content['content']);
671 $this->assertFalse($content['is_public'], 'Entry is no more shared');
672 $this->assertContains('2017-03-06', $content['published_at']);
675 public function testPatchEntryWithoutQuotes()
677 $entry = $this->client
->getContainer()
678 ->get('doctrine.orm.entity_manager')
679 ->getRepository('WallabagCoreBundle:Entry')
680 ->findOneByUser($this->getUserId());
683 $this->markTestSkipped('No content found in db.');
686 $previousContent = $entry->getContent();
687 $previousLanguage = $entry->getLanguage();
689 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
690 'title' => 'New awesome title',
691 'tags' => 'new tag ' . uniqid(),
694 'authors' => ['bob', 'sponge'],
697 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
699 $content = json_decode($this->client
->getResponse()->getContent(), true);
701 $this->assertSame($entry->getId(), $content['id']);
702 $this->assertSame($entry->getUrl(), $content['url']);
703 $this->assertGreaterThanOrEqual(1, \
count($content['tags']), 'We force only one tag');
704 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
705 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
706 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
709 public function testPatchEntryWithOriginUrl()
711 $entry = $this->client
->getContainer()
712 ->get('doctrine.orm.entity_manager')
713 ->getRepository('WallabagCoreBundle:Entry')
714 ->findOneByUser($this->getUserId());
717 $this->markTestSkipped('No content found in db.');
720 $previousContent = $entry->getContent();
721 $previousLanguage = $entry->getLanguage();
723 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
724 'title' => 'Another awesome title just for profit',
725 'origin_url' => 'https://myawesomesource.example.com',
728 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
730 $content = json_decode($this->client
->getResponse()->getContent(), true);
732 $this->assertSame($entry->getId(), $content['id']);
733 $this->assertSame($entry->getUrl(), $content['url']);
734 $this->assertSame('https://myawesomesource.example.com', $content['origin_url']);
735 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
736 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
737 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
740 public function testPatchEntryRemoveOriginUrl()
742 $entry = $this->client
->getContainer()
743 ->get('doctrine.orm.entity_manager')
744 ->getRepository('WallabagCoreBundle:Entry')
745 ->findOneByUser($this->getUserId());
748 $this->markTestSkipped('No content found in db.');
751 $previousContent = $entry->getContent();
752 $previousLanguage = $entry->getLanguage();
753 $previousTitle = $entry->getTitle();
755 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
759 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
761 $content = json_decode($this->client
->getResponse()->getContent(), true);
763 $this->assertSame($entry->getId(), $content['id']);
764 $this->assertSame($entry->getUrl(), $content['url']);
765 $this->assertEmpty($content['origin_url']);
766 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
767 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
768 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
769 $this->assertSame($previousTitle, $content['title'], 'Ensure title has not moved');
772 public function testPatchEntryNullOriginUrl()
774 $entry = $this->client
->getContainer()
775 ->get('doctrine.orm.entity_manager')
776 ->getRepository('WallabagCoreBundle:Entry')
777 ->findOneByUser($this->getUserId());
780 $this->markTestSkipped('No content found in db.');
783 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
784 'origin_url' => null,
787 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
789 $content = json_decode($this->client
->getResponse()->getContent(), true);
791 $this->assertNull($content['origin_url']);
794 public function testGetTagsEntry()
796 $entry = $this->client
->getContainer()
797 ->get('doctrine.orm.entity_manager')
798 ->getRepository('WallabagCoreBundle:Entry')
799 ->findOneWithTags($this->user
->getId());
804 $this->markTestSkipped('No content found in db.');
808 foreach ($entry->getTags() as $tag) {
809 $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()];
812 $this->client
->request('GET', '/api/entries/' . $entry->getId() . '/tags');
814 $this->assertSame(json_encode($tags, JSON_HEX_QUOT
), $this->client
->getResponse()->getContent());
817 public function testPostTagsOnEntry()
819 $entry = $this->client
->getContainer()
820 ->get('doctrine.orm.entity_manager')
821 ->getRepository('WallabagCoreBundle:Entry')
822 ->findOneByUser($this->getUserId());
825 $this->markTestSkipped('No content found in db.');
828 $nbTags = \
count($entry->getTags());
830 $newTags = 'tag1,tag2,tag3';
832 $this->client
->request('POST', '/api/entries/' . $entry->getId() . '/tags', ['tags' => $newTags]);
834 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
836 $content = json_decode($this->client
->getResponse()->getContent(), true);
838 $this->assertArrayHasKey('tags', $content);
839 $this->assertCount($nbTags +
3, $content['tags']);
841 $entryDB = $this->client
->getContainer()
842 ->get('doctrine.orm.entity_manager')
843 ->getRepository('WallabagCoreBundle:Entry')
844 ->find($entry->getId());
847 foreach ($entryDB->getTags()->toArray() as $tag) {
848 $tagsInDB[$tag->getId()] = $tag->getLabel();
851 foreach (explode(',', $newTags) as $tag) {
852 $this->assertContains($tag, $tagsInDB);
856 public function testDeleteOneTagEntry()
858 $entry = $this->client
->getContainer()
859 ->get('doctrine.orm.entity_manager')
860 ->getRepository('WallabagCoreBundle:Entry')
861 ->findOneWithTags($this->user
->getId());
865 $this->markTestSkipped('No content found in db.');
868 // hydrate the tags relations
869 $nbTags = \
count($entry->getTags());
870 $tag = $entry->getTags()[0];
872 $this->client
->request('DELETE', '/api/entries/' . $entry->getId() . '/tags/' . $tag->getId() . '.json');
874 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
876 $content = json_decode($this->client
->getResponse()->getContent(), true);
878 $this->assertArrayHasKey('tags', $content);
879 $this->assertCount($nbTags - 1, $content['tags']);
882 public function testSaveIsArchivedAfterPost()
884 $entry = $this->client
->getContainer()
885 ->get('doctrine.orm.entity_manager')
886 ->getRepository('WallabagCoreBundle:Entry')
887 ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]);
890 $this->markTestSkipped('No content found in db.');
893 $this->client
->request('POST', '/api/entries.json', [
894 'url' => $entry->getUrl(),
897 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
899 $content = json_decode($this->client
->getResponse()->getContent(), true);
901 $this->assertSame(1, $content['is_archived']);
904 public function testSaveIsStarredAfterPost()
906 $entry = $this->client
->getContainer()
907 ->get('doctrine.orm.entity_manager')
908 ->getRepository('WallabagCoreBundle:Entry')
909 ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]);
912 $this->markTestSkipped('No content found in db.');
915 $this->client
->request('POST', '/api/entries.json', [
916 'url' => $entry->getUrl(),
919 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
921 $content = json_decode($this->client
->getResponse()->getContent(), true);
923 $this->assertSame(1, $content['is_starred']);
926 public function testSaveIsArchivedAfterPatch()
928 $entry = $this->client
->getContainer()
929 ->get('doctrine.orm.entity_manager')
930 ->getRepository('WallabagCoreBundle:Entry')
931 ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]);
934 $this->markTestSkipped('No content found in db.');
937 $previousTitle = $entry->getTitle();
939 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
940 'title' => $entry->getTitle() . '++',
943 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
945 $content = json_decode($this->client
->getResponse()->getContent(), true);
947 $this->assertSame(1, $content['is_archived']);
948 $this->assertSame($previousTitle . '++', $content['title']);
951 public function testSaveIsStarredAfterPatch()
953 $now = new \
DateTime();
954 $entry = $this->client
->getContainer()
955 ->get('doctrine.orm.entity_manager')
956 ->getRepository('WallabagCoreBundle:Entry')
957 ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]);
960 $this->markTestSkipped('No content found in db.');
962 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
963 'title' => $entry->getTitle() . '++',
966 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
968 $content = json_decode($this->client
->getResponse()->getContent(), true);
970 $this->assertSame(1, $content['is_starred']);
971 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \
DateTime($content['starred_at']))->getTimestamp());
974 public function dataForEntriesExistWithUrl()
976 $url = hash('sha1', 'http://0.0.0.0/entry2');
980 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1',
981 'expectedValue' => 2,
984 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2',
985 'expectedValue' => true,
987 'hashed_url_with_id' => [
988 'url' => '/api/entries/exists?hashed_url=' . $url . '&return_id=1',
989 'expectedValue' => 2,
991 'hashed_url_without_id' => [
992 'url' => '/api/entries/exists?hashed_url=' . $url . '',
993 'expectedValue' => true,
999 * @dataProvider dataForEntriesExistWithUrl
1001 public function testGetEntriesExists($url, $expectedValue)
1003 $this->client
->request('GET', $url);
1005 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1007 $content = json_decode($this->client
->getResponse()->getContent(), true);
1009 $this->assertSame($expectedValue, $content['exists']);
1012 public function testGetEntriesExistsWithManyUrls()
1014 $url1 = 'http://0.0.0.0/entry2';
1015 $url2 = 'http://0.0.0.0/entry10';
1017 $this->client
->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1');
1019 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1021 $content = json_decode($this->client
->getResponse()->getContent(), true);
1023 $this->assertArrayHasKey($url1, $content);
1024 $this->assertArrayHasKey($url2, $content);
1025 // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value
1026 $this->assertGreaterThan(1, $content[$url1]);
1027 $this->assertNull($content[$url2]);
1030 public function testGetEntriesExistsWithManyUrlsReturnBool()
1032 $url1 = 'http://0.0.0.0/entry2';
1033 $url2 = 'http://0.0.0.0/entry10';
1034 $this->client
->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2);
1036 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1038 $content = json_decode($this->client
->getResponse()->getContent(), true);
1040 $this->assertArrayHasKey($url1, $content);
1041 $this->assertArrayHasKey($url2, $content);
1042 $this->assertTrue($content[$url1]);
1043 $this->assertFalse($content[$url2]);
1046 public function testGetEntriesExistsWithManyUrlsHashed()
1048 $url1 = 'http://0.0.0.0/entry2';
1049 $url2 = 'http://0.0.0.0/entry10';
1050 $this->client
->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('sha1', $url1) . '&hashed_urls[]=' . hash('sha1', $url2) . '&return_id=1');
1052 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1054 $content = json_decode($this->client
->getResponse()->getContent(), true);
1056 $this->assertArrayHasKey(hash('sha1', $url1), $content);
1057 $this->assertArrayHasKey(hash('sha1', $url2), $content);
1058 $this->assertSame(2, $content[hash('sha1', $url1)]);
1059 $this->assertNull($content[hash('sha1', $url2)]);
1062 public function testGetEntriesExistsWithManyUrlsHashedReturnBool()
1064 $url1 = 'http://0.0.0.0/entry2';
1065 $url2 = 'http://0.0.0.0/entry10';
1066 $this->client
->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('sha1', $url1) . '&hashed_urls[]=' . hash('sha1', $url2));
1068 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1070 $content = json_decode($this->client
->getResponse()->getContent(), true);
1072 $this->assertArrayHasKey(hash('sha1', $url1), $content);
1073 $this->assertArrayHasKey(hash('sha1', $url2), $content);
1074 $this->assertTrue($content[hash('sha1', $url1)]);
1075 $this->assertFalse($content[hash('sha1', $url2)]);
1078 public function testGetEntriesExistsWhichDoesNotExists()
1080 $this->client
->request('GET', '/api/entries/exists?hashed_url=' . hash('sha1', 'http://google.com/entry2'));
1082 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1084 $content = json_decode($this->client
->getResponse()->getContent(), true);
1086 $this->assertFalse($content['exists']);
1089 public function testGetEntriesExistsWithNoUrl()
1091 $this->client
->request('GET', '/api/entries/exists?hashed_url=');
1093 $this->assertSame(403, $this->client
->getResponse()->getStatusCode());
1096 public function testReloadEntryErrorWhileFetching()
1098 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
1099 ->getRepository('WallabagCoreBundle:Entry')
1100 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
1103 $this->markTestSkipped('No content found in db.');
1106 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '/reload.json');
1107 $this->assertSame(304, $this->client
->getResponse()->getStatusCode());
1110 public function testReloadEntry()
1112 $this->client
->request('POST', '/api/entries.json', [
1113 'url' => 'https://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',
1115 'tags' => 'google, apple',
1118 $json = json_decode($this->client
->getResponse()->getContent(), true);
1122 $this->client
->request('PATCH', '/api/entries/' . $json['id'] . '/reload.json');
1123 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1125 $content = json_decode($this->client
->getResponse()->getContent(), true);
1127 $this->assertNotEmpty($content['title']);
1129 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
1132 public function testPostEntriesTagsListAction()
1134 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
1135 ->getRepository('WallabagCoreBundle:Entry')
1136 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
1138 $tags = $entry->getTags();
1140 $this->assertCount(2, $tags);
1144 'url' => 'http://0.0.0.0/entry4',
1145 'tags' => 'new tag 1, new tag 2',
1149 $this->client
->request('POST', '/api/entries/tags/lists?list=' . json_encode($list));
1151 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1153 $content = json_decode($this->client
->getResponse()->getContent(), true);
1155 $this->assertInternalType('int', $content[0]['entry']);
1156 $this->assertSame('http://0.0.0.0/entry4', $content[0]['url']);
1158 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
1159 ->getRepository('WallabagCoreBundle:Entry')
1160 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
1162 $tags = $entry->getTags();
1163 $this->assertCount(4, $tags);
1166 public function testPostEntriesTagsListActionNoList()
1168 $this->client
->request('POST', '/api/entries/tags/lists?list=' . json_encode([]));
1170 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1172 $content = json_decode($this->client
->getResponse()->getContent(), true);
1174 $this->assertEmpty($content);
1177 public function testDeleteEntriesTagsListAction()
1179 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
1180 $entry = new Entry($em->getReference(User
::class, $this->getUserId()));
1181 $entry->setUrl('http://0.0.0.0/test-entry');
1182 $entry->addTag((new Tag())->setLabel('foo-tag'));
1183 $entry->addTag((new Tag())->setLabel('bar-tag'));
1184 $em->persist($entry);
1191 'url' => 'http://0.0.0.0/test-entry',
1192 'tags' => 'foo-tag, bar-tag',
1196 $this->client
->request('DELETE', '/api/entries/tags/list?list=' . json_encode($list));
1197 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1199 $entry = $em->getRepository('WallabagCoreBundle:Entry')->find($entry->getId());
1200 $this->assertCount(0, $entry->getTags());
1203 public function testDeleteEntriesTagsListActionNoList()
1205 $this->client
->request('DELETE', '/api/entries/tags/list?list=' . json_encode([]));
1207 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1209 $content = json_decode($this->client
->getResponse()->getContent(), true);
1211 $this->assertEmpty($content);
1214 public function testPostEntriesListAction()
1217 'https://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html',
1218 'http://0.0.0.0/entry2',
1221 $this->client
->request('POST', '/api/entries/lists?urls=' . json_encode($list));
1223 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1225 $content = json_decode($this->client
->getResponse()->getContent(), true);
1227 $this->assertInternalType('int', $content[0]['entry']);
1228 $this->assertSame('https://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']);
1230 $this->assertInternalType('int', $content[1]['entry']);
1231 $this->assertSame('http://0.0.0.0/entry2', $content[1]['url']);
1234 public function testPostEntriesListActionWithNoUrls()
1236 $this->client
->request('POST', '/api/entries/lists?urls=' . json_encode([]));
1238 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1240 $content = json_decode($this->client
->getResponse()->getContent(), true);
1242 $this->assertEmpty($content);
1245 public function testDeleteEntriesListAction()
1247 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
1248 $em->persist((new Entry($em->getReference(User
::class, $this->getUserId())))->setUrl('http://0.0.0.0/test-entry1'));
1253 'http://0.0.0.0/test-entry1',
1254 'http://0.0.0.0/test-entry-not-exist',
1257 $this->client
->request('DELETE', '/api/entries/list?urls=' . json_encode($list));
1259 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1261 $content = json_decode($this->client
->getResponse()->getContent(), true);
1263 $this->assertTrue($content[0]['entry']);
1264 $this->assertSame('http://0.0.0.0/test-entry1', $content[0]['url']);
1266 $this->assertFalse($content[1]['entry']);
1267 $this->assertSame('http://0.0.0.0/test-entry-not-exist', $content[1]['url']);
1270 public function testDeleteEntriesListActionWithNoUrls()
1272 $this->client
->request('DELETE', '/api/entries/list?urls=' . json_encode([]));
1274 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1276 $content = json_decode($this->client
->getResponse()->getContent(), true);
1278 $this->assertEmpty($content);
1281 public function testLimitBulkAction()
1284 'http://0.0.0.0/entry1',
1285 'http://0.0.0.0/entry1',
1286 'http://0.0.0.0/entry1',
1287 'http://0.0.0.0/entry1',
1288 'http://0.0.0.0/entry1',
1289 'http://0.0.0.0/entry1',
1290 'http://0.0.0.0/entry1',
1291 'http://0.0.0.0/entry1',
1292 'http://0.0.0.0/entry1',
1293 'http://0.0.0.0/entry1',
1294 'http://0.0.0.0/entry1',
1297 $this->client
->request('POST', '/api/entries/lists?urls=' . json_encode($list));
1299 $this->assertSame(400, $this->client
->getResponse()->getStatusCode());
1300 $this->assertContains('API limit reached', $this->client
->getResponse()->getContent());
1303 public function testRePostEntryAndReUsePublishedAt()
1305 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
1306 $entry = new Entry($em->getReference(User
::class, $this->getUserId()));
1307 $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »');
1308 $entry->setContent('hihi');
1309 $entry->setUrl('https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html');
1310 $entry->setPublishedAt(new \
DateTime('2017-06-26T07:46:02+0200'));
1311 $em->persist($entry);
1315 $this->client
->request('POST', '/api/entries.json', [
1316 'url' => 'https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html',
1319 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1321 $content = json_decode($this->client
->getResponse()->getContent(), true);
1323 $this->assertGreaterThan(0, $content['id']);
1324 $this->assertSame('https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html', $content['url']);