X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/a1f89ad5899453ebe3559a35112aca5332ed8952..refs/pull/2298/head:/tests/Entity/PageContentTest.php
diff --git a/tests/Entity/PageContentTest.php b/tests/Entity/PageContentTest.php
index e812d5bfe..99547fd17 100644
--- a/tests/Entity/PageContentTest.php
+++ b/tests/Entity/PageContentTest.php
@@ -1,8 +1,8 @@
-assertStatus(302);
$page = Page::find($page->id);
- $this->assertContains($includeTag, $page->html);
+ $this->assertStringContainsString($includeTag, $page->html);
$this->assertEquals('', $page->text);
}
@@ -71,6 +71,25 @@ class PageContentTest extends TestCase
$pageResp->assertSee($content);
}
+ public function test_page_includes_rendered_on_book_export()
+ {
+ $page = Page::query()->first();
+ $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}}";
+ $page->save();
+
+ $this->asEditor();
+ $htmlContent = $this->get($page->book->getUrl('/export/html'));
+ $htmlContent->assertSee('my cat is awesome and scratchy');
+ }
+
public function test_page_content_scripts_removed_by_default()
{
$this->asEditor();
@@ -242,4 +261,97 @@ class PageContentTest extends TestCase
$updatedPage = Page::where('id', '=', $page->id)->first();
$this->assertEquals(substr_count($updatedPage->html, "bkmrk-test\""), 1);
}
+
+ public function test_anchors_referencing_non_bkmrk_ids_rewritten_after_save()
+ {
+ $this->asEditor();
+ $page = Page::first();
+
+ $content = 'test
link
';
+ $this->put($page->getUrl(), [
+ 'name' => $page->name,
+ 'html' => $content,
+ 'summary' => ''
+ ]);
+
+ $updatedPage = Page::where('id', '=', $page->id)->first();
+ $this->assertStringContainsString('id="bkmrk-test"', $updatedPage->html);
+ $this->assertStringContainsString('href="#bkmrk-test"', $updatedPage->html);
+ }
+
+ public function test_get_page_nav_sets_correct_properties()
+ {
+ $content = 'Hello
There
Donkey
';
+ $pageContent = new PageContent(new Page(['html' => $content]));
+ $navMap = $pageContent->getNavigation($content);
+
+ $this->assertCount(3, $navMap);
+ $this->assertArrayMapIncludes([
+ 'nodeName' => 'h1',
+ 'link' => '#testa',
+ 'text' => 'Hello',
+ 'level' => 1,
+ ], $navMap[0]);
+ $this->assertArrayMapIncludes([
+ 'nodeName' => 'h2',
+ 'link' => '#testb',
+ 'text' => 'There',
+ 'level' => 2,
+ ], $navMap[1]);
+ $this->assertArrayMapIncludes([
+ 'nodeName' => 'h3',
+ 'link' => '#testc',
+ 'text' => 'Donkey',
+ 'level' => 3,
+ ], $navMap[2]);
+ }
+
+ public function test_get_page_nav_does_not_show_empty_titles()
+ {
+ $content = 'Hello
';
+ $pageContent = new PageContent(new Page(['html' => $content]));
+ $navMap = $pageContent->getNavigation($content);
+
+ $this->assertCount(1, $navMap);
+ $this->assertArrayMapIncludes([
+ 'nodeName' => 'h1',
+ 'link' => '#testa',
+ 'text' => 'Hello'
+ ], $navMap[0]);
+ }
+
+ public function test_get_page_nav_shifts_headers_if_only_smaller_ones_are_used()
+ {
+ $content = 'Hello
There
Donkey
';
+ $pageContent = new PageContent(new Page(['html' => $content]));
+ $navMap = $pageContent->getNavigation($content);
+
+ $this->assertCount(3, $navMap);
+ $this->assertArrayMapIncludes([
+ 'nodeName' => 'h4',
+ 'level' => 1,
+ ], $navMap[0]);
+ $this->assertArrayMapIncludes([
+ 'nodeName' => 'h5',
+ 'level' => 2,
+ ], $navMap[1]);
+ $this->assertArrayMapIncludes([
+ 'nodeName' => 'h6',
+ 'level' => 3,
+ ], $navMap[2]);
+ }
+
+ public function test_page_text_decodes_html_entities()
+ {
+ $page = Page::query()->first();
+
+ $this->actingAs($this->getAdmin())
+ ->put($page->getUrl(''), [
+ 'name' => 'Testing',
+ 'html' => '"Hello & welcome"
',
+ ]);
+
+ $page->refresh();
+ $this->assertEquals('"Hello & welcome"', $page->text);
+ }
}