X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/04d21c8a97da9463e6bedda620ecf1282722ea3e..refs/pull/5721/head:/tests/Unit/PageIncludeParserTest.php diff --git a/tests/Unit/PageIncludeParserTest.php b/tests/Unit/PageIncludeParserTest.php index de31504ff..83fded436 100644 --- a/tests/Unit/PageIncludeParserTest.php +++ b/tests/Unit/PageIncludeParserTest.php @@ -2,12 +2,15 @@ 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 { - public function test_include_simple_inline_text() + public function test_simple_inline_text() { $this->runParserTest( '
{{@45#content}}
', @@ -16,7 +19,7 @@ class PageIncludeParserTest extends TestCase ); } - public function test_include_simple_inline_text_with_existing_siblings() + public function test_simple_inline_text_with_existing_siblings() { $this->runParserTest( '{{@45#content}} Hithere!
', @@ -25,7 +28,7 @@ class PageIncludeParserTest extends TestCase ); } - public function test_include_simple_inline_text_within_other_text() + public function test_simple_inline_text_within_other_text() { $this->runParserTest( 'Hello {{@45#content}}there!
', @@ -34,13 +37,204 @@ class PageIncludeParserTest extends TestCase ); } - protected function runParserTest(string $html, array $contentById, string $expected) + public function test_complex_inline_text_within_other_text() { - $parser = new PageIncludeParser($html, function (int $id) use ($contentById) { - return $contentById[strval($id)] ?? null; + $this->runParserTest( + 'Hello {{@45#content}}there!
', + ['45' => 'Testing withsomeextratags
'], + 'Hello Testing withsomeextratagsthere!
', + ); + } + + public function test_block_content_types() + { + $inputs = [ + 'Text |
Code', + ]; + + foreach ($inputs as $input) { + $this->runParserTest( + '
A{{@45#content}}B
', + ['45' => $input], + 'A
' . $input . 'B
', + ); + } + } + + public function test_block_content_nested_origin_gets_placed_before() + { + $this->runParserTest( + 'A {{@45#content}} there!
', + ['45' => 'Testing'], + '
Testing
A there!
', + ); + } + + public function test_block_content_nested_origin_gets_placed_after() + { + $this->runParserTest( + 'Some really good {{@45#content}} there!
', + ['45' => 'Testing'], + '
Some really good there!
Testing', + ); + } + + public function test_block_content_in_shallow_origin_gets_split() + { + $this->runParserTest( + '
Some really good {{@45#content}} there!
', + ['45' => 'doggos'], + '
Some really good
doggos
there!
', + ); + } + + public function test_block_content_in_shallow_origin_split_does_not_duplicate_id() + { + $this->runParserTest( + 'Some really good {{@45#content}} there!
', + ['45' => 'doggos'], + '
Some really good
doggos
there!
', + ); + } + + public function test_block_content_in_shallow_origin_does_not_leave_empty_nodes() + { + $this->runParserTest( + '{{@45#content}}
', + ['45' => 'doggos'], + '
doggos', + ); + } + + public function test_block_content_in_allowable_parent_element() + { + $this->runParserTest( + '
doggos'], + '
doggos
{{@45#content}}
doggos'], + '
doggos
Cute {{@45#content}} over there!
doggos'], + '
Cute
doggos
over there!
Cute {{@45#content}} over there!
doggos'], + '
doggos
Cute over there!
{{@45#content}}
doggos'], + '
doggos
{{@45}}
', + ['45' => 'Testing
'], + 'Testing
', + ); + } + + public function test_multi_source_elem_whole_document() + { + $this->runParserTest( + '{{@45}}
', + ['45' => 'Testing
This'], + '
Testing
This', + ); + } + + public function test_multi_source_elem_whole_document_with_shared_content_origin() + { + $this->runParserTest( + '
This is {{@45}} some text
', + ['45' => 'Testing
This'], + '
This is
Testing
This
some text
', + ); + } + + 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( + '
This {{@45#content}}{{@45#content}} content is {{@45#content}}
', + ['45' => 'inline
'], + 'This inlineinline content is inline
', + ); + } + + public function test_multiple_tags_in_same_origin_with_block_content() + { + $this->runParserTest( + 'This {{@45#content}}{{@45#content}} content is {{@45#content}}
', + ['45' => 'block'], + '
This
block
block
content is
block', + ); + } + + public function test_multiple_tags_in_differing_origin_levels_with_block_content() + { + $this->runParserTest( + '
This {{@45#content}} content is {{@45#content}}
{{@45#content}}block'], + '
block
This content is
block
block
{{@45}}C{{@45}}
A
B
'], + 'A
B
C
A
B
A
B
A
B