]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
6b26376dbfb4a7709392a29e3d1dede3e3f3bc12
[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' => 1, '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' => 1, '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' => 1, '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' => 2, '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(1);
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(1, ['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(1, $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, 1));
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(1, $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(1);
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(1, $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(1);
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(1);
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(1);
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(1);
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(1);
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' => 1, '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' => 1, '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' => 1, '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' => 1, '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 dataForEntriesExistWithUrl()
924 {
925 return [
926 'with_id' => [
927 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1',
928 'expectedValue' => 2,
929 ],
930 'without_id' => [
931 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2',
932 'expectedValue' => true,
933 ],
934 ];
935 }
936
937 /**
938 * @dataProvider dataForEntriesExistWithUrl
939 */
940 public function testGetEntriesExists($url, $expectedValue)
941 {
942 $this->client->request('GET', $url);
943
944 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
945
946 $content = json_decode($this->client->getResponse()->getContent(), true);
947
948 $this->assertSame($expectedValue, $content['exists']);
949 }
950
951 public function testGetEntriesExistsWithManyUrls()
952 {
953 $url1 = 'http://0.0.0.0/entry2';
954 $url2 = 'http://0.0.0.0/entry10';
955 $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1');
956
957 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
958
959 $content = json_decode($this->client->getResponse()->getContent(), true);
960
961 $this->assertArrayHasKey($url1, $content);
962 $this->assertArrayHasKey($url2, $content);
963 $this->assertSame(2, $content[$url1]);
964 $this->assertNull($content[$url2]);
965 }
966
967 public function testGetEntriesExistsWithManyUrlsReturnBool()
968 {
969 $url1 = 'http://0.0.0.0/entry2';
970 $url2 = 'http://0.0.0.0/entry10';
971 $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2);
972
973 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
974
975 $content = json_decode($this->client->getResponse()->getContent(), true);
976
977 $this->assertArrayHasKey($url1, $content);
978 $this->assertArrayHasKey($url2, $content);
979 $this->assertTrue($content[$url1]);
980 $this->assertFalse($content[$url2]);
981 }
982
983 public function testGetEntriesExistsWhichDoesNotExists()
984 {
985 $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2');
986
987 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
988
989 $content = json_decode($this->client->getResponse()->getContent(), true);
990
991 $this->assertFalse($content['exists']);
992 }
993
994 public function testGetEntriesExistsWithNoUrl()
995 {
996 $this->client->request('GET', '/api/entries/exists?url=');
997
998 $this->assertSame(403, $this->client->getResponse()->getStatusCode());
999 }
1000
1001 public function testReloadEntryErrorWhileFetching()
1002 {
1003 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
1004 ->getRepository('WallabagCoreBundle:Entry')
1005 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
1006
1007 if (!$entry) {
1008 $this->markTestSkipped('No content found in db.');
1009 }
1010
1011 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '/reload.json');
1012 $this->assertSame(304, $this->client->getResponse()->getStatusCode());
1013 }
1014
1015 public function testReloadEntry()
1016 {
1017 $this->client->request('POST', '/api/entries.json', [
1018 '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',
1019 'archive' => '1',
1020 'tags' => 'google, apple',
1021 ]);
1022
1023 $json = json_decode($this->client->getResponse()->getContent(), true);
1024
1025 $this->setUp();
1026
1027 $this->client->request('PATCH', '/api/entries/' . $json['id'] . '/reload.json');
1028 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1029
1030 $content = json_decode($this->client->getResponse()->getContent(), true);
1031
1032 $this->assertNotEmpty($content['title']);
1033
1034 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
1035 }
1036
1037 public function testPostEntriesTagsListAction()
1038 {
1039 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
1040 ->getRepository('WallabagCoreBundle:Entry')
1041 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
1042
1043 $tags = $entry->getTags();
1044
1045 $this->assertCount(2, $tags);
1046
1047 $list = [
1048 [
1049 'url' => 'http://0.0.0.0/entry4',
1050 'tags' => 'new tag 1, new tag 2',
1051 ],
1052 ];
1053
1054 $this->client->request('POST', '/api/entries/tags/lists?list=' . json_encode($list));
1055
1056 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1057
1058 $content = json_decode($this->client->getResponse()->getContent(), true);
1059
1060 $this->assertInternalType('int', $content[0]['entry']);
1061 $this->assertSame('http://0.0.0.0/entry4', $content[0]['url']);
1062
1063 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
1064 ->getRepository('WallabagCoreBundle:Entry')
1065 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
1066
1067 $tags = $entry->getTags();
1068 $this->assertCount(4, $tags);
1069 }
1070
1071 public function testPostEntriesTagsListActionNoList()
1072 {
1073 $this->client->request('POST', '/api/entries/tags/lists?list=' . json_encode([]));
1074
1075 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1076
1077 $content = json_decode($this->client->getResponse()->getContent(), true);
1078
1079 $this->assertEmpty($content);
1080 }
1081
1082 public function testDeleteEntriesTagsListAction()
1083 {
1084 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1085 $entry = new Entry($em->getReference(User::class, 1));
1086 $entry->setUrl('http://0.0.0.0/test-entry');
1087 $entry->addTag((new Tag())->setLabel('foo-tag'));
1088 $entry->addTag((new Tag())->setLabel('bar-tag'));
1089 $em->persist($entry);
1090 $em->flush();
1091
1092 $em->clear();
1093
1094 $list = [
1095 [
1096 'url' => 'http://0.0.0.0/test-entry',
1097 'tags' => 'foo-tag, bar-tag',
1098 ],
1099 ];
1100
1101 $this->client->request('DELETE', '/api/entries/tags/list?list=' . json_encode($list));
1102 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1103
1104 $entry = $em->getRepository('WallabagCoreBundle:Entry')->find($entry->getId());
1105 $this->assertCount(0, $entry->getTags());
1106 }
1107
1108 public function testDeleteEntriesTagsListActionNoList()
1109 {
1110 $this->client->request('DELETE', '/api/entries/tags/list?list=' . json_encode([]));
1111
1112 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1113
1114 $content = json_decode($this->client->getResponse()->getContent(), true);
1115
1116 $this->assertEmpty($content);
1117 }
1118
1119 public function testPostEntriesListAction()
1120 {
1121 $list = [
1122 'https://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html',
1123 'http://0.0.0.0/entry2',
1124 ];
1125
1126 $this->client->request('POST', '/api/entries/lists?urls=' . json_encode($list));
1127
1128 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1129
1130 $content = json_decode($this->client->getResponse()->getContent(), true);
1131
1132 $this->assertInternalType('int', $content[0]['entry']);
1133 $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']);
1134
1135 $this->assertInternalType('int', $content[1]['entry']);
1136 $this->assertSame('http://0.0.0.0/entry2', $content[1]['url']);
1137 }
1138
1139 public function testPostEntriesListActionWithNoUrls()
1140 {
1141 $this->client->request('POST', '/api/entries/lists?urls=' . json_encode([]));
1142
1143 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1144
1145 $content = json_decode($this->client->getResponse()->getContent(), true);
1146
1147 $this->assertEmpty($content);
1148 }
1149
1150 public function testDeleteEntriesListAction()
1151 {
1152 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1153 $em->persist((new Entry($em->getReference(User::class, 1)))->setUrl('http://0.0.0.0/test-entry1'));
1154
1155 $em->flush();
1156 $em->clear();
1157 $list = [
1158 'http://0.0.0.0/test-entry1',
1159 'http://0.0.0.0/test-entry-not-exist',
1160 ];
1161
1162 $this->client->request('DELETE', '/api/entries/list?urls=' . json_encode($list));
1163
1164 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1165
1166 $content = json_decode($this->client->getResponse()->getContent(), true);
1167
1168 $this->assertTrue($content[0]['entry']);
1169 $this->assertSame('http://0.0.0.0/test-entry1', $content[0]['url']);
1170
1171 $this->assertFalse($content[1]['entry']);
1172 $this->assertSame('http://0.0.0.0/test-entry-not-exist', $content[1]['url']);
1173 }
1174
1175 public function testDeleteEntriesListActionWithNoUrls()
1176 {
1177 $this->client->request('DELETE', '/api/entries/list?urls=' . json_encode([]));
1178
1179 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1180
1181 $content = json_decode($this->client->getResponse()->getContent(), true);
1182
1183 $this->assertEmpty($content);
1184 }
1185
1186 public function testLimitBulkAction()
1187 {
1188 $list = [
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 'http://0.0.0.0/entry1',
1197 'http://0.0.0.0/entry1',
1198 'http://0.0.0.0/entry1',
1199 'http://0.0.0.0/entry1',
1200 ];
1201
1202 $this->client->request('POST', '/api/entries/lists?urls=' . json_encode($list));
1203
1204 $this->assertSame(400, $this->client->getResponse()->getStatusCode());
1205 $this->assertContains('API limit reached', $this->client->getResponse()->getContent());
1206 }
1207
1208 public function testRePostEntryAndReUsePublishedAt()
1209 {
1210 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1211 $entry = new Entry($em->getReference(User::class, 1));
1212 $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »');
1213 $entry->setContent('hihi');
1214 $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');
1215 $entry->setPublishedAt(new \DateTime('2017-06-26T07:46:02+0200'));
1216 $em->persist($entry);
1217 $em->flush();
1218 $em->clear();
1219
1220 $this->client->request('POST', '/api/entries.json', [
1221 'url' => 'https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html',
1222 ]);
1223
1224 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1225
1226 $content = json_decode($this->client->getResponse()->getContent(), true);
1227
1228 $this->assertGreaterThan(0, $content['id']);
1229 $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']);
1230 }
1231 }