aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php113
1 files changed, 110 insertions, 3 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
index 528366af..ee5b2ab7 100644
--- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
@@ -3,6 +3,7 @@
3namespace Tests\Wallabag\ApiBundle\Controller; 3namespace Tests\Wallabag\ApiBundle\Controller;
4 4
5use Tests\Wallabag\ApiBundle\WallabagApiTestCase; 5use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
6use Wallabag\CoreBundle\Entity\Tag;
6 7
7class WallabagRestControllerTest extends WallabagApiTestCase 8class WallabagRestControllerTest extends WallabagApiTestCase
8{ 9{
@@ -359,7 +360,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
359 $entry = $this->client->getContainer() 360 $entry = $this->client->getContainer()
360 ->get('doctrine.orm.entity_manager') 361 ->get('doctrine.orm.entity_manager')
361 ->getRepository('WallabagCoreBundle:Entry') 362 ->getRepository('WallabagCoreBundle:Entry')
362 ->findOneWithTags(1); 363 ->findOneWithTags($this->user->getId());
363 364
364 $entry = $entry[0]; 365 $entry = $entry[0];
365 366
@@ -421,7 +422,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
421 $entry = $this->client->getContainer() 422 $entry = $this->client->getContainer()
422 ->get('doctrine.orm.entity_manager') 423 ->get('doctrine.orm.entity_manager')
423 ->getRepository('WallabagCoreBundle:Entry') 424 ->getRepository('WallabagCoreBundle:Entry')
424 ->findOneWithTags(1); 425 ->findOneWithTags($this->user->getId());
425 $entry = $entry[0]; 426 $entry = $entry[0];
426 427
427 if (!$entry) { 428 if (!$entry) {
@@ -472,7 +473,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
472 $this->assertEquals($tag['label'], $content['label']); 473 $this->assertEquals($tag['label'], $content['label']);
473 $this->assertEquals($tag['slug'], $content['slug']); 474 $this->assertEquals($tag['slug'], $content['slug']);
474 475
475 $entries = $entry = $this->client->getContainer() 476 $entries = $this->client->getContainer()
476 ->get('doctrine.orm.entity_manager') 477 ->get('doctrine.orm.entity_manager')
477 ->getRepository('WallabagCoreBundle:Entry') 478 ->getRepository('WallabagCoreBundle:Entry')
478 ->findAllByTagId($this->user->getId(), $tag['id']); 479 ->findAllByTagId($this->user->getId(), $tag['id']);
@@ -480,6 +481,112 @@ class WallabagRestControllerTest extends WallabagApiTestCase
480 $this->assertCount(0, $entries); 481 $this->assertCount(0, $entries);
481 } 482 }
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
483 public function testGetVersion() 590 public function testGetVersion()
484 { 591 {
485 $this->client->request('GET', '/api/version'); 592 $this->client->request('GET', '/api/version');