mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
Update tests
This commit is contained in:
@@ -132,9 +132,7 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
|
||||
if (individualFolders != 'true') {
|
||||
if (!isset($s_dir[$dir])) {
|
||||
$this->cleanDir($dir . '/templates_c');
|
||||
file_put_contents($dir . '/templates_c/dummy.txt', ' ');
|
||||
$this->cleanDir($dir . '/cache');
|
||||
file_put_contents($dir . '/cache/dummy.txt', ' ');
|
||||
$s_dir[$dir] = true;
|
||||
}
|
||||
$dir = __DIR__;
|
||||
|
@@ -19,6 +19,11 @@ class OutputFilterTrimWhitespaceTest extends PHPUnit_Smarty
|
||||
$this->smarty->loadFilter('output', 'trimwhitespace');
|
||||
}
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
}
|
||||
|
||||
public function testWhitespace()
|
||||
{
|
||||
$expected =
|
||||
|
@@ -18,6 +18,11 @@ class PluginChainedLoadTest extends PHPUnit_Smarty
|
||||
$this->setUpSmarty(__DIR__);
|
||||
}
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
}
|
||||
|
||||
public function testPluginChainedLoad()
|
||||
{
|
||||
$this->smarty->addPluginsDir(__DIR__ . "/PHPunitplugins/");
|
||||
|
@@ -34,7 +34,7 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty
|
||||
'./templates_4',
|
||||
));
|
||||
|
||||
$expected = "templates\n\n templates_3\n templates\n\ntemplates_4";
|
||||
$expected = "templates\n templates_3\n templates\n\ntemplates_4";
|
||||
$this->assertEquals($expected, $this->smarty->fetch('extendsall:extendsall.tpl'));
|
||||
}
|
||||
|
||||
|
@@ -23,29 +23,70 @@ class ExtendsResourceTest extends PHPUnit_Smarty
|
||||
{
|
||||
$this->cleanDirs();
|
||||
}
|
||||
|
||||
public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
|
||||
{
|
||||
return str_replace('#', $tpl->_getVariable('test'), $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* test child/parent template chain with prepend
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function testCompileBlockChildPrepend_003()
|
||||
public function testCompileBlockChildPrepend_003($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName)
|
||||
{
|
||||
$this->smarty->registerFilter('pre', array($this, 'compiledPrefilter'));
|
||||
$this->smarty->assign('test', $testNumber);
|
||||
$this->smarty->caching = $caching;
|
||||
$this->smarty->inheritance_merge_compiled_includes = $merge;
|
||||
if ($merge) {
|
||||
$this->smarty->compile_id = 1;
|
||||
}
|
||||
$result = $this->smarty->fetch('extends:003_parent.tpl|003_child_prepend.tpl');
|
||||
$this->assertContains("prepend - Default Title", $result);
|
||||
$this->assertContains("prepend - Default Title", $result, $testName . ' - content');
|
||||
$this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure');
|
||||
}
|
||||
/**
|
||||
* test child/parent template chain with apppend
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function testCompileBlockChildAppend_004()
|
||||
public function testCompileBlockChildAppend_004($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName)
|
||||
{
|
||||
$this->smarty->merge_compiled_includes = true;
|
||||
$this->smarty->registerFilter('pre', array($this, 'compiledPrefilter'));
|
||||
$this->smarty->assign('test', $testNumber);
|
||||
$this->smarty->caching = $caching;
|
||||
$this->smarty->inheritance_merge_compiled_includes = $merge;
|
||||
if ($merge) {
|
||||
$this->smarty->compile_id = 1;
|
||||
}
|
||||
$result = $this->smarty->fetch('extends:004_parent.tpl|004_child_append.tpl');
|
||||
$this->assertContains("Default Title - append", $result);
|
||||
$this->assertContains("Default Title - append", $result, $testName . ' - content');
|
||||
$this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure');
|
||||
}
|
||||
|
||||
/**
|
||||
* test child/parent template chain with apppend
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function testCompileBlockAssignInChild_040($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName)
|
||||
{
|
||||
$this->smarty->registerFilter('pre', array($this, 'compiledPrefilter'));
|
||||
$this->smarty->assign('test', $testNumber);
|
||||
$this->smarty->caching = $caching;
|
||||
$this->smarty->inheritance_merge_compiled_includes = $merge;
|
||||
if ($merge) {
|
||||
$this->smarty->compile_id = 1;
|
||||
}
|
||||
$result = $this->smarty->fetch('extends:040_parent.tpl|040_child.tpl');
|
||||
$this->assertContains("var-bar-var", $result, $testName . ' - content');
|
||||
$this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure');
|
||||
}
|
||||
|
||||
/**
|
||||
* test grandchild/child/parent dependency test1
|
||||
*/
|
||||
public function testCompileBlockGrandChildMustCompile_021_1()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
$this->smarty->caching = true;
|
||||
$this->smarty->cache_lifetime = 1000;
|
||||
$tpl = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
|
||||
@@ -124,14 +165,26 @@ class ExtendsResourceTest extends PHPUnit_Smarty
|
||||
$result = $this->smarty->fetch($tpl2);
|
||||
$this->assertContains('Grandchild Page Title', $result);
|
||||
}
|
||||
/**
|
||||
* test child/parent template chain with prepend
|
||||
*/
|
||||
public function testCompileBlockChildPrepend_0032()
|
||||
{
|
||||
$this->smarty->caching = true;
|
||||
$result = $this->smarty->fetch('extends:003_parent.tpl|003_child_prepend.tpl');
|
||||
$this->assertContains("prepend - Default Title", $result);
|
||||
|
||||
public function data(){
|
||||
return array(
|
||||
/*
|
||||
* caching
|
||||
* merging
|
||||
* test nr
|
||||
* result compile nr
|
||||
* result render nr
|
||||
* text
|
||||
*/
|
||||
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'),
|
||||
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'),
|
||||
array(true, true, 7, 7, 7, 'caching, merge - new'),
|
||||
array(true, true, 8, 7, 7, 'caching, merge - exits'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1 +1,2 @@
|
||||
test:{$test nocache} compiled:# rendered:{$test}
|
||||
{block name='title'}Default Title{/block}
|
||||
|
@@ -1 +1,2 @@
|
||||
test:{$test nocache} compiled:# rendered:{$test}
|
||||
{block name='title'}Default Title{/block}
|
||||
|
@@ -1 +1,2 @@
|
||||
{block name='test'}-{$foo}-{/block}
|
||||
test:{$test nocache} compiled:# rendered:{$test}
|
||||
{block name='test'}var-{$foo}-var{/block}
|
||||
|
@@ -19,6 +19,11 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
|
||||
}
|
||||
|
||||
|
||||
public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
|
||||
{
|
||||
return str_replace('#', $tpl->_getVariable('test'), $text);
|
||||
}
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
@@ -50,11 +55,20 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
|
||||
|
||||
/**
|
||||
* test child/parent template chain
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function testCompileBlockChild_002()
|
||||
public function testCompileBlockChild_002($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName)
|
||||
{
|
||||
$this->smarty->registerFilter('pre', array($this, 'compiledPrefilter'));
|
||||
$this->smarty->assign('test', $testNumber);
|
||||
$this->smarty->caching = $caching;
|
||||
$this->smarty->merge_compiled_includes = $merge;
|
||||
if ($merge) {
|
||||
$this->smarty->compile_id = 1;
|
||||
}
|
||||
$result = $this->smarty->fetch('002_child.tpl');
|
||||
$this->assertContains('Page Title', $result);
|
||||
$this->assertContains('Page Title', $result, $testName . ' - content');
|
||||
$this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,13 +118,16 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
|
||||
|
||||
/**
|
||||
* test child/parent template chain loading plugin
|
||||
* @run SeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testCompileBlockChildPlugin_008()
|
||||
{
|
||||
$result = $this->smarty->fetch('008_child_plugin.tpl');
|
||||
$this->assertContains('escaped <text>', $result);
|
||||
$this->assertContains('escaped <text> 1', $result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test parent template with nested blocks
|
||||
*/
|
||||
@@ -350,16 +367,79 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
|
||||
*/
|
||||
public function testSmartyBlockParentOutsideBlock_026()
|
||||
{
|
||||
$this->smarty->fetch('026_parent.tpl');
|
||||
$this->smarty->fetch('026_child.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException SmartyCompilerException
|
||||
* @expectedExceptionMessage illegal {$smarty.block.parent} in parent template
|
||||
* @expectedExceptionMessage tag {$smarty.block.parent} used in parent template
|
||||
* test {$this->smarty.block.parent} in parent template
|
||||
*/
|
||||
public function testSmartyBlockParentInParent_027()
|
||||
{
|
||||
$result = $this->smarty->fetch('027_parent.tpl');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test child/parent template chain
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function testSmartyBlockVariablePartentInclude_28($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName)
|
||||
{
|
||||
$this->smarty->registerFilter('pre', array($this, 'compiledPrefilter'));
|
||||
$this->smarty->assign('test', $testNumber);
|
||||
$this->smarty->caching = $caching;
|
||||
$this->smarty->merge_compiled_includes = $merge;
|
||||
$this->smarty->compile_id = 10;
|
||||
if ($merge) {
|
||||
$this->smarty->compile_id = 11;
|
||||
}
|
||||
$this->smarty->assign('foo', '028_parent_include1.tpl');
|
||||
$result = $this->smarty->fetch('028_child.tpl');
|
||||
$this->assertContains('b1-include-1--b1', $result, $testName . ' - content');
|
||||
$this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure');
|
||||
}
|
||||
|
||||
/**
|
||||
* test child/parent template chain
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function testSmartyBlockVariablePartentInclude_282($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName)
|
||||
{
|
||||
$this->smarty->registerFilter('pre', array($this, 'compiledPrefilter'));
|
||||
$this->smarty->assign('test', $testNumber);
|
||||
$this->smarty->caching = $caching;
|
||||
$this->smarty->merge_compiled_includes = $merge;
|
||||
if ($merge) {
|
||||
$this->smarty->compile_id = 1;
|
||||
}
|
||||
$this->smarty->assign('foo', '028_parent_include2.tpl');
|
||||
$result = $this->smarty->fetch('028_child.tpl');
|
||||
$this->assertContains('b1-child-i2-include-2--b1', $result, $testName . ' - content');
|
||||
$this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function data(){
|
||||
return array(
|
||||
/*
|
||||
* caching
|
||||
* merging
|
||||
* test nr
|
||||
* result compile nr
|
||||
* result render nr
|
||||
* text
|
||||
*/
|
||||
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'),
|
||||
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'),
|
||||
array(true, true, 7, 7, 7, 'caching, merge - new'),
|
||||
array(true, true, 8, 7, 7, 'caching, merge - exits'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1 +1,2 @@
|
||||
test:{$test nocache} compiled:# rendered:{$test}
|
||||
{block name='title'}Default Title{/block}
|
||||
|
@@ -1,2 +1,2 @@
|
||||
{extends file='008_parent.tpl'}
|
||||
{block name='title'}{'escaped <text>'|escape}{/block}
|
||||
{block name='title'}{'escaped <text>'|escape} {counter start=1}{/block}
|
||||
|
@@ -1,2 +1,2 @@
|
||||
{extends file='002_parent.tpl'}
|
||||
{extends file='012_parent.tpl'}
|
||||
{block name='title'}Page Title{/block}
|
||||
|
@@ -1,2 +1,2 @@
|
||||
{extends file='002_parent.tpl'}
|
||||
{extends file='013_parent.tpl'}
|
||||
{block name='title'}Page Title{/block}
|
||||
|
@@ -0,0 +1,2 @@
|
||||
{extends '026_parent.tpl'}
|
||||
{$smarty.block.parent}{block 'b1'}{/block}
|
@@ -1 +1,2 @@
|
||||
test:{$test nocache} compiled:# rendered:{$test}
|
||||
{block 'b1'}b1-{include $foo}-b1{/block}
|
@@ -18,6 +18,11 @@ class PluginModifierCountSentencesTest extends PHPUnit_Smarty
|
||||
$this->setUpSmarty(__DIR__);
|
||||
}
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
}
|
||||
|
||||
public function testDefault()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{"hello world."|count_sentences}');
|
||||
|
Reference in New Issue
Block a user