4 use BookStack\Entities\Chapter;
5 use BookStack\Entities\Page;
7 class ExportTest extends TestCase
10 public function test_page_text_export()
12 $page = Page::first();
15 $resp = $this->get($page->getUrl('/export/plaintext'));
16 $resp->assertStatus(200);
17 $resp->assertSee($page->name);
18 $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $page->slug . '.txt"');
21 public function test_page_pdf_export()
23 $page = Page::first();
26 $resp = $this->get($page->getUrl('/export/pdf'));
27 $resp->assertStatus(200);
28 $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $page->slug . '.pdf"');
31 public function test_page_html_export()
33 $page = Page::first();
36 $resp = $this->get($page->getUrl('/export/html'));
37 $resp->assertStatus(200);
38 $resp->assertSee($page->name);
39 $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $page->slug . '.html"');
42 public function test_book_text_export()
44 $page = Page::first();
48 $resp = $this->get($book->getUrl('/export/plaintext'));
49 $resp->assertStatus(200);
50 $resp->assertSee($book->name);
51 $resp->assertSee($page->name);
52 $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $book->slug . '.txt"');
55 public function test_book_pdf_export()
57 $page = Page::first();
61 $resp = $this->get($book->getUrl('/export/pdf'));
62 $resp->assertStatus(200);
63 $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $book->slug . '.pdf"');
66 public function test_book_html_export()
68 $page = Page::first();
72 $resp = $this->get($book->getUrl('/export/html'));
73 $resp->assertStatus(200);
74 $resp->assertSee($book->name);
75 $resp->assertSee($page->name);
76 $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $book->slug . '.html"');
79 public function test_chapter_text_export()
81 $chapter = Chapter::first();
82 $page = $chapter->pages[0];
85 $resp = $this->get($chapter->getUrl('/export/plaintext'));
86 $resp->assertStatus(200);
87 $resp->assertSee($chapter->name);
88 $resp->assertSee($page->name);
89 $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $chapter->slug . '.txt"');
92 public function test_chapter_pdf_export()
94 $chapter = Chapter::first();
97 $resp = $this->get($chapter->getUrl('/export/pdf'));
98 $resp->assertStatus(200);
99 $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $chapter->slug . '.pdf"');
102 public function test_chapter_html_export()
104 $chapter = Chapter::first();
105 $page = $chapter->pages[0];
108 $resp = $this->get($chapter->getUrl('/export/html'));
109 $resp->assertStatus(200);
110 $resp->assertSee($chapter->name);
111 $resp->assertSee($page->name);
112 $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $chapter->slug . '.html"');
115 public function test_page_html_export_contains_custom_head_if_set()
117 $page = Page::first();
119 $customHeadContent = "<style>p{color: red;}</style>";
120 $this->setSettings(['app-custom-head' => $customHeadContent]);
122 $resp = $this->asEditor()->get($page->getUrl('/export/html'));
123 $resp->assertSee($customHeadContent);
126 public function test_page_html_export_use_absolute_dates()
128 $page = Page::first();
130 $resp = $this->asEditor()->get($page->getUrl('/export/html'));
131 $resp->assertSee($page->created_at->toDayDateTimeString());
132 $resp->assertDontSee($page->created_at->diffForHumans());
133 $resp->assertSee($page->updated_at->toDayDateTimeString());
134 $resp->assertDontSee($page->updated_at->diffForHumans());
137 public function test_html_export_media_protocol_updated()
139 $page = Page::first();
140 $page->html = '<p id="bkmrk-%C2%A0-0"> </p><p id="bkmrk-%C2%A0-1"><iframe src="//www.youtube.com/embed/LkFt_fp7FmE" width="560" height="314" allowfullscreen="allowfullscreen"></iframe></p><p id="bkmrk-"><iframe src="//player.vimeo.com/video/276396369?title=0&amp;byline=0" width="425" height="350" allowfullscreen="allowfullscreen"></iframe></p><p id="bkmrk--0"><iframe style="border: 0;" src="//maps.google.com/embed?testquery=true" width="600" height="450" frameborder="0" allowfullscreen="allowfullscreen"></iframe></p><p id="bkmrk--1"><iframe src="//www.dailymotion.com/embed/video/x2rqgfm" width="480" height="432" frameborder="0" allowfullscreen="allowfullscreen"></iframe></p><p id="bkmrk-%C2%A0-2"> </p>';
144 $resp = $this->get($page->getUrl('/export/html'));
145 $resp->assertStatus(200);
148 'https://www.youtube.com/embed/LkFt_fp7FmE',
149 'https://player.vimeo.com/video/276396369?title=0&amp;byline=0',
150 'https://maps.google.com/embed?testquery=true',
151 'https://www.dailymotion.com/embed/video/x2rqgfm',
154 foreach ($checks as $check) {
155 $resp->assertSee($check);
160 public function test_pdf_export_no_video_iframe() {
161 $page = Page::first();
162 $page->html = '<p id="bkmrk-%C2%A0-0"> </p>' .
163 '<p id="bkmrk-%C2%A0-1"><iframe src="//www.youtube.com/embed/LkFt_fp7FmE" width="560" height="314" allowfullscreen="allowfullscreen"></iframe></p>' .
164 '<p id="bkmrk-"><video src="//player.vimeo.com/video/276396369?title=0&amp;byline=0" width="425" height="350" allowfullscreen="allowfullscreen"></video></p>' .
165 '<p id="bkmrk--0"><iframe style="border: 0;" src="//maps.google.com/embed?testquery=true" width="600" height="450" frameborder="0" allowfullscreen="allowfullscreen"></iframe></p>' .
166 '<p id="bkmrk--1"><iframe src="//www.dailymotion.com/embed/video/x2rqgfm" width="480" height="432" frameborder="0" allowfullscreen="allowfullscreen"></iframe></p>' .
167 '<p id="bkmrk-%C2%A0-2"> </p>';
172 $resp = $this->get($page->getUrl('/export/pdf?isTesting=true'));
173 $resp->assertStatus(200);
180 foreach ($checks as $check) {
181 $resp->assertDontSee($check);