diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php | 81 |
1 files changed, 73 insertions, 8 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index fcfa8ccf..0eca7cde 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php | |||
@@ -44,10 +44,6 @@ class WallabagRestControllerTest extends WallabagTestCase | |||
44 | public function testWithBadHeaders() | 44 | public function testWithBadHeaders() |
45 | { | 45 | { |
46 | $client = $this->createClient(); | 46 | $client = $this->createClient(); |
47 | $client->request('GET', '/api/salts/admin.json'); | ||
48 | $salt = json_decode($client->getResponse()->getContent()); | ||
49 | |||
50 | $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); | ||
51 | 47 | ||
52 | $entry = $client->getContainer() | 48 | $entry = $client->getContainer() |
53 | ->get('doctrine.orm.entity_manager') | 49 | ->get('doctrine.orm.entity_manager') |
@@ -130,7 +126,7 @@ class WallabagRestControllerTest extends WallabagTestCase | |||
130 | $entry = $client->getContainer() | 126 | $entry = $client->getContainer() |
131 | ->get('doctrine.orm.entity_manager') | 127 | ->get('doctrine.orm.entity_manager') |
132 | ->getRepository('WallabagCoreBundle:Entry') | 128 | ->getRepository('WallabagCoreBundle:Entry') |
133 | ->findOneByIsDeleted(false); | 129 | ->findOneByUser(1); |
134 | 130 | ||
135 | if (!$entry) { | 131 | if (!$entry) { |
136 | $this->markTestSkipped('No content found in db.'); | 132 | $this->markTestSkipped('No content found in db.'); |
@@ -140,10 +136,79 @@ class WallabagRestControllerTest extends WallabagTestCase | |||
140 | 136 | ||
141 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 137 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
142 | 138 | ||
143 | $res = $client->getContainer() | 139 | // We'll try to delete this entry again |
140 | $client->request('GET', '/api/salts/admin.json'); | ||
141 | $salt = json_decode($client->getResponse()->getContent()); | ||
142 | |||
143 | $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); | ||
144 | |||
145 | $client->request('DELETE', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); | ||
146 | |||
147 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | ||
148 | } | ||
149 | |||
150 | public function testGetTagsEntry() | ||
151 | { | ||
152 | $client = $this->createClient(); | ||
153 | $client->request('GET', '/api/salts/admin.json'); | ||
154 | $salt = json_decode($client->getResponse()->getContent()); | ||
155 | $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); | ||
156 | |||
157 | $entry = $client->getContainer() | ||
158 | ->get('doctrine.orm.entity_manager') | ||
159 | ->getRepository('WallabagCoreBundle:Entry') | ||
160 | ->findOneWithTags(1); | ||
161 | |||
162 | $entry = $entry[0]; | ||
163 | |||
164 | if (!$entry) { | ||
165 | $this->markTestSkipped('No content found in db.'); | ||
166 | } | ||
167 | |||
168 | $tags = array(); | ||
169 | foreach ($entry->getTags() as $tag) { | ||
170 | $tags[] = array('id' => $tag->getId(), 'label' => $tag->getLabel()); | ||
171 | } | ||
172 | |||
173 | $client->request('GET', '/api/entries/'.$entry->getId().'/tags', array(), array(), $headers); | ||
174 | |||
175 | $this->assertEquals(json_encode($tags, JSON_HEX_QUOT), $client->getResponse()->getContent()); | ||
176 | } | ||
177 | |||
178 | public function testPostTagsOnEntry() | ||
179 | { | ||
180 | $client = $this->createClient(); | ||
181 | $client->request('GET', '/api/salts/admin.json'); | ||
182 | $salt = json_decode($client->getResponse()->getContent()); | ||
183 | $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); | ||
184 | |||
185 | $entry = $client->getContainer() | ||
186 | ->get('doctrine.orm.entity_manager') | ||
187 | ->getRepository('WallabagCoreBundle:Entry') | ||
188 | ->findOneByUser(1); | ||
189 | |||
190 | if (!$entry) { | ||
191 | $this->markTestSkipped('No content found in db.'); | ||
192 | } | ||
193 | |||
194 | $newTags = 'tag1,tag2,tag3'; | ||
195 | |||
196 | $client->request('POST', '/api/entries/'.$entry->getId().'/tags', array('tags' => $newTags), array(), $headers); | ||
197 | |||
198 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
199 | |||
200 | $entryDB = $client->getContainer() | ||
144 | ->get('doctrine.orm.entity_manager') | 201 | ->get('doctrine.orm.entity_manager') |
145 | ->getRepository('WallabagCoreBundle:Entry') | 202 | ->getRepository('WallabagCoreBundle:Entry') |
146 | ->findOneById($entry->getId()); | 203 | ->find($entry->getId()); |
147 | $this->assertEquals($res->isDeleted(), true); | 204 | |
205 | $tagsInDB = array(); | ||
206 | foreach ($entryDB->getTags()->toArray() as $tag) { | ||
207 | $tagsInDB[$tag->getId()] = $tag->getLabel(); | ||
208 | } | ||
209 | |||
210 | foreach (explode(',', $newTags) as $tag) { | ||
211 | $this->assertContains($tag, $tagsInDB); | ||
212 | } | ||
148 | } | 213 | } |
149 | } | 214 | } |