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