]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
Merge pull request #2327 from wallabag/user-management
[github/wallabag/wallabag.git] / tests / Wallabag / ApiBundle / Controller / WallabagRestControllerTest.php
1 <?php
2
3 namespace Tests\Wallabag\ApiBundle\Controller;
4
5 use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
6 use Wallabag\CoreBundle\Entity\Tag;
7
8 class WallabagRestControllerTest extends WallabagApiTestCase
9 {
10 protected static $salt;
11
12 public function testGetOneEntry()
13 {
14 $entry = $this->client->getContainer()
15 ->get('doctrine.orm.entity_manager')
16 ->getRepository('WallabagCoreBundle:Entry')
17 ->findOneBy(['user' => 1, 'isArchived' => false]);
18
19 if (!$entry) {
20 $this->markTestSkipped('No content found in db.');
21 }
22
23 $this->client->request('GET', '/api/entries/'.$entry->getId().'.json');
24 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
25
26 $content = json_decode($this->client->getResponse()->getContent(), true);
27
28 $this->assertEquals($entry->getTitle(), $content['title']);
29 $this->assertEquals($entry->getUrl(), $content['url']);
30 $this->assertCount(count($entry->getTags()), $content['tags']);
31 $this->assertEquals($entry->getUserName(), $content['user_name']);
32 $this->assertEquals($entry->getUserEmail(), $content['user_email']);
33 $this->assertEquals($entry->getUserId(), $content['user_id']);
34
35 $this->assertTrue(
36 $this->client->getResponse()->headers->contains(
37 'Content-Type',
38 'application/json'
39 )
40 );
41 }
42
43 public function testGetOneEntryWrongUser()
44 {
45 $entry = $this->client->getContainer()
46 ->get('doctrine.orm.entity_manager')
47 ->getRepository('WallabagCoreBundle:Entry')
48 ->findOneBy(['user' => 2, 'isArchived' => false]);
49
50 if (!$entry) {
51 $this->markTestSkipped('No content found in db.');
52 }
53
54 $this->client->request('GET', '/api/entries/'.$entry->getId().'.json');
55
56 $this->assertEquals(403, $this->client->getResponse()->getStatusCode());
57 }
58
59 public function testGetEntries()
60 {
61 $this->client->request('GET', '/api/entries');
62
63 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
64
65 $content = json_decode($this->client->getResponse()->getContent(), true);
66
67 $this->assertGreaterThanOrEqual(1, count($content));
68 $this->assertNotEmpty($content['_embedded']['items']);
69 $this->assertGreaterThanOrEqual(1, $content['total']);
70 $this->assertEquals(1, $content['page']);
71 $this->assertGreaterThanOrEqual(1, $content['pages']);
72
73 $this->assertTrue(
74 $this->client->getResponse()->headers->contains(
75 'Content-Type',
76 'application/json'
77 )
78 );
79 }
80
81 public function testGetStarredEntries()
82 {
83 $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);
84
85 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
86
87 $content = json_decode($this->client->getResponse()->getContent(), true);
88
89 $this->assertGreaterThanOrEqual(1, count($content));
90 $this->assertNotEmpty($content['_embedded']['items']);
91 $this->assertGreaterThanOrEqual(1, $content['total']);
92 $this->assertEquals(1, $content['page']);
93 $this->assertGreaterThanOrEqual(1, $content['pages']);
94
95 $this->assertTrue(
96 $this->client->getResponse()->headers->contains(
97 'Content-Type',
98 'application/json'
99 )
100 );
101 }
102
103 public function testGetArchiveEntries()
104 {
105 $this->client->request('GET', '/api/entries', ['archive' => 1]);
106
107 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
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']);
114 $this->assertEquals(1, $content['page']);
115 $this->assertGreaterThanOrEqual(1, $content['pages']);
116
117 $this->assertTrue(
118 $this->client->getResponse()->headers->contains(
119 'Content-Type',
120 'application/json'
121 )
122 );
123 }
124
125 public function testGetTaggedEntries()
126 {
127 $this->client->request('GET', '/api/entries', ['tags' => 'foo,bar']);
128
129 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
130
131 $content = json_decode($this->client->getResponse()->getContent(), true);
132
133 $this->assertGreaterThanOrEqual(1, count($content));
134 $this->assertNotEmpty($content['_embedded']['items']);
135 $this->assertGreaterThanOrEqual(1, $content['total']);
136 $this->assertEquals(1, $content['page']);
137 $this->assertGreaterThanOrEqual(1, $content['pages']);
138
139 $this->assertTrue(
140 $this->client->getResponse()->headers->contains(
141 'Content-Type',
142 'application/json'
143 )
144 );
145 }
146
147 public function testGetDatedEntries()
148 {
149 $this->client->request('GET', '/api/entries', ['since' => 1]);
150
151 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
152
153 $content = json_decode($this->client->getResponse()->getContent(), true);
154
155 $this->assertGreaterThanOrEqual(1, count($content));
156 $this->assertNotEmpty($content['_embedded']['items']);
157 $this->assertGreaterThanOrEqual(1, $content['total']);
158 $this->assertEquals(1, $content['page']);
159 $this->assertGreaterThanOrEqual(1, $content['pages']);
160
161 $this->assertTrue(
162 $this->client->getResponse()->headers->contains(
163 'Content-Type',
164 'application/json'
165 )
166 );
167 }
168
169 public function testGetDatedSupEntries()
170 {
171 $future = new \DateTime(date('Y-m-d H:i:s'));
172 $this->client->request('GET', '/api/entries', ['since' => $future->getTimestamp() + 1000]);
173
174 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
175
176 $content = json_decode($this->client->getResponse()->getContent(), true);
177
178 $this->assertGreaterThanOrEqual(1, count($content));
179 $this->assertEmpty($content['_embedded']['items']);
180 $this->assertEquals(0, $content['total']);
181 $this->assertEquals(1, $content['page']);
182 $this->assertEquals(1, $content['pages']);
183
184 $this->assertTrue(
185 $this->client->getResponse()->headers->contains(
186 'Content-Type',
187 'application/json'
188 )
189 );
190 }
191
192 public function testDeleteEntry()
193 {
194 $entry = $this->client->getContainer()
195 ->get('doctrine.orm.entity_manager')
196 ->getRepository('WallabagCoreBundle:Entry')
197 ->findOneByUser(1);
198
199 if (!$entry) {
200 $this->markTestSkipped('No content found in db.');
201 }
202
203 $this->client->request('DELETE', '/api/entries/'.$entry->getId().'.json');
204
205 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
206
207 $content = json_decode($this->client->getResponse()->getContent(), true);
208
209 $this->assertEquals($entry->getTitle(), $content['title']);
210 $this->assertEquals($entry->getUrl(), $content['url']);
211
212 // We'll try to delete this entry again
213 $this->client->request('DELETE', '/api/entries/'.$entry->getId().'.json');
214
215 $this->assertEquals(404, $this->client->getResponse()->getStatusCode());
216 }
217
218 public function testPostEntry()
219 {
220 $this->client->request('POST', '/api/entries.json', [
221 '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',
222 'tags' => 'google',
223 'title' => 'New title for my article',
224 ]);
225
226 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
227
228 $content = json_decode($this->client->getResponse()->getContent(), true);
229
230 $this->assertGreaterThan(0, $content['id']);
231 $this->assertEquals('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']);
232 $this->assertEquals(false, $content['is_archived']);
233 $this->assertEquals(false, $content['is_starred']);
234 $this->assertEquals('New title for my article', $content['title']);
235 $this->assertEquals(1, $content['user_id']);
236 $this->assertCount(1, $content['tags']);
237 }
238
239 public function testPostSameEntry()
240 {
241 $this->client->request('POST', '/api/entries.json', [
242 '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',
243 'archive' => '1',
244 'tags' => 'google, apple',
245 ]);
246
247 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
248
249 $content = json_decode($this->client->getResponse()->getContent(), true);
250
251 $this->assertGreaterThan(0, $content['id']);
252 $this->assertEquals('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']);
253 $this->assertEquals(true, $content['is_archived']);
254 $this->assertEquals(false, $content['is_starred']);
255 $this->assertCount(2, $content['tags']);
256 }
257
258 public function testPostArchivedAndStarredEntry()
259 {
260 $this->client->request('POST', '/api/entries.json', [
261 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
262 'archive' => '1',
263 'starred' => '1',
264 ]);
265
266 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
267
268 $content = json_decode($this->client->getResponse()->getContent(), true);
269
270 $this->assertGreaterThan(0, $content['id']);
271 $this->assertEquals('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']);
272 $this->assertEquals(true, $content['is_archived']);
273 $this->assertEquals(true, $content['is_starred']);
274 $this->assertEquals(1, $content['user_id']);
275 }
276
277 public function testPostArchivedAndStarredEntryWithoutQuotes()
278 {
279 $this->client->request('POST', '/api/entries.json', [
280 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
281 'archive' => 0,
282 'starred' => 1,
283 ]);
284
285 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
286
287 $content = json_decode($this->client->getResponse()->getContent(), true);
288
289 $this->assertGreaterThan(0, $content['id']);
290 $this->assertEquals('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']);
291 $this->assertEquals(false, $content['is_archived']);
292 $this->assertEquals(true, $content['is_starred']);
293 }
294
295 public function testPatchEntry()
296 {
297 $entry = $this->client->getContainer()
298 ->get('doctrine.orm.entity_manager')
299 ->getRepository('WallabagCoreBundle:Entry')
300 ->findOneByUser(1);
301
302 if (!$entry) {
303 $this->markTestSkipped('No content found in db.');
304 }
305
306 // hydrate the tags relations
307 $nbTags = count($entry->getTags());
308
309 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
310 'title' => 'New awesome title',
311 'tags' => 'new tag '.uniqid(),
312 'starred' => '1',
313 'archive' => '0',
314 ]);
315
316 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
317
318 $content = json_decode($this->client->getResponse()->getContent(), true);
319
320 $this->assertEquals($entry->getId(), $content['id']);
321 $this->assertEquals($entry->getUrl(), $content['url']);
322 $this->assertEquals('New awesome title', $content['title']);
323 $this->assertGreaterThan($nbTags, count($content['tags']));
324 $this->assertEquals(1, $content['user_id']);
325 }
326
327 public function testPatchEntryWithoutQuotes()
328 {
329 $entry = $this->client->getContainer()
330 ->get('doctrine.orm.entity_manager')
331 ->getRepository('WallabagCoreBundle:Entry')
332 ->findOneByUser(1);
333
334 if (!$entry) {
335 $this->markTestSkipped('No content found in db.');
336 }
337
338 // hydrate the tags relations
339 $nbTags = count($entry->getTags());
340
341 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
342 'title' => 'New awesome title',
343 'tags' => 'new tag '.uniqid(),
344 'starred' => 1,
345 'archive' => 0,
346 ]);
347
348 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
349
350 $content = json_decode($this->client->getResponse()->getContent(), true);
351
352 $this->assertEquals($entry->getId(), $content['id']);
353 $this->assertEquals($entry->getUrl(), $content['url']);
354 $this->assertEquals('New awesome title', $content['title']);
355 $this->assertGreaterThan($nbTags, count($content['tags']));
356 }
357
358 public function testGetTagsEntry()
359 {
360 $entry = $this->client->getContainer()
361 ->get('doctrine.orm.entity_manager')
362 ->getRepository('WallabagCoreBundle:Entry')
363 ->findOneWithTags($this->user->getId());
364
365 $entry = $entry[0];
366
367 if (!$entry) {
368 $this->markTestSkipped('No content found in db.');
369 }
370
371 $tags = [];
372 foreach ($entry->getTags() as $tag) {
373 $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()];
374 }
375
376 $this->client->request('GET', '/api/entries/'.$entry->getId().'/tags');
377
378 $this->assertEquals(json_encode($tags, JSON_HEX_QUOT), $this->client->getResponse()->getContent());
379 }
380
381 public function testPostTagsOnEntry()
382 {
383 $entry = $this->client->getContainer()
384 ->get('doctrine.orm.entity_manager')
385 ->getRepository('WallabagCoreBundle:Entry')
386 ->findOneByUser(1);
387
388 if (!$entry) {
389 $this->markTestSkipped('No content found in db.');
390 }
391
392 $nbTags = count($entry->getTags());
393
394 $newTags = 'tag1,tag2,tag3';
395
396 $this->client->request('POST', '/api/entries/'.$entry->getId().'/tags', ['tags' => $newTags]);
397
398 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
399
400 $content = json_decode($this->client->getResponse()->getContent(), true);
401
402 $this->assertArrayHasKey('tags', $content);
403 $this->assertEquals($nbTags + 3, count($content['tags']));
404
405 $entryDB = $this->client->getContainer()
406 ->get('doctrine.orm.entity_manager')
407 ->getRepository('WallabagCoreBundle:Entry')
408 ->find($entry->getId());
409
410 $tagsInDB = [];
411 foreach ($entryDB->getTags()->toArray() as $tag) {
412 $tagsInDB[$tag->getId()] = $tag->getLabel();
413 }
414
415 foreach (explode(',', $newTags) as $tag) {
416 $this->assertContains($tag, $tagsInDB);
417 }
418 }
419
420 public function testDeleteOneTagEntry()
421 {
422 $entry = $this->client->getContainer()
423 ->get('doctrine.orm.entity_manager')
424 ->getRepository('WallabagCoreBundle:Entry')
425 ->findOneWithTags($this->user->getId());
426 $entry = $entry[0];
427
428 if (!$entry) {
429 $this->markTestSkipped('No content found in db.');
430 }
431
432 // hydrate the tags relations
433 $nbTags = count($entry->getTags());
434 $tag = $entry->getTags()[0];
435
436 $this->client->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json');
437
438 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
439
440 $content = json_decode($this->client->getResponse()->getContent(), true);
441
442 $this->assertArrayHasKey('tags', $content);
443 $this->assertEquals($nbTags - 1, count($content['tags']));
444 }
445
446 public function testGetUserTags()
447 {
448 $this->client->request('GET', '/api/tags.json');
449
450 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
451
452 $content = json_decode($this->client->getResponse()->getContent(), true);
453
454 $this->assertGreaterThan(0, $content);
455 $this->assertArrayHasKey('id', $content[0]);
456 $this->assertArrayHasKey('label', $content[0]);
457
458 return end($content);
459 }
460
461 /**
462 * @depends testGetUserTags
463 */
464 public function testDeleteUserTag($tag)
465 {
466 $this->client->request('DELETE', '/api/tags/'.$tag['id'].'.json');
467
468 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
469
470 $content = json_decode($this->client->getResponse()->getContent(), true);
471
472 $this->assertArrayHasKey('label', $content);
473 $this->assertEquals($tag['label'], $content['label']);
474 $this->assertEquals($tag['slug'], $content['slug']);
475
476 $entries = $this->client->getContainer()
477 ->get('doctrine.orm.entity_manager')
478 ->getRepository('WallabagCoreBundle:Entry')
479 ->findAllByTagId($this->user->getId(), $tag['id']);
480
481 $this->assertCount(0, $entries);
482 }
483
484 public function testDeleteTagByLabel()
485 {
486 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
487 $entry = $this->client->getContainer()
488 ->get('doctrine.orm.entity_manager')
489 ->getRepository('WallabagCoreBundle:Entry')
490 ->findOneWithTags($this->user->getId());
491
492 $entry = $entry[0];
493
494 $tag = new Tag();
495 $tag->setLabel('Awesome tag for test');
496 $em->persist($tag);
497
498 $entry->addTag($tag);
499
500 $em->persist($entry);
501 $em->flush();
502
503 $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]);
504
505 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
506
507 $content = json_decode($this->client->getResponse()->getContent(), true);
508
509 $this->assertArrayHasKey('label', $content);
510 $this->assertEquals($tag->getLabel(), $content['label']);
511 $this->assertEquals($tag->getSlug(), $content['slug']);
512
513 $entries = $this->client->getContainer()
514 ->get('doctrine.orm.entity_manager')
515 ->getRepository('WallabagCoreBundle:Entry')
516 ->findAllByTagId($this->user->getId(), $tag->getId());
517
518 $this->assertCount(0, $entries);
519 }
520
521 public function testDeleteTagByLabelNotFound()
522 {
523 $this->client->request('DELETE', '/api/tag/label.json', ['tag' => 'does not exist']);
524
525 $this->assertEquals(404, $this->client->getResponse()->getStatusCode());
526 }
527
528 public function testDeleteTagsByLabel()
529 {
530 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
531 $entry = $this->client->getContainer()
532 ->get('doctrine.orm.entity_manager')
533 ->getRepository('WallabagCoreBundle:Entry')
534 ->findOneWithTags($this->user->getId());
535
536 $entry = $entry[0];
537
538 $tag = new Tag();
539 $tag->setLabel('Awesome tag for tagsLabel');
540 $em->persist($tag);
541
542 $tag2 = new Tag();
543 $tag2->setLabel('Awesome tag for tagsLabel 2');
544 $em->persist($tag2);
545
546 $entry->addTag($tag);
547 $entry->addTag($tag2);
548
549 $em->persist($entry);
550 $em->flush();
551
552 $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]);
553
554 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
555
556 $content = json_decode($this->client->getResponse()->getContent(), true);
557
558 $this->assertCount(2, $content);
559
560 $this->assertArrayHasKey('label', $content[0]);
561 $this->assertEquals($tag->getLabel(), $content[0]['label']);
562 $this->assertEquals($tag->getSlug(), $content[0]['slug']);
563
564 $this->assertArrayHasKey('label', $content[1]);
565 $this->assertEquals($tag2->getLabel(), $content[1]['label']);
566 $this->assertEquals($tag2->getSlug(), $content[1]['slug']);
567
568 $entries = $this->client->getContainer()
569 ->get('doctrine.orm.entity_manager')
570 ->getRepository('WallabagCoreBundle:Entry')
571 ->findAllByTagId($this->user->getId(), $tag->getId());
572
573 $this->assertCount(0, $entries);
574
575 $entries = $this->client->getContainer()
576 ->get('doctrine.orm.entity_manager')
577 ->getRepository('WallabagCoreBundle:Entry')
578 ->findAllByTagId($this->user->getId(), $tag2->getId());
579
580 $this->assertCount(0, $entries);
581 }
582
583 public function testDeleteTagsByLabelNotFound()
584 {
585 $this->client->request('DELETE', '/api/tags/label.json', ['tags' => 'does not exist']);
586
587 $this->assertEquals(404, $this->client->getResponse()->getStatusCode());
588 }
589
590 public function testGetVersion()
591 {
592 $this->client->request('GET', '/api/version');
593
594 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
595
596 $content = json_decode($this->client->getResponse()->getContent(), true);
597
598 $this->assertEquals($this->client->getContainer()->getParameter('wallabag_core.version'), $content);
599 }
600
601 public function testSaveIsArchivedAfterPost()
602 {
603 $entry = $this->client->getContainer()
604 ->get('doctrine.orm.entity_manager')
605 ->getRepository('WallabagCoreBundle:Entry')
606 ->findOneBy(['user' => 1, 'isArchived' => true]);
607
608 if (!$entry) {
609 $this->markTestSkipped('No content found in db.');
610 }
611
612 $this->client->request('POST', '/api/entries.json', [
613 'url' => $entry->getUrl(),
614 ]);
615
616 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
617
618 $content = json_decode($this->client->getResponse()->getContent(), true);
619
620 $this->assertEquals(true, $content['is_archived']);
621 }
622
623 public function testSaveIsStarredAfterPost()
624 {
625 $entry = $this->client->getContainer()
626 ->get('doctrine.orm.entity_manager')
627 ->getRepository('WallabagCoreBundle:Entry')
628 ->findOneBy(['user' => 1, 'isStarred' => true]);
629
630 if (!$entry) {
631 $this->markTestSkipped('No content found in db.');
632 }
633
634 $this->client->request('POST', '/api/entries.json', [
635 'url' => $entry->getUrl(),
636 ]);
637
638 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
639
640 $content = json_decode($this->client->getResponse()->getContent(), true);
641
642 $this->assertEquals(true, $content['is_starred']);
643 }
644
645 public function testSaveIsArchivedAfterPatch()
646 {
647 $entry = $this->client->getContainer()
648 ->get('doctrine.orm.entity_manager')
649 ->getRepository('WallabagCoreBundle:Entry')
650 ->findOneBy(['user' => 1, 'isArchived' => true]);
651
652 if (!$entry) {
653 $this->markTestSkipped('No content found in db.');
654 }
655
656 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
657 'title' => $entry->getTitle().'++',
658 ]);
659
660 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
661
662 $content = json_decode($this->client->getResponse()->getContent(), true);
663
664 $this->assertEquals(true, $content['is_archived']);
665 }
666
667 public function testSaveIsStarredAfterPatch()
668 {
669 $entry = $this->client->getContainer()
670 ->get('doctrine.orm.entity_manager')
671 ->getRepository('WallabagCoreBundle:Entry')
672 ->findOneBy(['user' => 1, 'isStarred' => true]);
673
674 if (!$entry) {
675 $this->markTestSkipped('No content found in db.');
676 }
677 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
678 'title' => $entry->getTitle().'++',
679 ]);
680
681 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
682
683 $content = json_decode($this->client->getResponse()->getContent(), true);
684
685 $this->assertEquals(true, $content['is_starred']);
686 }
687
688 public function testGetEntriesExists()
689 {
690 $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
691
692 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
693
694 $content = json_decode($this->client->getResponse()->getContent(), true);
695
696 $this->assertEquals(true, $content['exists']);
697 }
698
699 public function testGetEntriesExistsWhichDoesNotExists()
700 {
701 $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2');
702
703 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
704
705 $content = json_decode($this->client->getResponse()->getContent(), true);
706
707 $this->assertEquals(false, $content['exists']);
708 }
709 }