aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Tests
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-10-16 10:51:53 +0200
committerNicolas LÅ“uillet <nicolas.loeuillet@smile.fr>2015-11-09 16:32:48 +0100
commitadd597bad95b30dbecab3aecc8362a1ccd427976 (patch)
tree1e4976f41fb043bea41c4db4544b42458eee3500 /src/Wallabag/CoreBundle/Tests
parent03690d138792dde6405e3d2eb3c53f6572eb3c43 (diff)
downloadwallabag-add597bad95b30dbecab3aecc8362a1ccd427976.tar.gz
wallabag-add597bad95b30dbecab3aecc8362a1ccd427976.tar.zst
wallabag-add597bad95b30dbecab3aecc8362a1ccd427976.zip
Rework on export
- all export now return a `HttpFoundation\Response` - return a 404 on unsupported format - add tests
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests')
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php
new file mode 100644
index 00000000..19d5f01d
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php
@@ -0,0 +1,116 @@
1<?php
2
3namespace Wallabag\CoreBundle\Tests\Controller;
4
5use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
6
7class 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 $crawler = $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 $crawler = $client->request('GET', '/export/unread.xslx');
35
36 $this->assertEquals(404, $client->getResponse()->getStatusCode());
37 }
38
39 public function testEpubExport()
40 {
41 $this->logInAs('admin');
42 $client = $this->getClient();
43
44 ob_start();
45 $crawler = $client->request('GET', '/export/archive.epub');
46 ob_end_clean();
47
48 $this->assertEquals(200, $client->getResponse()->getStatusCode());
49
50 $headers = $client->getResponse()->headers;
51 $this->assertEquals('application/epub+zip', $headers->get('content-type'));
52 $this->assertEquals('attachment; filename="Archive articles.epub"', $headers->get('content-disposition'));
53 $this->assertEquals('binary', $headers->get('content-transfer-encoding'));
54 }
55
56 public function testMobiExport()
57 {
58 $this->logInAs('admin');
59 $client = $this->getClient();
60
61 $content = $client->getContainer()
62 ->get('doctrine.orm.entity_manager')
63 ->getRepository('WallabagCoreBundle:Entry')
64 ->findOneByUsernameAndNotArchived('admin');
65
66 ob_start();
67 $crawler = $client->request('GET', '/export/'.$content->getId().'.mobi');
68 ob_end_clean();
69
70 $this->assertEquals(200, $client->getResponse()->getStatusCode());
71
72 $headers = $client->getResponse()->headers;
73 $this->assertEquals('application/x-mobipocket-ebook', $headers->get('content-type'));
74 $this->assertEquals('attachment; filename="testtitleentry1.mobi"', $headers->get('content-disposition'));
75 $this->assertEquals('binary', $headers->get('content-transfer-encoding'));
76 }
77
78 public function testPdfExport()
79 {
80 $this->logInAs('admin');
81 $client = $this->getClient();
82
83 ob_start();
84 $crawler = $client->request('GET', '/export/all.pdf');
85 ob_end_clean();
86
87 $this->assertEquals(200, $client->getResponse()->getStatusCode());
88
89 $headers = $client->getResponse()->headers;
90 $this->assertEquals('application/pdf', $headers->get('content-type'));
91 $this->assertEquals('attachment; filename="All articles.pdf"', $headers->get('content-disposition'));
92 $this->assertEquals('binary', $headers->get('content-transfer-encoding'));
93 }
94
95 public function testCsvExport()
96 {
97 $this->logInAs('admin');
98 $client = $this->getClient();
99
100 ob_start();
101 $crawler = $client->request('GET', '/export/unread.csv');
102 ob_end_clean();
103
104 $this->assertEquals(200, $client->getResponse()->getStatusCode());
105
106 $headers = $client->getResponse()->headers;
107 $this->assertEquals('application/csv', $headers->get('content-type'));
108 $this->assertEquals('attachment; filename="Unread articles.csv"', $headers->get('content-disposition'));
109 $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding'));
110
111 $csv = str_getcsv($client->getResponse()->getContent(), "\n");
112
113 $this->assertGreaterThan(1, $csv);
114 $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language', $csv[0]);
115 }
116}