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