]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
Merge remote-tracking branch 'origin/master' into 2.1
[github/wallabag/wallabag.git] / tests / Wallabag / ApiBundle / Controller / WallabagRestControllerTest.php
CommitLineData
769e19dc
J
1<?php
2
23634d5d 3namespace Tests\Wallabag\ApiBundle\Controller;
769e19dc 4
23634d5d 5use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
a0e1eafc 6use Wallabag\CoreBundle\Entity\Tag;
769e19dc 7
8a493541 8class WallabagRestControllerTest extends WallabagApiTestCase
769e19dc
J
9{
10 protected static $salt;
11
769e19dc
J
12 public function testGetOneEntry()
13 {
fcb1fba5 14 $entry = $this->client->getContainer()
769e19dc
J
15 ->get('doctrine.orm.entity_manager')
16 ->getRepository('WallabagCoreBundle:Entry')
4094ea47 17 ->findOneBy(['user' => 1, 'isArchived' => false]);
769e19dc
J
18
19 if (!$entry) {
20 $this->markTestSkipped('No content found in db.');
21 }
22
fcb1fba5
NL
23 $this->client->request('GET', '/api/entries/'.$entry->getId().'.json');
24 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
769e19dc 25
fcb1fba5 26 $content = json_decode($this->client->getResponse()->getContent(), true);
769e19dc
J
27
28 $this->assertEquals($entry->getTitle(), $content['title']);
29 $this->assertEquals($entry->getUrl(), $content['url']);
30 $this->assertCount(count($entry->getTags()), $content['tags']);
bc44aa57
TC
31 $this->assertEquals($entry->getUserName(), $content['user_name']);
32 $this->assertEquals($entry->getUserEmail(), $content['user_email']);
33 $this->assertEquals($entry->getUserId(), $content['user_id']);
769e19dc
J
34
35 $this->assertTrue(
fcb1fba5 36 $this->client->getResponse()->headers->contains(
769e19dc
J
37 'Content-Type',
38 'application/json'
39 )
40 );
41 }
42
43 public function testGetOneEntryWrongUser()
44 {
fcb1fba5 45 $entry = $this->client->getContainer()
769e19dc
J
46 ->get('doctrine.orm.entity_manager')
47 ->getRepository('WallabagCoreBundle:Entry')
4094ea47 48 ->findOneBy(['user' => 2, 'isArchived' => false]);
769e19dc
J
49
50 if (!$entry) {
51 $this->markTestSkipped('No content found in db.');
52 }
53
fcb1fba5 54 $this->client->request('GET', '/api/entries/'.$entry->getId().'.json');
769e19dc 55
fcb1fba5 56 $this->assertEquals(403, $this->client->getResponse()->getStatusCode());
769e19dc
J
57 }
58
59 public function testGetEntries()
60 {
fcb1fba5 61 $this->client->request('GET', '/api/entries');
769e19dc 62
fcb1fba5 63 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
769e19dc 64
fcb1fba5 65 $content = json_decode($this->client->getResponse()->getContent(), true);
769e19dc
J
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(
fcb1fba5 74 $this->client->getResponse()->headers->contains(
769e19dc
J
75 'Content-Type',
76 'application/json'
77 )
78 );
79 }
80
81 public function testGetStarredEntries()
82 {
f0fd82d0 83 $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);
769e19dc 84
fcb1fba5 85 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
e6f55346 86
fcb1fba5 87 $content = json_decode($this->client->getResponse()->getContent(), true);
e6f55346
JB
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(
fcb1fba5 96 $this->client->getResponse()->headers->contains(
e6f55346
JB
97 'Content-Type',
98 'application/json'
99 )
100 );
101 }
102
103 public function testGetArchiveEntries()
104 {
4094ea47 105 $this->client->request('GET', '/api/entries', ['archive' => 1]);
769e19dc 106
fcb1fba5 107 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
769e19dc 108
fcb1fba5 109 $content = json_decode($this->client->getResponse()->getContent(), true);
769e19dc
J
110
111 $this->assertGreaterThanOrEqual(1, count($content));
9744e971 112 $this->assertNotEmpty($content['_embedded']['items']);
28803f10
TC
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']);
9744e971 135 $this->assertGreaterThanOrEqual(1, $content['total']);
769e19dc 136 $this->assertEquals(1, $content['page']);
9744e971 137 $this->assertGreaterThanOrEqual(1, $content['pages']);
769e19dc
J
138
139 $this->assertTrue(
fcb1fba5 140 $this->client->getResponse()->headers->contains(
769e19dc
J
141 'Content-Type',
142 'application/json'
143 )
144 );
145 }
146
e5fb89e5
TC
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
769e19dc
J
192 public function testDeleteEntry()
193 {
fcb1fba5 194 $entry = $this->client->getContainer()
769e19dc
J
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
fcb1fba5 203 $this->client->request('DELETE', '/api/entries/'.$entry->getId().'.json');
769e19dc 204
fcb1fba5 205 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
769e19dc 206
fcb1fba5 207 $content = json_decode($this->client->getResponse()->getContent(), true);
769e19dc
J
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
fcb1fba5 213 $this->client->request('DELETE', '/api/entries/'.$entry->getId().'.json');
769e19dc 214
fcb1fba5 215 $this->assertEquals(404, $this->client->getResponse()->getStatusCode());
769e19dc
J
216 }
217
218 public function testPostEntry()
219 {
4094ea47 220 $this->client->request('POST', '/api/entries.json', [
769e19dc
J
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',
51a15609 223 'title' => 'New title for my article',
4094ea47 224 ]);
769e19dc 225
fcb1fba5 226 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
769e19dc 227
fcb1fba5 228 $content = json_decode($this->client->getResponse()->getContent(), true);
769e19dc
J
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']);
51a15609 234 $this->assertEquals('New title for my article', $content['title']);
bc44aa57 235 $this->assertEquals(1, $content['user_id']);
769e19dc
J
236 $this->assertCount(1, $content['tags']);
237 }
238
3107f92a
TC
239 public function testPostSameEntry()
240 {
4094ea47 241 $this->client->request('POST', '/api/entries.json', [
3107f92a
TC
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',
2baca964 244 'tags' => 'google, apple',
4094ea47 245 ]);
3107f92a
TC
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']);
2baca964 255 $this->assertCount(2, $content['tags']);
3107f92a
TC
256 }
257
09d8bb6f 258 public function testPostArchivedAndStarredEntry()
816ad405 259 {
4094ea47 260 $this->client->request('POST', '/api/entries.json', [
816ad405 261 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
189ef634
TC
262 'archive' => '1',
263 'starred' => '1',
4094ea47 264 ]);
816ad405
TC
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']);
09d8bb6f 273 $this->assertEquals(true, $content['is_starred']);
bc44aa57 274 $this->assertEquals(1, $content['user_id']);
816ad405
TC
275 }
276
2f60e5ea
TC
277 public function testPostArchivedAndStarredEntryWithoutQuotes()
278 {
4094ea47 279 $this->client->request('POST', '/api/entries.json', [
2f60e5ea
TC
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,
4094ea47 283 ]);
2f60e5ea
TC
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
769e19dc
J
295 public function testPatchEntry()
296 {
fcb1fba5 297 $entry = $this->client->getContainer()
769e19dc
J
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
4094ea47 309 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
769e19dc
J
310 'title' => 'New awesome title',
311 'tags' => 'new tag '.uniqid(),
189ef634
TC
312 'starred' => '1',
313 'archive' => '0',
4094ea47 314 ]);
769e19dc 315
fcb1fba5 316 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
769e19dc 317
fcb1fba5 318 $content = json_decode($this->client->getResponse()->getContent(), true);
769e19dc
J
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']));
bc44aa57 324 $this->assertEquals(1, $content['user_id']);
769e19dc
J
325 }
326
2f60e5ea
TC
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
4094ea47 341 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
2f60e5ea
TC
342 'title' => 'New awesome title',
343 'tags' => 'new tag '.uniqid(),
344 'starred' => 1,
345 'archive' => 0,
4094ea47 346 ]);
2f60e5ea
TC
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
769e19dc
J
358 public function testGetTagsEntry()
359 {
fcb1fba5 360 $entry = $this->client->getContainer()
769e19dc
J
361 ->get('doctrine.orm.entity_manager')
362 ->getRepository('WallabagCoreBundle:Entry')
a0e1eafc 363 ->findOneWithTags($this->user->getId());
769e19dc
J
364
365 $entry = $entry[0];
366
367 if (!$entry) {
368 $this->markTestSkipped('No content found in db.');
369 }
370
4094ea47 371 $tags = [];
769e19dc 372 foreach ($entry->getTags() as $tag) {
4094ea47 373 $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()];
769e19dc
J
374 }
375
fcb1fba5 376 $this->client->request('GET', '/api/entries/'.$entry->getId().'/tags');
769e19dc 377
fcb1fba5 378 $this->assertEquals(json_encode($tags, JSON_HEX_QUOT), $this->client->getResponse()->getContent());
769e19dc
J
379 }
380
381 public function testPostTagsOnEntry()
382 {
fcb1fba5 383 $entry = $this->client->getContainer()
769e19dc
J
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
4094ea47 396 $this->client->request('POST', '/api/entries/'.$entry->getId().'/tags', ['tags' => $newTags]);
769e19dc 397
fcb1fba5 398 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
769e19dc 399
fcb1fba5 400 $content = json_decode($this->client->getResponse()->getContent(), true);
769e19dc
J
401
402 $this->assertArrayHasKey('tags', $content);
4346a860 403 $this->assertEquals($nbTags + 3, count($content['tags']));
769e19dc 404
fcb1fba5 405 $entryDB = $this->client->getContainer()
769e19dc
J
406 ->get('doctrine.orm.entity_manager')
407 ->getRepository('WallabagCoreBundle:Entry')
408 ->find($entry->getId());
409
4094ea47 410 $tagsInDB = [];
769e19dc
J
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
fcb1fba5 420 public function testDeleteOneTagEntry()
769e19dc 421 {
fcb1fba5 422 $entry = $this->client->getContainer()
769e19dc
J
423 ->get('doctrine.orm.entity_manager')
424 ->getRepository('WallabagCoreBundle:Entry')
a0e1eafc 425 ->findOneWithTags($this->user->getId());
fcb1fba5 426 $entry = $entry[0];
769e19dc
J
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
fcb1fba5 436 $this->client->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json');
769e19dc 437
fcb1fba5 438 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
769e19dc 439
fcb1fba5 440 $content = json_decode($this->client->getResponse()->getContent(), true);
769e19dc
J
441
442 $this->assertArrayHasKey('tags', $content);
4346a860 443 $this->assertEquals($nbTags - 1, count($content['tags']));
769e19dc
J
444 }
445
446 public function testGetUserTags()
447 {
fcb1fba5 448 $this->client->request('GET', '/api/tags.json');
769e19dc 449
fcb1fba5 450 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
769e19dc 451
fcb1fba5 452 $content = json_decode($this->client->getResponse()->getContent(), true);
769e19dc
J
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 {
fcb1fba5 466 $this->client->request('DELETE', '/api/tags/'.$tag['id'].'.json');
769e19dc 467
fcb1fba5 468 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
769e19dc 469
fcb1fba5 470 $content = json_decode($this->client->getResponse()->getContent(), true);
769e19dc
J
471
472 $this->assertArrayHasKey('label', $content);
473 $this->assertEquals($tag['label'], $content['label']);
fc732227 474 $this->assertEquals($tag['slug'], $content['slug']);
4059a061 475
a0e1eafc 476 $entries = $this->client->getContainer()
4059a061
JB
477 ->get('doctrine.orm.entity_manager')
478 ->getRepository('WallabagCoreBundle:Entry')
479 ->findAllByTagId($this->user->getId(), $tag['id']);
480
481 $this->assertCount(0, $entries);
769e19dc 482 }
9761bfa1 483
a0e1eafc
JB
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
6f8310b4
TC
590 public function testGetVersion()
591 {
592 $this->client->request('GET', '/api/version');
9761bfa1
V
593
594 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
595
596 $content = json_decode($this->client->getResponse()->getContent(), true);
597
6f8310b4 598 $this->assertEquals($this->client->getContainer()->getParameter('wallabag_core.version'), $content);
9761bfa1 599 }
bba271e6
YE
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
69221684 620 $this->assertEquals(true, $content['is_archived']);
bba271e6
YE
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
69221684 642 $this->assertEquals(true, $content['is_starred']);
bba271e6
YE
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
69221684 685 $this->assertEquals(true, $content['is_starred']);
bba271e6 686 }
6273fefd
JB
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 }
55551e33
JB
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 }
769e19dc 709}