3 namespace Tests\Exports;
7 class TextExportTest extends TestCase
9 public function test_page_text_export()
11 $page = $this->entities->page();
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"');
20 public function test_book_text_export()
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>']);
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"');
41 public function test_book_text_export_format()
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();
52 $resp = $this->asEditor()->get($entities['book']->getUrl('/export/plaintext'));
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);
59 public function test_chapter_text_export()
61 $chapter = $this->entities->chapter();
62 $page = $chapter->pages[0];
63 $this->entities->updatePage($page, ['html' => '<p>This is content within the page!</p>']);
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"');
74 public function test_chapter_text_export_format()
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();
82 $resp = $this->asEditor()->get($entities['book']->getUrl('/export/plaintext'));
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);