diff --git a/tests/classes/template/TemplateHandlerTest.php b/tests/classes/template/TemplateHandlerTest.php
new file mode 100644
index 000000000..3af37479e
--- /dev/null
+++ b/tests/classes/template/TemplateHandlerTest.php
@@ -0,0 +1,244 @@
+';
+
+ static public function provider()
+ {
+ return array(
+ // pipe cond
+ array(
+ ' 10">Link',
+ 'cond > 10){ ?> class="active">Link'
+ ),
+ // cond
+ array(
+ 'Link1say, hello',
+ 'Link1cond){ ?>say, hello'
+ ),
+ // cond
+ array(
+ 'Link1Link2',
+ 'Link1v==$__Context->k){ ?>Link2'
+ ),
+ // for loop
+ array(
+ '
',
+ 'i=0;$__Context->i<$__Context->len;$__Context->i++){ ?>- Link
'
+ ),
+ // foreach loop
+ array(
+ '',
+ 'arr&&count($__Context->arr))foreach($__Context->arr as $__Context->key=>$__Context->val){ ?>- Link
arr2&&count($__Context->arr2))foreach($__Context->arr2 as $__Context->key2=>$__Context->val2){ ?>
'
+ ),
+ // while loop
+ array(
+ '',
+ 'item=get_loop_item()){ ?>- Link
'
+ ),
+ // ~
+ 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',
+ 'i=0;$__Context->i<$__Context->len;$__Context->i++){ ?>Repeat this'
+ ),
+ // ~
+ array(
+ 'item{$key} : {$val}',
+ 'arr&&count($__Context->arr))foreach($__Context->arr as $__Context->key=>$__Context->val){ ?>itemkey ?> : val ?>'
+ ),
+ // ~
+ array(
+ '{$v->text}',
+ 'item=$__Context->list->getItem()){ ?>v->text ?>'
+ ),
+ // ~ ~ ~ ~
+ array(
+ 'ABC',
+ 'var){ ?>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/classes/template\',\'sample.html\') ?>This is another dummy
'
+ ),
+ //
+ array(
+ 'This is another dummy
',
+ 'compile(\'tests/classes\',\'sample.html\') ?>This is another dummy
'
+ ),
+ //
+ array(
+ '',
+ ''
+ ),
+ //
+ array(
+ '',
+ ''
+ ),
+ //
+ array(
+ '',
+ ''
+ ),
+ //
+ array(
+ '',
+ 'compile(); ?>'
+ ),
+ //
+ array(
+ '',
+ ''
+ ),
+ //
+ array(
+ '',
+ ''
+ ),
+ // comment
+ array(
+ '',
+ ''
+ ),
+ // self-closing tag
+ array(
+ '',
+ 'foo){ ?>'
+ ),
+ // relative path1
+ array(
+ '
',
+ '
'
+ ),
+ // relative path2
+ array(
+ '
',
+ '
'
+ ),
+ // error case
+ array(
+ '
',
+ '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}
',
+ '_m_list_all&&count($__Context->_m_list_all))foreach($__Context->_m_list_all as $__Context->key=>$__Context->val){ ?>key ?>
Loop block val ?>
'
+ ),
+ // issue 136
+ array(
+ '
bar',
+ 'var==\'foo\'){ ?>
bar'
+ ),
+ // issue 188
+ array(
+ 'Hello, world!
',
+ 'ii < $__Context->nn){ ?>dummy&&count($__Context->dummy))foreach($__Context->dummy as $__Context->k=>$__Context->v){ ?>Hello, world!
'
+ ),
+ // issue 190
+ array(
+ 'Hello, world!
',
+ 'i >= $__Context->n)){ ?>dummy&&count($__Context->dummy))foreach($__Context->dummy as $__Context->k=>$__Context->v){ ?>Hello, world!
'
+ ),
+ // issue 183
+ array(
+ '',
+ 'vvvls&&count($__Context->vvvls))foreach($__Context->vvvls as $__Context->vvv){ ?>| vvv ?> |
'."\n".'| C | D |
'
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provider
+ */
+ public function testParse($tpl, $expected)
+ {
+ $tmpl = TemplateHandler::getInstance();
+ $tmpl->init(dirname(__FILE__), 'sample.html');
+ $result = $tmpl->parse($tpl);
+
+ $this->assertEquals($result, $this->prefix.$expected);
+ }
+
+ public function testParse2()
+ {
+ $tmpl = TemplateHandler::getInstance();
+ $tmpl->init(dirname(__FILE__), 'no_file.html');
+
+ $result = $tmpl->parse();
+ $this->assertEquals($result, '');
+ }
+
+ public function testCompileDirect()
+ {
+ $tmpl = TemplateHandler::getInstance();
+ $result = $tmpl->compileDirect(dirname(__FILE__), 'sample.html');
+ $result = trim($result);
+
+ $this->assertEquals($result, $this->prefix.'has_blog){ ?>Taggon\'s blog');
+ }
+}