5 use BookStack\Entities\Tools\PageIncludeParser;
8 class PageIncludeParserTest extends TestCase
10 public function test_simple_inline_text()
13 '<p>{{@45#content}}</p>',
14 ['45' => '<p id="content">Testing</p>'],
19 public function test_simple_inline_text_with_existing_siblings()
22 '<p>{{@45#content}} <strong>Hi</strong>there!</p>',
23 ['45' => '<p id="content">Testing</p>'],
24 '<p>Testing <strong>Hi</strong>there!</p>',
28 public function test_simple_inline_text_within_other_text()
31 '<p>Hello {{@45#content}}there!</p>',
32 ['45' => '<p id="content">Testing</p>'],
33 '<p>Hello Testingthere!</p>',
37 public function test_block_content_types()
40 '<table id="content"><td>Text</td></table>',
41 '<ul id="content"><li>Item A</li></ul>',
42 '<ol id="content"><li>Item A</li></ol>',
43 '<pre id="content">Code</pre>',
46 foreach ($inputs as $input) {
48 '<p>A{{@45#content}}B</p>',
50 '<p>A</p>' . $input . '<p>B</p>',
55 public function test_block_content_nested_origin_gets_placed_before()
58 '<p><strong>A {{@45#content}} there!</strong></p>',
59 ['45' => '<pre id="content">Testing</pre>'],
60 '<pre id="content">Testing</pre><p><strong>A there!</strong></p>',
64 public function test_block_content_nested_origin_gets_placed_after()
67 '<p><strong>Some really good {{@45#content}} there!</strong></p>',
68 ['45' => '<pre id="content">Testing</pre>'],
69 '<p><strong>Some really good there!</strong></p><pre id="content">Testing</pre>',
73 public function test_block_content_in_shallow_origin_gets_split()
76 '<p>Some really good {{@45#content}} there!</p>',
77 ['45' => '<pre id="content">doggos</pre>'],
78 '<p>Some really good </p><pre id="content">doggos</pre><p> there!</p>',
82 public function test_block_content_in_shallow_origin_split_does_not_duplicate_id()
85 '<p id="test" title="Hi">Some really good {{@45#content}} there!</p>',
86 ['45' => '<pre id="content">doggos</pre>'],
87 '<p title="Hi">Some really good </p><pre id="content">doggos</pre><p id="test" title="Hi"> there!</p>',
91 public function test_block_content_in_shallow_origin_does_not_leave_empty_nodes()
94 '<p>{{@45#content}}</p>',
95 ['45' => '<pre id="content">doggos</pre>'],
96 '<pre id="content">doggos</pre>',
100 public function test_simple_whole_document()
102 $this->runParserTest(
104 ['45' => '<p id="content">Testing</p>'],
105 '<p id="content">Testing</p>',
109 public function test_multi_source_elem_whole_document()
111 $this->runParserTest(
113 ['45' => '<p>Testing</p><blockquote>This</blockquote>'],
114 '<p>Testing</p><blockquote>This</blockquote>',
118 public function test_multi_source_elem_whole_document_with_shared_content_origin()
120 $this->runParserTest(
121 '<p>This is {{@45}} some text</p>',
122 ['45' => '<p>Testing</p><blockquote>This</blockquote>'],
123 '<p>This is </p><p>Testing</p><blockquote>This</blockquote><p> some text</p>',
127 protected function runParserTest(string $html, array $contentById, string $expected)
129 $parser = new PageIncludeParser($html, function (int $id) use ($contentById) {
130 return $contentById[strval($id)] ?? '';
133 $result = $parser->parse();
134 $this->assertEquals($expected, $result);