aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php63
1 files changed, 42 insertions, 21 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php
index bde5251f..7f69bd67 100644
--- a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php
@@ -22,39 +22,49 @@ class TagRestControllerTest extends WallabagApiTestCase
22 return end($content); 22 return end($content);
23 } 23 }
24 24
25 /** 25 public function testDeleteUserTag()
26 * @depends testGetUserTags
27 */
28 public function testDeleteUserTag($tag)
29 { 26 {
30 $tagName = $tag['label']; 27 $tagLabel = 'tagtest';
28 $tag = new Tag();
29 $tag->setLabel($tagLabel);
31 30
32 $this->client->request('DELETE', '/api/tags/'.$tag['id'].'.json'); 31 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
32 $em->persist($tag);
33 $em->flush();
34 $em->clear();
35
36 $this->client->request('DELETE', '/api/tags/'.$tag->getId().'.json');
33 37
34 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 38 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
35 39
36 $content = json_decode($this->client->getResponse()->getContent(), true); 40 $content = json_decode($this->client->getResponse()->getContent(), true);
37 41
38 $this->assertArrayHasKey('label', $content); 42 $this->assertArrayHasKey('label', $content);
39 $this->assertEquals($tag['label'], $content['label']); 43 $this->assertEquals($tag->getLabel(), $content['label']);
40 $this->assertEquals($tag['slug'], $content['slug']); 44 $this->assertEquals($tag->getSlug(), $content['slug']);
41 45
42 $entries = $this->client->getContainer() 46 $entries = $em->getRepository('WallabagCoreBundle:Entry')
43 ->get('doctrine.orm.entity_manager') 47 ->findAllByTagId($this->user->getId(), $tag->getId());
44 ->getRepository('WallabagCoreBundle:Entry')
45 ->findAllByTagId($this->user->getId(), $tag['id']);
46 48
47 $this->assertCount(0, $entries); 49 $this->assertCount(0, $entries);
48 50
49 $tag = $this->client->getContainer() 51 $tag = $em->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($tagLabel);
50 ->get('doctrine.orm.entity_manager') 52
51 ->getRepository('WallabagCoreBundle:Tag') 53 $this->assertNull($tag, $tagLabel.' was removed because it begun an orphan tag');
52 ->findOneByLabel($tagName); 54 }
53 55
54 $this->assertNull($tag, $tagName.' was removed because it begun an orphan tag'); 56 public function dataForDeletingTagByLabel()
57 {
58 return [
59 'by_query' => [true],
60 'by_body' => [false],
61 ];
55 } 62 }
56 63
57 public function testDeleteTagByLabel() 64 /**
65 * @dataProvider dataForDeletingTagByLabel
66 */
67 public function testDeleteTagByLabel($useQueryString)
58 { 68 {
59 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); 69 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
60 $entry = $this->client->getContainer() 70 $entry = $this->client->getContainer()
@@ -73,7 +83,11 @@ class TagRestControllerTest extends WallabagApiTestCase
73 $em->persist($entry); 83 $em->persist($entry);
74 $em->flush(); 84 $em->flush();
75 85
76 $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]); 86 if ($useQueryString) {
87 $this->client->request('DELETE', '/api/tag/label.json?tag='.$tag->getLabel());
88 } else {
89 $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]);
90 }
77 91
78 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 92 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
79 93
@@ -98,7 +112,10 @@ class TagRestControllerTest extends WallabagApiTestCase
98 $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); 112 $this->assertEquals(404, $this->client->getResponse()->getStatusCode());
99 } 113 }
100 114
101 public function testDeleteTagsByLabel() 115 /**
116 * @dataProvider dataForDeletingTagByLabel
117 */
118 public function testDeleteTagsByLabel($useQueryString)
102 { 119 {
103 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); 120 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
104 $entry = $this->client->getContainer() 121 $entry = $this->client->getContainer()
@@ -122,7 +139,11 @@ class TagRestControllerTest extends WallabagApiTestCase
122 $em->persist($entry); 139 $em->persist($entry);
123 $em->flush(); 140 $em->flush();
124 141
125 $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]); 142 if ($useQueryString) {
143 $this->client->request('DELETE', '/api/tags/label.json?tags='.$tag->getLabel().','.$tag2->getLabel());
144 } else {
145 $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]);
146 }
126 147
127 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 148 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
128 149