From dd935863bd0251728af07e26d59923cc37b037a6 Mon Sep 17 00:00:00 2001 From: uwetews Date: Wed, 27 Jan 2016 00:28:36 +0100 Subject: [PATCH] add output filter tests for caching and nocache code --- tests/UnitTests/A_Core/Filter/FilterTest.php | 114 +++++++++++++++++- .../A_Core/Filter/templates/output_001.tpl | 1 + .../A_Core/Filter/templates/output_002.tpl | 1 + 3 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 tests/UnitTests/A_Core/Filter/templates/output_001.tpl create mode 100644 tests/UnitTests/A_Core/Filter/templates/output_002.tpl diff --git a/tests/UnitTests/A_Core/Filter/FilterTest.php b/tests/UnitTests/A_Core/Filter/FilterTest.php index cfbee3b7..589d37ea 100644 --- a/tests/UnitTests/A_Core/Filter/FilterTest.php +++ b/tests/UnitTests/A_Core/Filter/FilterTest.php @@ -10,15 +10,16 @@ * class for filter tests * * @runTestsInSeparateProcess - * @preserveGlobalState disabled + * @preserveGlobalState disabled * @backupStaticAttributes enabled */ class FilterTest extends PHPUnit_Smarty { public $loadSmartyBC = true; + public function setUp() { - $this->setUpSmarty(dirname(__FILE__)); + $this->setUpSmarty(__DIR__); } public function testInit() @@ -31,7 +32,7 @@ class FilterTest extends PHPUnit_Smarty */ public function testAutoloadOutputFilter() { - $this->smarty->autoload_filters['output'] = 'trimwhitespace'; + $this->smarty->autoload_filters[ 'output' ] = 'trimwhitespace'; $tpl = $this->smarty->createTemplate('eval:{"
hello world"}'); $this->assertEquals("
hello world", $this->smarty->fetch($tpl)); } @@ -41,7 +42,7 @@ class FilterTest extends PHPUnit_Smarty */ public function testAutoloadVariableFilter() { - $this->smarty->autoload_filters['variable'] = 'htmlspecialchars'; + $this->smarty->autoload_filters[ 'variable' ] = 'htmlspecialchars'; $tpl = $this->smarty->createTemplate('eval:{""}'); $this->assertEquals("<test>", $this->smarty->fetch($tpl)); } @@ -73,6 +74,94 @@ class FilterTest extends PHPUnit_Smarty $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() { $this->smartyBC->register_outputfilter('myoutputfilter'); @@ -96,6 +185,18 @@ class FilterTest extends PHPUnit_Smarty $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 @@ -162,6 +263,11 @@ function myoutputfilter($input) return str_replace(' ', ' ', $input); } +function myoutputfilter2($input, $tpl) +{ + return $input . ' filter ' . $tpl->tpl_vars[ 'bar' ]; +} + class myprefilterclass { static function myprefilter($input) diff --git a/tests/UnitTests/A_Core/Filter/templates/output_001.tpl b/tests/UnitTests/A_Core/Filter/templates/output_001.tpl new file mode 100644 index 00000000..b9490d3b --- /dev/null +++ b/tests/UnitTests/A_Core/Filter/templates/output_001.tpl @@ -0,0 +1 @@ +{$foo} \ No newline at end of file diff --git a/tests/UnitTests/A_Core/Filter/templates/output_002.tpl b/tests/UnitTests/A_Core/Filter/templates/output_002.tpl new file mode 100644 index 00000000..fc4caa73 --- /dev/null +++ b/tests/UnitTests/A_Core/Filter/templates/output_002.tpl @@ -0,0 +1 @@ +{$foo nocache} \ No newline at end of file