]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
58b617f3d5bc9519d1e50fe165875b931a037ae4
[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->assertSame('New title for my article', $content['title']);
442 $this->assertSame(1, $content['user_id']);
443 $this->assertCount(2, $content['tags']);
444 $this->assertNull($content['origin_url']);
445 $this->assertSame('my content', $content['content']);
446 $this->assertSame('de', $content['language']);
447 $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']);
448 $this->assertCount(2, $content['published_by']);
449 $this->assertContains('bob', $content['published_by']);
450 $this->assertContains('helen', $content['published_by']);
451 $this->assertTrue($content['is_public'], 'A public link has been generated for that entry');
452 }
453
454 public function testPostSameEntry()
455 {
456 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
457 $entry = new Entry($em->getReference(User::class, 1));
458 $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');
459 $entry->setArchived(true);
460 $entry->addTag((new Tag())->setLabel('google'));
461 $entry->addTag((new Tag())->setLabel('apple'));
462 $em->persist($entry);
463 $em->flush();
464 $em->clear();
465
466 $this->client->request('POST', '/api/entries.json', [
467 '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',
468 'archive' => '1',
469 'tags' => 'google, apple',
470 ]);
471
472 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
473
474 $content = json_decode($this->client->getResponse()->getContent(), true);
475
476 $this->assertGreaterThan(0, $content['id']);
477 $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']);
478 $this->assertSame(1, $content['is_archived']);
479 $this->assertSame(0, $content['is_starred']);
480 $this->assertCount(3, $content['tags']);
481 }
482
483 public function testPostEntryWhenFetchContentFails()
484 {
485 /** @var \Symfony\Component\DependencyInjection\Container $container */
486 $container = $this->client->getContainer();
487 $contentProxy = $this->getMockBuilder(ContentProxy::class)
488 ->disableOriginalConstructor()
489 ->setMethods(['updateEntry'])
490 ->getMock();
491 $contentProxy->expects($this->any())
492 ->method('updateEntry')
493 ->willThrowException(new \Exception('Test Fetch content fails'));
494 $container->set('wallabag_core.content_proxy', $contentProxy);
495
496 try {
497 $this->client->request('POST', '/api/entries.json', [
498 'url' => 'http://www.example.com/',
499 ]);
500
501 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
502 $content = json_decode($this->client->getResponse()->getContent(), true);
503 $this->assertGreaterThan(0, $content['id']);
504 $this->assertSame('http://www.example.com/', $content['url']);
505 $this->assertSame('www.example.com', $content['domain_name']);
506 $this->assertSame('www.example.com', $content['title']);
507 } finally {
508 // Remove the created entry to avoid side effects on other tests
509 if (isset($content['id'])) {
510 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
511 $entry = $em->getReference('WallabagCoreBundle:Entry', $content['id']);
512 $em->remove($entry);
513 $em->flush();
514 }
515 }
516 }
517
518 public function testPostArchivedAndStarredEntry()
519 {
520 $now = new \DateTime();
521 $this->client->request('POST', '/api/entries.json', [
522 'url' => 'https://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
523 'archive' => '1',
524 'starred' => '1',
525 ]);
526
527 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
528
529 $content = json_decode($this->client->getResponse()->getContent(), true);
530
531 $this->assertGreaterThan(0, $content['id']);
532 $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']);
533 $this->assertSame(1, $content['is_archived']);
534 $this->assertSame(1, $content['is_starred']);
535 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp());
536 $this->assertSame(1, $content['user_id']);
537 }
538
539 public function testPostArchivedAndStarredEntryWithoutQuotes()
540 {
541 $this->client->request('POST', '/api/entries.json', [
542 'url' => 'https://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
543 'archive' => 0,
544 'starred' => 1,
545 ]);
546
547 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
548
549 $content = json_decode($this->client->getResponse()->getContent(), true);
550
551 $this->assertGreaterThan(0, $content['id']);
552 $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']);
553 $this->assertSame(0, $content['is_archived']);
554 $this->assertSame(1, $content['is_starred']);
555 }
556
557 public function testPostEntryWithOriginUrl()
558 {
559 $this->client->request('POST', '/api/entries.json', [
560 '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',
561 'tags' => 'google',
562 'title' => 'New title for my article',
563 'content' => 'my content',
564 'language' => 'de',
565 'published_at' => '2016-09-08T11:55:58+0200',
566 'authors' => 'bob,helen',
567 'public' => 1,
568 'origin_url' => 'http://mysource.tld',
569 ]);
570
571 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
572
573 $content = json_decode($this->client->getResponse()->getContent(), true);
574
575 $this->assertGreaterThan(0, $content['id']);
576 $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']);
577 $this->assertSame('http://mysource.tld', $content['origin_url']);
578 }
579
580 public function testPatchEntry()
581 {
582 $entry = $this->client->getContainer()
583 ->get('doctrine.orm.entity_manager')
584 ->getRepository('WallabagCoreBundle:Entry')
585 ->findOneByUser(1);
586
587 if (!$entry) {
588 $this->markTestSkipped('No content found in db.');
589 }
590
591 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
592 'title' => 'New awesome title',
593 'tags' => 'new tag ' . uniqid(),
594 'starred' => '1',
595 'archive' => '0',
596 'language' => 'de_AT',
597 'preview_picture' => 'http://preview.io/picture.jpg',
598 'authors' => 'bob,sponge',
599 'content' => 'awesome',
600 'public' => 0,
601 'published_at' => 1488833381,
602 ]);
603
604 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
605
606 $content = json_decode($this->client->getResponse()->getContent(), true);
607
608 $this->assertSame($entry->getId(), $content['id']);
609 $this->assertSame($entry->getUrl(), $content['url']);
610 $this->assertSame('New awesome title', $content['title']);
611 $this->assertGreaterThanOrEqual(1, \count($content['tags']), 'We force only one tag');
612 $this->assertSame(1, $content['user_id']);
613 $this->assertSame('de_AT', $content['language']);
614 $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']);
615 $this->assertContains('sponge', $content['published_by']);
616 $this->assertContains('bob', $content['published_by']);
617 $this->assertSame('awesome', $content['content']);
618 $this->assertFalse($content['is_public'], 'Entry is no more shared');
619 $this->assertContains('2017-03-06', $content['published_at']);
620 }
621
622 public function testPatchEntryWithoutQuotes()
623 {
624 $entry = $this->client->getContainer()
625 ->get('doctrine.orm.entity_manager')
626 ->getRepository('WallabagCoreBundle:Entry')
627 ->findOneByUser(1);
628
629 if (!$entry) {
630 $this->markTestSkipped('No content found in db.');
631 }
632
633 $previousContent = $entry->getContent();
634 $previousLanguage = $entry->getLanguage();
635
636 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
637 'title' => 'New awesome title',
638 'tags' => 'new tag ' . uniqid(),
639 'starred' => 1,
640 'archive' => 0,
641 'authors' => ['bob', 'sponge'],
642 ]);
643
644 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
645
646 $content = json_decode($this->client->getResponse()->getContent(), true);
647
648 $this->assertSame($entry->getId(), $content['id']);
649 $this->assertSame($entry->getUrl(), $content['url']);
650 $this->assertGreaterThanOrEqual(1, \count($content['tags']), 'We force only one tag');
651 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
652 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
653 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
654 }
655
656 public function testPatchEntryWithOriginUrl()
657 {
658 $entry = $this->client->getContainer()
659 ->get('doctrine.orm.entity_manager')
660 ->getRepository('WallabagCoreBundle:Entry')
661 ->findOneByUser(1);
662
663 if (!$entry) {
664 $this->markTestSkipped('No content found in db.');
665 }
666
667 $previousContent = $entry->getContent();
668 $previousLanguage = $entry->getLanguage();
669
670 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
671 'title' => 'Another awesome title just for profit',
672 'origin_url' => 'https://myawesomesource.example.com',
673 ]);
674
675 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
676
677 $content = json_decode($this->client->getResponse()->getContent(), true);
678
679 $this->assertSame($entry->getId(), $content['id']);
680 $this->assertSame($entry->getUrl(), $content['url']);
681 $this->assertSame('https://myawesomesource.example.com', $content['origin_url']);
682 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
683 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
684 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
685 }
686
687 public function testPatchEntryRemoveOriginUrl()
688 {
689 $entry = $this->client->getContainer()
690 ->get('doctrine.orm.entity_manager')
691 ->getRepository('WallabagCoreBundle:Entry')
692 ->findOneByUser(1);
693
694 if (!$entry) {
695 $this->markTestSkipped('No content found in db.');
696 }
697
698 $previousContent = $entry->getContent();
699 $previousLanguage = $entry->getLanguage();
700 $previousTitle = $entry->getTitle();
701
702 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
703 'origin_url' => '',
704 ]);
705
706 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
707
708 $content = json_decode($this->client->getResponse()->getContent(), true);
709
710 $this->assertSame($entry->getId(), $content['id']);
711 $this->assertSame($entry->getUrl(), $content['url']);
712 $this->assertEmpty($content['origin_url']);
713 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
714 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
715 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
716 $this->assertSame($previousTitle, $content['title'], 'Ensure title has not moved');
717 }
718
719 public function testPatchEntryNullOriginUrl()
720 {
721 $entry = $this->client->getContainer()
722 ->get('doctrine.orm.entity_manager')
723 ->getRepository('WallabagCoreBundle:Entry')
724 ->findOneByUser(1);
725
726 if (!$entry) {
727 $this->markTestSkipped('No content found in db.');
728 }
729
730 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
731 'origin_url' => null,
732 ]);
733
734 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
735
736 $content = json_decode($this->client->getResponse()->getContent(), true);
737
738 $this->assertNull($content['origin_url']);
739 }
740
741 public function testGetTagsEntry()
742 {
743 $entry = $this->client->getContainer()
744 ->get('doctrine.orm.entity_manager')
745 ->getRepository('WallabagCoreBundle:Entry')
746 ->findOneWithTags($this->user->getId());
747
748 $entry = $entry[0];
749
750 if (!$entry) {
751 $this->markTestSkipped('No content found in db.');
752 }
753
754 $tags = [];
755 foreach ($entry->getTags() as $tag) {
756 $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()];
757 }
758
759 $this->client->request('GET', '/api/entries/' . $entry->getId() . '/tags');
760
761 $this->assertSame(json_encode($tags, JSON_HEX_QUOT), $this->client->getResponse()->getContent());
762 }
763
764 public function testPostTagsOnEntry()
765 {
766 $entry = $this->client->getContainer()
767 ->get('doctrine.orm.entity_manager')
768 ->getRepository('WallabagCoreBundle:Entry')
769 ->findOneByUser(1);
770
771 if (!$entry) {
772 $this->markTestSkipped('No content found in db.');
773 }
774
775 $nbTags = \count($entry->getTags());
776
777 $newTags = 'tag1,tag2,tag3';
778
779 $this->client->request('POST', '/api/entries/' . $entry->getId() . '/tags', ['tags' => $newTags]);
780
781 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
782
783 $content = json_decode($this->client->getResponse()->getContent(), true);
784
785 $this->assertArrayHasKey('tags', $content);
786 $this->assertSame($nbTags + 3, \count($content['tags']));
787
788 $entryDB = $this->client->getContainer()
789 ->get('doctrine.orm.entity_manager')
790 ->getRepository('WallabagCoreBundle:Entry')
791 ->find($entry->getId());
792
793 $tagsInDB = [];
794 foreach ($entryDB->getTags()->toArray() as $tag) {
795 $tagsInDB[$tag->getId()] = $tag->getLabel();
796 }
797
798 foreach (explode(',', $newTags) as $tag) {
799 $this->assertContains($tag, $tagsInDB);
800 }
801 }
802
803 public function testDeleteOneTagEntry()
804 {
805 $entry = $this->client->getContainer()
806 ->get('doctrine.orm.entity_manager')
807 ->getRepository('WallabagCoreBundle:Entry')
808 ->findOneWithTags($this->user->getId());
809 $entry = $entry[0];
810
811 if (!$entry) {
812 $this->markTestSkipped('No content found in db.');
813 }
814
815 // hydrate the tags relations
816 $nbTags = \count($entry->getTags());
817 $tag = $entry->getTags()[0];
818
819 $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '/tags/' . $tag->getId() . '.json');
820
821 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
822
823 $content = json_decode($this->client->getResponse()->getContent(), true);
824
825 $this->assertArrayHasKey('tags', $content);
826 $this->assertSame($nbTags - 1, \count($content['tags']));
827 }
828
829 public function testSaveIsArchivedAfterPost()
830 {
831 $entry = $this->client->getContainer()
832 ->get('doctrine.orm.entity_manager')
833 ->getRepository('WallabagCoreBundle:Entry')
834 ->findOneBy(['user' => 1, 'isArchived' => true]);
835
836 if (!$entry) {
837 $this->markTestSkipped('No content found in db.');
838 }
839
840 $this->client->request('POST', '/api/entries.json', [
841 'url' => $entry->getUrl(),
842 ]);
843
844 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
845
846 $content = json_decode($this->client->getResponse()->getContent(), true);
847
848 $this->assertSame(1, $content['is_archived']);
849 }
850
851 public function testSaveIsStarredAfterPost()
852 {
853 $entry = $this->client->getContainer()
854 ->get('doctrine.orm.entity_manager')
855 ->getRepository('WallabagCoreBundle:Entry')
856 ->findOneBy(['user' => 1, 'isStarred' => true]);
857
858 if (!$entry) {
859 $this->markTestSkipped('No content found in db.');
860 }
861
862 $this->client->request('POST', '/api/entries.json', [
863 'url' => $entry->getUrl(),
864 ]);
865
866 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
867
868 $content = json_decode($this->client->getResponse()->getContent(), true);
869
870 $this->assertSame(1, $content['is_starred']);
871 }
872
873 public function testSaveIsArchivedAfterPatch()
874 {
875 $entry = $this->client->getContainer()
876 ->get('doctrine.orm.entity_manager')
877 ->getRepository('WallabagCoreBundle:Entry')
878 ->findOneBy(['user' => 1, 'isArchived' => true]);
879
880 if (!$entry) {
881 $this->markTestSkipped('No content found in db.');
882 }
883
884 $previousTitle = $entry->getTitle();
885
886 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
887 'title' => $entry->getTitle() . '++',
888 ]);
889
890 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
891
892 $content = json_decode($this->client->getResponse()->getContent(), true);
893
894 $this->assertSame(1, $content['is_archived']);
895 $this->assertSame($previousTitle . '++', $content['title']);
896 }
897
898 public function testSaveIsStarredAfterPatch()
899 {
900 $now = new \DateTime();
901 $entry = $this->client->getContainer()
902 ->get('doctrine.orm.entity_manager')
903 ->getRepository('WallabagCoreBundle:Entry')
904 ->findOneBy(['user' => 1, 'isStarred' => true]);
905
906 if (!$entry) {
907 $this->markTestSkipped('No content found in db.');
908 }
909 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
910 'title' => $entry->getTitle() . '++',
911 ]);
912
913 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
914
915 $content = json_decode($this->client->getResponse()->getContent(), true);
916
917 $this->assertSame(1, $content['is_starred']);
918 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp());
919 }
920
921 public function dataForEntriesExistWithUrl()
922 {
923 return [
924 'with_id' => [
925 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1',
926 'expectedValue' => 2,
927 ],
928 'without_id' => [
929 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2',
930 'expectedValue' => true,
931 ],
932 ];
933 }
934
935 /**
936 * @dataProvider dataForEntriesExistWithUrl
937 */
938 public function testGetEntriesExists($url, $expectedValue)
939 {
940 $this->client->request('GET', $url);
941
942 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
943
944 $content = json_decode($this->client->getResponse()->getContent(), true);
945
946 $this->assertSame($expectedValue, $content['exists']);
947 }
948
949 public function testGetEntriesExistsWithManyUrls()
950 {
951 $url1 = 'http://0.0.0.0/entry2';
952 $url2 = 'http://0.0.0.0/entry10';
953 $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1');
954
955 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
956
957 $content = json_decode($this->client->getResponse()->getContent(), true);
958
959 $this->assertArrayHasKey($url1, $content);
960 $this->assertArrayHasKey($url2, $content);
961 $this->assertSame(2, $content[$url1]);
962 $this->assertNull($content[$url2]);
963 }
964
965 public function testGetEntriesExistsWithManyUrlsReturnBool()
966 {
967 $url1 = 'http://0.0.0.0/entry2';
968 $url2 = 'http://0.0.0.0/entry10';
969 $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2);
970
971 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
972
973 $content = json_decode($this->client->getResponse()->getContent(), true);
974
975 $this->assertArrayHasKey($url1, $content);
976 $this->assertArrayHasKey($url2, $content);
977 $this->assertTrue($content[$url1]);
978 $this->assertFalse($content[$url2]);
979 }
980
981 public function testGetEntriesExistsWhichDoesNotExists()
982 {
983 $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2');
984
985 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
986
987 $content = json_decode($this->client->getResponse()->getContent(), true);
988
989 $this->assertFalse($content['exists']);
990 }
991
992 public function testGetEntriesExistsWithNoUrl()
993 {
994 $this->client->request('GET', '/api/entries/exists?url=');
995
996 $this->assertSame(403, $this->client->getResponse()->getStatusCode());
997 }
998
999 public function testReloadEntryErrorWhileFetching()
1000 {
1001 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
1002 ->getRepository('WallabagCoreBundle:Entry')
1003 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
1004
1005 if (!$entry) {
1006 $this->markTestSkipped('No content found in db.');
1007 }
1008
1009 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '/reload.json');
1010 $this->assertSame(304, $this->client->getResponse()->getStatusCode());
1011 }
1012
1013 public function testReloadEntry()
1014 {
1015 $this->client->request('POST', '/api/entries.json', [
1016 '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',
1017 'archive' => '1',
1018 'tags' => 'google, apple',
1019 ]);
1020
1021 $json = json_decode($this->client->getResponse()->getContent(), true);
1022
1023 $this->setUp();
1024
1025 $this->client->request('PATCH', '/api/entries/' . $json['id'] . '/reload.json');
1026 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1027
1028 $content = json_decode($this->client->getResponse()->getContent(), true);
1029
1030 $this->assertNotEmpty($content['title']);
1031
1032 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
1033 }
1034
1035 public function testPostEntriesTagsListAction()
1036 {
1037 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
1038 ->getRepository('WallabagCoreBundle:Entry')
1039 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
1040
1041 $tags = $entry->getTags();
1042
1043 $this->assertCount(2, $tags);
1044
1045 $list = [
1046 [
1047 'url' => 'http://0.0.0.0/entry4',
1048 'tags' => 'new tag 1, new tag 2',
1049 ],
1050 ];
1051
1052 $this->client->request('POST', '/api/entries/tags/lists?list=' . json_encode($list));
1053
1054 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1055
1056 $content = json_decode($this->client->getResponse()->getContent(), true);
1057
1058 $this->assertInternalType('int', $content[0]['entry']);
1059 $this->assertSame('http://0.0.0.0/entry4', $content[0]['url']);
1060
1061 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
1062 ->getRepository('WallabagCoreBundle:Entry')
1063 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
1064
1065 $tags = $entry->getTags();
1066 $this->assertCount(4, $tags);
1067 }
1068
1069 public function testPostEntriesTagsListActionNoList()
1070 {
1071 $this->client->request('POST', '/api/entries/tags/lists?list=' . json_encode([]));
1072
1073 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1074
1075 $content = json_decode($this->client->getResponse()->getContent(), true);
1076
1077 $this->assertEmpty($content);
1078 }
1079
1080 public function testDeleteEntriesTagsListAction()
1081 {
1082 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1083 $entry = new Entry($em->getReference(User::class, 1));
1084 $entry->setUrl('http://0.0.0.0/test-entry');
1085 $entry->addTag((new Tag())->setLabel('foo-tag'));
1086 $entry->addTag((new Tag())->setLabel('bar-tag'));
1087 $em->persist($entry);
1088 $em->flush();
1089
1090 $em->clear();
1091
1092 $list = [
1093 [
1094 'url' => 'http://0.0.0.0/test-entry',
1095 'tags' => 'foo-tag, bar-tag',
1096 ],
1097 ];
1098
1099 $this->client->request('DELETE', '/api/entries/tags/list?list=' . json_encode($list));
1100 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1101
1102 $entry = $em->getRepository('WallabagCoreBundle:Entry')->find($entry->getId());
1103 $this->assertCount(0, $entry->getTags());
1104 }
1105
1106 public function testDeleteEntriesTagsListActionNoList()
1107 {
1108 $this->client->request('DELETE', '/api/entries/tags/list?list=' . json_encode([]));
1109
1110 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1111
1112 $content = json_decode($this->client->getResponse()->getContent(), true);
1113
1114 $this->assertEmpty($content);
1115 }
1116
1117 public function testPostEntriesListAction()
1118 {
1119 $list = [
1120 'https://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html',
1121 'http://0.0.0.0/entry2',
1122 ];
1123
1124 $this->client->request('POST', '/api/entries/lists?urls=' . json_encode($list));
1125
1126 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1127
1128 $content = json_decode($this->client->getResponse()->getContent(), true);
1129
1130 $this->assertInternalType('int', $content[0]['entry']);
1131 $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']);
1132
1133 $this->assertInternalType('int', $content[1]['entry']);
1134 $this->assertSame('http://0.0.0.0/entry2', $content[1]['url']);
1135 }
1136
1137 public function testPostEntriesListActionWithNoUrls()
1138 {
1139 $this->client->request('POST', '/api/entries/lists?urls=' . json_encode([]));
1140
1141 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1142
1143 $content = json_decode($this->client->getResponse()->getContent(), true);
1144
1145 $this->assertEmpty($content);
1146 }
1147
1148 public function testDeleteEntriesListAction()
1149 {
1150 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1151 $em->persist((new Entry($em->getReference(User::class, 1)))->setUrl('http://0.0.0.0/test-entry1'));
1152
1153 $em->flush();
1154 $em->clear();
1155 $list = [
1156 'http://0.0.0.0/test-entry1',
1157 'http://0.0.0.0/test-entry-not-exist',
1158 ];
1159
1160 $this->client->request('DELETE', '/api/entries/list?urls=' . json_encode($list));
1161
1162 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1163
1164 $content = json_decode($this->client->getResponse()->getContent(), true);
1165
1166 $this->assertTrue($content[0]['entry']);
1167 $this->assertSame('http://0.0.0.0/test-entry1', $content[0]['url']);
1168
1169 $this->assertFalse($content[1]['entry']);
1170 $this->assertSame('http://0.0.0.0/test-entry-not-exist', $content[1]['url']);
1171 }
1172
1173 public function testDeleteEntriesListActionWithNoUrls()
1174 {
1175 $this->client->request('DELETE', '/api/entries/list?urls=' . json_encode([]));
1176
1177 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1178
1179 $content = json_decode($this->client->getResponse()->getContent(), true);
1180
1181 $this->assertEmpty($content);
1182 }
1183
1184 public function testLimitBulkAction()
1185 {
1186 $list = [
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 'http://0.0.0.0/entry1',
1197 'http://0.0.0.0/entry1',
1198 ];
1199
1200 $this->client->request('POST', '/api/entries/lists?urls=' . json_encode($list));
1201
1202 $this->assertSame(400, $this->client->getResponse()->getStatusCode());
1203 $this->assertContains('API limit reached', $this->client->getResponse()->getContent());
1204 }
1205
1206 public function testRePostEntryAndReUsePublishedAt()
1207 {
1208 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1209 $entry = new Entry($em->getReference(User::class, 1));
1210 $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »');
1211 $entry->setContent('hihi');
1212 $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');
1213 $entry->setPublishedAt(new \DateTime('2017-06-26T07:46:02+0200'));
1214 $em->persist($entry);
1215 $em->flush();
1216 $em->clear();
1217
1218 $this->client->request('POST', '/api/entries.json', [
1219 'url' => 'https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html',
1220 ]);
1221
1222 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1223
1224 $content = json_decode($this->client->getResponse()->getContent(), true);
1225
1226 $this->assertGreaterThan(0, $content['id']);
1227 $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']);
1228 }
1229 }