Partial implementation of unit test for template parser v2

This commit is contained in:
Kijin Sung 2023-10-15 23:03:27 +09:00
parent a362f27f62
commit 9da1d56b21
4 changed files with 103 additions and 2 deletions

View file

@ -2,6 +2,7 @@
class TemplateParserV2Test extends \Codeception\TestCase\Test
{
private $prefix = '<?php if (!defined("RX_VERSION")) exit(); ?><?php $this->config->version = 2; ?>';
private $baseurl;
public function _before()
@ -9,8 +10,108 @@ class TemplateParserV2Test extends \Codeception\TestCase\Test
$this->baseurl = '/' . basename(dirname(dirname(dirname(dirname(__DIR__))))) . '/';
}
public function testParse()
public function testVersion()
{
// Extension is .html and config is explicitly declared
$source = '<config version="2" />' . "\n" . '<div>{{ RX_VERSION|noescape }}</div>';
$target = '<div><?php echo RX_VERSION; ?></div>';
$this->assertEquals($this->prefix . "\n" . $target, $this->_parse($source), false);
$source = '@version(2)' . "\n" . '<div>@php func_get_args(); @endphp</div>';
$target = '<div><?php func_get_args(); ?></div>';
$this->assertEquals($this->prefix . "\n" . $target, $this->_parse($source), false);
// Extension is .blade.php and config is not declared
$source = '<input @disabled(foo())>';
$target = '<input<?php if (foo()): ?> disabled="disabled"<?php endif; ?>>';
$this->assertEquals($this->prefix . $target, $this->_parse($source));
// Extension is .blade.php but version is incorrectly declared: will be parsed as v1
$source = '@version(1)' . "\n" . '<input @disabled(foo())>';
$target = '<input @disabled(foo())>';
$this->assertStringContainsString($target, $this->_parse($source));
}
public function testClassAliases()
{
}
public function testInclude()
{
}
public function testAssetLoading()
{
}
public function testEchoStatements()
{
}
public function testOutputFilters()
{
}
public function testPathConversion()
{
}
public function testBlockConditions()
{
}
public function testInlineConditions()
{
}
public function testMiscDirectives()
{
}
public function testComments()
{
}
public function testVerbatim()
{
}
public function testRawPhpCode()
{
}
public function testAutoEscape()
{
}
public function testCurlyBracesAndVars()
{
}
public function testCompile()
{
}
public function _parse($source, $force_v2 = true)
{
$filename = $force_v2 ? 'v2example.blade.php' : 'no_file.html';
$tmpl = new \Rhymix\Framework\Template('./tests/_data/template', $filename);
$result = $tmpl->parse($source);
return $result;
}
}