3 namespace Wallabag\CoreBundle\Tests\Controller
;
5 use Wallabag\CoreBundle\Tests\WallabagCoreTestCase
;
7 class ExportControllerTest
extends WallabagCoreTestCase
9 public function testLogin()
11 $client = $this->getClient();
13 $client->request('GET', '/export/unread.csv');
15 $this->assertEquals(302, $client->getResponse()->getStatusCode());
16 $this->assertContains('login', $client->getResponse()->headers
->get('location'));
19 public function testUnknownCategoryExport()
21 $this->logInAs('admin');
22 $client = $this->getClient();
24 $crawler = $client->request('GET', '/export/awesomeness.epub');
26 $this->assertEquals(404, $client->getResponse()->getStatusCode());
29 public function testUnknownFormatExport()
31 $this->logInAs('admin');
32 $client = $this->getClient();
34 $crawler = $client->request('GET', '/export/unread.xslx');
36 $this->assertEquals(404, $client->getResponse()->getStatusCode());
39 public function testEpubExport()
41 $this->logInAs('admin');
42 $client = $this->getClient();
45 $crawler = $client->request('GET', '/export/archive.epub');
48 $this->assertEquals(200, $client->getResponse()->getStatusCode());
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'));
56 public function testMobiExport()
58 $this->logInAs('admin');
59 $client = $this->getClient();
61 $content = $client->getContainer()
62 ->get('doctrine.orm.entity_manager')
63 ->getRepository('WallabagCoreBundle:Entry')
64 ->findOneByUsernameAndNotArchived('admin');
67 $crawler = $client->request('GET', '/export/'.$content->getId().'.mobi');
70 $this->assertEquals(200, $client->getResponse()->getStatusCode());
72 $headers = $client->getResponse()->headers
;
73 $this->assertEquals('application/x-mobipocket-ebook', $headers->get('content-type'));
74 $this->assertEquals('attachment; filename="'.preg_replace('/[^A-Za-z0-9\-]/', '', $content->getTitle()).'.mobi"', $headers->get('content-disposition'));
75 $this->assertEquals('binary', $headers->get('content-transfer-encoding'));
78 public function testPdfExport()
80 $this->logInAs('admin');
81 $client = $this->getClient();
84 $crawler = $client->request('GET', '/export/all.pdf');
87 $this->assertEquals(200, $client->getResponse()->getStatusCode());
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'));
95 public function testCsvExport()
97 $this->logInAs('admin');
98 $client = $this->getClient();
101 $crawler = $client->request('GET', '/export/unread.csv');
104 $this->assertEquals(200, $client->getResponse()->getStatusCode());
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'));
111 $csv = str_getcsv($client->getResponse()->getContent(), "\n");
113 $this->assertGreaterThan(1, $csv);
114 $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language', $csv[0]);
117 public function testJsonExport()
119 $this->logInAs('admin');
120 $client = $this->getClient();
123 $crawler = $client->request('GET', '/export/all.json');
126 $this->assertEquals(200, $client->getResponse()->getStatusCode());
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'));
134 public function testXmlExport()
136 $this->logInAs('admin');
137 $client = $this->getClient();
140 $crawler = $client->request('GET', '/export/unread.xml');
143 $this->assertEquals(200, $client->getResponse()->getStatusCode());
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'));