X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/2c34a99248fb6f5a75018872f765e418605099e5..refs/pull/2902/head:/tests/Entity/ExportTest.php diff --git a/tests/Entity/ExportTest.php b/tests/Entity/ExportTest.php index f9ba3d90e..7031c3875 100644 --- a/tests/Entity/ExportTest.php +++ b/tests/Entity/ExportTest.php @@ -1,5 +1,8 @@ -first(); @@ -133,7 +135,7 @@ class ExportTest extends TestCase { $page = Page::query()->first(); - $customHeadContent = ""; + $customHeadContent = ''; $this->setSettings(['app-custom-head' => $customHeadContent]); $resp = $this->asEditor()->get($page->getUrl('/export/html')); @@ -144,7 +146,7 @@ class ExportTest extends TestCase { $page = Page::query()->first(); - $customHeadContent = ""; + $customHeadContent = ''; $this->setSettings(['app-custom-head' => $customHeadContent]); $resp = $this->asEditor()->get($page->getUrl('/export/html')); @@ -209,8 +211,8 @@ class ExportTest extends TestCase { $page = Page::query()->first(); $page->html = '' - .'' - .''; + . '' + . ''; $storageDisk = Storage::disk('local'); $storageDisk->makeDirectory('uploads/images/gallery'); $storageDisk->put('uploads/images/gallery/svg_test.svg', 'good'); @@ -259,4 +261,109 @@ class ExportTest extends TestCase $resp->assertDontSee('ExportWizardTheFifth'); } + public function test_page_markdown_export() + { + $page = Page::query()->first(); + + $resp = $this->asEditor()->get($page->getUrl('/export/markdown')); + $resp->assertStatus(200); + $resp->assertSee($page->name); + $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $page->slug . '.md"'); + } + + public function test_page_markdown_export_uses_existing_markdown_if_apparent() + { + $page = Page::query()->first()->forceFill([ + 'markdown' => '# A header', + 'html' => '

Dogcat

', + ]); + $page->save(); + + $resp = $this->asEditor()->get($page->getUrl('/export/markdown')); + $resp->assertSee('A header'); + $resp->assertDontSee('Dogcat'); + } + + public function test_page_markdown_export_converts_html_where_no_markdown() + { + $page = Page::query()->first()->forceFill([ + 'markdown' => '', + 'html' => '

Dogcat

Some bold text

', + ]); + $page->save(); + + $resp = $this->asEditor()->get($page->getUrl('/export/markdown')); + $resp->assertSee("# Dogcat\n\nSome **bold** text"); + } + + public function test_page_markdown_export_does_not_convert_callouts() + { + $page = Page::query()->first()->forceFill([ + 'markdown' => '', + 'html' => '

Dogcat

Some callout text

Another line

', + ]); + $page->save(); + + $resp = $this->asEditor()->get($page->getUrl('/export/markdown')); + $resp->assertSee("# Dogcat\n\n

Some callout text

\n\nAnother line"); + } + + public function test_page_markdown_export_handles_bookstacks_wysiwyg_codeblock_format() + { + $page = Page::query()->first()->forceFill([ + 'markdown' => '', + 'html' => '

Dogcat

' . "\r\n" . '
var a = \'cat\';

Another line

', + ]); + $page->save(); + + $resp = $this->asEditor()->get($page->getUrl('/export/markdown')); + $resp->assertSee("# Dogcat\n\n```JavaScript\nvar a = 'cat';\n```\n\nAnother line"); + } + + public function test_chapter_markdown_export() + { + $chapter = Chapter::query()->first(); + $page = $chapter->pages()->first(); + $resp = $this->asEditor()->get($chapter->getUrl('/export/markdown')); + + $resp->assertSee('# ' . $chapter->name); + $resp->assertSee('# ' . $page->name); + } + + public function test_book_markdown_export() + { + $book = Book::query()->whereHas('pages')->whereHas('chapters')->first(); + $chapter = $book->chapters()->first(); + $page = $chapter->pages()->first(); + $resp = $this->asEditor()->get($book->getUrl('/export/markdown')); + + $resp->assertSee('# ' . $book->name); + $resp->assertSee('# ' . $chapter->name); + $resp->assertSee('# ' . $page->name); + } + + public function test_export_option_only_visible_and_accessible_with_permission() + { + $book = Book::query()->whereHas('pages')->whereHas('chapters')->first(); + $chapter = $book->chapters()->first(); + $page = $chapter->pages()->first(); + $entities = [$book, $chapter, $page]; + $user = $this->getViewer(); + $this->actingAs($user); + + foreach ($entities as $entity) { + $resp = $this->get($entity->getUrl()); + $resp->assertSee('/export/pdf'); + } + + /** @var Role $role */ + $this->removePermissionFromUser($user, 'content-export'); + + foreach ($entities as $entity) { + $resp = $this->get($entity->getUrl()); + $resp->assertDontSee('/export/pdf'); + $resp = $this->get($entity->getUrl('/export/pdf')); + $this->assertPermissionError($resp); + } + } }