summaryrefslogtreecommitdiff
path: root/tests/UnitTests/SmartyMethodsTests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/UnitTests/SmartyMethodsTests')
-rw-r--r--tests/UnitTests/SmartyMethodsTests/Append/AppendTest.php8
-rw-r--r--tests/UnitTests/SmartyMethodsTests/AppendByRef/AppendByRefTest.php64
-rw-r--r--tests/UnitTests/SmartyMethodsTests/AppendByRef/cache/.gitignore2
-rw-r--r--tests/UnitTests/SmartyMethodsTests/AppendByRef/templates_c/.gitignore2
-rw-r--r--tests/UnitTests/SmartyMethodsTests/Assign/AssignTest.php8
-rw-r--r--tests/UnitTests/SmartyMethodsTests/AssignByRef/AssignByRefTest.php33
-rw-r--r--tests/UnitTests/SmartyMethodsTests/AssignByRef/cache/.gitignore2
-rw-r--r--tests/UnitTests/SmartyMethodsTests/AssignByRef/templates_c/.gitignore2
-rw-r--r--tests/UnitTests/SmartyMethodsTests/AssignGlobal/AssignGlobalTest.php70
-rw-r--r--tests/UnitTests/SmartyMethodsTests/AssignGlobal/cache/.gitignore2
-rw-r--r--tests/UnitTests/SmartyMethodsTests/AssignGlobal/templates_c/.gitignore2
-rw-r--r--tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignTest.php10
-rw-r--r--tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignTest.php8
-rw-r--r--tests/UnitTests/SmartyMethodsTests/ClearCompiledTemplate/ClearCompiledTest.php67
-rw-r--r--tests/UnitTests/SmartyMethodsTests/CompileCheck/CompileCheckTest.php32
-rw-r--r--tests/UnitTests/SmartyMethodsTests/CompileCheck/templates_tmp/.gitignore1
-rw-r--r--tests/UnitTests/SmartyMethodsTests/GetTemplateVars/GetTemplateVarsTest.php20
-rw-r--r--tests/UnitTests/SmartyMethodsTests/RegisterBlock/RegisterBlockTest.php109
-rw-r--r--tests/UnitTests/SmartyMethodsTests/RegisterCompiler/RegisterCompilerFunctionTest.php18
-rw-r--r--tests/UnitTests/SmartyMethodsTests/RegisterFunction/RegisterFunctionTest.php36
-rw-r--r--tests/UnitTests/SmartyMethodsTests/RegisterModifier/RegisterModifierTest.php89
-rw-r--r--tests/UnitTests/SmartyMethodsTests/RegisterObject/CompileRegisteredObjectFunctionTest.php8
-rw-r--r--tests/UnitTests/SmartyMethodsTests/TemplateExist/TemplateExistsTest.php8
23 files changed, 270 insertions, 331 deletions
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
{