diff options
Diffstat (limited to 'tests/UnitTests')
255 files changed, 3105 insertions, 5047 deletions
diff --git a/tests/UnitTests/A_0/PathNormalization/PathNormalizationTest.php b/tests/UnitTests/A_0/PathNormalization/PathNormalizationTest.php index 620f21c8..8cfaff44 100644 --- a/tests/UnitTests/A_0/PathNormalization/PathNormalizationTest.php +++ b/tests/UnitTests/A_0/PathNormalization/PathNormalizationTest.php @@ -6,9 +6,9 @@ /** * class for path normalization tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PathNormalizationTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/A_0/PathNormalization/PluginDirNormalizationTest.php b/tests/UnitTests/A_0/PathNormalization/PluginDirNormalizationTest.php deleted file mode 100644 index 4d623876..00000000 --- a/tests/UnitTests/A_0/PathNormalization/PluginDirNormalizationTest.php +++ /dev/null @@ -1,145 +0,0 @@ -<?php -/* - * This file is part of the Smarty PHPUnit tests. - */ - -/** - * class for path normalization tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class PluginNormalizationTest extends PHPUnit_Smarty -{ - /* - * Setup test fixture - */ - public function setUp(): void - { - $this->setUpSmarty(__DIR__); - } - - public function testGetPluginsDefaultDir() - { - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(1, count($result)); - $this->assertEquals(SMARTY_PLUGINS_DIR, $result[ 0 ]); - } - public function testGetPluginsDefaultDir2() - { - $this->smarty->addPluginsDir('./foo/'); - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(2, count($result)); - $this->assertEquals(SMARTY_PLUGINS_DIR, $result[ 0 ]); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 1 ]); - } - - public function testSetPluginsDir1() - { - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(1, count($result)); - $this->smarty->setPluginsDir('foo'); - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(1, count($result)); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]); - } - - public function testSetPluginsDir2() - { - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(1, count($result)); - $this->smarty->setPluginsDir('foo/'); - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(1, count($result)); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]); - } - - public function testSetPluginsDir3() - { - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(1, count($result)); - $this->smarty->setPluginsDir('foo/.'); - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(1, count($result)); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]); - } - - public function testSetPluginsDir4() - { - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(1, count($result)); - $this->smarty->setPluginsDir('foo/./'); - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(1, count($result)); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]); - } - - public function testSetPluginsDir5() - { - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(1, count($result)); - $this->smarty->setPluginsDir('.foo'); - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(1, count($result)); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . '.foo' . DIRECTORY_SEPARATOR, $result[ 0 ]); - } - - public function testSetPluginsDir6() - { - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(1, count($result)); - $this->smarty->setPluginsDir('..foo'); - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(1, count($result)); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . '..foo' . DIRECTORY_SEPARATOR, $result[ 0 ]); - } - - public function testSetPluginsDir7() - { - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(1, count($result)); - $this->smarty->setPluginsDir('../foo'); - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(1, count($result)); - $this->assertEquals(substr(getcwd(), 0, - strlen(basename(getcwd()))) . 'foo' . DIRECTORY_SEPARATOR, - $result[ 0 ]); - } - - public function testSetPluginsDir8() - { - $this->smarty->setPluginsDir(array('foo', 'bah')); - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(2, count($result)); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'bah' . DIRECTORY_SEPARATOR, $result[ 1 ]); - } - - public function testSetPluginsDir9() - { - $this->smarty->setPluginsDir(array('foo', 'bah')); - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(2, count($result)); - $this->smarty->addPluginsDir('blar'); - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(3, count($result)); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'bah' . DIRECTORY_SEPARATOR, $result[ 1 ]); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'blar' . DIRECTORY_SEPARATOR, $result[ 2 ]); - } - - public function testSetPluginsDir10() - { - $this->smarty->setPluginsDir(array('foo', 'bah')); - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(2, count($result)); - $this->smarty->addPluginsDir(array('blar', 'smarty')); - $result = $this->smarty->getPluginsDir(); - $this->assertEquals(4, count($result)); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $result[ 0 ]); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'bah' . DIRECTORY_SEPARATOR, $result[ 1 ]); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'blar' . DIRECTORY_SEPARATOR, $result[ 2 ]); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'smarty' . DIRECTORY_SEPARATOR, $result[ 3 ]); - } - -} diff --git a/tests/UnitTests/A_0/PathNormalization/TemlateDirNormalizationTest.php b/tests/UnitTests/A_0/PathNormalization/TemlateDirNormalizationTest.php index cf47ff0c..f13eb2ff 100644 --- a/tests/UnitTests/A_0/PathNormalization/TemlateDirNormalizationTest.php +++ b/tests/UnitTests/A_0/PathNormalization/TemlateDirNormalizationTest.php @@ -6,9 +6,9 @@ /** * class for path normalization tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class TemplateNormalizationTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/A_1/ProtectedFolderVars/ProtectedFolderVarsTest.php b/tests/UnitTests/A_1/ProtectedFolderVars/ProtectedFolderVarsTest.php index a6fb46a3..1b7cd61a 100644 --- a/tests/UnitTests/A_1/ProtectedFolderVars/ProtectedFolderVarsTest.php +++ b/tests/UnitTests/A_1/ProtectedFolderVars/ProtectedFolderVarsTest.php @@ -3,12 +3,14 @@ * This file is part of the Smarty PHPUnit tests. */ +use Smarty\Smarty; + /** * class for protected $template_dir, $compile_dir, $cache_dir, $config_dir, $plugins_dir property tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class ProtectedFolderVarsTest extends PHPUnit_Smarty { @@ -27,7 +29,7 @@ class ProtectedFolderVarsTest extends PHPUnit_Smarty public function testTemplateDirDirectRelative() { $s = new Smarty(); - $s->template_dir = './foo'; + $s->setTemplateDir('./foo'); $d = $s->getTemplateDir(); $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]); } @@ -35,8 +37,8 @@ class ProtectedFolderVarsTest extends PHPUnit_Smarty public function testTemplateDirDirectRelativeArray() { $s = new Smarty(); - $s->template_dir = array('./foo', './bar/'); - $d = $s->template_dir; + $s->setTemplateDir(array('./foo', './bar/')); + $d = $s->getTemplateDir(); $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]); $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 1 ]); } @@ -44,7 +46,7 @@ class ProtectedFolderVarsTest extends PHPUnit_Smarty public function testTemplateDirDirectRelativeArrayAdd() { $s = new Smarty(); - $s->template_dir = './foo'; + $s->setTemplateDir('./foo'); $s->addTemplateDir('./bar/'); $d = $s->getTemplateDir(); $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]); @@ -61,7 +63,7 @@ class ProtectedFolderVarsTest extends PHPUnit_Smarty public function testTemplateDirDirectRelativeExtends2() { $s = new FolderT(); - $s->template_dir = './bar'; + $s->setTemplateDir('./bar'); $d = $s->getTemplateDir(); $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 0 ]); } @@ -73,7 +75,7 @@ class ProtectedFolderVarsTest extends PHPUnit_Smarty public function testConfigDirDirectRelative() { $s = new Smarty(); - $s->config_dir = './foo'; + $s->setConfigDir('./foo'); $d = $s->getConfigDir(); $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]); } @@ -81,8 +83,8 @@ class ProtectedFolderVarsTest extends PHPUnit_Smarty public function testConfigDirDirectRelativeArray() { $s = new Smarty(); - $s->config_dir = array('./foo', './bar/'); - $d = $s->config_dir; + $s->setConfigDir(array('./foo', './bar/')); + $d = $s->getConfigDir(); $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]); $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 1 ]); } @@ -90,7 +92,7 @@ class ProtectedFolderVarsTest extends PHPUnit_Smarty public function testConfigDirDirectRelativeArrayAdd() { $s = new Smarty(); - $s->config_dir = './foo'; + $s->setConfigDir('./foo'); $s->addConfigDir('./bar/'); $d = $s->getConfigDir(); $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]); @@ -107,64 +109,19 @@ class ProtectedFolderVarsTest extends PHPUnit_Smarty public function testConfigDirDirectRelativeExtends2() { $s = new FolderT(); - $s->config_dir = './bar'; + $s->setConfigDir('./bar'); $d = $s->getConfigDir(); $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 0 ]); } /* - * plugins_dir - */ - - public function testPluginDirDirectRelative() - { - $s = new Smarty(); - $s->plugins_dir = './foo'; - $d = $s->getPluginsDir(); - $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]); - } - - public function testPluginDirDirectRelativeArray() - { - $s = new Smarty(); - $s->plugins_dir = array('./foo', './bar/'); - $d = $s->plugins_dir; - $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]); - $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 1 ]); - } - - public function testPluginDirDirectRelativeArrayAdd() - { - $s = new Smarty(); - $s->plugins_dir = './foo'; - $s->addPluginsDir('./bar/'); - $d = $s->getPluginsDir(); - $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d[ 0 ]); - $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 1 ]); - } - - public function testPluginDirDirectRelativeExtends() - { - $s = new FolderT(); - $d = $s->getPluginsDir(); - $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'plug' . DIRECTORY_SEPARATOR, $d[ 0 ]); - } - - public function testPluginDirDirectRelativeExtends2() - { - $s = new FolderT(); - $s->plugins_dir = './bar'; - $d = $s->getPluginsDir(); - $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d[ 0 ]); - } - /* * compile_dir */ public function testCompileDirDirectRelative() { $s = new Smarty(); - $s->compile_dir = './foo'; + $s->setCompileDir('./foo'); $d = $s->getCompileDir(); $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d); } @@ -179,7 +136,7 @@ class ProtectedFolderVarsTest extends PHPUnit_Smarty public function testCompileDirDirectRelativeExtends2() { $s = new FolderT(); - $s->compile_dir = './bar'; + $s->setCompileDir('./bar'); $d = $s->getCompileDir(); $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d); } @@ -190,7 +147,7 @@ class ProtectedFolderVarsTest extends PHPUnit_Smarty public function testCacheDirDirectRelative() { $s = new Smarty(); - $s->cache_dir = './foo'; + $s->setCacheDir('./foo'); $d = $s->getCacheDir(); $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, $d); } @@ -205,13 +162,13 @@ class ProtectedFolderVarsTest extends PHPUnit_Smarty public function testCacheDirDirectRelativeExtends2() { $s = new FolderT(); - $s->cache_dir = './bar'; + $s->setCacheDir('./bar'); $d = $s->getCacheDir(); $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR, $d); } } -class FolderT extends Smarty +class FolderT extends \Smarty\Smarty { protected $template_dir = './foo'; diff --git a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php index f57af244..e1afc1ea 100644 --- a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php +++ b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php @@ -6,7 +6,7 @@ /** * class for protected $template_dir, $compile_dir, $cache_dir, $config_dir, $plugins_dir property tests * - * @backupStaticAttributes enabled + * */ class UndefinedTemplateVarTest extends PHPUnit_Smarty { @@ -65,26 +65,13 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty */ public function testError() { - $exceptionThrown = false; - - try { - $e1 = error_reporting(); - $this->assertEquals('undefined = ', $this->smarty->fetch('001_main.tpl')); - $e2 = error_reporting(); - $this->assertEquals($e1, $e2); - } catch (Exception $e) { - - $exceptionThrown = true; - $this->assertStringStartsWith('Undefined ', $e->getMessage()); - $this->assertTrue(in_array( - get_class($e), - [ - 'PHPUnit\Framework\Error\Warning', - 'PHPUnit\Framework\Error\Notice', - ] - )); - } - $this->assertTrue($exceptionThrown); + $this->smarty->error_unassigned = true; + $this->expectException(PHPUnit\Framework\Error\Error::class); + $this->expectExceptionMessage('Undefined '); + $e1 = error_reporting(); + $this->assertEquals('undefined = ', $this->smarty->fetch('001_main.tpl')); + $e2 = error_reporting(); + $this->assertEquals($e1, $e2); } public function testUndefinedSimpleVar() { @@ -145,9 +132,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty $this->assertEquals("ab", $this->smarty->fetch($tpl)); } - /** - * @group 20221124 - */ + public function testDereferenceOnNull() { $this->smarty->setErrorReporting(E_ALL & ~E_WARNING & ~E_NOTICE); $this->smarty->muteUndefinedOrNullWarnings(); @@ -156,9 +141,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty $this->assertEquals("ab", $this->smarty->fetch($tpl)); } - /** - * @group 20221124 - */ + public function testDereferenceOnBool() { $this->smarty->setErrorReporting(E_ALL & ~E_NOTICE); $this->smarty->muteUndefinedOrNullWarnings(); @@ -167,9 +150,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty $this->assertEquals("ab", $this->smarty->fetch($tpl)); } - /** - * @group 20221124 - */ + public function testDereferenceOnString() { $this->smarty->setErrorReporting(E_ALL & ~E_NOTICE); $this->smarty->muteUndefinedOrNullWarnings(); diff --git a/tests/UnitTests/A_Core/AutoEscape/AutoEscapeTest.php b/tests/UnitTests/A_Core/AutoEscape/AutoEscapeTest.php index f98d9a84..f8ea54d5 100644 --- a/tests/UnitTests/A_Core/AutoEscape/AutoEscapeTest.php +++ b/tests/UnitTests/A_Core/AutoEscape/AutoEscapeTest.php @@ -6,9 +6,9 @@ /** * class for 'escapeHtml' property tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class AutoEscapeTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/A_Core/Filter/FilterClosure.php b/tests/UnitTests/A_Core/Filter/FilterClosure.php index 2b642640..effbf29a 100644 --- a/tests/UnitTests/A_Core/Filter/FilterClosure.php +++ b/tests/UnitTests/A_Core/Filter/FilterClosure.php @@ -5,7 +5,7 @@ * @requires PHP 5.3 */ - $this->smarty->registerFilter(Smarty::FILTER_PRE, function ($input) { + $this->smarty->registerFilter(\Smarty\Smarty::FILTER_PRE, function ($input) { return '{$foo}' . $input; }); $tpl = $this->smarty->createTemplate('eval:{" hello world"}'); diff --git a/tests/UnitTests/A_Core/Filter/FilterTest.php b/tests/UnitTests/A_Core/Filter/FilterTest.php index bea43e33..ad005518 100644 --- a/tests/UnitTests/A_Core/Filter/FilterTest.php +++ b/tests/UnitTests/A_Core/Filter/FilterTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of filter * - * @package PHPunit + * @author Uwe Tews */ /** * class for filter tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class FilterTest extends PHPUnit_Smarty { @@ -26,32 +26,21 @@ class FilterTest extends PHPUnit_Smarty $this->cleanDirs(); } - /** - * test autoload output filter - */ - public function testAutoloadOutputFilter() - { - $this->smarty->autoload_filters[ 'output' ] = 'trimwhitespace'; - $tpl = $this->smarty->createTemplate('eval:{" <br>hello world"}'); - $this->assertEquals("<br>hello world", $this->smarty->fetch($tpl)); - } - - /** - * test autoload variable filter - */ - public function testAutoloadVariableFilter() - { - $this->smarty->autoload_filters[ 'variable' ] = 'htmlspecialchars'; - $tpl = $this->smarty->createTemplate('eval:{"<test>"}'); - $this->assertEquals("<test>", $this->smarty->fetch($tpl)); - } + /** + * test loaded filter + */ + public function testNoOutputFilter() + { + $tpl = $this->smarty->createTemplate('string:{" <br>hello world"}'); + $this->assertEquals(" <br>hello world", $this->smarty->fetch($tpl)); + } /** * test loaded filter */ public function testLoadedOutputFilter() { - $this->smarty->loadFilter(Smarty::FILTER_OUTPUT, 'trimwhitespace'); + $this->smarty->loadFilter(\Smarty\Smarty::FILTER_OUTPUT, 'trimwhitespace'); $tpl = $this->smarty->createTemplate('string:{" <br>hello world"}'); $this->assertEquals("<br>hello world", $this->smarty->fetch($tpl)); } @@ -61,96 +50,90 @@ class FilterTest extends PHPUnit_Smarty */ public function testRegisteredOutputFilter() { - $this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myoutputfilter'); + $this->smarty->registerFilter(\Smarty\Smarty::FILTER_OUTPUT, 'myoutputfilter'); $tpl = $this->smarty->createTemplate('eval:{"hello world"}'); $this->assertEquals("hello world", $this->smarty->fetch($tpl)); } + /** + * test unregister output filter + */ + public function testUnRegisterOutputFilter() + { + $this->smarty->registerFilter(\Smarty\Smarty::FILTER_OUTPUT, 'myoutputfilter'); + $this->smarty->unRegisterFilter(\Smarty\Smarty::FILTER_OUTPUT, 'myoutputfilter'); + $tpl = $this->smarty->createTemplate('eval:{"hello world"}'); + $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->smarty->registerFilter(\Smarty\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->smarty->registerFilter(\Smarty\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->smarty->registerFilter(\Smarty\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->smarty->registerFilter(\Smarty\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->smarty->registerFilter(\Smarty\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->smarty->registerFilter(\Smarty\Smarty::FILTER_OUTPUT, 'myoutputfilter2'); $this->assertEquals('12 filter 13', $this->smarty->fetch('output_002.tpl')); } @@ -171,7 +154,7 @@ class FilterTest extends PHPUnit_Smarty return '{$foo}' . $input; } - $this->smarty->registerFilter(Smarty::FILTER_PRE, 'myprefilter'); + $this->smarty->registerFilter(\Smarty\Smarty::FILTER_PRE, 'myprefilter'); $tpl = $this->smarty->createTemplate('eval:{" hello world"}'); $tpl->assign('foo', 'bar'); $this->assertEquals("bar hello world", $this->smarty->fetch($tpl)); @@ -191,7 +174,7 @@ class FilterTest extends PHPUnit_Smarty */ public function testRegisteredPreFilterClass() { - $this->smarty->registerFilter(Smarty::FILTER_PRE, array('myprefilterclass', 'myprefilter')); + $this->smarty->registerFilter(\Smarty\Smarty::FILTER_PRE, array('myprefilterclass', 'myprefilter')); $tpl = $this->smarty->createTemplate('eval:{" hello world"}'); $tpl->assign('foo', 'bar'); $this->assertEquals("bar hello world", $this->smarty->fetch($tpl)); @@ -207,7 +190,7 @@ class FilterTest extends PHPUnit_Smarty return '{$foo}' . $input; } - $this->smarty->registerFilter(Smarty::FILTER_POST, 'mypostfilter'); + $this->smarty->registerFilter(\Smarty\Smarty::FILTER_POST, 'mypostfilter'); $tpl = $this->smarty->createTemplate('eval:{" hello world"}'); $tpl->assign('foo', 'bar'); $this->assertEquals('{$foo} hello world', $this->smarty->fetch($tpl)); @@ -218,20 +201,20 @@ class FilterTest extends PHPUnit_Smarty */ public function testLoadedVariableFilter() { - $this->smarty->loadFilter("variable", "htmlspecialchars"); + $this->smarty->loadFilter(\Smarty\Smarty::FILTER_VARIABLE, "escape"); $tpl = $this->smarty->createTemplate('eval:{$foo}'); $tpl->assign('foo', '<?php ?>'); $this->assertEquals('<?php ?>', $this->smarty->fetch($tpl)); } /** - * test registered post filter + * test registered variable filter */ public function testRegisteredVariableFilter2() { $var = new VarFilter(); - $this->smarty->registerFilter(Smarty::FILTER_VARIABLE, array($var, 'variablefilter')); + $this->smarty->registerFilter(\Smarty\Smarty::FILTER_VARIABLE, array($var, 'my_filter')); $tpl = $this->smarty->createTemplate('string:{$foo}'); $tpl->assign('foo', 'bar'); $this->assertEquals('var{$foo}bar', $this->smarty->fetch($tpl)); @@ -240,7 +223,7 @@ class FilterTest extends PHPUnit_Smarty Class VarFilter { - function variablefilter($input, $smarty) + function my_filter($input) { return 'var{$foo}' . $input; } @@ -253,7 +236,7 @@ function myoutputfilter($input) function myoutputfilter2($input, $tpl) { - return $input . ' filter ' . $tpl->tpl_vars[ 'bar' ]; + return $input . ' filter ' . $tpl->getValue('bar'); } class myprefilterclass diff --git a/tests/UnitTests/A_Core/Filter/LoadFilterTest.php b/tests/UnitTests/A_Core/Filter/LoadFilterTest.php deleted file mode 100644 index 223fa1e0..00000000 --- a/tests/UnitTests/A_Core/Filter/LoadFilterTest.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php -/** - * Smarty PHPunit tests loadFilter method - * - * @package PHPunit - * @author Uwe Tews - */ - -/** - * class for loadFilter method tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class LoadFilterTest extends PHPUnit_Smarty -{ - public function setUp(): void - { - $this->setUpSmarty(__DIR__); - } - - /** - * test loadFilter method - */ - public function testLoadFilter() - { - $this->smarty->loadFilter('output', 'trimwhitespace'); - $this->assertTrue(is_callable($this->smarty->registered_filters['output']['smarty_outputfilter_trimwhitespace'])); - } -} diff --git a/tests/UnitTests/A_Core/Filter/RegisterFilterTest.php b/tests/UnitTests/A_Core/Filter/RegisterFilterTest.php deleted file mode 100644 index 95e806ac..00000000 --- a/tests/UnitTests/A_Core/Filter/RegisterFilterTest.php +++ /dev/null @@ -1,158 +0,0 @@ -<?php -/** - * Smarty PHPunit tests register_filter / unregister_filter methods - * - * @package PHPunit - * @author Uwe Tews - */ - -/** - * class for register_filter / unregister_filter methods tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class RegisterFilterTest extends PHPUnit_Smarty -{ - public function setUp(): void - { - $this->setUpSmarty(__DIR__); - } - - /** - * test register->preFilter method for function - */ - public function testRegisterPrefilterFunction() - { - $this->smarty->registerFilter(Smarty::FILTER_PRE, 'myfilter'); - $this->assertTrue(is_callable($this->smarty->registered_filters['pre']['myfilter'])); - } - - /** - * test register->preFilter method for class method - */ - public function testRegisterPrefiltermethod() - { - $this->smarty->registerFilter(Smarty::FILTER_PRE, array('myfilterclass', 'execute')); - $this->assertTrue(is_callable($this->smarty->registered_filters['pre']['myfilterclass_execute'])); - } - - /** - * test register->preFilter method for class object - */ - public function testRegisterPrefilterObject() - { - $this->smarty->registerFilter(Smarty::FILTER_PRE, array(new myfilterclass, 'execute')); - $this->assertTrue(is_callable($this->smarty->registered_filters['pre']['myfilterclass_execute'])); - } - - /** - * test unregister->preFilter method for function - */ - public function testUnegisterPrefilterFunction() - { - $this->smarty->registerFilter(Smarty::FILTER_PRE, 'myfilter'); - $this->smarty->unregisterFilter(Smarty::FILTER_PRE, 'myfilter'); - $this->assertFalse(isset($this->smarty->registered_filters['pre']['myfilter'])); - } - - /** - * test unregister->preFilter method for class method - */ - public function testUnregisterPrefiltermethod() - { - $this->smarty->registerFilter(Smarty::FILTER_PRE, array('myfilterclass', 'execute')); - $this->smarty->unregisterFilter(Smarty::FILTER_PRE, array('myfilterclass', 'execute')); - $this->assertFalse(isset($this->smarty->registered_filters['pre']['myfilterclass_execute'])); - } - - /** - * test register->postFilter method for function - */ - public function testRegisterPostfilterFunction() - { - $this->smarty->registerFilter(Smarty::FILTER_POST, 'myfilter'); - $this->assertTrue(is_callable($this->smarty->registered_filters['post']['myfilter'])); - } - - /** - * test register->postFilter method for class method - */ - public function testRegisterPostfiltermethod() - { - $this->smarty->registerFilter(Smarty::FILTER_POST, array('myfilterclass', 'execute')); - $this->assertTrue(is_callable($this->smarty->registered_filters['post']['myfilterclass_execute'])); - } - - /** - * test unregister->postFilter method for function - */ - public function testUnegisterPostfilterFunction() - { - $this->smarty->registerFilter(Smarty::FILTER_POST, 'myfilter'); - $this->smarty->unregisterFilter(Smarty::FILTER_POST, 'myfilter'); - $this->assertFalse(isset($this->smarty->registered_filters['post']['myfilter'])); - } - - /** - * test unregister->postFilter method for class method - */ - public function testUnregisterPostfiltermethod() - { - $this->smarty->registerFilter(Smarty::FILTER_POST, array('myfilterclass', 'execute')); - $this->smarty->unregisterFilter(Smarty::FILTER_POST, array('myfilterclass', 'execute')); - $this->assertFalse(isset($this->smarty->registered_filters['post']['myfilterclass_execute'])); - } - - /** - * test register->outputFilter method for function - */ - public function testRegisterOutputfilterFunction() - { - $this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myfilter'); - $this->assertTrue(is_callable($this->smarty->registered_filters['output']['myfilter'])); - } - - /** - * test register->outputFilter method for class method - */ - public function testRegisterOutputfiltermethod() - { - $this->smarty->registerFilter(Smarty::FILTER_OUTPUT, array('myfilterclass', 'execute')); - $this->assertTrue(is_callable($this->smarty->registered_filters['output']['myfilterclass_execute'])); - } - - /** - * test unregister->outputFilter method for function - */ - public function testUnegisterOutputfilterFunction() - { - $this->smarty->registerFilter(Smarty::FILTER_OUTPUT, 'myfilter'); - $this->smarty->unregisterFilter(Smarty::FILTER_OUTPUT, 'myfilter'); - $this->assertFalse(isset($this->smarty->registered_filters['output']['myfilter'])); - } - - /** - * test unregister->outputFilter method for class method - */ - public function testUnregisterOutputfiltermethod() - { - $this->smarty->registerFilter(Smarty::FILTER_OUTPUT, array('myfilterclass', 'execute')); - $this->smarty->unregisterFilter(Smarty::FILTER_OUTPUT, array('myfilterclass', 'execute')); - $this->assertFalse(isset($this->smarty->registered_filters['output']['myfilterclass_execute'])); - } -} - -function myfilter($input) -{ - return $input; -} - -class myfilterclass -{ - static function execute($input) - { - return $input; - } -} diff --git a/tests/UnitTests/A_Core/GetterSetter/GetterSetterTest.php b/tests/UnitTests/A_Core/GetterSetter/GetterSetterTest.php index da5a04f1..43d622b8 100644 --- a/tests/UnitTests/A_Core/GetterSetter/GetterSetterTest.php +++ b/tests/UnitTests/A_Core/GetterSetter/GetterSetterTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of generic getter/setter * - * @package PHPunit + * @author Uwe Tews */ /** * class for generic getter/setter tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class GetterSetterTest extends PHPUnit_Smarty { @@ -32,8 +32,8 @@ class GetterSetterTest extends PHPUnit_Smarty { $this->smarty->setLeftDelimiter('<{'); $this->smarty->setRightDelimiter('}>'); - $this->assertEquals('<{', $this->smarty->left_delimiter); - $this->assertEquals('}>', $this->smarty->right_delimiter); + $this->assertEquals('<{', $this->smarty->getLeftDelimiter()); + $this->assertEquals('}>', $this->smarty->getRightDelimiter()); } /** @@ -55,10 +55,10 @@ class GetterSetterTest extends PHPUnit_Smarty $tpl = $this->smarty->createTemplate('helloworld.tpl'); $tpl->setLeftDelimiter('<{'); $tpl->setRightDelimiter('}>'); - $this->assertEquals('<{', $tpl->smarty->left_delimiter); - $this->assertEquals('}>', $tpl->smarty->right_delimiter); - $this->assertEquals('{', $this->smarty->left_delimiter); - $this->assertEquals('}', $this->smarty->right_delimiter); + $this->assertEquals('<{', $tpl->getLeftDelimiter()); + $this->assertEquals('}>', $tpl->getRightDelimiter()); + $this->assertEquals('{', $this->smarty->getLeftDelimiter()); + $this->assertEquals('}', $this->smarty->getRightDelimiter()); } /** diff --git a/tests/UnitTests/A_Core/LoadPlugin/DefaultPluginHandlerTest.php b/tests/UnitTests/A_Core/LoadPlugin/DefaultPluginHandlerTest.php index 78d2c93f..218cfab8 100644 --- a/tests/UnitTests/A_Core/LoadPlugin/DefaultPluginHandlerTest.php +++ b/tests/UnitTests/A_Core/LoadPlugin/DefaultPluginHandlerTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests deault plugin handler * - * @package PHPunit + * @author Uwe Tews */ /** * class for plugin handler tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class DefaultPluginHandlerTest extends PHPUnit_Smarty { @@ -96,7 +96,7 @@ class DefaultPluginHandlerTest extends PHPUnit_Smarty function my_plugin_handler($tag, $type, $template, &$callback, &$script, &$cachable) { switch ($type) { - case Smarty::PLUGIN_FUNCTION: + case \Smarty\Smarty::PLUGIN_FUNCTION: switch ($tag) { case 'scriptfunction': $script = './scripts/script_function_tag.php'; @@ -116,7 +116,7 @@ function my_plugin_handler($tag, $type, $template, &$callback, &$script, &$cacha default: return false; } - case Smarty::PLUGIN_COMPILER: + case \Smarty\Smarty::PLUGIN_COMPILER: switch ($tag) { case 'scriptcompilerfunction': $script = './scripts/script_compiler_function_tag.php'; @@ -128,7 +128,7 @@ function my_plugin_handler($tag, $type, $template, &$callback, &$script, &$cacha default: return false; } - case Smarty::PLUGIN_BLOCK: + case \Smarty\Smarty::PLUGIN_BLOCK: switch ($tag) { case 'scriptblock': $script = './scripts/script_block_tag.php'; @@ -138,7 +138,7 @@ function my_plugin_handler($tag, $type, $template, &$callback, &$script, &$cacha default: return false; } - case Smarty::PLUGIN_MODIFIER: + case \Smarty\Smarty::PLUGIN_MODIFIER: switch ($tag) { case 'scriptmodifier': $script = './scripts/script_modifier.php'; diff --git a/tests/UnitTests/A_Core/LoadPlugin/IncludePathTest.php b/tests/UnitTests/A_Core/LoadPlugin/IncludePathTest.php deleted file mode 100644 index 680fc8f6..00000000 --- a/tests/UnitTests/A_Core/LoadPlugin/IncludePathTest.php +++ /dev/null @@ -1,51 +0,0 @@ -<?php - -/** - * Smarty PHPunit tests for File resources - * - * @package PHPunit - * @author Rodney Rehm - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class IncludePathTest extends PHPUnit_Smarty -{ - public function setUp(): void - { - $this->setUpSmarty(__DIR__); - $this->smarty->use_include_path = true; - $this->smarty->setPluginsDir(array('./include','./include1')); - $this->smarty->enableSecurity(); - $ds = DIRECTORY_SEPARATOR; - set_include_path($this->smarty->_realpath(__DIR__ . "{$ds}..{$ds}..{$ds}..{$ds}Include_Path{$ds}Plugins{$ds}", true) . PATH_SEPARATOR . get_include_path()); - } - - /** - * Tears down the fixture - * This method is called after a test is executed. - * - */ - protected function tearDown(): void - { - ini_restore('include_path'); - $this->smarty->disableSecurity(); - parent::tearDown(); - } - public function testInit() - { - $this->cleanDirs(); - } - public function testInclude1() - { - $this->assertStringContainsString('plugin1', $this->smarty->fetch('test_include_path1.tpl')); - } - public function testInclude2() - { - $this->assertStringContainsString('plugin2', $this->smarty->fetch('test_include_path2.tpl')); - } - public function testInclude3() - { - $this->assertStringContainsString('plugin3', $this->smarty->fetch('test_include_path3.tpl')); - } - } diff --git a/tests/UnitTests/A_Core/LoadPlugin/LoadPluginTest.php b/tests/UnitTests/A_Core/LoadPlugin/LoadPluginTest.php deleted file mode 100644 index 820f31a4..00000000 --- a/tests/UnitTests/A_Core/LoadPlugin/LoadPluginTest.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php -/** - * Smarty PHPunit basic core function tests - * - * @package PHPunit - * @author Uwe Tews - */ - -/** - * class core function tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class LoadPluginTest extends PHPUnit_Smarty -{ - public function setUp(): void - { - $this->setUpSmarty(__DIR__); - } - - /** - * loadPlugin test unkown plugin - */ - public function testLoadPluginErrorReturn() - { - $this->assertFalse($this->smarty->loadPlugin('Smarty_Not_Known')); - } - - /** - * loadPlugin test Smarty_Internal_Debug exists - */ - public function testLoadPluginSmartyInternalDebug() - { - $this->assertTrue($this->smarty->loadPlugin('Smarty_Internal_Debug') == true); - } - - /** - * loadPlugin test $template_class exists - */ - public function testLoadPluginSmartyTemplateClass() - { - $this->assertTrue($this->smarty->loadPlugin($this->smarty->template_class) == true); - } - - /** - * loadPlugin test loaging from plugins_dir - */ - public function testLoadPluginSmartyPluginCounter() - { - $this->assertTrue($this->smarty->loadPlugin('Smarty_Function_Counter') == true); - } -} diff --git a/tests/UnitTests/A_Core/LoadPlugin/include/function.plugin3.php b/tests/UnitTests/A_Core/LoadPlugin/include/function.plugin3.php deleted file mode 100644 index c9c3a6ef..00000000 --- a/tests/UnitTests/A_Core/LoadPlugin/include/function.plugin3.php +++ /dev/null @@ -1,5 +0,0 @@ -<?php -function smarty_function_plugin3($params, $template) -{ - return 'plugin3'; -} diff --git a/tests/UnitTests/A_Core/LoadPlugin/templates/test_include_path1.tpl b/tests/UnitTests/A_Core/LoadPlugin/templates/test_include_path1.tpl deleted file mode 100644 index 32e70cc6..00000000 --- a/tests/UnitTests/A_Core/LoadPlugin/templates/test_include_path1.tpl +++ /dev/null @@ -1 +0,0 @@ -{plugin1}
\ No newline at end of file diff --git a/tests/UnitTests/A_Core/LoadPlugin/templates/test_include_path2.tpl b/tests/UnitTests/A_Core/LoadPlugin/templates/test_include_path2.tpl deleted file mode 100644 index 95dc322b..00000000 --- a/tests/UnitTests/A_Core/LoadPlugin/templates/test_include_path2.tpl +++ /dev/null @@ -1 +0,0 @@ -{plugin2}
\ No newline at end of file diff --git a/tests/UnitTests/A_Core/LoadPlugin/templates/test_include_path3.tpl b/tests/UnitTests/A_Core/LoadPlugin/templates/test_include_path3.tpl deleted file mode 100644 index 711abf52..00000000 --- a/tests/UnitTests/A_Core/LoadPlugin/templates/test_include_path3.tpl +++ /dev/null @@ -1 +0,0 @@ -{plugin3}
\ No newline at end of file diff --git a/tests/UnitTests/A_Core/PluginTests/PHPunitplugins/function.chain1.php b/tests/UnitTests/A_Core/PluginTests/PHPunitplugins/function.chain1.php deleted file mode 100644 index 64b6f05d..00000000 --- a/tests/UnitTests/A_Core/PluginTests/PHPunitplugins/function.chain1.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php -function smarty_function_chain1($params, $tpl) -{ - $tpl->smarty->loadPlugin('smarty_function_chain2'); - - return smarty_function_chain2($params, $tpl); -} diff --git a/tests/UnitTests/A_Core/PluginTests/PHPunitplugins/function.chain2.php b/tests/UnitTests/A_Core/PluginTests/PHPunitplugins/function.chain2.php deleted file mode 100644 index 480ba0e0..00000000 --- a/tests/UnitTests/A_Core/PluginTests/PHPunitplugins/function.chain2.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php -function smarty_function_chain2($params, $tpl) -{ - $tpl->smarty->loadPlugin('smarty_function_chain3'); - - return smarty_function_chain3($params, $tpl); -} diff --git a/tests/UnitTests/A_Core/PluginTests/PHPunitplugins/function.chain3.php b/tests/UnitTests/A_Core/PluginTests/PHPunitplugins/function.chain3.php deleted file mode 100644 index 6c0f9920..00000000 --- a/tests/UnitTests/A_Core/PluginTests/PHPunitplugins/function.chain3.php +++ /dev/null @@ -1,5 +0,0 @@ -<?php -function smarty_function_chain3($params, $tpl) -{ - return 'from chain3'; -} diff --git a/tests/UnitTests/A_Core/PluginTests/PluginChainedLoadTest.php b/tests/UnitTests/A_Core/PluginTests/PluginChainedLoadTest.php deleted file mode 100644 index 0c71f260..00000000 --- a/tests/UnitTests/A_Core/PluginTests/PluginChainedLoadTest.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php -/** - * Smarty PHPunit tests chained loading of dependend pluglind - * - * @package PHPunit - * @author Rodney Rehm - */ - -/** - * class for modifier tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class PluginChainedLoadTest extends PHPUnit_Smarty -{ - public function setUp(): void - { - $this->setUpSmarty(__DIR__); - } - - public function testInit() - { - $this->cleanDirs(); - } - - public function testPluginChainedLoad() - { - $this->smarty->addPluginsDir(__DIR__ . "/PHPunitplugins/"); - $this->assertStringContainsString('from chain3', $this->smarty->fetch('test_plugin_chained_load.tpl')); - } -} diff --git a/tests/UnitTests/A_Core/PluginTests/Shared/SharedFunctionsTest.php b/tests/UnitTests/A_Core/PluginTests/Shared/SharedFunctionsTest.php deleted file mode 100644 index 522c08c7..00000000 --- a/tests/UnitTests/A_Core/PluginTests/Shared/SharedFunctionsTest.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php -/** - * Smarty PHPunit tests of shared plugin functions - * - * @package PHPunit - * @author Rodney Rehm - */ - -/** - * class for function tests - */ -class SharedFunctionsTest extends PHPUnit_Smarty -{ - public function setUp(): void - { - $this->setUpSmarty(__DIR__); - } - - /** - * test smarty_function_escape_special_chars() - */ - public function testEscapeSpecialChars() - { - require_once SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'; - - $this->assertEquals('hello<world ©', smarty_function_escape_special_chars('hello<world ©')); - $this->assertEquals('ö€', smarty_function_escape_special_chars('ö€')); - } -} diff --git a/tests/UnitTests/A_Core/PluginTests/Shared/cache/.gitignore b/tests/UnitTests/A_Core/PluginTests/Shared/cache/.gitignore deleted file mode 100644 index 1d34e205..00000000 --- a/tests/UnitTests/A_Core/PluginTests/Shared/cache/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -*
\ No newline at end of file diff --git a/tests/UnitTests/A_Core/PluginTests/Shared/templates_c/.gitignore b/tests/UnitTests/A_Core/PluginTests/Shared/templates_c/.gitignore deleted file mode 100644 index 1d34e205..00000000 --- a/tests/UnitTests/A_Core/PluginTests/Shared/templates_c/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -*
\ No newline at end of file diff --git a/tests/UnitTests/A_Core/PluginTests/cache/.gitignore b/tests/UnitTests/A_Core/PluginTests/cache/.gitignore deleted file mode 100644 index 1d34e205..00000000 --- a/tests/UnitTests/A_Core/PluginTests/cache/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -*
\ No newline at end of file diff --git a/tests/UnitTests/A_Core/PluginTests/helpers/_object_tostring.php b/tests/UnitTests/A_Core/PluginTests/helpers/_object_tostring.php deleted file mode 100644 index 4cb55e7f..00000000 --- a/tests/UnitTests/A_Core/PluginTests/helpers/_object_tostring.php +++ /dev/null @@ -1,26 +0,0 @@ -<?php - -class _object_toString -{ - protected $string = null; - - public function __construct($string) - { - $this->string = (string) $string; - } - - public function __toString() - { - return $this->string; - } -} - -class _object_noString -{ - protected $string = null; - - public function __construct($string) - { - $this->string = (string) $string; - } -} diff --git a/tests/UnitTests/A_Core/PluginTests/templates/test_plugin_chained_load.tpl b/tests/UnitTests/A_Core/PluginTests/templates/test_plugin_chained_load.tpl deleted file mode 100644 index 3badb70f..00000000 --- a/tests/UnitTests/A_Core/PluginTests/templates/test_plugin_chained_load.tpl +++ /dev/null @@ -1 +0,0 @@ -{chain1}
\ No newline at end of file diff --git a/tests/UnitTests/A_Core/PluginTests/templates_c/.gitignore b/tests/UnitTests/A_Core/PluginTests/templates_c/.gitignore deleted file mode 100644 index 1d34e205..00000000 --- a/tests/UnitTests/A_Core/PluginTests/templates_c/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -*
\ No newline at end of file diff --git a/tests/UnitTests/CacheModify/ModifiedSince/HttpModifiedSinceTest.php b/tests/UnitTests/CacheModify/ModifiedSince/HttpModifiedSinceTest.php index 509620e6..5ce70c11 100644 --- a/tests/UnitTests/CacheModify/ModifiedSince/HttpModifiedSinceTest.php +++ b/tests/UnitTests/CacheModify/ModifiedSince/HttpModifiedSinceTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests for cache resource file * - * @package PHPunit + * @author Uwe Tews */ /** * class for cache resource file tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class HttpModifiedSinceTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/CacheResourceTests/Apc/CacheResourceCustomApcTest.php b/tests/UnitTests/CacheResourceTests/Apc/CacheResourceCustomApcTest.php index fa3ca2b1..d75382d0 100644 --- a/tests/UnitTests/CacheResourceTests/Apc/CacheResourceCustomApcTest.php +++ b/tests/UnitTests/CacheResourceTests/Apc/CacheResourceCustomApcTest.php @@ -2,17 +2,18 @@ /** * Smarty PHPunit tests for cache resource Apc * - * @package PHPunit + * @author Uwe Tews */ include_once __DIR__ . '/../Memcache/CacheResourceCustomMemcacheTest.php'; +include_once __DIR__ . '/../_shared/PHPunitplugins/cacheresource.apctest.php'; /** * class for cache resource file tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class CacheResourceCustomApcTest extends CacheResourceCustomMemcacheTest { @@ -24,7 +25,7 @@ class CacheResourceCustomApcTest extends CacheResourceCustomMemcacheTest $this->setUpSmarty(__DIR__); parent::setUp(); $this->smarty->setCachingType('apc'); - $this->smarty->addPluginsDir(SMARTY_DIR . '../demo/plugins/'); + $this->smarty->registerCacheResource('apc', new Smarty_CacheResource_Apctest()); } } diff --git a/tests/UnitTests/CacheResourceTests/File/CacheResourceFileTest.php b/tests/UnitTests/CacheResourceTests/File/CacheResourceFileTest.php index 0205edbb..192cc531 100644 --- a/tests/UnitTests/CacheResourceTests/File/CacheResourceFileTest.php +++ b/tests/UnitTests/CacheResourceTests/File/CacheResourceFileTest.php @@ -2,7 +2,7 @@ /** * Smarty PHPunit tests for cache resource file * - * @package PHPunit + * @author Uwe Tews */ @@ -10,10 +10,6 @@ include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; /** * class for cache resource file tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled */ class CacheResourceFileTest extends CacheResourceTestCommon { @@ -41,8 +37,8 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->smarty->cache_lifetime = 1000; $this->smarty->setUseSubDirs(true); $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertEquals($this->buildCachedPath($tpl, true, null, null, 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file') - , $tpl->cached->filepath); + + $this->assertRegExp('/.*\/([a-f0-9]{2}\/){3}.*.php/', $tpl->getCached()->filepath); } /** @@ -54,8 +50,8 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->smarty->cache_lifetime = 1000; $this->smarty->setUseSubDirs(true); $tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar'); - $this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar', null, 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file') - , $tpl->cached->filepath); + + $this->assertRegExp('/.*\/foo\/bar\/([a-f0-9]{2}\/){3}.*.php/', $tpl->getCached()->filepath); } /** @@ -67,8 +63,7 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->smarty->cache_lifetime = 1000; $this->smarty->setUseSubDirs(true); $tpl = $this->smarty->createTemplate('helloworld.tpl', null, 'blar'); - $this->assertEquals($this->buildCachedPath($tpl, true, null, 'blar', 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file') - , $tpl->cached->filepath); + $this->assertRegExp('/.*\/blar\/([a-f0-9]{2}\/){3}.*.php/', $tpl->getCached()->filepath); } /** @@ -80,8 +75,7 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->smarty->cache_lifetime = 1000; $this->smarty->setUseSubDirs(true); $tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar'); - $this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar', 'blar', 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file') - , $tpl->cached->filepath); + $this->assertRegExp('/.*\/foo\/bar\/blar\\/([a-f0-9]{2}\/){3}.*.php/', $tpl->getCached()->filepath); } /** @@ -95,7 +89,7 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->smarty->setUseSubDirs(true); $tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar'); $this->writeCachedContent($tpl); - $this->assertTrue(file_exists($tpl->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); $this->assertEquals(1, $this->smarty->clearAllCache()); } @@ -114,13 +108,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->writeCachedContent($tpl2); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $this->writeCachedContent($tpl3); - $this->assertTrue(file_exists($tpl->cached->filepath)); - $this->assertTrue(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); + $this->assertTrue(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); $this->assertEquals(2, $this->smarty->clearCache(null, 'foo|bar')); - $this->assertFalse(file_exists($tpl->cached->filepath)); - $this->assertTrue(file_exists($tpl2->cached->filepath)); - $this->assertFalse(file_exists($tpl3->cached->filepath)); + $this->assertFalse(file_exists($tpl->getCached()->filepath)); + $this->assertTrue(file_exists($tpl2->getCached()->filepath)); + $this->assertFalse(file_exists($tpl3->getCached()->filepath)); } public function testClearCacheCacheIdCompileId2() @@ -135,13 +129,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->writeCachedContent($tpl2); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $this->writeCachedContent($tpl3); - $this->assertTrue(file_exists($tpl->cached->filepath)); - $this->assertTrue(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); + $this->assertTrue(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); $this->assertEquals(2, $this->smarty->clearCache('helloworld.tpl')); - $this->assertFalse(file_exists($tpl->cached->filepath)); - $this->assertFalse(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); + $this->assertFalse(file_exists($tpl->getCached()->filepath)); + $this->assertFalse(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); } public function testClearCacheCacheIdCompileId2Sub() @@ -156,13 +150,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->writeCachedContent($tpl2); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $this->writeCachedContent($tpl3); - $this->assertTrue(file_exists($tpl->cached->filepath)); - $this->assertTrue(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); + $this->assertTrue(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); $this->assertEquals(2, $this->smarty->clearCache('helloworld.tpl')); - $this->assertFalse(file_exists($tpl->cached->filepath)); - $this->assertFalse(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); + $this->assertFalse(file_exists($tpl->getCached()->filepath)); + $this->assertFalse(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); } public function testClearCacheCacheIdCompileId3() @@ -177,13 +171,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->writeCachedContent($tpl2); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $this->writeCachedContent($tpl3); - $this->assertTrue(file_exists($tpl->cached->filepath)); - $this->assertTrue(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); + $this->assertTrue(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); $this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); - $this->assertTrue(file_exists($tpl->cached->filepath)); - $this->assertFalse(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); + $this->assertFalse(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); } public function testClearCacheCacheIdCompileId3Sub() @@ -198,13 +192,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->writeCachedContent($tpl2); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $this->writeCachedContent($tpl3); - $this->assertTrue(file_exists($tpl->cached->filepath)); - $this->assertTrue(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); + $this->assertTrue(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); $this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); - $this->assertTrue(file_exists($tpl->cached->filepath)); - $this->assertFalse(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); + $this->assertFalse(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); } public function testClearCacheCacheIdCompileId4() @@ -219,13 +213,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->writeCachedContent($tpl2); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $this->writeCachedContent($tpl3); - $this->assertTrue(file_exists($tpl->cached->filepath)); - $this->assertTrue(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); + $this->assertTrue(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); $this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); - $this->assertTrue(file_exists($tpl->cached->filepath)); - $this->assertFalse(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); + $this->assertFalse(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); } public function testClearCacheCacheIdCompileId4Sub() @@ -240,13 +234,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->writeCachedContent($tpl2); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $this->writeCachedContent($tpl3); - $this->assertTrue(file_exists($tpl->cached->filepath)); - $this->assertTrue(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); + $this->assertTrue(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); $this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); - $this->assertTrue(file_exists($tpl->cached->filepath)); - $this->assertFalse(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); + $this->assertFalse(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); } public function testClearCacheCacheIdCompileId5() @@ -261,13 +255,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->writeCachedContent($tpl2); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $this->writeCachedContent($tpl3); - $this->assertTrue(file_exists($tpl->cached->filepath)); - $this->assertTrue(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); + $this->assertTrue(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); $this->assertEquals(2, $this->smarty->clearCache(null, null, 'blar')); - $this->assertFalse(file_exists($tpl->cached->filepath)); - $this->assertTrue(file_exists($tpl2->cached->filepath)); - $this->assertFalse(file_exists($tpl3->cached->filepath)); + $this->assertFalse(file_exists($tpl->getCached()->filepath)); + $this->assertTrue(file_exists($tpl2->getCached()->filepath)); + $this->assertFalse(file_exists($tpl3->getCached()->filepath)); } public function testClearCacheCacheIdCompileId5Sub() @@ -282,13 +276,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->writeCachedContent($tpl2); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $this->writeCachedContent($tpl3); - $this->assertTrue(file_exists($tpl->cached->filepath)); - $this->assertTrue(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); + $this->assertTrue(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); $this->assertEquals(2, $this->smarty->clearCache(null, null, 'blar')); - $this->assertFalse(file_exists($tpl->cached->filepath)); - $this->assertTrue(file_exists($tpl2->cached->filepath)); - $this->assertFalse(file_exists($tpl3->cached->filepath)); + $this->assertFalse(file_exists($tpl->getCached()->filepath)); + $this->assertTrue(file_exists($tpl2->getCached()->filepath)); + $this->assertFalse(file_exists($tpl3->getCached()->filepath)); } public function testClearCacheCacheFile() @@ -305,15 +299,15 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->writeCachedContent($tpl3); $tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); $this->writeCachedContent($tpl4); - $this->assertTrue(file_exists($tpl->cached->filepath)); - $this->assertTrue(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); - $this->assertTrue(file_exists($tpl4->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); + $this->assertTrue(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); + $this->assertTrue(file_exists($tpl4->getCached()->filepath)); $this->assertEquals(3, $this->smarty->clearCache('helloworld.tpl')); - $this->assertFalse(file_exists($tpl->cached->filepath)); - $this->assertFalse(file_exists($tpl2->cached->filepath)); - $this->assertFalse(file_exists($tpl3->cached->filepath)); - $this->assertTrue(file_exists($tpl4->cached->filepath)); + $this->assertFalse(file_exists($tpl->getCached()->filepath)); + $this->assertFalse(file_exists($tpl2->getCached()->filepath)); + $this->assertFalse(file_exists($tpl3->getCached()->filepath)); + $this->assertTrue(file_exists($tpl4->getCached()->filepath)); } public function testClearCacheCacheFileSub() @@ -330,15 +324,15 @@ class CacheResourceFileTest extends CacheResourceTestCommon $this->writeCachedContent($tpl3); $tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); $this->writeCachedContent($tpl4); - $this->assertTrue(file_exists($tpl->cached->filepath)); - $this->assertTrue(file_exists($tpl2->cached->filepath)); - $this->assertTrue(file_exists($tpl3->cached->filepath)); - $this->assertTrue(file_exists($tpl4->cached->filepath)); + $this->assertTrue(file_exists($tpl->getCached()->filepath)); + $this->assertTrue(file_exists($tpl2->getCached()->filepath)); + $this->assertTrue(file_exists($tpl3->getCached()->filepath)); + $this->assertTrue(file_exists($tpl4->getCached()->filepath)); $this->assertEquals(3, $this->smarty->clearCache('helloworld.tpl')); - $this->assertFalse(file_exists($tpl->cached->filepath)); - $this->assertFalse(file_exists($tpl2->cached->filepath)); - $this->assertFalse(file_exists($tpl3->cached->filepath)); - $this->assertTrue(file_exists($tpl4->cached->filepath)); + $this->assertFalse(file_exists($tpl->getCached()->filepath)); + $this->assertFalse(file_exists($tpl2->getCached()->filepath)); + $this->assertFalse(file_exists($tpl3->getCached()->filepath)); + $this->assertTrue(file_exists($tpl4->getCached()->filepath)); } /** diff --git a/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php b/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php index 434f2fa1..865f427d 100644 --- a/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php +++ b/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php @@ -2,7 +2,7 @@ /** * Smarty PHPunit tests for cache resource memcache * - * @package PHPunit + * @author Uwe Tews */ @@ -11,9 +11,9 @@ include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; /** * class for cache resource memcache tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon { @@ -47,9 +47,8 @@ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon $this->smarty->caching = true; $this->smarty->cache_lifetime = 1000; $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $tpl->loadCached(); - $sha1 = $tpl->source->uid . '#helloworld_tpl##'; - $this->assertEquals($sha1, $tpl->cached->filepath); + $sha1 = $tpl->getSource()->uid . '#helloworld_tpl##'; + $this->assertEquals($sha1, $tpl->getCached()->filepath); } /** @@ -60,9 +59,8 @@ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon $this->smarty->caching = true; $this->smarty->cache_lifetime = 1000; $tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar'); - $tpl->loadCached(); - $sha1 = $tpl->source->uid . '#helloworld_tpl#foo|bar#'; - $this->assertEquals($sha1, $tpl->cached->filepath); + $sha1 = $tpl->getSource()->uid . '#helloworld_tpl#foo|bar#'; + $this->assertEquals($sha1, $tpl->getCached()->filepath); } /** @@ -73,9 +71,8 @@ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon $this->smarty->caching = true; $this->smarty->cache_lifetime = 1000; $tpl = $this->smarty->createTemplate('helloworld.tpl', null, 'blar'); - $tpl->loadCached(); - $sha1 = $tpl->source->uid . '#helloworld_tpl##blar'; - $this->assertEquals($sha1, $tpl->cached->filepath); + $sha1 = $tpl->getSource()->uid . '#helloworld_tpl##blar'; + $this->assertEquals($sha1, $tpl->getCached()->filepath); } /** @@ -86,8 +83,7 @@ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon $this->smarty->caching = true; $this->smarty->cache_lifetime = 1000; $tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar'); - $tpl->loadCached(); - $sha1 = $tpl->source->uid . '#helloworld_tpl#foo|bar#blar'; - $this->assertEquals($sha1, $tpl->cached->filepath); + $sha1 = $tpl->getSource()->uid . '#helloworld_tpl#foo|bar#blar'; + $this->assertEquals($sha1, $tpl->getCached()->filepath); } } diff --git a/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php b/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php index 3db8ccd8..c00a0282 100644 --- a/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php +++ b/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php @@ -2,7 +2,7 @@ /** * Smarty PHPunit tests for cache resource mysql * - * @package PHPunit + * @author Uwe Tews */ if (MysqlCacheEnable == true) { @@ -12,9 +12,9 @@ if (MysqlCacheEnable == true) { /** * class for cache resource file tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class CacheResourceCustomMysqlTest extends CacheResourceTestCommon { diff --git a/tests/UnitTests/CacheResourceTests/PDO/CacheResourceCustomPDOTest.php b/tests/UnitTests/CacheResourceTests/PDO/CacheResourceCustomPDOTest.php index fc9d0afd..2a372450 100644 --- a/tests/UnitTests/CacheResourceTests/PDO/CacheResourceCustomPDOTest.php +++ b/tests/UnitTests/CacheResourceTests/PDO/CacheResourceCustomPDOTest.php @@ -2,46 +2,41 @@ /** * Smarty PHPunit tests for cache resource Pdo * - * @package PHPunit + * @author Uwe Tews */ -if (PdoCacheEnable == true) { - include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; +include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; +include_once __DIR__ . '/cacheresource.pdotest.php'; - /** - * class for cache resource file tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ - class CacheResourceCustomPDOTest extends CacheResourceTestCommon - { +/** + * class for cache resource file tests + * + * + * @preserveGlobalState disabled + * + */ +class CacheResourceCustomPDOTest extends CacheResourceTestCommon +{ - public function setUp($dir = null, $clear = true) - { - if (PdoCacheEnable != true) { - $this->markTestSkipped('mysql Pdo tests are disabled'); - } - if (self::$init) { - $this->getConnection(); - } - $this->setUpSmarty(__DIR__); - parent::setUp(); - $this->smarty->setCachingType('pdo'); - $this->smarty->addPluginsDir(SMARTY_DIR . '../demo/plugins/'); - $this->assertTrue(false !== $this->smarty->loadPlugin('Smarty_CacheResource_Pdotest'), - 'loadPlugin() could not load PDO cache resource'); - $this->smarty->registerCacheResource('pdo', - new Smarty_CacheResource_Pdotest($this->getPDO(), 'output_cache')); + public function setUp($dir = null, $clear = true): void + { + if (PdoCacheEnable != true) { + $this->markTestSkipped('mysql Pdo tests are disabled'); } - - public function testInit() - { - $this->cleanDirs(); - $this->initMysqlCache(); + if (self::$init) { + $this->getConnection(); } + $this->setUpSmarty(__DIR__); + parent::setUp(); + $this->smarty->registerCacheResource('pdo', + new Smarty_CacheResource_Pdotest($this->getPDO(), 'output_cache')); + } + + public function testInit() + { + $this->cleanDirs(); + $this->initMysqlCache(); } } diff --git a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.pdotest.php b/tests/UnitTests/CacheResourceTests/PDO/cacheresource.pdotest.php index 4d695983..53ae840a 100644 --- a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.pdotest.php +++ b/tests/UnitTests/CacheResourceTests/PDO/cacheresource.pdotest.php @@ -1,13 +1,15 @@ <?php -require_once SMARTY_DIR . '../demo/plugins/cacheresource.pdo.php'; +use Smarty\Template\Cached; + +require_once __DIR__ . '/../../__shared/cacheresources/cacheresource.pdo.php'; class Smarty_CacheResource_Pdotest extends Smarty_CacheResource_Pdo { public $lockTime = 0; - public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached) + public function hasLock(\Smarty\Smarty $smarty, Cached $cached) { if ($this->lockTime) { $this->lockTime--; diff --git a/tests/UnitTests/CacheResourceTests/PDOgzip/CacheResourceCustomPDOGzipTest.php b/tests/UnitTests/CacheResourceTests/PDOgzip/CacheResourceCustomPDOGzipTest.php index 5df30e25..bcd89b8d 100644 --- a/tests/UnitTests/CacheResourceTests/PDOgzip/CacheResourceCustomPDOGzipTest.php +++ b/tests/UnitTests/CacheResourceTests/PDOgzip/CacheResourceCustomPDOGzipTest.php @@ -2,44 +2,41 @@ /** * Smarty PHPunit tests for cache resource file * - * @package PHPunit + * @author Uwe Tews */ -if (PdoGzipCacheEnable == true) { - include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; - /** - * class for cache resource file tests - * - * @backupStaticAttributes enabled - */ - class CacheResourceCustomPDOGzipTest extends CacheResourceTestCommon - { +include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; +include_once __DIR__ . '/cacheresource.pdo_gziptest.php'; - public function setUp($dir = null, $clear = true) - { - if (PdoGzipCacheEnable != true) { - $this->markTestSkipped('mysql Pdo Gzip tests are disabled'); - } - if (self::$init) { - $this->getConnection(); - } - $this->setUpSmarty(__DIR__); - parent::setUp(); - $this->smarty->setCachingType('pdo'); - $this->smarty->addPluginsDir(SMARTY_DIR . '../demo/plugins/'); - $this->assertTrue(false !== $this->smarty->loadPlugin('Smarty_CacheResource_Pdo_Gziptest'), - 'loadPlugin() could not load PDOGzip cache resource'); - $this->smarty->registerCacheResource('pdo', new Smarty_CacheResource_Pdo_Gziptest($this->getPDO(), - 'output_cache')); - } +/** + * class for cache resource file tests + * + * + */ +class CacheResourceCustomPDOGzipTest extends CacheResourceTestCommon +{ - public function testInit() - { - $this->cleanDirs(); - $this->initMysqlCache(); + public function setUp($dir = null, $clear = true): void + { + if (PdoGzipCacheEnable != true) { + $this->markTestSkipped('mysql Pdo Gzip tests are disabled'); + } + if (self::$init) { + $this->getConnection(); } + $this->setUpSmarty(__DIR__); + parent::setUp(); + $this->smarty->setCachingType('pdo'); + $this->smarty->registerCacheResource('pdo', new Smarty_CacheResource_Pdo_Gziptest($this->getPDO(), + 'output_cache')); + } + + public function testInit() + { + $this->cleanDirs(); + $this->initMysqlCache(); } } diff --git a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.pdo_gziptest.php b/tests/UnitTests/CacheResourceTests/PDOgzip/cacheresource.pdo_gziptest.php index e7dfa5f2..75745d60 100644 --- a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.pdo_gziptest.php +++ b/tests/UnitTests/CacheResourceTests/PDOgzip/cacheresource.pdo_gziptest.php @@ -1,12 +1,14 @@ <?php -require_once SMARTY_DIR . '../demo/plugins/cacheresource.pdo_gzip.php'; +use Smarty\Template\Cached; + +require_once __DIR__ . '/../../__shared/cacheresources/cacheresource.pdo_gzip.php'; class Smarty_CacheResource_Pdo_Gziptest extends Smarty_CacheResource_Pdo_Gzip { public $lockTime = 0; - public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached) + public function hasLock(\Smarty\Smarty $smarty, Cached $cached) { if ($this->lockTime) { $this->lockTime--; diff --git a/tests/UnitTests/CacheResourceTests/Registered/CacheResourceCustomRegisteredTest.php b/tests/UnitTests/CacheResourceTests/Registered/CacheResourceCustomRegisteredTest.php index 8bd34941..03acf270 100644 --- a/tests/UnitTests/CacheResourceTests/Registered/CacheResourceCustomRegisteredTest.php +++ b/tests/UnitTests/CacheResourceTests/Registered/CacheResourceCustomRegisteredTest.php @@ -2,7 +2,7 @@ /** * Smarty PHPunit tests for cache resource registered * - * @package PHPunit + * @author Uwe Tews */ if (MysqlCacheEnable == true) { @@ -11,9 +11,9 @@ if (MysqlCacheEnable == true) { /** * class for cache resource file tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class CacheResourceCustomRegisteredTest extends CacheResourceTestCommon { diff --git a/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php b/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php index a5361c18..222f1ad2 100644 --- a/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php +++ b/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php @@ -2,16 +2,18 @@ /** * Smarty PHPunit tests for cache resource file * - * @package PHPunit + * @author Uwe Tews */ +use Smarty\Template; + /** * class for cache resource file tests * - * @backupStaticAttributes enabled + * */ -class CacheResourceTestCommon extends PHPUnit_Smarty +abstract class CacheResourceTestCommon extends PHPUnit_Smarty { public static $touchResource = null; @@ -28,7 +30,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $this->assertEquals($a, $b); } - public function compiledPrefilter($text, Smarty_Internal_Template $tpl) + public function compiledPrefilter($text, Template $tpl) { $replace = $tpl->getTemplateVars('test'); return str_replace('#', $replace ?? '', $text); @@ -43,7 +45,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $this->smarty->cache_lifetime = 1000; $this->smarty->setUseSubDirs(true); $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertEquals($this->buildCachedPath($tpl), $tpl->cached->filepath); + $this->assertEquals($this->buildCachedPath($tpl), $tpl->getCached()->filepath); } /** @@ -54,7 +56,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $this->smarty->caching = true; $this->smarty->cache_lifetime = 1000; $tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar'); - $this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar'), $tpl->cached->filepath); + $this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar'), $tpl->getCached()->filepath); } /** @@ -65,7 +67,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $this->smarty->caching = true; $this->smarty->cache_lifetime = 1000; $tpl = $this->smarty->createTemplate('helloworld.tpl', null, 'blar'); - $this->assertEquals($this->buildCachedPath($tpl, true, null, 'blar'), $tpl->cached->filepath); + $this->assertEquals($this->buildCachedPath($tpl, true, null, 'blar'), $tpl->getCached()->filepath); } /** @@ -76,7 +78,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $this->smarty->caching = true; $this->smarty->cache_lifetime = 1000; $tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar'); - $this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar', 'blar'), $tpl->cached->filepath); + $this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar', 'blar'), $tpl->getCached()->filepath); } /** @@ -89,7 +91,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $this->smarty->cache_lifetime = 1000; $tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar'); $tpl->writeCachedContent('hello world'); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); + $this->assertEquals('hello world', $tpl->getCachedContent()); // Custom CacheResources may return -1 if they can't tell the number of deleted elements //$this->assertEquals(-1, $this->smarty->clearAllCache()); } @@ -110,15 +112,15 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world 3'); // test cached content - $this->assertEquals('hello world 1', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertEquals('hello world 2', $tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world 3', $tpl->cached->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world 1', $tpl->getCachedContent()); + $this->assertEquals('hello world 2', $tpl2->getCachedContent()); + $this->assertEquals('hello world 3', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(2, $this->smarty->clearCache(null, 'foo|bar')); // test that caches are deleted properly - $this->assertNull($tpl->cached->handler->getCachedContent($tpl)); - $this->assertEquals('hello world 2', $tpl->cached->handler->getCachedContent($tpl2)); - $this->assertNull($tpl->cached->handler->getCachedContent($tpl3)); + $this->assertNull($tpl->getCachedContent()); + $this->assertEquals('hello world 2', $tpl2->getCachedContent()); + $this->assertNull($tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId2() @@ -134,15 +136,15 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(2, $this->smarty->clearCache('helloworld.tpl')); // test that caches are deleted properly - $this->assertNull($tpl->cached->handler->getCachedContent($tpl)); - $this->assertNull($tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); + $this->assertNull($tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId2Sub() @@ -158,15 +160,15 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(2, $this->smarty->clearCache('helloworld.tpl')); // test that caches are deleted properly - $this->assertNull($tpl->cached->handler->getCachedContent($tpl)); - $this->assertNull($tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); + $this->assertNull($tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId3() @@ -182,15 +184,15 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); // test that caches are deleted properly - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertNull($tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId3Sub() @@ -206,15 +208,15 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); // test that caches are deleted properly - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertNull($tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId4() @@ -230,15 +232,15 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); // test that caches are deleted properly - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertNull($tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId4Sub() @@ -254,15 +256,15 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); // test that caches are deleted properly - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertNull($tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId5() @@ -278,15 +280,15 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(2, $this->smarty->clearCache(null, null, 'blar')); // test that caches are deleted properly - $this->assertNull($tpl->cached->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2)); - $this->assertNull($tpl->cached->handler->getCachedContent($tpl3)); + $this->assertNull($tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertNull($tpl3->getCachedContent()); } public function testClearCacheCacheIdCompileId5Sub() @@ -302,15 +304,15 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(2, $this->smarty->clearCache(null, null, 'blar')); // test that caches are deleted properly - $this->assertNull($tpl->cached->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2)); - $this->assertNull($tpl->cached->handler->getCachedContent($tpl3)); + $this->assertNull($tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertNull($tpl3->getCachedContent()); } public function testClearCacheCacheFile() @@ -328,17 +330,17 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); $tpl4->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); + $this->assertEquals('hello world', $tpl4->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(3, $this->smarty->clearCache('helloworld.tpl')); // test that caches are deleted properly - $this->assertNull($tpl->cached->handler->getCachedContent($tpl)); - $this->assertNull($tpl->cached->handler->getCachedContent($tpl2)); - $this->assertNull($tpl->cached->handler->getCachedContent($tpl3)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4)); + $this->assertNull($tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertNull($tpl3->getCachedContent()); + $this->assertEquals('hello world', $tpl4->getCachedContent()); } /** @@ -351,25 +353,32 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $this->smarty->clearAllCache(); // create and cache templates $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $tpl->writeCachedContent('hello world'); + $tpl->writeCachedContent('something else 1'); $tpl2 = $this->smarty->createTemplate('helloworld.tpl', null, 'bar'); - $tpl2->writeCachedContent('hello world'); + $tpl2->writeCachedContent('something else 2'); $tpl3 = $this->smarty->createTemplate('helloworld.tpl', 'buh|blar'); - $tpl3->writeCachedContent('hello world'); + $tpl3->writeCachedContent('something else 3'); // test cached content - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); - sleep(10); + $this->assertEquals('something else 1', $tpl->getCachedContent()); + $this->assertEquals('something else 2', $tpl2->getCachedContent()); + $this->assertEquals('something else 3', $tpl3->getCachedContent()); + sleep(4); $tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); - $tpl4->writeCachedContent('hello world'); + $tpl4->writeCachedContent('something else 4'); + // test number of deleted caches - $this->doClearCacheAssertion(3,$this->smarty->clearAllCache(5)); + $this->doClearCacheAssertion(3,$this->smarty->clearAllCache(2)); + + $tpl = $this->smarty->createTemplate('helloworld.tpl'); + $tpl2 = $this->smarty->createTemplate('helloworld.tpl', null, 'bar'); + $tpl3 = $this->smarty->createTemplate('helloworld.tpl', 'buh|blar'); + $tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); + // test that caches are deleted properly - $this->assertNull($tpl->cached->handler->getCachedContent($tpl)); - $this->assertNull($tpl->cached->handler->getCachedContent($tpl2)); - $this->assertNull($tpl->cached->handler->getCachedContent($tpl3)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); + $this->assertEquals('something else 4', $tpl4->getCachedContent()); } public function testClearCacheCacheFileSub() @@ -387,22 +396,20 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); $tpl4->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4)); + $this->assertEquals('hello world', $tpl->getCachedContent()); + $this->assertEquals('hello world', $tpl2->getCachedContent()); + $this->assertEquals('hello world', $tpl3->getCachedContent()); + $this->assertEquals('hello world', $tpl4->getCachedContent()); // test number of deleted caches $this->doClearCacheAssertion(3, $this->smarty->clearCache('helloworld.tpl')); // test that caches are deleted properly - $this->assertNull($tpl->cached->handler->getCachedContent($tpl)); - $this->assertNull($tpl->cached->handler->getCachedContent($tpl2)); - $this->assertNull($tpl->cached->handler->getCachedContent($tpl3)); - $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4)); + $this->assertNull($tpl->getCachedContent()); + $this->assertNull($tpl2->getCachedContent()); + $this->assertNull($tpl3->getCachedContent()); + $this->assertEquals('hello world', $tpl4->getCachedContent()); } /** * Test caching - * @runInSeparateProcess - * @preserveGlobalState disabled * @dataProvider data * @group slow */ @@ -415,7 +422,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $this->smarty->cache_locking = true; $this->smarty->locking_timeout = $lockTimeout; } - $this->smarty->compile_id = $compile_id; + $this->smarty->setCompileId($compile_id); $this->smarty->cache_id = $cache_id; $this->smarty->force_compile = $forceCompile; $this->smarty->force_cache = $forceCache; @@ -427,12 +434,12 @@ class CacheResourceTestCommon extends PHPUnit_Smarty } $tpl = $this->smarty->createTemplate('cacheresource.tpl', $this->smarty); if ($update) { - $this->assertEquals($t,$tpl->source->getTimeStamp(), $testName . ' - source touch'); + $this->assertEquals($t,$tpl->getSource()->getTimeStamp(), $testName . ' - source touch'); } if ($lockTime) { - $tpl->cached->handler->acquireLock($this->smarty, $tpl->cached); - $tpl->cached->handler->lockTime = $lockTime; - $tpl->cached->is_locked = false; + $tpl->getCached()->handler->acquireLock($this->smarty, $tpl->getCached()); + $tpl->getCached()->handler->lockTime = $lockTime; + $tpl->getCached()->is_locked = false; } $start = time(); if (isset($isCached)) { @@ -440,9 +447,9 @@ class CacheResourceTestCommon extends PHPUnit_Smarty if ($lockTimeout) { $time = time() - $start; $this->assertTrue($time >= $tmin && $time <= $tmax, $testName . ' - isCached() - lock time'); - $this->assertEquals(!$isCached, $tpl->cached->handler->hasLock($this->smarty, $tpl->cached), $testName . ' - isCached() - lock status'); + $this->assertEquals(!$isCached, $tpl->getCached()->handler->hasLock($this->smarty, $tpl->getCached()), $testName . ' - isCached() - lock status'); } else { - $this->assertFalse($tpl->cached->handler->hasLock($this->smarty, $tpl->cached), $testName . ' - isCached() - unexpected lock'); + $this->assertFalse($tpl->getCached()->handler->hasLock($this->smarty, $tpl->getCached()), $testName . ' - isCached() - unexpected lock'); } } $this->assertEquals("cache resource test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $this->smarty->fetch($tpl), $testName . ' - fetch() failure'); @@ -450,7 +457,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $time = time() - $start; $this->assertTrue($time >= $tmin && $time <= $tmax, $testName . ' - fetch() - lock time'); } - $this->assertFalse($tpl->cached->handler->hasLock($this->smarty, $tpl->cached, $testName . ' - lock not removed')); + $this->assertFalse($tpl->getCached()->handler->hasLock($this->smarty, $tpl->getCached(), $testName . ' - lock not removed')); } public function data(){ @@ -505,12 +512,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty array(10, 4, 6, null, false, 2, 10, false, false, false, 32, 32, 32, 'lock timeout - new compiled'), ); } - /** - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * - */ + public function testCachingDisabled1() { $this->smarty->assign('test', 50); @@ -518,12 +520,6 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $this->assertFalse($tpl->isCached(), 'isCached() status'); $this->assertEquals('cache resource test:50 compiled:50 rendered:50', $this->smarty->fetch($tpl), 'fetch()'); } - /** - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * - */ public function testCachingDisabled2() { $this->smarty->assign('test', 51); @@ -534,8 +530,6 @@ class CacheResourceTestCommon extends PHPUnit_Smarty /** * Test caching - * @runInSeparateProcess - * @preserveGlobalState disabled * @dataProvider dataDir * */ diff --git a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.apctest.php b/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.apctest.php index a5dddb28..38b061dc 100644 --- a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.apctest.php +++ b/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.apctest.php @@ -1,12 +1,16 @@ <?php -require_once SMARTY_DIR . '../demo/plugins/cacheresource.apc.php'; +use Smarty\Smarty; +use Smarty\Template; +use Smarty\Template\Cached; + +require_once __DIR__ . '/../../../__shared/cacheresources/cacheresource.apc.php'; class Smarty_CacheResource_Apctest extends Smarty_CacheResource_Apc { public $lockTime = 0; - public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached) + public function hasLock(Smarty $smarty, Cached $cached) { if ($this->lockTime) { $this->lockTime--; @@ -17,7 +21,7 @@ class Smarty_CacheResource_Apctest extends Smarty_CacheResource_Apc return parent::hasLock($smarty, $cached); } - public function get(Smarty_Internal_Template $_template) + public function get(Template $_template) { $this->contents = array(); $this->timestamps = array(); @@ -26,13 +30,4 @@ class Smarty_CacheResource_Apctest extends Smarty_CacheResource_Apc return $t ? $t : null; } - public function __sleep() - { - return array(); - } - - public function __wakeup() - { - $this->__construct(); - } } diff --git a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.filetest.php b/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.filetest.php index 369460b7..f97147fa 100644 --- a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.filetest.php +++ b/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.filetest.php @@ -1,11 +1,11 @@ <?php -class Smarty_CacheResource_Filetest extends Smarty_Internal_CacheResource_File +class Smarty_CacheResource_Filetest extends \Smarty\Cacheresource\File { public $lockTime = 0; - public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached) + public function hasLock(\Smarty\Smarty $smarty, \Smarty\Template\Cached $cached) { if ($this->lockTime) { $this->lockTime--; diff --git a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.memcachetest.php b/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.memcachetest.php index 8569ec8a..77f9d5f9 100644 --- a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.memcachetest.php +++ b/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.memcachetest.php @@ -1,12 +1,15 @@ <?php -require_once SMARTY_DIR . '../demo/plugins/cacheresource.memcache.php'; +use Smarty\Template; +use Smarty\Template\Cached; + +require_once __DIR__ . '/../../../__shared/cacheresources/cacheresource.memcache.php'; class Smarty_CacheResource_Memcachetest extends Smarty_CacheResource_Memcache { public $lockTime = 0; - public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached) + public function hasLock(\Smarty\Smarty $smarty, Cached $cached) { if ($this->lockTime) { $this->lockTime--; @@ -17,7 +20,7 @@ class Smarty_CacheResource_Memcachetest extends Smarty_CacheResource_Memcache return parent::hasLock($smarty, $cached); } - public function get(Smarty_Internal_Template $_template) + public function get(Template $_template) { $this->contents = array(); $this->timestamps = array(); @@ -26,13 +29,4 @@ class Smarty_CacheResource_Memcachetest extends Smarty_CacheResource_Memcache return $t ? $t : null; } - public function __sleep() - { - return array(); - } - - public function __wakeup() - { - $this->__construct(); - } } diff --git a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.mysqltest.php b/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.mysqltest.php index 47c47e45..5bc53bd1 100644 --- a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.mysqltest.php +++ b/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/cacheresource.mysqltest.php @@ -1,24 +1,19 @@ <?php -require_once SMARTY_DIR . '../demo/plugins/cacheresource.mysql.php'; +use Smarty\Exception; +use Smarty\Template\Cached; + +require_once __DIR__ . '/../../../__shared/cacheresources/cacheresource.mysql.php'; class Smarty_CacheResource_Mysqltest extends Smarty_CacheResource_Mysql { public $lockTime = 0; - public function __construct() { - try { - $this->db = PHPUnit_Smarty::$pdo; - } catch (PDOException $e) { - throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); - } - $this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id'); - $this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id'); - $this->save = $this->db->prepare('REPLACE INTO output_cache (id, name, cache_id, compile_id, content) - VALUES (:id, :name, :cache_id, :compile_id, :content)'); - } + protected function db(): PDO { + return PHPUnit_Smarty::$pdo; + } - public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached) + public function hasLock(\Smarty\Smarty $smarty, Cached $cached) { if ($this->lockTime) { $this->lockTime--; diff --git a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/resource.filetest.php b/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/resource.filetest.php index d5676d61..0aa280c4 100644 --- a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/resource.filetest.php +++ b/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/resource.filetest.php @@ -1,19 +1,23 @@ <?php -class Smarty_Resource_Filetest extends Smarty_Internal_Resource_File +use Smarty\Resource\FilePlugin; +use Smarty\Template; +use Smarty\Template\Source; + +class Smarty_Resource_FiletestPlugin extends FilePlugin { /** - * populate Source Object with meta data from Resource + * populate Source Object with metadata from Resource * - * @param Smarty_Template_Source $source source object - * @param Smarty_Internal_Template $_template template object + * @param Source $source source object + * @param Template $_template template object */ - public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) + public function populate(Source $source, Template $_template = null) { parent::populate($source, $_template); if ($source->exists) { - if (isset(CacheResourceTestCommon::$touchResource[$source->filepath])) { - $source->timestamp = CacheResourceTestCommon::$touchResource[$source->filepath]; + if (isset(CacheResourceTestCommon::$touchResource[$source->getResourceName()])) { + $source->timestamp = CacheResourceTestCommon::$touchResource[$source->getResourceName()]; } } } diff --git a/tests/UnitTests/Compiler/CompilerPlugin/CompileCompilerPluginTest.php b/tests/UnitTests/Compiler/CompilerPlugin/CompileCompilerPluginTest.php index e28b35e8..ba747981 100644 --- a/tests/UnitTests/Compiler/CompilerPlugin/CompileCompilerPluginTest.php +++ b/tests/UnitTests/Compiler/CompilerPlugin/CompileCompilerPluginTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of compiler plugins * - * @package PHPunit + * @author Uwe Tews */ /** * class for compiler plugin tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class CompileCompilerPluginTest extends PHPUnit_Smarty { @@ -30,8 +30,8 @@ class CompileCompilerPluginTest extends PHPUnit_Smarty */ public function testCompilerPluginFunction() { - $this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'compilerplugin', 'mycompilerplugin'); - $this->smarty->compile_id = 'function'; + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_COMPILER, 'compilerplugin', 'mycompilerplugin'); + $this->smarty->setCompileId('function'); $this->assertEquals("Hello World", $this->smarty->fetch('compilerplugintest.tpl')); } /** @@ -39,8 +39,8 @@ class CompileCompilerPluginTest extends PHPUnit_Smarty */ public function testCompilerPluginClassStatic() { - $this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'compilerplugin', array('CompilerPluginClass', 'statCompile')); - $this->smarty->compile_id = 'static'; + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_COMPILER, 'compilerplugin', array('CompilerPluginClass', 'statCompile')); + $this->smarty->setCompileId('static'); $this->assertEquals("Static World", $this->smarty->fetch('compilerplugintest.tpl')); } /** @@ -49,8 +49,8 @@ class CompileCompilerPluginTest extends PHPUnit_Smarty public function testCompilerPluginClassObject() { $plugin = new CompilerPluginClass; - $this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'compilerplugin', array($plugin, 'compile')); - $this->smarty->compile_id = 'object'; + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_COMPILER, 'compilerplugin', array($plugin, 'compile')); + $this->smarty->setCompileId('object'); $this->assertEquals("Public World", $this->smarty->fetch('compilerplugintest.tpl')); } } diff --git a/tests/UnitTests/Compiler/Delimiter/AutoLiteralTest.php b/tests/UnitTests/Compiler/Delimiter/AutoLiteralTest.php index d359ba63..40d21653 100644 --- a/tests/UnitTests/Compiler/Delimiter/AutoLiteralTest.php +++ b/tests/UnitTests/Compiler/Delimiter/AutoLiteralTest.php @@ -2,15 +2,15 @@ /** * Smarty PHPunit tests of delimiter * - * @package PHPunit + * @author Uwe Tews */ /** * class for delimiter tests * - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * */ class AutoliteralTest extends PHPUnit_Smarty { @@ -44,8 +44,6 @@ class AutoliteralTest extends PHPUnit_Smarty } /** * test '{ ' delimiter in double quotes auto_literal true - * @runInSeparateProcess - * */ public function testSetAutoliteralDoublequote() { @@ -54,8 +52,6 @@ class AutoliteralTest extends PHPUnit_Smarty } /** * test '{ ' delimiter in double quotes auto_literal false - * @runInSeparateProcess - * */ public function testSetAutoliteralDoublequote2() { @@ -66,8 +62,6 @@ class AutoliteralTest extends PHPUnit_Smarty /** * test '{{ ' delimiter in double quotes auto_literal true - * @runInSeparateProcess - * */ public function testSetAutoliteralDoublequote3() { diff --git a/tests/UnitTests/Compiler/Delimiter/DelimiterTest.php b/tests/UnitTests/Compiler/Delimiter/DelimiterTest.php index 06d5c6f3..4092d9fb 100644 --- a/tests/UnitTests/Compiler/Delimiter/DelimiterTest.php +++ b/tests/UnitTests/Compiler/Delimiter/DelimiterTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of delimiter * - * @package PHPunit + * @author Uwe Tews */ /** * class for delimiter tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class DelimiterTest extends PHPUnit_Smarty { @@ -30,8 +30,8 @@ class DelimiterTest extends PHPUnit_Smarty */ public function testDelimiter1() { - $this->smarty->left_delimiter = '<{'; - $this->smarty->right_delimiter = '}>'; + $this->smarty->setLeftDelimiter('<{'); + $this->smarty->setRightDelimiter('}>'); $tpl = $this->smarty->createTemplate('eval:start <{* comment *}>hello <{if true}><{"world"}><{/if}> end'); $this->assertEquals("start hello world end", $this->smarty->fetch($tpl)); } @@ -40,8 +40,8 @@ class DelimiterTest extends PHPUnit_Smarty */ public function testDelimiter10() { - $this->smarty->left_delimiter = '<'; - $this->smarty->right_delimiter = '>'; + $this->smarty->setLeftDelimiter('<'); + $this->smarty->setRightDelimiter('>'); $tpl = $this->smarty->createTemplate('eval:start <* comment *>hello <if 1 < 2><"world"></if> end'); $this->assertEquals("start hello world end", $this->smarty->fetch($tpl)); } @@ -51,8 +51,8 @@ class DelimiterTest extends PHPUnit_Smarty */ public function testDelimiter2() { - $this->smarty->left_delimiter = '<-{'; - $this->smarty->right_delimiter = '}->'; + $this->smarty->setLeftDelimiter('<-{'); + $this->smarty->setRightDelimiter('}->'); $tpl = $this->smarty->createTemplate('eval:<-<-{* comment *}-><-{if true}-><-{"hello world"}-><-{/if}->->'); $this->assertEquals("<-hello world->", $this->smarty->fetch($tpl)); } @@ -62,8 +62,8 @@ class DelimiterTest extends PHPUnit_Smarty */ public function testDelimiter3() { - $this->smarty->left_delimiter = '<--{'; - $this->smarty->right_delimiter = '}-->'; + $this->smarty->setLeftDelimiter('<--{'); + $this->smarty->setRightDelimiter('}-->'); $tpl = $this->smarty->createTemplate('eval:<--{* comment *}--><--{if true}--><--{"hello world"}--><--{/if}-->'); $this->assertEquals("hello world", $this->smarty->fetch($tpl)); } @@ -73,8 +73,8 @@ class DelimiterTest extends PHPUnit_Smarty */ public function testDelimiter4() { - $this->smarty->left_delimiter = '{{'; - $this->smarty->right_delimiter = '}}'; + $this->smarty->setLeftDelimiter('{{'); + $this->smarty->setRightDelimiter('}}'); $tpl = $this->smarty->createTemplate('eval:{{* comment *}}{{if true}}{{"hello world"}}{{/if}}'); $this->assertEquals("hello world", $this->smarty->fetch($tpl)); } @@ -84,8 +84,8 @@ class DelimiterTest extends PHPUnit_Smarty */ public function testDelimiter5() { - $this->smarty->left_delimiter = '{='; - $this->smarty->right_delimiter = '=}'; + $this->smarty->setLeftDelimiter('{='); + $this->smarty->setRightDelimiter('=}'); $tpl = $this->smarty->createTemplate('eval:{=assign var=foo value="hello world" nocache=}{=$foo=}'); $this->assertEquals("hello world", $this->smarty->fetch($tpl)); } @@ -94,8 +94,8 @@ class DelimiterTest extends PHPUnit_Smarty */ public function testDelimiterIssue450() { - $this->smarty->left_delimiter = '{^'; - $this->smarty->right_delimiter = '^}'; + $this->smarty->setLeftDelimiter('{^'); + $this->smarty->setRightDelimiter('^}'); $tpl = $this->smarty->createTemplate('eval:{^assign var=foo value="hello world" nocache^}{^$foo^}'); $this->assertEquals("hello world", $this->smarty->fetch($tpl)); } diff --git a/tests/UnitTests/Compiler/Delimiter/UserLiteralTest.php b/tests/UnitTests/Compiler/Delimiter/UserLiteralTest.php index 52308a20..33a17eea 100644 --- a/tests/UnitTests/Compiler/Delimiter/UserLiteralTest.php +++ b/tests/UnitTests/Compiler/Delimiter/UserLiteralTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of delimiter * - * @package PHPunit + * @author Uwe Tews */ /** * class for delimiter tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class UserliteralTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/ConfigFileTests/defaultHandler/DefaultConfigHandlerTest.php b/tests/UnitTests/ConfigFileTests/defaultHandler/DefaultConfigHandlerTest.php index 7c358412..ab5ecdc6 100644 --- a/tests/UnitTests/ConfigFileTests/defaultHandler/DefaultConfigHandlerTest.php +++ b/tests/UnitTests/ConfigFileTests/defaultHandler/DefaultConfigHandlerTest.php @@ -2,16 +2,18 @@ /** * Smarty PHPUnit tests default config handler * - * @package PHPunit + * @author Uwe Tews */ +use Smarty\Smarty; + /** * class for default config handler test * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class DefaultConfigHandlerTest extends PHPUnit_Smarty { @@ -32,8 +34,8 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty */ public function testUnknownConfigFile() { - $this->expectException('SmartyException'); - $this->expectExceptionMessage('Unable to load config \'file:foo.conf\''); + $this->expectException(\Smarty\Exception::class); + $this->expectExceptionMessage('Unable to load \'file:foo.conf\''); $this->smarty->configLoad('foo.conf'); } @@ -42,7 +44,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty */ public function testRegisterUnknownDefaultConfigHandler() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('Default config handler'); $this->expectExceptionMessage('not callable'); $this->smarty->registerDefaultConfigHandler('foo'); @@ -52,7 +54,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty * test default config handler replacement (config data) * * @throws \Exception - * @throws \SmartyException + * @throws \Smarty\Exception */ public function testDefaultConfigHandlerReplacement() { @@ -65,7 +67,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty * test default config handler replacement (other config file) * * @throws \Exception - * @throws \SmartyException + * @throws \Smarty\Exception */ public function testDefaultConfigHandlerReplacementByConfigFile() { @@ -76,8 +78,8 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty public function testDefaultConfigHandlerReplacementByConfigFileFail() { - $this->expectException('SmartyException'); - $this->expectExceptionMessage("Unable to load config default file 'no.conf' for 'file:fo.conf'"); + $this->expectException(\Smarty\Exception::class); + $this->expectExceptionMessage("Unable to load default file 'no.conf' for 'file:fo.conf'"); $this->smarty->registerDefaultConfigHandler('configHandlerFile'); $this->smarty->configLoad('fo.conf'); $this->assertEquals("123.4", $this->smarty->fetch('number.tpl')); @@ -88,8 +90,8 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty */ public function testDefaultConfigHandlerReplacementReturningFalse() { - $this->expectException('SmartyException'); - $this->expectExceptionMessage('Unable to load config \'file:foo.conf\''); + $this->expectException(\Smarty\Exception::class); + $this->expectExceptionMessage('Unable to load \'file:foo.conf\''); $this->smarty->configLoad('foo.conf'); } @@ -98,7 +100,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty */ public function testDefaultConfigHandlerReplacementReturningFalse1() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('No config default content for \'file:bla.conf\''); $this->smarty->registerDefaultConfigHandler('configHandlerData'); $this->smarty->configLoad('bla.conf'); @@ -117,7 +119,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty * * @return bool */ -function configHandlerData($resource_type, $resource_name, &$config_source, &$config_timestamp, Smarty $smarty) +function configHandlerData($resource_type, $resource_name, &$config_source, &$config_timestamp, \Smarty\Smarty $smarty) { if ($resource_name !== 'foo.conf') { return false; @@ -140,7 +142,7 @@ function configHandlerData($resource_type, $resource_name, &$config_source, &$co * * @return string */ -function configHandlerFile($resource_type, $resource_name, &$config_source, &$config_timestamp, Smarty $smarty) +function configHandlerFile($resource_type, $resource_name, &$config_source, &$config_timestamp, \Smarty\Smarty $smarty) { if ($resource_name !== 'foo.conf') { return 'no.conf'; @@ -160,7 +162,7 @@ function configHandlerFile($resource_type, $resource_name, &$config_source, &$co * * @return bool */ -function configHandlerFalse($resource_type, $resource_name, &$config_source, &$config_timestamp, Smarty $smarty) +function configHandlerFalse($resource_type, $resource_name, &$config_source, &$config_timestamp, \Smarty\Smarty $smarty) { return false; } diff --git a/tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php b/tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php index b4a75439..d555df72 100644 --- a/tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php +++ b/tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of config variables * - * @package PHPunit + * @author Uwe Tews */ /** * class for config variable tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class ConfigVarTest extends PHPUnit_Smarty { @@ -43,9 +43,6 @@ class ConfigVarTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled - * * test string config variable */ public function testConfigText() @@ -55,9 +52,6 @@ class ConfigVarTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled - * * test line string config variable */ public function testConfigLine() @@ -67,9 +61,6 @@ class ConfigVarTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled - * * test config variables in global sections */ public function testConfigVariableGlobalSections() @@ -79,9 +70,6 @@ class ConfigVarTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled - * * test config variables loading section2 */ public function testConfigVariableSection2() @@ -91,9 +79,6 @@ class ConfigVarTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled - * * test config variables loading section special char */ public function testConfigVariableSectionSpecialChar() @@ -103,9 +88,6 @@ class ConfigVarTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled - * * test config variables loading section foo/bar */ public function testConfigVariableSectionFooBar() @@ -115,9 +97,6 @@ class ConfigVarTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled - * * test config variables loaded in different scopes from different sections (Smarty and template) */ public function testConfigDifferentScope() @@ -132,9 +111,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test config variables of hidden sections * shall display variables from hidden section - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigVariableHidden() { @@ -146,9 +122,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test config variables of disabled hidden sections * shall display not variables from hidden section - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigVariableHiddenDisable() { @@ -160,9 +133,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test getConfigVars - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigGetSingleConfigVar() { @@ -172,9 +142,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test getConfigVars return all variables - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigGetAllConfigVars() { @@ -187,9 +154,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test clearConfig for single variable - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigClearSingleConfigVar() { @@ -200,9 +164,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test clearConfig for all variables - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigClearConfigAll() { @@ -215,22 +176,17 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test config vars on data object - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigTextData() { $data = $this->smarty->createData(); $data->configLoad('test.conf'); - $this->assertEquals("123bvc", $this->smarty->fetch('text.tpl', $data)); + $tpl = $this->smarty->createTemplate('text.tpl', $data); + $this->assertEquals("123bvc", $this->smarty->fetch($tpl)); } /** * test getConfigVars on data object - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigGetSingleConfigVarData() { @@ -241,9 +197,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test getConfigVars return all variables on data object - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigGetAllConfigVarsData() { @@ -257,9 +210,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test clearConfig for single variable on data object - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigClearSingleConfigVarData() { @@ -272,9 +222,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test clearConfig for all variables on data object - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigClearConfigAllData() { @@ -288,9 +235,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test config vars on template object - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigTextTemplate() { @@ -301,9 +245,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test getConfigVars on template object - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigGetSingleConfigVarTemplate() { @@ -314,9 +255,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test getConfigVariable on template object - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigGetSingleConfigVarTemplate2() { @@ -327,9 +265,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test getConfigVars return all variables on template object - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigGetAllConfigVarsTemplate() { @@ -343,9 +278,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test clearConfig for single variable on template object - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigClearSingleConfigVarTemplate() { @@ -358,9 +290,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test clearConfig for all variables on template object - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigClearConfigAllTemplate() { @@ -374,9 +303,6 @@ class ConfigVarTest extends PHPUnit_Smarty /** * test config variables loading from absolute file path - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testConfigAbsolutePath() { @@ -387,7 +313,7 @@ class ConfigVarTest extends PHPUnit_Smarty public function testConfigResourceDb4() { - $this->smarty->addPluginsDir(__DIR__ . "/PHPunitplugins/"); + $this->smarty->addPluginsDir(__DIR__ . "/../../ResourceTests/ResourcePlugins/PHPunitplugins/"); $this->smarty->configLoad('db4:foo.conf'); $this->assertEquals("bar", $this->smarty->fetch('foo.tpl')); } diff --git a/tests/UnitTests/ConfigFileTests/file/PHPunitplugins/resource.db4.php b/tests/UnitTests/ConfigFileTests/file/PHPunitplugins/resource.db4.php deleted file mode 100644 index 920c349a..00000000 --- a/tests/UnitTests/ConfigFileTests/file/PHPunitplugins/resource.db4.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -/* - * Smarty plugin - * ------------------------------------------------------------- - * File: resource.db3.php - * Type: resource - * Name: db - * Purpose: Fetches templates from a database - * ------------------------------------------------------------- - */ - -class Smarty_Resource_Db4 extends Smarty_Resource -{ - public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) - { - $source->filepath = 'db4:'; - $source->uid = sha1($source->resource); - $source->timestamp = 0; - $source->exists = true; - } - - public function getContent(Smarty_Template_Source $source) - { - return "foo = 'bar'\n"; - } -} diff --git a/tests/UnitTests/ResourceTests/Custom/Ambiguous/CustomResourceAmbiguousTest.php b/tests/UnitTests/ResourceTests/Custom/Ambiguous/CustomResourceAmbiguousTest.php index 326dbfc2..610d8de3 100644 --- a/tests/UnitTests/ResourceTests/Custom/Ambiguous/CustomResourceAmbiguousTest.php +++ b/tests/UnitTests/ResourceTests/Custom/Ambiguous/CustomResourceAmbiguousTest.php @@ -2,16 +2,12 @@ /** * Smarty PHPunit tests for File resources * - * @package PHPunit + * @author Uwe Tews */ /** * class for file resource tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled */ class CustomResourceAmbiguousTest extends PHPUnit_Smarty { @@ -46,76 +42,59 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty public function testNone() { - $resource_handler = new Smarty_Resource_Ambiguous(__DIR__ . '/templates/ambiguous/'); + $resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/'); $this->smarty->registerResource('ambiguous', $resource_handler); $this->smarty->setDefaultResourceType('ambiguous'); - $this->smarty->setAllowAmbiguousResources(true); +// $this->smarty->setAllowAmbiguousResources(true); $tpl = $this->smarty->createTemplate('foobar.tpl'); - $this->assertFalse($tpl->source->exists); + $this->assertFalse($tpl->getSource()->exists); } - /** - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * - */ public function testCase1() { - $resource_handler = new Smarty_Resource_Ambiguous(__DIR__ . '/templates/ambiguous/'); + $resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/'); $this->smarty->registerResource('ambiguous', $resource_handler); $this->smarty->setDefaultResourceType('ambiguous'); - $this->smarty->setAllowAmbiguousResources(true); +// $this->smarty->setAllowAmbiguousResources(true); $resource_handler->setSegment('case1'); $tpl = $this->smarty->createTemplate('foobar.tpl'); - $this->assertTrue($tpl->source->exists); - $this->assertEquals('case1', $tpl->source->getContent()); + $this->assertTrue($tpl->getSource()->exists); + $this->assertEquals('case1', $tpl->getSource()->getContent()); } - /** - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * - */ public function testCase2() { - $resource_handler = new Smarty_Resource_Ambiguous(__DIR__ . '/templates/ambiguous/'); + $resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/'); $this->smarty->registerResource('ambiguous', $resource_handler); $this->smarty->setDefaultResourceType('ambiguous'); - $this->smarty->setAllowAmbiguousResources(true); +// $this->smarty->setAllowAmbiguousResources(true); $resource_handler->setSegment('case2'); $tpl = $this->smarty->createTemplate('foobar.tpl'); - $this->assertTrue($tpl->source->exists); - $this->assertEquals('case2', $tpl->source->getContent()); + $this->assertTrue($tpl->getSource()->exists); + $this->assertEquals('case2', $tpl->getSource()->getContent()); } - /** - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * - */ + public function testCaseSwitching() { - $resource_handler = new Smarty_Resource_Ambiguous(__DIR__ . '/templates/ambiguous/'); + $resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/'); $this->smarty->registerResource('ambiguous', $resource_handler); $this->smarty->setDefaultResourceType('ambiguous'); - $this->smarty->setAllowAmbiguousResources(true); +// $this->smarty->setAllowAmbiguousResources(true); $resource_handler->setSegment('case1'); $tpl = $this->smarty->createTemplate('foobar.tpl'); - $this->assertTrue($tpl->source->exists); - $this->assertEquals('case1', $tpl->source->getContent()); + $this->assertTrue($tpl->getSource()->exists); + $this->assertEquals('case1', $tpl->getSource()->getContent()); $resource_handler->setSegment('case2'); $tpl = $this->smarty->createTemplate('foobar.tpl'); - $this->assertTrue($tpl->source->exists); - $this->assertEquals('case2', $tpl->source->getContent()); + $this->assertTrue($tpl->getSource()->exists); + $this->assertEquals('case2', $tpl->getSource()->getContent()); } } diff --git a/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php b/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php index 934b8aa0..85ffadd5 100644 --- a/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php +++ b/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php @@ -1,12 +1,18 @@ <?php +use Smarty\Exception; +use Smarty\Resource\FilePlugin; +use Smarty\Smarty; +use Smarty\Template; +use Smarty\Template\Source; + /** * Ambiguous Filename Custom Resource Example * - * @package Resource-examples + * @author Rodney Rehm */ -class Smarty_Resource_Ambiguous extends Smarty_Internal_Resource_File +class Smarty_Resource_AmbiguousPlugin extends FilePlugin { protected $directory; protected $segment; @@ -23,36 +29,38 @@ class Smarty_Resource_Ambiguous extends Smarty_Internal_Resource_File } /** - * modify resource_name according to resource handlers specifications - * - * @param Smarty $smarty Smarty instance - * @param string $resource_name resource_name to make unique - * - * @return string unique resource name - */ - public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) - { - return get_class($this) . '#' . $this->segment . '#' . $resource_name; - } - - /** * populate Source Object with meta data from Resource * - * @param Smarty_Template_Source $source source object - * @param Smarty_Internal_Template $_template template object + * @param Source $source source object + * @param Template $_template template object */ - public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) + public function populate(Source $source, Template $_template = null) { $segment = ''; if ($this->segment) { $segment = rtrim($this->segment, "/\\") . DIRECTORY_SEPARATOR; } - $source->filepath = $this->directory . $segment . $source->name; - $source->uid = sha1($source->filepath); - if ($_template->smarty->getCompileCheck() && !isset($source->timestamp)) { - $source->timestamp = @filemtime($source->filepath); + $source->uid = sha1($segment . '#' . $source->getResourceName()); + if ($_template->getSmarty()->getCompileCheck() && !isset($source->timestamp)) { + $source->timestamp = @filemtime($this->directory . $segment . $source->name); $source->exists = !!$source->timestamp; } } + + public function getContent(Source $source) { + + $segment = ''; + if ($this->segment) { + $segment = rtrim($this->segment, "/\\") . DIRECTORY_SEPARATOR; + } + + if ($source->exists) { + return file_get_contents($this->directory . $segment . $source->name); + } + throw new Exception( + 'Unable to read ' . ($source->isConfig ? 'config' : 'template') . + " {$source->type} '{$source->name}'" + ); + } } diff --git a/tests/UnitTests/ResourceTests/Custom/DemoPluginExtendsAll/ResourceExtendsAllPluginTest.php b/tests/UnitTests/ResourceTests/Custom/DemoPluginExtendsAll/ResourceExtendsAllPluginTest.php index 5e81a8c3..0cbbfce0 100644 --- a/tests/UnitTests/ResourceTests/Custom/DemoPluginExtendsAll/ResourceExtendsAllPluginTest.php +++ b/tests/UnitTests/ResourceTests/Custom/DemoPluginExtendsAll/ResourceExtendsAllPluginTest.php @@ -2,16 +2,18 @@ /** * Smarty PHPUnit tests demo resource plugin extendsall * - * @package PHPunit + * @author Uwe Tews */ +require_once __DIR__ . '/../../../__shared/resources/resource.extendsall.php'; + /** * class for demo resource plugin extendsall tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty { @@ -27,13 +29,10 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty /** * test extendsall - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testResourcePluginExtendsall() { - $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/"); + $this->smarty->registerResource('extendsall', new My_Resource_Extendsall()); $this->smarty->setTemplateDir(array('root' => './templates', './templates_2', './templates_3', './templates_4',)); @@ -44,15 +43,12 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty /** * test extendsall * changed tepmplate_setting - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testResourcePluginExtendsall2() { - $this->smarty->setMergeCompiledIncludes(true); - $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/"); + $this->smarty->registerResource('extendsall', new My_Resource_Extendsall()); + $this->smarty->setMergeCompiledIncludes(true); $this->smarty->setTemplateDir(array('./templates_3', './templates_4',)); $expected = "templates_3templates_3templates_3templates_4"; @@ -61,7 +57,7 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty public function testResourcePluginExtendsallOne() { - $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/"); + $this->smarty->registerResource('extendsall', new My_Resource_Extendsall()); $this->smarty->setTemplateDir(array('root' => './templates', './templates_2', './templates_3', './templates_4',)); @@ -71,13 +67,10 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty /** * test extendsall special application - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testResourcePluginExtendsallSpecialApplication() { - $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/"); + $this->smarty->registerResource('extendsall', new My_Resource_Extendsall()); $this->smarty->setTemplateDir(array('./templates_2', './templates_1',)); $this->smarty->setDefaultResourceType('extendsall'); $this->assertEquals('<p>data1 from templates1</p><p>data1 from templates2</p><p>data2 from templates1</p>', @@ -86,13 +79,10 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty /** * test extendsall special application - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testResourcePluginExtendsallSpecialApplication2() { - $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/"); + $this->smarty->registerResource('extendsall', new My_Resource_Extendsall()); $this->smarty->setTemplateDir(array('./templates_3', './templates_2', './templates_1',)); $this->smarty->setDefaultResourceType('extendsall'); $this->assertEquals('<p>data1 from templates1</p><p>data1 from templates3</p><p>data1 from templates2</p><p>data2 from templates1</p>', @@ -101,14 +91,11 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty /** * test extendsall special application - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testResourcePluginExtendsallSpecialApplication3() { $this->smarty->setMergeCompiledIncludes(true); - $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/"); + $this->smarty->registerResource('extendsall', new My_Resource_Extendsall()); $this->smarty->setTemplateDir(array('./templates_2', './templates_1',)); $this->smarty->setDefaultResourceType('extendsall'); $this->assertEquals('<p>data1 from templates1</p><p>data1 from templates2</p><p>data2 from templates1</p>', @@ -117,14 +104,11 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty /** * test extendsall special application - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testResourcePluginExtendsallSpecialApplication4() { $this->smarty->setMergeCompiledIncludes(true); - $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/"); + $this->smarty->registerResource('extendsall', new My_Resource_Extendsall()); $this->smarty->setTemplateDir(array('./templates_2', './templates_1',)); $this->smarty->setDefaultResourceType('extendsall'); $this->assertEquals('<p>data1 from templates1</p><p>data1 from templates2</p><p>data2 from templates1</p>', @@ -133,14 +117,11 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty /** * test extendsall special application - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testResourcePluginExtendsallSpecialApplication5() { $this->smarty->setMergeCompiledIncludes(true); - $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/"); + $this->smarty->registerResource('extendsall', new My_Resource_Extendsall()); $this->smarty->setTemplateDir(array('./templates_3', './templates_2', './templates_1',)); $this->smarty->setDefaultResourceType('extendsall'); $this->assertEquals('<p>data1 from templates1</p><p>data1 from templates3</p><p>data1 from templates2</p><p>data2 from templates1</p>', @@ -149,14 +130,11 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty /** * test extendsall special application - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testResourcePluginExtendsallSpecialApplication6() { $this->smarty->setMergeCompiledIncludes(true); - $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/"); + $this->smarty->registerResource('extendsall', new My_Resource_Extendsall()); $this->smarty->setTemplateDir(array('./templates_3', './templates_2', './templates_1',)); $this->smarty->setDefaultResourceType('extendsall'); $this->assertEquals('<p>data1 from templates1</p><p>data1 from templates3</p><p>data1 from templates2</p><p>data2 from templates1</p>', diff --git a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/PHPunitplugins/resource.mysqlstest.php b/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/PHPunitplugins/resource.mysqlstest.php deleted file mode 100644 index f64ab457..00000000 --- a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/PHPunitplugins/resource.mysqlstest.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php -require_once SMARTY_DIR . '../demo/plugins/resource.mysqls.php'; - -class Smarty_Resource_Mysqlstest extends Smarty_Resource_Mysqls -{ - public function __construct() - { - try { - $this->db = PHPUnit_Smarty::$pdo; - } - catch - (PDOException $e) { - throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); - } - $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); - } -} - diff --git a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/PHPunitplugins/resource.mysqltest.php b/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/PHPunitplugins/resource.mysqltest.php deleted file mode 100644 index 2b05da9d..00000000 --- a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/PHPunitplugins/resource.mysqltest.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php -require_once SMARTY_DIR . '../demo/plugins/resource.mysql.php'; - -class Smarty_Resource_Mysqltest extends Smarty_Resource_Mysql -{ - public function __construct() - { - try { - $this->db = PHPUnit_Smarty::$pdo; - } - catch - (PDOException $e) { - throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); - } - $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); - $this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name'); - } -} - diff --git a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php b/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php index 6309eff9..16d85489 100644 --- a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php +++ b/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php @@ -2,20 +2,20 @@ /** * Smarty PHPunit tests resource plugins * - * @package PHPunit + * @author Uwe Tews */ if (MysqlResourceEnable == true) { /** * class for resource plugins tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class ResourceMysqlPluginTest extends PHPUnit_Smarty { - public function setUp() + public function setUp(): void { if (MysqlResourceEnable != true) { $this->markTestSkipped('Msqlresource tests are disabled'); @@ -39,10 +39,6 @@ if (MysqlResourceEnable == true) { /** * test resource plugin rendering of a custom resource - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testResourcePluginMysql() { @@ -51,10 +47,6 @@ if (MysqlResourceEnable == true) { /** * test must compile - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testMustCompile() { @@ -62,12 +54,9 @@ if (MysqlResourceEnable == true) { $this->assertFalse($tpl->mustCompile()); } - /** + /** * test must compile - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * + * @group slow */ public function testMustCompile2() { @@ -79,10 +68,6 @@ if (MysqlResourceEnable == true) { /** * test resource plugin rendering of a custom resource - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testResourcePluginMysql2() { @@ -91,10 +76,6 @@ if (MysqlResourceEnable == true) { /** * test clear compiled - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testClearCompiled() { @@ -103,10 +84,6 @@ if (MysqlResourceEnable == true) { /** * test must compile - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testMustCompile3() { @@ -121,7 +98,7 @@ if (MysqlResourceEnable == true) { { //$this->smarty->addPluginsDir("./PHPunitplugins/"); $tpl = $this->smarty->createTemplate('mysqltest:test.tpl'); - $this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->compiled->filepath); + $this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->getCompiled()->filepath); } public function testResourcePluginMysqlCompiledFilepathCache() @@ -131,20 +108,16 @@ if (MysqlResourceEnable == true) { $this->smarty->setForceCompile(true); $this->smarty->fetch('mysqltest:test.tpl'); $tpl = $this->smarty->createTemplate('mysqltest:test.tpl'); - $this->assertEquals($this->buildCompiledPath($tpl, false, true, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->compiled->filepath); + $this->assertEquals($this->buildCompiledPath($tpl, false, true, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->getCompiled()->filepath); $this->smarty->caching = false; } /** * test unknown template - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testUnknownTemplate() { - $this->expectException('SmartyException'); - $this->expectExceptionMessage('Unable to load template \'mysqlstest:foo.tpl\''); + $this->expectException(\Smarty\Exception::class); + $this->expectExceptionMessage('Unable to load \'mysqlstest:foo.tpl\''); $this->assertEquals('foo', $this->smarty->fetch('mysqlstest:foo.tpl')); } } diff --git a/tests/UnitTests/ResourceTests/DefaultHandler/DefaultTemplateHandlerTest.php b/tests/UnitTests/ResourceTests/DefaultHandler/DefaultTemplateHandlerTest.php index 64c7174b..f2073507 100644 --- a/tests/UnitTests/ResourceTests/DefaultHandler/DefaultTemplateHandlerTest.php +++ b/tests/UnitTests/ResourceTests/DefaultHandler/DefaultTemplateHandlerTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests deault template handler * - * @package PHPunit + * @author Uwe Tews */ /** * class for block plugin tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class DefaultTemplateHandlerTest extends PHPUnit_Smarty { @@ -36,7 +36,7 @@ class DefaultTemplateHandlerTest extends PHPUnit_Smarty $this->smarty->fetch('foo.tpl'); } catch (Exception $e) { - $this->assertStringContainsString('Unable to load template', $e->getMessage()); + $this->assertStringContainsString('Unable to load', $e->getMessage()); return; } @@ -93,7 +93,7 @@ class DefaultTemplateHandlerTest extends PHPUnit_Smarty } } -function my_template_handler($resource_type, $resource_name, &$template_source, &$template_timestamp, Smarty $smarty) +function my_template_handler($resource_type, $resource_name, &$template_source, &$template_timestamp, \Smarty\Smarty $smarty) { $output = "Recsource $resource_name of type $resource_type not found"; $template_source = $output; @@ -102,12 +102,12 @@ function my_template_handler($resource_type, $resource_name, &$template_source, return true; } -function my_template_handler_file($resource_type, $resource_name, &$template_source, &$template_timestamp, Smarty $smarty) +function my_template_handler_file($resource_type, $resource_name, &$template_source, &$template_timestamp, \Smarty\Smarty $smarty) { return $smarty->getTemplateDir(0) . 'helloworld.tpl'; } -function my_false($resource_type, $resource_name, &$template_source, &$template_timestamp, Smarty $smarty) +function my_false($resource_type, $resource_name, &$template_source, &$template_timestamp, \Smarty\Smarty $smarty) { return false; } diff --git a/tests/UnitTests/ResourceTests/Eval/EvalResourceTest.php b/tests/UnitTests/ResourceTests/Eval/EvalResourceTest.php index d8cd146d..f4bad162 100644 --- a/tests/UnitTests/ResourceTests/Eval/EvalResourceTest.php +++ b/tests/UnitTests/ResourceTests/Eval/EvalResourceTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests for eval resources * - * @package PHPunit + * @author Uwe Tews */ /** * class for eval resource tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class EvalResourceTest extends PHPUnit_Smarty { @@ -31,7 +31,7 @@ class EvalResourceTest extends PHPUnit_Smarty public function testTemplateEvalExists1() { $tpl = $this->smarty->createTemplate('eval:{$foo}'); - $this->assertTrue($tpl->source->exists); + $this->assertTrue($tpl->getSource()->exists); } public function testTemplateEvalExists2() @@ -39,22 +39,16 @@ class EvalResourceTest extends PHPUnit_Smarty $this->assertTrue($this->smarty->templateExists('eval:{$foo}')); } - /** - * test getTemplateFilepath - */ - public function testGetTemplateFilepath() + public function testGetTemplateResourceName() { $tpl = $this->smarty->createTemplate('eval:hello world'); - $this->assertEquals('2aae6c35c94fcfb415dbe95f408b9ce91ee846ed', $tpl->source->filepath); + $this->assertEquals('hello world', $tpl->getSource()->getResourceName()); } - /** - * test getTemplateTimestamp - */ public function testGetTemplateTimestamp() { $tpl = $this->smarty->createTemplate('eval:hello world'); - $this->assertTrue($tpl->source->getTimeStamp()); + $this->assertTrue($tpl->getSource()->getTimeStamp()); } /** @@ -63,7 +57,7 @@ class EvalResourceTest extends PHPUnit_Smarty public function testGetTemplateSource() { $tpl = $this->smarty->createTemplate('eval:hello world{$foo}'); - $this->assertEquals('hello world{$foo}', $tpl->source->getContent()); + $this->assertEquals('hello world{$foo}', $tpl->getSource()->getContent()); } /** @@ -81,7 +75,7 @@ class EvalResourceTest extends PHPUnit_Smarty public function testUsesCompiler() { $tpl = $this->smarty->createTemplate('eval:hello world'); - $this->assertFalse($tpl->source->handler->uncompiled); + $this->markTestIncomplete(); } /** @@ -90,7 +84,7 @@ class EvalResourceTest extends PHPUnit_Smarty public function testIsEvaluated() { $tpl = $this->smarty->createTemplate('eval:hello world'); - $this->assertTrue($tpl->source->handler->recompiled); + $this->assertTrue($tpl->getSource()->handler->recompiled); } /** @@ -108,7 +102,7 @@ class EvalResourceTest extends PHPUnit_Smarty public function testGetCompiledFilepath() { $tpl = $this->smarty->createTemplate('eval:hello world'); - $this->assertFalse($tpl->compiled->filepath); + $this->assertNull($tpl->getCompiled()->filepath); } /** @@ -117,7 +111,7 @@ class EvalResourceTest extends PHPUnit_Smarty public function testGetCompiledTimestamp() { $tpl = $this->smarty->createTemplate('eval:hello world'); - $this->assertFalse($tpl->compiled->getTimeStamp()); + $this->assertFalse($tpl->getCompiled()->getTimeStamp()); } /** diff --git a/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php b/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php index e3816d12..2ef17719 100644 --- a/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php +++ b/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php @@ -2,16 +2,14 @@ /** * Smarty PHPunit tests for Extendsresource * - * @package PHPunit + * @author Uwe Tews */ +use Smarty\Template; + /** * class for extends resource tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled */ class ExtendsResourceTest extends PHPUnit_Smarty { @@ -27,15 +25,13 @@ class ExtendsResourceTest extends PHPUnit_Smarty $this->cleanDirs(); } - public function compiledPrefilter($text, Smarty_Internal_Template $tpl) + public function compiledPrefilter($text, Template $tpl) { return str_replace('#', $tpl->getTemplateVars('test'), $text); } /** * test child/parent template chain with prepend - * @runInSeparateProcess - * @preserveGlobalState disabled * @dataProvider data */ public function testCompileBlockChildPrepend_003($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName) @@ -45,16 +41,20 @@ class ExtendsResourceTest extends PHPUnit_Smarty $this->smarty->caching = $caching; $this->smarty->merge_compiled_includes = $merge; if ($merge) { - $this->smarty->compile_id = 1; + $this->smarty->setCompileId(1); } $result = $this->smarty->fetch('extends:003_parent.tpl|003_child_prepend.tpl'); - $this->assertStringContainsString("prepend - Default Title", $result, $testName . ' - content'); - $this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure'); + $this->assertStringContainsString( + "prepend - Default Title", $result, $testName . ' - content'); + $this->assertStringContainsString( + "test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", + $result, + $testName . ' - fetch() failure' + ); } + /** * test child/parent template chain with apppend - * @run InSeparateProcess - * @preserveGlobalState disabled * @dataProvider data */ public function testCompileBlockChildAppend_004($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName) @@ -64,7 +64,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty $this->smarty->caching = $caching; $this->smarty->merge_compiled_includes = $merge; if ($merge) { - $this->smarty->compile_id = 1; + $this->smarty->setCompileId(1); } $result = $this->smarty->fetch('extends:004_parent.tpl|004_child_append.tpl'); $this->assertStringContainsString("Default Title - append", $result, $testName . ' - content'); @@ -73,8 +73,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty /** * test child/parent template chain with apppend - * @runInSeparateProcess - * @preserveGlobalState disabled * @dataProvider data */ public function testCompileBlockAssignInChild_040($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName) @@ -84,7 +82,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty $this->smarty->caching = $caching; $this->smarty->merge_compiled_includes = $merge; if ($merge) { - $this->smarty->compile_id = 1; + $this->smarty->setCompileId(1); } $result = $this->smarty->fetch('extends:040_parent.tpl|040_child.tpl'); $this->assertStringContainsString("var-bar-var", $result, $testName . ' - content'); @@ -101,7 +99,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty $this->smarty->caching = $caching; $this->smarty->merge_compiled_includes = $merge; if ($merge) { - $this->smarty->compile_id = 1; + $this->smarty->setCompileId(1); } $result = $this->smarty->fetch('extends:050_parent.tpl|050_child.tpl|050_grandchild.tpl'); $this->assertStringContainsString("var-bar-var", $result, $testName . ' - content'); @@ -110,8 +108,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty /** * test grandchild/child/parent dependency test1 - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testCompileBlockGrandChildMustCompile_021_1() { @@ -125,8 +121,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty /** * test grandchild/child/parent dependency test1 - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testCompileBlockGrandChildMustCompile_021_12() { @@ -140,8 +134,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty /** * test grandchild/child/parent dependency test2 - * @runInSeparateProcess - * @preserveGlobalState disabled * @group slow */ public function testCompileBlockGrandChildMustCompile_021_2() @@ -158,9 +150,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty } /** * test grandchild/child/parent dependency test2 - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testCompileBlockGrandChildMustCompile_021_22() { @@ -174,9 +163,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty /** * test grandchild/child/parent dependency test3 - * @runInSeparateProcess - * @preserveGlobalState disabled - * + * @group slow */ public function testCompileBlockGrandChildMustCompile_021_3() { @@ -192,9 +179,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty } /** * test grandchild/child/parent dependency test3 - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testCompileBlockGrandChildMustCompile_021_32() { @@ -208,8 +192,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty /** * test grandchild/child/parent dependency test4 - * @runInSeparateProcess - * @preserveGlobalState disabled * @group slow */ public function testCompileBlockGrandChildMustCompile_021_4() @@ -226,9 +208,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty } /** * test grandchild/child/parent dependency test4 - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testCompileBlockGrandChildMustCompile_021_42() { @@ -242,9 +221,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty /** * test relative includes in {block} - * - * @runInSeparateProcess - * @preserveGlobalState disabled * @dataProvider data */ public function testCompileBlockRelativeIncludes_033($caching, $merge, $testNumber, $compileTestNumber, @@ -276,7 +252,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty */ array(false, false, 1, 1, 1, 'no caching, no merge - new'), array(false, false, 2, 1, 2, 'no caching, no merge - exits'), - array(true, false, 3, 3, 3, 'caching, no merge - new'), // 2 + array(true, false, 3, 3, 3, 'caching, no merge - new'), array(true, false, 4, 3, 3, 'caching, no merge - exits'), array(false, true, 5, 5, 5, 'no caching, merge - new'), array(false, true, 6, 5, 6, 'no caching, merge - exits'), @@ -284,60 +260,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty array(true, true, 8, 7, 7, 'caching, merge - exits'), ); } - /** - * test relative includes in {block} - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider data2 - */ - public function testCompileBlockExtendsRecursion_034($extends_recursion, $merge, $testNumber, $compileTestNumber, - $renderTestNumber, $testName) - { - if (!property_exists($this->smarty, 'extends_recursion')) { - $this->markTestSkipped('no extends_recursion'); - } else { - $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); - $this->smarty->assign('test', $testNumber); - $this->smarty->setExtendsRecursion($extends_recursion); - $this->smarty->setMergeCompiledIncludes($merge); - $cid = 0; - if ($merge) { - $cid = 1; - } - if ($extends_recursion) { - $cid += 2; - } - $this->smarty->setCompileId($cid); - $result = $this->smarty->fetch('extends:034_parent.tpl|034_grandchild.tpl'); - $this->assertStringContainsString('grandchild - grandchild', $result, $testName . ' - grand'); - $this->assertStringContainsString('parent - parent', $result, $testName . ' - grand'); - $this->assertStringContainsString($extends_recursion ? 'child - child' : 'child - parent', $result, - $testName . ' - grand'); - $this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", - $result, $testName . ' - fetch() failure'); - } - } - public function data2(){ - return array( - /* - * extends_recursion - * merging - * test nr - * result compile nr - * result render nr - * text - */ - array(false, false, 1, 1, 1, 'no EXTENDS; no merge - new'), - array(false, false, 2, 1, 2, 'no EXTENDS; no merge - exits'), - array(true, false, 3, 3, 3, 'EXTENDS; no merge - new'), - array(true, false, 4, 3, 4, 'EXTENDS; no merge - exits'), - array(false, true, 5, 5, 5, 'no EXTENDS; merge - new'), - array(false, true, 6, 5, 6, 'no EXTENDS; merge - exits'), - array(true, true, 7, 7, 7, 'EXTENDS; merge - new'), - array(true, true, 8, 7, 8, 'EXTENDS; merge - exits'), - ); - } } diff --git a/tests/UnitTests/ResourceTests/File/FileResourceTest.php b/tests/UnitTests/ResourceTests/File/FileResourceTest.php index c4e8c069..44201d4b 100644 --- a/tests/UnitTests/ResourceTests/File/FileResourceTest.php +++ b/tests/UnitTests/ResourceTests/File/FileResourceTest.php @@ -2,16 +2,18 @@ /** * Smarty PHPunit tests for File resources * - * @package PHPunit + * @author Uwe Tews */ +use Smarty\Exception; + /** * class for file resource tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class FileResourceTest extends PHPUnit_Smarty { @@ -36,16 +38,16 @@ class FileResourceTest extends PHPUnit_Smarty /** * */ - public function testGetTemplateFilepath() + public function testGetTemplateResourceName() { $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertEquals($this->normalizePath("./templates/helloworld.tpl"), $tpl->source->filepath); + $this->assertEquals('helloworld.tpl', $tpl->getSource()->getResourceName()); } public function testTemplateFileExists1() { $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertTrue($tpl->source->exists); + $this->assertTrue($tpl->getSource()->exists); } public function testTemplateFileExists2() @@ -56,7 +58,7 @@ class FileResourceTest extends PHPUnit_Smarty public function testTemplateFileNotExists1() { $tpl = $this->smarty->createTemplate('notthere.tpl'); - $this->assertFalse($tpl->source->exists); + $this->assertFalse($tpl->getSource()->exists); } public function testTemplateFileNotExists2() @@ -69,7 +71,7 @@ class FileResourceTest extends PHPUnit_Smarty */ public function testTemplateFileNotExists3() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('Unable to'); $this->expectExceptionMessage('notthere.tpl'); $this->smarty->fetch('notthere.tpl'); @@ -78,34 +80,26 @@ class FileResourceTest extends PHPUnit_Smarty public function testGetTemplateTimestamp() { $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertTrue(is_integer($tpl->source->getTimeStamp())); - $this->assertEquals(10, strlen($tpl->source->getTimeStamp())); + $this->assertTrue(is_integer($tpl->getSource()->getTimeStamp())); + $this->assertEquals(10, strlen($tpl->getSource()->getTimeStamp())); } public function testGetTemplateSource() { $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertEquals('hello world', $tpl->source->getContent()); + $this->assertEquals('hello world', $tpl->getSource()->getContent()); } public function testUsesCompiler() { $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertFalse($tpl->source->handler->uncompiled); + $this->markTestIncomplete(); } public function testIsEvaluated() { $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertFalse($tpl->source->handler->recompiled); - } - - public function testGetCompiledFilepath() - { - $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'helloworld.tpl', 'file', $this->smarty->getTemplateDir(0)) - , $tpl->compiled->filepath - ); + $this->assertFalse($tpl->getSource()->handler->recompiled); } /** @@ -115,8 +109,8 @@ class FileResourceTest extends PHPUnit_Smarty { $tpl = $this->smarty->createTemplate('helloworld.tpl'); // create dummy compiled file - file_put_contents($tpl->compiled->filepath, '<?php ?>'); - touch($tpl->compiled->filepath, $tpl->source->getTimeStamp()); + file_put_contents($tpl->getCompiled()->filepath, '<?php ?>'); + touch($tpl->getCompiled()->filepath, $tpl->getSource()->getTimeStamp()); } /** @@ -125,9 +119,9 @@ class FileResourceTest extends PHPUnit_Smarty public function testGetCompiledTimestamp() { $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertTrue(is_integer($tpl->compiled->getTimeStamp())); - $this->assertEquals(10, strlen($tpl->compiled->getTimeStamp())); - $this->assertEquals($tpl->compiled->getTimeStamp(), $tpl->source->getTimeStamp()); + $this->assertTrue(is_integer($tpl->getCompiled()->getTimeStamp())); + $this->assertEquals(10, strlen($tpl->getCompiled()->getTimeStamp())); + $this->assertEquals($tpl->getCompiled()->getTimeStamp(), $tpl->getSource()->getTimeStamp()); } public function testMustCompileExisting() @@ -143,18 +137,18 @@ class FileResourceTest extends PHPUnit_Smarty $this->assertTrue($tpl->mustCompile()); } - /** - * @doesNotPerformAssertions - */ - public function testMustCompileTouchedSourcePrepare() - { - // touch to prepare next test - sleep(2); - $tpl = $this->smarty->createTemplate('helloworld.tpl'); - touch($tpl->source->filepath); - } - public function testMustCompileTouchedSource() + /** + * @group slow + */ + public function testMustCompileTouchedSource() { + // touch to prepare next test + sleep(2); + $this->smarty->createTemplate('helloworld.tpl'); + touch(__DIR__ . '/templates/helloworld.tpl'); + + $this->setUp(); + $tpl = $this->smarty->createTemplate('helloworld.tpl'); $this->assertTrue($tpl->mustCompile()); // clean up for next tests @@ -165,29 +159,26 @@ class FileResourceTest extends PHPUnit_Smarty { $tpl = $this->smarty->createTemplate('helloworld.tpl'); $tpl->compileTemplateSource(); - $this->assertTrue(file_exists($tpl->compiled->filepath)); - } - - public function testGetCachedFilepath() - { - $this->smarty->caching = true; - $this->smarty->cache_lifetime = 1000; - $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertEquals($this->buildCachedPath($tpl, false, null, null, 'helloworld.tpl', 'file', $this->smarty->getTemplateDir(0), 'file') - , $tpl->cached->filepath - ); + $this->assertTrue(file_exists($tpl->getCompiled()->filepath)); } public function testGetCachedTimestamp() { // create dummy cache file for the following test - file_put_contents($this->buildCachedPath($this->smarty, false, null, null, 'helloworld.tpl', 'file', $this->smarty->getTemplateDir(0), 'file') - , '<?php ?>'); - $this->smarty->caching = true; - $this->smarty->cache_lifetime = 1000; + $this->smarty->caching = true; + $this->smarty->cache_lifetime = 1000; + $tpl = $this->smarty->createTemplate('helloworld.tpl'); + $tpl->fetch(); + $timestamp = $tpl->getCached()->timestamp; + + + $this->smarty = new \Smarty\Smarty(); + $this->smarty->caching = true; + $this->smarty->cache_lifetime = 1000; + $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertTrue(is_integer($tpl->cached->timestamp)); - $this->assertEquals(10, strlen($tpl->cached->timestamp)); + $this->assertTrue(is_integer($tpl->getCached()->timestamp)); + $this->assertEquals($timestamp, $tpl->getCached()->timestamp); } @@ -206,7 +197,7 @@ class FileResourceTest extends PHPUnit_Smarty /** * * @run InSeparateProcess - * @preserveGlobalState disabled + * * */ public function testRelativeIncludeSub() @@ -215,26 +206,23 @@ class FileResourceTest extends PHPUnit_Smarty $this->assertStringContainsString('hello world', $result); } /** - * @runInSeparateProcess - * @preserveGlobalState disabled - * * test relative include fail */ public function testRelativeIncludeFail() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('Unable to'); $this->smarty->fetch('relative_sub.tpl'); } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * * test relative include fail other dir */ public function testRelativeIncludeFailOtherDir() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('./hello.tpl'); $this->smarty->addTemplateDir('./templates_2'); $this->smarty->fetch('relative_notexist.tpl'); @@ -242,8 +230,8 @@ class FileResourceTest extends PHPUnit_Smarty /** * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testRelativeFetch() @@ -258,8 +246,8 @@ class FileResourceTest extends PHPUnit_Smarty /** * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testRelativeFetch2() @@ -274,8 +262,8 @@ class FileResourceTest extends PHPUnit_Smarty /** * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testRelativeFetchCwd() @@ -295,8 +283,8 @@ class FileResourceTest extends PHPUnit_Smarty /** * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testRelativeFetchCwd2() @@ -331,7 +319,7 @@ class FileResourceTest extends PHPUnit_Smarty return; } - catch (SmartyException $e) { + catch (Exception $e) { // this was expected to fail } } else { diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/FileIncludePathTest.php b/tests/UnitTests/ResourceTests/FileIncludePath/FileIncludePathTest.php deleted file mode 100644 index 1447ef09..00000000 --- a/tests/UnitTests/ResourceTests/FileIncludePath/FileIncludePathTest.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php - -/** - * Smarty PHPunit tests for File resources - * - * @package PHPunit - * @author Rodney Rehm - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class FileIncludePathTest extends PHPUnit_Smarty -{ - public function setUp(): void - { - $this->setUpSmarty(__DIR__); - $this->smarty->use_include_path = true; - $this->smarty->setTemplateDir(array('./templates', './templates_2', './include')); - $this->smarty->enableSecurity(); - $ds = DIRECTORY_SEPARATOR; - set_include_path($this->smarty->_realpath(__DIR__ . "{$ds}..{$ds}..{$ds}..{$ds}Include_Path{$ds}Tpl{$ds}", true) . PATH_SEPARATOR . get_include_path()); - } - - /** - * Tears down the fixture - * This method is called after a test is executed. - * - */ - protected function tearDown(): void - { - ini_restore('include_path'); - $this->smarty->disableSecurity(); - parent::tearDown(); - } - public function testInit() - { - $this->cleanDirs(); - } - public function testInclude1() - { - $this->assertStringContainsString('include_test1', $this->smarty->fetch('test1.tpl')); - } - public function testInclude2() - { - $this->assertStringContainsString('include_test2', $this->smarty->fetch('test2.tpl')); - } - public function testInclude3() - { - $this->assertStringContainsString('include_test3', $this->smarty->fetch('test3.tpl')); - } - public function testInclude31() - { - $this->smarty->use_include_path = false; - $this->smarty->security_policy->secure_dir = getcwd(); - $this->assertStringContainsString('include_test3', $this->smarty->fetch('test3.tpl')); - } - public function testInclude4() - { - $this->assertStringContainsString('include_test4', $this->smarty->fetch('test4.tpl')); - } - public function testInclude5() - { - $this->smarty->setTemplateDir(array('./')); - $this->assertStringContainsString('include path root', $this->smarty->fetch('test5.tpl')); - } - - } diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/cache/.gitignore b/tests/UnitTests/ResourceTests/FileIncludePath/cache/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/ResourceTests/FileIncludePath/cache/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/include_test3.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/include_test3.tpl deleted file mode 100644 index 61298afb..00000000 --- a/tests/UnitTests/ResourceTests/FileIncludePath/include_test3.tpl +++ /dev/null @@ -1 +0,0 @@ -include_test3 diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates/dirname.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates/dirname.tpl deleted file mode 100644 index f10e14ab..00000000 --- a/tests/UnitTests/ResourceTests/FileIncludePath/templates/dirname.tpl +++ /dev/null @@ -1 +0,0 @@ -templates
\ No newline at end of file diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates/test1.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates/test1.tpl deleted file mode 100644 index dcc96887..00000000 --- a/tests/UnitTests/ResourceTests/FileIncludePath/templates/test1.tpl +++ /dev/null @@ -1 +0,0 @@ -{include 'include_test1.tpl'}
\ No newline at end of file diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates/test2.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates/test2.tpl deleted file mode 100644 index b5d41850..00000000 --- a/tests/UnitTests/ResourceTests/FileIncludePath/templates/test2.tpl +++ /dev/null @@ -1 +0,0 @@ -{include 'include_test2.tpl'}
\ No newline at end of file diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates/test3.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates/test3.tpl deleted file mode 100644 index 5d5690be..00000000 --- a/tests/UnitTests/ResourceTests/FileIncludePath/templates/test3.tpl +++ /dev/null @@ -1 +0,0 @@ -{include 'include_test3.tpl'}
\ No newline at end of file diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates_2/dirname.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates_2/dirname.tpl deleted file mode 100644 index b6e9ce55..00000000 --- a/tests/UnitTests/ResourceTests/FileIncludePath/templates_2/dirname.tpl +++ /dev/null @@ -1 +0,0 @@ -templates_2
\ No newline at end of file diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates_2/include_test1.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates_2/include_test1.tpl deleted file mode 100644 index c8d49087..00000000 --- a/tests/UnitTests/ResourceTests/FileIncludePath/templates_2/include_test1.tpl +++ /dev/null @@ -1 +0,0 @@ -include_test1 diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates_3/dirname.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates_3/dirname.tpl deleted file mode 100644 index 404b4397..00000000 --- a/tests/UnitTests/ResourceTests/FileIncludePath/templates_3/dirname.tpl +++ /dev/null @@ -1 +0,0 @@ -templates_3
\ No newline at end of file diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates_4/dirname.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates_4/dirname.tpl deleted file mode 100644 index b744ef31..00000000 --- a/tests/UnitTests/ResourceTests/FileIncludePath/templates_4/dirname.tpl +++ /dev/null @@ -1 +0,0 @@ -templates_4
\ No newline at end of file diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates_c/.gitignore b/tests/UnitTests/ResourceTests/FileIncludePath/templates_c/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/ResourceTests/FileIncludePath/templates_c/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/ResourceTests/FileIndexed/FileResourceIndexedTest.php b/tests/UnitTests/ResourceTests/FileIndexed/FileResourceIndexedTest.php index 5f8ed76f..9065c10d 100644 --- a/tests/UnitTests/ResourceTests/FileIndexed/FileResourceIndexedTest.php +++ b/tests/UnitTests/ResourceTests/FileIndexed/FileResourceIndexedTest.php @@ -3,11 +3,11 @@ /** * Smarty PHPunit tests for File resources * - * @package PHPunit + * @author Rodney Rehm - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class FileResourceIndexedTest extends PHPUnit_Smarty { @@ -25,30 +25,6 @@ class FileResourceIndexedTest extends PHPUnit_Smarty $this->cleanDirs(); } - public function testGetTemplateFilepath() - { - $tpl = $this->smarty->createTemplate('dirname.tpl'); - $this->assertEquals($this->normalizePath("./templates/dirname.tpl"), $tpl->source->filepath); - } - - public function testGetTemplateFilepathNumber() - { - $tpl = $this->smarty->createTemplate('[1]dirname.tpl'); - $this->assertEquals($this->normalizePath('./templates_2/dirname.tpl'), $tpl->source->filepath); - } - - public function testGetTemplateFilepathNumeric() - { - $tpl = $this->smarty->createTemplate('[10]dirname.tpl'); - $this->assertEquals($this->normalizePath('./templates_3/dirname.tpl'), $tpl->source->filepath); - } - - public function testGetTemplateFilepathName() - { - $tpl = $this->smarty->createTemplate('[foo]dirname.tpl'); - $this->assertEquals($this->normalizePath('./templates_4/dirname.tpl'), $tpl->source->filepath); - } - public function testFetch() { $tpl = $this->smarty->createTemplate('dirname.tpl'); @@ -101,15 +77,18 @@ class FileResourceIndexedTest extends PHPUnit_Smarty public function testGetCompiledFilepath() { $tpl = $this->smarty->createTemplate('[foo]dirname.tpl'); - $this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'dirname.tpl', 'file', $this->smarty->getTemplateDir('foo')), $tpl->compiled->filepath); + $tpl2 = $this->smarty->createTemplate('dirname.tpl'); + + $this->assertNotEquals($tpl->getCompiled()->filepath, $tpl2->getCompiled()->filepath); } public function testGetCachedFilepath() { $this->smarty->caching = true; $this->smarty->cache_lifetime = 1000; - $tpl = $this->smarty->createTemplate('[foo]dirname.tpl'); - $this->assertEquals($this->buildCachedPath($tpl, false, null, null, 'dirname.tpl', 'file', $this->smarty->getTemplateDir('foo')) - , $tpl->cached->filepath); + $tpl = $this->smarty->createTemplate('[foo]dirname.tpl'); + $tpl2 = $this->smarty->createTemplate('dirname.tpl'); + + $this->assertNotEquals($tpl->getCached()->filepath, $tpl2->getCached()->filepath); } } diff --git a/tests/UnitTests/ResourceTests/Php/PhpResourceTest.php b/tests/UnitTests/ResourceTests/Php/PhpResourceTest.php deleted file mode 100644 index fdb62085..00000000 --- a/tests/UnitTests/ResourceTests/Php/PhpResourceTest.php +++ /dev/null @@ -1,301 +0,0 @@ -<?php -/** - * Smarty PHPunit tests for PHP resources - * - * @package PHPunit - * @author Uwe Tews - */ - -/** - * class for PHP resource tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class PhpResourceTest extends PHPUnit_Smarty -{ - public function setUp(): void - { - $this->setUpSmarty(__DIR__); - } - - public function testInit() - { - $this->cleanDirs(); - } - - protected function relative($path) - { - $path = str_replace(str_replace("\\", "/", __DIR__), '.', str_replace("\\", "/", $path)); - - return $path; - } - - /** - * test getTemplateFilepath - */ - public function testGetTemplateFilepath() - { - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $this->assertEquals($this->normalizePath("./templates/phphelloworld.php"), $tpl->source->filepath); - } - - /** - * test getTemplateTimestamp - */ - public function testGetTemplateTimestamp() - { - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $this->assertTrue(is_integer($tpl->source->getTimeStamp())); - $this->assertEquals(10, strlen($tpl->source->getTimeStamp())); - } - - /** - * test getTemplateSource - *-/ - * public function testGetTemplateSource() - * { - * $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - * $this->assertStringContainsString('php hello world', $tpl->source->getContent()); - * } - * /** - * test usesCompiler - */ - public function testUsesCompiler() - { - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $this->assertTrue($tpl->source->handler->uncompiled); - } - - /** - * test isEvaluated - */ - public function testIsEvaluated() - { - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $this->assertFalse($tpl->source->handler->recompiled); - } - - /** - * test mustCompile - */ - public function testMustCompile() - { - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $this->assertFalse($tpl->mustCompile()); - } - - /** - * test getCachedFilepath - */ - public function testGetCachedFilepath() - { - $this->smarty->setAllowPhpTemplates(true); - $this->smarty->caching = true; - $this->smarty->cache_lifetime = 1000; - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $expected = $this->buildCachedPath($tpl, false, null, null, 'phphelloworld.php', 'php', - $this->smarty->getTemplateDir(0), 'file'); - $this->assertEquals($expected, $tpl->cached->filepath); - } - - /** - * test create cache file used by the following tests - */ - public function testCreateCacheFile() - { - // create dummy cache file - $this->smarty->setAllowPhpTemplates(true); - $this->smarty->caching = true; - $this->smarty->cache_lifetime = 1000; - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $this->assertStringContainsString('php hello world', $this->smarty->fetch($tpl)); - } - - /** - * test getCachedTimestamp caching enabled - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * - */ - public function testGetCachedTimestamp() - { - $this->smarty->setAllowPhpTemplates(true); - $this->smarty->caching = true; - $this->smarty->cache_lifetime = 1000; - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $this->assertTrue(is_integer($tpl->cached->timestamp)); - $this->assertEquals(10, strlen($tpl->cached->timestamp)); - } - - /** - * test isCached - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * - */ - public function testIsCached() - { - $this->smarty->setAllowPhpTemplates(true); - $this->smarty->caching = true; - $this->smarty->cache_lifetime = 10000; - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $this->assertTrue($tpl->isCached()); - } - - /** - * test isCached caching disabled - */ - public function testIsCachedCachingDisabled() - { - $this->smarty->setAllowPhpTemplates(true); - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $this->assertFalse($tpl->isCached()); - } - - /** - * test isCached on touched source - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * @doesNotPerformAssertions - */ - public function testIsCachedTouchedSourcePrepare() - { - $this->smarty->setAllowPhpTemplates(true); - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - sleep(2); - touch($tpl->source->filepath); - } - - /** - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * - */ - public function testIsCachedTouchedSource() - { - $this->smarty->setAllowPhpTemplates(true); - $this->smarty->caching = true; - $this->smarty->cache_lifetime = 1000; - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $this->assertFalse($tpl->isCached()); - } - - /** - * test is cache file is written - */ - public function testWriteCachedContent() - { - $this->smarty->setAllowPhpTemplates(true); - $this->smarty->caching = true; - $this->smarty->cache_lifetime = 1000; - $this->cleanCacheDir(); - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $this->smarty->fetch($tpl); - $this->assertTrue(file_exists($tpl->cached->filepath)); - } - - /** - * test getRenderedTemplate - */ - public function testGetRenderedTemplate() - { - $this->smarty->setAllowPhpTemplates(true); - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $this->assertStringContainsString('php hello world', $tpl->fetch()); - } - - /** - * test $smarty->is_cached - * @doesNotPerformAssertions - */ - public function testSmartyIsCachedPrepare() - { - // clean up for next tests - $this->cleanCacheDir(); - $this->smarty->setAllowPhpTemplates(true); - // prepare files for next test - $this->smarty->caching = true; - $this->smarty->cache_lifetime = 1000; - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $this->smarty->fetch($tpl); - } - - /** - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * - */ - public function testSmartyIsCached() - { - $this->smarty->setAllowPhpTemplates(true); - $this->smarty->caching = true; - $this->smarty->cache_lifetime = 1000; - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $this->assertTrue($this->smarty->isCached($tpl)); - } - - /** - * test $smarty->is_cached caching disabled - */ - public function testSmartyIsCachedCachingDisabled() - { - $this->smarty->setAllowPhpTemplates(true); - $tpl = $this->smarty->createTemplate('php:phphelloworld.php'); - $this->assertFalse($this->smarty->isCached($tpl)); - } - - public function testGetTemplateFilepathName() - { - $this->smarty->addTemplateDir('./templates_2', 'foo'); - $tpl = $this->smarty->createTemplate('php:[foo]helloworld.php'); - $this->assertEquals('./templates_2/helloworld.php', $this->relative($tpl->source->filepath)); - } - - public function testGetCachedFilepathName() - { - $this->smarty->addTemplateDir('./templates_2', 'foo'); - $this->smarty->caching = true; - $this->smarty->cache_lifetime = 1000; - $tpl = $this->smarty->createTemplate('php:[foo]helloworld.php'); - $path = $tpl->cached->filepath; - $expected = $this->buildCachedPath($tpl, false, null, null, 'helloworld.php', 'php', - $this->smarty->getTemplateDir('foo'), 'file'); - $this->assertEquals($expected, $path); - } - - /** - * test {include} php resource - */ - public function testIncludePhpTemplate() - { - $this->smarty->setAllowPhpTemplates(true); - $this->assertStringContainsString('php hello world', $this->smarty->fetch('includephp.tpl')); - } - - /** - * test {include} php resource caching - */ - public function testIncludePhpTemplateCaching() - { - $this->smarty->caching = true; - $this->smarty->setAllowPhpTemplates(true); - $this->assertStringContainsString('php hello world', $this->smarty->fetch('includephp.tpl')); - } - - /** - * test clearCompiledTemplate() - */ - public function testClearCompiled() - { - $this->smarty->setAllowPhpTemplates(true); - $this->assertEquals(0, $this->smarty->clearCompiledTemplate('php:phphelloworld.php')); - } - -} diff --git a/tests/UnitTests/ResourceTests/Php/cache/.gitignore b/tests/UnitTests/ResourceTests/Php/cache/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/ResourceTests/Php/cache/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/ResourceTests/Php/templates/includephp.tpl b/tests/UnitTests/ResourceTests/Php/templates/includephp.tpl deleted file mode 100644 index 5baa76d2..00000000 --- a/tests/UnitTests/ResourceTests/Php/templates/includephp.tpl +++ /dev/null @@ -1 +0,0 @@ -{include 'php:phphelloworld.php'}
\ No newline at end of file diff --git a/tests/UnitTests/ResourceTests/Php/templates/phphelloworld.php b/tests/UnitTests/ResourceTests/Php/templates/phphelloworld.php deleted file mode 100644 index 6fe5b4ba..00000000 --- a/tests/UnitTests/ResourceTests/Php/templates/phphelloworld.php +++ /dev/null @@ -1 +0,0 @@ -php hello world diff --git a/tests/UnitTests/ResourceTests/Php/templates_2/helloworld.php b/tests/UnitTests/ResourceTests/Php/templates_2/helloworld.php deleted file mode 100644 index 6fe5b4ba..00000000 --- a/tests/UnitTests/ResourceTests/Php/templates_2/helloworld.php +++ /dev/null @@ -1 +0,0 @@ -php hello world diff --git a/tests/UnitTests/ResourceTests/Php/templates_c/.gitignore b/tests/UnitTests/ResourceTests/Php/templates_c/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/ResourceTests/Php/templates_c/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php b/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php index 1f62bc4c..407aa461 100644 --- a/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php +++ b/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php @@ -2,16 +2,18 @@ /** * Smarty PHPunit tests register->resource * - * @package PHPunit + * @author Uwe Tews */ +use Smarty\Resource\CustomPlugin; + /** * class for register->resource tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class RegisteredResourceTest extends PHPUnit_Smarty { @@ -20,7 +22,7 @@ class RegisteredResourceTest extends PHPUnit_Smarty { $this->setUpSmarty(__DIR__); - $this->smarty->registerResource("rr", new RegisteredResourceTest_Resource1()); + $this->smarty->registerResource("rr", new RegisteredResourceTest_Resource1Plugin()); } @@ -47,8 +49,8 @@ class RegisteredResourceTest extends PHPUnit_Smarty public function testResourcePluginTimestamp() { $tpl = $this->smarty->createTemplate('rr:test'); - $this->assertTrue(is_integer($tpl->source->getTimeStamp())); - $this->assertEquals(10, strlen($tpl->source->getTimeStamp())); + $this->assertTrue(is_integer($tpl->getSource()->getTimeStamp())); + $this->assertEquals(10, strlen($tpl->getSource()->getTimeStamp())); } /** @@ -56,11 +58,11 @@ class RegisteredResourceTest extends PHPUnit_Smarty */ public function testResourceCompileIdChange() { - $this->smarty->registerResource('myresource', new RegisteredResourceTest_Resource2()); - $this->smarty->compile_id = 'a'; + $this->smarty->registerResource('myresource', new RegisteredResourceTest_Resource2Plugin()); + $this->smarty->setCompileId('a'); $this->assertEquals('this is template 1', $this->smarty->fetch('myresource:some')); $this->assertEquals('this is template 1', $this->smarty->fetch('myresource:some')); - $this->smarty->compile_id = 'b'; + $this->smarty->setCompileId('b'); $this->assertEquals('this is template 2', $this->smarty->fetch('myresource:some')); $this->assertEquals('this is template 2', $this->smarty->fetch('myresource:some')); } @@ -69,7 +71,7 @@ class RegisteredResourceTest extends PHPUnit_Smarty * */ public function testSmartyTemplate() { - $this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource3()); + $this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource3Plugin()); $this->assertEquals('template = mytpl:foo', $this->smarty->fetch('mytpl:foo')); } /** @@ -77,12 +79,12 @@ class RegisteredResourceTest extends PHPUnit_Smarty * */ public function testSmartyCurrentDir() { - $this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource4()); + $this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource4Plugin()); $this->assertEquals('current_dir = .', $this->smarty->fetch('mytpl:bar')); } } -class RegisteredResourceTest_Resource1 extends Smarty_Resource_Custom { +class RegisteredResourceTest_Resource1Plugin extends CustomPlugin { protected function fetch($name, &$source, &$mtime) { $source = '{$x="hello world"}{$x}'; @@ -91,7 +93,7 @@ class RegisteredResourceTest_Resource1 extends Smarty_Resource_Custom { } -class RegisteredResourceTest_Resource2 extends Smarty_Resource_Custom { +class RegisteredResourceTest_Resource2Plugin extends CustomPlugin { protected function fetch($name, &$source, &$mtime) { @@ -112,7 +114,7 @@ class RegisteredResourceTest_Resource2 extends Smarty_Resource_Custom { } -class RegisteredResourceTest_Resource3 extends Smarty_Resource_Custom { +class RegisteredResourceTest_Resource3Plugin extends CustomPlugin { protected function fetch($name, &$source, &$mtime) { $source = 'template = {$smarty.template}'; @@ -121,7 +123,7 @@ class RegisteredResourceTest_Resource3 extends Smarty_Resource_Custom { } -class RegisteredResourceTest_Resource4 extends Smarty_Resource_Custom { +class RegisteredResourceTest_Resource4Plugin extends CustomPlugin { protected function fetch($name, &$source, &$mtime) { $source = 'current_dir = {$smarty.current_dir}'; diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db.php b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db.php index 668b83da..59315504 100644 --- a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db.php +++ b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db.php @@ -10,16 +10,19 @@ * ------------------------------------------------------------- */ -class Smarty_Resource_Db extends Smarty_Resource_Recompiled { +use Smarty\Resource\RecompiledPlugin; +use Smarty\Template; +use Smarty\Template\Source; - public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) { - $source->filepath = 'db:'; +class Smarty_Resource_Db extends RecompiledPlugin { + + public function populate(Source $source, Template $_template = null) { $source->uid = sha1($source->resource); $source->timestamp = 1000000000; $source->exists = true; } - public function getContent(Smarty_Template_Source $source) { + public function getContent(Source $source) { return '{$x="hello world"}{$x}'; } } diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db2.php b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db2.php index 3eefce7c..a4f65402 100644 --- a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db2.php +++ b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db2.php @@ -10,17 +10,20 @@ * ------------------------------------------------------------- */ -class Smarty_Resource_Db2 extends Smarty_Resource_Recompiled +use Smarty\Resource\RecompiledPlugin; +use Smarty\Template; +use Smarty\Template\Source; + +class Smarty_Resource_Db2 extends RecompiledPlugin { - public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) + public function populate(Source $source, Template $_template = null) { - $source->filepath = 'db2:'; $source->uid = sha1($source->resource); $source->timestamp = 0; $source->exists = true; } - public function getContent(Smarty_Template_Source $source) + public function getContent(Source $source) { return '{$x="hello world"}{$x}'; } diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db3.php b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db3.php index 0b07233b..455255e2 100644 --- a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db3.php +++ b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db3.php @@ -10,22 +10,24 @@ * ------------------------------------------------------------- */ -class Smarty_Resource_Db3 extends Smarty_Resource +use Smarty\Template; +use Smarty\Template\Source; + +class Smarty_Resource_Db3 extends Smarty\Resource\BasePlugin { - public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) + public function populate(Source $source, Template $_template = null) { - $source->filepath = 'db3:'; $source->uid = sha1($source->resource); $source->timestamp = 0; $source->exists = true; } - public function getContent(Smarty_Template_Source $source) + public function getContent(Source $source) { return '{$x="hello world"}{$x}'; } - public function getCompiledFilepath(Smarty_Internal_Template $_template) + public function getCompiledFilepath(Template $_template) { return false; } diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db4.php b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db4.php index 611d3e43..571df0d8 100644 --- a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db4.php +++ b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db4.php @@ -10,19 +10,22 @@ * ------------------------------------------------------------- */ -class Smarty_Resource_Db4 extends Smarty_Resource +use Smarty\Template; +use Smarty\Template\Config; +use Smarty\Template\Source; + +class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin { - public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) + public function populate(Source $source, Template $_template = null) { - $source->filepath = 'db4:'; $source->uid = sha1($source->resource); $source->timestamp = 0; $source->exists = true; } - public function getContent(Smarty_Template_Source $source) + public function getContent(Source $source) { - if ($source->is_config) { + if ($source instanceof Config) { return "foo = 'bar'\n"; } diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php b/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php index 9aa46718..5b1b3854 100644 --- a/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php +++ b/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests resource plugins * - * @package PHPunit + * @author Uwe Tews */ /** * class for resource plugins tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class ResourcePluginTest extends PHPUnit_Smarty { @@ -49,7 +49,6 @@ class ResourcePluginTest extends PHPUnit_Smarty public function testResourcePluginRegisteredInstance() { $this->smarty->addPluginsDir("./PHPunitplugins/"); - $this->smarty->loadPlugin('Smarty_Resource_Db2'); $this->smarty->registerResource('db2a', new Smarty_Resource_Db2('db2a')); $this->assertEquals('hello world', $this->smarty->fetch('db2a:test')); } @@ -63,7 +62,7 @@ class ResourcePluginTest extends PHPUnit_Smarty $tpl = $this->smarty->createTemplate('db2:test.tpl'); $expected = realpath('./templates_c/' . sha1('db2:test.tpl') . '.db2.test.tpl.php'); $this->assertFalse(!!$expected); - $this->assertFalse($tpl->compiled->filepath); + $this->assertNull($tpl->getCompiled()->filepath); } /** @@ -73,8 +72,8 @@ class ResourcePluginTest extends PHPUnit_Smarty { $this->smarty->addPluginsDir("./PHPunitplugins/"); $tpl = $this->smarty->createTemplate('db:test'); - $this->assertTrue(is_integer($tpl->source->getTimeStamp())); - $this->assertEquals(10, strlen($tpl->source->getTimeStamp())); + $this->assertTrue(is_integer($tpl->getSource()->getTimeStamp())); + $this->assertEquals(10, strlen($tpl->getSource()->getTimeStamp())); } } diff --git a/tests/UnitTests/ResourceTests/Stream/StreamResourceTest.php b/tests/UnitTests/ResourceTests/Stream/StreamResourceTest.php index e5eedcc1..e2a8ff70 100644 --- a/tests/UnitTests/ResourceTests/Stream/StreamResourceTest.php +++ b/tests/UnitTests/ResourceTests/Stream/StreamResourceTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests for stream resources * - * @package PHPunit + * @author Uwe Tews */ /** * class for stream resource tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class StreamResourceTest extends PHPUnit_Smarty { @@ -27,7 +27,6 @@ class StreamResourceTest extends PHPUnit_Smarty fclose($fp); } - public function testInit() { $this->cleanDirs(); @@ -41,10 +40,10 @@ class StreamResourceTest extends PHPUnit_Smarty /** * test getTemplateFilepath */ - public function testGetTemplateFilepath() + public function testGetFullResourceName() { $tpl = $this->smarty->createTemplate('global:mytest'); - $this->assertEquals('global://mytest', $tpl->source->filepath); + $this->assertEquals('global:mytest', $tpl->getSource()->getFullResourceName()); } /** @@ -53,7 +52,7 @@ class StreamResourceTest extends PHPUnit_Smarty public function testGetTemplateTimestamp() { $tpl = $this->smarty->createTemplate('global:mytest'); - $this->assertTrue($tpl->source->getTimeStamp()); + $this->assertTrue($tpl->getSource()->getTimeStamp()); } /** @@ -62,7 +61,7 @@ class StreamResourceTest extends PHPUnit_Smarty public function testGetTemplateSource() { $tpl = $this->smarty->createTemplate('global:mytest', null, null, $this->smarty); - $this->assertEquals('hello world {$foo}', $tpl->source->getContent()); + $this->assertEquals('hello world {$foo}', $tpl->getSource()->getContent()); } /** @@ -71,7 +70,7 @@ class StreamResourceTest extends PHPUnit_Smarty public function testUsesCompiler() { $tpl = $this->smarty->createTemplate('global:mytest'); - $this->assertFalse($tpl->source->handler->uncompiled); + $this->markTestIncomplete(); } /** @@ -80,7 +79,7 @@ class StreamResourceTest extends PHPUnit_Smarty public function testIsEvaluated() { $tpl = $this->smarty->createTemplate('global:mytest'); - $this->assertTrue($tpl->source->handler->recompiled); + $this->assertTrue($tpl->getSource()->handler->recompiled); } /** @@ -98,7 +97,7 @@ class StreamResourceTest extends PHPUnit_Smarty public function testGetCompiledFilepath() { $tpl = $this->smarty->createTemplate('global:mytest'); - $this->assertFalse($tpl->compiled->filepath); + $this->assertNull($tpl->getCompiled()->filepath); } /** @@ -107,7 +106,7 @@ class StreamResourceTest extends PHPUnit_Smarty public function testGetCompiledTimestamp() { $tpl = $this->smarty->createTemplate('global:mytest'); - $this->assertFalse($tpl->compiled->getTimeStamp()); + $this->assertFalse($tpl->getCompiled()->getTimeStamp()); } /** @@ -116,7 +115,7 @@ class StreamResourceTest extends PHPUnit_Smarty public function testTemplateStreamExists1() { $tpl = $this->smarty->createTemplate('global:mytest'); - $this->assertTrue($tpl->source->exists); + $this->assertTrue($tpl->getSource()->exists); } public function testTemplateStreamExists2() @@ -130,7 +129,7 @@ class StreamResourceTest extends PHPUnit_Smarty public function testTemplateStreamNotExists1() { $tpl = $this->smarty->createTemplate('global:notthere'); - $this->assertFalse($tpl->source->exists); + $this->assertFalse($tpl->getSource()->exists); } public function testTemplateStramNotExists2() @@ -138,15 +137,15 @@ class StreamResourceTest extends PHPUnit_Smarty $this->assertFalse($this->smarty->templateExists('global:notthere')); } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * * test not existing template */ public function testTemplateStramNotExists3() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('\'global:notthere\''); $this->smarty->fetch('global:notthere'); } diff --git a/tests/UnitTests/ResourceTests/String/StringResourceTest.php b/tests/UnitTests/ResourceTests/String/StringResourceTest.php index 35be632f..a048d8b8 100644 --- a/tests/UnitTests/ResourceTests/String/StringResourceTest.php +++ b/tests/UnitTests/ResourceTests/String/StringResourceTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests for string resources * - * @package PHPunit + * @author Uwe Tews */ /** * class for string resource tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class StringResourceTest extends PHPUnit_Smarty { @@ -42,7 +42,7 @@ class StringResourceTest extends PHPUnit_Smarty public function testTemplateStringExists1() { $tpl = $this->smarty->createTemplate('string:{$foo}'); - $this->assertTrue($tpl->source->exists); + $this->assertTrue($tpl->getSource()->exists); } public function testTemplateStringExists2() @@ -56,7 +56,7 @@ class StringResourceTest extends PHPUnit_Smarty public function testGetTemplateFilepath() { $tpl = $this->smarty->createTemplate('string:hello world'); - $this->assertEquals($this->buildSourcePath($tpl), $tpl->source->filepath); + $this->assertEquals('hello world', $tpl->getSource()->getResourceName()); } /** @@ -65,7 +65,7 @@ class StringResourceTest extends PHPUnit_Smarty public function testGetTemplateTimestamp() { $tpl = $this->smarty->createTemplate('string:hello world'); - $this->assertTrue($tpl->source->getTimeStamp()); + $this->assertTrue($tpl->getSource()->getTimeStamp()); } /** @@ -74,7 +74,7 @@ class StringResourceTest extends PHPUnit_Smarty public function testGetTemplateSource() { $tpl = $this->smarty->createTemplate('string:hello world{$foo}'); - $this->assertEquals('hello world{$foo}', $tpl->source->getContent()); + $this->assertEquals('hello world{$foo}', $tpl->getSource()->getContent()); } /** @@ -83,7 +83,7 @@ class StringResourceTest extends PHPUnit_Smarty public function testUsesCompiler() { $tpl = $this->smarty->createTemplate('string:hello world'); - $this->assertFalse($tpl->source->handler->uncompiled); + $this->markTestIncomplete(); } /** @@ -92,7 +92,7 @@ class StringResourceTest extends PHPUnit_Smarty public function testIsEvaluated() { $tpl = $this->smarty->createTemplate('string:hello world'); - $this->assertFalse($tpl->source->handler->recompiled); + $this->assertFalse($tpl->getSource()->handler->recompiled); } /** @@ -105,21 +105,12 @@ class StringResourceTest extends PHPUnit_Smarty } /** - * test getCompiledFilepath - */ - public function testGetCompiledFilepath() - { - $tpl = $this->smarty->createTemplate('string:hello world'); - $this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'hello world', 'string', $this->smarty->getTemplateDir(0)), $tpl->compiled->filepath); - } - - /** * test getCompiledTimestamp */ public function testGetCompiledTimestamp() { $tpl = $this->smarty->createTemplate('string:hello world'); - $this->assertFalse($tpl->compiled->getTimeStamp()); + $this->assertFalse($tpl->getCompiled()->getTimeStamp()); } /** @@ -137,7 +128,7 @@ class StringResourceTest extends PHPUnit_Smarty public function testGetCachedTimestamp() { $tpl = $this->smarty->createTemplate('string:hello world'); - $this->assertFalse($tpl->cached->timestamp); + $this->assertFalse($tpl->getCached()->timestamp); } /** diff --git a/tests/UnitTests/SecurityTests/FunctionTest.php b/tests/UnitTests/SecurityTests/FunctionTest.php index 30804b85..3ef09b15 100644 --- a/tests/UnitTests/SecurityTests/FunctionTest.php +++ b/tests/UnitTests/SecurityTests/FunctionTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of function calls * - * @package PHPunit + * @author Uwe Tews */ /** * class for function tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class FunctionTest extends PHPUnit_Smarty { @@ -31,14 +31,8 @@ class FunctionTest extends PHPUnit_Smarty public function testUnknownFunction() { $this->smarty->enableSecurity(); - try { - $this->smarty->fetch('eval:{unknown()}'); - } - catch (Exception $e) { - $this->assertStringContainsString("PHP function 'unknown' not allowed by security setting", $e->getMessage()); - - return; - } - $this->fail('Exception for unknown function has not been raised.'); + $this->expectException(\Smarty\CompilerException::class); + $this->expectExceptionMessage('unknown modifier'); + $this->smarty->fetch('eval:{unknown()}'); } } diff --git a/tests/UnitTests/SecurityTests/SecurityTest.php b/tests/UnitTests/SecurityTests/SecurityTest.php index 7631a0a6..5f896cc8 100644 --- a/tests/UnitTests/SecurityTests/SecurityTest.php +++ b/tests/UnitTests/SecurityTests/SecurityTest.php @@ -2,16 +2,18 @@ /** * Smarty PHPunit tests for security * - * @package PHPunit + * @author Uwe Tews */ +use Smarty\CompilerException; + /** * class for security test * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class SecurityTest extends PHPUnit_Smarty { @@ -28,18 +30,6 @@ class SecurityTest extends PHPUnit_Smarty } /** - * test that security is loaded -' *'/ - public function testSecurityReenable() - { - $this->smarty->disableSecurity(); - $this->smarty->enableSecurity('Security'); - $this->smarty->fetch('helloworld.tpl'); - $this->smarty->disableSecurity(); - $this->smarty->enableSecurity('Security'); - $this->smarty->fetch('helloworld.tpl'); - } -/** * test that security is loaded */ public function testSecurityLoaded() @@ -50,32 +40,9 @@ class SecurityTest extends PHPUnit_Smarty /** * test trusted PHP function */ - public function testTrustedPHPFunction() - { - $this->assertEquals("5", $this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{sizeof($foo)}')); - } - -/** - * test not trusted PHP function - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testNotTrustedPHPFunction() - { - $this->expectException('SmartyException'); - $this->expectExceptionMessage('PHP function \'sizeof\' not allowed by security setting'); - $this->smarty->security_policy->php_functions = array('null'); - $this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{sizeof($foo)}'); - } - -/** - * test not trusted PHP function at disabled security - */ - public function testDisabledTrustedPHPFunction() + public function testTrustedFunction() { - $this->smarty->security_policy->php_functions = array('null'); - $this->smarty->disableSecurity(); - $this->assertEquals("5", $this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{sizeof($foo)}')); + $this->assertEquals("5", $this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{count($foo)}')); } /** @@ -84,32 +51,21 @@ class SecurityTest extends PHPUnit_Smarty */ public function testTrustedModifier() { - $this->assertEquals("5", @$this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{$foo|@sizeof}')); + $this->assertEquals("5", @$this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{$foo|@count}')); } /** * test not trusted modifier - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @deprecated */ public function testNotTrustedModifier() { - $this->expectException('SmartyException'); - $this->expectExceptionMessage('modifier \'sizeof\' not allowed by security setting'); - $this->smarty->security_policy->php_modifiers = array('null'); - @$this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{$foo|@sizeof}'); - } - -/** - * test not trusted modifier at disabled security - * @deprecated - */ - public function testDisabledTrustedModifier() - { - $this->smarty->security_policy->php_modifiers = array('null'); - $this->smarty->disableSecurity(); - @$this->assertEquals("5", $this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{$foo|@sizeof}')); + $this->smarty->security_policy->disabled_modifiers[] = 'escape'; + $this->expectException(\Smarty\Exception::class); + $this->expectExceptionMessage('modifier \'escape\' disabled by security setting'); + @$this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{$foo|escape}'); } /** @@ -123,12 +79,12 @@ class SecurityTest extends PHPUnit_Smarty /** * test not allowed tag - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testNotAllowedTags2() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('tag \'cycle\' not allowed by security setting'); $this->smarty->security_policy->allowed_tags = array('counter'); $this->smarty->fetch('string:{counter}{cycle values="1,2"}'); @@ -136,12 +92,12 @@ class SecurityTest extends PHPUnit_Smarty /** * test disabled tag - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testDisabledTags() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('tag \'cycle\' disabled by security setting'); $this->smarty->security_policy->disabled_tags = array('cycle'); $this->smarty->fetch('string:{counter}{cycle values="1,2"}'); @@ -166,12 +122,12 @@ class SecurityTest extends PHPUnit_Smarty /** * test not allowed modifier - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testNotAllowedModifier() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('modifier \'lower\' not allowed by security setting'); $this->smarty->security_policy->allowed_modifiers = array('upper'); $this->smarty->fetch('string:{"hello"|upper}{"world"|lower}'); @@ -179,12 +135,12 @@ class SecurityTest extends PHPUnit_Smarty /** * test disabled modifier - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testDisabledModifier() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('modifier \'lower\' disabled by security setting'); $this->smarty->security_policy->disabled_modifiers = array('lower'); $this->smarty->fetch('string:{"hello"|upper}{"world"|lower}'); @@ -230,12 +186,12 @@ class SecurityTest extends PHPUnit_Smarty /** * test not trusted directory * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testNotTrustedDirectory() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('not trusted file path'); $this->smarty->security_policy->secure_dir = array(str_replace('\\', '/', __DIR__ . '/templates_3/')); $this->smarty->fetch('string:{include file="templates_2/hello.tpl"}'); @@ -260,40 +216,40 @@ class SecurityTest extends PHPUnit_Smarty $this->assertEquals('25', $this->smarty->fetch($tpl)); } - /** - * test not trusted PHP function - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testNotTrustedStaticClass() - { - $this->expectException('SmartyException'); + /** + * test not trusted PHP function + * + * + */ + public function testNotTrustedStaticClass() + { + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('access to static class \'mysecuritystaticclass\' not allowed by security setting'); $this->smarty->security_policy->static_classes = array('null'); $this->smarty->fetch('string:{mysecuritystaticclass::square(5)}'); } - /** - * test not trusted PHP function - */ - public function testNotTrustedStaticClassEval() - { - $this->expectException('SmartyException'); - $this->expectExceptionMessage('dynamic static class not allowed by security setting'); - $this->smarty->security_policy->static_classes = array('null'); - $this->smarty->fetch('string:{$test = "mysecuritystaticclass"}{$test::square(5)}'); - } + /** + * test not trusted PHP function + */ + public function testNotTrustedStaticClassEval() + { + $this->expectException(\Smarty\Exception::class); + $this->expectExceptionMessage('dynamic static class not allowed by security setting'); + $this->smarty->security_policy->static_classes = array('null'); + $this->smarty->fetch('string:{$test = "mysecuritystaticclass"}{$test::square(5)}'); + } - /** - * test not trusted PHP function - */ - public function testNotTrustedStaticClassSmartyVar() - { - $this->expectException('SmartyException'); - $this->expectExceptionMessage('dynamic static class not allowed by security setting'); - $this->smarty->security_policy->static_classes = array('null'); - $this->smarty->fetch('string:{$smarty.template_object::square(5)}'); - } + /** + * test not trusted PHP function + */ + public function testNotTrustedStaticClassSmartyVar() + { + $this->expectException(\Smarty\Exception::class); + $this->expectExceptionMessage('dynamic static class not allowed by security setting'); + $this->smarty->security_policy->static_classes = array('null'); + $this->smarty->fetch('string:{$smarty.template_object::square(5)}'); + } public function testChangedTrustedDirectory() { @@ -311,41 +267,43 @@ class SecurityTest extends PHPUnit_Smarty /** * test template file exits * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testTemplateTrustedStream() { - stream_wrapper_register("global", "ResourceStreamSecurity") + stream_wrapper_register("global", ResourceStreamSecurity::class) or die("Failed to register protocol"); $fp = fopen("global://mytest", "r+"); fwrite($fp, 'hello world {$foo}'); fclose($fp); $this->smarty->security_policy->streams= array('global'); $tpl = $this->smarty->createTemplate('global:mytest'); - $this->assertTrue($tpl->source->exists); + $this->assertTrue($tpl->getSource()->exists); + stream_wrapper_unregister("global"); } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * test template file exits */ public function testTemplateNotTrustedStream() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('stream \'global\' not allowed by security setting'); - stream_wrapper_register("global", "ResourceStreamSecurity") + stream_wrapper_register("global", ResourceStreamSecurity::class) or die("Failed to register protocol"); $fp = fopen("global://mytest", "r+"); fwrite($fp, 'hello world {$foo}'); fclose($fp); $this->smarty->security_policy->streams= array('notrusted'); $tpl = $this->smarty->createTemplate('global:mytest'); - $this->assertTrue($tpl->source->exists); + $this->assertTrue($tpl->getSource()->exists); + stream_wrapper_unregister("global"); } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testTrustedUri() { @@ -356,12 +314,12 @@ class SecurityTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testNotTrustedUri() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('URI \'https://www.smarty.net/docs/en/preface.tpl\' not allowed by security setting'); $this->smarty->security_policy->trusted_uri = array(); $this->assertStringContainsString('<title>Preface | Smarty</title>', $this->smarty->fetch('string:{fetch file="https://www.smarty.net/docs/en/preface.tpl"}')); @@ -371,7 +329,7 @@ class SecurityTest extends PHPUnit_Smarty * In security mode, accessing $smarty.template_object should be illegal. */ public function testSmartyTemplateObject() { - $this->expectException(SmartyCompilerException::class); + $this->expectException(CompilerException::class); $this->smarty->display('string:{$smarty.template_object}'); } @@ -387,10 +345,7 @@ class mysecuritystaticclass return $i * $i; } } -class Security extends Smarty_Security -{ -} #[AllowDynamicProperties] class ResourceStreamSecurity { diff --git a/tests/UnitTests/SmartyMethodsTests/Append/AppendTest.php b/tests/UnitTests/SmartyMethodsTests/Append/AppendTest.php index a10744cd..43736d01 100644 --- a/tests/UnitTests/SmartyMethodsTests/Append/AppendTest.php +++ b/tests/UnitTests/SmartyMethodsTests/Append/AppendTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests append method * - * @package PHPunit + * @author Uwe Tews */ /** * class for append tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class AppendTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/SmartyMethodsTests/AppendByRef/AppendByRefTest.php b/tests/UnitTests/SmartyMethodsTests/AppendByRef/AppendByRefTest.php deleted file mode 100644 index 0f6abe5e..00000000 --- a/tests/UnitTests/SmartyMethodsTests/AppendByRef/AppendByRefTest.php +++ /dev/null @@ -1,64 +0,0 @@ -<?php -/** - * Smarty PHPunit tests appendByRef method - * - * @package PHPunit - * @author Uwe Tews - */ - -/** - * class for appendByRef tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class AppendByRefTest extends PHPUnit_Smarty -{ - public function setUp(): void - { - $this->setUpSmarty(__DIR__); - } - - /** - * test appendByRef - */ - public function testAppendByRef() - { - $bar = 'bar'; - $bar2 = 'bar2'; - $this->smarty->appendByRef('foo', $bar); - $this->smarty->appendByRef('foo', $bar2); - $bar = 'newbar'; - $bar2 = 'newbar2'; - $this->assertEquals('newbar newbar2', $this->smarty->fetch('eval:{$foo[0]} {$foo[1]}')); - } - - /** - * test appendByRef to unassigned variable - */ - public function testAppendByRefUnassigned() - { - $bar2 = 'bar2'; - $this->smarty->appendByRef('foo', $bar2); - $bar2 = 'newbar2'; - $this->assertEquals('newbar2', $this->smarty->fetch('eval:{$foo[0]}')); - } - - /** - * test appendByRef merge - * - * @todo fix testAppendByRefMerge - */ - public function testAppendByRefMerge() - { - $foo = array('a' => 'a', 'b' => 'b', 'c' => 'c'); - $bar = array('b' => 'd'); - $this->smarty->assignByRef('foo', $foo); - $this->smarty->appendByRef('foo', $bar, true); - $this->assertEquals('a d c', $this->smarty->fetch('eval:{$foo["a"]} {$foo["b"]} {$foo["c"]}')); - $bar = array('b' => 'newd'); - $this->smarty->appendByRef('foo', $bar, true); - $this->assertEquals('a newd c', $this->smarty->fetch('eval:{$foo["a"]} {$foo["b"]} {$foo["c"]}')); - } -} diff --git a/tests/UnitTests/SmartyMethodsTests/AppendByRef/cache/.gitignore b/tests/UnitTests/SmartyMethodsTests/AppendByRef/cache/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/SmartyMethodsTests/AppendByRef/cache/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/SmartyMethodsTests/AppendByRef/templates_c/.gitignore b/tests/UnitTests/SmartyMethodsTests/AppendByRef/templates_c/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/SmartyMethodsTests/AppendByRef/templates_c/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/SmartyMethodsTests/Assign/AssignTest.php b/tests/UnitTests/SmartyMethodsTests/Assign/AssignTest.php index 75c4de76..ea5f3a4b 100644 --- a/tests/UnitTests/SmartyMethodsTests/Assign/AssignTest.php +++ b/tests/UnitTests/SmartyMethodsTests/Assign/AssignTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests assign method * - * @package PHPunit + * @author Uwe Tews */ /** * class for assign tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class AssignTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/SmartyMethodsTests/AssignByRef/AssignByRefTest.php b/tests/UnitTests/SmartyMethodsTests/AssignByRef/AssignByRefTest.php deleted file mode 100644 index e6d01146..00000000 --- a/tests/UnitTests/SmartyMethodsTests/AssignByRef/AssignByRefTest.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php -/** - * Smarty PHPunit tests assignByRef method - * - * @package PHPunit - * @author Uwe Tews - */ - -/** - * class for assignByRef tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class AssignByRefTest extends PHPUnit_Smarty -{ - public function setUp(): void - { - $this->setUpSmarty(__DIR__); - } - - /** - * test simple assignByRef - */ - public function testSimpleAssignByRef() - { - $bar = 'bar'; - $this->smarty->assignByRef('foo', $bar); - $bar = 'newbar'; - $this->assertEquals('newbar', $this->smarty->fetch('eval:{$foo}')); - } -} diff --git a/tests/UnitTests/SmartyMethodsTests/AssignByRef/cache/.gitignore b/tests/UnitTests/SmartyMethodsTests/AssignByRef/cache/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/SmartyMethodsTests/AssignByRef/cache/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/SmartyMethodsTests/AssignByRef/templates_c/.gitignore b/tests/UnitTests/SmartyMethodsTests/AssignByRef/templates_c/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/SmartyMethodsTests/AssignByRef/templates_c/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/SmartyMethodsTests/AssignGlobal/AssignGlobalTest.php b/tests/UnitTests/SmartyMethodsTests/AssignGlobal/AssignGlobalTest.php deleted file mode 100644 index 8f61b81d..00000000 --- a/tests/UnitTests/SmartyMethodsTests/AssignGlobal/AssignGlobalTest.php +++ /dev/null @@ -1,70 +0,0 @@ -<?php -/** - * Smarty PHPunit tests assignGlobal method and {assignGlobal} tag - * - * @package PHPunit - * @author Uwe Tews - */ - -/** - * class for assignGlobal method and {assignGlobal} tag tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class AssignGlobalTest extends PHPUnit_Smarty -{ - public function setUp(): void - { - $this->setUpSmarty(__DIR__); - } - - - public function testInit() - { - $this->cleanDirs(); - } - /** - * test assignGlobal and getGlobal - */ - public function testAssignGlobalGetGlobal() - { - $this->smarty->assignGlobal('foo', 'bar'); - $this->assertEquals('bar', $this->smarty->getGlobal('foo')); - } - - /** - * test assignGlobal and getGlobal on arrays - */ - public function testAssignGlobalGetGlobalArray() - { - $this->smarty->assignGlobal('foo', array('foo' => 'bar', 'foo2' => 'bar2')); - $a1 = array('foo' => array('foo' => 'bar', 'foo2' => 'bar2')); - $a2 = $this->smarty->getGlobal(); - unset($a2['SCRIPT_NAME']); - $this->assertTrue($a1 === $a2); - } - - /** - * test assignGlobal tag - */ - public function testAssignGlobalTag() - { - $this->smarty->assignGlobal('foo', 'bar'); - $this->assertEquals('bar', $this->smarty->fetch('eval:{$foo}')); - $this->assertEquals('buh', $this->smarty->fetch('eval:{assign var=foo value=buh scope=global}{$foo}')); - $this->assertEquals('buh', $this->smarty->fetch('eval:{$foo}')); - $this->assertEquals('buh', $this->smarty->getGlobal('foo')); - } - - /** - * test global var array element tag - */ - public function testGlobalVarArrayTag() - { - $this->smarty->assignGlobal('foo', array('foo' => 'bar', 'foo2' => 'bar2')); - $this->assertEquals('bar2', $this->smarty->fetch('eval:{$foo.foo2}')); - $this->assertEquals('bar', $this->smarty->fetch('eval:{$foo.foo}')); - } -} diff --git a/tests/UnitTests/SmartyMethodsTests/AssignGlobal/cache/.gitignore b/tests/UnitTests/SmartyMethodsTests/AssignGlobal/cache/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/SmartyMethodsTests/AssignGlobal/cache/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/SmartyMethodsTests/AssignGlobal/templates_c/.gitignore b/tests/UnitTests/SmartyMethodsTests/AssignGlobal/templates_c/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/SmartyMethodsTests/AssignGlobal/templates_c/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignTest.php b/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignTest.php index 9363f323..f9caa8a6 100644 --- a/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignTest.php +++ b/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignTest.php @@ -2,21 +2,17 @@ /** * Smarty PHPunit tests clearing all assigned variables * - * @package PHPunit + * @author Uwe Tews */ /** * class for clearing all assigned variables tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled */ class ClearAllAssignTest extends PHPUnit_Smarty { - protected $_data = null; - protected $_tpl = null; + private $_data = null; + private $_tpl = null; public function setUp(): void { diff --git a/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignTest.php b/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignTest.php index 8d34c3e7..c9237be2 100644 --- a/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignTest.php +++ b/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests clearing assigned variables * - * @package PHPunit + * @author Uwe Tews */ /** * class for clearing assigned variables tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class ClearAssignTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/SmartyMethodsTests/ClearCompiledTemplate/ClearCompiledTest.php b/tests/UnitTests/SmartyMethodsTests/ClearCompiledTemplate/ClearCompiledTest.php index 0944928a..8e638d98 100644 --- a/tests/UnitTests/SmartyMethodsTests/ClearCompiledTemplate/ClearCompiledTest.php +++ b/tests/UnitTests/SmartyMethodsTests/ClearCompiledTemplate/ClearCompiledTest.php @@ -2,7 +2,7 @@ /** * Smarty PHPunit tests for deleting compiled templates * - * @package PHPunit + * @author Uwe Tews * @author Rodney Rehm */ @@ -10,18 +10,16 @@ /** * class for delete compiled template tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class ClearCompiledTest extends PHPUnit_Smarty { - public $methodName = null; public function setUp(): void { $this->setUpSmarty(__DIR__); $this->smarty->addTemplateDir('./templates_2/'); - $this->methodName = 'clearCompiledTemplate'; } @@ -56,7 +54,7 @@ class ClearCompiledTest extends PHPUnit_Smarty protected function makeFiles() { $this->_files = array(); - $directory_length = strlen($this->getSmartyObj()->getCompileDir()); + $directory_length = strlen($this->getSmarty()->getCompileDir()); $templates = array( 'helloworld.tpl' => array(null, 'compile1', 'compile2'), 'helloworld2.tpl' => array(null, 'compile1', 'compile2'), @@ -66,14 +64,11 @@ class ClearCompiledTest extends PHPUnit_Smarty foreach ($templates as $template => $compile_ids) { foreach ($compile_ids as $compile_id) { - $tpl = $this->getSmartyObj()->createTemplate($template, null, $compile_id); + $tpl = $this->getSmarty()->createTemplate($template, null, $compile_id); $tpl->fetch(); - $this->_files[$template . '#' . $compile_id] = substr($tpl->compiled->filepath, $directory_length); + $this->_files[$template . '#' . $compile_id] = substr($tpl->getCompiled()->filepath, $directory_length); } } - // TODO - //Smarty::$_resource_cache = array(); - //$this->getSmartyObj()->_cache['template_objects'] = array(); return $this->_files; } @@ -108,7 +103,7 @@ class ClearCompiledTest extends PHPUnit_Smarty */ protected function touchFiles($keys, $offset = 0) { - $base = $this->getSmartyObj()->getCompileDir(); + $base = $this->getSmarty()->getCompileDir(); $time = time(); foreach ($keys as $key) { if (isset($this->_files[$key])) { @@ -126,7 +121,7 @@ class ClearCompiledTest extends PHPUnit_Smarty */ protected function getFiles() { - $directory = realpath($this->getSmartyObj()->getCompileDir()); + $directory = realpath($this->getSmarty()->getCompileDir()); if (!$directory) { return array(); } @@ -163,12 +158,12 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearAll($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); $expected = array(); - $this->assertEquals(12, $this->getSmartyObj()->{$this->methodName}()); + $this->assertEquals(12, $this->getSmarty()->clearCompiledTemplate()); $this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->clearFiles(); @@ -197,7 +192,7 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearTemplate($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); @@ -206,7 +201,7 @@ class ClearCompiledTest extends PHPUnit_Smarty 'ambiguous/case1/foobar.tpl#', 'ambiguous/case1/foobar.tpl#compile1', 'ambiguous/case1/foobar.tpl#compile2', '[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2', ); - $this->assertEquals(3, $this->getSmartyObj()->{$this->methodName}('helloworld.tpl')); + $this->assertEquals(3, $this->getSmarty()->clearCompiledTemplate('helloworld.tpl')); $this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->clearFiles(); @@ -214,12 +209,12 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearOtherTemplate($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); $expected = array_keys($this->_files); - $this->assertEquals(0, $this->getSmartyObj()->{$this->methodName}('foobar.tpl')); + $this->assertEquals(0, $this->getSmarty()->clearCompiledTemplate('foobar.tpl')); $this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->clearFiles(); @@ -248,7 +243,7 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearCompileid($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); @@ -258,7 +253,7 @@ class ClearCompiledTest extends PHPUnit_Smarty 'ambiguous/case1/foobar.tpl#', 'ambiguous/case1/foobar.tpl#compile2', '[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile2', ); - $count = $this->getSmartyObj()->{$this->methodName}(null, 'compile1'); + $count = $this->getSmarty()->clearCompiledTemplate(null, 'compile1'); $this->assertEquals(4, $count); $this->assertEquals($this->expectFiles($expected), $this->getFiles()); @@ -267,12 +262,12 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearOtherCompileid($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); $expected = array_keys($this->_files); - $this->assertEquals(0, $this->getSmartyObj()->{$this->methodName}(null, 'other')); + $this->assertEquals(0, $this->getSmarty()->clearCompiledTemplate(null, 'other')); $this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->clearFiles(); @@ -291,13 +286,13 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearExpired($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); $expected = array('helloworld.tpl#', 'helloworld2.tpl#'); $this->touchFiles(array_diff(array_keys($this->_files), $expected), - 1000); - $this->assertEquals(10, $this->getSmartyObj()->{$this->methodName}(null, null, 500)); + $this->assertEquals(10, $this->getSmarty()->clearCompiledTemplate(null, null, 500)); $this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->clearFiles(); @@ -316,7 +311,7 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearTemplateExpired($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); @@ -327,7 +322,7 @@ class ClearCompiledTest extends PHPUnit_Smarty '[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2', ); $this->touchFiles(array('helloworld.tpl#compile1'), - 1000); - $this->assertEquals(1, $this->getSmartyObj()->{$this->methodName}("helloworld.tpl", null, 500)); + $this->assertEquals(1, $this->getSmarty()->clearCompiledTemplate("helloworld.tpl", null, 500)); $this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->clearFiles(); @@ -346,7 +341,7 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearTemplateCacheidExpired($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); @@ -357,7 +352,7 @@ class ClearCompiledTest extends PHPUnit_Smarty '[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2', ); $this->touchFiles(array('helloworld.tpl#compile1', 'helloworld.tpl#compile2'), - 1000); - $this->assertEquals(1, $this->getSmartyObj()->{$this->methodName}("helloworld.tpl", "compile1", 500)); + $this->assertEquals(1, $this->getSmarty()->clearCompiledTemplate("helloworld.tpl", "compile1", 500)); $this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->clearFiles(); @@ -376,7 +371,7 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearCacheidExpired($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); @@ -387,7 +382,7 @@ class ClearCompiledTest extends PHPUnit_Smarty '[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2', ); $this->touchFiles(array('helloworld.tpl#compile1'), - 1000); - $this->assertEquals(1, $this->getSmartyObj()->{$this->methodName}(null, "compile1", 500)); + $this->assertEquals(1, $this->getSmarty()->clearCompiledTemplate(null, "compile1", 500)); $this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->clearFiles(); @@ -406,7 +401,7 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearTemplateCacheid($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); @@ -416,7 +411,7 @@ class ClearCompiledTest extends PHPUnit_Smarty 'ambiguous/case1/foobar.tpl#', 'ambiguous/case1/foobar.tpl#compile1', 'ambiguous/case1/foobar.tpl#compile2', '[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2', ); - $this->assertEquals(1, $this->getSmartyObj()->{$this->methodName}("helloworld.tpl", "compile1")); + $this->assertEquals(1, $this->getSmarty()->clearCompiledTemplate("helloworld.tpl", "compile1")); $this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->clearFiles(); @@ -434,7 +429,7 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearAmbiguousTemplate($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); @@ -446,7 +441,7 @@ class ClearCompiledTest extends PHPUnit_Smarty 'helloworld2.tpl#', 'helloworld2.tpl#compile1', 'helloworld2.tpl#compile2', '[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2', ); - $this->assertEquals(3, $this->getSmartyObj()->{$this->methodName}("ambiguous/case1/foobar.tpl")); + $this->assertEquals(3, $this->getSmarty()->clearCompiledTemplate("ambiguous/case1/foobar.tpl")); $this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->clearFiles(); diff --git a/tests/UnitTests/SmartyMethodsTests/CompileCheck/CompileCheckTest.php b/tests/UnitTests/SmartyMethodsTests/CompileCheck/CompileCheckTest.php index 48e8730a..2c401b5e 100644 --- a/tests/UnitTests/SmartyMethodsTests/CompileCheck/CompileCheckTest.php +++ b/tests/UnitTests/SmartyMethodsTests/CompileCheck/CompileCheckTest.php @@ -4,7 +4,6 @@ */ class CompileCheckTest extends PHPUnit_Smarty { - public $methodName = null; public function setUp(): void { $this->setUpSmarty(__DIR__); @@ -36,7 +35,7 @@ class CompileCheckTest extends PHPUnit_Smarty * @return void */ private function softResetSmarty() { - $this->smarty = new Smarty(); + $this->smarty = new \Smarty\Smarty(); $this->smarty->addTemplateDir('./templates_tmp'); } @@ -49,7 +48,7 @@ class CompileCheckTest extends PHPUnit_Smarty $this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl')); $this->softResetSmarty(); - $this->smarty->setCompileCheck(Smarty::COMPILECHECK_ON); + $this->smarty->setCompileCheck(\Smarty\Smarty::COMPILECHECK_ON); $this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl')); } @@ -63,12 +62,12 @@ class CompileCheckTest extends PHPUnit_Smarty $this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl')); $this->softResetSmarty(); - $this->smarty->setCompileCheck(Smarty::COMPILECHECK_ON); + $this->smarty->setCompileCheck(\Smarty\Smarty::COMPILECHECK_ON); unlink('./templates_tmp/base.tpl'); sleep(1); - $this->expectException(Exception::class); + $this->expectException(\Smarty\Exception::class); $this->smarty->fetch('base.tpl'); } @@ -81,7 +80,7 @@ class CompileCheckTest extends PHPUnit_Smarty $this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl')); $this->softResetSmarty(); - $this->smarty->setCompileCheck(Smarty::COMPILECHECK_ON); + $this->smarty->setCompileCheck(\Smarty\Smarty::COMPILECHECK_ON); sleep(1); file_put_contents('./templates_tmp/base.tpl', 'hello'); @@ -98,7 +97,24 @@ class CompileCheckTest extends PHPUnit_Smarty $this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl')); $this->softResetSmarty(); - $this->smarty->setCompileCheck(Smarty::COMPILECHECK_OFF); + $this->smarty->setCompileCheck(\Smarty\Smarty::COMPILECHECK_OFF); + + $this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl')); + } + + /** + * @group slow + */ + public function testCompileCheckOff1() + { + $this->makeFiles(); + $this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl')); + + $this->softResetSmarty(); + $this->smarty->setCompileCheck(\Smarty\Smarty::COMPILECHECK_OFF); + + unlink('./templates_tmp/base.tpl'); + sleep(1); $this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl')); } @@ -112,7 +128,7 @@ class CompileCheckTest extends PHPUnit_Smarty $this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl')); $this->softResetSmarty(); - $this->smarty->setCompileCheck(Smarty::COMPILECHECK_OFF); + $this->smarty->setCompileCheck(\Smarty\Smarty::COMPILECHECK_OFF); sleep(1); file_put_contents('./templates_tmp/base.tpl', 'hello'); diff --git a/tests/UnitTests/SmartyMethodsTests/CompileCheck/templates_tmp/.gitignore b/tests/UnitTests/SmartyMethodsTests/CompileCheck/templates_tmp/.gitignore index d88cc144..a0f57452 100644 --- a/tests/UnitTests/SmartyMethodsTests/CompileCheck/templates_tmp/.gitignore +++ b/tests/UnitTests/SmartyMethodsTests/CompileCheck/templates_tmp/.gitignore @@ -1,2 +1,3 @@ # Ignore anything in here, but keep this directory * + diff --git a/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/GetTemplateVarsTest.php b/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/GetTemplateVarsTest.php index 0f356ff3..4aab7c3b 100644 --- a/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/GetTemplateVarsTest.php +++ b/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/GetTemplateVarsTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests getTemplateVars method * - * @package PHPunit + * @author Uwe Tews */ /** * class for getTemplateVars method test * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class GetTemplateVarsTest extends PHPUnit_Smarty { @@ -57,7 +57,7 @@ class GetTemplateVarsTest extends PHPUnit_Smarty $data2 = $this->smarty->createData($data1); $this->smarty->assign('foo', 'bar'); $this->smarty->assign('blar', 'buh'); - $this->assertEquals("bar", $this->smarty->getTemplateVars('foo', $data2)); + $this->assertEquals("bar", $data2->getTemplateVars('foo')); } /** @@ -70,7 +70,7 @@ class GetTemplateVarsTest extends PHPUnit_Smarty $this->smarty->assign('foo', 'bar'); $data1->assign('blar', 'buh'); $data2->assign('foo2', 'bar2'); - $vars = $this->smarty->getTemplateVars(null, $data2); + $vars = $data2->getTemplateVars(null); $this->assertTrue(is_array($vars)); $this->assertEquals("bar", $vars['foo']); $this->assertEquals("bar2", $vars['foo2']); @@ -87,7 +87,7 @@ class GetTemplateVarsTest extends PHPUnit_Smarty $this->smarty->assign('foo', 'bar'); $data1->assign('blar', 'buh'); $data2->assign('foo2', 'bar2'); - $vars = $this->smarty->getTemplateVars(null, $data2, false); + $vars = $data2->getTemplateVars(null, false); $this->assertTrue(is_array($vars)); $this->assertFalse(isset($vars['foo'])); $this->assertEquals("bar2", $vars['foo2']); @@ -105,8 +105,8 @@ class GetTemplateVarsTest extends PHPUnit_Smarty $this->smarty->assign('foo', 'bar'); $data1->assign('blar', 'buh'); $data2->assign('foo2', 'bar2'); - $this->assertEquals("", $this->smarty->getTemplateVars('foo', $data2, false)); - $this->assertEquals("bar2", $this->smarty->getTemplateVars('foo2', $data2, false)); - $this->assertEquals("", $this->smarty->getTemplateVars('blar', $data2, false)); + $this->assertEquals("", $data2->getTemplateVars('foo', false)); + $this->assertEquals("bar2", $data2->getTemplateVars('foo2', false)); + $this->assertEquals("", $data2->getTemplateVars('blar', false)); } } diff --git a/tests/UnitTests/SmartyMethodsTests/RegisterBlock/RegisterBlockTest.php b/tests/UnitTests/SmartyMethodsTests/RegisterBlock/RegisterBlockTest.php index dce15034..1a0564eb 100644 --- a/tests/UnitTests/SmartyMethodsTests/RegisterBlock/RegisterBlockTest.php +++ b/tests/UnitTests/SmartyMethodsTests/RegisterBlock/RegisterBlockTest.php @@ -2,16 +2,19 @@ /** * Smarty PHPunit tests register->block / unregister->block methods * - * @package PHPunit + * @author Uwe Tews */ +use Smarty\Compiler\Template; +use Smarty\Smarty; + /** * class for register->block / unregister->block methods tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class RegisterBlockTest extends PHPUnit_Smarty { @@ -109,8 +112,8 @@ class RegisterBlockTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testRegisterBlockCaching2() @@ -125,8 +128,8 @@ class RegisterBlockTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testRegisterBlockCaching3() @@ -142,24 +145,30 @@ class RegisterBlockTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testRegisterBlockCaching4() { $this->smarty->caching = 1; $this->smarty->cache_lifetime = 1000; - $this->smarty->assign('x', 4); - $this->smarty->assign('y', 40); - $this->smarty->assign('z', 400); - $this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'testblock', 'myblockcache', false); + $this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'testblock', 'myblockcache', false); + + $this->smarty->assign('x', 3); + $this->smarty->assign('y', 30); + $this->smarty->assign('z', 300); + $this->assertEquals('3 30 300', $this->smarty->fetch('test_register_block.tpl')); + + $this->smarty->assign('x', 4); + $this->smarty->assign('y', 40); + $this->smarty->assign('z', 400); $this->assertEquals('3 40 300', $this->smarty->fetch('test_register_block.tpl')); } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testRegisterBlockCaching1Wrapper() @@ -175,8 +184,8 @@ class RegisterBlockTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testRegisterBlockCaching2Wrapper() @@ -191,8 +200,8 @@ class RegisterBlockTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testRegisterBlockCaching3Wrapper() @@ -207,22 +216,40 @@ class RegisterBlockTest extends PHPUnit_Smarty $this->assertEquals('3 30 300', $this->smarty->fetch('test_register_block.tpl')); } - /** - * @runInSeparateProcess - * @preserveGlobalState disabled - * - */ public function testRegisterBlockCaching4Wrapper() { + $this->cleanDirs(); + $this->smarty->caching = 1; $this->smarty->cache_lifetime = 1000; + $this->smarty->registerPlugin('block', 'testblock', 'myblockcache'); + + $this->smarty->assign('x', 3); + $this->smarty->assign('y', 30); + $this->smarty->assign('z', 300); + $this->assertEquals('3 30 300', $this->smarty->fetch('test_register_block.tpl')); + $this->smarty->assign('x', 4); $this->smarty->assign('y', 40); $this->smarty->assign('z', 400); - $this->smarty->registerPlugin('block', 'testblock', 'myblockcache', false); - $this->assertEquals('3 40 300', $this->smarty->fetch('test_register_block.tpl')); + $this->assertEquals('3 30 300', $this->smarty->fetch('test_register_block.tpl')); } + /** + * test register block with handler that supports positional params + */ + public function testRegisterBlockWithPositionalParams() + { + $this->cleanDirs(); + $this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'testblock', blockparamsCompiler::class); + $this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'testblockclose', blockparamsCompiler::class); + $result = $this->smarty->fetch('string:{testblock "foo" "bar"} block + contents + {/testblock}'); + $this->assertStringContainsString('first', $result); + $this->assertStringContainsString('second', $result); + } + /** * test unregister->block method */ @@ -230,14 +257,14 @@ class RegisterBlockTest extends PHPUnit_Smarty { $this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'testblock', 'myblock'); $this->smarty->unregisterPlugin(Smarty::PLUGIN_BLOCK, 'testblock'); - $this->assertFalse(isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK]['testblock'])); + $this->assertNull($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_BLOCK, 'testblock')); } public function testUnregisterBlockWrapper() { $this->smarty->registerPlugin('block', 'testblock', 'myblock'); $this->smarty->unregisterPlugin('block', 'testblock'); - $this->assertFalse(isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK]['testblock'])); + $this->assertNull($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_BLOCK, 'testblock')); } /** @@ -246,7 +273,7 @@ class RegisterBlockTest extends PHPUnit_Smarty public function testUnregisterBlockNotRegistered() { $this->smarty->unregisterPlugin(Smarty::PLUGIN_BLOCK, 'testblock'); - $this->assertFalse(isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK]['testblock'])); + $this->assertNull($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_BLOCK, 'testblock')); } } @@ -272,6 +299,28 @@ function myblockcache($params, $content, &$smarty_tpl, &$repeat) return $content; } +class blockparamsCompiler extends \Smarty\Compile\Base { + + protected $shorttag_order = ["first", "second"]; + protected $optional_attributes = ["first", "second"]; + + public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null) { + $_attr = $this->getAttributes($compiler, $args); + + $output = ''; + if (isset($_attr['first'])) { + $output .= 'first'; + } + + if (isset($_attr['second'])) { + $output .= 'second'; + } + + return $output; + } + +} + class myblockclass { static function static_method($params, $content, &$smarty_tpl, &$repeat) diff --git a/tests/UnitTests/SmartyMethodsTests/RegisterCompiler/RegisterCompilerFunctionTest.php b/tests/UnitTests/SmartyMethodsTests/RegisterCompiler/RegisterCompilerFunctionTest.php index 62494be1..ec2287ad 100644 --- a/tests/UnitTests/SmartyMethodsTests/RegisterCompiler/RegisterCompilerFunctionTest.php +++ b/tests/UnitTests/SmartyMethodsTests/RegisterCompiler/RegisterCompilerFunctionTest.php @@ -2,16 +2,18 @@ /** * Smarty PHPunit tests register->compilerFunction / unregister->compilerFunction methods * - * @package PHPunit + * @author Uwe Tews */ +use Smarty\Smarty; + /** * class for register->compilerFunction / unregister->compilerFunction methods tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class RegisterCompilerFunctionTest extends PHPUnit_Smarty { @@ -31,7 +33,7 @@ class RegisterCompilerFunctionTest extends PHPUnit_Smarty public function testRegisterCompilerFunction() { $this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'testcompilerfunction', 'mycompilerfunction'); - $this->assertEquals('mycompilerfunction', $this->smarty->registered_plugins['compiler']['testcompilerfunction'][0]); + $this->assertEquals('mycompilerfunction', $this->smarty->getRegisteredPlugin('compiler', 'testcompilerfunction')[0]); $this->assertEquals('hello world 1', $this->smarty->fetch('eval:{testcompilerfunction var=1}')); } @@ -72,7 +74,7 @@ class RegisterCompilerFunctionTest extends PHPUnit_Smarty { $this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'testcompilerfunction', 'mycompilerfunction'); $this->smarty->unregisterPlugin(Smarty::PLUGIN_COMPILER, 'testcompilerfunction'); - $this->assertFalse(isset($this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER]['testcompilerfunction'])); + $this->assertNull($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_COMPILER, 'testcompilerfunction')); } /** @@ -81,7 +83,7 @@ class RegisterCompilerFunctionTest extends PHPUnit_Smarty public function testUnregisterCompilerFunctionNotRegistered() { $this->smarty->unregisterPlugin(Smarty::PLUGIN_COMPILER, 'testcompilerfunction'); - $this->assertFalse(isset($this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER]['testcompilerfunction'])); + $this->assertNull($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_COMPILER, 'testcompilerfunction')); } /** @@ -91,7 +93,7 @@ class RegisterCompilerFunctionTest extends PHPUnit_Smarty { $this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'testcompilerfunction', 'mycompilerfunction'); $this->smarty->unregisterPlugin(Smarty::PLUGIN_COMPILER, 'testcompilerfunction'); - $this->assertTrue(isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK]['testcompilerfunction'])); + $this->assertIsArray($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_BLOCK, 'testcompilerfunction')); } } diff --git a/tests/UnitTests/SmartyMethodsTests/RegisterFunction/RegisterFunctionTest.php b/tests/UnitTests/SmartyMethodsTests/RegisterFunction/RegisterFunctionTest.php index 29f44336..6aa91240 100644 --- a/tests/UnitTests/SmartyMethodsTests/RegisterFunction/RegisterFunctionTest.php +++ b/tests/UnitTests/SmartyMethodsTests/RegisterFunction/RegisterFunctionTest.php @@ -2,16 +2,18 @@ /** * Smarty PHPunit tests register/unregister function plugins * - * @package PHPunit + * @author Uwe Tews */ +use Smarty\Smarty; + /** * class for register/unregister function plugins methods tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * * */ class RegisterFunctionTest extends PHPUnit_Smarty @@ -33,7 +35,7 @@ class RegisterFunctionTest extends PHPUnit_Smarty { $this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction'); $this->assertEquals('myfunction', - $this->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ 'testfunction' ][ 0 ]); + $this->smarty->getRegisteredPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction')[0]); $this->assertEquals('hello world 1', $this->smarty->fetch('eval:{testfunction value=1}')); } @@ -59,8 +61,8 @@ class RegisterFunctionTest extends PHPUnit_Smarty /** * test registerPlugin method for function cached * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testRegisterFunctionCaching1() { @@ -76,8 +78,8 @@ class RegisterFunctionTest extends PHPUnit_Smarty /** * test registerPlugin method for function cached * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testRegisterFunctionCaching2() @@ -93,8 +95,8 @@ class RegisterFunctionTest extends PHPUnit_Smarty /** * test registerPlugin method for function not cached * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testRegisterFunctionCaching3() @@ -111,8 +113,8 @@ class RegisterFunctionTest extends PHPUnit_Smarty /** * test registerPlugin method for function not cached * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testRegisterFunctionCaching4() @@ -132,26 +134,26 @@ class RegisterFunctionTest extends PHPUnit_Smarty { $this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction'); $this->smarty->unregisterPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction'); - $this->assertFalse(isset($this->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ 'testfunction' ])); + $this->assertNull($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction')); } /** - * test test unregisterPlugin method for function not registered + * test unregisterPlugin method for function not registered */ public function testUnregisterFunctionNotRegistered() { $this->smarty->unregisterPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction'); - $this->assertFalse(isset($this->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ 'testfunction' ])); + $this->assertNull($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction')); } /** - * test test unregisterPlugin method for function other registered + * test unregisterPlugin method for function other registered */ public function testUnregisterFunctionOtherRegistered() { $this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'testfunction', 'myfunction'); $this->smarty->unregisterPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction'); - $this->assertTrue(isset($this->smarty->registered_plugins[ Smarty::PLUGIN_BLOCK ][ 'testfunction' ])); + $this->assertIsArray($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_BLOCK, 'testfunction')); } } diff --git a/tests/UnitTests/SmartyMethodsTests/RegisterModifier/RegisterModifierTest.php b/tests/UnitTests/SmartyMethodsTests/RegisterModifier/RegisterModifierTest.php index 50b25086..267448d9 100644 --- a/tests/UnitTests/SmartyMethodsTests/RegisterModifier/RegisterModifierTest.php +++ b/tests/UnitTests/SmartyMethodsTests/RegisterModifier/RegisterModifierTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests register->modifier / unregister->modifier methods * - * @package PHPunit + * @author Uwe Tews */ /** * class for register->modifier / unregister->modifier methods tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class RegisterModifierTest extends PHPUnit_Smarty { @@ -30,8 +30,8 @@ class RegisterModifierTest extends PHPUnit_Smarty */ public function testRegisterModifier() { - $this->smarty->registerPlugin(Smarty::PLUGIN_MODIFIER, 'testmodifier', 'mymodifier'); - $this->assertEquals('mymodifier', $this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER]['testmodifier'][0]); + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'testmodifier', 'mymodifier'); + $this->assertEquals('mymodifier', $this->smarty->getRegisteredPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'testmodifier')[0]); $this->smarty->assign('foo', 'foo'); $this->smarty->assign('bar', 'bar'); $this->assertEquals('foo function blar bar', $this->smarty->fetch('eval:{$foo|testmodifier:blar:$bar}')); @@ -42,7 +42,7 @@ class RegisterModifierTest extends PHPUnit_Smarty */ public function testRegisterModifierClass() { - $this->smarty->registerPlugin(Smarty::PLUGIN_MODIFIER, 'testmodifier', array('mymodifierclass', 'static_method')); + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'testmodifier', array('mymodifierclass', 'static_method')); $this->smarty->assign('foo', 'foo'); $this->smarty->assign('bar', 'bar'); $this->assertEquals('foo static blar bar', $this->smarty->fetch('eval:{$foo|testmodifier:blar:$bar}')); @@ -54,7 +54,7 @@ class RegisterModifierTest extends PHPUnit_Smarty public function testRegisterModifierObject() { $obj = new mymodifierclass; - $this->smarty->registerPlugin(Smarty::PLUGIN_MODIFIER, 'testmodifier', array($obj, 'object_method')); + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'testmodifier', array($obj, 'object_method')); $this->smarty->assign('foo', 'foo'); $this->smarty->assign('bar', 'bar'); $this->assertEquals('foo object blar bar', $this->smarty->fetch('eval:{$foo|testmodifier:blar:$bar}')); @@ -65,9 +65,9 @@ class RegisterModifierTest extends PHPUnit_Smarty */ public function testUnregisterModifier() { - $this->smarty->registerPlugin(Smarty::PLUGIN_MODIFIER, 'testmodifier', 'mymodifier'); - $this->smarty->unregisterPlugin(Smarty::PLUGIN_MODIFIER, 'testmodifier'); - $this->assertFalse(isset($this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER]['testmodifier'])); + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'testmodifier', 'mymodifier'); + $this->smarty->unregisterPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'testmodifier'); + $this->assertNull($this->smarty->getRegisteredPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'testmodifier')); } /** @@ -75,8 +75,8 @@ class RegisterModifierTest extends PHPUnit_Smarty */ public function testUnregisterModifierNotRegistered() { - $this->smarty->unregisterPlugin(Smarty::PLUGIN_MODIFIER, 'testmodifier'); - $this->assertFalse(isset($this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER]['testmodifier'])); + $this->smarty->unregisterPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'testmodifier'); + $this->assertNull($this->smarty->getRegisteredPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'testmodifier')); } /** @@ -84,10 +84,67 @@ class RegisterModifierTest extends PHPUnit_Smarty */ public function testUnregisterModifierOtherRegistered() { - $this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'testmodifier', 'mymodifier'); - $this->smarty->unregisterPlugin(Smarty::PLUGIN_MODIFIER, 'testmodifier'); - $this->assertTrue(isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK]['testmodifier'])); + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_BLOCK, 'testmodifier', 'mymodifier'); + $this->smarty->unregisterPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'testmodifier'); + $this->assertIsArray($this->smarty->getRegisteredPlugin(\Smarty\Smarty::PLUGIN_BLOCK, 'testmodifier')); } + + /** + * test cannot call native PHP fuctions by default + * @dataProvider dataUnknownModifiers + */ + public function testNativePHPModifiers($template, $expectedValue) + { + $this->cleanDirs(); + $this->expectException(\Smarty\CompilerException::class); + $this->expectExceptionMessage('unknown modifier'); + $this->smarty->fetch('string:' . $template); + } + + public function dataUnknownModifiers(): array { + return [ + ['{"blah"|substr:1:2}', 'la'], + ['{"blah"|ucfirst}', 'Blah'], + ['{"blah"|md5}', md5('blah')], + ]; + } + + /** + * test register wildcard modifier using extension + * @dataProvider dataUnknownModifiers + */ + public function testUnregisterModifiers($template, $expectedValue) + { + $this->cleanDirs(); + $this->smarty->addExtension(new WildcardExtension()); + $this->assertEquals($expectedValue, $this->smarty->fetch('string:' . $template)); + } + + /** + * test register wildcard modifier using setExtensions + * @dataProvider dataUnknownModifiers + */ + public function testSetExtensions($template, $expectedValue) + { + $this->cleanDirs(); + $this->smarty->setExtensions([ + new \Smarty\Extension\CoreExtension(), + new WildcardExtension() + ]); + $this->assertEquals($expectedValue, $this->smarty->fetch('string:' . $template)); + } + +} + +class WildcardExtension extends \Smarty\Extension\Base { + + public function getModifierCallback(string $modifierName) { + if (is_callable($modifierName)) { + return $modifierName; + } + return null; + } + } function mymodifier($a, $b, $c) diff --git a/tests/UnitTests/SmartyMethodsTests/RegisterObject/CompileRegisteredObjectFunctionTest.php b/tests/UnitTests/SmartyMethodsTests/RegisterObject/CompileRegisteredObjectFunctionTest.php index eaee1360..9aca31fd 100644 --- a/tests/UnitTests/SmartyMethodsTests/RegisterObject/CompileRegisteredObjectFunctionTest.php +++ b/tests/UnitTests/SmartyMethodsTests/RegisterObject/CompileRegisteredObjectFunctionTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of registered object functions * - * @package PHPunit + * @author Uwe Tews */ /** * class for registered object function tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class CompileRegisteredObjectFunctionTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/SmartyMethodsTests/TemplateExist/TemplateExistsTest.php b/tests/UnitTests/SmartyMethodsTests/TemplateExist/TemplateExistsTest.php index 92e0d9c7..2917982a 100644 --- a/tests/UnitTests/SmartyMethodsTests/TemplateExist/TemplateExistsTest.php +++ b/tests/UnitTests/SmartyMethodsTests/TemplateExist/TemplateExistsTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests for templateExists method * - * @package PHPunit + * @author Uwe Tews */ /** * class for templateExists tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class TemplateExistsTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/Comments/CommentsTest.php b/tests/UnitTests/TemplateSource/Comments/CommentsTest.php index b8bd2cc8..443ac39e 100644 --- a/tests/UnitTests/TemplateSource/Comments/CommentsTest.php +++ b/tests/UnitTests/TemplateSource/Comments/CommentsTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests comments in templates * - * @package PHPunit + * @author Uwe Tews */ /** * class for security test * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class CommentsTest extends PHPUnit_Smarty { @@ -28,7 +28,7 @@ class CommentsTest extends PHPUnit_Smarty /** * Test comments * - * @preserveGlobalState disabled + * * @dataProvider dataTestComments */ public function testComments($code, $result, $testName, $testNumber) @@ -36,7 +36,7 @@ class CommentsTest extends PHPUnit_Smarty $name = empty($testName) ? $testNumber : $testName; $file = "testComments_{$name}.tpl"; $this->makeTemplateFile($file, $code); - $this->smarty->template_dir = './templates_tmp'; + $this->smarty->setTemplateDir('./templates_tmp'); $this->assertEquals($result, $this->smarty->fetch($file), $file); diff --git a/tests/UnitTests/TemplateSource/NullCoalescingTest.php b/tests/UnitTests/TemplateSource/NullCoalescingTest.php new file mode 100644 index 00000000..2432527a --- /dev/null +++ b/tests/UnitTests/TemplateSource/NullCoalescingTest.php @@ -0,0 +1,34 @@ +<?php + +class NullCoalescingTest extends PHPUnit_Smarty { + + public function setUp(): void + { + $this->setUpSmarty('/tmp'); + $this->cleanDirs(); + } + + public function testUndefined() { + $tpl = $this->smarty->createTemplate('string:{$myvar ?? "undefined"}'); + $this->assertEquals('undefined', $this->smarty->fetch($tpl)); + } + + /** + * @dataProvider dataForOther + */ + public function testOther($value, $expected) { + $tpl = $this->smarty->createTemplate('string:{$myvar ?? "undefined"}'); + $tpl->assign('myvar', $value); + $this->assertEquals($expected, $this->smarty->fetch($tpl)); + } + + public function dataForOther() { + return [ + [null, 'undefined'], + ['blah', 'blah'], + ['', ''], + [false, false], + ]; + } + +} diff --git a/tests/UnitTests/TemplateSource/Spacing/SpacingTest.php b/tests/UnitTests/TemplateSource/Spacing/SpacingTest.php index 7f92fb03..098d9eb8 100644 --- a/tests/UnitTests/TemplateSource/Spacing/SpacingTest.php +++ b/tests/UnitTests/TemplateSource/Spacing/SpacingTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests spacing in template output * - * @package PHPunit + * @author Uwe Tews */ /** * class for spacing test * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class SpacingTest extends PHPUnit_Smarty { @@ -28,16 +28,16 @@ class SpacingTest extends PHPUnit_Smarty /** * Test spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testSpacing($code, $result, $testName, $testNumber) { $name = empty($testName) ? $testNumber : $testName; $file = "Spacing_{$name}.tpl"; $this->makeTemplateFile($file, $code); - $this->smarty->template_dir = './templates_tmp'; + $this->smarty->setTemplateDir('./templates_tmp'); $this->smarty->assign('file', $file); $this->smarty->assign('foo', 'bar'); $this->assertEquals($result, diff --git a/tests/UnitTests/TemplateSource/StaticClass/StaticClassAccessTest.php b/tests/UnitTests/TemplateSource/StaticClass/StaticClassAccessTest.php index b3fbdb18..7836172c 100644 --- a/tests/UnitTests/TemplateSource/StaticClass/StaticClassAccessTest.php +++ b/tests/UnitTests/TemplateSource/StaticClass/StaticClassAccessTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests static class access to constants, variables and methods * - * @package PHPunit + * @author Uwe Tews */ /** * class for static class access to constants, variables and methods tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class StaticClassAccessTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TagTests/Append/CompileAppendTest.php b/tests/UnitTests/TemplateSource/TagTests/Append/CompileAppendTest.php index 4590982b..dc99abcf 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Append/CompileAppendTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Append/CompileAppendTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of append tags * - * @package PHPunit + * @author Uwe Tews */ /** * class for append tags tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class CompileAppendTest extends PHPUnit_Smarty { @@ -32,8 +32,8 @@ class CompileAppendTest extends PHPUnit_Smarty /** * Test {append} tags * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider dataTestAppend */ public function testAppend($code, $result, $testName, $testNumber) @@ -70,9 +70,9 @@ class CompileAppendTest extends PHPUnit_Smarty /** * Test Assign spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testAppendSpacing($code, $result, $testName, $testNumber) { @@ -88,9 +88,9 @@ class CompileAppendTest extends PHPUnit_Smarty /** * Test Append nocache spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testAppendSpacingNocache($code, $result, $testName, $testNumber) { @@ -107,9 +107,9 @@ class CompileAppendTest extends PHPUnit_Smarty /** * Test Append nocache spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testAppendSpacingNocache2($code, $result, $testName, $testNumber) { @@ -118,6 +118,12 @@ class CompileAppendTest extends PHPUnit_Smarty $this->smarty->setCompileId('1'); $this->smarty->setCaching(1); $this->smarty->setTemplateDir('./templates_tmp'); + + $this->smarty->assign('foo', 'bar',true); + $this->assertEquals($result, + $this->smarty->fetch($file), + "testSpacing - {$file}"); + $this->smarty->assign('foo', 'foo',true); $this->assertEquals(str_replace('bar','foo',$result), $this->smarty->fetch($file), diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/CompileAssignTest.php b/tests/UnitTests/TemplateSource/TagTests/Assign/CompileAssignTest.php index d9be6c7c..e654efa2 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/CompileAssignTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/CompileAssignTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of assign tags * - * @package PHPunit + * @author Uwe Tews */ /** * class for assign tags tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class CompileAssignTest extends PHPUnit_Smarty { @@ -33,7 +33,7 @@ class CompileAssignTest extends PHPUnit_Smarty * Test assign tags * * @not runInSeparateProcess - * @preserveGlobalState disabled + * * @dataProvider dataTestAssign */ public function testAssign($code, $result, $testName, $testNumber) @@ -93,9 +93,9 @@ class CompileAssignTest extends PHPUnit_Smarty /** * Test Assign spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testAssignSpacing($code, $result, $testName, $testNumber) { @@ -111,9 +111,9 @@ class CompileAssignTest extends PHPUnit_Smarty /** * Test Output nocache spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testAssignSpacingNocache($code, $result, $testName, $testNumber) { @@ -130,9 +130,9 @@ class CompileAssignTest extends PHPUnit_Smarty /** * Test Output nocache spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testAssignSpacingNocache2($code, $result, $testName, $testNumber) { diff --git a/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/CompileBlockPluginTest.php b/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/CompileBlockPluginTest.php index 1c3e8b2e..328cd4c1 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/CompileBlockPluginTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/CompileBlockPluginTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of block plugins * - * @package PHPunit + * @author Uwe Tews */ /** * class for block plugin tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class CompileBlockPluginTest extends PHPUnit_Smarty { @@ -50,97 +50,71 @@ class CompileBlockPluginTest extends PHPUnit_Smarty */ public function testBlockPluginUnknown() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('unknown tag \'bar\''); $this->assertEquals("hello world", $this->smarty->fetch('unknown.tpl')); } /** * test block plugin function definition in script - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testBlockPluginRegisteredFunction() { - $this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'blockplugintest', 'myblockplugintest'); + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_BLOCK, 'blockplugintest', 'myblockplugintest'); $this->assertEquals('block test', $this->smarty->fetch('registered.tpl')); } /** * test block plugin function definition in script - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testBlockPluginRegisteredFunction2() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('block tag \'blockplugintest\' not callable'); $this->assertEquals('block test', $this->smarty->fetch('registered.tpl')); } /** * test block plugin static method - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testBlockPluginRegisteredStatic() { - $this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'blockpluginstatic', array('myblockclass1', 'staticfunc')); + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_BLOCK, 'blockpluginstatic', array('myblockclass1', 'staticfunc')); $this->assertEquals('static block test', $this->smarty->fetch('registered_static.tpl')); } /** * test block plugin static method failure - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testBlockPluginRegisteredStatic2() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('block tag \'blockpluginstatic\' not callable'); $this->assertEquals('static block test', $this->smarty->fetch('registered_static.tpl')); } /** * test block plugin object method - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testBlockPluginRegisteredMethod() { $object = new myblockclass1(); - $this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'blockpluginmethod', array($object, 'methodfunc')); + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_BLOCK, 'blockpluginmethod', array($object, 'methodfunc')); $this->assertEquals('method block test', $this->smarty->fetch('registered_method.tpl')); } /** * test block plugin object method failure - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testBlockPluginRegisteredMethod2() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('block tag \'blockpluginmethod\' not callable'); $this->assertEquals('method block test', $this->smarty->fetch('registered_method.tpl')); } /** * test block plugin registered object - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testBlockPluginRegisteredObject() { @@ -151,23 +125,16 @@ class CompileBlockPluginTest extends PHPUnit_Smarty /** * test block plugin registered object failure - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function testBlockPluginRegisteredObject2() { - $this->expectException('SmartyException'); - $this->expectExceptionMessage('block tag \'myobject\' not callable'); + $this->expectException(\Smarty\Exception::class); + $this->expectExceptionMessage('block tag \'myobject\' not callable or registered'); $this->assertEquals('object block test', $this->smarty->fetch('registered_object.tpl')); } /** * test block plugin repeat function - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testBlockPluginRepeat() { @@ -176,10 +143,6 @@ class CompileBlockPluginTest extends PHPUnit_Smarty /** * test block plugin repeat function with modifier - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testBlockPluginRepeatModidier1() { @@ -188,10 +151,6 @@ class CompileBlockPluginTest extends PHPUnit_Smarty /** * test block plugin repeat function with modifier list - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testBlockPluginRepeatModidier2() { @@ -200,10 +159,6 @@ class CompileBlockPluginTest extends PHPUnit_Smarty /** * test block plugin with no output - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testBlockPluginNoOutput() { @@ -212,10 +167,6 @@ class CompileBlockPluginTest extends PHPUnit_Smarty /** * test nested block plugin - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testBlockPluginNested() { @@ -224,10 +175,6 @@ class CompileBlockPluginTest extends PHPUnit_Smarty /** * test default block plugin - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testBlockPluginDefault1() { @@ -237,10 +184,6 @@ class CompileBlockPluginTest extends PHPUnit_Smarty /** * test default block plugin - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * */ public function testBlockPluginDefault2() { @@ -249,25 +192,9 @@ class CompileBlockPluginTest extends PHPUnit_Smarty } /** - * test tag stack - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * - */ - public function testBlockPluginTagStack() - { - $this->assertEquals('noop-teststack', $this->smarty->fetch('tag_stack.tpl')); - $this->assertEmpty($this->smarty->_cache[ '_tag_stack' ]); - } - - /** * Test caching * - * @runInSeparateProcess - * @preserveGlobalState disabled * @dataProvider data - * */ public function testCache($isCached, $caching, @@ -281,8 +208,8 @@ class CompileBlockPluginTest extends PHPUnit_Smarty $testName) { $this->smarty->registerFilter('pre', array($this, 'prefilterTest')); - $this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'cachetest', 'myblockplugintest2', $cachable); - $this->smarty->compile_id = $compileid; + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_BLOCK, 'cachetest', 'myblockplugintest2', $cachable); + $this->smarty->setCompileId($compileid); $this->smarty->caching = $caching; $this->smarty->cache_lifetime = 1000; $this->smarty->assign('test', $testNumber); @@ -317,9 +244,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty /** * Test spacings * - * @preserveGlobalState disabled * @dataProvider dataTestSpacing - * @runInSeparateProcess */ public function testSpacing($code, $result, $testName, $testNumber) { @@ -358,9 +283,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty /** * Test spacings * - * @preserveGlobalState disabled * @dataProvider dataTestDefaultSpacing - * @runInSeparateProcess */ public function testSpacingDefault($code, $result, $testName, $testNumber) { @@ -369,7 +292,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty $this->makeTemplateFile($file, $code); $this->smarty->setTemplateDir('./templates_tmp'); $this->smarty->registerDefaultPluginHandler('my_block_plugin_handler'); - $this->smarty->compile_id='default'; + $this->smarty->setCompileId('default'); $this->smarty->assign('foo', 'bar'); $this->assertEquals($result, $this->smarty->fetch($file), @@ -402,9 +325,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty /** * Test nocache block spacings * - * @preserveGlobalState disabled * @dataProvider dataTestNocacheSpacing - * @runInSeparateProcess */ public function testBlockNocache($code, $result, $testName, $testNumber) { @@ -422,9 +343,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty /** * Test nocache block spacings * - * @preserveGlobalState disabled * @dataProvider dataTestNocacheSpacing - * @runInSeparateProcess */ public function testBlockNocache2($code, $result, $testName, $testNumber) { @@ -459,7 +378,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty } } -function myblockplugintest($params, $content, &$smarty_tpl, &$repeat) +function myblockplugintest($params, $content, $smarty_tpl, &$repeat) { if (!$repeat) { $output = str_replace('hello world', 'block test', $content); @@ -468,7 +387,7 @@ function myblockplugintest($params, $content, &$smarty_tpl, &$repeat) } } -function myblockplugintest2($params, $content, &$smarty_tpl, &$repeat) +function myblockplugintest2($params, $content, $smarty_tpl, &$repeat) { if (!$repeat) { $output = str_replace('hello world', "block test{$params['var']}", $content); @@ -479,7 +398,7 @@ function myblockplugintest2($params, $content, &$smarty_tpl, &$repeat) class myblockclass1 { - static function staticfunc($params, $content, &$smarty_tpl, &$repeat) + static function staticfunc($params, $content, $smarty_tpl, &$repeat) { if (!$repeat) { $output = str_replace('hello world', 'static block test', $content); @@ -487,7 +406,7 @@ class myblockclass1 } } - public function methodfunc($params, $content, &$smarty_tpl, &$repeat) + public function methodfunc($params, $content, $smarty_tpl, &$repeat) { if (!$repeat) { $output = str_replace('hello world', 'method block test', $content); @@ -495,7 +414,7 @@ class myblockclass1 } } - public function objectfunc($params, $content, &$smarty_tpl, &$repeat) + public function objectfunc($params, $content, $smarty_tpl, &$repeat) { if (!$repeat) { $output = str_replace('hello world', 'object block test', $content); @@ -507,11 +426,11 @@ class myblockclass1 function my_block_plugin_handler($tag, $type, $template, &$callback, &$script, &$cachable) { switch ($type) { - case Smarty::PLUGIN_BLOCK: + case \Smarty\Smarty::PLUGIN_BLOCK: switch ($tag) { case 'scriptblock': - $script = './scripts/script_block_tag.php'; - $callback = 'default_script_block_tag'; + $script = './scripts/script_block_tag2.php'; + $callback = 'default_script_block_tag2'; return true; default: diff --git a/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.noop.php b/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.noop.php index 0e163e59..fbd5e693 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.noop.php +++ b/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.noop.php @@ -2,8 +2,8 @@ /** * Smarty plugin for testing block plugins * - * @package Smarty - * @subpackage PHPunitPlugin + + */ /** diff --git a/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.nooutput.php b/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.nooutput.php index 398c9a3b..ce59bc43 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.nooutput.php +++ b/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.nooutput.php @@ -2,8 +2,8 @@ /** * Smarty plugin for testing block plugins * - * @package Smarty - * @subpackage PHPunitPlugin + + */ /** diff --git a/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.testblock.php b/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.testblock.php index 63f1108a..b56dad97 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.testblock.php +++ b/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.testblock.php @@ -2,8 +2,8 @@ /** * Smarty plugin for testing block plugins * - * @package Smarty - * @subpackage PHPunitPlugin + + */ /** diff --git a/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.testparameter.php b/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.testparameter.php index bdac3291..0c8f616e 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.testparameter.php +++ b/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.testparameter.php @@ -2,20 +2,23 @@ /** * Smarty plugin for testing block plugins * - * @package Smarty - * @subpackage PHPunitPlugin + + */ + +use Smarty\Template; + /** * Smarty {testparameter}{/testparameter} block plugin * * @param array $params parameter array * @param string $content contents of the block - * @param \Smarty_Internal_Template $template template object + * @param \Smarty\Template $template template object * @param bool $repeat flag * * @return string content re-formatted */ -function smarty_block_testparameter($params, $content, Smarty_Internal_Template $template, &$repeat) +function smarty_block_testparameter($params, $content, Template $template, &$repeat) { if (isset($content)) { return $content; diff --git a/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.teststack.php b/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.teststack.php deleted file mode 100644 index f1eef38d..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/PHPunitplugins/block.teststack.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php -/** - * Smarty plugin for testing block plugins - * - * @package Smarty - * @subpackage PHPunitPlugin - */ - -/** - * Smarty {teststack}{/teststack} block plugin - * - * @param array $params parameter array - * @param string $content contents of the block - * @param object $template template object - * @param bool $repeat flag - * - * @return string content re-formatted - */ -function smarty_block_teststack($params, $content, $template, &$repeat) -{ - if (isset($content)) { - $stack = $template->smarty->_cache['_tag_stack']; - return $stack[0][0] . '-' . $stack[1][0]; - } -} diff --git a/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/scripts/script_block_tag.php b/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/scripts/script_block_tag2.php index a61f14d6..71497a40 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/scripts/script_block_tag.php +++ b/tests/UnitTests/TemplateSource/TagTests/BlockPlugin/scripts/script_block_tag2.php @@ -1,5 +1,5 @@ <?php -function default_script_block_tag($params, $content, $template, &$repeat) +function default_script_block_tag2($params, $content, $template, &$repeat) { if (isset($content)) { return 'scriptblock ' . $content; diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php b/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php index b14eab67..1b0ee50f 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php @@ -2,16 +2,14 @@ /** * Smarty PHPunit tests for Block Extends * - * @package PHPunit + * @author Uwe Tews */ +use Smarty\Template; + /** * class for block extends compiler tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled */ class CompileBlockExtendsTest extends PHPUnit_Smarty { @@ -21,7 +19,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty //$this->smarty->setMergeCompiledIncludes(true); } - public function compiledPrefilter($text, Smarty_Internal_Template $tpl) + public function compiledPrefilter($text, Template $tpl) { return str_replace('#', $tpl->getTemplateVars('test'), $text); } @@ -60,8 +58,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test child/parent template chain * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockChild_002($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, @@ -85,8 +83,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test child/parent template chain with prepend * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockChildPrepend_003($caching, $merge, $testNumber, $compileTestNumber, @@ -111,8 +109,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test child/parent template chain with prepend * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockGrandPrepend_003($caching, $merge, $testNumber, $compileTestNumber, @@ -138,8 +136,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test child/parent template chain with apppend * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockChildAppend_004($caching, $merge, $testNumber, $compileTestNumber, @@ -165,8 +163,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test grandchild/parent template chain with apppend * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockGrandAppend_004($caching, $merge, $testNumber, $compileTestNumber, @@ -192,8 +190,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test grandchild/parent template chain with apppend * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockGrandAppendPrepend_004($caching, $merge, $testNumber, $compileTestNumber, @@ -219,8 +217,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test child/parent template chain with apppend and shorttags * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockChildAppendShortag_005($caching, $merge, $testNumber, $compileTestNumber, @@ -245,8 +243,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test child/parent template chain with {$this->smarty.block.child) * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockChildSmartyChild_006($caching, $merge, $testNumber, $compileTestNumber, @@ -271,8 +269,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test child/parent template chain with {$this->smarty.block.parent) * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockChildSmartyParent_007($caching, $merge, $testNumber, $compileTestNumber, @@ -298,8 +296,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test grandchild/child/parent template chain with {$this->smarty.block.parent) * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockChildSmartyParent_007_2($caching, $merge, $testNumber, $compileTestNumber, @@ -325,8 +323,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test child/parent template chain loading plugin * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockChildPlugin_008($caching, $merge, $testNumber, $compileTestNumber, @@ -352,8 +350,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test parent template with nested blocks * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockParentNested_009($caching, $merge, $testNumber, $compileTestNumber, @@ -377,8 +375,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test child/parent template chain with nested block * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockChildNested_010($caching, $merge, $testNumber, $compileTestNumber, @@ -403,8 +401,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test child/parent template chain with nested block and include * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockChildNestedInclude_011($caching, $merge, $testNumber, $compileTestNumber, @@ -430,8 +428,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test template chain with nested block level test * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockChildNestedInclude_012($caching, $merge, $testNumber, $compileTestNumber, @@ -457,8 +455,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test nested child block with hide * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockChildNestedHide_018($caching, $merge, $testNumber, $compileTestNumber, @@ -481,8 +479,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test nested grand/child block with hide * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockChildNestedHide_018_2($caching, $merge, $testNumber, $compileTestNumber, @@ -505,8 +503,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test nested grandgrand/grand/child block with hide * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockChildNestedHide_018_3($caching, $merge, $testNumber, $compileTestNumber, @@ -529,8 +527,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test child/parent template chain starting in subtempates * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockStartSubTemplates_020($caching, $merge, $testNumber, $compileTestNumber, @@ -557,8 +555,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test grandchild/child/parent dependency test1 * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testCompileBlockGrandChildMustCompile_021_1() { @@ -573,7 +571,6 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty $result = $this->smarty->fetch($tpl); $this->assertStringContainsString('(grand|b)content grand b(grand|/b)(child|b)content child b(child|/b)(parent|b)content parent b(parent|/b)', $result); - $this->smarty->_clearTemplateCache(); $this->smarty->assign('parent', 'parent2'); $this->smarty->assign('child', 'child2', true); $this->smarty->assign('grand', 'grand2', true); @@ -587,8 +584,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test grandchild/child/parent dependency test1 * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testCompileBlockGrandChildMustCompile_021_12() { @@ -607,9 +604,6 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test grandchild/child/parent dependency test2 - * - * @runInSeparateProcess - * @preserveGlobalState disabled * @group slow */ public function testCompileBlockGrandChildMustCompile_021_2() @@ -628,7 +622,6 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty $result = $this->smarty->fetch($tpl); $this->assertStringContainsString('(grand|b)content grand4 b(grand|/b)(child|b)content child4 b(child|/b)(parent|b)content parent4 b(parent|/b)', $result); - $this->smarty->_clearTemplateCache(); $this->smarty->assign('parent', 'parent5'); $this->smarty->assign('child', 'child5', true); $this->smarty->assign('grand', 'grand5', true); @@ -642,9 +635,6 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test grandchild/child/parent dependency test3 - * - * @runInSeparateProcess - * @preserveGlobalState disabled * @group slow */ public function testCompileBlockGrandChildMustCompile_021_3() @@ -668,8 +658,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test grandchild/child/parent dependency test3 * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @group slow */ public function testCompileBlockGrandChildMustCompile_021_32() @@ -689,9 +679,6 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test grandchild/child/parent dependency test4 - * - * @runInSeparateProcess - * @preserveGlobalState disabled * @group slow */ public function testCompileBlockGrandChildMustCompile_021_4() @@ -715,8 +702,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test grandchild/child/parent dependency test4 * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @group slow */ public function testCompileBlockGrandChildMustCompile_021_42() @@ -757,7 +744,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty */ public function testSmartyBlockChildOutsideBlock_025() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('\'{$smarty.block.child}\' used outside {block} tags'); $this->smarty->fetch('025_parent.tpl'); } @@ -767,7 +754,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty */ public function testSmartyBlockParentOutsideBlock_026() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('\'{$smarty.block.parent}\' used outside {block} tags'); $this->smarty->fetch('026_child.tpl'); } @@ -777,7 +764,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty */ public function testSmartyBlockParentInParent_027() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('illegal \'{$smarty.block.parent}\''); $this->smarty->fetch('027_parent.tpl'); } @@ -785,8 +772,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test child/parent template chain * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testSmartyBlockVariablePartentInclude_28($caching, $merge, $testNumber, $compileTestNumber, @@ -832,8 +819,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test grandchild/child/parent template chain with nested {$this->smarty.block.child} and {include nocache} * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockGrandChildNested_030($caching, $merge, $testNumber, $compileTestNumber, @@ -855,8 +842,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test grandchild/child/parent template chain with nested {$this->smarty.block.child} and {include nocache} * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockGrandChildNestedRelative_030($caching, $merge, $testNumber, $compileTestNumber, @@ -878,8 +865,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test grandchild/child/parent template chain with nested {$this->smarty.block.child} and {include nocache} * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockSmartyBlockParent_034_1($caching, $merge, $testNumber, $compileTestNumber, @@ -897,77 +884,12 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty $this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure'); } - /** - * test grandchild/child/parent template chain with nested {$this->smarty.block.child} and {include nocache} - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider data - */ - public function testCompileBlockSmartyBlockParent_034_2($caching, $merge, $testNumber, $compileTestNumber, - $renderTestNumber, $testName) - { - $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); - $this->smarty->assign('test', $testNumber); - $this->smarty->setCaching($caching); - $this->smarty->setMergeCompiledIncludes($merge); - if ($merge) { - $this->smarty->setCompileId(1); - } - $result = $this->smarty->fetch('034_2child.tpl'); - $this->assertStringContainsString('parent b1', $result, $testName . ' - content'); - $this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, - $testName . ' - fetch() failure'); - } - /** - * test grandchild/child/parent template chain with nested {$this->smarty.block.child} and {include nocache} - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider data - */ - public function testCompileBlockSmartyBlockParent_034_3($caching, $merge, $testNumber, $compileTestNumber, - $renderTestNumber, $testName) - { - $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); - $this->smarty->assign('test', $testNumber); - $this->smarty->setCaching($caching); - $this->smarty->setMergeCompiledIncludes($merge); - if ($merge) { - $this->smarty->setCompileId(1); - } - $result = $this->smarty->fetch('034_3child.tpl'); - $this->assertStringContainsString('parent b1', $result, $testName . ' - content'); - $this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, - $testName . ' - fetch() failure'); - } - /** - * test grandchild/child/parent template chain with nested {$this->smarty.block.child} and {include nocache} - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider data - */ - public function testCompileBlockSmartyBlockParent_034_4($caching, $merge, $testNumber, $compileTestNumber, - $renderTestNumber, $testName) - { - $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); - $this->smarty->assign('test', $testNumber); - $this->smarty->setCaching($caching); - $this->smarty->setMergeCompiledIncludes($merge); - if ($merge) { - $this->smarty->setCompileId(1); - } - $result = $this->smarty->fetch('034_4child.tpl'); - $this->assertStringContainsString('parent b1', $result, $testName . ' - content'); - $this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, - $testName . ' - fetch() failure'); - } + /** * test child/parent template chain with {$this->smarty.block.child) * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockSmartyBlockChild_035_1($caching, $merge, $testNumber, $compileTestNumber, @@ -990,87 +912,6 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty $testName . ' - fetch() failure'); } - /** - * test child/parent template chain with {$this->smarty.block.child) - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider data - */ - public function testCompileBlockSmartyBlockChild_035_2($caching, $merge, $testNumber, $compileTestNumber, - $renderTestNumber, $testName) - { - $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); - $this->smarty->assign('test', $testNumber); - $this->smarty->assign('parenttpl', '035_2parent.tpl'); - $this->smarty->assign('parent', 'parent', true); - $this->smarty->assign('child', 'child', true); - $this->smarty->setCaching($caching); - $this->smarty->setMergeCompiledIncludes($merge); - if ($merge) { - $this->smarty->setCompileId(1); - } - $result = $this->smarty->fetch('035_child.tpl'); - $this->assertStringContainsString('(parent|b)content (child|b)content child b(child|/b) b(parent|/b)', $result, - $testName . ' - content'); - $this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, - $testName . ' - fetch() failure'); - } - /** - * test child/parent template chain with {$this->smarty.block.child) - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider data - */ - public function testCompileBlockSmartyBlockChild_035_3($caching, $merge, $testNumber, $compileTestNumber, - $renderTestNumber, $testName) - { - $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); - $this->smarty->assign('test', $testNumber); - $this->smarty->assign('parenttpl', '035_3parent.tpl'); - $this->smarty->assign('parent', 'parent', true); - $this->smarty->assign('child', 'child', true); - $this->smarty->setCaching($caching); - $this->smarty->setMergeCompiledIncludes($merge); - if ($merge) { - $this->smarty->setCompileId(1); - } - $result = $this->smarty->fetch('035_child.tpl'); - $this->assertStringContainsString('(parent|b)content (child|b)content child b(child|/b) b(parent|/b)', $result, - $testName . ' - content'); - $this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, - $testName . ' - fetch() failure'); - } - /** - * test child/parent template chain with {$this->smarty.block.child) - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider data - */ - public function testCompileBlockSmartyBlockChild_035_4($caching, $merge, $testNumber, $compileTestNumber, - $renderTestNumber, $testName) - { - $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); - $this->smarty->assign('test', $testNumber); - $this->smarty->assign('parenttpl', '035_4parent.tpl'); - $this->smarty->assign('parent', 'parent', true); - $this->smarty->assign('child', 'child', true); - $this->smarty->setCaching($caching); - $this->smarty->setMergeCompiledIncludes($merge); - if ($merge) { - $this->smarty->setCompileId(1); - } - $result = $this->smarty->fetch('035_child.tpl'); - $this->assertStringContainsString('(parent|b)content (child|b)content child b(child|/b) b(parent|/b)', $result, - $testName . ' - content'); - $this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, - $testName . ' - fetch() failure'); - } - - - public function data() { return array(/* @@ -1096,7 +937,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty */ public function testPostFilter_031() { - function smarty_postfilter_test031($compiled, Smarty_Internal_Template $template) + function smarty_postfilter_test031($compiled, Template $template) { return str_replace("'foo'", "'bar'", $compiled); } @@ -1121,8 +962,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test relative includes in {block} * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider data */ public function testCompileBlockRelativeIncludes_033($caching, $merge, $testNumber, $compileTestNumber, @@ -1147,7 +988,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty */ public function testSmartyBlockWrongBlockName_036() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('$smarty.block is not defined'); $this->smarty->fetch('036_parent.tpl'); } @@ -1156,35 +997,16 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty */ public function testSmartyParentBlockCalledInParent_036_1() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('inheritance: illegal \'{$smarty.block.parent}\' used in child template'); $this->smarty->fetch('036_1_parent.tpl'); } /** - * test {block_parent} - */ - public function testSmartyParentBlockCalledInParent_036_2() - { - $this->expectException('SmartyException'); - $this->expectExceptionMessage('inheritance: illegal \'{block_parent}\' used in child template'); - $this->smarty->fetch('036_2_parent.tpl'); - } - /** - * test {block_parent} - */ - public function testSmartyParentBlockCalledInParent_036_3() - { - $this->expectException('SmartyException'); - $this->expectExceptionMessage('inheritance: illegal \'{parent}\' used in child template'); - $this->smarty->fetch('036_3_parent.tpl'); - } - - /** * test smarty.block */ public function testSmartyBlockMissigBlockName_037() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('$smarty.block is not defined'); $this->smarty->fetch('037_parent.tpl'); } @@ -1192,9 +1014,9 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * Test spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testSpacing($code, $result, $testName, $testNumber) { @@ -1210,9 +1032,9 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * Test Output nocache spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testBlockSpacingNocache($code, $result, $testName, $testNumber) { @@ -1229,9 +1051,9 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * Test Output nocache spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testBlockSpacingNocache2($code, $result, $testName, $testNumber) { @@ -1268,9 +1090,9 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * Test spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestChildSpacing - * @runInSeparateProcess + * */ public function testChildSpacing($code, $result, $testName, $testNumber) { @@ -1317,9 +1139,9 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * Test Block nocache spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestBlockNocache - * @runInSeparateProcess + * */ public function testBlockNocacheSpacing($code, $result, $name, $testNumber) { @@ -1336,9 +1158,9 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * Test Block nocache spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestBlockNocache - * @runInSeparateProcess + * */ public function testBlockNocacheSpacing2($code, $result, $name, $testNumber) { @@ -1352,7 +1174,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty "blockNocache - {$file}"); } /* - * Data provider für TestBlockNocache + * Data provider for TestBlockNocache */ public function dataTestBlockNocache() { diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_2child.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_2child.tpl deleted file mode 100644 index 07ff346b..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_2child.tpl +++ /dev/null @@ -1,2 +0,0 @@ -{extends '034_parent.tpl'} -{block 'b1'}{parent assign='foo'}{$foo}{/block}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_3child.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_3child.tpl deleted file mode 100644 index a4e701b0..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_3child.tpl +++ /dev/null @@ -1,2 +0,0 @@ -{extends '034_parent.tpl'} -{block 'b1'}{parent}{/block}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_4child.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_4child.tpl deleted file mode 100644 index 431145fd..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_4child.tpl +++ /dev/null @@ -1,2 +0,0 @@ -{extends '034_parent.tpl'} -{block 'b1'}{block_parent}{/block}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_2parent.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_2parent.tpl deleted file mode 100644 index 06fed627..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_2parent.tpl +++ /dev/null @@ -1,2 +0,0 @@ -test:{$test nocache} compiled:# rendered:{$test} -{block name='b'}(parent|b)content {child assign='foo'}{$foo} b(parent|/b){/block}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_3parent.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_3parent.tpl deleted file mode 100644 index 1ada9dfa..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_3parent.tpl +++ /dev/null @@ -1,2 +0,0 @@ -test:{$test nocache} compiled:# rendered:{$test} -{block name='b'}(parent|b)content {child} b(parent|/b){/block}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_4parent.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_4parent.tpl deleted file mode 100644 index 9cea0612..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_4parent.tpl +++ /dev/null @@ -1,2 +0,0 @@ -test:{$test nocache} compiled:# rendered:{$test} -{block name='b'}(parent|b)content {block_child} b(parent|/b){/block}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_2_parent.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_2_parent.tpl deleted file mode 100644 index f96cb679..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_2_parent.tpl +++ /dev/null @@ -1 +0,0 @@ -{block name='b'}{block_parent}{/block}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_3_parent.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_3_parent.tpl deleted file mode 100644 index 6c8516f2..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_3_parent.tpl +++ /dev/null @@ -1 +0,0 @@ -{block name='b'}{parent}{/block}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Capture/CompileCaptureTest.php b/tests/UnitTests/TemplateSource/TagTests/Capture/CompileCaptureTest.php index 8c1c7d6d..97a3c54f 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Capture/CompileCaptureTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Capture/CompileCaptureTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of capture tags * - * @package PHPunit + * @author Uwe Tews */ /** * class for capture tags tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class CompileCaptureTest extends PHPUnit_Smarty { @@ -31,7 +31,7 @@ class CompileCaptureTest extends PHPUnit_Smarty * Test capture tags * * @not runInSeparateProcess - * @preserveGlobalState disabled + * * @dataProvider dataTestCapture */ public function testCapture($code, $result, $testName, $testNumber) @@ -83,8 +83,8 @@ class CompileCaptureTest extends PHPUnit_Smarty /** * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testCompileCaptureNocache2() @@ -107,9 +107,9 @@ class CompileCaptureTest extends PHPUnit_Smarty /** * Test spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testSpacing($code, $result, $testName, $testNumber) { diff --git a/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/CompilerPluginTest.php b/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/CompilerPluginTest.php index 68bfc45a..78efeb9b 100644 --- a/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/CompilerPluginTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/CompilerPluginTest.php @@ -2,16 +2,12 @@ /** * Smarty PHPunit tests compiler plugin * - * @package PHPunit + * @author Uwe Tews */ /** * class for compiler plugin tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled */ class CompilerPluginTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/PHPunitplugins/compiler.test.php b/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/PHPunitplugins/compiler.test.php index 615e0413..13ca0dee 100644 --- a/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/PHPunitplugins/compiler.test.php +++ b/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/PHPunitplugins/compiler.test.php @@ -1,10 +1,12 @@ <?php // compiler.test.php -class smarty_compiler_test extends Smarty_Internal_CompileBase +use Smarty\Compile\Base; + +class smarty_compiler_test extends Base { - public function compile($args, $compiler) - { + + public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { $this->required_attributes = array('data'); $_attr = $this->getAttributes($compiler, $args); @@ -14,15 +16,3 @@ class smarty_compiler_test extends Smarty_Internal_CompileBase return "<?php echo 'test output'; ?>"; } } - -// compiler.testclose.php -class smarty_compiler_testclose extends Smarty_Internal_CompileBase -{ - public function compile($args, $compiler) - { - - $this->closeTag($compiler, 'test'); - - return ''; - } -} diff --git a/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/PHPunitplugins/compiler.testclose.php b/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/PHPunitplugins/compiler.testclose.php index bd751f06..68ab73f1 100644 --- a/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/PHPunitplugins/compiler.testclose.php +++ b/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/PHPunitplugins/compiler.testclose.php @@ -1,13 +1,15 @@ <?php // compiler.testclose.php -class smarty_compiler_testclose extends Smarty_Internal_CompileBase +use Smarty\Compile\Base; + +class smarty_compiler_testclose extends Base { - public function execute($args, $compiler) - { - $this->closeTag($compiler, 'test'); + public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { + + $this->closeTag($compiler, 'test'); - return ''; - } -} + return ''; + } +}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/CompileConfigLoadTest.php b/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/CompileConfigLoadTest.php index 18cbe4cb..5a402028 100644 --- a/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/CompileConfigLoadTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/CompileConfigLoadTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of the {config_load} tag * - * @package PHPunit + * @author Uwe Tews */ /** * class for config variable tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class CompileConfigLoadTest extends PHPUnit_Smarty { @@ -37,8 +37,8 @@ class CompileConfigLoadTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * * test {load_config} loading section2 */ @@ -47,8 +47,8 @@ class CompileConfigLoadTest extends PHPUnit_Smarty $this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('001_section2.tpl')); } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * * test {load_config} loading section2 */ @@ -59,8 +59,8 @@ class CompileConfigLoadTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * * test {load_config} loading section2 */ @@ -70,8 +70,8 @@ class CompileConfigLoadTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * * test {load_config} loading section2 shorttags */ @@ -83,8 +83,8 @@ class CompileConfigLoadTest extends PHPUnit_Smarty /** * test config varibales loading all sections from template * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testConfigVariableAllSectionsTemplate_004() { @@ -95,8 +95,8 @@ class CompileConfigLoadTest extends PHPUnit_Smarty /** * test config varibales overwrite * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testConfigVariableOverwrite_005() { @@ -104,16 +104,16 @@ class CompileConfigLoadTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testConfigVariableOverwrite_006() { $this->assertEquals("Welcome to Smarty! Overwrite3", $this->smarty->fetch('006_overwrite.tpl')); } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testConfigVariableOverwrite_0061() { @@ -125,8 +125,8 @@ class CompileConfigLoadTest extends PHPUnit_Smarty /** * test config varibales overwrite false * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testConfigVariableOverwrite_007() { @@ -137,8 +137,8 @@ class CompileConfigLoadTest extends PHPUnit_Smarty /** * test config varibales booleanize on * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testConfigVariableBooleanizeOn_008() { @@ -150,8 +150,8 @@ class CompileConfigLoadTest extends PHPUnit_Smarty /** * test config varibales booleanize off * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testConfigVariableBooleanizeOff_008() { @@ -165,7 +165,7 @@ class CompileConfigLoadTest extends PHPUnit_Smarty */ public function testConfigSyntaxError_009() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('Syntax error in config file'); $this->smarty->fetch('009_error.tpl'); } diff --git a/tests/UnitTests/TemplateSource/TagTests/Delimiter/CompileDelimiterTest.php b/tests/UnitTests/TemplateSource/TagTests/Delimiter/CompileDelimiterTest.php index 1100beb8..4a90c535 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Delimiter/CompileDelimiterTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Delimiter/CompileDelimiterTest.php @@ -2,7 +2,7 @@ /** * Smarty PHPunit tests compilation of delimiter tags * - * @package PHPunit + * @author Uwe Tews */ @@ -10,8 +10,8 @@ * class for delimiter tags tests * * @run TestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * */ class CompileDelimiterTest extends PHPUnit_Smarty { @@ -43,7 +43,7 @@ class CompileDelimiterTest extends PHPUnit_Smarty public function testLeftDelimiterError() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('nocache option not allowed'); $tpl = $this->smarty->createTemplate('string:x{ldelim nocache}x'); $this->assertEquals('x{x', $this->smarty->fetch($tpl)); diff --git a/tests/UnitTests/TemplateSource/TagTests/Eval/CompileEvalTest.php b/tests/UnitTests/TemplateSource/TagTests/Eval/CompileEvalTest.php index cd6d14bf..1c2ad006 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Eval/CompileEvalTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Eval/CompileEvalTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of {eval} tag * - * @package PHPunit + * @author Uwe Tews */ /** * class for {eval} tag tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class CompileEvalTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TagTests/For/CompileForTest.php b/tests/UnitTests/TemplateSource/TagTests/For/CompileForTest.php index 07137973..21d997d6 100644 --- a/tests/UnitTests/TemplateSource/TagTests/For/CompileForTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/For/CompileForTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of {for} tag * - * @package PHPunit + * @author Uwe Tews */ /** * class for {for} tag tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class CompileForTest extends PHPUnit_Smarty { @@ -29,9 +29,9 @@ class CompileForTest extends PHPUnit_Smarty /** * Test For * - * @preserveGlobalState disabled + * * @dataProvider dataTestFor - * @runInSeparateProcess + * */ public function testFor($code, $result, $testName, $testNumber) { @@ -90,8 +90,8 @@ class CompileForTest extends PHPUnit_Smarty /** * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testForNocacheVar2() @@ -114,8 +114,8 @@ class CompileForTest extends PHPUnit_Smarty /** * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testForNocacheTag2() @@ -138,8 +138,8 @@ class CompileForTest extends PHPUnit_Smarty /** * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testForCache2() @@ -153,9 +153,9 @@ class CompileForTest extends PHPUnit_Smarty /** * Test spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testSpacing($code, $result, $testName, $testNumber) { diff --git a/tests/UnitTests/TemplateSource/TagTests/Foreach/CompileForeachTest.php b/tests/UnitTests/TemplateSource/TagTests/Foreach/CompileForeachTest.php index d0a496c8..3e39d5e2 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Foreach/CompileForeachTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Foreach/CompileForeachTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of {foreach} tag * - * @package PHPunit + * @author Uwe Tews */ /** * class for {foreach} tag tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class CompileForeachTest extends PHPUnit_Smarty { @@ -31,7 +31,7 @@ class CompileForeachTest extends PHPUnit_Smarty * Test foreach tags * * - * @preserveGlobalState disabled + * * @dataProvider dataTestForeach */ public function testForeach($code, $foo, $result, $testName, $testNumber) @@ -105,7 +105,7 @@ class CompileForeachTest extends PHPUnit_Smarty * Test foreach tags caching * * - * @preserveGlobalState disabled + * * @dataProvider dataTestForeachNocache */ public function testForeachCaching($code, $new, $assignNocache, $foo, $result, $testName, $testNumber) @@ -151,8 +151,8 @@ class CompileForeachTest extends PHPUnit_Smarty /* * test foreach and nocache * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testForeachNocacheVar1_024() @@ -165,8 +165,8 @@ class CompileForeachTest extends PHPUnit_Smarty /** * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testForeachNocacheVar2_024() @@ -179,8 +179,8 @@ class CompileForeachTest extends PHPUnit_Smarty /** * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testForeachNocacheTag1_025() @@ -193,8 +193,8 @@ class CompileForeachTest extends PHPUnit_Smarty /** * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testForeachNocacheTag2_25() @@ -207,8 +207,8 @@ class CompileForeachTest extends PHPUnit_Smarty /** * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testForeachCache1_26() @@ -221,8 +221,8 @@ class CompileForeachTest extends PHPUnit_Smarty /** * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testForeachCache2_26() @@ -303,9 +303,9 @@ class CompileForeachTest extends PHPUnit_Smarty /** * Test spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testSpacing($code, $result, $testName, $testNumber) { @@ -347,9 +347,9 @@ class CompileForeachTest extends PHPUnit_Smarty /** * Test spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestElseSpacing - * @runInSeparateProcess + * */ public function testElseSpacing($code, $result, $testName, $testNumber) { diff --git a/tests/UnitTests/TemplateSource/TagTests/FunctionPlugin/CompileFunctionPluginTest.php b/tests/UnitTests/TemplateSource/TagTests/FunctionPlugin/CompileFunctionPluginTest.php index bb130b58..fd62a5ef 100644 --- a/tests/UnitTests/TemplateSource/TagTests/FunctionPlugin/CompileFunctionPluginTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/FunctionPlugin/CompileFunctionPluginTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of function plugins * - * @package PHPunit + * @author Uwe Tews */ /** * class for function plugin tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class CompileFunctionPluginTest extends PHPUnit_Smarty { @@ -42,7 +42,7 @@ class CompileFunctionPluginTest extends PHPUnit_Smarty */ public function testFunctionPluginRegisteredFunction() { - $this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'plugintest', 'myplugintest'); + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_FUNCTION, 'plugintest', 'myplugintest'); $tpl = $this->smarty->createTemplate('string:{plugintest foo=bar}', $this->smarty); $this->assertEquals("plugin test called bar", $this->smarty->fetch($tpl)); } diff --git a/tests/UnitTests/TemplateSource/TagTests/If/CompileIfTest.php b/tests/UnitTests/TemplateSource/TagTests/If/CompileIfTest.php index 1fe73e9f..9d4debde 100644 --- a/tests/UnitTests/TemplateSource/TagTests/If/CompileIfTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/If/CompileIfTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of {if} tag * - * @package PHPunit + * @author Uwe Tews */ /** * class for {if} tag tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class CompileIfTest extends PHPUnit_Smarty { @@ -33,7 +33,7 @@ class CompileIfTest extends PHPUnit_Smarty * Test if tags * * @not runInSeparateProcess - * @preserveGlobalState disabled + * * @dataProvider dataTestIf */ public function testIf($code, $result, $testName, $testNumber) @@ -148,8 +148,8 @@ class CompileIfTest extends PHPUnit_Smarty /** * Test if nocache tags * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider dataTestIfNocache */ public function testIfNocache($var, $value, $code, $result, $testName, $testNumber, $file = null) @@ -165,7 +165,7 @@ class CompileIfTest extends PHPUnit_Smarty $this->smarty->assign($var, $value, true); $this->smarty->assign($var . '2', $value); $this->assertEquals($result, $this->strip($this->smarty->fetch('run_code_caching.tpl')), - "testIfNocahe - {$code} - {$testName}"); + "testIfNocache - {$code} - {$testName}"); } /* @@ -205,9 +205,9 @@ class CompileIfTest extends PHPUnit_Smarty /** * Test spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testSpacing($code, $result, $testName, $testNumber) { diff --git a/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php b/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php index c9b1c154..8a7cb78e 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of the {include} tag * - * @package PHPunit + * @author Uwe Tews */ /** * class for {include} tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class CompileIncludeTest extends PHPUnit_Smarty { @@ -31,8 +31,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * test spacing * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider includeProviderCaching */ public function testSpacing_001($merge, $caching, $text) @@ -49,8 +49,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * test spacing * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider includeProviderCaching */ public function testSpacing_001V2($merge, $caching, $text) @@ -67,8 +67,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * test spacing * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider includeProviderCaching */ public function testSpacing_001V3($merge, $caching, $text) @@ -85,8 +85,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * test standard output * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider includeProvider */ public function testIncludeStandard_001($merge, $text) @@ -100,8 +100,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * test standard output var * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider includeProvider */ public function testIncludeStandardNocacheVar($merge, $text) @@ -117,8 +117,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * Test that assign attribute does not create standard output * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider includeProvider */ public function testIncludeAssign1($merge, $text) @@ -131,8 +131,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * Test that assign attribute does load variable * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider includeProvider */ public function testIncludeAssign2($merge, $text) @@ -145,8 +145,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * Test passing local vars eval * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider includeProvider */ public function testIncludePassVars($merge, $text) @@ -160,8 +160,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * Test passing local vars include * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider includeProvider */ public function testIncludePassVars2($merge, $text) @@ -177,8 +177,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * Test recursive includes * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider includeProvider */ public function testRecursiveIncludes1($merge, $text) @@ -193,8 +193,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * Test recursive includes 2 * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider includeProvider */ public function testRecursiveIncludes2($merge, $text) @@ -244,9 +244,9 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * Test Include spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testIncludeSpacing($code, $result, $testName, $testNumber) { @@ -262,9 +262,9 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * Test Output spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testIncludeSpacingNocache($code, $result, $testName, $testNumber) { @@ -281,9 +281,9 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * Test Output spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testIncludeSpacingNocache2($code, $result, $testName, $testNumber) { @@ -324,4 +324,11 @@ class CompileIncludeTest extends PHPUnit_Smarty array("A{include file='include_spacing3.tpl'}B\nC", "AbarB\nC", '3_Newline3', $i++), ); } + + public function testModifierWrongPlace() { + $this->smarty->debugging = true; + $this->expectException(\Smarty\CompilerException::class); + $this->expectExceptionMessage('No modifiers allowed'); + $this->smarty->fetch('include_with_modifier.tpl'); + } } diff --git a/tests/UnitTests/TemplateSource/TagTests/Include/templates/include_with_modifier.tpl b/tests/UnitTests/TemplateSource/TagTests/Include/templates/include_with_modifier.tpl new file mode 100644 index 00000000..15dd825d --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Include/templates/include_with_modifier.tpl @@ -0,0 +1 @@ +{include|upper file="helloworld.tpl"}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Insert/CompileInsertTest.php b/tests/UnitTests/TemplateSource/TagTests/Insert/CompileInsertTest.php deleted file mode 100644 index e9a5328f..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Insert/CompileInsertTest.php +++ /dev/null @@ -1,269 +0,0 @@ -<?php -/** - * Smarty PHPunit tests compilation of the {insert} tag - * - * @package PHPunit - * @author Uwe Tews - */ - -/** - * class for {insert} tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class CompileInsertTest extends PHPUnit_Smarty -{ - public function setUp(): void - { - $this->setUpSmarty(__DIR__); - $this->smarty->addPluginsDir(__DIR__ . "/PHPunitplugins/"); - $this->smarty->enableSecurity(); - } - - - public function testInit() - { - $this->cleanDirs(); - } - /** - * Test For - * - * @preserveGlobalState disabled - * @dataProvider dataTestInsert - * @runInSeparateProcess - */ - public function testInsert($code, $result, $testName, $testNumber) - { - $name = empty($testName) ? $testNumber : $testName; - $file = "Insert_{$name}.tpl"; - $this->makeTemplateFile($file, $code); - $this->smarty->assign('variable', 'test'); - $this->smarty->setTemplateDir('./templates_tmp'); - $this->assertEquals($result, - $this->smarty->fetch($file), - $file); - } - - /* - * Data provider für testInsert - */ - public function dataTestInsert() - { - $i = 1; - /* - * Code - * result - * test name - * test number - */ - return array( - array('start {insert name=\'test\' foo=\'bar\'} end', 'start insert function parameter value bar end', 'T1', $i++), - array('start {insert name="test" foo=\'bar\'} end', 'start insert function parameter value bar end', 'T2', $i++), - array('start {insert name=$variable foo=\'bar\'} end', 'start insert function parameter value bar end', 'T3', $i++), - array("start {insert name='test' foo='bar' assign=blar} end {\$blar}", 'start end insert function parameter value bar', 'T4', $i++), - array("start {insert name='test' foo='bar' assign=blar} end", 'start end', 'T5', $i++), - ); - } - - - - - /** - * test insert plugin - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testInsertPlugin1() - { - global $insertglobal; - $insertglobal = 'global'; - $tpl = $this->smarty->createTemplate('insertplugintest.tpl'); - $tpl->assign('foo', 'bar'); - $this->assertEquals('param foo bar globalvar global', $this->smarty->fetch($tpl)); - } - /** - * @runInSeparateProcess - * @preserveGlobalState disabled - * test insert plugin - */ - public function testInsertPlugin2() - { - global $insertglobal; - $insertglobal = 'global 2'; - $tpl = $this->smarty->createTemplate('insertplugintest.tpl'); - $tpl->assign('foo', 'buh'); - $this->assertEquals('param foo buh globalvar global 2', $this->smarty->fetch($tpl)); - } - - /** - * test insert plugin caching - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testInsertPluginCaching1_1() - { - global $insertglobal; - $insertglobal = 'global'; - $this->smarty->caching = true; - $tpl = $this->smarty->createTemplate('insertplugintest.tpl'); - $tpl->assign('foo', 'bar', true); - $this->assertEquals('param foo bar globalvar global', $this->smarty->fetch($tpl)); - } - - /** - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * - */ - public function testInsertPluginCaching1_2() - { - $this->smarty->addPluginsDir(__DIR__ . "/PHPunitplugins/"); - global $insertglobal; - $insertglobal = 'changed global 2'; - $this->smarty->caching = 1; - $tpl = $this->smarty->createTemplate('insertplugintest.tpl'); - $tpl->assign('foo', 'buh', true); -// $this->assertTrue($tpl->isCached()); - $this->assertEquals('param foo buh globalvar changed global 2', $this->smarty->fetch($tpl)); - } - - /** - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * - */ - public function testInsertPluginCaching1_3() - { - $this->smarty->addPluginsDir(__DIR__ . "/PHPunitplugins/"); - global $insertglobal; - $insertglobal = 'changed global'; - $this->smarty->caching = 1; -// $this->smarty->setForceCompile(true); - $this->smarty->assign('foo', 'bar', true); - $this->assertEquals('param foo bar globalvar changed global', $this->smarty->fetch('insertplugintest.tpl')); - } - - /** - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * - */ - public function testInsertPluginCaching1_4() - { - global $insertglobal; - $this->smarty->addPluginsDir(__DIR__ . "/PHPunitplugins/"); - $insertglobal = 'changed global 4'; - $this->smarty->caching = 1; - $this->smarty->assign('foo', 'buh', true); - $this->assertTrue($this->smarty->isCached('insertplugintest.tpl')); - $this->assertEquals('param foo buh globalvar changed global 4', $this->smarty->fetch('insertplugintest.tpl')); - } - /** - * test insert plugin caching 2 - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testInsertPluginCaching2_1() - { - global $insertglobal; - $insertglobal = 'global'; - $this->smarty->caching = true; - $this->smarty->compile_id = 1; - $tpl = $this->smarty->createTemplate('insertplugintest.tpl'); - $tpl->assign('foo', 'bar'); - $this->assertEquals('param foo bar globalvar global', $this->smarty->fetch($tpl)); - } - - /** - * test insert plugin caching 2 - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testInsertPluginCaching2_2() - { - global $insertglobal; - $insertglobal = 'global 2'; - $this->smarty->caching = true; - $this->smarty->compile_id = 1; - $tpl = $this->smarty->createTemplate('insertplugintest.tpl'); - $tpl->assign('foo', 'buh'); - $this->assertStringContainsString('param foo bar globalvar global 2', $this->smarty->fetch($tpl)); - } - /** - * test insert plugin caching 3 - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testInsertPluginCaching3_1() - { - $this->smarty->caching = true; - $this->smarty->assign('insert',$t=time()); - $this->assertStringContainsString($t.'Inner template', $this->smarty->fetch('insertplugintest2.tpl')); - } - - /** - * test insert plugin caching 2 - * @runInSeparateProcess - * @preserveGlobalState disabled - * @group slow - */ - public function testInsertPluginCaching3_2() - { - sleep(2); - $this->smarty->caching = true; - $this->smarty->assign('insert',$t=time()); - $this->assertStringContainsString($t.'Inner template', $this->smarty->fetch('insertplugintest2.tpl')); - } - - - /** - * test inserted function none existing function - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testInsertFunctionNoneExistingFunction() - { - $tpl = $this->smarty->createTemplate("eval:start {insert name='mustfail' foo='bar' assign=blar} end {\$blar}"); - try { - $this->smarty->fetch($tpl); - } - catch (Exception $e) { - $this->assertStringContainsString("{insert} no function or plugin found for 'mustfail'", $e->getMessage()); - - return; - } - $this->fail('Exception for "function is not callable" has not been raised.'); - } - - /** - * test inserted function none existing script - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testInsertFunctionNoneExistingScript() - { - $tpl = $this->smarty->createTemplate("eval:{insert name='mustfail' foo='bar' script='nofile.php'}"); - try { - $this->smarty->fetch($tpl); - } - catch (Exception $e) { - $this->assertStringContainsString('missing script file', $e->getMessage()); - - return; - } - $this->fail('Exception for "missing file" has not been raised.'); - } -} - -/** - * test function - */ -function insert_test($params, $template) -{ - return "insert function parameter value $params[foo]"; -} diff --git a/tests/UnitTests/TemplateSource/TagTests/Insert/PHPunitplugins/insert.insertplugintest.php b/tests/UnitTests/TemplateSource/TagTests/Insert/PHPunitplugins/insert.insertplugintest.php deleted file mode 100644 index cd2e27cd..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Insert/PHPunitplugins/insert.insertplugintest.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php -function smarty_insert_insertplugintest($params, $template) -{ - global $insertglobal; - - return 'param foo ' . $params['foo'] . ' globalvar ' . $insertglobal; -} diff --git a/tests/UnitTests/TemplateSource/TagTests/Insert/PHPunitplugins/insert.test2.php b/tests/UnitTests/TemplateSource/TagTests/Insert/PHPunitplugins/insert.test2.php deleted file mode 100644 index 75f3ccb8..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Insert/PHPunitplugins/insert.test2.php +++ /dev/null @@ -1,6 +0,0 @@ -<?php - -function smarty_insert_test2($params, $smarty) { - - return $smarty->tpl_vars[$params['var']]->value; -} diff --git a/tests/UnitTests/TemplateSource/TagTests/Insert/cache/.gitignore b/tests/UnitTests/TemplateSource/TagTests/Insert/cache/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Insert/cache/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/TemplateSource/TagTests/Insert/templates/inner.tpl b/tests/UnitTests/TemplateSource/TagTests/Insert/templates/inner.tpl deleted file mode 100644 index e5f67304..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Insert/templates/inner.tpl +++ /dev/null @@ -1 +0,0 @@ -Inner template diff --git a/tests/UnitTests/TemplateSource/TagTests/Insert/templates/insertplugintest.tpl b/tests/UnitTests/TemplateSource/TagTests/Insert/templates/insertplugintest.tpl deleted file mode 100644 index 579f2548..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Insert/templates/insertplugintest.tpl +++ /dev/null @@ -1 +0,0 @@ -{insert name='insertplugintest' foo=$foo}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Insert/templates/insertplugintest2.tpl b/tests/UnitTests/TemplateSource/TagTests/Insert/templates/insertplugintest2.tpl deleted file mode 100644 index a1834ab0..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Insert/templates/insertplugintest2.tpl +++ /dev/null @@ -1,2 +0,0 @@ -{insert name='test2' var='insert'} -{include 'inner.tpl'}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Insert/templates_c/.gitignore b/tests/UnitTests/TemplateSource/TagTests/Insert/templates_c/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Insert/templates_c/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/TemplateSource/TagTests/Insert/templates_tmp/.gitignore b/tests/UnitTests/TemplateSource/TagTests/Insert/templates_tmp/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Insert/templates_tmp/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/TemplateSource/TagTests/Literal/LiteralTest.php b/tests/UnitTests/TemplateSource/TagTests/Literal/LiteralTest.php index 64c9432c..b71ed781 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Literal/LiteralTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Literal/LiteralTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests appendByRef method * - * @package PHPunit + * @author Uwe Tews */ /** * class for appendByRef tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class LiteralTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/CompileMakeNocacheTest.php b/tests/UnitTests/TemplateSource/TagTests/MakeNocache/CompileMakeNocacheTest.php deleted file mode 100644 index ca520b9c..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/CompileMakeNocacheTest.php +++ /dev/null @@ -1,309 +0,0 @@ -<?php -/** - * Smarty PHPunit tests compilation of {make_nocache} tags - * - * @package PHPunit - * @author Uwe Tews - */ - -/** - * class for {make_nocache} tags tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class CompileMakeNocacheTest extends PHPUnit_Smarty -{ - public function setUp(): void - { - $this->setUpSmarty(__DIR__); - $this->smarty->addPluginsDir("../../../__shared/PHPunitplugins/"); - $this->smarty->addTemplateDir("../../../__shared/templates/"); - $this->smarty->addTemplateDir("./templates_tmp"); - } - - public function testInit() - { - $this->cleanDirs(); - } - - /** - * Test {make_nocache} tags caching disabled - * - * @not runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider dataTestMakeNocache001 - */ - public function testMakeNocache_001($foo, $result) - { - if ($foo) { - $this->smarty->assign('foo', $foo); - } - $this->assertEquals($result, $this->smarty->fetch('001_test_foo.tpl'), - "foo = {$foo}"); - } - - /* - * Data provider für testMakeNocache_001 - */ - public function dataTestMakeNocache001() - { - - /* - * $foo - * result - * - */ - return array(array(1, '#001_test_foo.tpl:$foo =1'), array(2, '#001_test_foo.tpl:$foo =2'), - array(null, '#001_test_foo.tpl:$foo =>unassigned<'),); - } - - /** - * Test {make_nocache} cached tags - * - * @not runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider dataTestMakeNocache001_1 - */ - public function testMakeNocache_001_1($foo, $result) - { - $this->smarty->setCaching(true); - if ($foo) { - $this->smarty->assign('foo', $foo); - } - $this->assertEquals($result, $this->smarty->fetch('001_test_foo.tpl'), - "foo = {$foo}"); - } - - /* - * Data provider für testMakeNocache_001_1 - */ - public function dataTestMakeNocache001_1() - { - - /* - * $foo - * result - * - */ - return array(array(1, '#001_test_foo.tpl:$foo =1'), array(2, '#001_test_foo.tpl:$foo =1'), - array(null, '#001_test_foo.tpl:$foo =1'),); - } - - /** - * Test {make_nocache} cached tags existing nocahe variable - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider dataTestMakeNocache001_2 - */ - public function testMakeNocache_001_2($foo, $result) - { - $this->smarty->setCaching(true); - if ($foo) { - $this->smarty->assign('foo', $foo, true); - } - $this->assertEquals($result, $this->smarty->fetch('001_test_foo.tpl'), - "foo = {$foo}"); - } - - /* - * Data provider für testMakeNocache_001_2 - */ - public function dataTestMakeNocache001_2() - { - - /* - * $foo - * result - * - */ - return array(array(1, '#001_test_foo.tpl:$foo =1'), array(2, '#001_test_foo.tpl:$foo =2'), - array(null, '#001_test_foo.tpl:$foo =1'),); - } - - /** - * Test {make_nocache} cached tags reassign - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider dataTestMakeNocache001_3 - */ - public function testMakeNocache_001_3($foo, $result) - { - $this->smarty->setCaching(true); - if ($foo) { - $this->smarty->assign('foo', $foo); - } - $this->smarty->assign('bar', $foo + 4, true); - $this->assertEquals($result, $this->smarty->fetch('001_test_foo_assign.tpl'), - "foo = {$foo}"); - } - - /* - * Data provider für testMakeNocache_001_3 - */ - public function dataTestMakeNocache001_3() - { - - /* - * $foo - * result - * - */ - return array(array(1, '#001_test_foo_assign.tpl:$foo =5'), array(2, '#001_test_foo_assign.tpl:$foo =6'), - array(null, '#001_test_foo_assign.tpl:$foo =4'),); - } - - /** - * Test {make_nocache} cached tags {if} - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider dataTestMakeNocache001_4 - */ - public function testMakeNocache_001_4($foo, $bar, $result) - { - $this->smarty->setCaching(true); - $this->smarty->assign('foo', $foo); - $this->smarty->assign('bar', $bar); - $this->assertEquals($result, $this->smarty->fetch('001_test_foo_if.tpl'), - "foo = {$foo}"); - } - - /* - * Data provider für testMakeNocache_001_4 - */ - public function dataTestMakeNocache001_4() - { - /* - * $foo - * $bar - * result - * - */ - return array(array(10, 9, 'greater'), array(9, 10, 'greater'),); - } - - /** - * Test {make_nocache} cached tags {if} nocache - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider dataTestMakeNocache001_5 - */ - public function testMakeNocache_001_5($foo, $bar, $result) - { - $this->smarty->setCaching(true); - $this->smarty->compile_id = 1; - if ($foo) { - $this->smarty->assign('foo', $foo); - } - $this->smarty->assign('bar', $bar, true); - $this->assertEquals($result, $this->smarty->fetch('001_test_foo_if.tpl'), - "foo = {$foo}"); - } - - /* - * Data provider für testMakeNocache_001_5 - */ - public function dataTestMakeNocache001_5() - { - /* - * $foo - * $bar - * result - * - */ - return array(array(10, 9, 'greater'), array(9, 10, 'not greater'), array(null, 11, 'not greater'), - array(null, 2, 'greater'),); - } - - /** - * Test {make_nocache} cached tags {foreach} - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider dataTestMakeNocache001_6 - */ - public function testMakeNocache_001_6($foo, $bar, $result) - { - $this->smarty->setCaching(true); - $this->smarty->assign('foo', $foo, true); - $this->smarty->assign('bar', $bar); - $this->assertEquals($result, $this->smarty->fetch('001_test_foo_foreach.tpl'), - "foo = {$foo}"); - } - - /* - * Data provider für testMakeNocache_001_6 - */ - public function dataTestMakeNocache001_6() - { - - /* - * $foo - * $bar - * result - * - */ - return array(array(2, array(1, 2, 3, 4), ' 1 2match 3 4'), array(3, array(7, 8, 9), ' 1 2 3match 4'),); - } - - /** - * Test {make_nocache} cached tags {foreach} nocache - * - * @runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider dataTestMakeNocache001_7 - */ - public function testMakeNocache_001_7($foo, $bar, $result) - { - $this->smarty->setCaching(true); - $this->smarty->compile_id = 1; - $this->smarty->assign('foo', $foo, true); - $this->smarty->assign('bar', $bar, true); - $this->assertEquals($result, $this->smarty->fetch('001_test_foo_foreach.tpl'), - "foo = {$foo}"); - } - - /* - * Data provider für testMakeNocache_001_7 - */ - public function dataTestMakeNocache001_7() - { - - /* - * $foo - * $bar - * result - * - */ - return array(array(2, array(1, 2, 3, 4), ' 1 2match 3 4'), array(7, array(7, 8, 9), ' 7match 8 9'),); - } - /** - * Test {make_nocache} with values containing '\' - * - * @preserveGlobalState disabled - */ - public function testMakeNocache_002() - { - $this->smarty->setCaching(true); - $this->smarty->assign('foo', 'uwe\'s'); - $this->assertEquals($this->strip('uwe\'s'), $this->smarty->fetch('002_test_backslash.tpl')); - } - - /** - * Test {make_nocache} with values containing spaces - * - * @preserveGlobalState disabled - */ - public function testMakeNocache_003() - { - $this->smarty->setCaching(true); - $this->smarty->assign('foo', 'the Smarty template engine'); - $this->assertEquals('the Smarty template engine', $this->smarty->fetch('003_test_spaces.tpl')); - } - -} diff --git a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/cache/.gitignore b/tests/UnitTests/TemplateSource/TagTests/MakeNocache/cache/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/cache/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/001_test_foo.tpl b/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/001_test_foo.tpl deleted file mode 100644 index 4253b8dd..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/001_test_foo.tpl +++ /dev/null @@ -1 +0,0 @@ -{make_nocache $foo}{checkvar var=foo types='template' nocache}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/001_test_foo_assign.tpl b/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/001_test_foo_assign.tpl deleted file mode 100644 index 7042daf3..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/001_test_foo_assign.tpl +++ /dev/null @@ -1 +0,0 @@ -{make_nocache $foo}{$foo=$bar nocache}{checkvar var=foo types='template' nocache}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/001_test_foo_foreach.tpl b/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/001_test_foo_foreach.tpl deleted file mode 100644 index 326fa569..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/001_test_foo_foreach.tpl +++ /dev/null @@ -1,3 +0,0 @@ -{foreach $bar as $i} - {$i}{make_nocache $i}{if $i == $foo}match{/if} -{/foreach}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/001_test_foo_if.tpl b/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/001_test_foo_if.tpl deleted file mode 100644 index fe2c88e1..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/001_test_foo_if.tpl +++ /dev/null @@ -1 +0,0 @@ -{make_nocache $foo}{if $foo > $bar}greater{else}not greater{/if}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/002_test_backslash.tpl b/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/002_test_backslash.tpl deleted file mode 100644 index ab21fba8..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/002_test_backslash.tpl +++ /dev/null @@ -1 +0,0 @@ -{make_nocache $foo}{$foo nocache}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/003_test_spaces.tpl b/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/003_test_spaces.tpl deleted file mode 100644 index ab21fba8..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates/003_test_spaces.tpl +++ /dev/null @@ -1 +0,0 @@ -{make_nocache $foo}{$foo nocache}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates_c/.gitignore b/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates_c/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/MakeNocache/templates_c/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/TemplateSource/TagTests/Nocache/CompileNocacheTest.php b/tests/UnitTests/TemplateSource/TagTests/Nocache/CompileNocacheTest.php index 5aea12b2..9efd5329 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Nocache/CompileNocacheTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Nocache/CompileNocacheTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of {nocache} tag * - * @package PHPunit + * @author Uwe Tews */ /** * class for {nocache} tag tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class CompileNocacheTest extends PHPUnit_Smarty { @@ -59,8 +59,8 @@ class CompileNocacheTest extends PHPUnit_Smarty /** * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * */ public function testNocacheCachingYes2() diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginBlock/PluginBlockTextformatTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginBlock/PluginBlockTextformatTest.php index 854d2b4a..d6dc3cd6 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginBlock/PluginBlockTextformatTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginBlock/PluginBlockTextformatTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginBlockTextformatTest extends PHPUnit_Smarty { @@ -22,20 +22,16 @@ class PluginBlockTextformatTest extends PHPUnit_Smarty $this->setUpSmarty(__DIR__); } - public function testDefault() - { - $result = "This is foo. This is foo. This is foo.\nThis is foo. This is foo. This is foo.\n\nThis is bar.\n\nbar foo bar foo foo. bar foo bar foo\nfoo. bar foo bar foo foo. bar foo bar\nfoo foo. bar foo bar foo foo. bar foo\nbar foo foo. bar foo bar foo foo.\n\n"; - $tpl = $this->smarty->createTemplate('string:{textformat wrap=40}' . $this->string . '{/textformat}'); - $this->assertEquals($result, $this->smarty->fetch($tpl)); - } + public function testInit() + { + $this->cleanDirs(); + } - public function testDefaultWithoutMbstring() + public function testDefault() { - Smarty::$_MBSTRING = false; $result = "This is foo. This is foo. This is foo.\nThis is foo. This is foo. This is foo.\n\nThis is bar.\n\nbar foo bar foo foo. bar foo bar foo\nfoo. bar foo bar foo foo. bar foo bar\nfoo foo. bar foo bar foo foo. bar foo\nbar foo foo. bar foo bar foo foo.\n\n"; $tpl = $this->smarty->createTemplate('string:{textformat wrap=40}' . $this->string . '{/textformat}'); $this->assertEquals($result, $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; } public function testIndent() @@ -45,15 +41,6 @@ class PluginBlockTextformatTest extends PHPUnit_Smarty $this->assertEquals($result, $this->smarty->fetch($tpl)); } - public function testIndentWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $result = " This is foo. This is foo. This is\n foo. This is foo. This is foo. This\n is foo.\n\n This is bar.\n\n bar foo bar foo foo. bar foo bar foo\n foo. bar foo bar foo foo. bar foo\n bar foo foo. bar foo bar foo foo.\n bar foo bar foo foo. bar foo bar foo\n foo.\n\n"; - $tpl = $this->smarty->createTemplate('string:{textformat wrap=40 indent=4}' . $this->string . '{/textformat}'); - $this->assertEquals($result, $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testIndentFirst() { $result = " This is foo. This is foo. This\n is foo. This is foo. This is foo.\n This is foo.\n\n This is bar.\n\n bar foo bar foo foo. bar foo bar\n foo foo. bar foo bar foo foo. bar\n foo bar foo foo. bar foo bar foo\n foo. bar foo bar foo foo. bar foo\n bar foo foo.\n\n"; @@ -61,15 +48,6 @@ class PluginBlockTextformatTest extends PHPUnit_Smarty $this->assertEquals($result, $this->smarty->fetch($tpl)); } - public function testIndentFirstWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $result = " This is foo. This is foo. This\n is foo. This is foo. This is foo.\n This is foo.\n\n This is bar.\n\n bar foo bar foo foo. bar foo bar\n foo foo. bar foo bar foo foo. bar\n foo bar foo foo. bar foo bar foo\n foo. bar foo bar foo foo. bar foo\n bar foo foo.\n\n"; - $tpl = $this->smarty->createTemplate('string:{textformat wrap=40 indent=4 indent_first=4}' . $this->string . '{/textformat}'); - $this->assertEquals($result, $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testIndentchar() { $result = "####This is foo. This is foo. This is\n####foo. This is foo. This is foo. This\n####is foo.\n\n####This is bar.\n\n####bar foo bar foo foo. bar foo bar foo\n####foo. bar foo bar foo foo. bar foo\n####bar foo foo. bar foo bar foo foo.\n####bar foo bar foo foo. bar foo bar foo\n####foo.\n\n"; @@ -77,15 +55,6 @@ class PluginBlockTextformatTest extends PHPUnit_Smarty $this->assertEquals($result, $this->smarty->fetch($tpl)); } - public function testIndentcharWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $result = "####This is foo. This is foo. This is\n####foo. This is foo. This is foo. This\n####is foo.\n\n####This is bar.\n\n####bar foo bar foo foo. bar foo bar foo\n####foo. bar foo bar foo foo. bar foo\n####bar foo foo. bar foo bar foo foo.\n####bar foo bar foo foo. bar foo bar foo\n####foo.\n\n"; - $tpl = $this->smarty->createTemplate('string:{textformat wrap=40 indent=4 indent_char="#"}' . $this->string . '{/textformat}'); - $this->assertEquals($result, $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testIndentcharFirst() { $result = "########This is foo. This is foo. This\n####is foo. This is foo. This is foo.\n####This is foo.\n\n########This is bar.\n\n########bar foo bar foo foo. bar foo bar\n####foo foo. bar foo bar foo foo. bar\n####foo bar foo foo. bar foo bar foo\n####foo. bar foo bar foo foo. bar foo\n####bar foo foo.\n\n"; @@ -93,15 +62,6 @@ class PluginBlockTextformatTest extends PHPUnit_Smarty $this->assertEquals($result, $this->smarty->fetch($tpl)); } - public function testIndentcharFirstWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $result = "########This is foo. This is foo. This\n####is foo. This is foo. This is foo.\n####This is foo.\n\n########This is bar.\n\n########bar foo bar foo foo. bar foo bar\n####foo foo. bar foo bar foo foo. bar\n####foo bar foo foo. bar foo bar foo\n####foo. bar foo bar foo foo. bar foo\n####bar foo foo.\n\n"; - $tpl = $this->smarty->createTemplate('string:{textformat wrap=40 indent=4 indent_first=4 indent_char="#"}' . $this->string . '{/textformat}'); - $this->assertEquals($result, $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testWrapchar() { $result = " This is foo. This is foo. This is#foo. This is foo. This is foo. This#is foo.## This is bar.## bar foo bar foo foo. bar foo bar foo#foo. bar foo bar foo foo. bar foo#bar foo foo. bar foo bar foo foo.#bar foo bar foo foo. bar foo bar foo#foo.##"; @@ -109,15 +69,6 @@ class PluginBlockTextformatTest extends PHPUnit_Smarty $this->assertEquals($result, $this->smarty->fetch($tpl)); } - public function testWrapcharWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $result = " This is foo. This is foo. This is#foo. This is foo. This is foo. This#is foo.## This is bar.## bar foo bar foo foo. bar foo bar foo#foo. bar foo bar foo foo. bar foo#bar foo foo. bar foo bar foo foo.#bar foo bar foo foo. bar foo bar foo#foo.##"; - $tpl = $this->smarty->createTemplate('string:{textformat wrap=40 indent=4 wrap_char="#"}' . $this->string . '{/textformat}'); - $this->assertEquals($result, $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testStyleEmail() { $result = "This is foo. This is foo. This is foo. This is foo. This is foo. This is\nfoo.\n\nThis is bar.\n\nbar foo bar foo foo. bar foo bar foo foo. bar foo bar foo foo. bar foo\nbar foo foo. bar foo bar foo foo. bar foo bar foo foo. bar foo bar foo\nfoo.\n\n"; @@ -125,12 +76,4 @@ class PluginBlockTextformatTest extends PHPUnit_Smarty $this->assertEquals($result, $this->smarty->fetch($tpl)); } - public function testStyleEmailWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $result = "This is foo. This is foo. This is foo. This is foo. This is foo. This is\nfoo.\n\nThis is bar.\n\nbar foo bar foo foo. bar foo bar foo foo. bar foo bar foo foo. bar foo\nbar foo foo. bar foo bar foo foo. bar foo bar foo foo. bar foo bar foo\nfoo.\n\n"; - $tpl = $this->smarty->createTemplate('string:{textformat style="email"}' . $this->string . '{/textformat}'); - $this->assertEquals($result, $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } } diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/CountTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/CountTest.php new file mode 100644 index 00000000..b4e78c48 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/CountTest.php @@ -0,0 +1,28 @@ +<?php + +namespace UnitTests\TemplateSource\TagTests\PluginFunction; +class CountTest extends \PHPUnit_Smarty { + + public function setUp(): void { + $this->setUpSmarty(__DIR__); + } + + public function testBasicSyntax() { + $this->assertEquals('3', $this->smarty->fetch("string:{count([1,2,3])}")); + } + + public function testNonRecursive() { + $this->assertEquals('3', $this->smarty->fetch("string:{count([1,2,[3,4]])}")); + } + + public function testRecursive() { + $this->assertEquals('5', $this->smarty->fetch("string:{count([1,2,[3,4]], 1)}")); + } + + public function testInvalidParameters() { + $this->expectException(\Smarty\Exception::class); + $this->expectExceptionMessage('Invalid number of arguments'); + $this->assertEquals("", $this->smarty->fetch("string:{count()}")); + } + +}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/EmptyTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/EmptyTest.php new file mode 100644 index 00000000..34a56eb3 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/EmptyTest.php @@ -0,0 +1,44 @@ +<?php + +namespace UnitTests\TemplateSource\TagTests\PluginFunction; +class EmptyTest extends \PHPUnit_Smarty { + + public function setUp(): void { + $this->setUpSmarty(__DIR__); + } + + public function testBasicSyntax() { + $this->assertEquals("yay", $this->smarty->fetch("string:{if empty(\$noSuch)}yay{/if}")); + } + + public function testEmptyStringIsEmpty() { + $this->assertEquals("yay", $this->smarty->fetch("string:{if empty('')}yay{/if}")); + } + + public function testFalseIsEmpty() { + $this->smarty->assign('test', false); + $this->assertEquals("yay", $this->smarty->fetch("string:{if empty(\$test)}yay{/if}")); + } + + public function testIntZeroIsEmpty() { + $this->smarty->assign('test', 0); + $this->assertEquals("yay", $this->smarty->fetch("string:{if empty(\$test)}yay{/if}")); + } + + public function testStringZeroIsEmpty() { + $this->smarty->assign('test', '0'); + $this->assertEquals("yay", $this->smarty->fetch("string:{if empty(\$test)}yay{/if}")); + } + + public function testIntThreeIsNotEmpty() { + $this->smarty->assign('test', 3); + $this->assertEquals("nay", $this->smarty->fetch("string:{if empty(\$test)}yay{else}nay{/if}")); + } + + public function testInvalidParameters() { + $this->expectException(\Smarty\CompilerException::class); + $this->expectExceptionMessage('Invalid number of arguments'); + $this->assertEquals("", $this->smarty->fetch("string:{empty(3, 'foo')}")); + } + +}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/InArrayTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/InArrayTest.php new file mode 100644 index 00000000..b27c2585 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/InArrayTest.php @@ -0,0 +1,27 @@ +<?php + +class InArrayTest extends \PHPUnit_Smarty { + + public function setUp(): void + { + $this->setUpSmarty(__DIR__); + } + + public function testBasicSyntax() + { + $this->assertEquals("yay", $this->smarty->fetch("string:{if in_array(3,[3])}yay{/if}")); + } + + public function testNotInArray() + { + $this->assertEquals("nay", $this->smarty->fetch("string:{if in_array(2,[3])}yay{else}nay{/if}")); + } + + public function testInvalidParameters() + { + $this->expectException(\Smarty\Exception::class); + $this->expectExceptionMessage('Invalid number of arguments'); + $this->assertEquals("", $this->smarty->fetch("string:{in_array('foo')}")); + } + +}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/IsArrayTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/IsArrayTest.php new file mode 100644 index 00000000..65731d27 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/IsArrayTest.php @@ -0,0 +1,28 @@ +<?php + +namespace UnitTests\TemplateSource\TagTests\PluginFunction; +class IsArrayTest extends \PHPUnit_Smarty { + + public function setUp(): void { + $this->setUpSmarty(__DIR__); + } + + public function testBasicSyntax() { + $this->assertEquals("yay", $this->smarty->fetch("string:{if is_array([3])}yay{/if}")); + } + + public function testIntNotIsArray() { + $this->assertEquals("nay", $this->smarty->fetch("string:{if is_array(2)}yay{else}nay{/if}")); + } + + public function testStringNotIsArray() { + $this->assertEquals("nay", $this->smarty->fetch("string:{if is_array('foo')}yay{else}nay{/if}")); + } + + public function testInvalidParameters() { + $this->expectException(\Smarty\Exception::class); + $this->expectExceptionMessage('Invalid number of arguments'); + $this->assertEquals("", $this->smarty->fetch("string:{is_array(3, 'foo')}")); + } + +}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/IssetTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/IssetTest.php new file mode 100644 index 00000000..a54b244a --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/IssetTest.php @@ -0,0 +1,45 @@ +<?php + +namespace UnitTests\TemplateSource\TagTests\PluginFunction; +class IssetTest extends \PHPUnit_Smarty { + + public function setUp(): void { + $this->setUpSmarty(__DIR__); + } + + public function testBasicSyntax() { + $this->assertEquals("nay", $this->smarty->fetch("string:{if isset(\$noSuch)}yay{else}nay{/if}")); + } + + public function testEmptyStringIsset() { + $this->assertEquals("yay", $this->smarty->fetch("string:{if isset('')}yay{/if}")); + } + + public function testFalseIsset() { + $this->smarty->assign('test', false); + $this->assertEquals("yay", $this->smarty->fetch("string:{if isset(\$test)}yay{/if}")); + } + + public function testIntZeroIsset() { + $this->smarty->assign('test', 0); + $this->assertEquals("yay", $this->smarty->fetch("string:{if isset(\$test)}yay{/if}")); + } + + public function testMultivar() { + $this->smarty->assign('test', 0); + $this->smarty->assign('test2', 'pizza'); + $this->assertEquals("yay", $this->smarty->fetch("string:{if isset(\$test, \$test2)}yay{/if}")); + } + + public function testMultivarOneNotset() { + $this->smarty->assign('test', 0); + $this->assertEquals("nay", $this->smarty->fetch("string:{if isset(\$test, \$test2)}yay{else}nay{/if}")); + } + + public function testInvalidParameters() { + $this->expectException(\Smarty\CompilerException::class); + $this->expectExceptionMessage('Invalid number of arguments'); + $this->assertEquals("", $this->smarty->fetch("string:{if isset()}blurp{/if}")); + } + +}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionFetchTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionFetchTest.php index 13e9f3a3..bece9d6d 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionFetchTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionFetchTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginFunctionFetchTest extends PHPUnit_Smarty { @@ -29,8 +29,8 @@ class PluginFunctionFetchTest extends PHPUnit_Smarty /** * test {fetch} from UIR * -* @runInSeparateProcess -* @preserveGlobalState disabled +* +* */ public function testFetchUri() { @@ -40,12 +40,12 @@ class PluginFunctionFetchTest extends PHPUnit_Smarty /** * test {fetch} invalid uri * -* @runInSeparateProcess -* @preserveGlobalState disabled +* +* */ public function testFetchInvalidUri() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('{fetch} cannot read resource \'https://foo.smarty.net/foo.dat\''); $this->smarty->fetch('string:{fetch file="https://foo.smarty.net/foo.dat"}'); } @@ -54,11 +54,11 @@ class PluginFunctionFetchTest extends PHPUnit_Smarty * test {fetch file=...} access to file from path not aloo/wed by security settings * * @run InSeparateProcess - * @preserveGlobalState disabled + * */ public function testFetchSecurity() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('not trusted file path'); $this->cleanDirs(); $dir=$this->smarty->getTemplateDir(); @@ -69,11 +69,11 @@ class PluginFunctionFetchTest extends PHPUnit_Smarty * test {fetch file=...} access to file from path not aloo/wed by security settings * * @run InSeparateProcess - * @preserveGlobalState disabled + * */ public function testFetchSecurity2() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('not trusted file path'); $this->cleanDirs(); $this->smarty->getTemplateDir(); diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php index 7deb4df7..0bf8b51e 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php @@ -2,7 +2,7 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ @@ -11,9 +11,9 @@ require_once(__DIR__ . '/helpers/_object_tostring.php'); /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginFunctionHtmlCheckboxesTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlOptionsTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlOptionsTest.php index 7520f87c..36b33dd1 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlOptionsTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlOptionsTest.php @@ -2,7 +2,7 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ @@ -11,9 +11,9 @@ require_once(__DIR__ . '/helpers/_object_tostring.php'); /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginFunctionHtmlOptionsTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlRadiosTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlRadiosTest.php index ac9046ba..dc05456b 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlRadiosTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlRadiosTest.php @@ -2,7 +2,7 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ @@ -10,9 +10,9 @@ require_once(__DIR__ . '/helpers/_object_tostring.php'); /** * class for modifier tests - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginFunctionHtmlRadiosTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlSelectDateTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlSelectDateTest.php index 633a1c81..f48dc8a0 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlSelectDateTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlSelectDateTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginFunctionHtmlSelectDateTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlSelectTimeTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlSelectTimeTest.php index 1077b599..d13862d7 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlSelectTimeTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlSelectTimeTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginFunctionHtmlSelectTimeTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionMailtoTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionMailtoTest.php index 792142c6..db3430b6 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionMailtoTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionMailtoTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginFunctionMailtoTest extends PHPUnit_Smarty { @@ -27,15 +27,6 @@ class PluginFunctionMailtoTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testDefaultWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $result = '<a href="mailto:me@example.com" >me@example.com</a>'; - $tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com"}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testText() { $result = '<a href="mailto:me@example.com" >send me some mail</a>'; @@ -43,47 +34,20 @@ class PluginFunctionMailtoTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testTextWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $result = '<a href="mailto:me@example.com" >send me some mail</a>'; - $tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" text="send me some mail"}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testEncodeJavascript() { - $result = '<script type="text/javascript">document.write(unescape(\'%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%22%20%3e%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%3c%2f%61%3e\'))</script>'; + $result = '<script>document.write(unescape(\'%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%22%20%3e%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%3c%2f%61%3e\'))</script>'; $tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" encode="javascript"}'); $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testEncodeJavascriptWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $result = '<script type="text/javascript">document.write(unescape(\'%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%22%20%3e%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%3c%2f%61%3e\'))</script>'; - $tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" encode="javascript"}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testEncodeJavascriptCharcode() { - $result = '<script type="text/javascript">document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,109,101,64,101,120,97,109,112,108,101,46,99,111,109,34,32,62,109,101,64,101,120,97,109,112,108,101,46,99,111,109,60,47,97,62))</script>'; + $result = '<script>document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,109,101,64,101,120,97,109,112,108,101,46,99,111,109,34,32,62,109,101,64,101,120,97,109,112,108,101,46,99,111,109,60,47,97,62))</script>'; $tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" encode="javascript_charcode"}'); $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testEncodeJavascriptCharcodeWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $result = '<script type="text/javascript">document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,109,101,64,101,120,97,109,112,108,101,46,99,111,109,34,32,62,109,101,64,101,120,97,109,112,108,101,46,99,111,109,60,47,97,62))</script>'; - $tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" encode="javascript_charcode"}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testEncodeHex() { $result = '<a href="mailto:%6d%65@%65%78%61%6d%70%6c%65.%63%6f%6d" >me@example.com</a>'; @@ -91,15 +55,6 @@ class PluginFunctionMailtoTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testEncodeHexWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $result = '<a href="mailto:%6d%65@%65%78%61%6d%70%6c%65.%63%6f%6d" >me@example.com</a>'; - $tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" encode="hex"}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testSubject() { $result = '<a href="mailto:me@example.com?subject=Hello%20to%20you%21" >me@example.com</a>'; @@ -107,15 +62,6 @@ class PluginFunctionMailtoTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testSubjectWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $result = '<a href="mailto:me@example.com?subject=Hello%20to%20you%21" >me@example.com</a>'; - $tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" subject="Hello to you!"}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testCc() { $result = '<a href="mailto:me@example.com?cc=you@example.com,they@example.com" >me@example.com</a>'; @@ -123,15 +69,6 @@ class PluginFunctionMailtoTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testCcWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $result = '<a href="mailto:me@example.com?cc=you@example.com,they@example.com" >me@example.com</a>'; - $tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" cc="you@example.com,they@example.com"}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testExtra() { $result = '<a href="mailto:me@example.com" class="email">me@example.com</a>'; @@ -139,15 +76,6 @@ class PluginFunctionMailtoTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testExtraWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $result = '<a href="mailto:me@example.com" class="email">me@example.com</a>'; - $tpl = $this->smarty->createTemplate('eval:{mailto address="me@example.com" extra=\'class="email"\'}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testUmlauts() { $result = '<a href="mailto:me+smtpext@example.com?cc=you@example.com,they@example.com&subject=h%C3%A4llo%20w%C3%B6rld" >me+smtpext@example.com</a>'; @@ -155,18 +83,9 @@ class PluginFunctionMailtoTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testUmlautsWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $result = '<a href="mailto:me+smtpext@example.com?cc=you@example.com,they@example.com&subject=h%C3%A4llo%20w%C3%B6rld" >me+smtpext@example.com</a>'; - $tpl = $this->smarty->createTemplate('eval:{mailto address="me+smtpext@example.com" cc="you@example.com,they@example.com" subject="hällo wörld"}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testJavascriptChars() { - $result = '<script type="text/javascript">document.write(unescape(\'%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%26%71%75%6f%74%3b%26%67%74%3b%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%26%23%30%33%39%3b%29%3b%20%61%6c%65%72%74%28%26%71%75%6f%74%3b%69%6e%6a%65%63%74%69%6f%6e%26%71%75%6f%74%3b%29%3b%20%2f%2f%22%20%3e%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%26%71%75%6f%74%3b%26%67%74%3b%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%26%23%30%33%39%3b%29%3b%20%61%6c%65%72%74%28%26%71%75%6f%74%3b%69%6e%6a%65%63%74%69%6f%6e%26%71%75%6f%74%3b%29%3b%20%2f%2f%3c%2f%61%3e\'))</script>'; + $result = '<script>document.write(unescape(\'%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%26%71%75%6f%74%3b%26%67%74%3b%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%26%23%30%33%39%3b%29%3b%20%61%6c%65%72%74%28%26%71%75%6f%74%3b%69%6e%6a%65%63%74%69%6f%6e%26%71%75%6f%74%3b%29%3b%20%2f%2f%22%20%3e%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%26%71%75%6f%74%3b%26%67%74%3b%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%26%23%30%33%39%3b%29%3b%20%61%6c%65%72%74%28%26%71%75%6f%74%3b%69%6e%6a%65%63%74%69%6f%6e%26%71%75%6f%74%3b%29%3b%20%2f%2f%3c%2f%61%3e\'))</script>'; $this->smarty->assign('address', 'me@example.com">me@example.com\'); alert("injection"); //'); $tpl = $this->smarty->createTemplate('eval:{mailto address=$address encode=javascript}'); $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/TimeTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/TimeTest.php new file mode 100644 index 00000000..d64fd92d --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/TimeTest.php @@ -0,0 +1,20 @@ +<?php + +namespace UnitTests\TemplateSource\TagTests\PluginFunction; +class TimeTest extends \PHPUnit_Smarty { + + public function setUp(): void { + $this->setUpSmarty(__DIR__); + } + + public function testBasicSyntax() { + $this->assertStringMatchesFormat('%d', $this->smarty->fetch("string:{time()}")); + } + + public function testInvalidParameters() { + $this->expectException(\Smarty\Exception::class); + $this->expectExceptionMessage('Invalid number of arguments'); + $this->assertEquals("", $this->smarty->fetch("string:{time(3, 'foo')}")); + } + +}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCapitalizeTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCapitalizeTest.php index 9fc10d75..577d430b 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCapitalizeTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCapitalizeTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class PluginModifierCapitalizeTest extends PHPUnit_Smarty { @@ -40,33 +40,6 @@ class PluginModifierCapitalizeTest extends PHPUnit_Smarty $this->assertEquals("Next X-Men Film, X3, Delayed. Ümlauts Äre Cööl.", $this->smarty->fetch($tpl)); } - public function testDefaultWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"next x-men fiLm, x3, delayed."|capitalize}'); - $this->assertEquals("Next X-Men FiLm, x3, Delayed.", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - - public function testDigitsWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"next x-men fiLm, x3, delayed."|capitalize:true}'); - $this->assertEquals("Next X-Men FiLm, X3, Delayed.", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - - public function testTrueCaptialsWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"next x-men fiLm, x3, delayed."|capitalize:true:true}'); - $this->assertEquals("Next X-Men Film, X3, Delayed.", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testQuotes() { $tpl = $this->smarty->createTemplate('string:{"next x-men fiLm, x3, \"delayed. umlauts\" foo."|capitalize}'); @@ -75,17 +48,6 @@ class PluginModifierCapitalizeTest extends PHPUnit_Smarty $this->assertEquals("Next X-Men FiLm, x3, 'Delayed. Umlauts' Foo.", $this->smarty->fetch($tpl)); } - public function testQuotesWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"next x-men fiLm, x3, \"delayed. umlauts\" foo."|capitalize}'); - $this->assertEquals("Next X-Men FiLm, x3, \"Delayed. Umlauts\" Foo.", $this->smarty->fetch($tpl)); - $tpl = $this->smarty->createTemplate('string:{"next x-men fiLm, x3, \'delayed. umlauts\' foo."|capitalize}'); - $this->assertEquals("Next X-Men FiLm, x3, 'Delayed. Umlauts' Foo.", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testQuotesDigits() { $tpl = @@ -96,19 +58,6 @@ class PluginModifierCapitalizeTest extends PHPUnit_Smarty $this->assertEquals("Next X-Men FiLm, X3, 'Delayed. Umlauts' Foo.", $this->smarty->fetch($tpl)); } - public function testQuotesDigitsWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $tpl = - $this->smarty->createTemplate('string:{"next x-men fiLm, x3, \"delayed. umlauts\" foo."|capitalize:true}'); - $this->assertEquals("Next X-Men FiLm, X3, \"Delayed. Umlauts\" Foo.", $this->smarty->fetch($tpl)); - $tpl = - $this->smarty->createTemplate('string:{"next x-men fiLm, x3, \'delayed. umlauts\' foo."|capitalize:true}'); - $this->assertEquals("Next X-Men FiLm, X3, 'Delayed. Umlauts' Foo.", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testQuotesTrueCapitals() { $tpl = @@ -119,19 +68,6 @@ class PluginModifierCapitalizeTest extends PHPUnit_Smarty $this->assertEquals("Next X-Men Film, X3, 'Delayed. Umlauts' Foo.", $this->smarty->fetch($tpl)); } - public function testQuotesTrueCapitalsWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $tpl = - $this->smarty->createTemplate('string:{"next x-men fiLm, x3, \"delayed. umlauts\" foo."|capitalize:true:true}'); - $this->assertEquals("Next X-Men Film, X3, \"Delayed. Umlauts\" Foo.", $this->smarty->fetch($tpl)); - $tpl = - $this->smarty->createTemplate('string:{"next x-men fiLm, x3, \'delayed. umlauts\' foo."|capitalize:true:true}'); - $this->assertEquals("Next X-Men Film, X3, 'Delayed. Umlauts' Foo.", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testQuotesBeginning() { $tpl = $this->smarty->createTemplate('string:{"\"delayed. umlauts\" foo."|capitalize}'); @@ -140,14 +76,4 @@ class PluginModifierCapitalizeTest extends PHPUnit_Smarty $this->assertEquals("'Delayed. Umlauts' Foo.", $this->smarty->fetch($tpl)); } - public function testQuotesBeginningWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"\"delayed. umlauts\" foo."|capitalize}'); - $this->assertEquals("\"Delayed. Umlauts\" Foo.", $this->smarty->fetch($tpl)); - $tpl = $this->smarty->createTemplate('string:{"\'delayed. umlauts\' foo."|capitalize}'); - $this->assertEquals("'Delayed. Umlauts' Foo.", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } } diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCharsetTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCharsetTest.php index 92ff9514..e463ca05 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCharsetTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCharsetTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class PluginModifierCharsetTest extends PHPUnit_Smarty { @@ -28,17 +28,6 @@ class PluginModifierCharsetTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $tpl->fetch()); } - public function testToLatin1WithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $encoded = "hällö wörld 2"; - $result = mb_convert_encoding($encoded, 'ISO-8859-1', 'UTF-8'); - $tpl = $this->smarty->createTemplate('string:{"' . $encoded . '"|to_charset}'); - $this->assertEquals($encoded, $tpl->fetch()); - Smarty::$_MBSTRING = true; - } - public function testFromLatin1() { $result = "hällö wörld 3"; @@ -47,17 +36,6 @@ class PluginModifierCharsetTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $tpl->fetch()); } - public function testFromLatin1WithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $result = "hällö wörld 4"; - $encoded = mb_convert_encoding($result, 'ISO-8859-1', 'UTF-8'); - $tpl = $this->smarty->createTemplate('string:{"' . $encoded . '"|from_charset}'); - $this->assertEquals($encoded, $tpl->fetch()); - Smarty::$_MBSTRING = true; - } - public function testFromUtf32le() { $result = "hällö wörld 5"; @@ -66,17 +44,6 @@ class PluginModifierCharsetTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $tpl->fetch()); } - public function testFromUtf32leWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $result = "hällö wörld 6"; - $encoded = mb_convert_encoding($result, "UTF-32LE", "UTF-8"); - $tpl = $this->smarty->createTemplate('string:{"' . $encoded . '"|from_charset:"UTF-32LE"}'); - $this->assertEquals($encoded, $tpl->fetch()); - Smarty::$_MBSTRING = true; - } - public function testToUtf32le() { $encoded = "hällö wörld 7"; @@ -85,14 +52,4 @@ class PluginModifierCharsetTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $tpl->fetch()); } - public function testToUtf32leWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $encoded = "hällö wörld 8"; - $result = mb_convert_encoding($encoded, "UTF-32LE", "UTF-8"); - $tpl = $this->smarty->createTemplate('string:{"' . $encoded . '"|to_charset:"UTF-32LE"}'); - $this->assertEquals($encoded, $tpl->fetch()); - Smarty::$_MBSTRING = true; - } } diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountCharactersTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountCharactersTest.php index 14955ded..7e4ebe6c 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountCharactersTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountCharactersTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class PluginModifierCountCharactersTest extends PHPUnit_Smarty { @@ -27,16 +27,6 @@ class PluginModifierCountCharactersTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testDefaultWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId ('mb'); - $result = "29"; - $tpl = $this->smarty->createTemplate('string:{"Cold Wave Linked to Temperatures."|count_characters}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testSpaces() { $result = "33"; @@ -44,16 +34,6 @@ class PluginModifierCountCharactersTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testSpacesWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId ('mb'); - $result = "33"; - $tpl = $this->smarty->createTemplate('string:{"Cold Wave Linked to Temperatures."|count_characters:true}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testUmlauts() { $result = "29"; @@ -61,16 +41,6 @@ class PluginModifierCountCharactersTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testUmlautsWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId ('mb'); - $result = "29"; - $tpl = $this->smarty->createTemplate('string:{"Cold Wäve Linked tö Temperatures."|count_characters}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testUmlautsSpaces() { $result = "33"; @@ -78,13 +48,4 @@ class PluginModifierCountCharactersTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testUmlautsSpacesWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId ('mb'); - $result = "33"; - $tpl = $this->smarty->createTemplate('string:{"Cold Wäve Linked tö Temperatures."|count_characters:true}'); - $this->assertNotEquals($result, $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } } diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountSentencesTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountSentencesTest.php index 1abd12b8..caec7630 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountSentencesTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountSentencesTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginModifierCountSentencesTest extends PHPUnit_Smarty { @@ -35,18 +35,6 @@ class PluginModifierCountSentencesTest extends PHPUnit_Smarty $this->assertEquals("0", $this->smarty->fetch($tpl)); } - public function testDefaultWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"hello world."|count_sentences}'); - $this->assertEquals("1", $this->smarty->fetch($tpl)); - $tpl = $this->smarty->createTemplate('string:{"hello world. I\'m another? Sentence!"|count_sentences}'); - $this->assertEquals("3", $this->smarty->fetch($tpl)); - $tpl = $this->smarty->createTemplate('string:{"hello world.wrong"|count_sentences}'); - $this->assertEquals("0", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testUmlauts() { $tpl = $this->smarty->createTemplate('string:{"hello worldä."|count_sentences}'); diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountTest.php index 2bbcb573..2e8b24e8 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountTest.php @@ -6,9 +6,9 @@ /** * class for modifier tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class PluginModifierCountTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountWordsTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountWordsTest.php index c6c1b543..97a3cc53 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountWordsTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountWordsTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginModifierCountWordsTest extends PHPUnit_Smarty { @@ -27,15 +27,6 @@ class PluginModifierCountWordsTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testDefaultWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $result = "7"; - $tpl = $this->smarty->createTemplate('string:{"Dealers Will Hear Car Talk at Noon."|count_words}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testDashes() { $result = "7"; @@ -43,15 +34,6 @@ class PluginModifierCountWordsTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testDashesWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $result = "7"; - $tpl = $this->smarty->createTemplate('string:{"Smalltime-Dealers Will Hear Car Talk at Noon."|count_words}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testUmlauts() { $result = "7"; @@ -59,12 +41,4 @@ class PluginModifierCountWordsTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testUmlautsWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $result = "7"; - $tpl = $this->smarty->createTemplate('string:{"Dealers Will Hear Cär Talk at Nöön."|count_words}'); - $this->assertNotEquals($result, $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } } diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierDefaultTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierDefaultTest.php index a2582011..0400e017 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierDefaultTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierDefaultTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginModifierDefaultTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierEscapeTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierEscapeTest.php index 073f9fcf..5c0c2edf 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierEscapeTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierEscapeTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginModifierEscapeTest extends PHPUnit_Smarty { @@ -33,28 +33,12 @@ class PluginModifierEscapeTest extends PHPUnit_Smarty $this->assertEquals("I'm some <html> to ä be "escaped" or &copy;", $this->smarty->fetch($tpl)); } - public function testHtmlWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"I\'m some <html> to ä be \"escaped\" or ©"|escape:"html"}'); - $this->assertEquals("I'm some <html> to ä be "escaped" or &copy;", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testHtmlDouble() { $tpl = $this->smarty->createTemplate('string:{"I\'m some <html> to ä be \"escaped\" or ©"|escape:"html":null:false}'); $this->assertEquals("I'm some <html> to ä be "escaped" or ©", $this->smarty->fetch($tpl)); } - public function testHtmlDoubleWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"I\'m some <html> to ä be \"escaped\" or ©"|escape:"html":null:false}'); - $this->assertEquals("I'm some <html> to ä be "escaped" or ©", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testHtmlallCompiled() { $tpl = $this->smarty->createTemplate('string:{"I\'m some <html> to ä be \"escaped\" or ©"|escape:"htmlall"}'); @@ -68,37 +52,12 @@ class PluginModifierEscapeTest extends PHPUnit_Smarty $this->assertEquals("I'm some <html> to ä be "escaped" or &copy;", $this->smarty->fetch($tpl)); } - public function testHtmlallWithoutMbstringCompiled() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"I\'m some <html> to ä be \"escaped\" or ©"|escape:"htmlall"}'); - $this->assertEquals("I'm some <html> to ä be "escaped" or &copy;", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - - public function testHtmlallWithoutMbstringModifier() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"I\'m some <html> to ä be \"escaped\" or ©"|escape:$mode}'); - $this->smarty->assign('mode', 'htmlall'); - $this->assertEquals("I'm some <html> to ä be "escaped" or &copy;", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testHtmlallDouble() { $tpl = $this->smarty->createTemplate('string:{"I\'m some <html> to ä be \"escaped\" or ©"|escape:"htmlall":null:false}'); $this->assertEquals("I'm some <html> to ä be "escaped" or ©", $this->smarty->fetch($tpl)); } - public function testHtmlallDoubleWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"I\'m some <html> to ä be \"escaped\" or ©"|escape:"htmlall":null:false}'); - $this->assertEquals("I'm some <html> to ä be "escaped" or ©", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testUrlCompiled() { $tpl = $this->smarty->createTemplate('string:{"http://some.encoded.com/url?parts#foo"|escape:"url"}'); @@ -112,42 +71,18 @@ class PluginModifierEscapeTest extends PHPUnit_Smarty $this->assertEquals("http%3A%2F%2Fsome.encoded.com%2Furl%3Fparts%23foo", $this->smarty->fetch($tpl)); } - public function testUrlWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"http://some.encoded.com/url?parts#foo"|escape:"url"}'); - $this->assertEquals("http%3A%2F%2Fsome.encoded.com%2Furl%3Fparts%23foo", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testUrlpathinfo() { $tpl = $this->smarty->createTemplate('string:{"http://some.encoded.com/url?parts#foo"|escape:"urlpathinfo"}'); $this->assertEquals("http%3A//some.encoded.com/url%3Fparts%23foo", $this->smarty->fetch($tpl)); } - public function testUrlpathinfoWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"http://some.encoded.com/url?parts#foo"|escape:"urlpathinfo"}'); - $this->assertEquals("http%3A//some.encoded.com/url%3Fparts%23foo", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testHex() { $tpl = $this->smarty->createTemplate('string:{"a/cäa"|escape:"hex"}'); $this->assertEquals("%61%2f%63%c3%a4%61", $this->smarty->fetch($tpl)); } - public function testHexWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"a/cäa"|escape:"hex"}'); - $this->assertEquals("%61%2f%63%c3%a4%61", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testHexentity() { $q = "aäЗдравсствуйте"; @@ -159,19 +94,6 @@ class PluginModifierEscapeTest extends PHPUnit_Smarty $this->assertEquals("abc", $this->smarty->fetch($tpl)); } - public function testHexentityWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $q = "aäЗдравсствуйте"; - $r = html_entity_decode($q, ENT_NOQUOTES, 'UTF-8'); - $tpl = $this->smarty->createTemplate('string:{"' . $r . '"|escape:"hexentity"}'); - $this->assertNotEquals("aäЗдравсствуйте", $this->smarty->fetch($tpl)); - - $tpl = $this->smarty->createTemplate('string:{"abc"|escape:"hexentity"}'); - $this->assertEquals("abc", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testDecentity() { $q = "aäЗдравсствуйте"; @@ -183,79 +105,42 @@ class PluginModifierEscapeTest extends PHPUnit_Smarty $this->assertEquals("abc", $this->smarty->fetch($tpl)); } - public function testDecentityWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $q = "aäЗдравсствуйте"; - $r = html_entity_decode($q, ENT_NOQUOTES, 'UTF-8'); - $tpl = $this->smarty->createTemplate('string:{"' . $r . '"|escape:"decentity"}'); - $this->assertNotEquals("aäЗдравсствуйте", $this->smarty->fetch($tpl)); - - $tpl = $this->smarty->createTemplate('string:{"abc"|escape:"decentity"}'); - $this->assertEquals("abc", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testJavascript() { $tpl = $this->smarty->createTemplate('string:{"var x = { foo : \"bar\n\" };"|escape:"javascript"}'); $this->assertEquals("var x = { foo : \\\"bar\\n\\\" };", $this->smarty->fetch($tpl)); } - public function testJavascriptWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"var x = { foo : \"bar\n\" };"|escape:"javascript"}'); - $this->assertEquals("var x = { foo : \\\"bar\\n\\\" };", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testMail() { $tpl = $this->smarty->createTemplate('string:{"smarty@example.com"|escape:"mail"}'); $this->assertEquals("smarty [AT] example [DOT] com", $this->smarty->fetch($tpl)); } - public function testMailWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"smarty@example.com"|escape:"mail"}'); - $this->assertEquals("smarty [AT] example [DOT] com", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testNonstd() { $tpl = $this->smarty->createTemplate('string:{"sma\'rty|»example«.com"|escape:"nonstd"}'); $this->assertEquals("sma'rty|»example«.com", $this->smarty->fetch($tpl)); } - public function testNonstdWithoutMbstring() + public function testTemplateLiteralBackticks() { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"' . mb_convert_encoding('sma\'rty@»example«.com', 'ISO-8859-1', 'UTF-8') . '"|escape:"nonstd"}'); - $this->assertEquals("sma'rty@»example«.com", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; + $tpl = $this->smarty->createTemplate('string:{"`Hello, World!`"|escape:"javascript"}'); + $this->assertEquals("\\`Hello, World!\\`", $this->smarty->fetch($tpl)); } - public function testTemplateLiteralBackticks() - { - $tpl = $this->smarty->createTemplate('string:{"`Hello, World!`"|escape:"javascript"}'); - $this->assertEquals("\\`Hello, World!\\`", $this->smarty->fetch($tpl)); - } - - public function testTemplateLiteralInterpolation() - { - $tpl = $this->smarty->createTemplate('string:{$vector|escape:"javascript"}'); - $this->smarty->assign('vector', "`Hello, \${name}!`"); - $this->assertEquals("\\`Hello, \\\$\\{name}!\\`", $this->smarty->fetch($tpl)); - } + public function testTemplateLiteralInterpolation() + { + $tpl = $this->smarty->createTemplate('string:{$vector|escape:"javascript"}'); + $this->smarty->assign('vector', "`Hello, \${name}!`"); + $this->assertEquals("\\`Hello, \\\$\\{name}!\\`", $this->smarty->fetch($tpl)); + } - public function testTemplateLiteralBackticksAndInterpolation() - { - $this->smarty->assign('vector', '`${alert(`Hello, ${name}!`)}${`\n`}`'); - $tpl = $this->smarty->createTemplate('string:{$vector|escape:"javascript"}'); - $this->assertEquals("\\`\\\$\\{alert(\\`Hello, \\\$\\{name}!\\`)}\\\$\\{\\`\\\\n\\`}\\`", $this->smarty->fetch($tpl)); - } + public function testTemplateLiteralBackticksAndInterpolation() + { + $this->smarty->assign('vector', '`${alert(`Hello, ${name}!`)}${`\n`}`'); + $tpl = $this->smarty->createTemplate('string:{$vector|escape:"javascript"}'); + $this->assertEquals("\\`\\\$\\{alert(\\`Hello, \\\$\\{name}!\\`)}\\\$\\{\\`\\\\n\\`}\\`", $this->smarty->fetch($tpl)); + } } diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierExplodeTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierExplodeTest.php index 5cd13dd3..ecefc6f8 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierExplodeTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierExplodeTest.php @@ -5,9 +5,9 @@ namespace UnitTests\TemplateSource\TagTests\PluginModifier; /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginModifierExplodeTest extends \PHPUnit_Smarty { @@ -19,7 +19,7 @@ class PluginModifierExplodeTest extends \PHPUnit_Smarty /** * @return void - * @throws \SmartyException + * @throws \Smarty\Exception * * @dataProvider explodeDataProvider */ diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierLowerTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierLowerTest.php index 06235551..c5567a1d 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierLowerTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierLowerTest.php @@ -2,15 +2,15 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginModifierLowerTest extends PHPUnit_Smarty { @@ -26,15 +26,6 @@ class PluginModifierLowerTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testDefaultWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $result = "two convicts evade noose, jury hung."; - $tpl = $this->smarty->createTemplate('string:{"Two Convicts Evade Noose, Jury Hung."|lower}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testUmlauts() { $result = "two convicts eväde nööse, jury hung."; @@ -42,12 +33,4 @@ class PluginModifierLowerTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testUmlautsWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $result = "two convicts eväde nööse, jury hung."; - $tpl = $this->smarty->createTemplate('string:{"Two Convicts Eväde NöÖse, Jury Hung."|lower}'); - $this->assertNotEquals($result, $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } } diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierNl2brTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierNl2brTest.php index 9b2c50b4..52aa2c00 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierNl2brTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierNl2brTest.php @@ -6,9 +6,9 @@ /** * class for modifier tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class PluginModifierNl2brTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierNumberFormatTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierNumberFormatTest.php index 27feeac3..8a2ea8e5 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierNumberFormatTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierNumberFormatTest.php @@ -5,9 +5,9 @@ namespace UnitTests\TemplateSource\TagTests\PluginModifier; /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginModifierNumberFormatTest extends \PHPUnit_Smarty { @@ -18,7 +18,7 @@ class PluginModifierNumberFormatTest extends \PHPUnit_Smarty /** * @return void - * @throws \SmartyException + * @throws \Smarty\Exception * * @dataProvider numberFormatDataProvider */ diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierRegexReplaceTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierRegexReplaceTest.php index f0a79ffc..fb6bc604 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierRegexReplaceTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierRegexReplaceTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginModifierRegexReplaceTest extends PHPUnit_Smarty { @@ -26,14 +26,6 @@ class PluginModifierRegexReplaceTest extends PHPUnit_Smarty $this->assertEquals("Infertility unlikely to be passed on, experts say.", $this->smarty->fetch($tpl)); } - public function testDefaultWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"Infertility unlikely to\nbe passed on, experts say."|regex_replace:"/[\r\t\n]/":" "}'); - $this->assertEquals("Infertility unlikely to be passed on, experts say.", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testUmlauts() { $tpl = $this->smarty->createTemplate('string:{"Infertility unlikely tö\näe passed on, experts say."|regex_replace:"/[\r\t\n]/u":" "}'); diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierReplaceTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierReplaceTest.php index a4b6a12e..cf7e2bd9 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierReplaceTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierReplaceTest.php @@ -5,9 +5,9 @@ namespace UnitTests\TemplateSource\TagTests\PluginModifier; /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginModifierReplaceTest extends \PHPUnit_Smarty { @@ -18,7 +18,7 @@ class PluginModifierReplaceTest extends \PHPUnit_Smarty /** * @return void - * @throws \SmartyException + * @throws \Smarty\Exception * * @dataProvider replaceDataProvider */ diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierSpacifyTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierSpacifyTest.php index 79e2b1ce..52569081 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierSpacifyTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierSpacifyTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginModifierSpacifyTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierStrRepeatTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierStrRepeatTest.php index 6a2d0966..59d5b989 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierStrRepeatTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierStrRepeatTest.php @@ -6,9 +6,9 @@ /** * class for modifier tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class PluginModifierStrRepeatTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierStripTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierStripTest.php index ab1a4384..152341cd 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierStripTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierStripTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginModifierStripTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierTruncateTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierTruncateTest.php index 667fb7d7..4aa9383e 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierTruncateTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierTruncateTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginModifierTruncateTest extends PHPUnit_Smarty { @@ -27,15 +27,6 @@ class PluginModifierTruncateTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testDefaultWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $result = 'Two Sisters Reunite after Eighteen Years at Checkout Counter.'; - $tpl = $this->smarty->createTemplate('string:{"Two Sisters Reunite after Eighteen Years at Checkout Counter."|truncate}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testLength() { $result = 'Two Sisters Reunite after...'; @@ -43,15 +34,6 @@ class PluginModifierTruncateTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testLengthWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $result = 'Two Sisters Reunite after...'; - $tpl = $this->smarty->createTemplate('string:{"Two Sisters Reunite after Eighteen Years at Checkout Counter."|truncate:30}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testEtc() { $result = 'Two Sisters Reunite after'; @@ -59,15 +41,6 @@ class PluginModifierTruncateTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testEtcWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $result = 'Two Sisters Reunite after'; - $tpl = $this->smarty->createTemplate('string:{"Two Sisters Reunite after Eighteen Years at Checkout Counter."|truncate:30:""}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testEtc2() { $result = 'Two Sisters Reunite after---'; @@ -75,15 +48,6 @@ class PluginModifierTruncateTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testEtc2WithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $result = 'Two Sisters Reunite after---'; - $tpl = $this->smarty->createTemplate('string:{"Two Sisters Reunite after Eighteen Years at Checkout Counter."|truncate:30:"---"}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testBreak() { $result = 'Two Sisters Reunite after Eigh'; @@ -91,15 +55,6 @@ class PluginModifierTruncateTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testBreakWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $result = 'Two Sisters Reunite after Eigh'; - $tpl = $this->smarty->createTemplate('string:{"Two Sisters Reunite after Eighteen Years at Checkout Counter."|truncate:30:"":true}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testBreak2() { $result = 'Two Sisters Reunite after E...'; @@ -107,15 +62,6 @@ class PluginModifierTruncateTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testBreak2WithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $result = 'Two Sisters Reunite after E...'; - $tpl = $this->smarty->createTemplate('string:{"Two Sisters Reunite after Eighteen Years at Checkout Counter."|truncate:30:"...":true}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testMiddle() { $result = 'Two Sisters Re..ckout Counter.'; @@ -123,12 +69,4 @@ class PluginModifierTruncateTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testMiddleWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $result = 'Two Sisters Re..ckout Counter.'; - $tpl = $this->smarty->createTemplate('string:{"Two Sisters Reunite after Eighteen Years at Checkout Counter."|truncate:30:"..":true:true}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } } diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierUnescapeTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierUnescapeTest.php index 2fdefb2e..3a7e51b1 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierUnescapeTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierUnescapeTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginModifierUnescapeTest extends PHPUnit_Smarty { @@ -28,16 +28,6 @@ class PluginModifierUnescapeTest extends PHPUnit_Smarty $this->assertEquals($result, $this->smarty->fetch($tpl)); } - public function testHtmlWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $encoded = "aäЗдра><&amp;ääвсствуйте"; - $result = "aäЗдра><&ääвсствуйте"; - $tpl = $this->smarty->createTemplate('string:{"' . $encoded . '"|unescape:"html"}'); - $this->assertEquals($result, $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testHtmlall() { $encoded = "'"aäЗдра><&amp;ääвсствуйте"; @@ -46,16 +36,6 @@ class PluginModifierUnescapeTest extends PHPUnit_Smarty $this->assertEquals($result, $this->smarty->fetch($tpl)); } - public function testHtmlallWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $encoded = "'"aäЗдра><&amp;ääвсствуйте"; - $result = "'\"aäЗдра><&ääвсствуйте"; - $tpl = $this->smarty->createTemplate('string:{"' . $encoded . '"|unescape:"htmlall"}'); - $this->assertEquals($result, $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testUrl() { $encoded = "a%C3%A4%D0%97%D0%B4%D1%80%D0%B0%3E%3C%26amp%3B%C3%A4%C3%A4%D0%B2%D1%81%D1%81%D1%82%D0%B2%3F%3D%2B%D1%83%D0%B9%D1%82%D0%B5"; diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierUpperTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierUpperTest.php index 84d35a7c..7616f5ea 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierUpperTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierUpperTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginModifierUpperTest extends PHPUnit_Smarty { @@ -27,15 +27,6 @@ class PluginModifierUpperTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testDefaultWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $result = "IF STRIKE ISN'T SETTLED QUICKLY IT MAY LAST A WHILE."; - $tpl = $this->smarty->createTemplate('string:{"If Strike isn\'t Settled Quickly it may Last a While."|upper}'); - $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testUmlauts() { $result = "IF STRIKE ISN'T SÄTTLED ÜQUICKLY IT MAY LAST A WHILE."; @@ -43,12 +34,4 @@ class PluginModifierUpperTest extends PHPUnit_Smarty $this->assertEquals(str_replace("\r", '', $result), $this->smarty->fetch($tpl)); } - public function testUmlautsWithoutMbstring() - { - Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb'); - $result = "IF STRIKE ISN'T SÄTTLED ÜQUICKLY IT MAY LAST A WHILE."; - $tpl = $this->smarty->createTemplate('string:{"If Strike isn\'t Sättled ÜQuickly it may Last a While."|upper}'); - $this->assertNotEquals($result, $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } } diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierWordwrapTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierWordwrapTest.php index 20b6f223..a833735f 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierWordwrapTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierWordwrapTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PluginModifierWordwrapTest extends PHPUnit_Smarty { @@ -26,15 +26,6 @@ class PluginModifierWordwrapTest extends PHPUnit_Smarty $this->assertEquals("Blind woman gets new kidney from dad she hasn't seen in years.", $this->smarty->fetch($tpl)); } - public function testDefaultWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"Blind woman gets new kidney from dad she hasn\'t seen in years."|wordwrap}'); - $this->assertEquals("Blind woman gets new kidney from dad she hasn't seen in years.", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testDefaultUmlauts() { $tpl = $this->smarty->createTemplate('string:{"äöüßñ woman ñsä new kidney from dad she hasn\'t seen in years."|wordwrap:30}'); @@ -47,45 +38,18 @@ class PluginModifierWordwrapTest extends PHPUnit_Smarty $this->assertEquals("Blind woman gets new kidney\nfrom dad she hasn't seen in\nyears.", $this->smarty->fetch($tpl)); } - public function testLengthWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"Blind woman gets new kidney from dad she hasn\'t seen in years."|wordwrap:30}'); - $this->assertEquals("Blind woman gets new kidney\nfrom dad she hasn't seen in\nyears.", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testBreak() { $tpl = $this->smarty->createTemplate('string:{"Blind woman gets new kidney from dad she hasn\'t seen in years."|wordwrap:30:"<br />\n"}'); $this->assertEquals("Blind woman gets new kidney<br />\nfrom dad she hasn't seen in<br />\nyears.", $this->smarty->fetch($tpl)); } - public function testBreakWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"Blind woman gets new kidney from dad she hasn\'t seen in years."|wordwrap:30:"<br />\n"}'); - $this->assertEquals("Blind woman gets new kidney<br />\nfrom dad she hasn't seen in<br />\nyears.", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testLong() { $tpl = $this->smarty->createTemplate('string:{"Blind woman withaverylongandunpronoucablenameorso gets new kidney from dad she hasn\'t seen in years."|wordwrap:26:"\n"}'); $this->assertEquals("Blind woman\nwithaverylongandunpronoucablenameorso\ngets new kidney from dad\nshe hasn't seen in years.", $this->smarty->fetch($tpl)); } - public function testLongWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"Blind woman withaverylongandunpronoucablenameorso gets new kidney from dad she hasn\'t seen in years."|wordwrap:26:"\n"}'); - $this->assertEquals("Blind woman\nwithaverylongandunpronoucablenameorso\ngets new kidney from dad\nshe hasn't seen in years.", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testLongUmlauts() { $tpl = $this->smarty->createTemplate('string:{"äöüßñ woman ñsääöüßñameorsoäöüßñäöüßñäöüßñäöüßñßñ gets new kidney from dad she hasn\'t seen in years."|wordwrap:26}'); @@ -98,15 +62,6 @@ class PluginModifierWordwrapTest extends PHPUnit_Smarty $this->assertEquals("Blind woman\nwithaverylongandunpronouca\nblenameorso gets new\nkidney from dad she hasn't\nseen in years.", $this->smarty->fetch($tpl)); } - public function testLongCutWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"Blind woman withaverylongandunpronoucablenameorso gets new kidney from dad she hasn\'t seen in years."|wordwrap:26:"\n":true}'); - $this->assertEquals("Blind woman\nwithaverylongandunpronouca\nblenameorso gets new\nkidney from dad she hasn't\nseen in years.", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testLongCutUmlauts() { $tpl = $this->smarty->createTemplate('string:{"äöüßñ woman ñsääöüßñameorsoäöüßñäöüßñäöüßñäöüßñßñ gets new kidney from dad she hasn\'t seen in years."|wordwrap:26:"\n":true}'); @@ -119,15 +74,6 @@ class PluginModifierWordwrapTest extends PHPUnit_Smarty $this->assertEquals("Blind woman\ngets new kidney from dad she\nhasn't seen in years.", $this->smarty->fetch($tpl)); } - public function testLinebreaksWithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"Blind woman\ngets new kidney from dad she hasn\'t seen in years."|wordwrap:30}'); - $this->assertEquals("Blind woman\ngets new kidney from dad she\nhasn't seen in years.", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - public function testLinebreaks2() { $tpl = $this->smarty->createTemplate('string:{"Blind woman @@ -138,26 +84,4 @@ class PluginModifierWordwrapTest extends PHPUnit_Smarty new kidney from\ndad she hasn't seen in years.", $this->smarty->fetch($tpl)); } - public function testLinebreaks2WithoutMbstring() - { - Smarty::$_MBSTRING = false; - $this->smarty->setCompileId('mb'); - $tpl = $this->smarty->createTemplate('string:{"Blind woman - gets - new kidney from dad she hasn\'t seen in years."|wordwrap:30}'); - $this->assertEquals("Blind woman - gets - new kidney from\ndad she hasn't seen in years.", $this->smarty->fetch($tpl)); - Smarty::$_MBSTRING = true; - } - /* - public function testUnicodeSpaces() - { - // Some Unicode Spaces - $string = " hello spaced       words "; - $string = mb_convert_encoding($string, 'UTF-8', "HTML-ENTITIES"); - $tpl = $this->smarty->createTemplate('string:{"' . $string . '"|strip}'); - $this->assertEquals(" hello spaced words ", $this->smarty->fetch($tpl)); - } - */ } diff --git a/tests/UnitTests/TemplateSource/TagTests/Section/CompileSectionTest.php b/tests/UnitTests/TemplateSource/TagTests/Section/CompileSectionTest.php index bb196012..c8cb33b4 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Section/CompileSectionTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Section/CompileSectionTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of {section} tag * - * @package PHPunit + * @author Uwe Tews */ /** * class for {section} tag tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class CompileSectionTest extends PHPUnit_Smarty { @@ -65,9 +65,9 @@ class CompileSectionTest extends PHPUnit_Smarty /** * Test spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testSpacing($code, $result, $testName, $testNumber) { @@ -109,9 +109,9 @@ class CompileSectionTest extends PHPUnit_Smarty /** * Test spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestElseSpacing - * @runInSeparateProcess + * */ public function testElseSpacing($code, $result, $testName, $testNumber) { diff --git a/tests/UnitTests/TemplateSource/TagTests/SetFilter/CompileSetfilterTest.php b/tests/UnitTests/TemplateSource/TagTests/SetFilter/CompileSetfilterTest.php index e86f28fe..cdc27e40 100644 --- a/tests/UnitTests/TemplateSource/TagTests/SetFilter/CompileSetfilterTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/SetFilter/CompileSetfilterTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of {setfilter} tag * - * @package PHPunit + * @author Uwe Tews */ /** * class for {setfilter} tag tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class CompileSetfilterTest extends PHPUnit_Smarty { @@ -28,29 +28,29 @@ class CompileSetfilterTest extends PHPUnit_Smarty /** * @run * InSeparateProcess - * @preserveGlobalState disabled + * */ public function testNestedSetfilter() { $this->smarty->setCaching(1); - $tpl = $this->smarty->createTemplate('string:{$foo}{setfilter htmlspecialchars} {$foo}{$foo nocache}{setfilter escape:"mail"} {$foo}{$foo nocache}{/setfilter} {$foo}{/setfilter} {$foo}'); + $tpl = $this->smarty->createTemplate('string:{$foo}{setfilter escape} {$foo}{$foo nocache}{setfilter escape:"mail"} {$foo}{$foo nocache}{/setfilter} {$foo}{/setfilter} {$foo}'); $tpl->assign('foo', '<a@b.c>'); $this->assertEquals("<a@b.c> <a@b.c><a@b.c> <a [AT] b [DOT] c><a [AT] b [DOT] c> <a@b.c> <a@b.c>", $this->smarty->fetch($tpl)); } public function testNestedSetfilter1() { $this->smarty->setCaching(1); - $tpl = $this->smarty->createTemplate('string:{$foo}{setfilter htmlspecialchars} {$foo}{$foo nocache}{setfilter escape:"mail"} {$foo}{$foo nocache}{/setfilter} {$foo}{/setfilter} {$foo}'); + $tpl = $this->smarty->createTemplate('string:{$foo}{setfilter escape} {$foo}{$foo nocache}{setfilter escape:"mail"} {$foo}{$foo nocache}{/setfilter} {$foo}{/setfilter} {$foo}'); $tpl->assign('foo', '<e@f.d>'); $this->assertEquals("<a@b.c> <a@b.c><e@f.d> <a [AT] b [DOT] c><e [AT] f [DOT] d> <a@b.c> <a@b.c>", $this->smarty->fetch($tpl)); } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testNestedSetfilter2() { - $tpl = $this->smarty->createTemplate('string:{$foo}{setfilter htmlspecialchars} {$foo}{setfilter escape:"mail"} {$foo}{/setfilter} {$foo}{/setfilter} {$foo}'); + $tpl = $this->smarty->createTemplate('string:{$foo}{setfilter escape} {$foo}{setfilter escape:"mail"} {$foo}{/setfilter} {$foo}{/setfilter} {$foo}'); $tpl->assign('foo', '<a@b.c>'); $this->assertEquals("<a@b.c> <a@b.c> <a [AT] b [DOT] c> <a@b.c> <a@b.c>", $this->smarty->fetch($tpl)); } diff --git a/tests/UnitTests/TemplateSource/TagTests/Strip/CompileStripTest.php b/tests/UnitTests/TemplateSource/TagTests/Strip/CompileStripTest.php index 5e26728d..35b2eaac 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Strip/CompileStripTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Strip/CompileStripTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of strip tags * - * @package PHPunit + * @author Uwe Tews */ /** * class for strip tags tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class CompileStripTest extends PHPUnit_Smarty { @@ -31,7 +31,7 @@ class CompileStripTest extends PHPUnit_Smarty * Test {strip} tags * * @not runInSeparateProcess - * @preserveGlobalState disabled + * * @dataProvider dataTestStrip */ public function testStrip($code, $result, $testName, $testNumber) diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php index 6d1da7f5..3f13cb4c 100644 --- a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php @@ -2,16 +2,18 @@ /** * Smarty PHPunit tests compilation of {function} tag * - * @package PHPunit + * @author Uwe Tews */ +use Smarty\CompilerException; + /** * class for {function} tag tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class CompileFunctionTest extends PHPUnit_Smarty { @@ -26,8 +28,8 @@ class CompileFunctionTest extends PHPUnit_Smarty $this->cleanDirs(); } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProvider * test simple function call tag * @@ -39,8 +41,8 @@ class CompileFunctionTest extends PHPUnit_Smarty $this->assertEquals("default param default 1 2 1", $this->smarty->fetch('test_template_function_001.tpl'), $text); } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProvider * test simple function call tag * @@ -53,8 +55,8 @@ class CompileFunctionTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProvider * test simple function call tag cached */ @@ -67,8 +69,8 @@ class CompileFunctionTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProvider * test simple function call tag cached */ @@ -82,8 +84,8 @@ class CompileFunctionTest extends PHPUnit_Smarty /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProvider * test simple function call tag cached no cache default variable */ @@ -99,8 +101,8 @@ class CompileFunctionTest extends PHPUnit_Smarty /** * test simple function call tag cached no cache default variable 2 * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * */ public function testSimpleFunctionCachedNocacheDefault_002_2() { @@ -112,8 +114,8 @@ class CompileFunctionTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProviderCachingValue * test simple function call tag plugin * @@ -130,8 +132,8 @@ class CompileFunctionTest extends PHPUnit_Smarty /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProvider * test simple function call tag 2 * @@ -143,8 +145,8 @@ class CompileFunctionTest extends PHPUnit_Smarty /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProvider * test simple function call recursive */ @@ -154,8 +156,8 @@ class CompileFunctionTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProviderInline * test inherited function call tag * @@ -167,8 +169,8 @@ class CompileFunctionTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProviderInline * test function definition in include * @@ -182,8 +184,8 @@ class CompileFunctionTest extends PHPUnit_Smarty /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProviderInline * test external function definition cached * @@ -200,8 +202,8 @@ class CompileFunctionTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * test external function definition and called by fetch * */ @@ -214,8 +216,8 @@ class CompileFunctionTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProviderInline * test external function definition cached 2 * @@ -233,8 +235,8 @@ class CompileFunctionTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProviderInline * test external function definition nocache call * @@ -251,8 +253,8 @@ class CompileFunctionTest extends PHPUnit_Smarty } /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProviderInline * test external function definition nocache call 2 * @@ -272,8 +274,8 @@ class CompileFunctionTest extends PHPUnit_Smarty /** * test external function definition nocache call 3 * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProviderInline */ public function testExternalDefinedFunctionNocachedCall3($merge, $text) @@ -291,8 +293,8 @@ class CompileFunctionTest extends PHPUnit_Smarty /** * test external defined recursion * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider functionProvider */ public function testExternalDefinedFunctionRecursion($text) @@ -349,9 +351,9 @@ class CompileFunctionTest extends PHPUnit_Smarty /** * Test spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testSpacing($code, $result, $testName, $testNumber) { @@ -367,9 +369,9 @@ class CompileFunctionTest extends PHPUnit_Smarty /** * Test Output nocache spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testSpacingNocache($code, $result, $testName, $testNumber) { @@ -386,9 +388,9 @@ class CompileFunctionTest extends PHPUnit_Smarty /** * Test Output nocache spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testSpacingNocache2($code, $result, $testName, $testNumber) { @@ -437,7 +439,7 @@ class CompileFunctionTest extends PHPUnit_Smarty * Test handling of function names that are a security risk */ public function testIllegalFunctionName() { - $this->expectException(SmartyCompilerException::class); + $this->expectException(CompilerException::class); $this->smarty->fetch('string:{function name=\'rce(){};echo "hi";function \'}{/function}'); } diff --git a/tests/UnitTests/TemplateSource/TagTests/While/CompileWhileTest.php b/tests/UnitTests/TemplateSource/TagTests/While/CompileWhileTest.php index 984dd7bd..eaabf29b 100644 --- a/tests/UnitTests/TemplateSource/TagTests/While/CompileWhileTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/While/CompileWhileTest.php @@ -2,7 +2,7 @@ /** * Smarty PHPunit tests compilation of {while} tag * - * @package PHPunit + * @author Uwe Tews */ @@ -10,8 +10,8 @@ * class for {while} tag tests * * @not runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * */ class CompileWhileTest extends PHPUnit_Smarty { @@ -46,9 +46,9 @@ class CompileWhileTest extends PHPUnit_Smarty /** * Test spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testSpacing($code, $result, $testName, $testNumber) { @@ -101,8 +101,8 @@ class CompileWhileTest extends PHPUnit_Smarty /** * Test nocache * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider dataTestNocache */ public function testNocache($value, $nocache, $code, $result, $testName, $testNumber) @@ -120,7 +120,7 @@ class CompileWhileTest extends PHPUnit_Smarty } /* - * Data provider für testNocache + * Data provider for testNocache */ public function dataTestNocache() { diff --git a/tests/UnitTests/TemplateSource/TagTests/_Attributes/AttributeTest.php b/tests/UnitTests/TemplateSource/TagTests/_Attributes/AttributeTest.php index c6778469..9beb5d09 100644 --- a/tests/UnitTests/TemplateSource/TagTests/_Attributes/AttributeTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/_Attributes/AttributeTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests for tag attributes * - * @package PHPunit + * @author Uwe Tews */ /** * class for tag attribute tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class AttributeTest extends PHPUnit_Smarty { @@ -32,7 +32,7 @@ class AttributeTest extends PHPUnit_Smarty */ public function testRequiredAttributeVar() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('missing \'var\' attribute'); $this->smarty->fetch('string:{assign value=1}'); } @@ -42,7 +42,7 @@ class AttributeTest extends PHPUnit_Smarty */ public function testUnexpectedAttribute() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('unexpected \'bar\' attribute'); $this->smarty->fetch('string:{assign var=foo value=1 bar=2}'); } @@ -52,7 +52,7 @@ class AttributeTest extends PHPUnit_Smarty */ public function testIllegalOptionValue() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('for option flag \'nocache\''); $this->expectExceptionMessage('illegal value'); $this->smarty->fetch('string:{assign var=foo value=1 nocache=buh}'); @@ -63,7 +63,7 @@ class AttributeTest extends PHPUnit_Smarty */ public function testTooManyShorthands() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('too many shorthand attributes'); $this->smarty->fetch('string:{assign foo 1 2}'); } diff --git a/tests/UnitTests/TemplateSource/TagTests/_Error/CompileErrorTest.php b/tests/UnitTests/TemplateSource/TagTests/_Error/CompileErrorTest.php index 05e1e160..e3c3191b 100644 --- a/tests/UnitTests/TemplateSource/TagTests/_Error/CompileErrorTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/_Error/CompileErrorTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compiler errors * - * @package PHPunit + * @author Uwe Tews */ /** * class for compiler tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class CompileErrorTest extends PHPUnit_Smarty { @@ -30,7 +30,7 @@ class CompileErrorTest extends PHPUnit_Smarty */ public function testNoneExistingTemplateError() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('no.tpl'); $this->smarty->fetch('eval:{include file=\'no.tpl\'}'); } @@ -40,7 +40,7 @@ class CompileErrorTest extends PHPUnit_Smarty */ public function testUnknownTagError() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('unknown tag \'unknown\''); $this->smarty->fetch('eval:{unknown}'); } @@ -50,7 +50,7 @@ class CompileErrorTest extends PHPUnit_Smarty */ public function testUnclosedTagError() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('unclosed {if} tag'); $this->smarty->fetch('eval:{if true}'); } @@ -60,7 +60,7 @@ class CompileErrorTest extends PHPUnit_Smarty */ public function testSyntaxError() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('Unexpected "}"'); $this->smarty->fetch('eval:{assign var=}'); } diff --git a/tests/UnitTests/TemplateSource/TagTests/_Print/PrintTest.php b/tests/UnitTests/TemplateSource/TagTests/_Print/PrintTest.php index 8d2b2fc6..f10af7da 100644 --- a/tests/UnitTests/TemplateSource/TagTests/_Print/PrintTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/_Print/PrintTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests variable output with nocache attribute * - * @package PHPunit + * @author Uwe Tews */ /** * class for variable output with nocache attribute tag tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PrintTest extends PHPUnit_Smarty { @@ -28,9 +28,9 @@ class PrintTest extends PHPUnit_Smarty /** * Test Output spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestOutputSpacing - * @runInSeparateProcess + * */ public function testOutputSpacing($code, $result, $testName, $testNumber) { @@ -46,9 +46,9 @@ class PrintTest extends PHPUnit_Smarty /** * Test Output nocache spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestOutputSpacing - * @runInSeparateProcess + * */ public function testOutputSpacingNocache($code, $result, $testName, $testNumber) { @@ -65,9 +65,9 @@ class PrintTest extends PHPUnit_Smarty /** * Test Output nocache spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestOutputSpacing - * @runInSeparateProcess + * */ public function testOutputSpacingNocache2($code, $result, $testName, $testNumber) { diff --git a/tests/UnitTests/TemplateSource/TagTests/break/CompileBreakTest.php b/tests/UnitTests/TemplateSource/TagTests/break/CompileBreakTest.php index c731e4d0..85e9aaaf 100644 --- a/tests/UnitTests/TemplateSource/TagTests/break/CompileBreakTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/break/CompileBreakTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compilation of {break} tag * - * @package PHPunit + * @author Uwe Tews */ /** * class for {break} tag tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class CompileBreakTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/TernaryTest.php b/tests/UnitTests/TemplateSource/TernaryTest.php new file mode 100644 index 00000000..95ce4b34 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TernaryTest.php @@ -0,0 +1,41 @@ +<?php + +class TernaryTest extends PHPUnit_Smarty { + + public function setUp(): void + { + $this->setUpSmarty('/tmp'); + $this->cleanDirs(); + } + + public function testTernaryTrue() { + $tpl = $this->smarty->createTemplate('string:{$a ? $b : $c}'); + $tpl->assign('a', true); + $tpl->assign('b', 'B'); + $tpl->assign('c', 'C'); + $this->assertEquals('B', $this->smarty->fetch($tpl)); + } + + public function testTernaryFalse() { + $tpl = $this->smarty->createTemplate('string:{$a ? $b : $c}'); + $tpl->assign('a', false); + $tpl->assign('b', 'B'); + $tpl->assign('c', 'C'); + $this->assertEquals('C', $this->smarty->fetch($tpl)); + } + + public function testShorthandTernaryTrue() { + $tpl = $this->smarty->createTemplate('string:{$a ?: $c}'); + $tpl->assign('a', true); + $tpl->assign('c', 'C'); + $this->assertEquals(true, $this->smarty->fetch($tpl)); + } + + public function testShorthandTernaryFalse() { + $tpl = $this->smarty->createTemplate('string:{$a ? $b : $c}'); + $tpl->assign('a', false); + $tpl->assign('c', 'C'); + $this->assertEquals('C', $this->smarty->fetch($tpl)); + } + +} diff --git a/tests/UnitTests/TemplateSource/ValueTests/Array/ArrayTest.php b/tests/UnitTests/TemplateSource/ValueTests/Array/ArrayTest.php index 75b1db85..94391ddd 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/Array/ArrayTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/Array/ArrayTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests array definitions and access * - * @package PHPunit + * @author Uwe Tews */ /** * class for array tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class ArrayTest extends PHPUnit_Smarty { @@ -27,9 +27,9 @@ class ArrayTest extends PHPUnit_Smarty /** * Test array access * - * @preserveGlobalState disabled + * * @dataProvider dataTestArray - * @runInSeparateProcess + * */ public function testArray($code, $result, $testName, $testNumber) { diff --git a/tests/UnitTests/TemplateSource/ValueTests/BoolenNull/BooleanNullTest.php b/tests/UnitTests/TemplateSource/ValueTests/BoolenNull/BooleanNullTest.php index d60a9a00..41b5a10c 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/BoolenNull/BooleanNullTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/BoolenNull/BooleanNullTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests literals true false null * - * @package PHPunit + * @author Uwe Tews */ /** * class for {$smarty.ldelim} {$smarty.rdelim} tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class BooleanNullTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/ValueTests/ConstantTests/ConstantsTest.php b/tests/UnitTests/TemplateSource/ValueTests/ConstantTests/ConstantsTest.php index fd821a8c..f85acafb 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/ConstantTests/ConstantsTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/ConstantTests/ConstantsTest.php @@ -3,11 +3,11 @@ /** * Smarty PHPunit tests of constants * - * @package PHPunit + * @author Uwe Tews - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ Class TestConst { diff --git a/tests/UnitTests/TemplateSource/ValueTests/DoubleQuoted/DoubleQuotedStringTest.php b/tests/UnitTests/TemplateSource/ValueTests/DoubleQuoted/DoubleQuotedStringTest.php index b6830230..688afb2e 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/DoubleQuoted/DoubleQuotedStringTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/DoubleQuoted/DoubleQuotedStringTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests double quoted strings * - * @package PHPunit + * @author Uwe Tews */ /** * class for double quoted string tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class DoubleQuotedStringTest extends PHPUnit_Smarty { @@ -31,7 +31,7 @@ class DoubleQuotedStringTest extends PHPUnit_Smarty /** * Test double qouted strings * - * @preserveGlobalState disabled + * * @dataProvider dataTestDoubleQuoted */ public function testDoubleQuoted($code, $result, $testName, $testNumber) @@ -84,7 +84,7 @@ class DoubleQuotedStringTest extends PHPUnit_Smarty */ public function testDoubleQuotedUnclosedBlock_001() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('unclosed \'{if}\' in doubled quoted string'); $this->smarty->fetch('001_unclosedBlock.tpl'); } diff --git a/tests/UnitTests/TemplateSource/ValueTests/Math/MathTest.php b/tests/UnitTests/TemplateSource/ValueTests/Math/MathTest.php index e4522e06..8d9f07f5 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/Math/MathTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/Math/MathTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class MathTest extends PHPUnit_Smarty { @@ -69,14 +69,6 @@ class MathTest extends PHPUnit_Smarty $this->assertEquals($expected, $this->smarty->fetch($tpl)); } - public function testSyntaxSin() - { - $this->smarty->disableSecurity(); - $expected = sin(4) . ' -- ' . sin(4); - $tpl = $this->smarty->createTemplate('eval:{$x = 4}{$x|sin} -- {$y = sin($x)}{$y}'); - $this->assertEquals($expected, $this->smarty->fetch($tpl)); - } - public function testFunctionSin() { $this->smarty->disableSecurity(); diff --git a/tests/UnitTests/TemplateSource/ValueTests/Modifier/ModifierTest.php b/tests/UnitTests/TemplateSource/ValueTests/Modifier/ModifierTest.php index 065a4920..2895ad97 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/Modifier/ModifierTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/Modifier/ModifierTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Uwe Tews */ /** * class for modifier tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class ModifierTest extends PHPUnit_Smarty { @@ -30,7 +30,7 @@ class ModifierTest extends PHPUnit_Smarty * Test modifier * * @not runInSeparateProcess - * @preserveGlobalState disabled + * * @dataProvider dataTestModifier */ public function testModifier($code, $result, $testName, $testNumber) @@ -79,7 +79,7 @@ class ModifierTest extends PHPUnit_Smarty */ public function testModifierRegisteredStaticClass() { - $this->smarty->registerPlugin(Smarty::PLUGIN_MODIFIER, 'testmodifier', array('testmodifierclass', 'staticcall')); + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'testmodifier', array('testmodifierclass', 'staticcall')); $this->smarty->assign('foo', 1); $this->assertEquals("mymodifier static 1", $this->smarty->fetch('testModifier_RegisteredStatic.tpl')); } @@ -90,7 +90,7 @@ class ModifierTest extends PHPUnit_Smarty public function testModifierRegisteredMethodCall() { $obj = new testmodifierclass(); - $this->smarty->registerPlugin(Smarty::PLUGIN_MODIFIER, 'testmodifier', array($obj, 'method')); + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'testmodifier', array($obj, 'method')); $this->smarty->assign('foo', 3); $this->assertEquals("mymodifier method 3", $this->smarty->fetch('testModifier_RegisteredMethod.tpl')); } @@ -100,7 +100,7 @@ class ModifierTest extends PHPUnit_Smarty */ public function testUnknownModifier() { - $this->expectException('SmartyCompilerException'); + $this->expectException(\Smarty\CompilerException::class); $this->expectExceptionMessage('unknown modifier \'unknown\''); $this->smarty->fetch('eval:{"hello world"|unknown}'); } @@ -110,7 +110,7 @@ class ModifierTest extends PHPUnit_Smarty */ public function testDefaultModifier() { - $this->smarty->default_modifiers = array('escape'); + $this->smarty->setDefaultModifiers(array('escape')); $this->smarty->assign('foo', '<bar>'); $this->assertEquals('<bar><bar>', $this->smarty->fetch('testModifier_Default.tpl')); } diff --git a/tests/UnitTests/TemplateSource/ValueTests/Objects/ObjectVariableTest.php b/tests/UnitTests/TemplateSource/ValueTests/Objects/ObjectVariableTest.php index 502a2271..9be49105 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/Objects/ObjectVariableTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/Objects/ObjectVariableTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests object variables * - * @package PHPunit + * @author Uwe Tews */ /** * class for object variable tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class ObjectVariableTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php b/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php index cf8970c5..cfbb32bb 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php @@ -2,7 +2,7 @@ /** * Smarty PHPunit tests of modifier * - * @package PHPunit + * @author Rodney Rehm */ @@ -11,9 +11,9 @@ * * * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PhpFunctionTest extends PHPUnit_Smarty { @@ -57,6 +57,7 @@ class PhpFunctionTest extends PHPUnit_Smarty public function testEmpty2() { $this->smarty->disableSecurity(); + $this->getSmarty()->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'pass', function ($v) { return $v; }); $this->smarty->assign('var', array(null, false, (int) 0, @@ -78,6 +79,7 @@ class PhpFunctionTest extends PHPUnit_Smarty public function testEmpty3() { $this->smarty->disableSecurity(); + $this->getSmarty()->registerPlugin(\Smarty\Smarty::PLUGIN_FUNCTION, 'pass', function ($v) { return $v; }); $this->smarty->assign('var', array(true, (int) 1, (float) 0.1, @@ -97,6 +99,7 @@ class PhpFunctionTest extends PHPUnit_Smarty public function testEmpty4() { $this->smarty->disableSecurity(); + $this->getSmarty()->registerPlugin(\Smarty\Smarty::PLUGIN_FUNCTION, 'pass', function ($v) { return $v; }); $this->smarty->assign('var', new TestIsset()); $expected = ' true , false , false , true , true , true , false '; $this->assertEquals($expected, $this->smarty->fetch('string:{strip}{if empty($var->isNull)} true {else} false {/IF} @@ -114,6 +117,7 @@ class PhpFunctionTest extends PHPUnit_Smarty public function testIsset1() { $this->smarty->disableSecurity(); + $this->getSmarty()->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'pass', function ($v) { return $v; }); $this->smarty->assign('isNull', null); $this->smarty->assign('isSet', 1); $this->smarty->assign('arr', array('isNull' => null, 'isSet' => 1)); @@ -135,6 +139,7 @@ class PhpFunctionTest extends PHPUnit_Smarty { $this->smarty->disableSecurity(); $this->smarty->assign('var', new TestIsset()); + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'pass', function ($v) { return $v; }); $expected = ' false , true , true , false , false , false , true '; $this->assertEquals($expected, $this->smarty->fetch('string:{strip}{if isset($var->isNull)} true {else} false {/IF} ,{if isset($var->isSet)} true {else} false {/IF} @@ -155,6 +160,7 @@ class PhpFunctionTest extends PHPUnit_Smarty public function testIsset3($strTemplate, $result) { $this->smarty->disableSecurity(); + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'intval', 'intval'); $this->smarty->assign('varobject', new TestIsset()); $this->smarty->assign('vararray', $vararray = array( @@ -199,15 +205,6 @@ class PhpFunctionTest extends PHPUnit_Smarty } /** - * @param mixed $v - * - * @return mixed - */ -function pass($v) { - return $v; -} - -/** * Class TestIsset */ class TestIsset { diff --git a/tests/UnitTests/TemplateSource/ValueTests/SingleQouted/SingleQuotedStringTest.php b/tests/UnitTests/TemplateSource/ValueTests/SingleQouted/SingleQuotedStringTest.php index 02919d93..e9f3333f 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/SingleQouted/SingleQuotedStringTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/SingleQouted/SingleQuotedStringTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests single quoted strings * - * @package PHPunit + * @author Uwe Tews */ /** * class for single quoted string tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class SingleQuotedStringTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Constant/SmartyConstantTest.php b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Constant/SmartyConstantTest.php index 08002c64..26ba767e 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Constant/SmartyConstantTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Constant/SmartyConstantTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests {$smarty.constant.foo} * - * @package PHPunit + * @author Uwe Tews */ /** * class for {$smarty.constant.foo} tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class SmartyConstantTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Cookie/CookieTest.php b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Cookie/CookieTest.php index 84bafb09..f54cd12c 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Cookie/CookieTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Cookie/CookieTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests {$smarty.cookies.foo} * - * @package PHPunit + * @author Uwe Tews */ /** * class for $smarty.cookies.foo} tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class CookieTest extends PHPUnit_Smarty { @@ -27,8 +27,8 @@ class CookieTest extends PHPUnit_Smarty /** * test cookies * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider dataProvider */ public function testCookie($caching, $value) { @@ -49,8 +49,8 @@ class CookieTest extends PHPUnit_Smarty /** * test cookies with modifier * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider dataProviderModifier */ public function testCookieModifier($caching, $value, $result) { diff --git a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Delimiter/SmartyDelimiterTest.php b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Delimiter/SmartyDelimiterTest.php index 3cb1de4a..47304b0d 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Delimiter/SmartyDelimiterTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Delimiter/SmartyDelimiterTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests {$smarty.ldelim} {$smarty.rdelim} * - * @package PHPunit + * @author Uwe Tews */ /** * class for {$smarty.ldelim} {$smarty.rdelim} tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class SmartyDelimiterTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Error/SmartyErrorTest.php b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Error/SmartyErrorTest.php index 40f85e59..baf805a6 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Error/SmartyErrorTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Error/SmartyErrorTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests undefined Smarty special variable * - * @package PHPunit + * @author Uwe Tews */ /** * class for undefined Smarty special variable tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class SmartyErrorTest extends PHPUnit_Smarty { @@ -28,8 +28,8 @@ class SmartyErrorTest extends PHPUnit_Smarty * test undefined Smarty special variable */ public function testSmartyError() { - $this->expectException('SmartyException'); + $this->expectException(\Smarty\Exception::class); $this->expectExceptionMessage('$smarty.foo is not defined'); - $this->assertEquals(Smarty::SMARTY_VERSION, $this->smarty->fetch('error.tpl')); + $this->assertEquals(\Smarty\Smarty::SMARTY_VERSION, $this->smarty->fetch('error.tpl')); } } diff --git a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Now/SmartyNowTest.php b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Now/SmartyNowTest.php index 4e5f5f50..32116a7c 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Now/SmartyNowTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Now/SmartyNowTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests {$smarty.now} * - * @package PHPunit + * @author Uwe Tews */ /** * class for {$smarty.now} tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class SmartyNowTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Post/PostTest.php b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Post/PostTest.php index b7204666..92bfea4a 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Post/PostTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Post/PostTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests {$smarty.post.foo} * - * @package PHPunit + * @author Uwe Tews */ /** * class for {$smarty.post.foo} tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class PostTest extends PHPUnit_Smarty { @@ -27,8 +27,8 @@ class PostTest extends PHPUnit_Smarty /** * test $_POST * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider dataProvider */ public function testPost($caching, $value) { @@ -40,8 +40,8 @@ class PostTest extends PHPUnit_Smarty /** * test $_POST with modifier * - * @runInSeparateProcess - * @preserveGlobalState disabled + * + * * @dataProvider dataProviderModifier */ public function testPostModifier($caching, $value, $result) { diff --git a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/TemplateObject/SmartyTemplateObjectTest.php b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/TemplateObject/SmartyTemplateObjectTest.php index 0fb2fe38..1ee56beb 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/TemplateObject/SmartyTemplateObjectTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/TemplateObject/SmartyTemplateObjectTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests {$smarty.template_objects} * - * @package PHPunit + * @author Uwe Tews */ /** * class for {$smarty.template_objects} tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class SmartyTemplateObjectTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/TemplateObject/templates/template_object.tpl b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/TemplateObject/templates/template_object.tpl index 08babe7e..d927d64b 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/TemplateObject/templates/template_object.tpl +++ b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/TemplateObject/templates/template_object.tpl @@ -1 +1 @@ -{if $smarty.template_object instanceof Smarty_Internal_Template}okay{/if}
\ No newline at end of file +{if $smarty.template_object instanceof \Smarty\Template}okay{/if}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Version/SmartyVersionTest.php b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Version/SmartyVersionTest.php index 8e295824..efbc2dd6 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Version/SmartyVersionTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/SmartySpecialVars/Version/SmartyVersionTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests {$smarty.version} * - * @package PHPunit + * @author Uwe Tews */ /** * class for {$smarty.version} tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class SmartyVersionTest extends PHPUnit_Smarty { @@ -29,6 +29,6 @@ class SmartyVersionTest extends PHPUnit_Smarty * */ public function testSmartyVersion() { - $this->assertEquals(Smarty::SMARTY_VERSION, $this->smarty->fetch('version.tpl')); + $this->assertEquals(\Smarty\Smarty::SMARTY_VERSION, $this->smarty->fetch('version.tpl')); } } diff --git a/tests/UnitTests/TemplateSource/ValueTests/Variables/Stream/StreamVariableTest.php b/tests/UnitTests/TemplateSource/ValueTests/Variables/Stream/StreamVariableTest.php index c832fc70..500dcc62 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/Variables/Stream/StreamVariableTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/Variables/Stream/StreamVariableTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests stream variables * - * @package PHPunit + * @author Uwe Tews */ /** * class for stream variables tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class StreamVariableTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/ValueTests/Variables/VariableVariable/VariableVariableTest.php b/tests/UnitTests/TemplateSource/ValueTests/Variables/VariableVariable/VariableVariableTest.php index 84843262..997a342a 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/Variables/VariableVariable/VariableVariableTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/Variables/VariableVariable/VariableVariableTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests variable variables * - * @package PHPunit + * @author Uwe Tews */ /** * class for variable variables tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class VariableVariableTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/X_Scopes/ScopeTest.php b/tests/UnitTests/TemplateSource/X_Scopes/ScopeTest.php index 8c0a7156..4f805fae 100644 --- a/tests/UnitTests/TemplateSource/X_Scopes/ScopeTest.php +++ b/tests/UnitTests/TemplateSource/X_Scopes/ScopeTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests for scopes * - * @package PHPunit + * @author Uwe Tews */ /** * class scope tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class ScopeTest extends PHPUnit_Smarty { @@ -31,27 +31,26 @@ class ScopeTest extends PHPUnit_Smarty /** * Test scope * - * @runInSeparateProcess - * @preserveGlobalState disabled * @dataProvider dataTestAppendScope */ public function testAppendScope($code, $useSmarty, $result, $testName, $testNumber) { $file = "testAppendScope_{$testNumber}.tpl"; $this->makeTemplateFile($file, $code . '{checkvar var=foo}'); - $this->smarty->assignGlobal('file', $file); - $this->smarty->assign('foo', 'smarty'); - $this->smarty->assignGlobal('foo', 'global'); + $this->smarty->assign('file', $file); + $this->smarty->assign('foo', 'global'); $data1 = $this->smarty->createData($useSmarty ? $this->smarty : null); $data = $this->smarty->createData($data1); $data1->assign('foo', 'data1'); $data->assign('foo', 'data'); - $this->assertEquals($result, $this->smarty->fetch('scope_tag.tpl', $data), - "test - {$code} - {$testName}"); + + $tpl = $this->smarty->createTemplate('scope_tag.tpl', $data); + + $this->assertEquals($result, $this->smarty->fetch($tpl),"test - {$code} - {$testName}"); } - /* - * Data provider für testAppendScope + /** + * Data provider for testAppendScope */ public function dataTestAppendScope() { @@ -62,42 +61,76 @@ class ScopeTest extends PHPUnit_Smarty * result * test name */ - return array(array('{$foo[] = \'newvar\' scope=tpl_root}', true, - '#testAppendScope_0.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)#scope_include.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)#scope_tag.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)#data:$foo =\'data\'#data:$foo =\'data1\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++,), - array('{append var=foo value=\'newvar\' scope=tpl_root}', true, - '#testAppendScope_1.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)#scope_include.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)#scope_tag.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)#data:$foo =\'data\'#data:$foo =\'data1\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++,), - array('{append var=foo value=\'newvar\' scope=global}', true, - '#testAppendScope_2.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)#scope_include.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)#scope_tag.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)#data:$foo =\'data\'#data:$foo =\'data1\'#Smarty:$foo =\'smarty\'#global:$foo =array(0=>\'data\',1=>\'newvar\',)', - '', $i ++,), - array('{append var=foo value=\'newvar\' scope=smarty}', true, - '#testAppendScope_3.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)#scope_include.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)#scope_tag.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)#data:$foo =\'data\'#data:$foo =\'data1\'#Smarty:$foo =array(0=>\'data\',1=>\'newvar\',)#global:$foo =\'global\'', - '', $i ++,),); + return [ + [ + '{$foo[] = \'newvar\' scope=tpl_root}', + true, + '#testAppendScope_0.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)' . + '#scope_include.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)' . + '#scope_tag.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)' . + '#data:$foo =\'data\'' . + '#data:$foo =\'data1\'' . + '#global:$foo =\'global\'', + '', + $i++, + ], + [ + '{append var=foo value=\'newvar\' scope=tpl_root}', true, + '#testAppendScope_1.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)' . + '#scope_include.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)' . + '#scope_tag.tpl:$foo =array(0=>\'data\',1=>\'newvar\',)' . + '#data:$foo =\'data\'' . + '#data:$foo =\'data1\'' . + '#global:$foo =\'global\'', + '', + $i++, + ], + [ + '{append var=foo value=\'newvar\' scope=global}', true, + '#testAppendScope_2.tpl:$foo =\'data\'' . + '#scope_include.tpl:$foo =\'data\'' . + '#scope_tag.tpl:$foo =\'data\'' . + '#data:$foo =\'data\'' . + '#data:$foo =\'data1\'' . + '#global:$foo =array(0=>\'data\',1=>\'newvar\',)', + '', + $i++, + ], + [ + '{append var=foo value=\'newvar\' scope=global}', true, + '#testAppendScope_3.tpl:$foo =\'data\'' . + '#scope_include.tpl:$foo =\'data\'' . + '#scope_tag.tpl:$foo =\'data\'' . + '#data:$foo =\'data\'' . + '#data:$foo =\'data1\'' . + '#global:$foo =array(0=>\'data\',1=>\'newvar\',)', + '', + $i++, + ], + ]; } /** * Test scope - * - * @not runInSeparateProcess - * @preserveGlobalState disabled * @dataProvider dataTestAssignScope */ public function testAssignScope($code, $useSmarty, $result, $testName, $testNumber) { $file = "testAssignScope_{$testNumber}.tpl"; $this->makeTemplateFile($file, $code . '{checkvar var=foo}'); - $this->smarty->assignGlobal('file', $file); - $this->smarty->assign('foo', 'smarty'); - $this->smarty->assignGlobal('foo', 'global'); + + $this->smarty->assign('foo', 'global'); $data = $this->smarty->createData($useSmarty ? $this->smarty : null); + $data->assign('file', $file); $data->assign('foo', 'data'); - $this->assertEquals('#' . $file . $result, - $this->smarty->fetch('scope_tag.tpl', $data), "test - {$code} - {$testName}"); + + $tpl = $this->smarty->createTemplate('scope_tag.tpl', $data); + + $this->assertEquals('#' . $file . $result, $this->smarty->fetch($tpl), "test - {$code} - {$testName}"); } /* - * Data provider für testAssignScope + * Data provider for testAssignScope */ public function dataTestAssignScope() { @@ -108,39 +141,48 @@ class ScopeTest extends PHPUnit_Smarty * result * test name */ - return array(array('{$foo = \'newvar\'}', true, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++,), array('{assign var=foo value=\'newvar\'}', true, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++,), array('{$foo = \'newvar\' scope=local}', true, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++,), - array('{assign var=foo value=\'newvar\' scope=local}', true, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++,), array('{$foo = \'newvar\' scope=parent}', true, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++,), array('{assign var=foo value=\'newvar\' scope=parent}', true, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++,), - array('{$foo = \'newvar\' scope=tpl_root}', true, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++,), array('{$foo = \'newvar\' scope=global}', true, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'newvar\'', - '', $i ++,), array('{$foo = \'newvar\' scope=root}', true, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++,), - array('{$foo = \'newvar\' scope=root}', false, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - 'no smarty', $i ++,), array('{$foo = \'newvar\' scope=smarty}', false, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'newvar\'#global:$foo =\'global\'', - 'no smarty', $i ++,),); + return [ + ['{$foo = \'newvar\'}', true, + ':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'', + 'default', $i++,], + ['{assign var=foo value=\'newvar\'}', true, + ':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'', + 'assign tag', $i++,], + ['{$foo = \'newvar\' scope=local}', true, + ':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'', + 'local', $i++,], + ['{assign var=foo value=\'newvar\' scope=local}', true, + ':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'', + 'assign tag local', $i++,], + ['{$foo = \'newvar\' scope=parent}', true, + ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'', + 'parent', $i++,], + ['{assign var=foo value=\'newvar\' scope=parent}', true, + ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'', + 'assign tag parent', $i++,], + ['{$foo = \'newvar\' scope=tpl_root}', true, + ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'data\'#global:$foo =\'global\'', + 'tpl_root', $i++,], + ['{$foo = \'newvar\' scope=global}', true, + ':$foo =\'data\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'newvar\'', + 'global', $i++,], + ['{$foo = \'newvar\' scope=root}', true, + ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#global:$foo =\'global\'', + 'root', $i++,], + ['{$foo = \'newvar\' scope=root}', false, + ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#global:$foo =\'global\'', + 'root, no smarty', $i++,], + ['{$foo = \'newvar\' scope=global}', false, + ':$foo =\'data\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'newvar\'', + 'global, no smarty', $i++,], + ]; } - /** - * Test scope nocache - * - * @runInSeparateProcess - * @preserveGlobalState disabled + /** + * Test scope nocache + * + * + * * @dataProvider dataTestScopeNocache */ public function testScopeNocache($var, $file, $result) @@ -163,36 +205,29 @@ class ScopeTest extends PHPUnit_Smarty * result */ return array(array('b1', 'test_scope_assignbar.tpl', - '#test_scope_assignbar.tpl:$foo =\'b1\'#Smarty:$foo =\'smarty\'#global:$foo =\'b1\'',), + '#test_scope_assignbar.tpl:$foo =\'b1\'#global:$foo =\'b1\'',), array('b2', 'test_scope_assignbar.tpl', - '#test_scope_assignbar.tpl:$foo =\'b2\'#Smarty:$foo =\'smarty\'#global:$foo =\'b2\'',), + '#test_scope_assignbar.tpl:$foo =\'b2\'#global:$foo =\'b2\'',), array('b1', 'test_scope_assignnocache.tpl', - '#test_scope_assignnocache.tpl:$foo =\'b1\'#Smarty:$foo =\'smarty\'#global:$foo =\'b1\'',), + '#test_scope_assignnocache.tpl:$foo =\'b1\'#global:$foo =\'b1\'',), array('b2', 'test_scope_assignnocache.tpl', - '#test_scope_assignnocache.tpl:$foo =\'b2\'#Smarty:$foo =\'smarty\'#global:$foo =\'b2\'',),); + '#test_scope_assignnocache.tpl:$foo =\'b2\'#global:$foo =\'b2\'',),); } /** * Test scope - * - * @runInSeparateProcess - * @preserveGlobalState disabled * @dataProvider dataTestIncludeScope */ public function testIncludeScope($code, $useSmarty, $result, $testName, $testNumber = null) { $file = "testIncludeScope_{$testNumber}.tpl"; $this->makeTemplateFile($file, $code); - $this->smarty->assignGlobal('file', $file); - $this->smarty->assign('foo', 'smarty'); - $this->smarty->assignGlobal('foo', 'global'); + $this->smarty->assign('foo', 'global'); $data = $this->smarty->createData($useSmarty ? $this->smarty : null); $data->assign('foo', 'data'); - if (!$useSmarty) { - $testName .= 'no smarty'; - } - $this->assertEquals($result, $this->smarty->fetch('test_scope.tpl', $data), - "test - {$code} - {$testName}"); + $data->assign('file', $file); + $tpl = $this->smarty->createTemplate('test_scope.tpl', $data); + $this->assertEquals($result, $this->smarty->fetch($tpl), "test - {$code} - {$testName}"); } /* @@ -201,94 +236,85 @@ class ScopeTest extends PHPUnit_Smarty public function dataTestIncludeScope() { $i = 0; - return array(/* - * Code - * use Smarty object - * result - * test name - */ - array('{include \'test_scope_assign.tpl\'}', true, - '#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i . - '.tpl:$foo =\'data\'#test_scope.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++), array('{include \'test_scope_assign.tpl\' scope=parent}', true, - '#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i . - '.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++), - array('{include \'test_scope_assign.tpl\' scope=tpl_root}', true, - '#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i . - '.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++), array('{include \'test_scope_assign.tpl\' scope=root}', true, - '#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i . - '.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++), array('{include \'test_scope_assign.tpl\' scope=root}', false, - '#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . - $i . - '.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++), - array('{include \'test_scope_assign.tpl\' scope=smarty}', true, - '#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i . - '.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'newvar\'#global:$foo =\'global\'', - '', $i ++), array('{include \'test_scope_assign.tpl\' scope=global}', true, - '#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i . - '.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'newvar\'', - '', $i ++), - array('{include \'test_scope_pluginassign.tpl\' scope=global}', true, - '#test_scope_pluginassign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i . - '.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'newvar\'', - '', $i ++), array('{include \'test_scope_assign_noscope.tpl\' scope=root}', true, - '#test_scope_assign_noscope.tpl:$foo =\'newvar\'#testIncludeScope_' . $i . - '.tpl:$foo =\'data\'#test_scope.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'', - '', $i ++),); + return [ + /* + * Code + * use Smarty object + * result + * test name + */ + ['{include \'test_scope_assign.tpl\'}', true, + '#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i . + '.tpl:$foo =\'data\'#test_scope.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'', + 'basic', $i++], + ['{include \'test_scope_assign.tpl\' scope=parent}', true, + '#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i . + '.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'', + 'parent scope', $i++], + ['{include \'test_scope_assign.tpl\' scope=tpl_root}', true, + '#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i . + '.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'data\'#global:$foo =\'global\'', + 'tpl_root scope', $i++], + ['{include \'test_scope_assign.tpl\' scope=root}', true, + '#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i . + '.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#global:$foo =\'global\'', + 'root scope', $i++], + ['{include \'test_scope_assign.tpl\' scope=root}', false, + '#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i . + '.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#global:$foo =\'global\'', + 'root scope / no smarty', $i++], + ['{include \'test_scope_assign.tpl\' scope=global}', true, + '#test_scope_assign.tpl:$foo =\'data\'#testIncludeScope_' . $i . + '.tpl:$foo =\'data\'#test_scope.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'newvar\'', + 'global scope', $i++], + ['{include \'test_scope_pluginassign.tpl\' scope=global}', true, + '#test_scope_pluginassign.tpl:$foo =\'data\'#testIncludeScope_' . $i . + '.tpl:$foo =\'data\'#test_scope.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'newvar\'', + 'pluginassign global', $i++], + ['{include \'test_scope_assign_noscope.tpl\' scope=root}', true, + '#test_scope_assign_noscope.tpl:$foo =\'newvar\'#testIncludeScope_' . $i . + '.tpl:$foo =\'data\'#test_scope.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'', + 'noscope root', $i++], + ]; } /** * Test scope - * - * @not runInSeparateProcess - * @preserveGlobalState disabled * @dataProvider dataTestConfigScope */ public function testConfigScope($code, $useSmarty, $result, $testName, $testNumber) { $file = "testConfigScope_{$testNumber}.tpl"; $this->makeTemplateFile($file, $code . '{checkconfigvar var=foo}'); - $this->smarty->assignGlobal('file', $file); - $this->smarty->configLoad('smarty.conf'); - $data = $this->smarty->createData($useSmarty ? $this->smarty : null); - $data->configLoad('data.conf'); - $this->assertEquals('#' . $file . $result, - $this->smarty->fetch('scope_tag.tpl', $data), "test - {$code} - {$testName}"); + $this->smarty->configLoad('smarty.conf'); + $data = $this->smarty->createData($useSmarty ? $this->smarty : null); + $data->assign('file', $file); + $data->configLoad('data.conf'); + $tpl = $this->smarty->createTemplate('scope_tag.tpl', $data); + $this->assertEquals( + '#' . $file . $result, + $this->smarty->fetch($tpl), + "test - {$code} - {$testName} + "); } /* - * Data provider für testConfigScope + * Data provider for testConfigScope */ public function dataTestConfigScope() { - $i = 0; - /* - * Code - * use Smarty object - * result - * test name - */ - return array(array('{config_load \'template.conf\'}', true, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'', - '', $i ++,), array('{config_load \'template.conf\' scope=local}', true, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'', - '', $i ++,), array('{config_load \'template.conf\' scope=parent}', true, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'', - '', $i ++,), - array('{config_load \'template.conf\' scope=tpl_root}', true, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'', - '', $i ++,), array('{config_load \'template.conf\' scope=root}', true, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#Smarty:$foo =\'smarty\'', - '', $i ++,), array('{config_load \'template.conf\' scope=root}', false, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#Smarty:$foo =\'smarty\'', - 'no smarty', $i ++,), - array('{config_load \'template.conf\' scope=smarty}', false, - ':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'newvar\'', - 'no smarty', $i ++,),); + $i = 0; + /* + * Code + * use Smarty object + * result + * test name + */ + return [ + ['{config_load \'template.conf\'}', true, + ':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'smarty\'', + '', $i++,], + ]; } /** diff --git a/tests/UnitTests/TemplateSource/Xml/XmlTest.php b/tests/UnitTests/TemplateSource/Xml/XmlTest.php index 542f2c41..fe7de221 100644 --- a/tests/UnitTests/TemplateSource/Xml/XmlTest.php +++ b/tests/UnitTests/TemplateSource/Xml/XmlTest.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests of the <?xml...> tag handling * - * @package PHPunit + * @author Uwe Tews */ /** * class for <?xml...> tests * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * + * + * */ class XmlTest extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/_Issues/327/ModifierIssue327Test.php b/tests/UnitTests/TemplateSource/_Issues/327/ModifierIssue327Test.php index caacbebd..c9ba0d26 100644 --- a/tests/UnitTests/TemplateSource/_Issues/327/ModifierIssue327Test.php +++ b/tests/UnitTests/TemplateSource/_Issues/327/ModifierIssue327Test.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compiler errors * - * @package PHPunit + * @author Uwe Tews */ /** * class for compiler tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class ModifierIssue327Test extends PHPUnit_Smarty { diff --git a/tests/UnitTests/TemplateSource/_Issues/419/ExtendsIssue419Test.php b/tests/UnitTests/TemplateSource/_Issues/419/ExtendsIssue419Test.php index 5ea20027..2079fc0a 100644 --- a/tests/UnitTests/TemplateSource/_Issues/419/ExtendsIssue419Test.php +++ b/tests/UnitTests/TemplateSource/_Issues/419/ExtendsIssue419Test.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compiler errors * - * @package PHPunit + * @author Uwe Tews */ /** * class for compiler tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class ExtendsIssue419Test extends PHPUnit_Smarty { @@ -27,8 +27,8 @@ class ExtendsIssue419Test extends PHPUnit_Smarty public function testextends419() { - $this->smarty->left_delimiter = '{{'; - $this->smarty->right_delimiter = '}}'; + $this->smarty->setLeftDelimiter('{{'); + $this->smarty->setRightDelimiter('}}'); $this->assertEquals('child', $this->smarty->fetch('extends:001_parent.tpl|001_child.tpl')); } diff --git a/tests/UnitTests/TemplateSource/_Issues/422/NestedLoopIssue422Test.php b/tests/UnitTests/TemplateSource/_Issues/422/NestedLoopIssue422Test.php index e8104d5c..03a48e1f 100644 --- a/tests/UnitTests/TemplateSource/_Issues/422/NestedLoopIssue422Test.php +++ b/tests/UnitTests/TemplateSource/_Issues/422/NestedLoopIssue422Test.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compiler errors * - * @package PHPunit + * @author Uwe Tews */ /** * class for compiler tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * * * Problem with total property of {section} and {foreach} in nested loop */ diff --git a/tests/UnitTests/TemplateSource/_Issues/428/SectionPropertiesShortSyntaxIssue428Test.php b/tests/UnitTests/TemplateSource/_Issues/428/SectionPropertiesShortSyntaxIssue428Test.php index 7a9c6ab2..c880bcb2 100644 --- a/tests/UnitTests/TemplateSource/_Issues/428/SectionPropertiesShortSyntaxIssue428Test.php +++ b/tests/UnitTests/TemplateSource/_Issues/428/SectionPropertiesShortSyntaxIssue428Test.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compiler errors * - * @package PHPunit + * @author Uwe Tews */ /** * class for compiler tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * * * Short syntax of section properties did not work */ diff --git a/tests/UnitTests/TemplateSource/_Issues/549/MbSplitEncodingIssue549Test.php b/tests/UnitTests/TemplateSource/_Issues/549/MbSplitEncodingIssue549Test.php index 7490c56b..7ddb9283 100644 --- a/tests/UnitTests/TemplateSource/_Issues/549/MbSplitEncodingIssue549Test.php +++ b/tests/UnitTests/TemplateSource/_Issues/549/MbSplitEncodingIssue549Test.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests - issue #549 regression tests * - * @package PHPunit + * @author Andrey Repin <anrdaemon@yandex.ru> */ /** * class for compiler tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * * * mb_split breaks if Smarty encoding is not the same as mbstring regex encoding. */ @@ -30,18 +30,13 @@ class MbSplitEncodingIssue549Test extends PHPUnit_Smarty public function setUp(): void { - if(!\Smarty::$_MBSTRING) - { - $this->markTestSkipped("mbstring extension is not in use by Smarty"); - } - - $this->charset = \Smarty::$_CHARSET; + $this->charset = \Smarty\Smarty::$_CHARSET; $this->setUpSmarty(__DIR__); } protected function tearDown(): void { - \Smarty::$_CHARSET = $this->charset ?: \Smarty::$_CHARSET; + \Smarty\Smarty::$_CHARSET = $this->charset ?: \Smarty\Smarty::$_CHARSET; $this->cleanDirs(); } @@ -70,7 +65,7 @@ class MbSplitEncodingIssue549Test extends PHPUnit_Smarty \extract($data, \EXTR_SKIP); \mb_regex_encoding($mb_regex_encoding); - \Smarty::$_CHARSET = $mb_int_encoding; + \Smarty\Smarty::$_CHARSET = $mb_int_encoding; $this->assertEquals($result, $this->smarty->fetch("string:{\"$subject\"|replace:\"$pattern\":\"$replacement\"}")); } diff --git a/tests/UnitTests/TemplateSource/_Issues/topic26878/NewlineSpacing.php b/tests/UnitTests/TemplateSource/_Issues/topic26878/NewlineSpacing.php index 6fcf32ac..6de26639 100644 --- a/tests/UnitTests/TemplateSource/_Issues/topic26878/NewlineSpacing.php +++ b/tests/UnitTests/TemplateSource/_Issues/topic26878/NewlineSpacing.php @@ -2,16 +2,16 @@ /** * Smarty PHPunit tests compiler errors * - * @package PHPunit + * @author Uwe Tews */ /** * class for compiler tests * - * @runTestsInSeparateProcess + * * @preserveGlobalState disabled - * @backupStaticAttributes enabled + * */ class NewlineSpacing extends PHPUnit_Smarty { @@ -28,16 +28,16 @@ class NewlineSpacing extends PHPUnit_Smarty /** * Test spacings * - * @preserveGlobalState disabled + * * @dataProvider dataTestSpacing - * @runInSeparateProcess + * */ public function testSpacing($code, $result, $testName, $testNumber) { $name = empty($testName) ? $testNumber : $testName; $file = "Spacing_{$name}.tpl"; $this->makeTemplateFile($file, $code); - $this->smarty->template_dir = './templates_tmp'; + $this->smarty->setTemplateDir('./templates_tmp'); $this->smarty->assign('file', $file); $this->smarty->assign('foo', 'bar'); $this->assertEquals($result, diff --git a/tests/UnitTests/__shared/PHPunitplugins/block.dummyblock.php b/tests/UnitTests/__shared/PHPunitplugins/block.dummyblock.php index 7de4fa09..b20ca8ec 100644 --- a/tests/UnitTests/__shared/PHPunitplugins/block.dummyblock.php +++ b/tests/UnitTests/__shared/PHPunitplugins/block.dummyblock.php @@ -2,8 +2,8 @@ /** * Smarty block plugin dummy for testing plugin functionallity * - * @package Smarty - * @subpackage PHPunitPlugin + + */ /** * Smarty {dummyblock} {/dummyblock} diff --git a/tests/UnitTests/__shared/PHPunitplugins/compiler.getparamsshort.php b/tests/UnitTests/__shared/PHPunitplugins/compiler.getparamsshort.php index e5907eb1..368b4a91 100644 --- a/tests/UnitTests/__shared/PHPunitplugins/compiler.getparamsshort.php +++ b/tests/UnitTests/__shared/PHPunitplugins/compiler.getparamsshort.php @@ -2,10 +2,12 @@ /** * Smarty plugin params * - * @package Smarty - * @subpackage PHPunitPlugin + + */ +use Smarty\Compile\Base; + /** * Smarty {getparams} * @@ -14,13 +16,13 @@ * * @return string */ -class smarty_compiler_getparamsshort extends Smarty_Internal_CompileBase +class smarty_compiler_getparamsshort extends Base { /** * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $required_attributes = array(); @@ -28,18 +30,18 @@ class smarty_compiler_getparamsshort extends Smarty_Internal_CompileBase * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $optional_attributes = array('_any'); /** * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $shorttag_order = array('s1', 's2', 's3'); - public function compile($args, $compiler) + public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { $_attr = $this->getAttributes($compiler, $args); $output = '<?php echo "array('; diff --git a/tests/UnitTests/__shared/PHPunitplugins/function.checkconfigvar.php b/tests/UnitTests/__shared/PHPunitplugins/function.checkconfigvar.php index c026793b..94fcc2c9 100644 --- a/tests/UnitTests/__shared/PHPunitplugins/function.checkconfigvar.php +++ b/tests/UnitTests/__shared/PHPunitplugins/function.checkconfigvar.php @@ -2,10 +2,12 @@ /** * Smarty plugin for testing scopes in config vars * - * @package Smarty - * @subpackage PHPunitPlugin + + */ +use Smarty\Template; + /** * Smarty {checkconfigvar} * @@ -17,29 +19,29 @@ function smarty_function_checkconfigvar($params, $template) { $output = ''; - $types = array('template', 'data', 'smarty'); + $types = array('template', 'data', 'global'); if (isset($params['types'])) { $types = (array)$params['types']; } $var = $params['var']; $ptr = $template; while ($ptr) { - if (in_array('template', $types) && $ptr instanceof Smarty_Internal_Template) { - $output .= "#{$ptr->source->name}:\${$var} ="; - $output .= isset($ptr->config_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->config_vars[$var], true)) : 'null'; + if (in_array('template', $types) && $ptr instanceof Template) { + $output .= "#{$ptr->getSource()->name}:\${$var} ="; + $output .= $ptr->hasConfigVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getConfigVariable($var), true)) : 'null'; $ptr = $ptr->parent; - } elseif (in_array('data', $types) && $ptr instanceof Smarty_Data) { + } elseif (in_array('data', $types) && !($ptr instanceof Template || $ptr instanceof \Smarty\Smarty)) { $output .= "#data:\${$var} ="; - $output .= isset($ptr->config_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->config_vars[$var], true)) : 'null'; + $output .= $ptr->hasConfigVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getConfigVariable($var), true)) : 'null'; $ptr = $ptr->parent; } else { $ptr = null; } } - if (in_array('smarty', $types)) { - $output .= "#Smarty:\${$var} ="; - $output .= isset($template->smarty->config_vars[ $var ]) ? - preg_replace('/\s/', '', var_export($template->smarty->config_vars[ $var ], true)) : 'null'; + if (in_array('global', $types)) { + $output .= "#global:\${$var} ="; + $output .= $template->getSmarty()->hasConfigVariable($var) ? + preg_replace('/\s/', '', var_export($template->getSmarty()->getConfigVariable($var), true)) : 'null'; } return $output; } diff --git a/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php b/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php index 5d549c8b..62a4e674 100644 --- a/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php +++ b/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php @@ -2,55 +2,52 @@ /** * Smarty plugin for testing scopes * - * @package Smarty - * @subpackage PHPunitPlugin + + */ +use Smarty\Template; + /** * Smarty {checkvar} * * @param array $params parameter array - * @param object $template template object + * @param Template $template template object * * @return string */ -function smarty_function_checkvar($params, $template) +function smarty_function_checkvar($params, \Smarty\Template $template) { $output = ''; - $types = array('template', 'data', 'smarty', 'global'); + $types = ['template', 'data', 'global']; if (isset($params['types'])) { $types = (array)$params['types']; } $var = $params['var']; $ptr = $template; while ($ptr) { - if (in_array('template', $types) && $ptr instanceof Smarty_Internal_Template) { - $output .= "#{$ptr->source->name}:\${$var} ="; - $output .= isset($ptr->tpl_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->tpl_vars[$var]->value, true)) : '>unassigned<'; + if (in_array('template', $types) && $ptr instanceof Template) { + $output .= "#{$ptr->getSource()->name}:\${$var} ="; + $output .= $ptr->hasVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getValue($var), true)) : '>unassigned<'; $i = 0; - while (isset($ptr->_cache[ 'varStack' ][ $i ])) { - $output .= "#{$ptr->_cache[ 'varStack' ][ $i ]['name']} = "; - $output .= isset($ptr->_cache[ 'varStack' ][ $i ][ 'tpl' ][$var]) ? preg_replace('/\s/', '', var_export($ptr->_cache[ 'varStack' ][ $i ][ 'tpl' ][$var]->value, true)) : '>unassigned<'; + while (isset($ptr->_var_stack[ $i ])) { + $output .= "#{$ptr->_var_stack[ $i ]['name']} = "; + $output .= isset($ptr->_var_stack[ $i ][ 'tpl' ][$var]) ? preg_replace('/\s/', '', var_export($ptr->_var_stack[ $i ][ 'tpl' ][$var]->value, true)) : '>unassigned<'; $i ++; } $ptr = $ptr->parent; - } elseif (in_array('data', $types) && $ptr instanceof Smarty_Data) { + } elseif (in_array('data', $types) && !($ptr instanceof Template || $ptr instanceof \Smarty\Smarty)) { $output .= "#data:\${$var} ="; - $output .= isset($ptr->tpl_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->tpl_vars[$var]->value, true)) : '>unassigned<'; + $output .= $ptr->hasVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getValue($var), true)) : '>unassigned<'; $ptr = $ptr->parent; } else { $ptr = null; } } - if (in_array('smarty', $types)) { - $output .= "#Smarty:\${$var} ="; - $output .= isset($template->smarty->tpl_vars[ $var ]) ? - preg_replace('/\s/', '', var_export($template->smarty->tpl_vars[ $var ]->value, true)) : '>unassigned<'; - } if (in_array('global', $types)) { $output .= "#global:\${$var} ="; - $output .= isset(Smarty::$global_tpl_vars[ $var ]) ? - preg_replace('/\s/', '', var_export(Smarty::$global_tpl_vars[ $var ]->value, true)) : '>unassigned<'; + $output .= $template->getSmarty()->hasVariable($var) ? + preg_replace('/\s/', '', var_export($template->getSmarty()->getValue($var), true)) : '>unassigned<'; } return $output; } diff --git a/tests/UnitTests/__shared/PHPunitplugins/function.getparams.php b/tests/UnitTests/__shared/PHPunitplugins/function.getparams.php index be1c26ab..41075800 100644 --- a/tests/UnitTests/__shared/PHPunitplugins/function.getparams.php +++ b/tests/UnitTests/__shared/PHPunitplugins/function.getparams.php @@ -2,10 +2,12 @@ /** * Smarty plugin params * - * @package Smarty - * @subpackage PHPunitPlugin + + */ +use Smarty\Template; + /** * Smarty {gatparams} * @@ -14,7 +16,7 @@ * * @return string */ -function smarty_function_getparams($params, Smarty_Internal_Template $template) +function smarty_function_getparams($params, Template $template) { return var_export($params, true); } diff --git a/tests/UnitTests/__shared/PHPunitplugins/function.getvar.php b/tests/UnitTests/__shared/PHPunitplugins/function.getvar.php index 2b78fbbb..c1b0756b 100644 --- a/tests/UnitTests/__shared/PHPunitplugins/function.getvar.php +++ b/tests/UnitTests/__shared/PHPunitplugins/function.getvar.php @@ -2,10 +2,12 @@ /** * Smarty plugin getvar * - * @package Smarty - * @subpackage PHPunitPlugin + + */ +use Smarty\Template; + /** * Smarty {getvar} * @@ -14,7 +16,7 @@ * * @return string */ -function smarty_function_getvar($params, Smarty_Internal_Template $template) +function smarty_function_getvar($params, Template $template) { if (isset($params[ 'assign' ])) { $template->assign($params[ 'assign' ], $template->getTemplateVars($params[ 'var' ])); diff --git a/tests/UnitTests/__shared/PHPunitplugins/function.pluginassign.php b/tests/UnitTests/__shared/PHPunitplugins/function.pluginassign.php index 111d9d05..7786b742 100644 --- a/tests/UnitTests/__shared/PHPunitplugins/function.pluginassign.php +++ b/tests/UnitTests/__shared/PHPunitplugins/function.pluginassign.php @@ -2,8 +2,8 @@ /** * Smarty plugin for assign * - * @package Smarty - * @subpackage PHPunitPlugin + + */ /** diff --git a/tests/UnitTests/__shared/cacheresources/cacheresource.apc.php b/tests/UnitTests/__shared/cacheresources/cacheresource.apc.php new file mode 100644 index 00000000..3f437888 --- /dev/null +++ b/tests/UnitTests/__shared/cacheresources/cacheresource.apc.php @@ -0,0 +1,73 @@ +<?php + +/** + * APC CacheResource + * CacheResource Implementation based on the KeyValueStore API to use + * memcache as the storage resource for Smarty's output caching. + * * + * + + * @author Uwe Tews + */ +class Smarty_CacheResource_Apc extends \Smarty\Cacheresource\KeyValueStore +{ + + /** + * Read values for a set of keys from cache + * + * @param array $keys list of keys to fetch + * + * @return array list of values with the given keys used as indexes + * @return boolean true on success, false on failure + */ + protected function read(array $keys) + { + $_res = array(); + $res = apc_fetch($keys); + foreach ($res as $k => $v) { + $_res[ $k ] = $v; + } + return $_res; + } + + /** + * Save values for a set of keys to cache + * + * @param array $keys list of values to save + * @param int $expire expiration time + * + * @return boolean true on success, false on failure + */ + protected function write(array $keys, $expire = null) + { + foreach ($keys as $k => $v) { + apc_store($k, $v, $expire); + } + return true; + } + + /** + * Remove values from cache + * + * @param array $keys list of keys to delete + * + * @return boolean true on success, false on failure + */ + protected function delete(array $keys) + { + foreach ($keys as $k) { + apc_delete($k); + } + return true; + } + + /** + * Remove *all* values from cache + * + * @return boolean true on success, false on failure + */ + protected function purge() + { + return apc_clear_cache('user'); + } +} diff --git a/tests/UnitTests/__shared/cacheresources/cacheresource.memcache.php b/tests/UnitTests/__shared/cacheresources/cacheresource.memcache.php new file mode 100644 index 00000000..bc212a82 --- /dev/null +++ b/tests/UnitTests/__shared/cacheresources/cacheresource.memcache.php @@ -0,0 +1,101 @@ +<?php + +/** + * Memcache CacheResource + * CacheResource Implementation based on the KeyValueStore API to use + * memcache as the storage resource for Smarty's output caching. + * Note that memcache has a limitation of 256 characters per cache-key. + * To avoid complications all cache-keys are translated to a sha1 hash. + * + + * @author Rodney Rehm + */ +class Smarty_CacheResource_Memcache extends \Smarty\Cacheresource\KeyValueStore +{ + /** + * memcache instance + * + * @var Memcache + */ + private $memcache = null; + + /** + * @return Memcache|Memcached + */ + public function getMemcache() { + if ($this->memcache === null) { + if (class_exists('Memcached')) { + $this->memcache = new Memcached(); + } else { + $this->memcache = new Memcache(); + } + $this->memcache->addServer('127.0.0.1', 11211); + } + return $this->memcache; + } + + /** + * Read values for a set of keys from cache + * + * @param array $keys list of keys to fetch + * + * @return array list of values with the given keys used as indexes + * @return boolean true on success, false on failure + */ + protected function read(array $keys) + { + $res = array(); + foreach ($keys as $key) { + $k = sha1($key); + $res[$key] = $this->getMemcache()->get($k); + } + return $res; + } + + /** + * Save values for a set of keys to cache + * + * @param array $keys list of values to save + * @param int $expire expiration time + * + * @return boolean true on success, false on failure + */ + protected function write(array $keys, $expire = null) + { + foreach ($keys as $k => $v) { + $k = sha1($k); + if (class_exists('Memcached')) { + $this->getMemcache()->set($k, $v, $expire); + } else { + $this->getMemcache()->set($k, $v, 0, $expire); + } + } + return true; + } + + /** + * Remove values from cache + * + * @param array $keys list of keys to delete + * + * @return boolean true on success, false on failure + */ + protected function delete(array $keys) + { + foreach ($keys as $k) { + $k = sha1($k); + $this->getMemcache()->delete($k); + } + return true; + } + + /** + * Remove *all* values from cache + * + * @return boolean true on success, false on failure + */ + protected function purge() + { + return $this->getMemcache()->flush(); + } +} diff --git a/tests/UnitTests/__shared/cacheresources/cacheresource.mysql.php b/tests/UnitTests/__shared/cacheresources/cacheresource.mysql.php new file mode 100644 index 00000000..9b51c272 --- /dev/null +++ b/tests/UnitTests/__shared/cacheresources/cacheresource.mysql.php @@ -0,0 +1,190 @@ +<?php + +use Smarty\Exception; + +/** + * MySQL CacheResource + * CacheResource Implementation based on the Custom API to use + * MySQL as the storage resource for Smarty's output caching. + * Table definition: + * <pre>CREATE TABLE IF NOT EXISTS `output_cache` ( + * `id` CHAR(40) NOT NULL COMMENT 'sha1 hash', + * `name` VARCHAR(250) NOT NULL, + * `cache_id` VARCHAR(250) NULL DEFAULT NULL, + * `compile_id` VARCHAR(250) NULL DEFAULT NULL, + * `modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + * `content` LONGTEXT NOT NULL, + * PRIMARY KEY (`id`), + * INDEX(`name`), + * INDEX(`cache_id`), + * INDEX(`compile_id`), + * INDEX(`modified`) + * ) ENGINE = InnoDB;</pre> + * + + * @author Rodney Rehm + */ +class Smarty_CacheResource_Mysql extends \Smarty\Cacheresource\Custom +{ + + /** + * @return PDO + * @throws Exception + */ + protected function db(): PDO { + static $dbConn = null; + try { + return $dbConn ?? ($dbConn = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty")); + } catch (PDOException $e) { + throw new Exception('Mysql Resource failed: ' . $e->getMessage()); + } + } + + /** + * @return false|PDOStatement + * @throws Exception + */ + protected function fetchQuery() { + static $query = null; + return $query ?? $query = $this->db()->prepare('SELECT modified, content FROM output_cache WHERE id = :id'); + } + + /** + * @return false|PDOStatement + * @throws Exception + */ + protected function fetchTimestampQuery() { + static $query = null; + return $query ?? $query = $this->db()->prepare('SELECT modified FROM output_cache WHERE id = :id'); + } + + /** + * @return false|PDOStatement + * @throws Exception + */ + protected function saveQuery() { + static $query = null; + return $query ?? $query = $this->db()->prepare( + 'REPLACE INTO output_cache (id, name, cache_id, compile_id, content) + VALUES (:id, :name, :cache_id, :compile_id, :content)' + ); + } + + /** + * fetch cached content and its modification time from data source + * + * @param string $id unique cache content identifier + * @param string $name template name + * @param string $cache_id cache id + * @param string $compile_id compile id + * @param string $content cached content + * @param integer $mtime cache modification timestamp (epoch) + * + * @return void + * @throws Exception + */ + protected function fetch($id, $name, $cache_id, $compile_id, &$content, &$mtime) + { + $this->fetchQuery()->execute(array('id' => $id)); + $row = $this->fetchQuery()->fetch(); + $this->fetchQuery()->closeCursor(); + if ($row) { + $content = $row[ 'content' ]; + $mtime = strtotime($row[ 'modified' ]); + } else { + $content = null; + $mtime = null; + } + } + + /** + * Fetch cached content's modification timestamp from data source + * + * @note implementing this method is optional. Only implement it if modification times can be accessed faster than + * loading the complete cached content. + * + * @param string $id unique cache content identifier + * @param string $name template name + * @param string $cache_id cache id + * @param string $compile_id compile id + * + * @return integer|boolean timestamp (epoch) the template was modified, or false if not found + */ + protected function fetchTimestamp($id, $name, $cache_id, $compile_id) + { + $this->fetchTimestampQuery()->execute(array('id' => $id)); + $mtime = strtotime($this->fetchTimestampQuery()->fetchColumn()); + $this->fetchTimestampQuery()->closeCursor(); + return $mtime; + } + + /** + * Save content to cache + * + * @param string $id unique cache content identifier + * @param string $name template name + * @param string $cache_id cache id + * @param string $compile_id compile id + * @param integer|null $exp_time seconds till expiration time in seconds or null + * @param string $content content to cache + * + * @return boolean success + */ + protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content) + { + $this->saveQuery()->execute( + array('id' => $id, + 'name' => $name, + 'cache_id' => $cache_id, + 'compile_id' => $compile_id, + 'content' => $content,) + ); + return !!$this->saveQuery()->rowCount(); + } + + /** + * Delete content from cache + * + * @param string $name template name + * @param string $cache_id cache id + * @param string $compile_id compile id + * @param integer|null $exp_time seconds till expiration or null + * + * @return integer number of deleted caches + */ + protected function delete($name, $cache_id, $compile_id, $exp_time) + { + // delete the whole cache + if ($name === null && $cache_id === null && $compile_id === null && $exp_time === null) { + // returning the number of deleted caches would require a second query to count them + $query = $this->db()->query('TRUNCATE TABLE output_cache'); + return -1; + } + // build the filter + $where = array(); + // equal test name + if ($name !== null) { + $where[] = 'name = ' . $this->db()->quote($name); + } + // equal test compile_id + if ($compile_id !== null) { + $where[] = 'compile_id = ' . $this->db()->quote($compile_id); + } + // range test expiration time + if ($exp_time !== null) { + $where[] = 'modified < DATE_SUB(NOW(), INTERVAL ' . intval($exp_time) . ' SECOND)'; + } + // equal test cache_id and match sub-groups + if ($cache_id !== null) { + $where[] = + '(cache_id = ' . + $this->db()->quote($cache_id) . + ' OR cache_id LIKE ' . + $this->db()->quote($cache_id . '|%') . + ')'; + } + // run delete query + $query = $this->db()->query('DELETE FROM output_cache WHERE ' . join(' AND ', $where)); + return $query->rowCount(); + } +} diff --git a/tests/UnitTests/__shared/cacheresources/cacheresource.pdo.php b/tests/UnitTests/__shared/cacheresources/cacheresource.pdo.php new file mode 100644 index 00000000..8be18ec9 --- /dev/null +++ b/tests/UnitTests/__shared/cacheresources/cacheresource.pdo.php @@ -0,0 +1,347 @@ +<?php + +use Smarty\Exception; + +/** + * PDO Cache Handler + * Allows you to store Smarty Cache files into your db. + * Example table : + * CREATE TABLE `smarty_cache` ( + * `id` char(40) NOT NULL COMMENT 'sha1 hash', + * `name` varchar(250) NOT NULL, + * `cache_id` varchar(250) DEFAULT NULL, + * `compile_id` varchar(250) DEFAULT NULL, + * `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + * `expire` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + * `content` mediumblob NOT NULL, + * PRIMARY KEY (`id`), + * KEY `name` (`name`), + * KEY `cache_id` (`cache_id`), + * KEY `compile_id` (`compile_id`), + * KEY `modified` (`modified`), + * KEY `expire` (`expire`) + * ) ENGINE=InnoDB + * Example usage : + * $cnx = new PDO("mysql:host=localhost;dbname=mydb", "username", "password"); + * $smarty->setCachingType('pdo'); + * $smarty->registerCacheResource('pdo', new Smarty_CacheResource_Pdo($cnx, 'smarty_cache')); + * + * @author Beno!t POLASZEK - 2014 + */ +class Smarty_CacheResource_Pdo extends \Smarty\Cacheresource\Custom +{ + /** + * @var string[] + */ + protected $fetchStatements = array('default' => 'SELECT %2$s + FROM %1$s + WHERE 1 + AND id = :id + AND cache_id IS NULL + AND compile_id IS NULL', + 'withCacheId' => 'SELECT %2$s + FROM %1$s + WHERE 1 + AND id = :id + AND cache_id = :cache_id + AND compile_id IS NULL', + 'withCompileId' => 'SELECT %2$s + FROM %1$s + WHERE 1 + AND id = :id + AND compile_id = :compile_id + AND cache_id IS NULL', + 'withCacheIdAndCompileId' => 'SELECT %2$s + FROM %1$s + WHERE 1 + AND id = :id + AND cache_id = :cache_id + AND compile_id = :compile_id'); + + /** + * @var string + */ + protected $insertStatement = 'INSERT INTO %s + + SET id = :id, + name = :name, + cache_id = :cache_id, + compile_id = :compile_id, + modified = CURRENT_TIMESTAMP, + expire = DATE_ADD(CURRENT_TIMESTAMP, INTERVAL :expire SECOND), + content = :content + + ON DUPLICATE KEY UPDATE + name = :name, + cache_id = :cache_id, + compile_id = :compile_id, + modified = CURRENT_TIMESTAMP, + expire = DATE_ADD(CURRENT_TIMESTAMP, INTERVAL :expire SECOND), + content = :content'; + + /** + * @var string + */ + protected $deleteStatement = 'DELETE FROM %1$s WHERE %2$s'; + + /** + * @var string + */ + protected $truncateStatement = 'TRUNCATE TABLE %s'; + + /** + * @var string + */ + protected $fetchColumns = 'modified, content'; + + /** + * @var string + */ + protected $fetchTimestampColumns = 'modified'; + + /** + * @var \PDO + */ + protected $pdo; + + /** + * @var + */ + protected $table; + + /** + * @var null + */ + protected $database; + + /** + * Constructor + * + * @param PDO $pdo PDO : active connection + * @param string $table : table (or view) name + * @param string $database : optional - if table is located in another db + * + * @throws \Smarty\Exception + */ + public function __construct(PDO $pdo, $table, $database = null) + { + if (is_null($table)) { + throw new Exception("Table name for caching can't be null"); + } + $this->pdo = $pdo; + $this->table = $table; + $this->database = $database; + $this->fillStatementsWithTableName(); + } + + /** + * Fills the table name into the statements. + * + * @return $this Current Instance + * @access protected + */ + protected function fillStatementsWithTableName() + { + foreach ($this->fetchStatements as &$statement) { + $statement = sprintf($statement, $this->getTableName(), '%s'); + } + $this->insertStatement = sprintf($this->insertStatement, $this->getTableName()); + $this->deleteStatement = sprintf($this->deleteStatement, $this->getTableName(), '%s'); + $this->truncateStatement = sprintf($this->truncateStatement, $this->getTableName()); + return $this; + } + + /** + * Gets the fetch statement, depending on what you specify + * + * @param string $columns : the column(s) name(s) you want to retrieve from the database + * @param string $id unique cache content identifier + * @param string|null $cache_id cache id + * @param string|null $compile_id compile id + * + * @access protected + * @return \PDOStatement + */ + protected function getFetchStatement($columns, $id, $cache_id = null, $compile_id = null) + { + $args = array(); + if (!is_null($cache_id) && !is_null($compile_id)) { + $query = $this->fetchStatements[ 'withCacheIdAndCompileId' ] and + $args = array('id' => $id, 'cache_id' => $cache_id, 'compile_id' => $compile_id); + } elseif (is_null($cache_id) && !is_null($compile_id)) { + $query = $this->fetchStatements[ 'withCompileId' ] and + $args = array('id' => $id, 'compile_id' => $compile_id); + } elseif (!is_null($cache_id) && is_null($compile_id)) { + $query = $this->fetchStatements[ 'withCacheId' ] and $args = array('id' => $id, 'cache_id' => $cache_id); + } else { + $query = $this->fetchStatements[ 'default' ] and $args = array('id' => $id); + } + $query = sprintf($query, $columns); + $stmt = $this->pdo->prepare($query); + foreach ($args as $key => $value) { + $stmt->bindValue($key, $value); + } + return $stmt; + } + + /** + * fetch cached content and its modification time from data source + * + * @param string $id unique cache content identifier + * @param string $name template name + * @param string|null $cache_id cache id + * @param string|null $compile_id compile id + * @param string $content cached content + * @param integer $mtime cache modification timestamp (epoch) + * + * @return void + * @access protected + */ + protected function fetch($id, $name, $cache_id, $compile_id, &$content, &$mtime) + { + $stmt = $this->getFetchStatement($this->fetchColumns, $id, $cache_id, $compile_id); + $stmt->execute(); + $row = $stmt->fetch(); + $stmt->closeCursor(); + if ($row) { + $content = $this->outputContent($row[ 'content' ]); + $mtime = strtotime($row[ 'modified' ]); + } else { + $content = null; + $mtime = null; + } + } + + /** + * Fetch cached content's modification timestamp from data source + * {@internal implementing this method is optional. + * Only implement it if modification times can be accessed faster than loading the complete cached content.}} + * + * @param string $id unique cache content identifier + * @param string $name template name + * @param string|null $cache_id cache id + * @param string|null $compile_id compile id + * + * @return integer|boolean timestamp (epoch) the template was modified, or false if not found + * @access protected + */ + // protected function fetchTimestamp($id, $name, $cache_id = null, $compile_id = null) { + // $stmt = $this->getFetchStatement($this->fetchTimestampColumns, $id, $cache_id, $compile_id); + // $stmt -> execute(); + // $mtime = strtotime($stmt->fetchColumn()); + // $stmt -> closeCursor(); + // return $mtime; + // } + /** + * Save content to cache + * + * @param string $id unique cache content identifier + * @param string $name template name + * @param string|null $cache_id cache id + * @param string|null $compile_id compile id + * @param integer|null $exp_time seconds till expiration time in seconds or null + * @param string $content content to cache + * + * @return boolean success + * @access protected + */ + protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content) + { + $stmt = $this->pdo->prepare($this->insertStatement); + $stmt->bindValue('id', $id); + $stmt->bindValue('name', $name); + $stmt->bindValue('cache_id', $cache_id, (is_null($cache_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR); + $stmt->bindValue('compile_id', $compile_id, (is_null($compile_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR); + $stmt->bindValue('expire', (int)$exp_time, PDO::PARAM_INT); + $stmt->bindValue('content', $this->inputContent($content)); + $stmt->execute(); + return !!$stmt->rowCount(); + } + + /** + * Encodes the content before saving to database + * + * @param string $content + * + * @return string $content + * @access protected + */ + protected function inputContent($content) + { + return $content; + } + + /** + * Decodes the content before saving to database + * + * @param string $content + * + * @return string $content + * @access protected + */ + protected function outputContent($content) + { + return $content; + } + + /** + * Delete content from cache + * + * @param string|null $name template name + * @param string|null $cache_id cache id + * @param string|null $compile_id compile id + * @param integer|null|-1 $exp_time seconds till expiration or null + * + * @return integer number of deleted caches + * @access protected + */ + protected function delete($name = null, $cache_id = null, $compile_id = null, $exp_time = null) + { + // delete the whole cache + if ($name === null && $cache_id === null && $compile_id === null && $exp_time === null) { + // returning the number of deleted caches would require a second query to count them + $this->pdo->query($this->truncateStatement); + return -1; + } + // build the filter + $where = array(); + // equal test name + if ($name !== null) { + $where[] = 'name = ' . $this->pdo->quote($name); + } + // equal test cache_id and match sub-groups + if ($cache_id !== null) { + $where[] = + '(cache_id = ' . + $this->pdo->quote($cache_id) . + ' OR cache_id LIKE ' . + $this->pdo->quote($cache_id . '|%') . + ')'; + } + // equal test compile_id + if ($compile_id !== null) { + $where[] = 'compile_id = ' . $this->pdo->quote($compile_id); + } + // for clearing expired caches + if ($exp_time === \Smarty\Smarty::CLEAR_EXPIRED) { + $where[] = 'expire < CURRENT_TIMESTAMP'; + } // range test expiration time + elseif ($exp_time !== null) { + $where[] = 'modified < DATE_SUB(NOW(), INTERVAL ' . intval($exp_time) . ' SECOND)'; + } + // run delete query + $query = $this->pdo->query(sprintf($this->deleteStatement, join(' AND ', $where))); + return $query->rowCount(); + } + + /** + * Gets the formatted table name + * + * @return string + * @access protected + */ + protected function getTableName() + { + return (is_null($this->database)) ? "`{$this->table}`" : "`{$this->database}`.`{$this->table}`"; + } +} diff --git a/tests/UnitTests/__shared/cacheresources/cacheresource.pdo_gzip.php b/tests/UnitTests/__shared/cacheresources/cacheresource.pdo_gzip.php new file mode 100644 index 00000000..89818abb --- /dev/null +++ b/tests/UnitTests/__shared/cacheresources/cacheresource.pdo_gzip.php @@ -0,0 +1,42 @@ +<?php + +require_once __DIR__ . '/cacheresource.pdo.php'; + +/** + * PDO Cache Handler with GZIP support + * Example usage : + * $cnx = new PDO("mysql:host=localhost;dbname=mydb", "username", "password"); + * $smarty->setCachingType('pdo_gzip'); + * $smarty->registerCacheResource('pdo_gzip', new Smarty_CacheResource_Pdo_Gzip($cnx, 'smarty_cache')); + * + * @require Smarty_CacheResource_Pdo class + * @author Beno!t POLASZEK - 2014 + */ +class Smarty_CacheResource_Pdo_Gzip extends Smarty_CacheResource_Pdo +{ + /** + * Encodes the content before saving to database + * + * @param string $content + * + * @return string $content + * @access protected + */ + protected function inputContent($content) + { + return gzdeflate($content); + } + + /** + * Decodes the content before saving to database + * + * @param string $content + * + * @return string $content + * @access protected + */ + protected function outputContent($content) + { + return gzinflate($content); + } +} diff --git a/tests/UnitTests/__shared/resources/resource.extendsall.php b/tests/UnitTests/__shared/resources/resource.extendsall.php new file mode 100644 index 00000000..9ffddc05 --- /dev/null +++ b/tests/UnitTests/__shared/resources/resource.extendsall.php @@ -0,0 +1,66 @@ +<?php + +use Smarty\Exception; +use Smarty\Template; +use Smarty\Template\Source; + +/** + * Extends All Resource + * Resource Implementation modifying the extends-Resource to walk + * through the template_dirs and inherit all templates of the same name + * + + * @author Rodney Rehm + */ +class My_Resource_Extendsall extends \Smarty\Resource\ExtendsPlugin +{ + /** + * populate Source Object with meta data from Resource + * + * @param Source $source source object + * @param Template $_template template object + * + * @return void + */ + public function populate(Source $source, Template $_template = null) + { + $uid = ''; + $sources = array(); + $timestamp = 0; + foreach ($source->getSmarty()->getTemplateDir() as $key => $directory) { + try { + $s = \Smarty\Template\Source::load(null, $source->getSmarty(), + 'file:' . '[' . $key . ']' . $source->name); + if (!$s->exists) { + continue; + } + $sources[ $s->uid ] = $s; + $uid .= $s->uid; + $timestamp = $s->timestamp > $timestamp ? $s->timestamp : $timestamp; + } catch (Exception $e) { + } + } + if (!$sources) { + $source->exists = false; + return; + } + $sources = array_reverse($sources, true); + reset($sources); + $s = current($sources); + $source->components = $sources; + $source->uid = sha1($uid . $source->getSmarty()->_joined_template_dir); + $source->exists = true; + $source->timestamp = $timestamp; + } + + /** + * Disable timestamp checks for extendsall resource. + * The individual source components will be checked. + * + * @return bool false + */ + public function checkTimestamps() + { + return false; + } +} |
