X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/4874dc1304ee26737884d787893743ae323e5cf2..refs/pull/5676/head:/tests/Unit/PageIncludeParserTest.php diff --git a/tests/Unit/PageIncludeParserTest.php b/tests/Unit/PageIncludeParserTest.php index ee7a64344..83fded436 100644 --- a/tests/Unit/PageIncludeParserTest.php +++ b/tests/Unit/PageIncludeParserTest.php @@ -2,7 +2,10 @@ namespace Tests\Unit; +use BookStack\Entities\Tools\PageIncludeContent; use BookStack\Entities\Tools\PageIncludeParser; +use BookStack\Entities\Tools\PageIncludeTag; +use BookStack\Util\HtmlDocument; use Tests\TestCase; class PageIncludeParserTest extends TestCase @@ -178,6 +181,15 @@ class PageIncludeParserTest extends TestCase ); } + public function test_multi_source_elem_whole_document_with_nested_content_origin() + { + $this->runParserTest( + '

{{@45}}

', + ['45' => '

Testing

This
'], + '

Testing

This
', + ); + } + public function test_multiple_tags_in_same_origin_with_inline_content() { $this->runParserTest( @@ -201,7 +213,7 @@ class PageIncludeParserTest extends TestCase $this->runParserTest( '

This {{@45#content}} content is {{@45#content}}

{{@45#content}}
', ['45' => '
block
'], - '
block

This content is

block
block
', + '
block

This content is

block
block
', ); } @@ -214,13 +226,15 @@ class PageIncludeParserTest extends TestCase ); } - protected function runParserTest(string $html, array $contentById, string $expected) + protected function runParserTest(string $html, array $contentById, string $expected): void { - $parser = new PageIncludeParser($html, function (int $id) use ($contentById) { - return $contentById[strval($id)] ?? ''; + $doc = new HtmlDocument($html); + $parser = new PageIncludeParser($doc, function (PageIncludeTag $tag) use ($contentById): PageIncludeContent { + $html = $contentById[strval($tag->getPageId())] ?? ''; + return PageIncludeContent::fromHtmlAndTag($html, $tag); }); - $result = $parser->parse(); - $this->assertEquals($expected, $result); + $parser->parse(); + $this->assertEquals($expected, $doc->getBodyInnerHtml()); } }