]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php
Rework on export
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tests / Controller / ExportControllerTest.php
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 $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 }