mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
add output filter tests for caching and nocache code
This commit is contained in:
@@ -10,15 +10,16 @@
|
|||||||
* class for filter tests
|
* class for filter tests
|
||||||
*
|
*
|
||||||
* @runTestsInSeparateProcess
|
* @runTestsInSeparateProcess
|
||||||
* @preserveGlobalState disabled
|
* @preserveGlobalState disabled
|
||||||
* @backupStaticAttributes enabled
|
* @backupStaticAttributes enabled
|
||||||
*/
|
*/
|
||||||
class FilterTest extends PHPUnit_Smarty
|
class FilterTest extends PHPUnit_Smarty
|
||||||
{
|
{
|
||||||
public $loadSmartyBC = true;
|
public $loadSmartyBC = true;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->setUpSmarty(dirname(__FILE__));
|
$this->setUpSmarty(__DIR__);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInit()
|
public function testInit()
|
||||||
@@ -31,7 +32,7 @@ class FilterTest extends PHPUnit_Smarty
|
|||||||
*/
|
*/
|
||||||
public function testAutoloadOutputFilter()
|
public function testAutoloadOutputFilter()
|
||||||
{
|
{
|
||||||
$this->smarty->autoload_filters['output'] = 'trimwhitespace';
|
$this->smarty->autoload_filters[ 'output' ] = 'trimwhitespace';
|
||||||
$tpl = $this->smarty->createTemplate('eval:{" <br>hello world"}');
|
$tpl = $this->smarty->createTemplate('eval:{" <br>hello world"}');
|
||||||
$this->assertEquals("<br>hello world", $this->smarty->fetch($tpl));
|
$this->assertEquals("<br>hello world", $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
@@ -41,7 +42,7 @@ class FilterTest extends PHPUnit_Smarty
|
|||||||
*/
|
*/
|
||||||
public function testAutoloadVariableFilter()
|
public function testAutoloadVariableFilter()
|
||||||
{
|
{
|
||||||
$this->smarty->autoload_filters['variable'] = 'htmlspecialchars';
|
$this->smarty->autoload_filters[ 'variable' ] = 'htmlspecialchars';
|
||||||
$tpl = $this->smarty->createTemplate('eval:{"<test>"}');
|
$tpl = $this->smarty->createTemplate('eval:{"<test>"}');
|
||||||
$this->assertEquals("<test>", $this->smarty->fetch($tpl));
|
$this->assertEquals("<test>", $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
@@ -73,6 +74,94 @@ class FilterTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals("hello world", $this->smarty->fetch($tpl));
|
$this->assertEquals("hello world", $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test registered output filter not cached
|
||||||
|
*
|
||||||
|
* @runInSeparateProcess
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
*/
|
||||||
|
public function testRegisteredOutputFilter_001()
|
||||||
|
{
|
||||||
|
$this->smarty->assign('foo', 1);
|
||||||
|
$this->smarty->assign('bar', 2);
|
||||||
|
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myoutputfilter2');
|
||||||
|
$this->assertEquals('1 filter 2', $this->smarty->fetch('output_001.tpl'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test registered output filter not cached 2"
|
||||||
|
*
|
||||||
|
* @runInSeparateProcess
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
*/
|
||||||
|
public function testRegisteredOutputFilter_001_2()
|
||||||
|
{
|
||||||
|
$this->smarty->assign('foo', 3);
|
||||||
|
$this->smarty->assign('bar', 4);
|
||||||
|
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myoutputfilter2');
|
||||||
|
$this->assertEquals('3 filter 4', $this->smarty->fetch('output_001.tpl'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test registered output filter cached 1"
|
||||||
|
*
|
||||||
|
* @runInSeparateProcess
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
*/
|
||||||
|
public function testRegisteredOutputFilter_001_3()
|
||||||
|
{
|
||||||
|
$this->smarty->setCaching(true);
|
||||||
|
$this->smarty->assign('foo', 5);
|
||||||
|
$this->smarty->assign('bar', 6);
|
||||||
|
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myoutputfilter2');
|
||||||
|
$this->assertEquals('5 filter 6', $this->smarty->fetch('output_001.tpl'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test registered output filter cached 1"
|
||||||
|
*
|
||||||
|
* @runInSeparateProcess
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
*/
|
||||||
|
public function testRegisteredOutputFilter_001_4()
|
||||||
|
{
|
||||||
|
$this->smarty->setCaching(true);
|
||||||
|
$this->smarty->assign('foo', 7);
|
||||||
|
$this->smarty->assign('bar', 8);
|
||||||
|
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myoutputfilter2');
|
||||||
|
$this->assertEquals('5 filter 6', $this->smarty->fetch('output_001.tpl'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test registered output filter cached nocache"
|
||||||
|
*
|
||||||
|
* @runInSeparateProcess
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
*/
|
||||||
|
public function testRegisteredOutputFilter_002_1()
|
||||||
|
{
|
||||||
|
$this->smarty->setCaching(true);
|
||||||
|
$this->smarty->assign('foo', 10);
|
||||||
|
$this->smarty->assign('bar', 11);
|
||||||
|
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myoutputfilter2');
|
||||||
|
$this->assertEquals('10 filter 11', $this->smarty->fetch('output_002.tpl'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test registered output filter cached nocache"
|
||||||
|
*
|
||||||
|
* @runInSeparateProcess
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
*/
|
||||||
|
public function testRegisteredOutputFilter_002_2()
|
||||||
|
{
|
||||||
|
$this->smarty->setCaching(true);
|
||||||
|
$this->smarty->assign('foo', 12);
|
||||||
|
$this->smarty->assign('bar', 13);
|
||||||
|
$this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myoutputfilter2');
|
||||||
|
$this->assertEquals('12 filter 13', $this->smarty->fetch('output_002.tpl'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testRegisteredOutputFilterWrapper()
|
public function testRegisteredOutputFilterWrapper()
|
||||||
{
|
{
|
||||||
$this->smartyBC->register_outputfilter('myoutputfilter');
|
$this->smartyBC->register_outputfilter('myoutputfilter');
|
||||||
@@ -96,6 +185,18 @@ class FilterTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals("bar hello world", $this->smarty->fetch($tpl));
|
$this->assertEquals("bar hello world", $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test registered pre filter closure
|
||||||
|
*/
|
||||||
|
public function testRegisteredPreFilterClosure()
|
||||||
|
{
|
||||||
|
$this->smarty->registerFilter(Smarty::FILTER_PRE, function ($input) {
|
||||||
|
return '{$foo}' . $input;
|
||||||
|
});
|
||||||
|
$tpl = $this->smarty->createTemplate('eval:{" hello world"}');
|
||||||
|
$tpl->assign('foo', 'buh');
|
||||||
|
$this->assertEquals("buh hello world", $this->smarty->fetch($tpl));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test registered pre filter class
|
* test registered pre filter class
|
||||||
@@ -162,6 +263,11 @@ function myoutputfilter($input)
|
|||||||
return str_replace(' ', ' ', $input);
|
return str_replace(' ', ' ', $input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function myoutputfilter2($input, $tpl)
|
||||||
|
{
|
||||||
|
return $input . ' filter ' . $tpl->tpl_vars[ 'bar' ];
|
||||||
|
}
|
||||||
|
|
||||||
class myprefilterclass
|
class myprefilterclass
|
||||||
{
|
{
|
||||||
static function myprefilter($input)
|
static function myprefilter($input)
|
||||||
|
1
tests/UnitTests/A_Core/Filter/templates/output_001.tpl
Normal file
1
tests/UnitTests/A_Core/Filter/templates/output_001.tpl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{$foo}
|
1
tests/UnitTests/A_Core/Filter/templates/output_002.tpl
Normal file
1
tests/UnitTests/A_Core/Filter/templates/output_002.tpl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{$foo nocache}
|
Reference in New Issue
Block a user