X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/78ebcb6f38ee7a984b26cd56dff882ae9d7e9f95..refs/pull/5676/head:/tests/Entity/PageContentTest.php diff --git a/tests/Entity/PageContentTest.php b/tests/Entity/PageContentTest.php index 53107d14d..23a38b573 100644 --- a/tests/Entity/PageContentTest.php +++ b/tests/Entity/PageContentTest.php @@ -5,13 +5,10 @@ namespace Tests\Entity; use BookStack\Entities\Models\Page; use BookStack\Entities\Tools\PageContent; use Tests\TestCase; -use Tests\Uploads\UsesImages; class PageContentTest extends TestCase { - use UsesImages; - - protected $base64Jpeg = '/9j/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/yQALCAABAAEBAREA/8wABgAQEAX/2gAIAQEAAD8A0s8g/9k='; + protected string $base64Jpeg = '/9j/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/yQALCAABAAEBAREA/8wABgAQEAX/2gAIAQEAAD8A0s8g/9k='; public function test_page_includes() { @@ -60,55 +57,48 @@ class PageContentTest extends TestCase $this->assertEquals('', $page->text); } - public function test_page_includes_do_not_break_tables() + public function test_page_includes_rendered_on_book_export() { $page = $this->entities->page(); - $secondPage = $this->entities->page(); + $secondPage = Page::query() + ->where('book_id', '!=', $page->book_id) + ->first(); - $content = '
test |
my cat is awesome and scratchy
'; $secondPage->html = $content; $secondPage->save(); - $page->html = "{{@{$secondPage->id}#table}}"; + $page->html = "{{@{$secondPage->id}#bkmrk-meow}}"; $page->save(); - $pageResp = $this->asEditor()->get($page->getUrl()); - $pageResp->assertSee($content, false); + $this->asEditor(); + $htmlContent = $this->get($page->book->getUrl('/export/html')); + $htmlContent->assertSee('my cat is awesome and scratchy'); } - public function test_page_includes_do_not_break_code() + public function test_page_includes_can_be_nested_up_to_three_times() { $page = $this->entities->page(); - $secondPage = $this->entities->page(); - - $content = 'var cat = null;
';
- $secondPage->html = $content;
- $secondPage->save();
-
- $page->html = "{{@{$secondPage->id}#bkmrk-code}}";
+ $tag = "{{@{$page->id}#bkmrk-test}}";
+ $page->html = 'Hello Barry ' . $tag . '
'; $page->save(); $pageResp = $this->asEditor()->get($page->getUrl()); - $pageResp->assertSee($content, false); + $this->withHtml($pageResp)->assertElementContains('#bkmrk-test', 'Hello Barry Hello Barry Hello Barry Hello Barry ' . $tag); + $this->withHtml($pageResp)->assertElementNotContains('#bkmrk-test', 'Hello Barry Hello Barry Hello Barry Hello Barry Hello Barry ' . $tag); } - public function test_page_includes_rendered_on_book_export() + public function test_page_includes_to_nonexisting_pages_does_not_error() { $page = $this->entities->page(); - $secondPage = Page::query() - ->where('book_id', '!=', $page->book_id) - ->first(); - - $content = 'my cat is awesome and scratchy
'; - $secondPage->html = $content; - $secondPage->save(); - - $page->html = "{{@{$secondPage->id}#bkmrk-meow}}"; + $missingId = Page::query()->max('id') + 1; + $tag = "{{@{$missingId}}}"; + $page->html = 'Hello Barry ' . $tag . '
'; $page->save(); - $this->asEditor(); - $htmlContent = $this->get($page->book->getUrl('/export/html')); - $htmlContent->assertSee('my cat is awesome and scratchy'); + $pageResp = $this->asEditor()->get($page->getUrl()); + $pageResp->assertOk(); + $pageResp->assertSee('Hello Barry'); } public function test_page_content_scripts_removed_by_default() @@ -479,11 +469,25 @@ class PageContentTest extends TestCase ], $navMap[2]); } + public function test_get_page_nav_respects_non_breaking_spaces() + { + $content = '"Hello & welcome"
', @@ -591,7 +595,7 @@ class PageContentTest extends TestCase $imageFile = public_path($imagePath); $this->assertEquals(base64_decode($this->base64Jpeg), file_get_contents($imageFile)); - $this->deleteImage($imagePath); + $this->files->deleteAtRelativePath($imagePath); } public function test_base64_images_get_extracted_when_containing_whitespace() @@ -615,7 +619,7 @@ class PageContentTest extends TestCase $imageFile = public_path($imagePath); $this->assertEquals(base64_decode($base64PngWithoutWhitespace), file_get_contents($imageFile)); - $this->deleteImage($imagePath); + $this->files->deleteAtRelativePath($imagePath); } public function test_base64_images_within_html_blanked_if_not_supported_extension_for_extract() @@ -640,6 +644,35 @@ class PageContentTest extends TestCase } } + public function test_base64_images_within_html_blanked_if_no_image_create_permission() + { + $editor = $this->users->editor(); + $page = $this->entities->page(); + $this->permissions->removeUserRolePermissions($editor, ['image-create-all']); + + $this->actingAs($editor)->put($page->getUrl(), [ + 'name' => $page->name, + 'html' => 'test
test%A
test
test%A
', $page->refresh()->html); } + + public function test_page_save_with_many_headers_and_links_is_reasonable() + { + $page = $this->entities->page(); + + $content = ''; + for ($i = 0; $i < 500; $i++) { + $content .= "
Simple Test |