Update for 3.1.28

This commit is contained in:
uwetews
2015-08-23 15:04:21 +02:00
parent 75adb86450
commit 5c416f2f0f
52 changed files with 135 additions and 103 deletions

View File

@@ -0,0 +1,5 @@
<?php
function smarty_function_plugin1($params, $template)
{
return 'plugin1';
}

View File

@@ -0,0 +1,5 @@
<?php
function smarty_function_plugin2($params, $template)
{
return 'plugin2';
}

View File

@@ -129,6 +129,8 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
mkdir($dir . '/configs');
}
if (individualFolders != 'true') {
$this->cleanDir($dir . '/templates_c');
$this->cleanDir($dir . '/cache');
$dir = __DIR__;
}
if (!is_dir($dir . '/templates_c')) {
@@ -529,49 +531,6 @@ KEY `expire` (`expire`)
}
}
/**
* Remove Smarty object from cached resources
*
*/
public function clearResourceCache()
{
if (class_exists('Smarty_Resource', false)) {
if (isset(Smarty_Resource::$sources) && !empty(Smarty_Resource::$sources)) {
foreach (Smarty_Resource::$sources as $obj) {
if (isset($obj->smarty)) {
$obj->smarty = null;
}
}
Smarty_Resource::$sources = array();
}
if (isset(Smarty_Resource::$compileds) && !empty(Smarty_Resource::$compileds)) {
foreach (Smarty_Resource::$compileds as $obj) {
if (isset($obj->smarty)) {
$obj->smarty = null;
}
}
Smarty_Resource::$compileds = array();
}
if (isset(Smarty_Resource::$resources) && !empty(Smarty_Resource::$resources)) {
foreach (Smarty_Resource::$resources as $obj) {
if (isset($obj->smarty)) {
$obj->smarty = null;
}
}
Smarty_Resource::$resources = array();
}
}
if (class_exists('Smarty_CacheResource', false)) {
if (isset(Smarty_CacheResource::$resources) && !empty(Smarty_CacheResource::$resources)) {
foreach (Smarty_CacheResource::$resources as $obj) {
if (isset($obj->smarty)) {
$obj->smarty = null;
}
}
Smarty_CacheResource::$resources = array();
}
}
}
/**
* Tears down the fixture
@@ -580,7 +539,6 @@ KEY `expire` (`expire`)
*/
protected function tearDown()
{
$this->clearResourceCache();
if (isset($this->smarty->smarty)) {
$this->smarty->smarty = null;
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Smarty PHPunit tests for File resources
*
* @package PHPunit
* @author Rodney Rehm
* @backupStaticAttributes enabled
*/
class IncludePathTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(__DIR__);
$this->smarty->use_include_path = true;
$this->smarty->setPluginsDir(array('./include','./include1'));
$this->smarty->enableSecurity();
$ds = DS;
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()
{
restore_include_path();
$this->smarty->disableSecurity();
parent::tearDown();
}
public function testInit()
{
$this->cleanDirs();
}
public function testInclude1()
{
$this->assertContains('plugin1', $this->smarty->fetch('test_include_path1.tpl'));
}
public function testInclude2()
{
$this->assertContains('plugin2', $this->smarty->fetch('test_include_path2.tpl'));
}
public function testInclude3()
{
$this->assertContains('plugin3', $this->smarty->fetch('test_include_path3.tpl'));
}
}

View File

@@ -0,0 +1,5 @@
<?php
function smarty_function_plugin3($params, $template)
{
return 'plugin3';
}

View File

@@ -0,0 +1 @@
{plugin1}

View File

@@ -0,0 +1 @@
{plugin2}

View File

@@ -0,0 +1 @@
{plugin3}

View File

@@ -30,7 +30,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty
public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
{
return str_replace('#', $tpl->getVariable('test'), $text);
return str_replace('#', $tpl->_getVariable('test'), $text);
}
/**
@@ -376,7 +376,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty
*/
public function testCache($lockTime, $lockTimeout, $compile_id, $cache_id, $isCached, $tmin, $tmax, $forceCompile, $forceCache, $update, $testNumber, $compileTestNumber, $renderTestNumber, $testName)
{
if ($testNumber == 27) {
if ($testNumber == 13) {
$i =0;
}
$this->smarty->caching = true;

View File

@@ -46,7 +46,7 @@ if (defined(MysqlResourceEnable) && MysqlResourceEnable == 'true') {
// $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
$this->smarty->addPluginsDir("./PHPunitplugins/");
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
$this->assertEquals(strtotime("2010-12-25 22:00:00"), $tpl->source->timestamp);
$this->assertEquals(strtotime("2010-12-25 22:00:00"), $tpl->source->getTimeStamp());
}
/**
@@ -81,7 +81,7 @@ if (defined(MysqlResourceEnable) && MysqlResourceEnable == 'true') {
// $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
$this->smarty->addPluginsDir("./PHPunitplugins/");
$tpl = $this->smarty->createTemplate('mysqlstest:test.tpl');
$this->assertEquals(strtotime("2010-12-25 22:00:00"), $tpl->source->timestamp);
$this->assertEquals(strtotime("2010-12-25 22:00:00"), $tpl->source->getTimeStamp());
}
}
}

View File

@@ -79,7 +79,7 @@ class EvalResourceTest extends PHPUnit_Smarty
public function testUsesCompiler()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertFalse($tpl->source->uncompiled);
$this->assertFalse($tpl->source->handler->uncompiled);
}
/**
@@ -88,7 +88,7 @@ class EvalResourceTest extends PHPUnit_Smarty
public function testIsEvaluated()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertTrue($tpl->source->recompiled);
$this->assertTrue($tpl->source->handler->recompiled);
}
/**

View File

@@ -52,7 +52,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty
$this->assertFalse($tpl->isCached());
$result = $this->smarty->fetch($tpl);
$this->assertContains('Grandchild Page Title', $result);
$this->smarty->template_objects = null;
$this->smarty->_cache['template_objects'] = null;
$tpl2 = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
$this->assertTrue($tpl2->isCached());
$result = $this->smarty->fetch($tpl2);
@@ -74,7 +74,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty
$this->assertFalse($tpl->isCached());
$result = $this->smarty->fetch($tpl);
$this->assertContains('Grandchild Page Title', $result);
$this->smarty->template_objects = null;
$this->smarty->_cache['template_objects'] = null;
$tpl2 = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
$this->assertTrue($tpl2->isCached());
$result = $this->smarty->fetch($tpl2);
@@ -96,7 +96,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty
$this->assertFalse($tpl->isCached());
$result = $this->smarty->fetch($tpl);
$this->assertContains('Grandchild Page Title', $result);
$this->smarty->template_objects = null;
$this->smarty->_cache['template_objects'] = null;
$tpl2 = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
$this->assertTrue($tpl2->isCached());
$result = $this->smarty->fetch($tpl2);
@@ -118,7 +118,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty
$this->assertFalse($tpl->isCached());
$result = $this->smarty->fetch($tpl);
$this->assertContains('Grandchild Page Title', $result);
$this->smarty->template_objects = null;
$this->smarty->_cache['template_objects'] = null;
$tpl2 = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
$this->assertTrue($tpl2->isCached());
$result = $this->smarty->fetch($tpl2);

View File

@@ -90,13 +90,13 @@ class FileResourceTest extends PHPUnit_Smarty
public function testUsesCompiler()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertFalse($tpl->source->uncompiled);
$this->assertFalse($tpl->source->handler->uncompiled);
}
public function testIsEvaluated()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertFalse($tpl->source->recompiled);
$this->assertFalse($tpl->source->handler->recompiled);
}
public function testGetCompiledFilepath()

View File

@@ -63,7 +63,7 @@ class PhpResourceTest extends PHPUnit_Smarty
public function testUsesCompiler()
{
$tpl = $this->smarty->createTemplate('php:phphelloworld.php');
$this->assertTrue($tpl->source->uncompiled);
$this->assertTrue($tpl->source->handler->uncompiled);
}
/**
@@ -72,7 +72,7 @@ class PhpResourceTest extends PHPUnit_Smarty
public function testIsEvaluated()
{
$tpl = $this->smarty->createTemplate('php:phphelloworld.php');
$this->assertFalse($tpl->source->recompiled);
$this->assertFalse($tpl->source->handler->recompiled);
}
/**

View File

@@ -69,7 +69,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testUsesCompiler()
{
$tpl = $this->smarty->createTemplate('global:mytest');
$this->assertFalse($tpl->source->uncompiled);
$this->assertFalse($tpl->source->handler->uncompiled);
}
/**
@@ -78,7 +78,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testIsEvaluated()
{
$tpl = $this->smarty->createTemplate('global:mytest');
$this->assertTrue($tpl->source->recompiled);
$this->assertTrue($tpl->source->handler->recompiled);
}
/**

View File

@@ -81,7 +81,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testUsesCompiler()
{
$tpl = $this->smarty->createTemplate('string:hello world');
$this->assertFalse($tpl->source->uncompiled);
$this->assertFalse($tpl->source->handler->uncompiled);
}
/**
@@ -90,7 +90,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testIsEvaluated()
{
$tpl = $this->smarty->createTemplate('string:hello world');
$this->assertFalse($tpl->source->recompiled);
$this->assertFalse($tpl->source->handler->recompiled);
}
/**

View File

@@ -89,7 +89,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
}
// TODO
//Smarty::$_resource_cache = array();
$this->smarty->template_objects = array();
//$this->smarty->_cache['template_objects'] = array();
return $this->_files;
}

View File

@@ -232,14 +232,14 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
*/
public function testCompileBlockGrandChildMustCompile_021_1()
{
$this->cleanDirs();
$this->smarty->setCompileDir('./templates_c/mustcompile');
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('021_grandchild.tpl');
$this->assertFalse($tpl->isCached());
$result = $this->smarty->fetch($tpl);
$this->assertContains('Grandchild Page Title', $result);
$this->smarty->template_objects = null;
$this->smarty->_cache['template_objects'] = null;
$tpl2 = $this->smarty->createTemplate('021_grandchild.tpl');
$this->assertTrue($tpl2->isCached());
$result = $this->smarty->fetch($tpl2);
@@ -252,6 +252,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
*/
public function testCompileBlockGrandChildMustCompile_021_2()
{
$this->smarty->setCompileDir('./templates_c/mustcompile');
sleep(2);
touch($this->smarty->getTemplateDir(0) . '021_grandchild.tpl');
clearstatcache();
@@ -261,7 +262,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
$this->assertFalse($tpl->isCached());
$result = $this->smarty->fetch($tpl);
$this->assertContains('Grandchild Page Title', $result);
$this->smarty->template_objects = null;
$this->smarty->_cache['template_objects'] = null;
$tpl2 = $this->smarty->createTemplate('021_grandchild.tpl');
$this->assertTrue($tpl2->isCached());
$result = $this->smarty->fetch($tpl2);
@@ -274,6 +275,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
*/
public function testCompileBlockGrandChildMustCompile_021_3()
{
$this->smarty->setCompileDir('./templates_c/mustcompile');
sleep(2);
touch($this->smarty->getTemplateDir(0) . '021_child.tpl');
clearstatcache();
@@ -283,7 +285,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
$this->assertFalse($tpl->isCached());
$result = $this->smarty->fetch($tpl);
$this->assertContains('Grandchild Page Title', $result);
$this->smarty->template_objects = null;
$this->smarty->_cache['template_objects'] = null;
$tpl2 = $this->smarty->createTemplate('021_grandchild.tpl');
$this->assertTrue($tpl2->isCached());
$result = $this->smarty->fetch($tpl2);
@@ -296,6 +298,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
*/
public function testCompileBlockGrandChildMustCompile_021_4()
{
$this->smarty->setCompileDir('./templates_c/mustcompile');
sleep(2);
touch($this->smarty->getTemplateDir(0) . '021_parent.tpl');
clearstatcache();
@@ -305,7 +308,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
$this->assertFalse($tpl->isCached());
$result = $this->smarty->fetch($tpl);
$this->assertContains('Grandchild Page Title', $result);
$this->smarty->template_objects = null;
$this->smarty->_cache['template_objects'] = null;
$tpl2 = $this->smarty->createTemplate('021_grandchild.tpl');
$this->assertTrue($tpl2->isCached());
$result = $this->smarty->fetch($tpl2);

View File

@@ -24,7 +24,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
$this->cleanDirs();
}
/**
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProvider
* test simple function call tag
@@ -38,7 +38,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
}
/**
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProvider
* test simple function call tag cached
@@ -52,7 +52,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
}
/**
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProvider
* test simple function call tag cached
@@ -67,7 +67,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
/**
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProvider
* test simple function call tag cached no cache default variable
@@ -82,7 +82,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
}
/**
* test simple function call tag ached no cache default variable 2
* test simple function call tag cached no cache default variable 2
*
* @run InSeparateProcess
* @preserveGlobalState disabled
@@ -97,21 +97,22 @@ class CompileFunctionTest extends PHPUnit_Smarty
}
/**
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProvider
* @dataProvider functionProviderCaching
* test simple function call tag plugin
*
*/
public function testSimpleFunctionPlugin_003()
public function testSimpleFunctionPlugin_003($caching, $text)
{
$this->smarty->setCaching($caching);
$this->smarty->assign('param', 1);
$this->smarty->assign('default', 2, true);
$this->assertEquals("default 1", $this->smarty->fetch('test_template_function_003.tpl'));
$this->assertEquals("default 1", $this->smarty->fetch('test_template_function_003.tpl'), $text);
}
/**
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProvider
* test simple function call tag plugin nocache
@@ -123,12 +124,12 @@ class CompileFunctionTest extends PHPUnit_Smarty
$this->smarty->setCompileId(1);
$this->smarty->assign('param', 1);
$this->smarty->assign('default', 2, true);
$this->assertEquals("default 1", $this->smarty->fetch('test_template_function_003.tpl'));
$this->assertEquals("default 1", $this->smarty->fetch('test_template_function_003.tpl'), $text);
}
/**
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProvider
* test simple function call tag 2
@@ -141,7 +142,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
/**
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProvider
* test simple function call recursive
@@ -152,7 +153,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
}
/**
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProviderInline
* test inherited function call tag
@@ -165,7 +166,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
}
/**
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProviderInline
* test function definition in include
@@ -180,7 +181,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
/**
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProviderInline
* test external function definition cached
@@ -198,7 +199,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
}
/**
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProviderInline
* test external function definition cached 2
@@ -217,7 +218,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
}
/**
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProviderInline
* test external function definition nocache call
@@ -235,7 +236,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
}
/**
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProviderInline
* test external function definition nocache call 2
@@ -256,7 +257,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
/**
* test external function definition nocache call 3
*
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProviderInline
*/
@@ -273,24 +274,15 @@ class CompileFunctionTest extends PHPUnit_Smarty
}
/**
* test external function definition nocache call 3
* test external defined recursion
*
* @run InSeparateProcess
* @runinSeparateProcess
* @preserveGlobalState disabled
* @dataProvider functionProvider
*/
public function testExternalDefinedFunctionRecursion()
public function testExternalDefinedFunctionRecursion($text)
{
$this->assertEquals('12345', $this->smarty->fetch('test_template_function_recursion2.tpl'));
}
/**
* test external function definition nocache call 3
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testExternalDefinedFunctionRecursion2()
{
$this->assertEquals('12345', $this->smarty->fetch('test_template_function_recursion2.tpl'));
$this->assertEquals('12345', $this->smarty->fetch('test_template_function_recursion2.tpl'), $text);
}
/**
@@ -306,7 +298,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
);
}
/**
* Function data provider inline
* Function data provider
*/
public function functionProvider()
{
@@ -315,4 +307,16 @@ class CompileFunctionTest extends PHPUnit_Smarty
array('call'),
);
}
/**
* Function data provider
*/
public function functionProviderCaching()
{
return array(
array(false, 'normal compile'),
array(false, 'normal call'),
array(true, 'cached compile'),
array(true, 'cached call'),
);
}
}