diff options
Diffstat (limited to 'tests/Wallabag/ApiBundle')
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php | 19 | ||||
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 104 |
2 files changed, 72 insertions, 51 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php index 95befa9c..6659443b 100644 --- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php | |||
@@ -82,11 +82,24 @@ class DeveloperControllerTest extends WallabagCoreTestCase | |||
82 | 82 | ||
83 | public function testRemoveClient() | 83 | public function testRemoveClient() |
84 | { | 84 | { |
85 | $this->logInAs('admin'); | ||
86 | $client = $this->getClient(); | 85 | $client = $this->getClient(); |
87 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | 86 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); |
88 | $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | ||
89 | 87 | ||
88 | // Try to remove an admin's client with a wrong user | ||
89 | $this->logInAs('bob'); | ||
90 | $client->request('GET', '/developer'); | ||
91 | $this->assertContains('no_client', $client->getResponse()->getContent()); | ||
92 | |||
93 | // get an ID of a admin's client | ||
94 | $this->logInAs('admin'); | ||
95 | $nbClients = $em->getRepository('WallabagApiBundle:Client')->findByUser($this->getLoggedInUserId()); | ||
96 | |||
97 | $this->logInAs('bob'); | ||
98 | $client->request('GET', '/developer/client/delete/'.$nbClients[0]->getId()); | ||
99 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | ||
100 | |||
101 | // Try to remove the admin's client with the good user | ||
102 | $this->logInAs('admin'); | ||
90 | $crawler = $client->request('GET', '/developer'); | 103 | $crawler = $client->request('GET', '/developer'); |
91 | 104 | ||
92 | $link = $crawler | 105 | $link = $crawler |
@@ -98,7 +111,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase | |||
98 | $client->click($link); | 111 | $client->click($link); |
99 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 112 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
100 | 113 | ||
101 | $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | 114 | $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findByUser($this->getLoggedInUserId()); |
102 | $this->assertGreaterThan(count($newNbClients), count($nbClients)); | 115 | $this->assertGreaterThan(count($newNbClients), count($nbClients)); |
103 | } | 116 | } |
104 | } | 117 | } |
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 825f8f7a..566e9493 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | |||
@@ -30,12 +30,55 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
30 | $this->assertEquals($entry->getUserEmail(), $content['user_email']); | 30 | $this->assertEquals($entry->getUserEmail(), $content['user_email']); |
31 | $this->assertEquals($entry->getUserId(), $content['user_id']); | 31 | $this->assertEquals($entry->getUserId(), $content['user_id']); |
32 | 32 | ||
33 | $this->assertTrue( | 33 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
34 | $this->client->getResponse()->headers->contains( | 34 | } |
35 | 'Content-Type', | 35 | |
36 | 'application/json' | 36 | public function testExportEntry() |
37 | ) | 37 | { |
38 | ); | 38 | $entry = $this->client->getContainer() |
39 | ->get('doctrine.orm.entity_manager') | ||
40 | ->getRepository('WallabagCoreBundle:Entry') | ||
41 | ->findOneBy(['user' => 1, 'isArchived' => false]); | ||
42 | |||
43 | if (!$entry) { | ||
44 | $this->markTestSkipped('No content found in db.'); | ||
45 | } | ||
46 | |||
47 | $this->client->request('GET', '/api/entries/'.$entry->getId().'/export.epub'); | ||
48 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
49 | |||
50 | // epub format got the content type in the content | ||
51 | $this->assertContains('application/epub', $this->client->getResponse()->getContent()); | ||
52 | $this->assertEquals('application/epub+zip', $this->client->getResponse()->headers->get('Content-Type')); | ||
53 | |||
54 | // re-auth client for mobi | ||
55 | $client = $this->createAuthorizedClient(); | ||
56 | $client->request('GET', '/api/entries/'.$entry->getId().'/export.mobi'); | ||
57 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
58 | |||
59 | $this->assertEquals('application/x-mobipocket-ebook', $client->getResponse()->headers->get('Content-Type')); | ||
60 | |||
61 | // re-auth client for pdf | ||
62 | $client = $this->createAuthorizedClient(); | ||
63 | $client->request('GET', '/api/entries/'.$entry->getId().'/export.pdf'); | ||
64 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
65 | |||
66 | $this->assertContains('PDF-', $client->getResponse()->getContent()); | ||
67 | $this->assertEquals('application/pdf', $client->getResponse()->headers->get('Content-Type')); | ||
68 | |||
69 | // re-auth client for pdf | ||
70 | $client = $this->createAuthorizedClient(); | ||
71 | $client->request('GET', '/api/entries/'.$entry->getId().'/export.txt'); | ||
72 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
73 | |||
74 | $this->assertContains('text/plain', $client->getResponse()->headers->get('Content-Type')); | ||
75 | |||
76 | // re-auth client for pdf | ||
77 | $client = $this->createAuthorizedClient(); | ||
78 | $client->request('GET', '/api/entries/'.$entry->getId().'/export.csv'); | ||
79 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
80 | |||
81 | $this->assertContains('application/csv', $client->getResponse()->headers->get('Content-Type')); | ||
39 | } | 82 | } |
40 | 83 | ||
41 | public function testGetOneEntryWrongUser() | 84 | public function testGetOneEntryWrongUser() |
@@ -68,12 +111,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
68 | $this->assertEquals(1, $content['page']); | 111 | $this->assertEquals(1, $content['page']); |
69 | $this->assertGreaterThanOrEqual(1, $content['pages']); | 112 | $this->assertGreaterThanOrEqual(1, $content['pages']); |
70 | 113 | ||
71 | $this->assertTrue( | 114 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
72 | $this->client->getResponse()->headers->contains( | ||
73 | 'Content-Type', | ||
74 | 'application/json' | ||
75 | ) | ||
76 | ); | ||
77 | } | 115 | } |
78 | 116 | ||
79 | public function testGetEntriesWithFullOptions() | 117 | public function testGetEntriesWithFullOptions() |
@@ -115,12 +153,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
115 | $this->assertContains('since=1443274283', $content['_links'][$link]['href']); | 153 | $this->assertContains('since=1443274283', $content['_links'][$link]['href']); |
116 | } | 154 | } |
117 | 155 | ||
118 | $this->assertTrue( | 156 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
119 | $this->client->getResponse()->headers->contains( | ||
120 | 'Content-Type', | ||
121 | 'application/json' | ||
122 | ) | ||
123 | ); | ||
124 | } | 157 | } |
125 | 158 | ||
126 | public function testGetStarredEntries() | 159 | public function testGetStarredEntries() |
@@ -148,12 +181,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
148 | $this->assertContains('sort=updated', $content['_links'][$link]['href']); | 181 | $this->assertContains('sort=updated', $content['_links'][$link]['href']); |
149 | } | 182 | } |
150 | 183 | ||
151 | $this->assertTrue( | 184 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
152 | $this->client->getResponse()->headers->contains( | ||
153 | 'Content-Type', | ||
154 | 'application/json' | ||
155 | ) | ||
156 | ); | ||
157 | } | 185 | } |
158 | 186 | ||
159 | public function testGetArchiveEntries() | 187 | public function testGetArchiveEntries() |
@@ -180,12 +208,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
180 | $this->assertContains('archive=1', $content['_links'][$link]['href']); | 208 | $this->assertContains('archive=1', $content['_links'][$link]['href']); |
181 | } | 209 | } |
182 | 210 | ||
183 | $this->assertTrue( | 211 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
184 | $this->client->getResponse()->headers->contains( | ||
185 | 'Content-Type', | ||
186 | 'application/json' | ||
187 | ) | ||
188 | ); | ||
189 | } | 212 | } |
190 | 213 | ||
191 | public function testGetTaggedEntries() | 214 | public function testGetTaggedEntries() |
@@ -212,12 +235,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
212 | $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']); | 235 | $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']); |
213 | } | 236 | } |
214 | 237 | ||
215 | $this->assertTrue( | 238 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
216 | $this->client->getResponse()->headers->contains( | ||
217 | 'Content-Type', | ||
218 | 'application/json' | ||
219 | ) | ||
220 | ); | ||
221 | } | 239 | } |
222 | 240 | ||
223 | public function testGetDatedEntries() | 241 | public function testGetDatedEntries() |
@@ -244,12 +262,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
244 | $this->assertContains('since=1443274283', $content['_links'][$link]['href']); | 262 | $this->assertContains('since=1443274283', $content['_links'][$link]['href']); |
245 | } | 263 | } |
246 | 264 | ||
247 | $this->assertTrue( | 265 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
248 | $this->client->getResponse()->headers->contains( | ||
249 | 'Content-Type', | ||
250 | 'application/json' | ||
251 | ) | ||
252 | ); | ||
253 | } | 266 | } |
254 | 267 | ||
255 | public function testGetDatedSupEntries() | 268 | public function testGetDatedSupEntries() |
@@ -277,12 +290,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
277 | $this->assertContains('since='.($future->getTimestamp() + 1000), $content['_links'][$link]['href']); | 290 | $this->assertContains('since='.($future->getTimestamp() + 1000), $content['_links'][$link]['href']); |
278 | } | 291 | } |
279 | 292 | ||
280 | $this->assertTrue( | 293 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
281 | $this->client->getResponse()->headers->contains( | ||
282 | 'Content-Type', | ||
283 | 'application/json' | ||
284 | ) | ||
285 | ); | ||
286 | } | 294 | } |
287 | 295 | ||
288 | public function testDeleteEntry() | 296 | public function testDeleteEntry() |