]> BookStack Code Mirror - bookstack/blob - tests/Entity/ExportTest.php
fix missing word
[bookstack] / tests / Entity / ExportTest.php
1 <?php namespace Tests;
2
3
4 use BookStack\Entities\Chapter;
5 use BookStack\Entities\Page;
6
7 class ExportTest extends TestCase
8 {
9
10     public function test_page_text_export()
11     {
12         $page = Page::first();
13         $this->asEditor();
14
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"');
19     }
20
21     public function test_page_pdf_export()
22     {
23         $page = Page::first();
24         $this->asEditor();
25
26         $resp = $this->get($page->getUrl('/export/pdf'));
27         $resp->assertStatus(200);
28         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $page->slug . '.pdf"');
29     }
30
31     public function test_page_html_export()
32     {
33         $page = Page::first();
34         $this->asEditor();
35
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"');
40     }
41
42     public function test_book_text_export()
43     {
44         $page = Page::first();
45         $book = $page->book;
46         $this->asEditor();
47
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"');
53     }
54
55     public function test_book_pdf_export()
56     {
57         $page = Page::first();
58         $book = $page->book;
59         $this->asEditor();
60
61         $resp = $this->get($book->getUrl('/export/pdf'));
62         $resp->assertStatus(200);
63         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $book->slug . '.pdf"');
64     }
65
66     public function test_book_html_export()
67     {
68         $page = Page::first();
69         $book = $page->book;
70         $this->asEditor();
71
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"');
77     }
78
79     public function test_book_html_export_shows_chapter_descriptions()
80     {
81         $chapterDesc = 'My custom test chapter description ' . str_random(12);
82         $chapter = Chapter::query()->first();
83         $chapter->description = $chapterDesc;
84         $chapter->save();
85
86         $book = $chapter->book;
87         $this->asEditor();
88
89         $resp = $this->get($book->getUrl('/export/html'));
90         $resp->assertSee($chapterDesc);
91     }
92
93     public function test_chapter_text_export()
94     {
95         $chapter = Chapter::first();
96         $page = $chapter->pages[0];
97         $this->asEditor();
98
99         $resp = $this->get($chapter->getUrl('/export/plaintext'));
100         $resp->assertStatus(200);
101         $resp->assertSee($chapter->name);
102         $resp->assertSee($page->name);
103         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $chapter->slug . '.txt"');
104     }
105
106     public function test_chapter_pdf_export()
107     {
108         $chapter = Chapter::first();
109         $this->asEditor();
110
111         $resp = $this->get($chapter->getUrl('/export/pdf'));
112         $resp->assertStatus(200);
113         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $chapter->slug . '.pdf"');
114     }
115
116     public function test_chapter_html_export()
117     {
118         $chapter = Chapter::first();
119         $page = $chapter->pages[0];
120         $this->asEditor();
121
122         $resp = $this->get($chapter->getUrl('/export/html'));
123         $resp->assertStatus(200);
124         $resp->assertSee($chapter->name);
125         $resp->assertSee($page->name);
126         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $chapter->slug . '.html"');
127     }
128
129     public function test_page_html_export_contains_custom_head_if_set()
130     {
131         $page = Page::first();
132
133         $customHeadContent = "<style>p{color: red;}</style>";
134         $this->setSettings(['app-custom-head' => $customHeadContent]);
135
136         $resp = $this->asEditor()->get($page->getUrl('/export/html'));
137         $resp->assertSee($customHeadContent);
138     }
139
140     public function test_page_html_export_use_absolute_dates()
141     {
142         $page = Page::first();
143
144         $resp = $this->asEditor()->get($page->getUrl('/export/html'));
145         $resp->assertSee($page->created_at->toDayDateTimeString());
146         $resp->assertDontSee($page->created_at->diffForHumans());
147         $resp->assertSee($page->updated_at->toDayDateTimeString());
148         $resp->assertDontSee($page->updated_at->diffForHumans());
149     }
150
151 }