diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-06-23 11:47:46 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-06-23 11:47:46 +0200 |
commit | f49d9ca383c9f8a1bc426cfabf6b1cea53ea26b4 (patch) | |
tree | 156b1a29cfbe1962e68d409c3dea5a3911a34e9c /src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php | |
parent | 49e2854d5c15bbce3f24f91da34450e8f209295b (diff) | |
parent | fb5c17a9ab5e10b1de9caa50e73638fdae19cb78 (diff) | |
download | wallabag-f49d9ca383c9f8a1bc426cfabf6b1cea53ea26b4.tar.gz wallabag-f49d9ca383c9f8a1bc426cfabf6b1cea53ea26b4.tar.zst wallabag-f49d9ca383c9f8a1bc426cfabf6b1cea53ea26b4.zip |
Merge branch 'master' into 2.1
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php | 251 |
1 files changed, 0 insertions, 251 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php deleted file mode 100644 index 76c98055..00000000 --- a/src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php +++ /dev/null | |||
@@ -1,251 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Tests\Controller; | ||
4 | |||
5 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; | ||
6 | |||
7 | class ExportControllerTest extends WallabagCoreTestCase | ||
8 | { | ||
9 | public function testLogin() | ||
10 | { | ||
11 | $client = $this->getClient(); | ||
12 | |||
13 | $client->request('GET', '/export/unread.csv'); | ||
14 | |||
15 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
16 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | ||
17 | } | ||
18 | |||
19 | public function testUnknownCategoryExport() | ||
20 | { | ||
21 | $this->logInAs('admin'); | ||
22 | $client = $this->getClient(); | ||
23 | |||
24 | $client->request('GET', '/export/awesomeness.epub'); | ||
25 | |||
26 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | ||
27 | } | ||
28 | |||
29 | public function testUnknownFormatExport() | ||
30 | { | ||
31 | $this->logInAs('admin'); | ||
32 | $client = $this->getClient(); | ||
33 | |||
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.doc'); | ||
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().'.doc'); | ||
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'); | ||
62 | |||
63 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | ||
64 | } | ||
65 | |||
66 | public function testEpubExport() | ||
67 | { | ||
68 | $this->logInAs('admin'); | ||
69 | $client = $this->getClient(); | ||
70 | |||
71 | ob_start(); | ||
72 | $crawler = $client->request('GET', '/export/archive.epub'); | ||
73 | ob_end_clean(); | ||
74 | |||
75 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
76 | |||
77 | $headers = $client->getResponse()->headers; | ||
78 | $this->assertEquals('application/epub+zip', $headers->get('content-type')); | ||
79 | $this->assertEquals('attachment; filename="Archive articles.epub"', $headers->get('content-disposition')); | ||
80 | $this->assertEquals('binary', $headers->get('content-transfer-encoding')); | ||
81 | } | ||
82 | |||
83 | public function testMobiExport() | ||
84 | { | ||
85 | $this->logInAs('admin'); | ||
86 | $client = $this->getClient(); | ||
87 | |||
88 | $content = $client->getContainer() | ||
89 | ->get('doctrine.orm.entity_manager') | ||
90 | ->getRepository('WallabagCoreBundle:Entry') | ||
91 | ->findOneByUsernameAndNotArchived('admin'); | ||
92 | |||
93 | ob_start(); | ||
94 | $crawler = $client->request('GET', '/export/'.$content->getId().'.mobi'); | ||
95 | ob_end_clean(); | ||
96 | |||
97 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
98 | |||
99 | $headers = $client->getResponse()->headers; | ||
100 | $this->assertEquals('application/x-mobipocket-ebook', $headers->get('content-type')); | ||
101 | $this->assertEquals('attachment; filename="'.preg_replace('/[^A-Za-z0-9\-]/', '', $content->getTitle()).'.mobi"', $headers->get('content-disposition')); | ||
102 | $this->assertEquals('binary', $headers->get('content-transfer-encoding')); | ||
103 | } | ||
104 | |||
105 | public function testPdfExport() | ||
106 | { | ||
107 | $this->logInAs('admin'); | ||
108 | $client = $this->getClient(); | ||
109 | |||
110 | ob_start(); | ||
111 | $crawler = $client->request('GET', '/export/all.pdf'); | ||
112 | ob_end_clean(); | ||
113 | |||
114 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
115 | |||
116 | $headers = $client->getResponse()->headers; | ||
117 | $this->assertEquals('application/pdf', $headers->get('content-type')); | ||
118 | $this->assertEquals('attachment; filename="All articles.pdf"', $headers->get('content-disposition')); | ||
119 | $this->assertEquals('binary', $headers->get('content-transfer-encoding')); | ||
120 | } | ||
121 | |||
122 | public function testTxtExport() | ||
123 | { | ||
124 | $this->logInAs('admin'); | ||
125 | $client = $this->getClient(); | ||
126 | |||
127 | ob_start(); | ||
128 | $crawler = $client->request('GET', '/export/all.txt'); | ||
129 | ob_end_clean(); | ||
130 | |||
131 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
132 | |||
133 | $headers = $client->getResponse()->headers; | ||
134 | $this->assertEquals('text/plain; charset=UTF-8', $headers->get('content-type')); | ||
135 | $this->assertEquals('attachment; filename="All articles.txt"', $headers->get('content-disposition')); | ||
136 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); | ||
137 | } | ||
138 | |||
139 | public function testCsvExport() | ||
140 | { | ||
141 | $this->logInAs('admin'); | ||
142 | $client = $this->getClient(); | ||
143 | |||
144 | // to be sure results are the same | ||
145 | $contentInDB = $client->getContainer() | ||
146 | ->get('doctrine.orm.entity_manager') | ||
147 | ->getRepository('WallabagCoreBundle:Entry') | ||
148 | ->createQueryBuilder('e') | ||
149 | ->leftJoin('e.user', 'u') | ||
150 | ->where('u.username = :username')->setParameter('username', 'admin') | ||
151 | ->andWhere('e.isArchived = true') | ||
152 | ->getQuery() | ||
153 | ->getArrayResult(); | ||
154 | |||
155 | ob_start(); | ||
156 | $crawler = $client->request('GET', '/export/archive.csv'); | ||
157 | ob_end_clean(); | ||
158 | |||
159 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
160 | |||
161 | $headers = $client->getResponse()->headers; | ||
162 | $this->assertEquals('application/csv', $headers->get('content-type')); | ||
163 | $this->assertEquals('attachment; filename="Archive articles.csv"', $headers->get('content-disposition')); | ||
164 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); | ||
165 | |||
166 | $csv = str_getcsv($client->getResponse()->getContent(), "\n"); | ||
167 | |||
168 | $this->assertGreaterThan(1, $csv); | ||
169 | // +1 for title line | ||
170 | $this->assertEquals(count($contentInDB) + 1, count($csv)); | ||
171 | $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language', $csv[0]); | ||
172 | } | ||
173 | |||
174 | public function testJsonExport() | ||
175 | { | ||
176 | $this->logInAs('admin'); | ||
177 | $client = $this->getClient(); | ||
178 | |||
179 | // to be sure results are the same | ||
180 | $contentInDB = $client->getContainer() | ||
181 | ->get('doctrine.orm.entity_manager') | ||
182 | ->getRepository('WallabagCoreBundle:Entry') | ||
183 | ->createQueryBuilder('e') | ||
184 | ->leftJoin('e.user', 'u') | ||
185 | ->where('u.username = :username')->setParameter('username', 'admin') | ||
186 | ->getQuery() | ||
187 | ->getArrayResult(); | ||
188 | |||
189 | ob_start(); | ||
190 | $crawler = $client->request('GET', '/export/all.json'); | ||
191 | ob_end_clean(); | ||
192 | |||
193 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
194 | |||
195 | $headers = $client->getResponse()->headers; | ||
196 | $this->assertEquals('application/json', $headers->get('content-type')); | ||
197 | $this->assertEquals('attachment; filename="All articles.json"', $headers->get('content-disposition')); | ||
198 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); | ||
199 | |||
200 | $content = json_decode($client->getResponse()->getContent(), true); | ||
201 | $this->assertEquals(count($contentInDB), count($content)); | ||
202 | $this->assertArrayHasKey('id', $content[0]); | ||
203 | $this->assertArrayHasKey('title', $content[0]); | ||
204 | $this->assertArrayHasKey('url', $content[0]); | ||
205 | $this->assertArrayHasKey('is_archived', $content[0]); | ||
206 | $this->assertArrayHasKey('is_starred', $content[0]); | ||
207 | $this->assertArrayHasKey('content', $content[0]); | ||
208 | $this->assertArrayHasKey('mimetype', $content[0]); | ||
209 | $this->assertArrayHasKey('language', $content[0]); | ||
210 | $this->assertArrayHasKey('reading_time', $content[0]); | ||
211 | $this->assertArrayHasKey('domain_name', $content[0]); | ||
212 | $this->assertArrayHasKey('tags', $content[0]); | ||
213 | } | ||
214 | |||
215 | public function testXmlExport() | ||
216 | { | ||
217 | $this->logInAs('admin'); | ||
218 | $client = $this->getClient(); | ||
219 | |||
220 | // to be sure results are the same | ||
221 | $contentInDB = $client->getContainer() | ||
222 | ->get('doctrine.orm.entity_manager') | ||
223 | ->getRepository('WallabagCoreBundle:Entry') | ||
224 | ->createQueryBuilder('e') | ||
225 | ->leftJoin('e.user', 'u') | ||
226 | ->where('u.username = :username')->setParameter('username', 'admin') | ||
227 | ->andWhere('e.isArchived = false') | ||
228 | ->getQuery() | ||
229 | ->getArrayResult(); | ||
230 | |||
231 | ob_start(); | ||
232 | $crawler = $client->request('GET', '/export/unread.xml'); | ||
233 | ob_end_clean(); | ||
234 | |||
235 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
236 | |||
237 | $headers = $client->getResponse()->headers; | ||
238 | $this->assertEquals('application/xml', $headers->get('content-type')); | ||
239 | $this->assertEquals('attachment; filename="Unread articles.xml"', $headers->get('content-disposition')); | ||
240 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); | ||
241 | |||
242 | $content = new \SimpleXMLElement($client->getResponse()->getContent()); | ||
243 | $this->assertGreaterThan(0, $content->count()); | ||
244 | $this->assertEquals(count($contentInDB), $content->count()); | ||
245 | $this->assertNotEmpty('id', (string) $content->entry[0]->id); | ||
246 | $this->assertNotEmpty('title', (string) $content->entry[0]->title); | ||
247 | $this->assertNotEmpty('url', (string) $content->entry[0]->url); | ||
248 | $this->assertNotEmpty('content', (string) $content->entry[0]->content); | ||
249 | $this->assertNotEmpty('domain_name', (string) $content->entry[0]->domain_name); | ||
250 | } | ||
251 | } | ||