Update tests

This commit is contained in:
uwetews
2015-08-29 14:23:14 +02:00
parent 4645b78e8b
commit d5c9859241
16 changed files with 179 additions and 26 deletions

View File

@@ -132,9 +132,7 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
if (individualFolders != 'true') { if (individualFolders != 'true') {
if (!isset($s_dir[$dir])) { if (!isset($s_dir[$dir])) {
$this->cleanDir($dir . '/templates_c'); $this->cleanDir($dir . '/templates_c');
file_put_contents($dir . '/templates_c/dummy.txt', ' ');
$this->cleanDir($dir . '/cache'); $this->cleanDir($dir . '/cache');
file_put_contents($dir . '/cache/dummy.txt', ' ');
$s_dir[$dir] = true; $s_dir[$dir] = true;
} }
$dir = __DIR__; $dir = __DIR__;

View File

@@ -19,6 +19,11 @@ class OutputFilterTrimWhitespaceTest extends PHPUnit_Smarty
$this->smarty->loadFilter('output', 'trimwhitespace'); $this->smarty->loadFilter('output', 'trimwhitespace');
} }
public function testInit()
{
$this->cleanDirs();
}
public function testWhitespace() public function testWhitespace()
{ {
$expected = $expected =

View File

@@ -18,6 +18,11 @@ class PluginChainedLoadTest extends PHPUnit_Smarty
$this->setUpSmarty(__DIR__); $this->setUpSmarty(__DIR__);
} }
public function testInit()
{
$this->cleanDirs();
}
public function testPluginChainedLoad() public function testPluginChainedLoad()
{ {
$this->smarty->addPluginsDir(__DIR__ . "/PHPunitplugins/"); $this->smarty->addPluginsDir(__DIR__ . "/PHPunitplugins/");

View File

@@ -34,7 +34,7 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty
'./templates_4', './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')); $this->assertEquals($expected, $this->smarty->fetch('extendsall:extendsall.tpl'));
} }

View File

@@ -23,29 +23,70 @@ class ExtendsResourceTest extends PHPUnit_Smarty
{ {
$this->cleanDirs(); $this->cleanDirs();
} }
public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
{
return str_replace('#', $tpl->_getVariable('test'), $text);
}
/** /**
* test child/parent template chain with prepend * 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'); $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 * 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'));
$result = $this->smarty->fetch('extends:004_parent.tpl|004_child_append.tpl'); $this->smarty->assign('test', $testNumber);
$this->assertContains("Default Title - append", $result); $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, $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 * test grandchild/child/parent dependency test1
*/ */
public function testCompileBlockGrandChildMustCompile_021_1() public function testCompileBlockGrandChildMustCompile_021_1()
{ {
$this->cleanDirs();
$this->smarty->caching = true; $this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000; $this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl'); $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); $result = $this->smarty->fetch($tpl2);
$this->assertContains('Grandchild Page Title', $result); $this->assertContains('Grandchild Page Title', $result);
} }
/**
* test child/parent template chain with prepend public function data(){
return array(
/*
* caching
* merging
* test nr
* result compile nr
* result render nr
* text
*/ */
public function testCompileBlockChildPrepend_0032() array(false, false, 1, 1, 1, 'no caching, no merge - new'),
{ array(false, false, 2, 1, 2, 'no caching, no merge - exits'),
$this->smarty->caching = true; array(true, false, 3, 3, 3, 'caching, no merge - new'),
$result = $this->smarty->fetch('extends:003_parent.tpl|003_child_prepend.tpl'); array(true, false, 4, 3, 3, 'caching, no merge - exits'),
$this->assertContains("prepend - Default Title", $result); 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'),
);
} }
} }

View File

@@ -1 +1,2 @@
test:{$test nocache} compiled:# rendered:{$test}
{block name='title'}Default Title{/block} {block name='title'}Default Title{/block}

View File

@@ -1 +1,2 @@
test:{$test nocache} compiled:# rendered:{$test}
{block name='title'}Default Title{/block} {block name='title'}Default Title{/block}

View File

@@ -1 +1,2 @@
{block name='test'}-{$foo}-{/block} test:{$test nocache} compiled:# rendered:{$test}
{block name='test'}var-{$foo}-var{/block}

View File

@@ -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() public function testInit()
{ {
$this->cleanDirs(); $this->cleanDirs();
@@ -50,11 +55,20 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
/** /**
* test child/parent template chain * 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'); $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 * test child/parent template chain loading plugin
* @run SeparateProcess
* @preserveGlobalState disabled
*/ */
public function testCompileBlockChildPlugin_008() public function testCompileBlockChildPlugin_008()
{ {
$result = $this->smarty->fetch('008_child_plugin.tpl'); $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 * test parent template with nested blocks
*/ */
@@ -350,16 +367,79 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
*/ */
public function testSmartyBlockParentOutsideBlock_026() public function testSmartyBlockParentOutsideBlock_026()
{ {
$this->smarty->fetch('026_parent.tpl'); $this->smarty->fetch('026_child.tpl');
} }
/** /**
* @expectedException SmartyCompilerException * @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 * test {$this->smarty.block.parent} in parent template
*/ */
public function testSmartyBlockParentInParent_027() public function testSmartyBlockParentInParent_027()
{ {
$result = $this->smarty->fetch('027_parent.tpl'); $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'),
);
}
} }

View File

@@ -1 +1,2 @@
test:{$test nocache} compiled:# rendered:{$test}
{block name='title'}Default Title{/block} {block name='title'}Default Title{/block}

View File

@@ -1,2 +1,2 @@
{extends file='008_parent.tpl'} {extends file='008_parent.tpl'}
{block name='title'}{'escaped <text>'|escape}{/block} {block name='title'}{'escaped <text>'|escape} {counter start=1}{/block}

View File

@@ -1,2 +1,2 @@
{extends file='002_parent.tpl'} {extends file='012_parent.tpl'}
{block name='title'}Page Title{/block} {block name='title'}Page Title{/block}

View File

@@ -1,2 +1,2 @@
{extends file='002_parent.tpl'} {extends file='013_parent.tpl'}
{block name='title'}Page Title{/block} {block name='title'}Page Title{/block}

View File

@@ -0,0 +1,2 @@
{extends '026_parent.tpl'}
{$smarty.block.parent}{block 'b1'}{/block}

View File

@@ -1 +1,2 @@
test:{$test nocache} compiled:# rendered:{$test}
{block 'b1'}b1-{include $foo}-b1{/block} {block 'b1'}b1-{include $foo}-b1{/block}

View File

@@ -18,6 +18,11 @@ class PluginModifierCountSentencesTest extends PHPUnit_Smarty
$this->setUpSmarty(__DIR__); $this->setUpSmarty(__DIR__);
} }
public function testInit()
{
$this->cleanDirs();
}
public function testDefault() public function testDefault()
{ {
$tpl = $this->smarty->createTemplate('string:{"hello world."|count_sentences}'); $tpl = $this->smarty->createTemplate('string:{"hello world."|count_sentences}');