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:
46
tests/Unit/PageIncludeParserTest.php
Normal file
46
tests/Unit/PageIncludeParserTest.php
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user