]> BookStack Code Mirror - bookstack/blob - tests/Exports/TextExportTest.php
Lexical: Added about button/view
[bookstack] / tests / Exports / TextExportTest.php
1 <?php
2
3 namespace Tests\Exports;
4
5 use Tests\TestCase;
6
7 class TextExportTest extends TestCase
8 {
9     public function test_page_text_export()
10     {
11         $page = $this->entities->page();
12         $this->asEditor();
13
14         $resp = $this->get($page->getUrl('/export/plaintext'));
15         $resp->assertStatus(200);
16         $resp->assertSee($page->name);
17         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $page->slug . '.txt"');
18     }
19
20     public function test_book_text_export()
21     {
22         $book = $this->entities->bookHasChaptersAndPages();
23         $directPage = $book->directPages()->first();
24         $chapter = $book->chapters()->first();
25         $chapterPage = $chapter->pages()->first();
26         $this->entities->updatePage($directPage, ['html' => '<p>My awesome page</p>']);
27         $this->entities->updatePage($chapterPage, ['html' => '<p>My little nested page</p>']);
28         $this->asEditor();
29
30         $resp = $this->get($book->getUrl('/export/plaintext'));
31         $resp->assertStatus(200);
32         $resp->assertSee($book->name);
33         $resp->assertSee($chapterPage->name);
34         $resp->assertSee($chapter->name);
35         $resp->assertSee($directPage->name);
36         $resp->assertSee('My awesome page');
37         $resp->assertSee('My little nested page');
38         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $book->slug . '.txt"');
39     }
40
41     public function test_book_text_export_format()
42     {
43         $entities = $this->entities->createChainBelongingToUser($this->users->viewer());
44         $this->entities->updatePage($entities['page'], ['html' => '<p>My great page</p><p>Full of <strong>great</strong> stuff</p>', 'name' => 'My wonderful page!']);
45         $entities['chapter']->name = 'Export chapter';
46         $entities['chapter']->description = "A test chapter to be exported\nIt has loads of info within";
47         $entities['book']->name = 'Export Book';
48         $entities['book']->description = "This is a book with stuff to export";
49         $entities['chapter']->save();
50         $entities['book']->save();
51
52         $resp = $this->asEditor()->get($entities['book']->getUrl('/export/plaintext'));
53
54         $expected = "Export Book\nThis is a book with stuff to export\n\nExport chapter\nA test chapter to be exported\nIt has loads of info within\n\n";
55         $expected .= "My wonderful page!\nMy great page Full of great stuff";
56         $resp->assertSee($expected);
57     }
58
59     public function test_chapter_text_export()
60     {
61         $chapter = $this->entities->chapter();
62         $page = $chapter->pages[0];
63         $this->entities->updatePage($page, ['html' => '<p>This is content within the page!</p>']);
64         $this->asEditor();
65
66         $resp = $this->get($chapter->getUrl('/export/plaintext'));
67         $resp->assertStatus(200);
68         $resp->assertSee($chapter->name);
69         $resp->assertSee($page->name);
70         $resp->assertSee('This is content within the page!');
71         $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $chapter->slug . '.txt"');
72     }
73
74     public function test_chapter_text_export_format()
75     {
76         $entities = $this->entities->createChainBelongingToUser($this->users->viewer());
77         $this->entities->updatePage($entities['page'], ['html' => '<p>My great page</p><p>Full of <strong>great</strong> stuff</p>', 'name' => 'My wonderful page!']);
78         $entities['chapter']->name = 'Export chapter';
79         $entities['chapter']->description = "A test chapter to be exported\nIt has loads of info within";
80         $entities['chapter']->save();
81
82         $resp = $this->asEditor()->get($entities['book']->getUrl('/export/plaintext'));
83
84         $expected = "Export chapter\nA test chapter to be exported\nIt has loads of info within\n\n";
85         $expected .= "My wonderful page!\nMy great page Full of great stuff";
86         $resp->assertSee($expected);
87     }
88 }