diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php | 93 |
1 files changed, 89 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php index febdf4d4..3d3b97a9 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php | |||
@@ -21,7 +21,7 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
21 | $this->logInAs('admin'); | 21 | $this->logInAs('admin'); |
22 | $client = $this->getClient(); | 22 | $client = $this->getClient(); |
23 | 23 | ||
24 | $crawler = $client->request('GET', '/export/awesomeness.epub'); | 24 | $client->request('GET', '/export/awesomeness.epub'); |
25 | 25 | ||
26 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 26 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
27 | } | 27 | } |
@@ -31,7 +31,34 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
31 | $this->logInAs('admin'); | 31 | $this->logInAs('admin'); |
32 | $client = $this->getClient(); | 32 | $client = $this->getClient(); |
33 | 33 | ||
34 | $crawler = $client->request('GET', '/export/unread.xslx'); | 34 | $client->request('GET', '/export/unread.xslx'); |
35 | |||
36 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | ||
37 | } | ||
38 | |||
39 | public function testUnsupportedFormatExport() | ||
40 | { | ||
41 | $this->logInAs('admin'); | ||
42 | $client = $this->getClient(); | ||
43 | |||
44 | $client->request('GET', '/export/unread.txt'); | ||
45 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | ||
46 | |||
47 | $content = $client->getContainer() | ||
48 | ->get('doctrine.orm.entity_manager') | ||
49 | ->getRepository('WallabagCoreBundle:Entry') | ||
50 | ->findOneByUsernameAndNotArchived('admin'); | ||
51 | |||
52 | $client->request('GET', '/export/'.$content->getId().'.txt'); | ||
53 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | ||
54 | } | ||
55 | |||
56 | public function testBadEntryId() | ||
57 | { | ||
58 | $this->logInAs('admin'); | ||
59 | $client = $this->getClient(); | ||
60 | |||
61 | $client->request('GET', '/export/0.mobi'); | ||
35 | 62 | ||
36 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 63 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
37 | } | 64 | } |
@@ -97,20 +124,33 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
97 | $this->logInAs('admin'); | 124 | $this->logInAs('admin'); |
98 | $client = $this->getClient(); | 125 | $client = $this->getClient(); |
99 | 126 | ||
127 | // to be sure results are the same | ||
128 | $contentInDB = $client->getContainer() | ||
129 | ->get('doctrine.orm.entity_manager') | ||
130 | ->getRepository('WallabagCoreBundle:Entry') | ||
131 | ->createQueryBuilder('e') | ||
132 | ->leftJoin('e.user', 'u') | ||
133 | ->where('u.username = :username')->setParameter('username', 'admin') | ||
134 | ->andWhere('e.isArchived = true') | ||
135 | ->getQuery() | ||
136 | ->getArrayResult(); | ||
137 | |||
100 | ob_start(); | 138 | ob_start(); |
101 | $crawler = $client->request('GET', '/export/unread.csv'); | 139 | $crawler = $client->request('GET', '/export/archive.csv'); |
102 | ob_end_clean(); | 140 | ob_end_clean(); |
103 | 141 | ||
104 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 142 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
105 | 143 | ||
106 | $headers = $client->getResponse()->headers; | 144 | $headers = $client->getResponse()->headers; |
107 | $this->assertEquals('application/csv', $headers->get('content-type')); | 145 | $this->assertEquals('application/csv', $headers->get('content-type')); |
108 | $this->assertEquals('attachment; filename="Unread articles.csv"', $headers->get('content-disposition')); | 146 | $this->assertEquals('attachment; filename="Archive articles.csv"', $headers->get('content-disposition')); |
109 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); | 147 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); |
110 | 148 | ||
111 | $csv = str_getcsv($client->getResponse()->getContent(), "\n"); | 149 | $csv = str_getcsv($client->getResponse()->getContent(), "\n"); |
112 | 150 | ||
113 | $this->assertGreaterThan(1, $csv); | 151 | $this->assertGreaterThan(1, $csv); |
152 | // +1 for title line | ||
153 | $this->assertEquals(count($contentInDB)+1, count($csv)); | ||
114 | $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language', $csv[0]); | 154 | $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language', $csv[0]); |
115 | } | 155 | } |
116 | 156 | ||
@@ -119,6 +159,16 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
119 | $this->logInAs('admin'); | 159 | $this->logInAs('admin'); |
120 | $client = $this->getClient(); | 160 | $client = $this->getClient(); |
121 | 161 | ||
162 | // to be sure results are the same | ||
163 | $contentInDB = $client->getContainer() | ||
164 | ->get('doctrine.orm.entity_manager') | ||
165 | ->getRepository('WallabagCoreBundle:Entry') | ||
166 | ->createQueryBuilder('e') | ||
167 | ->leftJoin('e.user', 'u') | ||
168 | ->where('u.username = :username')->setParameter('username', 'admin') | ||
169 | ->getQuery() | ||
170 | ->getArrayResult(); | ||
171 | |||
122 | ob_start(); | 172 | ob_start(); |
123 | $crawler = $client->request('GET', '/export/all.json'); | 173 | $crawler = $client->request('GET', '/export/all.json'); |
124 | ob_end_clean(); | 174 | ob_end_clean(); |
@@ -129,6 +179,21 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
129 | $this->assertEquals('application/json', $headers->get('content-type')); | 179 | $this->assertEquals('application/json', $headers->get('content-type')); |
130 | $this->assertEquals('attachment; filename="All articles.json"', $headers->get('content-disposition')); | 180 | $this->assertEquals('attachment; filename="All articles.json"', $headers->get('content-disposition')); |
131 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); | 181 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); |
182 | |||
183 | $content = json_decode($client->getResponse()->getContent(), true); | ||
184 | $this->assertEquals(count($contentInDB), count($content)); | ||
185 | $this->assertArrayHasKey('id', $content[0]); | ||
186 | $this->assertArrayHasKey('title', $content[0]); | ||
187 | $this->assertArrayHasKey('url', $content[0]); | ||
188 | $this->assertArrayHasKey('is_archived', $content[0]); | ||
189 | $this->assertArrayHasKey('is_starred', $content[0]); | ||
190 | $this->assertArrayHasKey('content', $content[0]); | ||
191 | $this->assertArrayHasKey('mimetype', $content[0]); | ||
192 | $this->assertArrayHasKey('language', $content[0]); | ||
193 | $this->assertArrayHasKey('reading_time', $content[0]); | ||
194 | $this->assertArrayHasKey('domain_name', $content[0]); | ||
195 | $this->assertArrayHasKey('preview_picture', $content[0]); | ||
196 | $this->assertArrayHasKey('tags', $content[0]); | ||
132 | } | 197 | } |
133 | 198 | ||
134 | public function testXmlExport() | 199 | public function testXmlExport() |
@@ -136,6 +201,17 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
136 | $this->logInAs('admin'); | 201 | $this->logInAs('admin'); |
137 | $client = $this->getClient(); | 202 | $client = $this->getClient(); |
138 | 203 | ||
204 | // to be sure results are the same | ||
205 | $contentInDB = $client->getContainer() | ||
206 | ->get('doctrine.orm.entity_manager') | ||
207 | ->getRepository('WallabagCoreBundle:Entry') | ||
208 | ->createQueryBuilder('e') | ||
209 | ->leftJoin('e.user', 'u') | ||
210 | ->where('u.username = :username')->setParameter('username', 'admin') | ||
211 | ->andWhere('e.isArchived = false') | ||
212 | ->getQuery() | ||
213 | ->getArrayResult(); | ||
214 | |||
139 | ob_start(); | 215 | ob_start(); |
140 | $crawler = $client->request('GET', '/export/unread.xml'); | 216 | $crawler = $client->request('GET', '/export/unread.xml'); |
141 | ob_end_clean(); | 217 | ob_end_clean(); |
@@ -146,5 +222,14 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
146 | $this->assertEquals('application/xml', $headers->get('content-type')); | 222 | $this->assertEquals('application/xml', $headers->get('content-type')); |
147 | $this->assertEquals('attachment; filename="Unread articles.xml"', $headers->get('content-disposition')); | 223 | $this->assertEquals('attachment; filename="Unread articles.xml"', $headers->get('content-disposition')); |
148 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); | 224 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); |
225 | |||
226 | $content = new \SimpleXMLElement($client->getResponse()->getContent()); | ||
227 | $this->assertGreaterThan(0, $content->count()); | ||
228 | $this->assertEquals(count($contentInDB), $content->count()); | ||
229 | $this->assertNotEmpty('id', (string) $content->entry[0]->id); | ||
230 | $this->assertNotEmpty('title', (string) $content->entry[0]->title); | ||
231 | $this->assertNotEmpty('url', (string) $content->entry[0]->url); | ||
232 | $this->assertNotEmpty('content', (string) $content->entry[0]->content); | ||
233 | $this->assertNotEmpty('domain_name', (string) $content->entry[0]->domain_name); | ||
149 | } | 234 | } |
150 | } | 235 | } |