Imported Upstream version 1.3.1
This commit is contained in:
36
HTML_Template_IT-1.3.1/tests/AllTests.php
Normal file
36
HTML_Template_IT-1.3.1/tests/AllTests.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
if (!defined('PHPUnit_MAIN_METHOD')) {
|
||||
define('PHPUnit_MAIN_METHOD', 'HTML_Template_IT_AllTests::main');
|
||||
}
|
||||
|
||||
require_once 'PHPUnit/TextUI/TestRunner.php';
|
||||
require_once 'PHPUnit/Framework/TestSuite.php';
|
||||
|
||||
|
||||
require_once 'ITTest.php';
|
||||
require_once 'ITXTest.php';
|
||||
|
||||
|
||||
class HTML_Template_IT_AllTests
|
||||
{
|
||||
public static function main()
|
||||
{
|
||||
|
||||
PHPUnit_TextUI_TestRunner::run(self::suite());
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
$suite = new PHPUnit_Framework_TestSuite('HTML_Template_IT tests');
|
||||
|
||||
$suite->addTestSuite('ITTest');
|
||||
$suite->addTestSuite('ITXTest');
|
||||
|
||||
return $suite;
|
||||
}
|
||||
}
|
||||
|
||||
if (PHPUnit_MAIN_METHOD == 'HTML_Template_IT_AllTests::main') {
|
||||
HTML_Template_IT_AllTests::main();
|
||||
}
|
||||
?>
|
||||
416
HTML_Template_IT-1.3.1/tests/ITTest.php
Normal file
416
HTML_Template_IT-1.3.1/tests/ITTest.php
Normal file
@@ -0,0 +1,416 @@
|
||||
<?php
|
||||
require_once 'HTML/Template/IT.php';
|
||||
require_once 'PHPUnit/Framework/TestCase.php';
|
||||
|
||||
class ITTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* An HTML_Template_IT object
|
||||
* @var object
|
||||
*/
|
||||
var $tpl;
|
||||
|
||||
function setUp()
|
||||
{
|
||||
$this->tpl = new HTML_Template_IT(dirname(__FILE__) . '/templates');
|
||||
}
|
||||
|
||||
function tearDown()
|
||||
{
|
||||
unset($this->tpl);
|
||||
}
|
||||
|
||||
function _stripWhitespace($str)
|
||||
{
|
||||
return preg_replace('/\\s+/', '', $str);
|
||||
}
|
||||
|
||||
function _methodExists($name)
|
||||
{
|
||||
if (in_array(strtolower($name), get_class_methods($this->tpl))) {
|
||||
return true;
|
||||
}
|
||||
$this->assertTrue(false, 'method '. $name . ' not implemented in ' . get_class($this->tpl));
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a setTemplate method
|
||||
*
|
||||
*/
|
||||
function testSetTemplate()
|
||||
{
|
||||
$result = $this->tpl->setTemplate('A template', false, false);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error setting template: '. $result->getMessage());
|
||||
}
|
||||
$this->assertEquals('A template', $this->tpl->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a loadTemplatefile method
|
||||
*
|
||||
*/
|
||||
function testLoadTemplatefile()
|
||||
{
|
||||
$result = $this->tpl->loadTemplatefile('loadtemplatefile.html', false, false);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
|
||||
}
|
||||
$this->assertEquals('A template', trim($this->tpl->get()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a setVariable method
|
||||
*
|
||||
*/
|
||||
function testSetVariable()
|
||||
{
|
||||
$result = $this->tpl->setTemplate('{placeholder1} {placeholder2} {placeholder3}', true, true);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error setting template: '. $result->getMessage());
|
||||
}
|
||||
// "scalar" call
|
||||
$this->tpl->setVariable('placeholder1', 'var1');
|
||||
// array call
|
||||
$this->tpl->setVariable(array(
|
||||
'placeholder2' => 'var2',
|
||||
'placeholder3' => 'var3'
|
||||
));
|
||||
$this->assertEquals('var1 var2 var3', $this->tpl->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the <!-- INCLUDE --> functionality
|
||||
*
|
||||
*/
|
||||
function testInclude()
|
||||
{
|
||||
$result = $this->tpl->loadTemplateFile('include.html', false, false);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
|
||||
}
|
||||
$this->assertEquals('Master file; Included file', trim($this->tpl->get()));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function testCurrentBlock()
|
||||
{
|
||||
$result = $this->tpl->loadTemplateFile('blockiteration.html', true, true);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
|
||||
}
|
||||
$this->tpl->setVariable('outer', 'a');
|
||||
$this->tpl->setCurrentBlock('inner_block');
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$this->tpl->setVariable('inner', $i + 1);
|
||||
$this->tpl->parseCurrentBlock();
|
||||
} // for
|
||||
$this->assertEquals('a|1|2|3|4|5#', $this->_stripWhitespace($this->tpl->get()));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function testRemovePlaceholders()
|
||||
{
|
||||
$result = $this->tpl->setTemplate('{placeholder1},{placeholder2},{placeholder3}', true, true);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error setting template: '. $result->getMessage());
|
||||
}
|
||||
// we do not set {placeholder3}
|
||||
$this->tpl->setVariable(array(
|
||||
'placeholder1' => 'var1',
|
||||
'placeholder2' => 'var2'
|
||||
));
|
||||
$this->assertEquals('var1,var2,', $this->tpl->get());
|
||||
|
||||
// Now, we should really add a switch for keeping {stuff} in
|
||||
// data supplied to setVariable() safe. Until then, removing it should
|
||||
// be expected behaviour
|
||||
$result = $this->tpl->setTemplate('{placeholder1},{placeholder2},{placeholder3}', true, true);
|
||||
$this->tpl->setOption('preserve_input', false);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error setting template: '. $result->getMessage());
|
||||
}
|
||||
$this->tpl->setVariable(array(
|
||||
'placeholder1' => 'var1',
|
||||
'placeholder2' => 'var2',
|
||||
'placeholder3' => 'var3{stuff}'
|
||||
));
|
||||
$this->assertEquals('var1,var2,var3', $this->tpl->get());
|
||||
|
||||
$result = $this->tpl->setTemplate('{placeholder1},{placeholder2},{placeholder3}', true, true);
|
||||
$this->tpl->setOption('preserve_input', true);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error setting template: '. $result->getMessage());
|
||||
}
|
||||
$this->tpl->setVariable(array(
|
||||
'placeholder1' => 'var1',
|
||||
'placeholder2' => 'var2',
|
||||
'placeholder3' => 'var3{stuff}'
|
||||
));
|
||||
$this->assertEquals('var1,var2,var3{stuff}', $this->tpl->get());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function testTouchBlock()
|
||||
{
|
||||
$result = $this->tpl->loadTemplateFile('blockiteration.html', false, true);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
|
||||
}
|
||||
$this->tpl->setVariable('outer', 'data');
|
||||
// inner_block should be preserved in output, even if empty
|
||||
$this->tpl->touchBlock('inner_block');
|
||||
$this->assertEquals('data|{inner}#', $this->_stripWhitespace($this->tpl->get()));
|
||||
}
|
||||
|
||||
// Not available in stock class
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/*
|
||||
function testHideBlock()
|
||||
{
|
||||
if (!$this->_methodExists('hideBlock')) {
|
||||
return;
|
||||
}
|
||||
$result = $this->tpl->loadTemplateFile('blockiteration.html', false, true);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
|
||||
}
|
||||
$this->tpl->setVariable(array(
|
||||
'outer' => 'data',
|
||||
'inner' => 'stuff'
|
||||
));
|
||||
// inner_block is not empty, but should be removed nonetheless
|
||||
$this->tpl->hideBlock('inner_block');
|
||||
$this->assertEquals('data#', $this->_stripWhitespace($this->tpl->get()));
|
||||
}
|
||||
*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/*
|
||||
function testSetGlobalVariable()
|
||||
{
|
||||
if (!$this->_methodExists('setGlobalVariable')) {
|
||||
return;
|
||||
}
|
||||
$result = $this->tpl->loadTemplateFile('globals.html', false, true);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
|
||||
}
|
||||
$this->tpl->setGlobalVariable('glob', 'glob');
|
||||
// {var2} is not, block_two should be removed
|
||||
$this->tpl->setVariable(array(
|
||||
'var1' => 'one',
|
||||
'var3' => 'three'
|
||||
));
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$this->tpl->setVariable('var4', $i + 1);
|
||||
$this->tpl->parse('block_four');
|
||||
} // for
|
||||
$this->assertEquals('glob:one#glob:three|glob:1|glob:2|glob:3#', $this->_stripWhitespace($this->tpl->get()));
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Test for bug #9501. preg_replace treat $<NUM> and \<NUM> as
|
||||
* backreferences. IT escapes them.
|
||||
*
|
||||
*/
|
||||
function testBug9501()
|
||||
{
|
||||
$this->tpl->setTemplate("Test: {VALUE}");
|
||||
$this->tpl->clearCache = true;
|
||||
|
||||
$this->tpl->setVariable("VALUE", '$12.34');
|
||||
$this->assertEquals('Test: $12.34', $this->tpl->get());
|
||||
|
||||
$this->tpl->setVariable("VALUE", '$1256.34');
|
||||
$this->assertEquals('Test: $1256.34', $this->tpl->get());
|
||||
|
||||
$this->tpl->setVariable("VALUE", '^1.34');
|
||||
$this->assertEquals('Test: ^1.34', $this->tpl->get());
|
||||
|
||||
$this->tpl->setVariable("VALUE", '$1.34');
|
||||
$this->assertEquals('Test: $1.34', $this->tpl->get());
|
||||
|
||||
$this->tpl->setVariable("VALUE", '\$12.34');
|
||||
$this->assertEquals('Test: \$12.34', $this->tpl->get());
|
||||
|
||||
$this->tpl->setVariable("VALUE", "\$12.34");
|
||||
$this->assertEquals('Test: $12.34', $this->tpl->get());
|
||||
|
||||
$this->tpl->setVariable("VALUE", "\$12.34");
|
||||
$this->assertEquals('Test: $12.34', $this->tpl->get());
|
||||
|
||||
// $12 is not parsed as a variable as it starts with a number
|
||||
$this->tpl->setVariable("VALUE", "$12.34");
|
||||
$this->assertEquals('Test: $12.34', $this->tpl->get());
|
||||
|
||||
$this->tpl->setVariable("VALUE", "\\$12.34");
|
||||
$this->assertEquals('Test: \$12.34', $this->tpl->get());
|
||||
|
||||
// taken from the bugreport
|
||||
$word = 'Cost is $456.98';
|
||||
$this->tpl->setVariable("VALUE", $word);
|
||||
$this->assertEquals('Test: Cost is $456.98', $this->tpl->get());
|
||||
|
||||
$word = "Cost is \$" . '183.22';
|
||||
$this->tpl->setVariable("VALUE", $word);
|
||||
$this->assertEquals('Test: Cost is $183.22', $this->tpl->get());
|
||||
}
|
||||
|
||||
function testBug9783 ()
|
||||
{
|
||||
$this->tpl->setTemplate("<!-- BEGIN entry -->{DATA} <!-- END entry -->", true, true);
|
||||
$data = array ('{Bakken}', 'Soria', 'Joye');
|
||||
foreach ($data as $name) {
|
||||
$this->tpl->setCurrentBlock('entry');
|
||||
$this->tpl->setVariable('DATA', $name);
|
||||
$this->tpl->parseCurrentBlock();
|
||||
}
|
||||
|
||||
$this->assertEquals('{Bakken} Soria Joye', trim($this->tpl->get()));
|
||||
|
||||
}
|
||||
|
||||
function testBug9853 ()
|
||||
{
|
||||
$this->tpl->loadTemplatefile("bug_9853_01.tpl", true, true);
|
||||
|
||||
$this->tpl->setVariable("VAR" , "Ok !");
|
||||
$this->tpl->parse("foo1");
|
||||
|
||||
$this->tpl->setVariable("VAR" , "Ok !");
|
||||
$this->tpl->parse("foo2");
|
||||
|
||||
$this->tpl->setVariable("VAR." , "Ok !");
|
||||
$this->tpl->setVariable("VAR2" , "Okay");
|
||||
$this->tpl->parse("bar");
|
||||
|
||||
$this->tpl->parse();
|
||||
$output01 = $this->tpl->get();
|
||||
|
||||
$this->tpl->loadTemplatefile("bug_9853_02.tpl", true, true);
|
||||
|
||||
$this->tpl->setVariable("VAR" , "Ok !");
|
||||
$this->tpl->parse("foo.");
|
||||
|
||||
$this->tpl->setVariable("VAR" , "Ok !");
|
||||
$this->tpl->parse("foo2");
|
||||
|
||||
$this->tpl->setVariable("VAR." , "Ok !");
|
||||
$this->tpl->setVariable("VAR2" , "Okay");
|
||||
$this->tpl->parse("bar");
|
||||
|
||||
$this->tpl->parse();
|
||||
$output02 = $this->tpl->get();
|
||||
|
||||
$this->assertEquals($output01, $output02);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests iterations over two blocks
|
||||
*
|
||||
*/
|
||||
function testBlockIteration()
|
||||
{
|
||||
$data = array(
|
||||
'a',
|
||||
array('b', array('1', '2', '3', '4')),
|
||||
'c',
|
||||
array('d', array('5', '6', '7'))
|
||||
);
|
||||
|
||||
$result = $this->tpl->loadTemplateFile('blockiteration.html', true, true);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
|
||||
}
|
||||
foreach ($data as $value) {
|
||||
if (is_array($value)) {
|
||||
$this->tpl->setVariable('outer', $value[0]);
|
||||
foreach ($value[1] as $v) {
|
||||
$this->tpl->setVariable('inner', $v);
|
||||
$this->tpl->parse('inner_block');
|
||||
}
|
||||
} else {
|
||||
$this->tpl->setVariable('outer', $value);
|
||||
}
|
||||
$this->tpl->parse('outer_block');
|
||||
}
|
||||
$this->assertEquals('a#b|1|2|3|4#c#d|5|6|7#', $this->_stripWhitespace($this->tpl->get()));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
function testTouchBlockIteration()
|
||||
{
|
||||
$data = array('a','b','c','d','e');
|
||||
$result = $this->tpl->loadTemplateFile('blockiteration.html', true, true);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
|
||||
}
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$this->tpl->setVariable('outer', $data[$i]);
|
||||
// the inner_block is empty and should be removed
|
||||
if (0 == $i % 2) {
|
||||
$this->tpl->touchBlock('inner_block');
|
||||
}
|
||||
$this->tpl->parse('outer_block');
|
||||
}
|
||||
$this->assertEquals('a|#b#c|#d#e|#', $this->_stripWhitespace($this->tpl->get()));
|
||||
}
|
||||
|
||||
public function testShouldSetOptionsCorrectly() {
|
||||
$result = $this->tpl->setOption('removeEmptyBlocks', false);
|
||||
|
||||
$this->assertFalse(PEAR::isError($result));
|
||||
|
||||
$this->assertFalse($this->tpl->removeEmptyBlocks);
|
||||
|
||||
$result = $this->tpl->setOption('removeEmptyBlocks', true);
|
||||
|
||||
$this->assertFalse(PEAR::isError($result));
|
||||
|
||||
$this->assertTrue($this->tpl->removeEmptyBlocks);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testPlaceholderReplacementScope() {
|
||||
$result = $this->tpl->loadTemplateFile('placeholderreplacementscope.html', true, true);
|
||||
|
||||
if (PEAR::isError($result)) {
|
||||
$this->fail('Error loading template file: ' . $result->getMessage());
|
||||
}
|
||||
|
||||
|
||||
$this->tpl->setCurrentBlock('foo');
|
||||
$this->tpl->setVariable('var1','test');
|
||||
$this->tpl->parseCurrentBlock();
|
||||
$this->tpl->setCurrentBlock('bar');
|
||||
$this->tpl->setVariable('var1','not');
|
||||
$this->tpl->setVariable('var2','good');
|
||||
$this->tpl->parseCurrentBlock();
|
||||
|
||||
$actual = $this->_stripWhitespace($this->tpl->get());
|
||||
$this->assertEquals('testgood', $actual);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
171
HTML_Template_IT-1.3.1/tests/ITXTest.php
Normal file
171
HTML_Template_IT-1.3.1/tests/ITXTest.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
require_once 'HTML/Template/ITX.php';
|
||||
require_once 'PHPUnit/Framework/TestCase.php';
|
||||
|
||||
require_once 'ITTest.php';
|
||||
|
||||
function _uppercaseCallback($ary)
|
||||
{
|
||||
return strtoupper($ary[0]);
|
||||
}
|
||||
|
||||
class Callbacks
|
||||
{
|
||||
static function _lowercaseCallback($ary)
|
||||
{
|
||||
return strtolower($ary[0]);
|
||||
}
|
||||
|
||||
static function _numberFormatCallback($float, $decimals)
|
||||
{
|
||||
return number_format($float, $decimals);
|
||||
}
|
||||
}
|
||||
|
||||
class ITXTest extends ITTest
|
||||
{
|
||||
function setUp()
|
||||
{
|
||||
$this->tpl = new HTML_Template_ITX(dirname(__FILE__) . '/templates');
|
||||
}
|
||||
|
||||
function testPlaceholderExists()
|
||||
{
|
||||
$this->tpl->setTemplate('{var}');
|
||||
$this->assertSame("__global__", $this->tpl->placeholderExists('var'), 'Existing placeholder \'var\' reported as nonexistant');
|
||||
$this->assertSame("", $this->tpl->placeholderExists('foobar'), 'Nonexistant placeholder \'foobar\' reported as existing');
|
||||
$this->assertSame("__global__", $this->tpl->placeholderExists('var', '__global__'), 'Existing in block \'__global__\' placeholder \'var\' reported as nonexistant');
|
||||
$this->assertSame("", $this->tpl->placeholderExists('foobar', '__global__'), 'Nonexistant in block \'__global__\' placeholder \'foobar\' reported as existing');
|
||||
}
|
||||
|
||||
function testBlockExists()
|
||||
{
|
||||
$this->tpl->setTemplate('{var}');
|
||||
$this->assertTrue($this->tpl->blockExists('__global__'), 'Existing block \'__global__\' reported as nonexistant');
|
||||
$this->assertTrue(!$this->tpl->blockExists('foobar'), 'Nonexistant block \'foobar\' reported as existing');
|
||||
}
|
||||
|
||||
function testAddBlock()
|
||||
{
|
||||
$result = $this->tpl->loadTemplatefile('blocks.html', true, true);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
|
||||
}
|
||||
$this->tpl->addBlock('var', 'added', 'added:{new_var}');
|
||||
$this->assertTrue($this->tpl->blockExists('added'), 'The new block seems to be missing');
|
||||
$this->assertTrue(!$this->tpl->placeholderExists('var'), 'The old variable seems to be still present in the template');
|
||||
$this->tpl->setVariable('new_var', 'new_value');
|
||||
$this->assertEquals('added:new_value', $this->_stripWhitespace($this->tpl->get()));
|
||||
}
|
||||
|
||||
function testAddBlockfile()
|
||||
{
|
||||
$result = $this->tpl->loadTemplatefile('blocks.html', true, true);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
|
||||
}
|
||||
$result = $this->tpl->addBlockfile('var', 'added', 'addblock.html');
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error adding block from file: '. $result->getMessage());
|
||||
}
|
||||
$this->assertTrue($this->tpl->blockExists('added'), 'The new block seems to be missing');
|
||||
$this->assertTrue(!$this->tpl->placeholderExists('var'), 'The old variable seems to be still present in the template');
|
||||
$this->tpl->setVariable('new_var', 'new_value');
|
||||
$this->assertEquals('added:new_value', $this->_stripWhitespace($this->tpl->get()));
|
||||
}
|
||||
|
||||
function testReplaceBlock()
|
||||
{
|
||||
$result = $this->tpl->loadTemplatefile('blocks.html', true, true);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
|
||||
}
|
||||
$this->tpl->setVariable('old_var', 'old_value');
|
||||
$this->tpl->parse('old_block');
|
||||
// old_block's contents should be discarded
|
||||
$this->tpl->replaceBlock('old_block', 'replaced:{replaced_var}#', false);
|
||||
$this->assertTrue(!$this->tpl->blockExists('old_inner_block') && !$this->tpl->placeholderExists('old_var'),
|
||||
'The replaced block\'s contents seem to be still present');
|
||||
$this->tpl->setVariable('replaced_var', 'replaced_value');
|
||||
$this->tpl->parse('old_block');
|
||||
// this time old_block's contents should be preserved
|
||||
$this->tpl->replaceBlock('old_block', 'replaced_again:{brand_new_var}', true);
|
||||
$this->tpl->setVariable('brand_new_var', 'brand_new_value');
|
||||
$this->assertEquals('replaced:replaced_value#replaced_again:brand_new_value', $this->_stripWhitespace($this->tpl->get()));
|
||||
}
|
||||
|
||||
function testReplaceBlockfile()
|
||||
{
|
||||
$result = $this->tpl->loadTemplatefile('blocks.html', true, true);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
|
||||
}
|
||||
$this->tpl->setVariable('old_var', 'old_value');
|
||||
$this->tpl->parse('old_block');
|
||||
// old_block's contents should be discarded
|
||||
$result = $this->tpl->replaceBlockfile('old_block', 'replaceblock.html', false);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error replacing block from file: '. $result->getMessage());
|
||||
}
|
||||
$this->assertTrue(!$this->tpl->blockExists('old_inner_block') && !$this->tpl->placeholderExists('old_var'),
|
||||
'The replaced block\'s contents seem to be still present');
|
||||
$this->tpl->setVariable(array(
|
||||
'replaced_var' => 'replaced_value',
|
||||
'replaced_inner_var' => 'inner_value'
|
||||
));
|
||||
$this->tpl->parse('old_block');
|
||||
// this time old_block's contents should be preserved
|
||||
$result = $this->tpl->replaceBlockfile('old_block', 'addblock.html', true);
|
||||
if (PEAR::isError($result)) {
|
||||
$this->assertTrue(false, 'Error replacing block from file: '. $result->getMessage());
|
||||
}
|
||||
$this->tpl->setVariable('new_var', 'again');
|
||||
$this->assertEquals('replaced:replaced_value|inner_value#added:again', $this->_stripWhitespace($this->tpl->get()));
|
||||
}
|
||||
|
||||
function testCallback()
|
||||
{
|
||||
$this->tpl->setTemplate('callback:func_uppercase(word)');
|
||||
$this->tpl->setCallbackFunction('uppercase', '_uppercaseCallback');
|
||||
$res = $this->tpl->performCallback();
|
||||
if (PEAR::isError($res)) {
|
||||
$this->assertTrue(false, 'Error performing callback: '. $res->getMessage());
|
||||
}
|
||||
$this->assertEquals('callback:WORD', $this->tpl->get());
|
||||
|
||||
$this->tpl->setTemplate('callback:func_lowercase(Word)');
|
||||
$this->tpl->setCallbackFunction('lowercase', array('Callbacks','_lowercaseCallback'));
|
||||
$res = $this->tpl->performCallback();
|
||||
if (PEAR::isError($res)) {
|
||||
$this->assertTrue(false, 'Error performing callback: '. $res->getMessage());
|
||||
}
|
||||
$this->assertEquals('callback:word', $this->tpl->get());
|
||||
|
||||
$this->tpl->setTemplate('callback:func_lowercase(Word)');
|
||||
$this->tpl->setCallbackFunction('lowercase', array(new Callbacks,'_lowercaseCallback'));
|
||||
$res = $this->tpl->performCallback();
|
||||
if (PEAR::isError($res)) {
|
||||
$this->assertTrue(false, 'Error performing callback: '. $res->getMessage());
|
||||
}
|
||||
$this->assertEquals('callback:word', $this->tpl->get());
|
||||
|
||||
$this->tpl->setTemplate('callback:func_numberFormat(1.5, 2)');
|
||||
$this->tpl->setCallbackFunction('numberFormat', array('Callbacks', '_numberFormatCallback'), '', true);
|
||||
$res = $this->tpl->performCallback();
|
||||
if (PEAR::isError($res)) {
|
||||
$this->assertTrue(false, 'Error performing callback: '. $res->getMessage());
|
||||
}
|
||||
$this->assertEquals('callback:1.50', $this->tpl->get());
|
||||
|
||||
$this->tpl->setTemplate('callback:func_numberFormat(1.5, 2)');
|
||||
$GLOBALS['obj'] = new Callbacks;
|
||||
$this->tpl->setCallbackFunction('numberFormat', '_numberFormatCallback', 'obj', true);
|
||||
$res = $this->tpl->performCallback();
|
||||
if (PEAR::isError($res)) {
|
||||
$this->assertTrue(false, 'Error performing callback: '. $res->getMessage());
|
||||
}
|
||||
$this->assertEquals('callback:1.50', $this->tpl->get());
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
1
HTML_Template_IT-1.3.1/tests/templates/__include.html
Normal file
1
HTML_Template_IT-1.3.1/tests/templates/__include.html
Normal file
@@ -0,0 +1 @@
|
||||
Included file
|
||||
1
HTML_Template_IT-1.3.1/tests/templates/addblock.html
Normal file
1
HTML_Template_IT-1.3.1/tests/templates/addblock.html
Normal file
@@ -0,0 +1 @@
|
||||
added:{new_var}
|
||||
@@ -0,0 +1,7 @@
|
||||
<!-- BEGIN outer_block -->
|
||||
{outer}
|
||||
<!-- BEGIN inner_block -->
|
||||
|{inner}
|
||||
<!-- END inner_block -->
|
||||
#
|
||||
<!-- END outer_block -->
|
||||
8
HTML_Template_IT-1.3.1/tests/templates/blocks.html
Normal file
8
HTML_Template_IT-1.3.1/tests/templates/blocks.html
Normal file
@@ -0,0 +1,8 @@
|
||||
{var}
|
||||
<!-- BEGIN old_block -->
|
||||
old:{old_var}
|
||||
<!-- BEGIN old_inner_block -->
|
||||
|{old_inner_var}
|
||||
<!-- END old_inner_block -->
|
||||
#
|
||||
<!-- END old_block -->
|
||||
20
HTML_Template_IT-1.3.1/tests/templates/bug_9853_01.tpl
Normal file
20
HTML_Template_IT-1.3.1/tests/templates/bug_9853_01.tpl
Normal file
@@ -0,0 +1,20 @@
|
||||
############ TEST ################
|
||||
|
||||
before foo1 bloc
|
||||
<!-- BEGIN foo1 -->
|
||||
In foo1...{VAR}
|
||||
<!-- END foo1 -->
|
||||
after foo1 bloc
|
||||
|
||||
before foo2 bloc
|
||||
<!-- BEGIN foo2 -->
|
||||
In foo2...{VAR}
|
||||
<!-- END foo2 -->
|
||||
after foo2 bloc
|
||||
|
||||
before bar bloc
|
||||
<!-- BEGIN bar -->
|
||||
In bar...{VAR.}
|
||||
In bar...{VAR2}
|
||||
<!-- END bar -->
|
||||
after bar bloc
|
||||
20
HTML_Template_IT-1.3.1/tests/templates/bug_9853_02.tpl
Normal file
20
HTML_Template_IT-1.3.1/tests/templates/bug_9853_02.tpl
Normal file
@@ -0,0 +1,20 @@
|
||||
############ TEST ################
|
||||
|
||||
before foo1 bloc
|
||||
<!-- BEGIN foo. -->
|
||||
In foo1...{VAR}
|
||||
<!-- END foo. -->
|
||||
after foo1 bloc
|
||||
|
||||
before foo2 bloc
|
||||
<!-- BEGIN foo2 -->
|
||||
In foo2...{VAR}
|
||||
<!-- END foo2 -->
|
||||
after foo2 bloc
|
||||
|
||||
before bar bloc
|
||||
<!-- BEGIN bar -->
|
||||
In bar...{VAR.}
|
||||
In bar...{VAR2}
|
||||
<!-- END bar -->
|
||||
after bar bloc
|
||||
13
HTML_Template_IT-1.3.1/tests/templates/globals.html
Normal file
13
HTML_Template_IT-1.3.1/tests/templates/globals.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!-- BEGIN block_one -->
|
||||
{glob}:{var1}#
|
||||
<!-- END block_one -->
|
||||
<!-- BEGIN block_two -->
|
||||
{glob}:{var2}#
|
||||
<!-- END block_two -->
|
||||
<!-- BEGIN block_three -->
|
||||
{glob}:{var3}
|
||||
<!-- BEGIN block_four -->
|
||||
|{glob}:{var4}
|
||||
<!-- END block_four -->
|
||||
#
|
||||
<!-- END block_three -->
|
||||
1
HTML_Template_IT-1.3.1/tests/templates/include.html
Normal file
1
HTML_Template_IT-1.3.1/tests/templates/include.html
Normal file
@@ -0,0 +1 @@
|
||||
Master file; <!-- INCLUDE __include.html -->
|
||||
@@ -0,0 +1 @@
|
||||
A template
|
||||
8
HTML_Template_IT-1.3.1/tests/templates/placeholderreplacementscope.html
Executable file
8
HTML_Template_IT-1.3.1/tests/templates/placeholderreplacementscope.html
Executable file
@@ -0,0 +1,8 @@
|
||||
<!-- BEGIN foo -->
|
||||
{var1}
|
||||
<!-- END foo -->
|
||||
<!-- BEGIN bar -->
|
||||
{var2}
|
||||
<!-- END bar -->
|
||||
|
||||
|
||||
5
HTML_Template_IT-1.3.1/tests/templates/replaceblock.html
Normal file
5
HTML_Template_IT-1.3.1/tests/templates/replaceblock.html
Normal file
@@ -0,0 +1,5 @@
|
||||
replaced:{replaced_var}
|
||||
<!-- BEGIN new_inner_block -->
|
||||
|{replaced_inner_var}
|
||||
<!-- END new_inner_block -->
|
||||
#
|
||||
Reference in New Issue
Block a user