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->assertNotNull($content['_embedded']['items'][0]['content']);
138 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
141 public function testGetEntriesDetailMetadata()
143 $this->client
->request('GET', '/api/entries?detail=metadata');
145 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
147 $content = json_decode($this->client
->getResponse()->getContent(), true);
149 $this->assertGreaterThanOrEqual(1, \
count($content));
150 $this->assertNotEmpty($content['_embedded']['items']);
151 $this->assertGreaterThanOrEqual(1, $content['total']);
152 $this->assertSame(1, $content['page']);
153 $this->assertGreaterThanOrEqual(1, $content['pages']);
155 $this->assertNull($content['_embedded']['items'][0]['content']);
157 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
160 public function testGetEntriesWithFullOptions()
162 $this->client
->request('GET', '/api/entries', [
170 'since' => 1443274283,
174 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
176 $content = json_decode($this->client
->getResponse()->getContent(), true);
178 $this->assertGreaterThanOrEqual(1, \
count($content));
179 $this->assertArrayHasKey('items', $content['_embedded']);
180 $this->assertGreaterThanOrEqual(0, $content['total']);
181 $this->assertSame(1, $content['page']);
182 $this->assertSame(2, $content['limit']);
183 $this->assertGreaterThanOrEqual(1, $content['pages']);
185 $this->assertArrayHasKey('_links', $content);
186 $this->assertArrayHasKey('self', $content['_links']);
187 $this->assertArrayHasKey('first', $content['_links']);
188 $this->assertArrayHasKey('last', $content['_links']);
190 foreach (['self', 'first', 'last'] as $link) {
191 $this->assertArrayHasKey('href', $content['_links'][$link]);
192 $this->assertContains('archive=1', $content['_links'][$link]['href']);
193 $this->assertContains('starred=1', $content['_links'][$link]['href']);
194 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
195 $this->assertContains('order=asc', $content['_links'][$link]['href']);
196 $this->assertContains('tags=foo', $content['_links'][$link]['href']);
197 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
198 $this->assertContains('public=0', $content['_links'][$link]['href']);
201 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
204 public function testGetEntriesPublicOnly()
206 $entry = $this->client
->getContainer()
207 ->get('doctrine.orm.entity_manager')
208 ->getRepository('WallabagCoreBundle:Entry')
209 ->findOneByUser($this->getUserId());
212 $this->markTestSkipped('No content found in db.');
215 // generate at least one public entry
216 $entry->generateUid();
218 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
219 $em->persist($entry);
222 $this->client
->request('GET', '/api/entries', [
226 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
228 $content = json_decode($this->client
->getResponse()->getContent(), true);
230 $this->assertGreaterThanOrEqual(1, \
count($content));
231 $this->assertArrayHasKey('items', $content['_embedded']);
232 $this->assertGreaterThanOrEqual(1, $content['total']);
233 $this->assertSame(1, $content['page']);
234 $this->assertSame(30, $content['limit']);
235 $this->assertGreaterThanOrEqual(1, $content['pages']);
237 $this->assertArrayHasKey('_links', $content);
238 $this->assertArrayHasKey('self', $content['_links']);
239 $this->assertArrayHasKey('first', $content['_links']);
240 $this->assertArrayHasKey('last', $content['_links']);
242 foreach (['self', 'first', 'last'] as $link) {
243 $this->assertArrayHasKey('href', $content['_links'][$link]);
244 $this->assertContains('public=1', $content['_links'][$link]['href']);
247 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
250 public function testGetEntriesOnPageTwo()
252 $this->client
->request('GET', '/api/entries', [
257 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
259 $content = json_decode($this->client
->getResponse()->getContent(), true);
261 $this->assertGreaterThanOrEqual(0, $content['total']);
262 $this->assertSame(2, $content['page']);
263 $this->assertSame(2, $content['limit']);
266 public function testGetStarredEntriesWithBadSort()
268 $this->client
->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated', 'order' => 'unknown']);
270 $this->assertSame(400, $this->client
->getResponse()->getStatusCode());
272 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
275 public function testGetStarredEntries()
277 $this->client
->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);
279 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
281 $content = json_decode($this->client
->getResponse()->getContent(), true);
283 $this->assertGreaterThanOrEqual(1, \
count($content));
284 $this->assertNotEmpty($content['_embedded']['items']);
285 $this->assertGreaterThanOrEqual(1, $content['total']);
286 $this->assertSame(1, $content['page']);
287 $this->assertGreaterThanOrEqual(1, $content['pages']);
289 $this->assertArrayHasKey('_links', $content);
290 $this->assertArrayHasKey('self', $content['_links']);
291 $this->assertArrayHasKey('first', $content['_links']);
292 $this->assertArrayHasKey('last', $content['_links']);
294 foreach (['self', 'first', 'last'] as $link) {
295 $this->assertArrayHasKey('href', $content['_links'][$link]);
296 $this->assertContains('starred=1', $content['_links'][$link]['href']);
297 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
300 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
303 public function testGetArchiveEntries()
305 $this->client
->request('GET', '/api/entries', ['archive' => 1]);
307 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
309 $content = json_decode($this->client
->getResponse()->getContent(), true);
311 $this->assertGreaterThanOrEqual(1, \
count($content));
312 $this->assertNotEmpty($content['_embedded']['items']);
313 $this->assertGreaterThanOrEqual(1, $content['total']);
314 $this->assertSame(1, $content['page']);
315 $this->assertGreaterThanOrEqual(1, $content['pages']);
317 $this->assertArrayHasKey('_links', $content);
318 $this->assertArrayHasKey('self', $content['_links']);
319 $this->assertArrayHasKey('first', $content['_links']);
320 $this->assertArrayHasKey('last', $content['_links']);
322 foreach (['self', 'first', 'last'] as $link) {
323 $this->assertArrayHasKey('href', $content['_links'][$link]);
324 $this->assertContains('archive=1', $content['_links'][$link]['href']);
327 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
330 public function testGetTaggedEntries()
332 $this->client
->request('GET', '/api/entries', ['tags' => 'foo,bar']);
334 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
336 $content = json_decode($this->client
->getResponse()->getContent(), true);
338 $this->assertGreaterThanOrEqual(1, \
count($content));
339 $this->assertNotEmpty($content['_embedded']['items']);
340 $this->assertGreaterThanOrEqual(1, $content['total']);
341 $this->assertSame(1, $content['page']);
342 $this->assertGreaterThanOrEqual(1, $content['pages']);
344 $this->assertContains('foo', array_column($content['_embedded']['items'][0]['tags'], 'label'), 'Entries tags should have "foo" tag');
345 $this->assertContains('bar', array_column($content['_embedded']['items'][0]['tags'], 'label'), 'Entries tags should have "bar" tag');
347 $this->assertArrayHasKey('_links', $content);
348 $this->assertArrayHasKey('self', $content['_links']);
349 $this->assertArrayHasKey('first', $content['_links']);
350 $this->assertArrayHasKey('last', $content['_links']);
352 foreach (['self', 'first', 'last'] as $link) {
353 $this->assertArrayHasKey('href', $content['_links'][$link]);
354 $this->assertContains('tags=' . urlencode('foo,bar'), $content['_links'][$link]['href']);
357 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
360 public function testGetTaggedEntriesWithBadParams()
362 $this->client
->request('GET', '/api/entries', ['tags' => ['foo', 'bar']]);
364 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
367 public function testGetDatedEntries()
369 $this->client
->request('GET', '/api/entries', ['since' => 1443274283]);
371 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
373 $content = json_decode($this->client
->getResponse()->getContent(), true);
375 $this->assertGreaterThanOrEqual(1, \
count($content));
376 $this->assertNotEmpty($content['_embedded']['items']);
377 $this->assertGreaterThanOrEqual(1, $content['total']);
378 $this->assertSame(1, $content['page']);
379 $this->assertGreaterThanOrEqual(1, $content['pages']);
381 $this->assertArrayHasKey('_links', $content);
382 $this->assertArrayHasKey('self', $content['_links']);
383 $this->assertArrayHasKey('first', $content['_links']);
384 $this->assertArrayHasKey('last', $content['_links']);
386 foreach (['self', 'first', 'last'] as $link) {
387 $this->assertArrayHasKey('href', $content['_links'][$link]);
388 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
391 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
394 public function testGetDatedSupEntries()
396 $future = new \
DateTime(date('Y-m-d H:i:s'));
397 $this->client
->request('GET', '/api/entries', ['since' => $future->getTimestamp() +
1000]);
399 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
401 $content = json_decode($this->client
->getResponse()->getContent(), true);
403 $this->assertGreaterThanOrEqual(1, \
count($content));
404 $this->assertEmpty($content['_embedded']['items']);
405 $this->assertSame(0, $content['total']);
406 $this->assertSame(1, $content['page']);
407 $this->assertSame(1, $content['pages']);
409 $this->assertArrayHasKey('_links', $content);
410 $this->assertArrayHasKey('self', $content['_links']);
411 $this->assertArrayHasKey('first', $content['_links']);
412 $this->assertArrayHasKey('last', $content['_links']);
414 foreach (['self', 'first', 'last'] as $link) {
415 $this->assertArrayHasKey('href', $content['_links'][$link]);
416 $this->assertContains('since=' . ($future->getTimestamp() +
1000), $content['_links'][$link]['href']);
419 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
422 public function testDeleteEntry()
424 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
425 $entry = new Entry($em->getReference(User
::class, 1));
426 $entry->setUrl('http://0.0.0.0/test-delete-entry');
427 $entry->setTitle('Test delete entry');
428 $em->persist($entry);
434 'title' => $entry->getTitle(),
435 'url' => $entry->getUrl(),
436 'id' => $entry->getId(),
439 $this->client
->request('DELETE', '/api/entries/' . $e['id'] . '.json');
441 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
443 $content = json_decode($this->client
->getResponse()->getContent(), true);
445 $this->assertSame($e['title'], $content['title']);
446 $this->assertSame($e['url'], $content['url']);
447 $this->assertSame($e['id'], $content['id']);
449 // We'll try to delete this entry again
450 $client = $this->createAuthorizedClient();
451 $client->request('DELETE', '/api/entries/' . $e['id'] . '.json');
453 $this->assertSame(404, $client->getResponse()->getStatusCode());
456 public function testDeleteEntryExpectId()
458 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
459 $entry = new Entry($em->getReference(User
::class, 1));
460 $entry->setUrl('http://0.0.0.0/test-delete-entry-id');
461 $em->persist($entry);
466 $id = $entry->getId();
468 $this->client
->request('DELETE', '/api/entries/' . $id . '.json?expect=id');
470 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
472 $content = json_decode($this->client
->getResponse()->getContent(), true);
474 $this->assertSame($id, $content['id']);
475 $this->assertArrayNotHasKey('url', $content);
477 // We'll try to delete this entry again
478 $client = $this->createAuthorizedClient();
479 $client->request('DELETE', '/api/entries/' . $id . '.json');
481 $this->assertSame(404, $client->getResponse()->getStatusCode());
484 public function testDeleteEntryExpectBadRequest()
486 $this->client
->request('DELETE', '/api/entries/1.json?expect=badrequest');
488 $this->assertSame(400, $this->client
->getResponse()->getStatusCode());
491 public function testPostEntry()
493 $this->client
->request('POST', '/api/entries.json', [
494 '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',
496 'title' => 'New title for my article',
497 'content' => 'my content',
499 'published_at' => '2016-09-08T11:55:58+0200',
500 'authors' => 'bob,helen',
504 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
506 $content = json_decode($this->client
->getResponse()->getContent(), true);
508 $this->assertGreaterThan(0, $content['id']);
509 $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']);
510 $this->assertSame(0, $content['is_archived']);
511 $this->assertSame(0, $content['is_starred']);
512 $this->assertNull($content['starred_at']);
513 $this->assertNull($content['archived_at']);
514 $this->assertSame('New title for my article', $content['title']);
515 $this->assertSame($this->getUserId(), $content['user_id']);
516 $this->assertCount(2, $content['tags']);
517 $this->assertNull($content['origin_url']);
518 $this->assertSame('my content', $content['content']);
519 $this->assertSame('de', $content['language']);
520 $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']);
521 $this->assertCount(2, $content['published_by']);
522 $this->assertContains('bob', $content['published_by']);
523 $this->assertContains('helen', $content['published_by']);
524 $this->assertTrue($content['is_public'], 'A public link has been generated for that entry');
527 public function testPostSameEntry()
529 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
530 $entry = new Entry($em->getReference(User
::class, $this->getUserId()));
531 $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');
532 $entry->setArchived(true);
533 $entry->addTag((new Tag())->setLabel('google'));
534 $entry->addTag((new Tag())->setLabel('apple'));
535 $em->persist($entry);
539 $this->client
->request('POST', '/api/entries.json', [
540 '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',
542 'tags' => 'google, apple',
545 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
547 $content = json_decode($this->client
->getResponse()->getContent(), true);
549 $this->assertGreaterThan(0, $content['id']);
550 $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']);
551 $this->assertSame(1, $content['is_archived']);
552 $this->assertSame(0, $content['is_starred']);
553 $this->assertCount(3, $content['tags']);
556 public function testPostEntryWhenFetchContentFails()
558 /** @var \Symfony\Component\DependencyInjection\Container $container */
559 $container = $this->client
->getContainer();
560 $contentProxy = $this->getMockBuilder(ContentProxy
::class)
561 ->disableOriginalConstructor()
562 ->setMethods(['updateEntry'])
564 $contentProxy->expects($this->any())
565 ->method('updateEntry')
566 ->willThrowException(new \
Exception('Test Fetch content fails'));
567 $container->set('wallabag_core.content_proxy', $contentProxy);
570 $this->client
->request('POST', '/api/entries.json', [
571 'url' => 'http://www.example.com/',
574 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
575 $content = json_decode($this->client
->getResponse()->getContent(), true);
576 $this->assertGreaterThan(0, $content['id']);
577 $this->assertSame('http://www.example.com/', $content['url']);
578 $this->assertSame('www.example.com', $content['domain_name']);
579 $this->assertSame('www.example.com', $content['title']);
581 // Remove the created entry to avoid side effects on other tests
582 if (isset($content['id'])) {
583 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
584 $entry = $em->getReference('WallabagCoreBundle:Entry', $content['id']);
591 public function testPostArchivedAndStarredEntry()
593 $now = new \
DateTime();
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(1, $content['is_archived']);
607 $this->assertSame(1, $content['is_starred']);
608 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \
DateTime($content['starred_at']))->getTimestamp());
609 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \
DateTime($content['archived_at']))->getTimestamp());
610 $this->assertSame($this->getUserId(), $content['user_id']);
613 public function testPostArchivedAndStarredEntryWithoutQuotes()
615 $this->client
->request('POST', '/api/entries.json', [
616 'url' => 'https://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
621 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
623 $content = json_decode($this->client
->getResponse()->getContent(), true);
625 $this->assertGreaterThan(0, $content['id']);
626 $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']);
627 $this->assertSame(0, $content['is_archived']);
628 $this->assertSame(1, $content['is_starred']);
631 public function testPostEntryWithOriginUrl()
633 $this->client
->request('POST', '/api/entries.json', [
634 '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',
636 'title' => 'New title for my article',
637 'content' => 'my content',
639 'published_at' => '2016-09-08T11:55:58+0200',
640 'authors' => 'bob,helen',
642 'origin_url' => 'http://mysource.tld',
645 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
647 $content = json_decode($this->client
->getResponse()->getContent(), true);
649 $this->assertGreaterThan(0, $content['id']);
650 $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']);
651 $this->assertSame('http://mysource.tld', $content['origin_url']);
654 public function testPatchEntry()
656 $entry = $this->client
->getContainer()
657 ->get('doctrine.orm.entity_manager')
658 ->getRepository('WallabagCoreBundle:Entry')
659 ->findOneByUser($this->getUserId());
662 $this->markTestSkipped('No content found in db.');
665 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
666 'title' => 'New awesome title',
667 'tags' => 'new tag ' . uniqid(),
670 'language' => 'de_AT',
671 'preview_picture' => 'http://preview.io/picture.jpg',
672 'authors' => 'bob,sponge',
673 'content' => 'awesome',
675 'published_at' => 1488833381,
678 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
680 $content = json_decode($this->client
->getResponse()->getContent(), true);
682 $this->assertSame($entry->getId(), $content['id']);
683 $this->assertSame($entry->getUrl(), $content['url']);
684 $this->assertSame('New awesome title', $content['title']);
685 $this->assertGreaterThanOrEqual(1, \
count($content['tags']), 'We force only one tag');
686 $this->assertSame($this->getUserId(), $content['user_id']);
687 $this->assertSame('de_AT', $content['language']);
688 $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']);
689 $this->assertContains('sponge', $content['published_by']);
690 $this->assertContains('bob', $content['published_by']);
691 $this->assertSame('awesome', $content['content']);
692 $this->assertFalse($content['is_public'], 'Entry is no more shared');
693 $this->assertContains('2017-03-06', $content['published_at']);
696 public function testPatchEntryWithoutQuotes()
698 $entry = $this->client
->getContainer()
699 ->get('doctrine.orm.entity_manager')
700 ->getRepository('WallabagCoreBundle:Entry')
701 ->findOneByUser($this->getUserId());
704 $this->markTestSkipped('No content found in db.');
707 $previousContent = $entry->getContent();
708 $previousLanguage = $entry->getLanguage();
710 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
711 'title' => 'New awesome title',
712 'tags' => 'new tag ' . uniqid(),
715 'authors' => ['bob', 'sponge'],
718 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
720 $content = json_decode($this->client
->getResponse()->getContent(), true);
722 $this->assertSame($entry->getId(), $content['id']);
723 $this->assertSame($entry->getUrl(), $content['url']);
724 $this->assertGreaterThanOrEqual(1, \
count($content['tags']), 'We force only one tag');
725 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
726 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
727 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
730 public function testPatchEntryWithOriginUrl()
732 $entry = $this->client
->getContainer()
733 ->get('doctrine.orm.entity_manager')
734 ->getRepository('WallabagCoreBundle:Entry')
735 ->findOneByUser($this->getUserId());
738 $this->markTestSkipped('No content found in db.');
741 $previousContent = $entry->getContent();
742 $previousLanguage = $entry->getLanguage();
744 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
745 'title' => 'Another awesome title just for profit',
746 'origin_url' => 'https://myawesomesource.example.com',
749 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
751 $content = json_decode($this->client
->getResponse()->getContent(), true);
753 $this->assertSame($entry->getId(), $content['id']);
754 $this->assertSame($entry->getUrl(), $content['url']);
755 $this->assertSame('https://myawesomesource.example.com', $content['origin_url']);
756 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
757 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
758 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
761 public function testPatchEntryRemoveOriginUrl()
763 $entry = $this->client
->getContainer()
764 ->get('doctrine.orm.entity_manager')
765 ->getRepository('WallabagCoreBundle:Entry')
766 ->findOneByUser($this->getUserId());
769 $this->markTestSkipped('No content found in db.');
772 $previousContent = $entry->getContent();
773 $previousLanguage = $entry->getLanguage();
774 $previousTitle = $entry->getTitle();
776 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
780 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
782 $content = json_decode($this->client
->getResponse()->getContent(), true);
784 $this->assertSame($entry->getId(), $content['id']);
785 $this->assertSame($entry->getUrl(), $content['url']);
786 $this->assertEmpty($content['origin_url']);
787 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
788 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
789 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
790 $this->assertSame($previousTitle, $content['title'], 'Ensure title has not moved');
793 public function testPatchEntryNullOriginUrl()
795 $entry = $this->client
->getContainer()
796 ->get('doctrine.orm.entity_manager')
797 ->getRepository('WallabagCoreBundle:Entry')
798 ->findOneByUser($this->getUserId());
801 $this->markTestSkipped('No content found in db.');
804 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
805 'origin_url' => null,
808 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
810 $content = json_decode($this->client
->getResponse()->getContent(), true);
812 $this->assertNull($content['origin_url']);
815 public function testGetTagsEntry()
817 $entry = $this->client
->getContainer()
818 ->get('doctrine.orm.entity_manager')
819 ->getRepository('WallabagCoreBundle:Entry')
820 ->findOneWithTags($this->user
->getId());
825 $this->markTestSkipped('No content found in db.');
829 foreach ($entry->getTags() as $tag) {
830 $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()];
833 $this->client
->request('GET', '/api/entries/' . $entry->getId() . '/tags');
835 $this->assertSame(json_encode($tags, JSON_HEX_QUOT
), $this->client
->getResponse()->getContent());
838 public function testPostTagsOnEntry()
840 $entry = $this->client
->getContainer()
841 ->get('doctrine.orm.entity_manager')
842 ->getRepository('WallabagCoreBundle:Entry')
843 ->findOneByUser($this->getUserId());
846 $this->markTestSkipped('No content found in db.');
849 $nbTags = \
count($entry->getTags());
851 $newTags = 'tag1,tag2,tag3';
853 $this->client
->request('POST', '/api/entries/' . $entry->getId() . '/tags', ['tags' => $newTags]);
855 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
857 $content = json_decode($this->client
->getResponse()->getContent(), true);
859 $this->assertArrayHasKey('tags', $content);
860 $this->assertCount($nbTags +
3, $content['tags']);
862 $entryDB = $this->client
->getContainer()
863 ->get('doctrine.orm.entity_manager')
864 ->getRepository('WallabagCoreBundle:Entry')
865 ->find($entry->getId());
868 foreach ($entryDB->getTags()->toArray() as $tag) {
869 $tagsInDB[$tag->getId()] = $tag->getLabel();
872 foreach (explode(',', $newTags) as $tag) {
873 $this->assertContains($tag, $tagsInDB);
877 public function testDeleteOneTagEntry()
879 $entry = $this->client
->getContainer()
880 ->get('doctrine.orm.entity_manager')
881 ->getRepository('WallabagCoreBundle:Entry')
882 ->findOneWithTags($this->user
->getId());
886 $this->markTestSkipped('No content found in db.');
889 // hydrate the tags relations
890 $nbTags = \
count($entry->getTags());
891 $tag = $entry->getTags()[0];
893 $this->client
->request('DELETE', '/api/entries/' . $entry->getId() . '/tags/' . $tag->getId() . '.json');
895 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
897 $content = json_decode($this->client
->getResponse()->getContent(), true);
899 $this->assertArrayHasKey('tags', $content);
900 $this->assertCount($nbTags - 1, $content['tags']);
903 public function testSaveIsArchivedAfterPost()
905 $entry = $this->client
->getContainer()
906 ->get('doctrine.orm.entity_manager')
907 ->getRepository('WallabagCoreBundle:Entry')
908 ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]);
911 $this->markTestSkipped('No content found in db.');
914 $this->client
->request('POST', '/api/entries.json', [
915 'url' => $entry->getUrl(),
918 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
920 $content = json_decode($this->client
->getResponse()->getContent(), true);
922 $this->assertSame(1, $content['is_archived']);
925 public function testSaveIsStarredAfterPost()
927 $entry = $this->client
->getContainer()
928 ->get('doctrine.orm.entity_manager')
929 ->getRepository('WallabagCoreBundle:Entry')
930 ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]);
933 $this->markTestSkipped('No content found in db.');
936 $this->client
->request('POST', '/api/entries.json', [
937 'url' => $entry->getUrl(),
940 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
942 $content = json_decode($this->client
->getResponse()->getContent(), true);
944 $this->assertSame(1, $content['is_starred']);
947 public function testSaveIsArchivedAfterPatch()
949 $entry = $this->client
->getContainer()
950 ->get('doctrine.orm.entity_manager')
951 ->getRepository('WallabagCoreBundle:Entry')
952 ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]);
955 $this->markTestSkipped('No content found in db.');
958 $previousTitle = $entry->getTitle();
960 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
961 'title' => $entry->getTitle() . '++',
964 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
966 $content = json_decode($this->client
->getResponse()->getContent(), true);
968 $this->assertSame(1, $content['is_archived']);
969 $this->assertSame($previousTitle . '++', $content['title']);
972 public function testSaveIsStarredAfterPatch()
974 $now = new \
DateTime();
975 $entry = $this->client
->getContainer()
976 ->get('doctrine.orm.entity_manager')
977 ->getRepository('WallabagCoreBundle:Entry')
978 ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]);
981 $this->markTestSkipped('No content found in db.');
983 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
984 'title' => $entry->getTitle() . '++',
987 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
989 $content = json_decode($this->client
->getResponse()->getContent(), true);
991 $this->assertSame(1, $content['is_starred']);
992 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \
DateTime($content['starred_at']))->getTimestamp());
995 public function dataForEntriesExistWithUrl()
997 $url = hash('sha1', 'http://0.0.0.0/entry2');
1001 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1',
1002 'expectedValue' => 2,
1005 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2',
1006 'expectedValue' => true,
1008 'hashed_url_with_id' => [
1009 'url' => '/api/entries/exists?hashed_url=' . $url . '&return_id=1',
1010 'expectedValue' => 2,
1012 'hashed_url_without_id' => [
1013 'url' => '/api/entries/exists?hashed_url=' . $url . '',
1014 'expectedValue' => true,
1020 * @dataProvider dataForEntriesExistWithUrl
1022 public function testGetEntriesExists($url, $expectedValue)
1024 $this->client
->request('GET', $url);
1026 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1028 $content = json_decode($this->client
->getResponse()->getContent(), true);
1030 $this->assertSame($expectedValue, $content['exists']);
1033 public function testGetEntriesExistsWithManyUrls()
1035 $url1 = 'http://0.0.0.0/entry2';
1036 $url2 = 'http://0.0.0.0/entry10';
1038 $this->client
->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1');
1040 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1042 $content = json_decode($this->client
->getResponse()->getContent(), true);
1044 $this->assertArrayHasKey($url1, $content);
1045 $this->assertArrayHasKey($url2, $content);
1046 // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value
1047 $this->assertGreaterThan(1, $content[$url1]);
1048 $this->assertNull($content[$url2]);
1051 public function testGetEntriesExistsWithManyUrlsReturnBool()
1053 $url1 = 'http://0.0.0.0/entry2';
1054 $url2 = 'http://0.0.0.0/entry10';
1055 $this->client
->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2);
1057 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1059 $content = json_decode($this->client
->getResponse()->getContent(), true);
1061 $this->assertArrayHasKey($url1, $content);
1062 $this->assertArrayHasKey($url2, $content);
1063 $this->assertTrue($content[$url1]);
1064 $this->assertFalse($content[$url2]);
1067 public function testGetEntriesExistsWithManyUrlsHashed()
1069 $url1 = 'http://0.0.0.0/entry2';
1070 $url2 = 'http://0.0.0.0/entry10';
1071 $this->client
->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('sha1', $url1) . '&hashed_urls[]=' . hash('sha1', $url2) . '&return_id=1');
1073 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1075 $content = json_decode($this->client
->getResponse()->getContent(), true);
1077 $this->assertArrayHasKey(hash('sha1', $url1), $content);
1078 $this->assertArrayHasKey(hash('sha1', $url2), $content);
1079 $this->assertSame(2, $content[hash('sha1', $url1)]);
1080 $this->assertNull($content[hash('sha1', $url2)]);
1083 public function testGetEntriesExistsWithManyUrlsHashedReturnBool()
1085 $url1 = 'http://0.0.0.0/entry2';
1086 $url2 = 'http://0.0.0.0/entry10';
1087 $this->client
->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('sha1', $url1) . '&hashed_urls[]=' . hash('sha1', $url2));
1089 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1091 $content = json_decode($this->client
->getResponse()->getContent(), true);
1093 $this->assertArrayHasKey(hash('sha1', $url1), $content);
1094 $this->assertArrayHasKey(hash('sha1', $url2), $content);
1095 $this->assertTrue($content[hash('sha1', $url1)]);
1096 $this->assertFalse($content[hash('sha1', $url2)]);
1099 public function testGetEntriesExistsWhichDoesNotExists()
1101 $this->client
->request('GET', '/api/entries/exists?url=http://google.com/entry2');
1103 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1105 $content = json_decode($this->client
->getResponse()->getContent(), true);
1107 $this->assertFalse($content['exists']);
1110 public function testGetEntriesExistsWhichDoesNotExistsWithHashedUrl()
1112 $this->client
->request('GET', '/api/entries/exists?hashed_url=' . hash('sha1', 'http://google.com/entry2'));
1114 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1116 $content = json_decode($this->client
->getResponse()->getContent(), true);
1118 $this->assertFalse($content['exists']);
1121 public function testGetEntriesExistsWithNoUrl()
1123 $this->client
->request('GET', '/api/entries/exists?url=');
1125 $this->assertSame(403, $this->client
->getResponse()->getStatusCode());
1128 public function testGetEntriesExistsWithNoHashedUrl()
1130 $this->client
->request('GET', '/api/entries/exists?hashed_url=');
1132 $this->assertSame(403, $this->client
->getResponse()->getStatusCode());
1135 public function testReloadEntryErrorWhileFetching()
1137 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
1138 ->getRepository('WallabagCoreBundle:Entry')
1139 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
1142 $this->markTestSkipped('No content found in db.');
1145 $this->client
->request('PATCH', '/api/entries/' . $entry->getId() . '/reload.json');
1146 $this->assertSame(304, $this->client
->getResponse()->getStatusCode());
1149 public function testReloadEntry()
1151 $this->client
->request('POST', '/api/entries.json', [
1152 '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',
1154 'tags' => 'google, apple',
1157 $json = json_decode($this->client
->getResponse()->getContent(), true);
1161 $this->client
->request('PATCH', '/api/entries/' . $json['id'] . '/reload.json');
1162 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1164 $content = json_decode($this->client
->getResponse()->getContent(), true);
1166 $this->assertNotEmpty($content['title']);
1168 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
1171 public function testPostEntriesTagsListAction()
1173 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
1174 ->getRepository('WallabagCoreBundle:Entry')
1175 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
1177 $tags = $entry->getTags();
1179 $this->assertCount(2, $tags);
1183 'url' => 'http://0.0.0.0/entry4',
1184 'tags' => 'new tag 1, new tag 2',
1188 $this->client
->request('POST', '/api/entries/tags/lists?list=' . json_encode($list));
1190 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1192 $content = json_decode($this->client
->getResponse()->getContent(), true);
1194 $this->assertInternalType('int', $content[0]['entry']);
1195 $this->assertSame('http://0.0.0.0/entry4', $content[0]['url']);
1197 $entry = $this->client
->getContainer()->get('doctrine.orm.entity_manager')
1198 ->getRepository('WallabagCoreBundle:Entry')
1199 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
1201 $tags = $entry->getTags();
1202 $this->assertCount(4, $tags);
1205 public function testPostEntriesTagsListActionNoList()
1207 $this->client
->request('POST', '/api/entries/tags/lists?list=' . json_encode([]));
1209 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1211 $content = json_decode($this->client
->getResponse()->getContent(), true);
1213 $this->assertEmpty($content);
1216 public function testDeleteEntriesTagsListAction()
1218 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
1219 $entry = new Entry($em->getReference(User
::class, $this->getUserId()));
1220 $entry->setUrl('http://0.0.0.0/test-entry');
1221 $entry->addTag((new Tag())->setLabel('foo-tag'));
1222 $entry->addTag((new Tag())->setLabel('bar-tag'));
1223 $em->persist($entry);
1230 'url' => 'http://0.0.0.0/test-entry',
1231 'tags' => 'foo-tag, bar-tag',
1235 $this->client
->request('DELETE', '/api/entries/tags/list?list=' . json_encode($list));
1236 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1238 $entry = $em->getRepository('WallabagCoreBundle:Entry')->find($entry->getId());
1239 $this->assertCount(0, $entry->getTags());
1242 public function testDeleteEntriesTagsListActionNoList()
1244 $this->client
->request('DELETE', '/api/entries/tags/list?list=' . json_encode([]));
1246 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1248 $content = json_decode($this->client
->getResponse()->getContent(), true);
1250 $this->assertEmpty($content);
1253 public function testPostEntriesListAction()
1256 'https://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html',
1257 'http://0.0.0.0/entry2',
1260 $this->client
->request('POST', '/api/entries/lists?urls=' . json_encode($list));
1262 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1264 $content = json_decode($this->client
->getResponse()->getContent(), true);
1266 $this->assertInternalType('int', $content[0]['entry']);
1267 $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']);
1269 $this->assertInternalType('int', $content[1]['entry']);
1270 $this->assertSame('http://0.0.0.0/entry2', $content[1]['url']);
1273 public function testPostEntriesListActionWithNoUrls()
1275 $this->client
->request('POST', '/api/entries/lists?urls=' . json_encode([]));
1277 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1279 $content = json_decode($this->client
->getResponse()->getContent(), true);
1281 $this->assertEmpty($content);
1284 public function testDeleteEntriesListAction()
1286 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
1287 $em->persist((new Entry($em->getReference(User
::class, $this->getUserId())))->setUrl('http://0.0.0.0/test-entry1'));
1292 'http://0.0.0.0/test-entry1',
1293 'http://0.0.0.0/test-entry-not-exist',
1296 $this->client
->request('DELETE', '/api/entries/list?urls=' . json_encode($list));
1298 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1300 $content = json_decode($this->client
->getResponse()->getContent(), true);
1302 $this->assertTrue($content[0]['entry']);
1303 $this->assertSame('http://0.0.0.0/test-entry1', $content[0]['url']);
1305 $this->assertFalse($content[1]['entry']);
1306 $this->assertSame('http://0.0.0.0/test-entry-not-exist', $content[1]['url']);
1309 public function testDeleteEntriesListActionWithNoUrls()
1311 $this->client
->request('DELETE', '/api/entries/list?urls=' . json_encode([]));
1313 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1315 $content = json_decode($this->client
->getResponse()->getContent(), true);
1317 $this->assertEmpty($content);
1320 public function testLimitBulkAction()
1323 'http://0.0.0.0/entry1',
1324 'http://0.0.0.0/entry1',
1325 'http://0.0.0.0/entry1',
1326 'http://0.0.0.0/entry1',
1327 'http://0.0.0.0/entry1',
1328 'http://0.0.0.0/entry1',
1329 'http://0.0.0.0/entry1',
1330 'http://0.0.0.0/entry1',
1331 'http://0.0.0.0/entry1',
1332 'http://0.0.0.0/entry1',
1333 'http://0.0.0.0/entry1',
1336 $this->client
->request('POST', '/api/entries/lists?urls=' . json_encode($list));
1338 $this->assertSame(400, $this->client
->getResponse()->getStatusCode());
1339 $this->assertContains('API limit reached', $this->client
->getResponse()->getContent());
1342 public function testRePostEntryAndReUsePublishedAt()
1344 $em = $this->client
->getContainer()->get('doctrine.orm.entity_manager');
1345 $entry = new Entry($em->getReference(User
::class, $this->getUserId()));
1346 $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »');
1347 $entry->setContent('hihi');
1348 $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');
1349 $entry->setPublishedAt(new \
DateTime('2017-06-26T07:46:02+0200'));
1350 $em->persist($entry);
1354 $this->client
->request('POST', '/api/entries.json', [
1355 'url' => 'https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html',
1358 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
1360 $content = json_decode($this->client
->getResponse()->getContent(), true);
1362 $this->assertGreaterThan(0, $content['id']);
1363 $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']);