|
3 | 3 | namespace Tests\Entity;
|
4 | 4 |
|
5 | 5 | use BookStack\Entities\Models\Book;
|
| 6 | +use BookStack\Entities\Models\Bookshelf; |
6 | 7 | use BookStack\Entities\Models\Chapter;
|
7 | 8 | use BookStack\Entities\Models\Page;
|
8 | 9 | use BookStack\Entities\Tools\PdfGenerator;
|
9 | 10 | use BookStack\Exceptions\PdfExportException;
|
| 11 | +use Illuminate\Database\Eloquent\Builder; |
10 | 12 | use Illuminate\Support\Facades\Storage;
|
11 | 13 | use Tests\TestCase;
|
12 | 14 |
|
@@ -566,4 +568,68 @@ public function test_html_exports_contain_body_classes_for_export_identification
|
566 | 568 | $resp = $this->asEditor()->get($page->getUrl('/export/html'));
|
567 | 569 | $this->withHtml($resp)->assertElementExists('body.export.export-format-html.export-engine-none');
|
568 | 570 | }
|
| 571 | + |
| 572 | + public function test_bookshelf_text_export() |
| 573 | + { |
| 574 | + $bookshelf = $this->entities->shelf(); |
| 575 | + $book = $bookshelf->books()->first(); |
| 576 | + $directPage = $book->directPages()->first(); |
| 577 | + $chapter = $book->chapters()->first(); |
| 578 | + |
| 579 | + $this->entities->updatePage($directPage, ['html' => '<p>My awesome page</p>']); |
| 580 | + $this->asEditor(); |
| 581 | + |
| 582 | + $resp = $this->get($bookshelf->getUrl('/export/plaintext')); |
| 583 | + $resp->assertStatus(200); |
| 584 | + $resp->assertSee($bookshelf->name); |
| 585 | + $resp->assertSee($book->name); |
| 586 | + $resp->assertSee($chapter->name); |
| 587 | + $resp->assertSee($directPage->name); |
| 588 | + $resp->assertSee('My awesome page'); |
| 589 | + $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $bookshelf->slug . '.txt"'); |
| 590 | + } |
| 591 | + |
| 592 | + public function test_bookshelf_pdf_export() |
| 593 | + { |
| 594 | + $bookshelf = $this->entities->shelf(); |
| 595 | + $this->asEditor(); |
| 596 | + |
| 597 | + $resp = $this->get($bookshelf->getUrl('/export/pdf')); |
| 598 | + $resp->assertStatus(200); |
| 599 | + $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $bookshelf->slug . '.pdf"'); |
| 600 | + } |
| 601 | + |
| 602 | + public function test_bookshelf_html_export() |
| 603 | + { |
| 604 | + $bookshelf = $this->entities->shelf(); |
| 605 | + $book = $bookshelf->books()->first(); |
| 606 | + |
| 607 | + $this->asEditor(); |
| 608 | + |
| 609 | + $resp = $this->get($bookshelf->getUrl('/export/html')); |
| 610 | + $resp->assertStatus(200); |
| 611 | + $resp->assertSee($bookshelf->name); |
| 612 | + $resp->assertSee($book->name); |
| 613 | + $resp->assertSee($bookshelf->description); |
| 614 | + $resp->assertSee($book->description); |
| 615 | + $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $bookshelf->slug . '.html"'); |
| 616 | + } |
| 617 | + |
| 618 | + public function test_bookshelf_markdown_export() |
| 619 | + { |
| 620 | + $bookshelf = Bookshelf::query()->whereHas('books', function (Builder $query) { |
| 621 | + $query->Has('chapters')->Has('pages'); |
| 622 | + }) |
| 623 | + ->with(['books.chapters', 'books.pages']) |
| 624 | + ->first(); |
| 625 | + $book = $bookshelf->books()->first(); |
| 626 | + $chapter = $book->chapters()->first(); |
| 627 | + $directPage = $book->directPages()->first(); |
| 628 | + $resp = $this->asEditor()->get($bookshelf->getUrl('/export/markdown')); |
| 629 | + |
| 630 | + $resp->assertSee('# ' . $bookshelf->name); |
| 631 | + $resp->assertSee('# ' . $book->name); |
| 632 | + $resp->assertSee('# ' . $chapter->name); |
| 633 | + $resp->assertSee('# ' . $directPage->name); |
| 634 | + } |
569 | 635 | }
|
0 commit comments