10">Link',
'?>cond > 10){ ?> class="active">Link '
),
// cond
array(
'Link1 say, hello ',
'?>Link1 cond){ ?>say, hello '
),
// cond
array(
'Link1 Link2 ',
'?>Link1 v==$__Context->k){ ?>Link2 '
),
// for loop
array(
'
',
'?>i=0;$__Context->i<$__Context->len;$__Context->i++){ ?>Link '
),
// foreach loop
array(
'',
'?>arr;if($tba7582b53a5d9d2bfecc5c52511ef7ee&&count($tba7582b53a5d9d2bfecc5c52511ef7ee))foreach($tba7582b53a5d9d2bfecc5c52511ef7ee as $__Context->key=>$__Context->val){ ?>Link arr2;if($tf92ab3139c8d388f9a5f63e0fdd8f516&&count($tf92ab3139c8d388f9a5f63e0fdd8f516))foreach($tf92ab3139c8d388f9a5f63e0fdd8f516 as $__Context->key2=>$__Context->val2){ ?> '
),
// while loop
array(
'',
'?>item=get_loop_item()){ ?>Link '
),
// ~
array(
'Link Hello, world ',
'?>Link cond){ ?>Hello, world '
),
// ~
array(
'Link Hello, {$world} ',
'?>Link cond){ ?>Hello, world ?> '
),
// ~ ~
array(
'Link Hello, world Wow ',
'?>Link cond){ ?>Hello, world Wow '
),
// ~ ~ ~
array(
'Link Hello, world HaHa Wow ',
'?>Link cond){ ?>Hello, world cond2){ ?>HaHa Wow '
),
// ~
array(
'Repeat this ',
PHP_EOL.'for($__Context->i=0;$__Context->i<$__Context->len;$__Context->i++){ ?>Repeat this '
),
// ~
array(
'item{$key} : {$val} ',
PHP_EOL . 'if($__Context->arr&&count($__Context->arr))foreach($__Context->arr as $__Context->key=>$__Context->val){ ?>itemkey ?> : val ?> '
),
// ~
array(
'{$v->text} ',
PHP_EOL.'while($__Context->item=$__Context->list->getItem()){ ?>v->text ?> '
),
// ~ ~ ~ ~
array(
' A BC ',
'?> var){;'.PHP_EOL.'case "A": ?> ABC '
),
// invalid block statement
array(
' ',
'?> '
),
// {@ ...PHP_CODE...}
array(
' {@$list_page = $page_no} ',
'?> list_page = $__Context->page_no ?> '
),
// %load_js_plugin
array(
' ',
'?> '
),
// #include
array(
'This is another dummy
',
'?> compile(\'tests/unit/classes/template\',\'sample.html\') ?>This is another dummy
'
),
//
array(
'This is another dummy
',
'?> compile(\'tests/unit/classes\',\'sample.html\') ?>This is another dummy
'
),
//
array(
' ',
'?> '
),
//
array(
' ',
'?> '
),
//
array(
' ',
'?> '
),
//
array(
' ',
'?> compile(); ?> '
),
//
array(
' ',
'?> '
),
//
array(
' ',
'?> '
),
// comment
array(
' ',
'?> '
),
// self-closing tag
array(
' ',
PHP_EOL . 'if($__Context->foo){ ?> '
),
// relative path1
array(
' ',
'?> '
),
// relative path2
array(
' ',
'?> '
),
// error case
array(
' ',
PHP_EOL . 'if($__Context->layout_info->logo_image){ ?> '
),
// error case - ignore stylesheets
array(
'',
'?>'
),
// error case - ignore json
array(
'',
'?>'
),
// error case - inline javascript
array(
'',
'?>'
),
// issue 103
array(
' ',
'?>'
),
// issue 135
array(
'{$key}
Loop block {$val}
',
PHP_EOL . '$t1b443c9e474abcf95c0ff70798d10a4c=$__Context->_m_list_all;if($t1b443c9e474abcf95c0ff70798d10a4c&&count($t1b443c9e474abcf95c0ff70798d10a4c))foreach($t1b443c9e474abcf95c0ff70798d10a4c as $__Context->key=>$__Context->val){ ?>key ?>
Loop block val ?>
'
),
// issue 136
array(
' bar',
PHP_EOL . 'if($__Context->var==\'foo\'){ ?> bar'
),
// issue 188
array(
'Hello, world!
',
PHP_EOL . 'if($__Context->ii < $__Context->nn){;' . PHP_EOL . '$te536ab402425aa07f37ece1808639b07=$__Context->dummy;if($te536ab402425aa07f37ece1808639b07&&count($te536ab402425aa07f37ece1808639b07))foreach($te536ab402425aa07f37ece1808639b07 as $__Context->k=>$__Context->v){ ?>Hello, world!
'
),
// issue 190
array(
'Hello, world!
',
PHP_EOL . 'if(!($__Context->i >= $__Context->n)){;' . PHP_EOL . '$tcf235db237866cd5f280e0a7fdb2dca8=$__Context->dummy;if($tcf235db237866cd5f280e0a7fdb2dca8&&count($tcf235db237866cd5f280e0a7fdb2dca8))foreach($tcf235db237866cd5f280e0a7fdb2dca8 as $__Context->k=>$__Context->v){ ?>Hello, world!
'
),
// issue 183
array(
'',
'?>vvvls;if($t605f930a4a05d6efbed70a9059f688fe&&count($t605f930a4a05d6efbed70a9059f688fe))foreach($t605f930a4a05d6efbed70a9059f688fe as $__Context->vvv){ ?>vvv ?> '."\n".'C D
'
),
// issue 512 - ignores
array(
'{$lang->sl_show_topimgtext}
',
'?>lang->sl_show_topimgtext ?>
'
),
// issue 584
array(
' ',
PHP_EOL . 'if($__Context->oBodex->display_extra_images[\'mobile\'] && $__Context->arr_extra && $__Context->arr_extra->bodex->mobile){ ?> '
),
// issue 831
array(
"class=\"on\">",
"?> act, array(\n'dispNmsAdminGroupList',\n'dispNmsAdminInsertGroup',\n'dispNmsAdminGroupInfo',\n'dispNmsAdminDeleteGroup'))){ ?>class=\"on\">"
),
// issue 746
array(
' ',
'?> '
),
// issue 696
array(
'{@ eval(\'$val = $document_srl;\')}',
PHP_EOL . 'eval(\'$__Context->val = $__Context->document_srl;\') ?>'
),
// https://github.com/xpressengine/xe-core/issues/1510
array(
' ',
PHP_EOL . 'if($__Context->foo->bar){ ?> '
),
// https://github.com/xpressengine/xe-core/issues/1510
array(
' ',
PHP_EOL . 'if($__Context->foo->bar > 100){ ?> '
),
// https://github.com/xpressengine/xe-core/issues/1510
array(
' ',
PHP_EOL . 'if($__Context->foo->bar){ ?> '
),
// https://github.com/xpressengine/xe-core/issues/1510
array(
' ',
PHP_EOL . 'if(!$__Context->module_info->title){ ?> '
),
// https://github.com/xpressengine/xe-core/issues/1510
array(
' use" src="../img/common/blank.gif" />',
PHP_EOL . 'if($__Context->mi->title){ ?> mi->use){ ?> class="tmp_class" src="/xe/tests/unit/classes/img/common/blank.gif" />'
),
array(
' ',
'?> foo->bar){ ?> '
),
array(
' ' . "\n" . ' ',
'?> ' . PHP_EOL . ' foo->bar){ ?> '
),
array(
'asf ',
'?>asf '
),
array(
' ',
'?> '
),
array(
' asdf src="../img/img.gif" asdf asdf src="../img/img.gif" asdf',
'?> asdf src="../img/img.gif" asdf asdf src="../img/img.gif" asdf'
),
array(
' asdf src="../img/img.gif" asdf',
'?> asdf src="../img/img.gif" asdf'
),
);
foreach ($tests as $test)
{
$tmpl = new TemplateHandlerWrapper;
$tmpl->init(__DIR__ . '/template', 'no_file.html');
$result = $tmpl->parse($test[0]);
$this->assertEquals($this->prefix . $test[1], $result);
}
}
public function testParseNoContent()
{
$tmpl = new TemplateHandlerWrapper;
$tmpl->init(__DIR__ . '/template', 'no_file.html');
$result = $tmpl->parse($tpl);
$this->assertEquals('', $result);
}
public function testCompileDirect()
{
$tmpl = TemplateHandler::getInstance();
$result = $tmpl->compileDirect(__DIR__ . '/template', 'sample.html');
$result = trim($result);
$this->assertEquals($result, $this->prefix.PHP_EOL.'if($__Context->has_blog){ ?>Taggon\'s blog '.PHP_EOL.'');
}
}
class TemplateHandlerWrapper extends \TemplateHandler {
private $inst;
function __construct() {
$this->inst = parent::getInstance();
}
public function init($tpl_path, $tpl_filename, $tpl_file = '') {
call_user_func(array($this->inst, 'init'), $tpl_path, $tpl_filename, $tpl_file);
}
public function parse($buff = null) {
return call_user_func(array($this->inst, 'parse'), $buff);
}
}