aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php')
-rw-r--r--src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php81
1 files changed, 77 insertions, 4 deletions
diff --git a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
index cce39d0b..ccb72d23 100644
--- a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
+++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
@@ -27,6 +27,9 @@ class WallabagRestControllerTest extends WallabagApiTestCase
27 $this->assertEquals($entry->getTitle(), $content['title']); 27 $this->assertEquals($entry->getTitle(), $content['title']);
28 $this->assertEquals($entry->getUrl(), $content['url']); 28 $this->assertEquals($entry->getUrl(), $content['url']);
29 $this->assertCount(count($entry->getTags()), $content['tags']); 29 $this->assertCount(count($entry->getTags()), $content['tags']);
30 $this->assertEquals($entry->getUserName(), $content['user_name']);
31 $this->assertEquals($entry->getUserEmail(), $content['user_email']);
32 $this->assertEquals($entry->getUserId(), $content['user_id']);
30 33
31 $this->assertTrue( 34 $this->assertTrue(
32 $this->client->getResponse()->headers->contains( 35 $this->client->getResponse()->headers->contains(
@@ -159,6 +162,25 @@ class WallabagRestControllerTest extends WallabagApiTestCase
159 $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']); 162 $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']);
160 $this->assertEquals(false, $content['is_archived']); 163 $this->assertEquals(false, $content['is_archived']);
161 $this->assertEquals(false, $content['is_starred']); 164 $this->assertEquals(false, $content['is_starred']);
165 $this->assertEquals(1, $content['user_id']);
166 $this->assertCount(1, $content['tags']);
167 }
168
169 public function testPostSameEntry()
170 {
171 $this->client->request('POST', '/api/entries.json', array(
172 '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',
173 'archive' => '1',
174 ));
175
176 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
177
178 $content = json_decode($this->client->getResponse()->getContent(), true);
179
180 $this->assertGreaterThan(0, $content['id']);
181 $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']);
182 $this->assertEquals(true, $content['is_archived']);
183 $this->assertEquals(false, $content['is_starred']);
162 $this->assertCount(1, $content['tags']); 184 $this->assertCount(1, $content['tags']);
163 } 185 }
164 186
@@ -166,8 +188,8 @@ class WallabagRestControllerTest extends WallabagApiTestCase
166 { 188 {
167 $this->client->request('POST', '/api/entries.json', array( 189 $this->client->request('POST', '/api/entries.json', array(
168 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', 190 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
169 'archive' => true, 191 'archive' => '1',
170 'starred' => true, 192 'starred' => '1',
171 )); 193 ));
172 194
173 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 195 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -178,6 +200,25 @@ class WallabagRestControllerTest extends WallabagApiTestCase
178 $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']); 200 $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']);
179 $this->assertEquals(true, $content['is_archived']); 201 $this->assertEquals(true, $content['is_archived']);
180 $this->assertEquals(true, $content['is_starred']); 202 $this->assertEquals(true, $content['is_starred']);
203 $this->assertEquals(1, $content['user_id']);
204 }
205
206 public function testPostArchivedAndStarredEntryWithoutQuotes()
207 {
208 $this->client->request('POST', '/api/entries.json', array(
209 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
210 'archive' => 0,
211 'starred' => 1,
212 ));
213
214 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
215
216 $content = json_decode($this->client->getResponse()->getContent(), true);
217
218 $this->assertGreaterThan(0, $content['id']);
219 $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']);
220 $this->assertEquals(false, $content['is_archived']);
221 $this->assertEquals(true, $content['is_starred']);
181 } 222 }
182 223
183 public function testPatchEntry() 224 public function testPatchEntry()
@@ -197,8 +238,40 @@ class WallabagRestControllerTest extends WallabagApiTestCase
197 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', array( 238 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', array(
198 'title' => 'New awesome title', 239 'title' => 'New awesome title',
199 'tags' => 'new tag '.uniqid(), 240 'tags' => 'new tag '.uniqid(),
200 'star' => true, 241 'starred' => '1',
201 'archive' => false, 242 'archive' => '0',
243 ));
244
245 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
246
247 $content = json_decode($this->client->getResponse()->getContent(), true);
248
249 $this->assertEquals($entry->getId(), $content['id']);
250 $this->assertEquals($entry->getUrl(), $content['url']);
251 $this->assertEquals('New awesome title', $content['title']);
252 $this->assertGreaterThan($nbTags, count($content['tags']));
253 $this->assertEquals(1, $content['user_id']);
254 }
255
256 public function testPatchEntryWithoutQuotes()
257 {
258 $entry = $this->client->getContainer()
259 ->get('doctrine.orm.entity_manager')
260 ->getRepository('WallabagCoreBundle:Entry')
261 ->findOneByUser(1);
262
263 if (!$entry) {
264 $this->markTestSkipped('No content found in db.');
265 }
266
267 // hydrate the tags relations
268 $nbTags = count($entry->getTags());
269
270 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', array(
271 'title' => 'New awesome title',
272 'tags' => 'new tag '.uniqid(),
273 'starred' => 1,
274 'archive' => 0,
202 )); 275 ));
203 276
204 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 277 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());