]> BookStack Code Mirror - bookstack/blobdiff - tests/Unit/PageIncludeParserTest.php
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / tests / Unit / PageIncludeParserTest.php
index c4c12762604c7ded62fbc9fb8919078f1f42b19f..83fded4367d606b6c9d72d2f76a81b39b59ad5bb 100644 (file)
@@ -2,7 +2,9 @@
 
 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;
 
@@ -179,6 +181,15 @@ class PageIncludeParserTest extends TestCase
         );
     }
 
+    public function test_multi_source_elem_whole_document_with_nested_content_origin()
+    {
+        $this->runParserTest(
+            '<p><strong>{{@45}}</strong></p>',
+            ['45' => '<p>Testing</p><blockquote>This</blockquote>'],
+            '<p>Testing</p><blockquote>This</blockquote>',
+        );
+    }
+
     public function test_multiple_tags_in_same_origin_with_inline_content()
     {
         $this->runParserTest(
@@ -202,7 +213,7 @@ class PageIncludeParserTest extends TestCase
         $this->runParserTest(
             '<div><p>This <strong>{{@45#content}}</strong> content is {{@45#content}}</p>{{@45#content}}</div>',
             ['45' => '<pre id="content">block</pre>'],
-            '<div><pre id="content">block</pre><p>This <strong></strong> content is </p><pre id="content">block</pre><pre id="content">block</pre></div>',
+            '<div><pre id="content">block</pre><p>This  content is </p><pre id="content">block</pre><pre id="content">block</pre></div>',
         );
     }
 
@@ -218,8 +229,9 @@ class PageIncludeParserTest extends TestCase
     protected function runParserTest(string $html, array $contentById, string $expected): void
     {
         $doc = new HtmlDocument($html);
-        $parser = new PageIncludeParser($doc, function (int $id) use ($contentById) {
-            return $contentById[strval($id)] ?? '';
+        $parser = new PageIncludeParser($doc, function (PageIncludeTag $tag) use ($contentById): PageIncludeContent {
+            $html = $contentById[strval($tag->getPageId())] ?? '';
+            return PageIncludeContent::fromHtmlAndTag($html, $tag);
         });
 
         $parser->parse();