]> BookStack Code Mirror - bookstack/blob - tests/Unit/PageIncludeParserTest.php
Includes: Started foundations for new include tag parser
[bookstack] / tests / Unit / PageIncludeParserTest.php
1 <?php
2
3 namespace Tests\Unit;
4
5 use BookStack\Entities\Tools\PageIncludeParser;
6 use Tests\TestCase;
7
8 class PageIncludeParserTest extends TestCase
9 {
10     public function test_include_simple_inline_text()
11     {
12         $this->runParserTest(
13             '<p>{{@45#content}}</p>',
14             ['45' => '<p id="content">Testing</p>'],
15             '<p>Testing</p>',
16         );
17     }
18
19     public function test_include_simple_inline_text_with_existing_siblings()
20     {
21         $this->runParserTest(
22             '<p>{{@45#content}} <strong>Hi</strong>there!</p>',
23             ['45' => '<p id="content">Testing</p>'],
24             '<p>Testing <strong>Hi</strong>there!</p>',
25         );
26     }
27
28     public function test_include_simple_inline_text_within_other_text()
29     {
30         $this->runParserTest(
31             '<p>Hello {{@45#content}}there!</p>',
32             ['45' => '<p id="content">Testing</p>'],
33             '<p>Hello Testingthere!</p>',
34         );
35     }
36
37     protected function runParserTest(string $html, array $contentById, string $expected)
38     {
39         $parser = new PageIncludeParser($html, function (int $id) use ($contentById) {
40             return $contentById[strval($id)] ?? null;
41         });
42
43         $result = $parser->parse();
44         $this->assertEquals($expected, $result);
45     }
46 }