1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-06 12:02:45 +03:00

Includes: Started foundations for new include tag parser

This commit is contained in:
Dan Brown
2023-11-22 22:14:28 +00:00
parent 22a9cf1e48
commit 04d21c8a97
2 changed files with 103 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
<?php
namespace Tests\Unit;
use BookStack\Entities\Tools\PageIncludeParser;
use Tests\TestCase;
class PageIncludeParserTest extends TestCase
{
public function test_include_simple_inline_text()
{
$this->runParserTest(
'<p>{{@45#content}}</p>',
['45' => '<p id="content">Testing</p>'],
'<p>Testing</p>',
);
}
public function test_include_simple_inline_text_with_existing_siblings()
{
$this->runParserTest(
'<p>{{@45#content}} <strong>Hi</strong>there!</p>',
['45' => '<p id="content">Testing</p>'],
'<p>Testing <strong>Hi</strong>there!</p>',
);
}
public function test_include_simple_inline_text_within_other_text()
{
$this->runParserTest(
'<p>Hello {{@45#content}}there!</p>',
['45' => '<p id="content">Testing</p>'],
'<p>Hello Testingthere!</p>',
);
}
protected function runParserTest(string $html, array $contentById, string $expected)
{
$parser = new PageIncludeParser($html, function (int $id) use ($contentById) {
return $contentById[strval($id)] ?? null;
});
$result = $parser->parse();
$this->assertEquals($expected, $result);
}
}