aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
diff options
context:
space:
mode:
authorJeremy Benoist <j0k3r@users.noreply.github.com>2016-10-12 14:06:33 +0200
committerGitHub <noreply@github.com>2016-10-12 14:06:33 +0200
commitb1b561da518ae3add4445c46ef8398a314c8de37 (patch)
tree3ff96d8cfe8021d6fbaa487dd0db2ef01f74ba42 /tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
parente4cf672ccf61689ba28c2e89fc55f83167800b18 (diff)
parent3f3a60879e168f4a8040c441e295fa63e024961d (diff)
downloadwallabag-b1b561da518ae3add4445c46ef8398a314c8de37.tar.gz
wallabag-b1b561da518ae3add4445c46ef8398a314c8de37.tar.zst
wallabag-b1b561da518ae3add4445c46ef8398a314c8de37.zip
Merge pull request #2372 from pmartin/api-get-entry-as-epub
API: ability to export entry in all available format (epub, pdf, etc...)
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php104
1 files changed, 56 insertions, 48 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
index 5dcb3e00..6bca3c8b 100644
--- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
@@ -32,12 +32,55 @@ class WallabagRestControllerTest extends WallabagApiTestCase
32 $this->assertEquals($entry->getUserEmail(), $content['user_email']); 32 $this->assertEquals($entry->getUserEmail(), $content['user_email']);
33 $this->assertEquals($entry->getUserId(), $content['user_id']); 33 $this->assertEquals($entry->getUserId(), $content['user_id']);
34 34
35 $this->assertTrue( 35 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
36 $this->client->getResponse()->headers->contains( 36 }
37 'Content-Type', 37
38 'application/json' 38 public function testExportEntry()
39 ) 39 {
40 ); 40 $entry = $this->client->getContainer()
41 ->get('doctrine.orm.entity_manager')
42 ->getRepository('WallabagCoreBundle:Entry')
43 ->findOneBy(['user' => 1, 'isArchived' => false]);
44
45 if (!$entry) {
46 $this->markTestSkipped('No content found in db.');
47 }
48
49 $this->client->request('GET', '/api/entries/'.$entry->getId().'/export.epub');
50 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
51
52 // epub format got the content type in the content
53 $this->assertContains('application/epub', $this->client->getResponse()->getContent());
54 $this->assertEquals('application/epub+zip', $this->client->getResponse()->headers->get('Content-Type'));
55
56 // re-auth client for mobi
57 $client = $this->createAuthorizedClient();
58 $client->request('GET', '/api/entries/'.$entry->getId().'/export.mobi');
59 $this->assertEquals(200, $client->getResponse()->getStatusCode());
60
61 $this->assertEquals('application/x-mobipocket-ebook', $client->getResponse()->headers->get('Content-Type'));
62
63 // re-auth client for pdf
64 $client = $this->createAuthorizedClient();
65 $client->request('GET', '/api/entries/'.$entry->getId().'/export.pdf');
66 $this->assertEquals(200, $client->getResponse()->getStatusCode());
67
68 $this->assertContains('PDF-', $client->getResponse()->getContent());
69 $this->assertEquals('application/pdf', $client->getResponse()->headers->get('Content-Type'));
70
71 // re-auth client for pdf
72 $client = $this->createAuthorizedClient();
73 $client->request('GET', '/api/entries/'.$entry->getId().'/export.txt');
74 $this->assertEquals(200, $client->getResponse()->getStatusCode());
75
76 $this->assertContains('text/plain', $client->getResponse()->headers->get('Content-Type'));
77
78 // re-auth client for pdf
79 $client = $this->createAuthorizedClient();
80 $client->request('GET', '/api/entries/'.$entry->getId().'/export.csv');
81 $this->assertEquals(200, $client->getResponse()->getStatusCode());
82
83 $this->assertContains('application/csv', $client->getResponse()->headers->get('Content-Type'));
41 } 84 }
42 85
43 public function testGetOneEntryWrongUser() 86 public function testGetOneEntryWrongUser()
@@ -70,12 +113,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
70 $this->assertEquals(1, $content['page']); 113 $this->assertEquals(1, $content['page']);
71 $this->assertGreaterThanOrEqual(1, $content['pages']); 114 $this->assertGreaterThanOrEqual(1, $content['pages']);
72 115
73 $this->assertTrue( 116 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
74 $this->client->getResponse()->headers->contains(
75 'Content-Type',
76 'application/json'
77 )
78 );
79 } 117 }
80 118
81 public function testGetEntriesWithFullOptions() 119 public function testGetEntriesWithFullOptions()
@@ -117,12 +155,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
117 $this->assertContains('since=1443274283', $content['_links'][$link]['href']); 155 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
118 } 156 }
119 157
120 $this->assertTrue( 158 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
121 $this->client->getResponse()->headers->contains(
122 'Content-Type',
123 'application/json'
124 )
125 );
126 } 159 }
127 160
128 public function testGetStarredEntries() 161 public function testGetStarredEntries()
@@ -150,12 +183,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
150 $this->assertContains('sort=updated', $content['_links'][$link]['href']); 183 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
151 } 184 }
152 185
153 $this->assertTrue( 186 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
154 $this->client->getResponse()->headers->contains(
155 'Content-Type',
156 'application/json'
157 )
158 );
159 } 187 }
160 188
161 public function testGetArchiveEntries() 189 public function testGetArchiveEntries()
@@ -182,12 +210,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
182 $this->assertContains('archive=1', $content['_links'][$link]['href']); 210 $this->assertContains('archive=1', $content['_links'][$link]['href']);
183 } 211 }
184 212
185 $this->assertTrue( 213 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
186 $this->client->getResponse()->headers->contains(
187 'Content-Type',
188 'application/json'
189 )
190 );
191 } 214 }
192 215
193 public function testGetTaggedEntries() 216 public function testGetTaggedEntries()
@@ -214,12 +237,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
214 $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']); 237 $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']);
215 } 238 }
216 239
217 $this->assertTrue( 240 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
218 $this->client->getResponse()->headers->contains(
219 'Content-Type',
220 'application/json'
221 )
222 );
223 } 241 }
224 242
225 public function testGetDatedEntries() 243 public function testGetDatedEntries()
@@ -246,12 +264,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
246 $this->assertContains('since=1443274283', $content['_links'][$link]['href']); 264 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
247 } 265 }
248 266
249 $this->assertTrue( 267 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
250 $this->client->getResponse()->headers->contains(
251 'Content-Type',
252 'application/json'
253 )
254 );
255 } 268 }
256 269
257 public function testGetDatedSupEntries() 270 public function testGetDatedSupEntries()
@@ -279,12 +292,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
279 $this->assertContains('since='.($future->getTimestamp() + 1000), $content['_links'][$link]['href']); 292 $this->assertContains('since='.($future->getTimestamp() + 1000), $content['_links'][$link]['href']);
280 } 293 }
281 294
282 $this->assertTrue( 295 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
283 $this->client->getResponse()->headers->contains(
284 'Content-Type',
285 'application/json'
286 )
287 );
288 } 296 }
289 297
290 public function testDeleteEntry() 298 public function testDeleteEntry()