cvs: pear /HTML_Template_IT/tests ITX_api_testcase.php
| From: | David Soria Parra | Date: | Thu, 17 Aug 2006 15:43:37 +0000 |
| Subject: | cvs: pear /HTML_Template_IT/tests ITX_api_testcase.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-41657@lists.php.net to get a copy of this message | ||
dsp Thu Aug 17 15:43:37 2006 UTC
Modified files:
/pear/HTML_Template_IT/tests ITX_api_testcase.php
Log:
Improve tests by testing callback on objects and test the new expandCallbackParameters option in
setCallbackFunction
http://cvs.php.net/viewvc.cgi/pear/HTML_Template_IT/tests/ITX_api_testcase.php?r1=1.1&r2=1.2&diff_format=u
Index: pear/HTML_Template_IT/tests/ITX_api_testcase.php
diff -u pear/HTML_Template_IT/tests/ITX_api_testcase.php:1.1
pear/HTML_Template_IT/tests/ITX_api_testcase.php:1.2
--- pear/HTML_Template_IT/tests/ITX_api_testcase.php:1.1 Wed Mar 12 02:21:13 2003
+++ pear/HTML_Template_IT/tests/ITX_api_testcase.php Thu Aug 17 15:43:37 2006
@@ -7,6 +7,18 @@
return strtoupper($ary[0]);
}
+class Callbacks
+{
+ function _lowercaseCallback($ary)
+ {
+ return strtolower($ary[0]);
+ }
+
+ function _numberFormatCallback($float, $decimals)
+ {
+ return number_format($float, $decimals);
+ }
+}
class ITX_api_TestCase extends IT_api_TestCase
{
@@ -123,6 +135,39 @@
$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());
}
}