]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php
use JMS Serializer
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tests / Controller / ExportControllerTest.php
CommitLineData
add597ba
JB
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'));
33c36f6b 74 $this->assertEquals('attachment; filename="'.preg_replace('/[^A-Za-z0-9\-]/', '', $content->getTitle()).'.mobi"', $headers->get('content-disposition'));
add597ba
JB
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 }
b3cc1a14
TC
116
117 public function testJsonExport()
118 {
119 $this->logInAs('admin');
120 $client = $this->getClient();
121
122 ob_start();
123 $crawler = $client->request('GET', '/export/all.json');
124 ob_end_clean();
125
126 $this->assertEquals(200, $client->getResponse()->getStatusCode());
127
128 $headers = $client->getResponse()->headers;
129 $this->assertEquals('application/json', $headers->get('content-type'));
130 $this->assertEquals('attachment; filename="All articles.json"', $headers->get('content-disposition'));
131 $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding'));
132 }
133
134 public function testXmlExport()
135 {
136 $this->logInAs('admin');
137 $client = $this->getClient();
138
139 ob_start();
140 $crawler = $client->request('GET', '/export/unread.xml');
141 ob_end_clean();
142
143 $this->assertEquals(200, $client->getResponse()->getStatusCode());
144
145 $headers = $client->getResponse()->headers;
146 $this->assertEquals('application/xml', $headers->get('content-type'));
147 $this->assertEquals('attachment; filename="Unread articles.xml"', $headers->get('content-disposition'));
148 $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding'));
149 }
add597ba 150}