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