aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php140
1 files changed, 92 insertions, 48 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 825f8f7a..409a8291 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()
@@ -670,4 +678,40 @@ class EntryRestControllerTest extends WallabagApiTestCase
670 678
671 $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); 679 $this->assertEquals(403, $this->client->getResponse()->getStatusCode());
672 } 680 }
681
682 public function testReloadEntryErrorWhileFetching()
683 {
684 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
685 ->getRepository('WallabagCoreBundle:Entry')
686 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
687
688 if (!$entry) {
689 $this->markTestSkipped('No content found in db.');
690 }
691
692 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json');
693 $this->assertEquals(304, $this->client->getResponse()->getStatusCode());
694 }
695
696 public function testReloadEntry()
697 {
698 $this->client->request('POST', '/api/entries.json', [
699 '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',
700 'archive' => '1',
701 'tags' => 'google, apple',
702 ]);
703
704 $json = json_decode($this->client->getResponse()->getContent(), true);
705
706 $this->setUp();
707
708 $this->client->request('PATCH', '/api/entries/'.$json['id'].'/reload.json');
709 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
710
711 $content = json_decode($this->client->getResponse()->getContent(), true);
712
713 $this->assertNotEmpty($content['title']);
714
715 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
716 }
673} 717}