From 7929770dcd22e288e0dbd37ed03b7475d09f6bc0 Mon Sep 17 00:00:00 2001 From: taggon Date: Thu, 22 Sep 2011 10:35:40 +0000 Subject: [PATCH] Add tests for TemplateHandler git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9277 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- .../template/TemplateHandlerTest.class.php | 35 +++++++++++++++++-- tests/classes/template/sample.html | 2 +- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/tests/classes/template/TemplateHandlerTest.class.php b/tests/classes/template/TemplateHandlerTest.class.php index 42759109c..a50331085 100644 --- a/tests/classes/template/TemplateHandlerTest.class.php +++ b/tests/classes/template/TemplateHandlerTest.class.php @@ -2,6 +2,7 @@ define('__DEBUG__', 1); define('_XE_PATH_', realpath(dirname(__FILE__).'/../../../')); +require _XE_PATH_.'/classes/file/FileHandler.class.php'; require _XE_PATH_.'/classes/template/TemplateHandler.class.php'; $_SERVER['SCRIPT_NAME'] = '/xe/index.php'; @@ -25,8 +26,8 @@ class TemplateHandlerTest extends PHPUnit_Framework_TestCase ), // cond array( - 'Link1Link2', - 'Link1var==$__Context->key){ ?>Link2' + 'Link1Link2', + 'Link1v==$__Context->k){ ?>Link2' ), // for loop array( @@ -83,6 +84,11 @@ class TemplateHandlerTest extends PHPUnit_Framework_TestCase 'ABC', 'var){ ?>ABC' ), + // invalid block statement + array( + '', + '' + ), // {@ ...PHP_CODE...} array( '{@$list_page = $page_no}', @@ -118,6 +124,11 @@ class TemplateHandlerTest extends PHPUnit_Framework_TestCase '', '' ), + // + array( + '', + 'compile(); ?>' + ), // array( '', @@ -178,8 +189,26 @@ class TemplateHandlerTest extends PHPUnit_Framework_TestCase { $tmpl = TemplateHandler::getInstance(); $tmpl->init(dirname(__FILE__), 'sample.html'); - $result = $tmpl->parse($tpl, $expected); + $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'); + } } diff --git a/tests/classes/template/sample.html b/tests/classes/template/sample.html index 3ce557d85..949b441ba 100644 --- a/tests/classes/template/sample.html +++ b/tests/classes/template/sample.html @@ -1 +1 @@ - +Taggon's blog