]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
176da3cd8b7192eb8b146953a79fc23fdc99afa5
[github/wallabag/wallabag.git] / tests / Wallabag / ApiBundle / Controller / EntryRestControllerTest.php
1 <?php
2
3 namespace Tests\Wallabag\ApiBundle\Controller;
4
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;
10
11 class EntryRestControllerTest extends WallabagApiTestCase
12 {
13 public function testGetOneEntry()
14 {
15 $entry = $this->client->getContainer()
16 ->get('doctrine.orm.entity_manager')
17 ->getRepository('WallabagCoreBundle:Entry')
18 ->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]);
19
20 if (!$entry) {
21 $this->markTestSkipped('No content found in db.');
22 }
23
24 $this->client->request('GET', '/api/entries/' . $entry->getId() . '.json');
25 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
26
27 $content = json_decode($this->client->getResponse()->getContent(), true);
28
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']);
35
36 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
37 }
38
39 public function testGetOneEntryWithOriginUrl()
40 {
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']);
45
46 if (!$entry) {
47 $this->markTestSkipped('No content found in db.');
48 }
49
50 $this->client->request('GET', '/api/entries/' . $entry->getId() . '.json');
51 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
52
53 $content = json_decode($this->client->getResponse()->getContent(), true);
54
55 $this->assertSame($entry->getOriginUrl(), $content['origin_url']);
56 }
57
58 public function testExportEntry()
59 {
60 $entry = $this->client->getContainer()
61 ->get('doctrine.orm.entity_manager')
62 ->getRepository('WallabagCoreBundle:Entry')
63 ->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]);
64
65 if (!$entry) {
66 $this->markTestSkipped('No content found in db.');
67 }
68
69 $this->client->request('GET', '/api/entries/' . $entry->getId() . '/export.epub');
70 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
71
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'));
75
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());
80
81 $this->assertSame('application/x-mobipocket-ebook', $client->getResponse()->headers->get('Content-Type'));
82
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());
87
88 $this->assertContains('PDF-', $client->getResponse()->getContent());
89 $this->assertSame('application/pdf', $client->getResponse()->headers->get('Content-Type'));
90
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());
95
96 $this->assertContains('text/plain', $client->getResponse()->headers->get('Content-Type'));
97
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());
102
103 $this->assertContains('application/csv', $client->getResponse()->headers->get('Content-Type'));
104 }
105
106 public function testGetOneEntryWrongUser()
107 {
108 $entry = $this->client->getContainer()
109 ->get('doctrine.orm.entity_manager')
110 ->getRepository('WallabagCoreBundle:Entry')
111 ->findOneBy(['user' => $this->getUserId('bob'), 'isArchived' => false]);
112
113 if (!$entry) {
114 $this->markTestSkipped('No content found in db.');
115 }
116
117 $this->client->request('GET', '/api/entries/' . $entry->getId() . '.json');
118
119 $this->assertSame(403, $this->client->getResponse()->getStatusCode());
120 }
121
122 public function testGetEntries()
123 {
124 $this->client->request('GET', '/api/entries');
125
126 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
127
128 $content = json_decode($this->client->getResponse()->getContent(), true);
129
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']);
135
136 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
137 }
138
139 public function testGetEntriesWithFullOptions()
140 {
141 $this->client->request('GET', '/api/entries', [
142 'archive' => 1,
143 'starred' => 1,
144 'sort' => 'updated',
145 'order' => 'asc',
146 'page' => 1,
147 'perPage' => 2,
148 'tags' => 'foo',
149 'since' => 1443274283,
150 'public' => 0,
151 ]);
152
153 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
154
155 $content = json_decode($this->client->getResponse()->getContent(), true);
156
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']);
163
164 $this->assertArrayHasKey('_links', $content);
165 $this->assertArrayHasKey('self', $content['_links']);
166 $this->assertArrayHasKey('first', $content['_links']);
167 $this->assertArrayHasKey('last', $content['_links']);
168
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']);
178 }
179
180 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
181 }
182
183 public function testGetEntriesPublicOnly()
184 {
185 $entry = $this->client->getContainer()
186 ->get('doctrine.orm.entity_manager')
187 ->getRepository('WallabagCoreBundle:Entry')
188 ->findOneByUser($this->getUserId());
189
190 if (!$entry) {
191 $this->markTestSkipped('No content found in db.');
192 }
193
194 // generate at least one public entry
195 $entry->generateUid();
196
197 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
198 $em->persist($entry);
199 $em->flush();
200
201 $this->client->request('GET', '/api/entries', [
202 'public' => 1,
203 ]);
204
205 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
206
207 $content = json_decode($this->client->getResponse()->getContent(), true);
208
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']);
215
216 $this->assertArrayHasKey('_links', $content);
217 $this->assertArrayHasKey('self', $content['_links']);
218 $this->assertArrayHasKey('first', $content['_links']);
219 $this->assertArrayHasKey('last', $content['_links']);
220
221 foreach (['self', 'first', 'last'] as $link) {
222 $this->assertArrayHasKey('href', $content['_links'][$link]);
223 $this->assertContains('public=1', $content['_links'][$link]['href']);
224 }
225
226 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
227 }
228
229 public function testGetEntriesOnPageTwo()
230 {
231 $this->client->request('GET', '/api/entries', [
232 'page' => 2,
233 'perPage' => 2,
234 ]);
235
236 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
237
238 $content = json_decode($this->client->getResponse()->getContent(), true);
239
240 $this->assertGreaterThanOrEqual(0, $content['total']);
241 $this->assertSame(2, $content['page']);
242 $this->assertSame(2, $content['limit']);
243 }
244
245 public function testGetStarredEntries()
246 {
247 $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);
248
249 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
250
251 $content = json_decode($this->client->getResponse()->getContent(), true);
252
253 $this->assertGreaterThanOrEqual(1, \count($content));
254 $this->assertNotEmpty($content['_embedded']['items']);
255 $this->assertGreaterThanOrEqual(1, $content['total']);
256 $this->assertSame(1, $content['page']);
257 $this->assertGreaterThanOrEqual(1, $content['pages']);
258
259 $this->assertArrayHasKey('_links', $content);
260 $this->assertArrayHasKey('self', $content['_links']);
261 $this->assertArrayHasKey('first', $content['_links']);
262 $this->assertArrayHasKey('last', $content['_links']);
263
264 foreach (['self', 'first', 'last'] as $link) {
265 $this->assertArrayHasKey('href', $content['_links'][$link]);
266 $this->assertContains('starred=1', $content['_links'][$link]['href']);
267 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
268 }
269
270 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
271 }
272
273 public function testGetArchiveEntries()
274 {
275 $this->client->request('GET', '/api/entries', ['archive' => 1]);
276
277 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
278
279 $content = json_decode($this->client->getResponse()->getContent(), true);
280
281 $this->assertGreaterThanOrEqual(1, \count($content));
282 $this->assertNotEmpty($content['_embedded']['items']);
283 $this->assertGreaterThanOrEqual(1, $content['total']);
284 $this->assertSame(1, $content['page']);
285 $this->assertGreaterThanOrEqual(1, $content['pages']);
286
287 $this->assertArrayHasKey('_links', $content);
288 $this->assertArrayHasKey('self', $content['_links']);
289 $this->assertArrayHasKey('first', $content['_links']);
290 $this->assertArrayHasKey('last', $content['_links']);
291
292 foreach (['self', 'first', 'last'] as $link) {
293 $this->assertArrayHasKey('href', $content['_links'][$link]);
294 $this->assertContains('archive=1', $content['_links'][$link]['href']);
295 }
296
297 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
298 }
299
300 public function testGetTaggedEntries()
301 {
302 $this->client->request('GET', '/api/entries', ['tags' => 'foo,bar']);
303
304 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
305
306 $content = json_decode($this->client->getResponse()->getContent(), true);
307
308 $this->assertGreaterThanOrEqual(1, \count($content));
309 $this->assertNotEmpty($content['_embedded']['items']);
310 $this->assertGreaterThanOrEqual(1, $content['total']);
311 $this->assertSame(1, $content['page']);
312 $this->assertGreaterThanOrEqual(1, $content['pages']);
313
314 $this->assertContains('foo', array_column($content['_embedded']['items'][0]['tags'], 'label'), 'Entries tags should have "foo" tag');
315 $this->assertContains('bar', array_column($content['_embedded']['items'][0]['tags'], 'label'), 'Entries tags should have "bar" tag');
316
317 $this->assertArrayHasKey('_links', $content);
318 $this->assertArrayHasKey('self', $content['_links']);
319 $this->assertArrayHasKey('first', $content['_links']);
320 $this->assertArrayHasKey('last', $content['_links']);
321
322 foreach (['self', 'first', 'last'] as $link) {
323 $this->assertArrayHasKey('href', $content['_links'][$link]);
324 $this->assertContains('tags=' . urlencode('foo,bar'), $content['_links'][$link]['href']);
325 }
326
327 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
328 }
329
330 public function testGetTaggedEntriesWithBadParams()
331 {
332 $this->client->request('GET', '/api/entries', ['tags' => ['foo', 'bar']]);
333
334 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
335 }
336
337 public function testGetDatedEntries()
338 {
339 $this->client->request('GET', '/api/entries', ['since' => 1443274283]);
340
341 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
342
343 $content = json_decode($this->client->getResponse()->getContent(), true);
344
345 $this->assertGreaterThanOrEqual(1, \count($content));
346 $this->assertNotEmpty($content['_embedded']['items']);
347 $this->assertGreaterThanOrEqual(1, $content['total']);
348 $this->assertSame(1, $content['page']);
349 $this->assertGreaterThanOrEqual(1, $content['pages']);
350
351 $this->assertArrayHasKey('_links', $content);
352 $this->assertArrayHasKey('self', $content['_links']);
353 $this->assertArrayHasKey('first', $content['_links']);
354 $this->assertArrayHasKey('last', $content['_links']);
355
356 foreach (['self', 'first', 'last'] as $link) {
357 $this->assertArrayHasKey('href', $content['_links'][$link]);
358 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
359 }
360
361 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
362 }
363
364 public function testGetDatedSupEntries()
365 {
366 $future = new \DateTime(date('Y-m-d H:i:s'));
367 $this->client->request('GET', '/api/entries', ['since' => $future->getTimestamp() + 1000]);
368
369 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
370
371 $content = json_decode($this->client->getResponse()->getContent(), true);
372
373 $this->assertGreaterThanOrEqual(1, \count($content));
374 $this->assertEmpty($content['_embedded']['items']);
375 $this->assertSame(0, $content['total']);
376 $this->assertSame(1, $content['page']);
377 $this->assertSame(1, $content['pages']);
378
379 $this->assertArrayHasKey('_links', $content);
380 $this->assertArrayHasKey('self', $content['_links']);
381 $this->assertArrayHasKey('first', $content['_links']);
382 $this->assertArrayHasKey('last', $content['_links']);
383
384 foreach (['self', 'first', 'last'] as $link) {
385 $this->assertArrayHasKey('href', $content['_links'][$link]);
386 $this->assertContains('since=' . ($future->getTimestamp() + 1000), $content['_links'][$link]['href']);
387 }
388
389 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
390 }
391
392 public function testDeleteEntry()
393 {
394 $entry = $this->client->getContainer()
395 ->get('doctrine.orm.entity_manager')
396 ->getRepository('WallabagCoreBundle:Entry')
397 ->findOneByUser($this->getUserId(), ['id' => 'asc']);
398
399 if (!$entry) {
400 $this->markTestSkipped('No content found in db.');
401 }
402
403 $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json');
404
405 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
406
407 $content = json_decode($this->client->getResponse()->getContent(), true);
408
409 $this->assertSame($entry->getTitle(), $content['title']);
410 $this->assertSame($entry->getUrl(), $content['url']);
411 $this->assertSame($entry->getId(), $content['id']);
412
413 // We'll try to delete this entry again
414 $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json');
415
416 $this->assertSame(404, $this->client->getResponse()->getStatusCode());
417 }
418
419 public function testPostEntry()
420 {
421 $this->client->request('POST', '/api/entries.json', [
422 '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',
423 'tags' => 'google',
424 'title' => 'New title for my article',
425 'content' => 'my content',
426 'language' => 'de',
427 'published_at' => '2016-09-08T11:55:58+0200',
428 'authors' => 'bob,helen',
429 'public' => 1,
430 ]);
431
432 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
433
434 $content = json_decode($this->client->getResponse()->getContent(), true);
435
436 $this->assertGreaterThan(0, $content['id']);
437 $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']);
438 $this->assertSame(0, $content['is_archived']);
439 $this->assertSame(0, $content['is_starred']);
440 $this->assertNull($content['starred_at']);
441 $this->assertNull($content['archived_at']);
442 $this->assertSame('New title for my article', $content['title']);
443 $this->assertSame($this->getUserId(), $content['user_id']);
444 $this->assertCount(2, $content['tags']);
445 $this->assertNull($content['origin_url']);
446 $this->assertSame('my content', $content['content']);
447 $this->assertSame('de', $content['language']);
448 $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']);
449 $this->assertCount(2, $content['published_by']);
450 $this->assertContains('bob', $content['published_by']);
451 $this->assertContains('helen', $content['published_by']);
452 $this->assertTrue($content['is_public'], 'A public link has been generated for that entry');
453 }
454
455 public function testPostSameEntry()
456 {
457 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
458 $entry = new Entry($em->getReference(User::class, $this->getUserId()));
459 $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');
460 $entry->setArchived(true);
461 $entry->addTag((new Tag())->setLabel('google'));
462 $entry->addTag((new Tag())->setLabel('apple'));
463 $em->persist($entry);
464 $em->flush();
465 $em->clear();
466
467 $this->client->request('POST', '/api/entries.json', [
468 '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',
469 'archive' => '1',
470 'tags' => 'google, apple',
471 ]);
472
473 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
474
475 $content = json_decode($this->client->getResponse()->getContent(), true);
476
477 $this->assertGreaterThan(0, $content['id']);
478 $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']);
479 $this->assertSame(1, $content['is_archived']);
480 $this->assertSame(0, $content['is_starred']);
481 $this->assertCount(3, $content['tags']);
482 }
483
484 public function testPostEntryWhenFetchContentFails()
485 {
486 /** @var \Symfony\Component\DependencyInjection\Container $container */
487 $container = $this->client->getContainer();
488 $contentProxy = $this->getMockBuilder(ContentProxy::class)
489 ->disableOriginalConstructor()
490 ->setMethods(['updateEntry'])
491 ->getMock();
492 $contentProxy->expects($this->any())
493 ->method('updateEntry')
494 ->willThrowException(new \Exception('Test Fetch content fails'));
495 $container->set('wallabag_core.content_proxy', $contentProxy);
496
497 try {
498 $this->client->request('POST', '/api/entries.json', [
499 'url' => 'http://www.example.com/',
500 ]);
501
502 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
503 $content = json_decode($this->client->getResponse()->getContent(), true);
504 $this->assertGreaterThan(0, $content['id']);
505 $this->assertSame('http://www.example.com/', $content['url']);
506 $this->assertSame('www.example.com', $content['domain_name']);
507 $this->assertSame('www.example.com', $content['title']);
508 } finally {
509 // Remove the created entry to avoid side effects on other tests
510 if (isset($content['id'])) {
511 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
512 $entry = $em->getReference('WallabagCoreBundle:Entry', $content['id']);
513 $em->remove($entry);
514 $em->flush();
515 }
516 }
517 }
518
519 public function testPostArchivedAndStarredEntry()
520 {
521 $now = new \DateTime();
522 $this->client->request('POST', '/api/entries.json', [
523 'url' => 'https://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
524 'archive' => '1',
525 'starred' => '1',
526 ]);
527
528 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
529
530 $content = json_decode($this->client->getResponse()->getContent(), true);
531
532 $this->assertGreaterThan(0, $content['id']);
533 $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']);
534 $this->assertSame(1, $content['is_archived']);
535 $this->assertSame(1, $content['is_starred']);
536 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp());
537 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['archived_at']))->getTimestamp());
538 $this->assertSame($this->getUserId(), $content['user_id']);
539 }
540
541 public function testPostArchivedAndStarredEntryWithoutQuotes()
542 {
543 $this->client->request('POST', '/api/entries.json', [
544 'url' => 'https://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
545 'archive' => 0,
546 'starred' => 1,
547 ]);
548
549 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
550
551 $content = json_decode($this->client->getResponse()->getContent(), true);
552
553 $this->assertGreaterThan(0, $content['id']);
554 $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']);
555 $this->assertSame(0, $content['is_archived']);
556 $this->assertSame(1, $content['is_starred']);
557 }
558
559 public function testPostEntryWithOriginUrl()
560 {
561 $this->client->request('POST', '/api/entries.json', [
562 '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',
563 'tags' => 'google',
564 'title' => 'New title for my article',
565 'content' => 'my content',
566 'language' => 'de',
567 'published_at' => '2016-09-08T11:55:58+0200',
568 'authors' => 'bob,helen',
569 'public' => 1,
570 'origin_url' => 'http://mysource.tld',
571 ]);
572
573 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
574
575 $content = json_decode($this->client->getResponse()->getContent(), true);
576
577 $this->assertGreaterThan(0, $content['id']);
578 $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']);
579 $this->assertSame('http://mysource.tld', $content['origin_url']);
580 }
581
582 public function testPatchEntry()
583 {
584 $entry = $this->client->getContainer()
585 ->get('doctrine.orm.entity_manager')
586 ->getRepository('WallabagCoreBundle:Entry')
587 ->findOneByUser($this->getUserId());
588
589 if (!$entry) {
590 $this->markTestSkipped('No content found in db.');
591 }
592
593 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
594 'title' => 'New awesome title',
595 'tags' => 'new tag ' . uniqid(),
596 'starred' => '1',
597 'archive' => '0',
598 'language' => 'de_AT',
599 'preview_picture' => 'http://preview.io/picture.jpg',
600 'authors' => 'bob,sponge',
601 'content' => 'awesome',
602 'public' => 0,
603 'published_at' => 1488833381,
604 ]);
605
606 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
607
608 $content = json_decode($this->client->getResponse()->getContent(), true);
609
610 $this->assertSame($entry->getId(), $content['id']);
611 $this->assertSame($entry->getUrl(), $content['url']);
612 $this->assertSame('New awesome title', $content['title']);
613 $this->assertGreaterThanOrEqual(1, \count($content['tags']), 'We force only one tag');
614 $this->assertSame($this->getUserId(), $content['user_id']);
615 $this->assertSame('de_AT', $content['language']);
616 $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']);
617 $this->assertContains('sponge', $content['published_by']);
618 $this->assertContains('bob', $content['published_by']);
619 $this->assertSame('awesome', $content['content']);
620 $this->assertFalse($content['is_public'], 'Entry is no more shared');
621 $this->assertContains('2017-03-06', $content['published_at']);
622 }
623
624 public function testPatchEntryWithoutQuotes()
625 {
626 $entry = $this->client->getContainer()
627 ->get('doctrine.orm.entity_manager')
628 ->getRepository('WallabagCoreBundle:Entry')
629 ->findOneByUser($this->getUserId());
630
631 if (!$entry) {
632 $this->markTestSkipped('No content found in db.');
633 }
634
635 $previousContent = $entry->getContent();
636 $previousLanguage = $entry->getLanguage();
637
638 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
639 'title' => 'New awesome title',
640 'tags' => 'new tag ' . uniqid(),
641 'starred' => 1,
642 'archive' => 0,
643 'authors' => ['bob', 'sponge'],
644 ]);
645
646 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
647
648 $content = json_decode($this->client->getResponse()->getContent(), true);
649
650 $this->assertSame($entry->getId(), $content['id']);
651 $this->assertSame($entry->getUrl(), $content['url']);
652 $this->assertGreaterThanOrEqual(1, \count($content['tags']), 'We force only one tag');
653 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
654 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
655 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
656 }
657
658 public function testPatchEntryWithOriginUrl()
659 {
660 $entry = $this->client->getContainer()
661 ->get('doctrine.orm.entity_manager')
662 ->getRepository('WallabagCoreBundle:Entry')
663 ->findOneByUser($this->getUserId());
664
665 if (!$entry) {
666 $this->markTestSkipped('No content found in db.');
667 }
668
669 $previousContent = $entry->getContent();
670 $previousLanguage = $entry->getLanguage();
671
672 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
673 'title' => 'Another awesome title just for profit',
674 'origin_url' => 'https://myawesomesource.example.com',
675 ]);
676
677 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
678
679 $content = json_decode($this->client->getResponse()->getContent(), true);
680
681 $this->assertSame($entry->getId(), $content['id']);
682 $this->assertSame($entry->getUrl(), $content['url']);
683 $this->assertSame('https://myawesomesource.example.com', $content['origin_url']);
684 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
685 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
686 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
687 }
688
689 public function testPatchEntryRemoveOriginUrl()
690 {
691 $entry = $this->client->getContainer()
692 ->get('doctrine.orm.entity_manager')
693 ->getRepository('WallabagCoreBundle:Entry')
694 ->findOneByUser($this->getUserId());
695
696 if (!$entry) {
697 $this->markTestSkipped('No content found in db.');
698 }
699
700 $previousContent = $entry->getContent();
701 $previousLanguage = $entry->getLanguage();
702 $previousTitle = $entry->getTitle();
703
704 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
705 'origin_url' => '',
706 ]);
707
708 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
709
710 $content = json_decode($this->client->getResponse()->getContent(), true);
711
712 $this->assertSame($entry->getId(), $content['id']);
713 $this->assertSame($entry->getUrl(), $content['url']);
714 $this->assertEmpty($content['origin_url']);
715 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
716 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
717 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
718 $this->assertSame($previousTitle, $content['title'], 'Ensure title has not moved');
719 }
720
721 public function testPatchEntryNullOriginUrl()
722 {
723 $entry = $this->client->getContainer()
724 ->get('doctrine.orm.entity_manager')
725 ->getRepository('WallabagCoreBundle:Entry')
726 ->findOneByUser($this->getUserId());
727
728 if (!$entry) {
729 $this->markTestSkipped('No content found in db.');
730 }
731
732 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
733 'origin_url' => null,
734 ]);
735
736 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
737
738 $content = json_decode($this->client->getResponse()->getContent(), true);
739
740 $this->assertNull($content['origin_url']);
741 }
742
743 public function testGetTagsEntry()
744 {
745 $entry = $this->client->getContainer()
746 ->get('doctrine.orm.entity_manager')
747 ->getRepository('WallabagCoreBundle:Entry')
748 ->findOneWithTags($this->user->getId());
749
750 $entry = $entry[0];
751
752 if (!$entry) {
753 $this->markTestSkipped('No content found in db.');
754 }
755
756 $tags = [];
757 foreach ($entry->getTags() as $tag) {
758 $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()];
759 }
760
761 $this->client->request('GET', '/api/entries/' . $entry->getId() . '/tags');
762
763 $this->assertSame(json_encode($tags, JSON_HEX_QUOT), $this->client->getResponse()->getContent());
764 }
765
766 public function testPostTagsOnEntry()
767 {
768 $entry = $this->client->getContainer()
769 ->get('doctrine.orm.entity_manager')
770 ->getRepository('WallabagCoreBundle:Entry')
771 ->findOneByUser($this->getUserId());
772
773 if (!$entry) {
774 $this->markTestSkipped('No content found in db.');
775 }
776
777 $nbTags = \count($entry->getTags());
778
779 $newTags = 'tag1,tag2,tag3';
780
781 $this->client->request('POST', '/api/entries/' . $entry->getId() . '/tags', ['tags' => $newTags]);
782
783 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
784
785 $content = json_decode($this->client->getResponse()->getContent(), true);
786
787 $this->assertArrayHasKey('tags', $content);
788 $this->assertSame($nbTags + 3, \count($content['tags']));
789
790 $entryDB = $this->client->getContainer()
791 ->get('doctrine.orm.entity_manager')
792 ->getRepository('WallabagCoreBundle:Entry')
793 ->find($entry->getId());
794
795 $tagsInDB = [];
796 foreach ($entryDB->getTags()->toArray() as $tag) {
797 $tagsInDB[$tag->getId()] = $tag->getLabel();
798 }
799
800 foreach (explode(',', $newTags) as $tag) {
801 $this->assertContains($tag, $tagsInDB);
802 }
803 }
804
805 public function testDeleteOneTagEntry()
806 {
807 $entry = $this->client->getContainer()
808 ->get('doctrine.orm.entity_manager')
809 ->getRepository('WallabagCoreBundle:Entry')
810 ->findOneWithTags($this->user->getId());
811 $entry = $entry[0];
812
813 if (!$entry) {
814 $this->markTestSkipped('No content found in db.');
815 }
816
817 // hydrate the tags relations
818 $nbTags = \count($entry->getTags());
819 $tag = $entry->getTags()[0];
820
821 $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '/tags/' . $tag->getId() . '.json');
822
823 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
824
825 $content = json_decode($this->client->getResponse()->getContent(), true);
826
827 $this->assertArrayHasKey('tags', $content);
828 $this->assertSame($nbTags - 1, \count($content['tags']));
829 }
830
831 public function testSaveIsArchivedAfterPost()
832 {
833 $entry = $this->client->getContainer()
834 ->get('doctrine.orm.entity_manager')
835 ->getRepository('WallabagCoreBundle:Entry')
836 ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]);
837
838 if (!$entry) {
839 $this->markTestSkipped('No content found in db.');
840 }
841
842 $this->client->request('POST', '/api/entries.json', [
843 'url' => $entry->getUrl(),
844 ]);
845
846 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
847
848 $content = json_decode($this->client->getResponse()->getContent(), true);
849
850 $this->assertSame(1, $content['is_archived']);
851 }
852
853 public function testSaveIsStarredAfterPost()
854 {
855 $entry = $this->client->getContainer()
856 ->get('doctrine.orm.entity_manager')
857 ->getRepository('WallabagCoreBundle:Entry')
858 ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]);
859
860 if (!$entry) {
861 $this->markTestSkipped('No content found in db.');
862 }
863
864 $this->client->request('POST', '/api/entries.json', [
865 'url' => $entry->getUrl(),
866 ]);
867
868 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
869
870 $content = json_decode($this->client->getResponse()->getContent(), true);
871
872 $this->assertSame(1, $content['is_starred']);
873 }
874
875 public function testSaveIsArchivedAfterPatch()
876 {
877 $entry = $this->client->getContainer()
878 ->get('doctrine.orm.entity_manager')
879 ->getRepository('WallabagCoreBundle:Entry')
880 ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]);
881
882 if (!$entry) {
883 $this->markTestSkipped('No content found in db.');
884 }
885
886 $previousTitle = $entry->getTitle();
887
888 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
889 'title' => $entry->getTitle() . '++',
890 ]);
891
892 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
893
894 $content = json_decode($this->client->getResponse()->getContent(), true);
895
896 $this->assertSame(1, $content['is_archived']);
897 $this->assertSame($previousTitle . '++', $content['title']);
898 }
899
900 public function testSaveIsStarredAfterPatch()
901 {
902 $now = new \DateTime();
903 $entry = $this->client->getContainer()
904 ->get('doctrine.orm.entity_manager')
905 ->getRepository('WallabagCoreBundle:Entry')
906 ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]);
907
908 if (!$entry) {
909 $this->markTestSkipped('No content found in db.');
910 }
911 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
912 'title' => $entry->getTitle() . '++',
913 ]);
914
915 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
916
917 $content = json_decode($this->client->getResponse()->getContent(), true);
918
919 $this->assertSame(1, $content['is_starred']);
920 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp());
921 }
922
923 public function testGetEntriesExistsWithReturnId()
924 {
925 $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1');
926
927 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
928
929 $content = json_decode($this->client->getResponse()->getContent(), true);
930
931 // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value
932 $this->assertGreaterThan(1, $content['exists']);
933 }
934
935 public function testGetEntriesExistsWithoutReturnId()
936 {
937 $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
938
939 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
940
941 $content = json_decode($this->client->getResponse()->getContent(), true);
942
943 $this->assertSame(true, $content['exists']);
944 }
945
946 public function testGetEntriesExistsWithManyUrls()
947 {
948 $url1 = 'http://0.0.0.0/entry2';
949 $url2 = 'http://0.0.0.0/entry10';
950 $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1');
951
952 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
953
954 $content = json_decode($this->client->getResponse()->getContent(), true);
955
956 $this->assertArrayHasKey($url1, $content);
957 $this->assertArrayHasKey($url2, $content);
958 // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value
959 $this->assertGreaterThan(1, $content[$url1]);
960 $this->assertNull($content[$url2]);
961 }
962
963 public function testGetEntriesExistsWithManyUrlsReturnBool()
964 {
965 $url1 = 'http://0.0.0.0/entry2';
966 $url2 = 'http://0.0.0.0/entry10';
967 $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2);
968
969 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
970
971 $content = json_decode($this->client->getResponse()->getContent(), true);
972
973 $this->assertArrayHasKey($url1, $content);
974 $this->assertArrayHasKey($url2, $content);
975 $this->assertTrue($content[$url1]);
976 $this->assertFalse($content[$url2]);
977 }
978
979 public function testGetEntriesExistsWhichDoesNotExists()
980 {
981 $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2');
982
983 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
984
985 $content = json_decode($this->client->getResponse()->getContent(), true);
986
987 $this->assertFalse($content['exists']);
988 }
989
990 public function testGetEntriesExistsWithNoUrl()
991 {
992 $this->client->request('GET', '/api/entries/exists?url=');
993
994 $this->assertSame(403, $this->client->getResponse()->getStatusCode());
995 }
996
997 public function testReloadEntryErrorWhileFetching()
998 {
999 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
1000 ->getRepository('WallabagCoreBundle:Entry')
1001 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
1002
1003 if (!$entry) {
1004 $this->markTestSkipped('No content found in db.');
1005 }
1006
1007 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '/reload.json');
1008 $this->assertSame(304, $this->client->getResponse()->getStatusCode());
1009 }
1010
1011 public function testReloadEntry()
1012 {
1013 $this->client->request('POST', '/api/entries.json', [
1014 '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',
1015 'archive' => '1',
1016 'tags' => 'google, apple',
1017 ]);
1018
1019 $json = json_decode($this->client->getResponse()->getContent(), true);
1020
1021 $this->setUp();
1022
1023 $this->client->request('PATCH', '/api/entries/' . $json['id'] . '/reload.json');
1024 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1025
1026 $content = json_decode($this->client->getResponse()->getContent(), true);
1027
1028 $this->assertNotEmpty($content['title']);
1029
1030 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
1031 }
1032
1033 public function testPostEntriesTagsListAction()
1034 {
1035 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
1036 ->getRepository('WallabagCoreBundle:Entry')
1037 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
1038
1039 $tags = $entry->getTags();
1040
1041 $this->assertCount(2, $tags);
1042
1043 $list = [
1044 [
1045 'url' => 'http://0.0.0.0/entry4',
1046 'tags' => 'new tag 1, new tag 2',
1047 ],
1048 ];
1049
1050 $this->client->request('POST', '/api/entries/tags/lists?list=' . json_encode($list));
1051
1052 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1053
1054 $content = json_decode($this->client->getResponse()->getContent(), true);
1055
1056 $this->assertInternalType('int', $content[0]['entry']);
1057 $this->assertSame('http://0.0.0.0/entry4', $content[0]['url']);
1058
1059 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
1060 ->getRepository('WallabagCoreBundle:Entry')
1061 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
1062
1063 $tags = $entry->getTags();
1064 $this->assertCount(4, $tags);
1065 }
1066
1067 public function testPostEntriesTagsListActionNoList()
1068 {
1069 $this->client->request('POST', '/api/entries/tags/lists?list=' . json_encode([]));
1070
1071 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1072
1073 $content = json_decode($this->client->getResponse()->getContent(), true);
1074
1075 $this->assertEmpty($content);
1076 }
1077
1078 public function testDeleteEntriesTagsListAction()
1079 {
1080 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1081 $entry = new Entry($em->getReference(User::class, $this->getUserId()));
1082 $entry->setUrl('http://0.0.0.0/test-entry');
1083 $entry->addTag((new Tag())->setLabel('foo-tag'));
1084 $entry->addTag((new Tag())->setLabel('bar-tag'));
1085 $em->persist($entry);
1086 $em->flush();
1087
1088 $em->clear();
1089
1090 $list = [
1091 [
1092 'url' => 'http://0.0.0.0/test-entry',
1093 'tags' => 'foo-tag, bar-tag',
1094 ],
1095 ];
1096
1097 $this->client->request('DELETE', '/api/entries/tags/list?list=' . json_encode($list));
1098 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1099
1100 $entry = $em->getRepository('WallabagCoreBundle:Entry')->find($entry->getId());
1101 $this->assertCount(0, $entry->getTags());
1102 }
1103
1104 public function testDeleteEntriesTagsListActionNoList()
1105 {
1106 $this->client->request('DELETE', '/api/entries/tags/list?list=' . json_encode([]));
1107
1108 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1109
1110 $content = json_decode($this->client->getResponse()->getContent(), true);
1111
1112 $this->assertEmpty($content);
1113 }
1114
1115 public function testPostEntriesListAction()
1116 {
1117 $list = [
1118 'https://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html',
1119 'http://0.0.0.0/entry2',
1120 ];
1121
1122 $this->client->request('POST', '/api/entries/lists?urls=' . json_encode($list));
1123
1124 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1125
1126 $content = json_decode($this->client->getResponse()->getContent(), true);
1127
1128 $this->assertInternalType('int', $content[0]['entry']);
1129 $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']);
1130
1131 $this->assertInternalType('int', $content[1]['entry']);
1132 $this->assertSame('http://0.0.0.0/entry2', $content[1]['url']);
1133 }
1134
1135 public function testPostEntriesListActionWithNoUrls()
1136 {
1137 $this->client->request('POST', '/api/entries/lists?urls=' . json_encode([]));
1138
1139 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1140
1141 $content = json_decode($this->client->getResponse()->getContent(), true);
1142
1143 $this->assertEmpty($content);
1144 }
1145
1146 public function testDeleteEntriesListAction()
1147 {
1148 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1149 $em->persist((new Entry($em->getReference(User::class, $this->getUserId())))->setUrl('http://0.0.0.0/test-entry1'));
1150
1151 $em->flush();
1152 $em->clear();
1153 $list = [
1154 'http://0.0.0.0/test-entry1',
1155 'http://0.0.0.0/test-entry-not-exist',
1156 ];
1157
1158 $this->client->request('DELETE', '/api/entries/list?urls=' . json_encode($list));
1159
1160 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1161
1162 $content = json_decode($this->client->getResponse()->getContent(), true);
1163
1164 $this->assertTrue($content[0]['entry']);
1165 $this->assertSame('http://0.0.0.0/test-entry1', $content[0]['url']);
1166
1167 $this->assertFalse($content[1]['entry']);
1168 $this->assertSame('http://0.0.0.0/test-entry-not-exist', $content[1]['url']);
1169 }
1170
1171 public function testDeleteEntriesListActionWithNoUrls()
1172 {
1173 $this->client->request('DELETE', '/api/entries/list?urls=' . json_encode([]));
1174
1175 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1176
1177 $content = json_decode($this->client->getResponse()->getContent(), true);
1178
1179 $this->assertEmpty($content);
1180 }
1181
1182 public function testLimitBulkAction()
1183 {
1184 $list = [
1185 'http://0.0.0.0/entry1',
1186 'http://0.0.0.0/entry1',
1187 'http://0.0.0.0/entry1',
1188 'http://0.0.0.0/entry1',
1189 'http://0.0.0.0/entry1',
1190 'http://0.0.0.0/entry1',
1191 'http://0.0.0.0/entry1',
1192 'http://0.0.0.0/entry1',
1193 'http://0.0.0.0/entry1',
1194 'http://0.0.0.0/entry1',
1195 'http://0.0.0.0/entry1',
1196 ];
1197
1198 $this->client->request('POST', '/api/entries/lists?urls=' . json_encode($list));
1199
1200 $this->assertSame(400, $this->client->getResponse()->getStatusCode());
1201 $this->assertContains('API limit reached', $this->client->getResponse()->getContent());
1202 }
1203
1204 public function testRePostEntryAndReUsePublishedAt()
1205 {
1206 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1207 $entry = new Entry($em->getReference(User::class, $this->getUserId()));
1208 $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »');
1209 $entry->setContent('hihi');
1210 $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');
1211 $entry->setPublishedAt(new \DateTime('2017-06-26T07:46:02+0200'));
1212 $em->persist($entry);
1213 $em->flush();
1214 $em->clear();
1215
1216 $this->client->request('POST', '/api/entries.json', [
1217 'url' => 'https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html',
1218 ]);
1219
1220 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1221
1222 $content = json_decode($this->client->getResponse()->getContent(), true);
1223
1224 $this->assertGreaterThan(0, $content['id']);
1225 $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']);
1226 }
1227 }