]> BookStack Code Mirror - bookstack/blob - tests/Entity/ExportTest.php
Merge branch 'master' of git://github.com/almandin/BookStack into almandin-master
[bookstack] / tests / Entity / ExportTest.php
1 <?php namespace Tests;
2
3
4 use BookStack\Entities\Chapter;
5 use BookStack\Entities\Page;
6 use BookStack\Uploads\HttpFetcher;
7 use Illuminate\Support\Str;
8
9 class ExportTest extends TestCase
10 {
11
12     public function test_page_text_export()
13     {
14         $page = Page::first();
15         $this->asEditor();
16
17         $resp = $this->get($page->getUrl('/export/plaintext'));
18         $resp->assertStatus(200);
19         $resp->assertSee($page->name);
20         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $page->slug . '.txt"');
21     }
22
23     public function test_page_pdf_export()
24     {
25         $page = Page::first();
26         $this->asEditor();
27
28         $resp = $this->get($page->getUrl('/export/pdf'));
29         $resp->assertStatus(200);
30         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $page->slug . '.pdf"');
31     }
32
33     public function test_page_html_export()
34     {
35         $page = Page::first();
36         $this->asEditor();
37
38         $resp = $this->get($page->getUrl('/export/html'));
39         $resp->assertStatus(200);
40         $resp->assertSee($page->name);
41         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $page->slug . '.html"');
42     }
43
44     public function test_book_text_export()
45     {
46         $page = Page::first();
47         $book = $page->book;
48         $this->asEditor();
49
50         $resp = $this->get($book->getUrl('/export/plaintext'));
51         $resp->assertStatus(200);
52         $resp->assertSee($book->name);
53         $resp->assertSee($page->name);
54         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $book->slug . '.txt"');
55     }
56
57     public function test_book_pdf_export()
58     {
59         $page = Page::first();
60         $book = $page->book;
61         $this->asEditor();
62
63         $resp = $this->get($book->getUrl('/export/pdf'));
64         $resp->assertStatus(200);
65         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $book->slug . '.pdf"');
66     }
67
68     public function test_book_html_export()
69     {
70         $page = Page::first();
71         $book = $page->book;
72         $this->asEditor();
73
74         $resp = $this->get($book->getUrl('/export/html'));
75         $resp->assertStatus(200);
76         $resp->assertSee($book->name);
77         $resp->assertSee($page->name);
78         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $book->slug . '.html"');
79     }
80
81     public function test_book_html_export_shows_chapter_descriptions()
82     {
83         $chapterDesc = 'My custom test chapter description ' . Str::random(12);
84         $chapter = Chapter::query()->first();
85         $chapter->description = $chapterDesc;
86         $chapter->save();
87
88         $book = $chapter->book;
89         $this->asEditor();
90
91         $resp = $this->get($book->getUrl('/export/html'));
92         $resp->assertSee($chapterDesc);
93     }
94
95     public function test_chapter_text_export()
96     {
97         $chapter = Chapter::first();
98         $page = $chapter->pages[0];
99         $this->asEditor();
100
101         $resp = $this->get($chapter->getUrl('/export/plaintext'));
102         $resp->assertStatus(200);
103         $resp->assertSee($chapter->name);
104         $resp->assertSee($page->name);
105         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $chapter->slug . '.txt"');
106     }
107
108     public function test_chapter_pdf_export()
109     {
110         $chapter = Chapter::first();
111         $this->asEditor();
112
113         $resp = $this->get($chapter->getUrl('/export/pdf'));
114         $resp->assertStatus(200);
115         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $chapter->slug . '.pdf"');
116     }
117
118     public function test_chapter_html_export()
119     {
120         $chapter = Chapter::first();
121         $page = $chapter->pages[0];
122         $this->asEditor();
123
124         $resp = $this->get($chapter->getUrl('/export/html'));
125         $resp->assertStatus(200);
126         $resp->assertSee($chapter->name);
127         $resp->assertSee($page->name);
128         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $chapter->slug . '.html"');
129     }
130
131     public function test_page_html_export_contains_custom_head_if_set()
132     {
133         $page = Page::first();
134
135         $customHeadContent = "<style>p{color: red;}</style>";
136         $this->setSettings(['app-custom-head' => $customHeadContent]);
137
138         $resp = $this->asEditor()->get($page->getUrl('/export/html'));
139         $resp->assertSee($customHeadContent);
140     }
141
142     public function test_page_html_export_use_absolute_dates()
143     {
144         $page = Page::first();
145
146         $resp = $this->asEditor()->get($page->getUrl('/export/html'));
147         $resp->assertSee($page->created_at->toDayDateTimeString());
148         $resp->assertDontSee($page->created_at->diffForHumans());
149         $resp->assertSee($page->updated_at->toDayDateTimeString());
150         $resp->assertDontSee($page->updated_at->diffForHumans());
151     }
152
153     public function test_page_export_sets_right_data_type_for_svg_embeds()
154     {
155         $page = Page::first();
156         $page->html = '<img src="http://example.com/image.svg">';
157         $page->save();
158
159         $this->asEditor();
160         $this->mockHttpFetch('<svg></svg>');
161         $resp = $this->get($page->getUrl('/export/html'));
162         $resp->assertStatus(200);
163         $resp->assertSee('<img src="data:image/svg+xml;base64');
164     }
165
166 }