baseurl = '/' . basename(dirname(dirname(dirname(__DIR__)))) . '/'; } public function testParse() { $tests = array( // pipe cond array( 'Link', '?>cond > 10){ ?> class="active">Link' ), // cond array( 'Link1say, hello', '?>Link1cond){ ?>say, hello' ), // cond array( 'Link1Link2', '?>Link1v==$__Context->k){ ?>Link2' ), // for loop array( '', '?>' ), // foreach loop array( '', '?>' ), // while loop array( '', '?>' ), // ~ array( 'LinkHello, world ', '?>Linkcond){ ?>Hello, world ' ), // ~ array( 'LinkHello, {$world}', '?>Linkcond){ ?>Hello, world ?>' ), // ~ ~ array( 'LinkHello, worldWow', '?>Linkcond){ ?>Hello, worldWow' ), // ~ ~ ~ array( 'LinkHello, worldHaHaWow', '?>Linkcond){ ?>Hello, worldcond2){ ?>HaHaWow' ), // ~ 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)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( 'logo', PHP_EOL . 'if($__Context->layout_info->logo_image){ ?>logo' ), // 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 . '$__loop_tmp=$__Context->_m_list_all;if($__loop_tmp)foreach($__loop_tmp 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 . '$__loop_tmp=$__Context->dummy;if($__loop_tmp)foreach($__loop_tmp as $__Context->k=>$__Context->v){ ?>
    Hello, world!
    ' ), // issue 190 array( '
    Hello, world!
    ', PHP_EOL . 'if(!($__Context->i >= $__Context->n)){;' . PHP_EOL . '$__loop_tmp=$__Context->dummy;if($__loop_tmp)foreach($__loop_tmp as $__Context->k=>$__Context->v){ ?>
    Hello, world!
    ' ), // issue 183 array( ''."\n".'
    {$vvv}
    CD
    ', '?>vvvls;if($__loop_tmp)foreach($__loop_tmp as $__Context->vvv){ ?>'."\n".'
    vvv ?>
    CD
    ' ), // issue 512 - ignores array( '
    {$lang->sl_show_topimgtext}
    ', '?>
    sl_show_topimgtext ?>
    ' ), // issue 584 array( 'mobile', PHP_EOL . 'if($__Context->oBodex->display_extra_images[\'mobile\'] && $__Context->arr_extra && $__Context->arr_extra->bodex->mobile){ ?>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( 'a!@#$%^&*()_-=[]{}?/', PHP_EOL . 'if($__Context->foo->bar > 100){ ?>a!@#$%^&*()_-=[]{}?/' ), // 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( '', PHP_EOL . 'if($__Context->mi->title){ ?>mi->use){ ?> class="tmp_class" src="' . $this->baseurl . 'tests/unit/classes/img/common/blank.gif" />' ), array( ' alt', '?> foo->bar){ ?>alt' ), array( '' . "\n" . ' alt', '?>' . PHP_EOL . ' foo->bar){ ?>alt' ), array( 'asf ', '?>asf ' ), array( '', '?>' ), array( 'asdf src="../img/img.gif" asdf src asdf src="../img/img.gif" asdf', '?>asdf src="../img/img.gif" asdf src asdf src="../img/img.gif" asdf' ), array( 'asdf src="../img/img.gif" asdf', '?>asdf src="../img/img.gif" asdf' ), array( '', '?>' ), // srcset (PR #1544) array( 'this is a test image.', '?>this is a test image.' ), // Rhymix improvements (PR #604) array( '{$_SERVER["REMOTE_ADDR"]}', '?>' ), array( '{escape($_COOKIE[$var], false)}', '?>var], false) ?>' ), array( '{$GLOBALS[$__Context->rhymix->rules]}', '?>rhymix->rules] ?>' ), array( '{$FOOBAR}', '?>FOOBAR ?>' ), array( '{RX_BASEDIR}', '?>{RX_BASEDIR}' ), array( '{\RX_BASEDIR}', '?>' ), // Rhymix improvements: object attributes enclosed in curly braces array( '
    {$foo->$bar[$bazz]}
    ', '?>
    foo->{$__Context->bar}[$__Context->bazz] ?>
    ' ), array( '
    ', "\n" . 'if($__Context->foo->{$__Context->bar}){ ?>
    ' ), array( '', "\n" . 'if($__Context->foo->{$__Context->bar}){ ?>' ), array( '
    • {$val}
    ', "\n" . '$__loop_tmp=$__Context->foo->{$__Context->bar};if($__loop_tmp)foreach($__loop_tmp as $__Context->key=>$__Context->val){ ?>foo->{$__Context->key}){ ?> class="test">
  • val ?>
  • ' ), // Rhymix autoescape array( '{$foo}', PHP_EOL . '$this->config->autoescape = true;' . "\n" . 'echo ($this->config->autoescape ? htmlspecialchars($__Context->foo, ENT_QUOTES, \'UTF-8\', false) : ($__Context->foo)) ?>' ), array( '{$foo}', PHP_EOL . '$this->config->autoescape = false;' . "\n" . 'echo ($this->config->autoescape ? htmlspecialchars($__Context->foo, ENT_QUOTES, \'UTF-8\', false) : ($__Context->foo)) ?>' ), array( '{$foo|auto}', PHP_EOL . '$this->config->autoescape = true;' . "\n" . 'echo ($this->config->autoescape ? htmlspecialchars($__Context->foo, ENT_QUOTES, \'UTF-8\', false) : ($__Context->foo)) ?>' ), array( '{$foo->$bar|auto}', PHP_EOL . '$this->config->autoescape = false;' . "\n" . 'echo ($this->config->autoescape ? htmlspecialchars($__Context->foo->{$__Context->bar}, ENT_QUOTES, \'UTF-8\', false) : ($__Context->foo->{$__Context->bar})) ?>' ), array( '{$foo|autoescape}', PHP_EOL . '$this->config->autoescape = true;' . "\n" . 'echo htmlspecialchars($__Context->foo, ENT_QUOTES, \'UTF-8\', false) ?>' ), array( '{$foo|autoescape}', PHP_EOL . '$this->config->autoescape = false;' . "\n" . 'echo htmlspecialchars($__Context->foo, ENT_QUOTES, \'UTF-8\', false) ?>' ), array( '{$foo|escape}', PHP_EOL . '$this->config->autoescape = true;' . "\n" . 'echo htmlspecialchars($__Context->foo, ENT_QUOTES, \'UTF-8\', true) ?>' ), array( '{$foo|escape}', PHP_EOL . '$this->config->autoescape = false;' . "\n" . 'echo htmlspecialchars($__Context->foo, ENT_QUOTES, \'UTF-8\', true) ?>' ), array( '{$foo|noescape}', PHP_EOL . '$this->config->autoescape = true;' . "\n" . 'echo $__Context->foo ?>' ), array( '{$foo|noescape}', PHP_EOL . '$this->config->autoescape = false;' . "\n" . 'echo $__Context->foo ?>' ), // Rhymix filters array( '

    {$foo|escape}

    ', '?>

    foo, ENT_QUOTES, \'UTF-8\', true) ?>

    ' ), array( '

    {$foo|json}

    ', '?>

    foo) ?>

    ' ), array( '

    {$foo|urlencode}

    ', '?>

    foo) ?>

    ' ), array( '

    {$foo|lower|nl2br}

    ', '?>

    foo)) ?>

    ' ), array( '

    {$foo|join:/|upper}

    ', '?>

    foo)) ?>

    ' ), array( '

    {$foo|join:\||upper}

    ', '?>

    foo)) ?>

    ' ), array( '

    {$foo|join:$separator}

    ', '?>

    separator, $__Context->foo) ?>

    ' ), array( '

    {$foo|strip}

    ', '?>

    foo) ?>

    ' ), array( '

    {$foo|strip:
    }

    ', '?>

    foo, \'
    \') ?>

    ' ), array( '

    {$foo|strip:$mytags}

    ', '?>

    foo, $__Context->mytags) ?>

    ' ), array( '

    {$foo|strip:myfunc($mytags)}

    ', '?>

    foo, myfunc($__Context->mytags)) ?>

    ' ), array( '

    {$foo|trim|date}

    ', '?>

    foo)), \'Y-m-d H:i:s\') ?>

    ' ), array( '

    {$foo|date:His}

    ', '?>

    foo), \'His\') ?>

    ' ), array( '

    {$foo|format:2}

    ', '?>

    foo, \'2\') ?>

    ' ), array( '

    {$foo->$bar|shorten}

    ', '?>

    foo->{$__Context->bar}) ?>

    ' ), array( '

    {$foo|shorten:2}

    ', '?>

    foo, \'2\') ?>

    ' ), array( '

    {$foo|date:His}

    ', '?>

    foo), \'His\') ?>

    ' ), array( '

    {$foo[$bar]|link}

    ', '?>

    foo[$__Context->bar] . \'">\' . $__Context->foo[$__Context->bar] . \'\' ?>

    ' ), array( '

    {$foo|link:http://www.rhymix.org}

    ', '?>

    \' . $__Context->foo . \'\' ?>

    ' ), array( '

    {$foo|link:$url}

    ', '?>

    url . \'">\' . $__Context->foo . \'\' ?>

    ' ), array( '

    {$foo|link:$url}

    ', PHP_EOL . '$this->config->autoescape = true; ?>

    config->autoescape ? htmlspecialchars($__Context->url, ENT_QUOTES, \'UTF-8\', false) : ($__Context->url)) . \'">\' . ($this->config->autoescape ? htmlspecialchars($__Context->foo, ENT_QUOTES, \'UTF-8\', false) : ($__Context->foo)) . \'\' ?>

    ' ), // Rhymix filters (reject malformed filters) array( '

    {$foo|dafuq}

    ', '?>

    ' ), array( '

    {$foo|4}

    ', '?>

    foo|4 ?>

    ' ), array( '

    {$foo|a+7|lower}

    ', '?>

    foo|a+7) ?>

    ' ), array( '

    {$foo|Filter}

    ', '?>

    foo|Filter ?>

    ' ), array( '

    {$foo|filter++}

    ', '?>

    foo|filter++ ?>

    ' ), array( '

    {$foo|filter:}

    ', '?>

    foo|filter: ?>

    ' ), array( '

    {$foo|$bar}

    ', '?>

    foo|$__Context->bar ?>

    ' ), array( '

    {$foo||bar}

    ', '?>

    foo||bar ?>

    ' ), array( '

    {htmlspecialchars($var, ENT_COMPAT | ENT_HTML401)}

    ', '?>

    var, ENT_COMPAT | ENT_HTML401) ?>

    ' ), array( '

    {$foo | $bar}

    ', '?>

    foo | $__Context->bar ?>

    ' ), ); 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(null); $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); } }