update block plugin tests

This commit is contained in:
uwetews
2016-01-02 04:56:22 +01:00
parent fb7908d710
commit 585850230c
12 changed files with 50 additions and 63 deletions

View File

@@ -19,7 +19,6 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
{ {
$this->setUpSmarty(dirname(__FILE__)); $this->setUpSmarty(dirname(__FILE__));
$this->smarty->addPluginsDir("./PHPunitplugins/"); $this->smarty->addPluginsDir("./PHPunitplugins/");
$this->smarty->setForceCompile(true);
$this->smarty->disableSecurity(); $this->smarty->disableSecurity();
} }
@@ -34,8 +33,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
*/ */
public function testBlockPluginNoAssign() public function testBlockPluginNoAssign()
{ {
$tpl = $this->smarty->createTemplate("eval:{textformat}hello world{/textformat}"); $this->assertEquals("hello world", $this->smarty->fetch('no_assign.tpl'));
$this->assertEquals("hello world", $this->smarty->fetch($tpl));
} }
/** /**
@@ -44,51 +42,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
*/ */
public function testBlockPluginAssign() public function testBlockPluginAssign()
{ {
$tpl = $this->smarty->createTemplate("eval:{textformat assign=foo}hello world{/textformat}{\$foo}"); $this->assertEquals("hello world", $this->smarty->fetch('assign.tpl'));
$this->assertEquals("hello world", $this->smarty->fetch($tpl));
}
/**
* test block plugin tag in template file
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testBlockPluginFromTemplateFile()
{
$tpl = $this->smarty->createTemplate('blockplugintest.tpl');
$this->assertEquals("abc", $this->smarty->fetch($tpl));
}
/**
* test block plugin tag in compiled template file
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testBlockPluginFromCompiledTemplateFile()
{
$this->smarty->setForceCompile(false);
$tpl = $this->smarty->createTemplate('blockplugintest.tpl');
$this->assertEquals("abc", $this->smarty->fetch($tpl));
}
/**
* test block plugin tag in template file
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testBlockPluginFromTemplateFileCache()
{
$this->smarty->setForceCompile(false);
$this->smarty->caching = 1;
$this->smarty->cache_lifetime = 10;
$tpl = $this->smarty->createTemplate('blockplugintest.tpl');
$this->assertEquals("abc", $this->smarty->fetch($tpl));
} }
/** /**
@@ -101,8 +55,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
public function testBlockPluginRegisteredFunction() public function testBlockPluginRegisteredFunction()
{ {
$this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'blockplugintest', 'myblockplugintest'); $this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'blockplugintest', 'myblockplugintest');
$tpl = $this->smarty->createTemplate('eval:{blockplugintest}hello world{/blockplugintest}'); $this->assertEquals('block test', $this->smarty->fetch('registered.tpl'));
$this->assertEquals('block test', $this->smarty->fetch($tpl));
} }
/** /**
@@ -111,28 +64,33 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
*/ */
public function testBlockPluginRepeat() public function testBlockPluginRepeat()
{ {
$this->smarty->addPluginsDir(dirname(__FILE__) . "/PHPunitplugins/"); $this->assertEquals('12345', $this->smarty->fetch('repeat.tpl'));
$this->assertEquals('12345', $this->smarty->fetch('eval:{testblock}{/testblock}'));
} }
/** /**
* * test block plugin repeat function with modifier
* *
*/ */
public function testBlockPluginRepeatModidier1() public function testBlockPluginRepeatModidier1()
{ {
$this->smarty->addPluginsDir(dirname(__FILE__) . "/PHPunitplugins/"); $this->assertEquals('11111', $this->smarty->fetch('repeat_modifier.tpl'));
$this->assertEquals('11111', $this->smarty->fetch('eval:{testblock}{/testblock|strlen}'));
} }
/** /**
* * test block plugin repeat function with modifier list
* *
*/ */
public function testBlockPluginRepeatModidier2() public function testBlockPluginRepeatModidier2()
{ {
$this->smarty->addPluginsDir(dirname(__FILE__) . "/PHPunitplugins/"); $this->assertEquals('11111', $this->smarty->fetch('repeat_modifier_2.tpl'));
$this->assertEquals('11111', $this->smarty->fetch('eval:{testblock}{/testblock|strlen|default:""}')); }
/**
* test block plugin with no output
*
*/
public function testBlockPluginNoOutput()
{
$this->assertEquals('default', $this->smarty->fetch('nooutput.tpl'));
} }
} }

View File

@@ -0,0 +1,24 @@
<?php
/**
* Smarty plugin for testing block plugins
*
* @package Smarty
* @subpackage PHPunitPlugin
*/
/**
* Smarty {nooutput}{/nooutput} block plugin
*
* @param array $params parameter array
* @param string $content contents of the block
* @param object $template template object
* @param bool $repeat flag
*
* @return string content re-formatted
*/
function smarty_block_nooutput($params, $content, $template, &$repeat)
{
if (isset($content)) {
$repeat = false;
}
}

View File

@@ -9,10 +9,10 @@
/** /**
* Smarty {testblock}{/testblock} block plugin * Smarty {testblock}{/testblock} block plugin
* *
* @param array $params parameter array
* @param string $content contents of the block * @param string $content contents of the block
* @param object $smarty Smarty object
* @param boolean $ &$repeat repeat flag
* @param object $template template object * @param object $template template object
* @param bool $repeat flag
* *
* @return string content re-formatted * @return string content re-formatted
*/ */
@@ -26,8 +26,7 @@ function smarty_block_testblock($params, $content, $template, &$repeat)
} else { } else {
$repeat = false; $repeat = false;
} }
return $loop;
return $loop;
} else { } else {
$loop = 0; $loop = 0;
} }

View File

@@ -0,0 +1 @@
{textformat assign=foo}hello world{/textformat}{$foo}

View File

@@ -1 +0,0 @@
{textformat}abc{/textformat}

View File

@@ -0,0 +1 @@
{textformat}hello world{/textformat}

View File

@@ -0,0 +1 @@
{nooutput}{/nooutput|default:'default'}

View File

@@ -0,0 +1 @@
{blockplugintest}hello world{/blockplugintest}

View File

@@ -0,0 +1 @@
{testblock}{/testblock}

View File

@@ -0,0 +1 @@
{testblock}{/testblock|strlen}

View File

@@ -0,0 +1 @@
{testblock}{/testblock|strlen|default:''}