* @author Kornel LesiĆski
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
* @version SVN: $Id: PostFilterTest.php 888 2010-06-08 09:48:33Z kornel $
* @link http://phptal.org/
*/
class MyPostFilter implements PHPTAL_Filter
{
public function filter($str)
{
if (preg_match('|(.*?)|s', $str, $m)) {
return $m[1];
}
return $str;
}
}
class MyPostFilter2 implements PHPTAL_Filter
{
public function filter($str)
{
return str_replace('test', 'test-filtered', $str);
}
}
class PostFilterTest extends PHPTAL_TestCase
{
function testIt()
{
$filter = new MyPostFilter();
$tpl = $this->newPHPTAL('input/postfilter.01.html');
$tpl->setPostFilter($filter);
$tpl->value = 'my value';
$res = normalize_html($tpl->execute());
$exp = normalize_html_file('output/postfilter.01.html');
$this->assertEquals($exp, $res);
}
function testMacro()
{
$tpl = $this->newPHPTAL();
$tpl->setPostFilter(new MyPostFilter2());
$tpl->setSource('test2
test1
');
$this->assertEquals(normalize_html('test-filtered1test-filtered2'), normalize_html($tpl->execute()));
}
}