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:
@@ -31,7 +31,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty
|
||||
$result = $this->smarty->fetch('extends:003_parent.tpl|003_child_prepend.tpl');
|
||||
$this->assertContains("prepend - Default Title", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test child/parent template chain with apppend
|
||||
*/
|
||||
@@ -41,5 +40,99 @@ class ExtendsResourceTest extends PHPUnit_Smarty
|
||||
$result = $this->smarty->fetch('extends:004_parent.tpl|004_child_append.tpl');
|
||||
$this->assertContains("Default Title - append", $result);
|
||||
}
|
||||
/**
|
||||
* 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');
|
||||
$this->assertFalse($tpl->isCached());
|
||||
$result = $this->smarty->fetch($tpl);
|
||||
$this->assertContains('Grandchild Page Title', $result);
|
||||
$this->smarty->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);
|
||||
$this->assertContains('Grandchild Page Title', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test grandchild/child/parent dependency test2
|
||||
*
|
||||
*/
|
||||
public function testCompileBlockGrandChildMustCompile_021_2()
|
||||
{
|
||||
sleep(2);
|
||||
touch($this->smarty->getTemplateDir(0) . '021_grandchild.tpl');
|
||||
clearstatcache();
|
||||
$this->smarty->caching = true;
|
||||
$this->smarty->cache_lifetime = 1000;
|
||||
$tpl = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
|
||||
$this->assertFalse($tpl->isCached());
|
||||
$result = $this->smarty->fetch($tpl);
|
||||
$this->assertContains('Grandchild Page Title', $result);
|
||||
$this->smarty->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);
|
||||
$this->assertContains('Grandchild Page Title', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test grandchild/child/parent dependency test3
|
||||
*
|
||||
*/
|
||||
public function testCompileBlockGrandChildMustCompile_021_3()
|
||||
{
|
||||
sleep(2);
|
||||
touch($this->smarty->getTemplateDir(0) . '021_child.tpl');
|
||||
clearstatcache();
|
||||
$this->smarty->caching = true;
|
||||
$this->smarty->cache_lifetime = 1000;
|
||||
$tpl = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
|
||||
$this->assertFalse($tpl->isCached());
|
||||
$result = $this->smarty->fetch($tpl);
|
||||
$this->assertContains('Grandchild Page Title', $result);
|
||||
$this->smarty->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);
|
||||
$this->assertContains('Grandchild Page Title', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test grandchild/child/parent dependency test4
|
||||
*
|
||||
*/
|
||||
public function testCompileBlockGrandChildMustCompile_021_4()
|
||||
{
|
||||
sleep(2);
|
||||
touch($this->smarty->getTemplateDir(0) . '021_parent.tpl');
|
||||
clearstatcache();
|
||||
$this->smarty->caching = true;
|
||||
$this->smarty->cache_lifetime = 1000;
|
||||
$tpl = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
|
||||
$this->assertFalse($tpl->isCached());
|
||||
$result = $this->smarty->fetch($tpl);
|
||||
$this->assertContains('Grandchild Page Title', $result);
|
||||
$this->smarty->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);
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1 @@
|
||||
{block name='title'}Page Title{/block}
|
@@ -0,0 +1 @@
|
||||
{block name='title'}Grandchild Page Title{/block}
|
@@ -0,0 +1 @@
|
||||
{block name='title'}Default Title{/block}
|
@@ -0,0 +1,4 @@
|
||||
{extends file='022_parent.tpl'}
|
||||
{block name='title'}Page Title{/block}
|
||||
|
||||
|
@@ -1,393 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests compilation of {php} and <?php...?> tag
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* class for {php} and <?php...?> tag tests
|
||||
*/
|
||||
class CompilePhp2Test extends PHPUnit_Smarty
|
||||
{
|
||||
public $loadSmartyBC = true;
|
||||
public $loadSmarty = false;
|
||||
public function setUp()
|
||||
{
|
||||
$this->setUpSmarty(__DIR__);
|
||||
$this->smartyBC->disableSecurity();
|
||||
}
|
||||
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
}
|
||||
public function testEndTagInStrings1()
|
||||
{
|
||||
$str = <<< STR
|
||||
<?php
|
||||
\$a = Array("?>" => 3 );
|
||||
\$b = Array("?>" => "?>");
|
||||
\$c = Array("a" => Array("b" => 7));
|
||||
class d_class
|
||||
{
|
||||
public \$d_attr = 8;
|
||||
}
|
||||
\$d = new d_class();
|
||||
\$e = Array("f" => \$d);
|
||||
|
||||
// '"
|
||||
# '"
|
||||
|
||||
echo '{\$a["?>"]}';
|
||||
echo "{\$a['?>']}";
|
||||
echo '{\$a["{\$b["?>"]}"]}';
|
||||
echo "{\$c['a']['b']}";
|
||||
echo "a{\$e['f']->d_attr}a";
|
||||
?>
|
||||
STR;
|
||||
|
||||
$this->smartyBC->left_delimiter = '{{';
|
||||
$this->smartyBC->right_delimiter = '}}';
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content));
|
||||
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals('{$a["?>"]}3{$a["{$b["?>"]}"]}7a8a', $content);
|
||||
}
|
||||
|
||||
public function testEndTagInStrings2()
|
||||
{
|
||||
$str = <<< STR
|
||||
<?php
|
||||
\$a = Array("?>" => 3 );
|
||||
\$b = Array("?>" => "?>");
|
||||
|
||||
echo "{\$a["?>"]}";
|
||||
echo "{\$a["{\$b["?>"]}"]}";
|
||||
?>
|
||||
STR;
|
||||
|
||||
$this->smartyBC->left_delimiter = '{{';
|
||||
$this->smartyBC->right_delimiter = '}}';
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content));
|
||||
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals('33', $content);
|
||||
}
|
||||
|
||||
public function testEndTagInStrings3()
|
||||
{
|
||||
$str = <<< STR
|
||||
<?php
|
||||
echo 'a?>a';
|
||||
echo '?>\\\\';
|
||||
echo '\\\\\\'?>a';
|
||||
echo '/*'; // */
|
||||
echo 1+1;
|
||||
?>
|
||||
STR;
|
||||
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content));
|
||||
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals('a?>a?>\\\\\'?>a/*2', $content);
|
||||
}
|
||||
|
||||
public function testEndTagInStrings4()
|
||||
{
|
||||
$str = <<< STR
|
||||
<?php
|
||||
echo "a?>a";
|
||||
echo "?>\\\\";
|
||||
echo "\\"?>";
|
||||
echo "\\\\\\"?>a";
|
||||
echo "/*";
|
||||
echo 1+1;
|
||||
?>
|
||||
STR;
|
||||
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content));
|
||||
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals('a?>a?>\\"?>\\"?>a/*2', $content);
|
||||
}
|
||||
|
||||
public function testEndTagInHEREDOC()
|
||||
{
|
||||
$str = <<< STR
|
||||
<?php
|
||||
echo <<< LALA
|
||||
LALA
|
||||
?>
|
||||
|
||||
"! ?> /*
|
||||
LALA
|
||||
LALA ;
|
||||
LALA;1+1;
|
||||
LALA;
|
||||
echo <<<LALA2
|
||||
LALA2;1+1;
|
||||
LALA2
|
||||
;
|
||||
?>
|
||||
STR;
|
||||
// " Fix emacs highlighting which chokes on preceding open quote
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content));
|
||||
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals(" LALA\n ?>\n\n \"! ?> /*\n LALA\nLALA ;\nLALA;1+1;LALA2;1+1;", str_replace("\r", '', $content));
|
||||
}
|
||||
|
||||
public function testEmbeddingsInHEREDOC1()
|
||||
{
|
||||
$str = <<< STR
|
||||
<?php
|
||||
\$a = Array("EOT?>'" => 1);
|
||||
|
||||
echo <<< EOT
|
||||
{\$a["EOT?>'"]}
|
||||
EOT;
|
||||
?>
|
||||
STR;
|
||||
// ' Fix emacs highlighting which chokes on preceding open quote
|
||||
$this->smartyBC->left_delimiter = '{{';
|
||||
$this->smartyBC->right_delimiter = '}}';
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content));
|
||||
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals("1", $content);
|
||||
}
|
||||
|
||||
public function testEmbeddingsInHEREDOC2()
|
||||
{
|
||||
$str = <<< STR
|
||||
<?php
|
||||
\$a = Array("\nEOT\n?>'" => 1);
|
||||
|
||||
echo <<< EOT
|
||||
{\$a[<<<EOT2
|
||||
|
||||
EOT
|
||||
?>'
|
||||
EOT2
|
||||
]}
|
||||
EOT
|
||||
;
|
||||
?>
|
||||
STR;
|
||||
// ' Fix emacs highlighting which chokes on preceding open quote
|
||||
$this->smartyBC->left_delimiter = '{{';
|
||||
$this->smartyBC->right_delimiter = '}}';
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content));
|
||||
/* Disabled due to bug in PHP easiest illustrated by:
|
||||
http://bugs.php.net/bug.php?id=50654
|
||||
|
||||
<?php
|
||||
$a = Array("b" => 1);
|
||||
|
||||
echo <<<ZZ
|
||||
{$a[<<<B
|
||||
b
|
||||
B
|
||||
]}
|
||||
ZZ;
|
||||
?>
|
||||
$this->smartyBC->left_delimiter = '{{';
|
||||
$this->smartyBC->right_delimiter = '}}';
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$this->smartyBC->security = false;
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals("11", $content);
|
||||
*/
|
||||
}
|
||||
|
||||
public function testEmbeddedHEREDOC()
|
||||
{
|
||||
$str = <<< STR
|
||||
<?php
|
||||
\$a = Array("4\"" => 3);
|
||||
\$b = Array("aa\"?>" => 4);
|
||||
|
||||
echo "{\$a[<<<EOT
|
||||
{\$b["aa\"?>"]}"
|
||||
EOT
|
||||
]}";
|
||||
?>
|
||||
STR;
|
||||
// " Fix emacs highlighting which chokes on preceding open quote
|
||||
$this->smartyBC->left_delimiter = '{{';
|
||||
$this->smartyBC->right_delimiter = '}}';
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content));
|
||||
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals("3", $content);
|
||||
}
|
||||
|
||||
public function testEmbeddedNOWDOC()
|
||||
{
|
||||
$str = <<< STR
|
||||
<?php
|
||||
\$a = Array("aa\"?>" => 3);
|
||||
|
||||
echo "{\$a[<<<'EOT'
|
||||
aa"?>
|
||||
EOT
|
||||
]}";
|
||||
?>
|
||||
STR;
|
||||
// " Fix emacs highlighting which chokes on preceding open quote
|
||||
$this->smartyBC->left_delimiter = '{{';
|
||||
$this->smartyBC->right_delimiter = '}}';
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content));
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.3.0') < 0) {
|
||||
return;
|
||||
}
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals("3", $content);
|
||||
}
|
||||
|
||||
public function testEndTagInNOWDOC()
|
||||
{
|
||||
$str = <<< STR
|
||||
<?php
|
||||
echo <<< 'LALA'
|
||||
aa ?> bb
|
||||
LALA;
|
||||
echo <<<'LALA2'
|
||||
LALA2;1+1;?>
|
||||
LALA2
|
||||
;
|
||||
?>
|
||||
STR;
|
||||
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content));
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.3.0') < 0) {
|
||||
return;
|
||||
}
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals("aa ?> bbLALA2;1+1;?>", $content);
|
||||
}
|
||||
|
||||
public function testNewlineHEREDOC()
|
||||
{
|
||||
$sprintf_str = "<?php echo <<<STR%sa%1\$sSTR;%1\$s?>";
|
||||
foreach (Array("\n", "\r\n") as $newline_chars) {
|
||||
$str = sprintf($sprintf_str, $newline_chars);
|
||||
|
||||
$this->smartyBC->php_handling = Smarty::PHP_PASSTHRU;
|
||||
$this->smartyBC->enableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
// For some reason $content doesn't preserve newline format. Not a big problem, I think.
|
||||
$this->assertEquals(preg_replace("/\r\n/", "\n", $str),
|
||||
preg_replace("/\r\n/", "\n", $content)
|
||||
);
|
||||
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals("a", $content);
|
||||
}
|
||||
}
|
||||
|
||||
public function testNewlineNOWDOC()
|
||||
{
|
||||
$sprintf_str = "<?php echo <<<'STR'%sa%1\$sSTR;%1\$s?>";
|
||||
foreach (Array("\n", "\r\n") as $newline_chars) {
|
||||
$str = sprintf($sprintf_str, $newline_chars);
|
||||
|
||||
$this->smartyBC->php_handling = Smarty::PHP_PASSTHRU;
|
||||
$this->smartyBC->enableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
// For some reason $content doesn't preserve newline format. Not a big problem, I think.
|
||||
$this->assertEquals(preg_replace("/\r\n/", "\n", $str),
|
||||
preg_replace("/\r\n/", "\n", $content)
|
||||
);
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals("a", $content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testEndTagInComment()
|
||||
{
|
||||
$str = <<< STR
|
||||
<?php
|
||||
|
||||
/*
|
||||
d?>dd "' <<< EOT
|
||||
*/
|
||||
echo 1+1;
|
||||
?>
|
||||
STR;
|
||||
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content));
|
||||
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate("eval:$str");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals('2', $content);
|
||||
}
|
||||
}
|
@@ -19,6 +19,8 @@ class CompilePhpTest extends PHPUnit_Smarty
|
||||
$this->setUpSmarty(__DIR__);
|
||||
$this->smartyBC->disableSecurity();
|
||||
$this->smarty->disableSecurity();
|
||||
$this->smarty->setCompileId($this->getName());
|
||||
$this->smartyBC->setCompileId($this->getName());
|
||||
}
|
||||
|
||||
public function testInit()
|
||||
@@ -30,7 +32,7 @@ class CompilePhpTest extends PHPUnit_Smarty
|
||||
* test <?php...\> tag
|
||||
* PHP_REMOVE
|
||||
*/
|
||||
public function testPHP_REMOVEphp()
|
||||
public function testPHP_REMOVE_php()
|
||||
{
|
||||
$this->smarty->setPhpHandling(Smarty::PHP_REMOVE);
|
||||
$content = $this->smarty->fetch("string:a<?php echo 'hello world'; ?>e");
|
||||
@@ -41,22 +43,17 @@ public function testPHP_REMOVEphp()
|
||||
* test <%...%> tag
|
||||
* PHP_REMOVE
|
||||
*/
|
||||
public function testPHP_REMOVEasp()
|
||||
public function testPHP_REMOVE_asp()
|
||||
{
|
||||
if (!ini_get('asp_tags')) {
|
||||
$this->markTestSkipped('asp tags disabled in php.ini');
|
||||
}
|
||||
$this->smarty->setPhpHandling(Smarty::PHP_REMOVE);
|
||||
$content = $this->smarty->fetch("string:a<% echo 'hello world';%>e");
|
||||
$this->assertEquals("a echo 'hello world';e", $content, 'remove <% %>');
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* test <script language='php'>...</script> tag
|
||||
* PHP_REMOVE
|
||||
*/
|
||||
public function testPHP_REMOVEscript()
|
||||
public function testPHP_REMOVE_script()
|
||||
{
|
||||
$this->smarty->setPhpHandling(Smarty::PHP_REMOVE);
|
||||
$content = $this->smarty->fetch("string:a<script language='php'> echo 'hello world';</script>e");
|
||||
@@ -66,7 +63,7 @@ public function testPHP_REMOVEphp()
|
||||
* test <?php...\> tag
|
||||
* PHP_PASSTHRU
|
||||
*/
|
||||
public function testPHP_PASSTHRUphp()
|
||||
public function testPHP_PASSTHRU_php()
|
||||
{
|
||||
$this->smarty->setPhpHandling(Smarty::PHP_PASSTHRU);
|
||||
$content = $this->smarty->fetch("string:pa<?php echo 'hello world'; ?>pe");
|
||||
@@ -76,30 +73,27 @@ public function testPHP_REMOVEphp()
|
||||
* test <%...%> tag
|
||||
* PHP_PASSTHRU
|
||||
*/
|
||||
public function testPHP_PASSTHRUasp()
|
||||
public function testPHP_PASSTHRU_asp()
|
||||
{
|
||||
if (!ini_get('asp_tags')) {
|
||||
$this->markTestSkipped('asp tags disabled in php.ini');
|
||||
}
|
||||
$this->smarty->setPhpHandling(Smarty::PHP_PASSTHRU);
|
||||
$content = $this->smarty->fetch("string:pa<% echo 'hello world';%>pe");
|
||||
$content = $this->smarty->fetch("string:pa<% echo 'hello world';%>pe");
|
||||
$this->assertEquals("pa<% echo 'hello world';%>pe", $content, 'passthru <% %>');
|
||||
}
|
||||
/**
|
||||
* test <script language='php'>...</script> tag
|
||||
* PHP_PASSTHRU
|
||||
*/
|
||||
public function testPHP_PASSTHRUscript()
|
||||
public function testPHP_PASSTHRU_script()
|
||||
{
|
||||
$this->smarty->setPhpHandling(Smarty::PHP_PASSTHRU);
|
||||
$content = $this->smarty->fetch("string:pa<script language='php'> echo 'hello world';</script>pe");
|
||||
$this->assertEquals("pa<script language=\'php\'> echo 'hello world';</script>pe", $content, "passthru <script language='php'>");
|
||||
$this->assertEquals("pa<script language='php'> echo 'hello world';</script>pe", $content, "passthru <script language='php'>");
|
||||
}
|
||||
/**
|
||||
* test <?php...\> tag
|
||||
* PHP_QUOTE
|
||||
*/
|
||||
public function testPHP_QUOTEphp()
|
||||
public function testPHP_QUOTE_php()
|
||||
{
|
||||
$this->smarty->setPhpHandling(Smarty::PHP_QUOTE);
|
||||
$content = $this->smarty->fetch("string:qa<?php echo 'hello world'; ?>qe");
|
||||
@@ -109,11 +103,8 @@ public function testPHP_REMOVEphp()
|
||||
* test <%...%> tag
|
||||
* PHP_QUOTE
|
||||
*/
|
||||
public function testPHP_QUOTEasp()
|
||||
public function testPHP_QUOTE_asp()
|
||||
{
|
||||
if (!ini_get('asp_tags')) {
|
||||
$this->markTestSkipped('asp tags disabled in php.ini');
|
||||
}
|
||||
$this->smarty->setPhpHandling(Smarty::PHP_QUOTE);
|
||||
$content = $this->smarty->fetch("string:qa<% echo 'hello world';%>qe");
|
||||
$this->assertEquals("qa<% echo 'hello world';%>qe", $content, 'qoute <% %>');
|
||||
@@ -122,7 +113,7 @@ public function testPHP_REMOVEphp()
|
||||
* test <script language='php'>...</script> tag
|
||||
* PHP_QUOTE
|
||||
*/
|
||||
public function testPHP_QUOTEscript()
|
||||
public function testPHP_QUOTE_script()
|
||||
{
|
||||
$this->smarty->setPhpHandling(Smarty::PHP_QUOTE);
|
||||
$content = $this->smarty->fetch("string:qa<script language='php'> echo 'hello world';</script>qe");
|
||||
@@ -132,7 +123,7 @@ public function testPHP_REMOVEphp()
|
||||
* test <?php...\> tag
|
||||
* PHP_ALLOW
|
||||
*/
|
||||
public function testPHP_ALLOWphp()
|
||||
public function testPHP_ALLOW_php()
|
||||
{
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$content = $this->smartyBC->fetch("string:aa <?php echo 'hello world'; ?> ae");
|
||||
@@ -141,20 +132,21 @@ public function testPHP_REMOVEphp()
|
||||
* test <%...%> tag
|
||||
* PHP_ALLOW
|
||||
*/
|
||||
public function testPHP_ALLOWasp()
|
||||
public function testPHP_ALLOW_asp()
|
||||
{
|
||||
if (!ini_get('asp_tags')) {
|
||||
$this->markTestSkipped('asp tags disabled in php.ini');
|
||||
}
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$content = $this->smartyBC->fetch("string:aa <% echo 'hello world';%> ae");
|
||||
$this->assertEquals('aa hello world ae', $content, 'allow <% %>');
|
||||
if (ini_get('asp_tags')) {
|
||||
$this->assertEquals('aa hello world ae', $content, 'allow <% %>');
|
||||
} else {
|
||||
$this->assertEquals("aa <% echo 'hello world';%> ae", $content, 'allow asp disabled <% %>');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* test <script language='php'>...</script> tag
|
||||
* PHP_ALLOW
|
||||
*/
|
||||
public function testPHP_ALLOWscript()
|
||||
public function testPHP_ALLOW_script()
|
||||
{
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$content = $this->smartyBC->fetch("string:aa <script language='php'> echo 'hello world';</script> ae");
|
||||
@@ -164,7 +156,7 @@ public function testPHP_REMOVEphp()
|
||||
* test <?php...\> tag
|
||||
* PHP_ALLOW
|
||||
*/
|
||||
public function testPHP_ALLOW2()
|
||||
public function testPHP_ALLOW_php2()
|
||||
{
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$content = $this->smartyBC->fetch("string:aa <?php echo '<?php'; ?> ae");
|
||||
@@ -174,38 +166,27 @@ public function testPHP_REMOVEphp()
|
||||
* test <?php...\> tag
|
||||
* PHP_ALLOW
|
||||
*/
|
||||
public function testPHP_ALLOW3()
|
||||
public function testPHP_ALLOW_php3()
|
||||
{
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$content = $this->smartyBC->fetch("string:aa <?php echo '?>'; ?> ae");
|
||||
$this->assertEquals('aa ?> ae', $content);
|
||||
}
|
||||
/**
|
||||
* test <?php...\> tag
|
||||
* PHP_ALLOW
|
||||
*/
|
||||
public function testPHP_ALLOW_php4()
|
||||
{
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$content = $this->smartyBC->fetch("string:aa <?php /* ?> */ echo '?>'; ?> ae");
|
||||
$this->assertEquals('aa ?> ae', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* test {php}{/php} tag
|
||||
* PHP_ALLOW
|
||||
*/
|
||||
public function testPHP_ALLOW5()
|
||||
{
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$content = $this->smartyBC->fetch("string:aa {php} echo 'hallo'; {/php} ae");
|
||||
$this->assertEquals('aa hallo ae', $content);
|
||||
}
|
||||
/**
|
||||
* test {php}{/php} tag
|
||||
* PHP_ALLOW
|
||||
*/
|
||||
public function testPHP_ALLOW6()
|
||||
{
|
||||
$this->smartyBC->caching = 1;
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$content = $this->smartyBC->fetch("string:aa {php nocache} echo 'hallo'; {/php} ae");
|
||||
$this->assertEquals('aa hallo ae', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException SmartyCompilerException
|
||||
* @expectedExceptionMessage PHP in template not allowed
|
||||
* @expectedExceptionMessage $smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it
|
||||
*/
|
||||
|
||||
public function testPHP_ALLOW_error()
|
||||
@@ -213,26 +194,6 @@ public function testPHP_REMOVEphp()
|
||||
$this->smarty->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$content = $this->smarty->fetch("string:aa <?php echo 'hallo'; ?> ae");
|
||||
}
|
||||
/**
|
||||
* test <?php...\> tag
|
||||
* default is PASSTHRU
|
||||
*/
|
||||
public function testPhpTag()
|
||||
{
|
||||
$tpl = $this->smartyBC->createTemplate("eval:<?php echo 'hello world'; ?>");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals("<?php echo 'hello world'; ?>", $content);
|
||||
}
|
||||
|
||||
// ALLOW
|
||||
public function testPhpTagAllow()
|
||||
{
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate("eval:<?php echo 'hello world'; ?>");
|
||||
$content = $this->smartyBC->fetch($tpl);
|
||||
$this->assertEquals('hello world', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* test <?=...\> shorttag
|
||||
@@ -244,14 +205,114 @@ public function testPHP_REMOVEphp()
|
||||
$content = $this->smartyBC->fetch('eval:<?=$foo?>');
|
||||
$this->assertEquals('<?=$foo?>', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP tag data provider
|
||||
* test unmatched <?php
|
||||
*
|
||||
*/
|
||||
public function includeProvider()
|
||||
public function testUnmatched_php()
|
||||
{
|
||||
return array(
|
||||
array(SMARTY::PHP_REMOVE, 'normal'),
|
||||
array(true, 'merged'),
|
||||
);
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$content = $this->smartyBC->fetch('string:aa <?php ee');
|
||||
$this->assertEquals('aa <?php ee', $content);
|
||||
}
|
||||
/**
|
||||
* test unmatched ?>
|
||||
*
|
||||
*/
|
||||
public function testUnmatched_php_close()
|
||||
{
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$content = $this->smartyBC->fetch('string:aa ?> ee');
|
||||
$this->assertEquals('aa ?> ee', $content);
|
||||
}
|
||||
/**
|
||||
* test unmatched <%
|
||||
*
|
||||
*/
|
||||
public function testUnmatched_asp()
|
||||
{
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$content = $this->smartyBC->fetch('string:aa <% ee');
|
||||
$this->assertEquals('aa <% ee', $content);
|
||||
}
|
||||
/**
|
||||
* test unmatched %>
|
||||
*
|
||||
*/
|
||||
public function testUnmatched_asp_close()
|
||||
{
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$content = $this->smartyBC->fetch('string:aa %> ee');
|
||||
$this->assertEquals('aa %> ee', $content);
|
||||
}
|
||||
/**
|
||||
* test unmatched <script language='php'>
|
||||
*
|
||||
*/
|
||||
public function testUnmatched_script()
|
||||
{
|
||||
$this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$content = $this->smartyBC->fetch("string:aa <script language='php'> echo 'hello world'; ae");
|
||||
$this->assertEquals("aa <script language='php'> echo 'hello world'; ae", $content);
|
||||
}
|
||||
/**
|
||||
* test {php}{/php} tag
|
||||
* PHP_ALLOW
|
||||
*/
|
||||
public function testPHP_Tag()
|
||||
{
|
||||
$content = $this->smartyBC->fetch("string:aa {php} echo 'hallo'; {/php} ae");
|
||||
$this->assertEquals('aa hallo ae', $content);
|
||||
}
|
||||
/**
|
||||
* test {php nocache}{/php} tag
|
||||
* PHP_ALLOW
|
||||
*/
|
||||
public function testPHP_Tag_Nocache()
|
||||
{
|
||||
$this->smartyBC->caching = 1;
|
||||
$content = $this->smartyBC->fetch("string:aa {php nocache} echo 'hallo'; {/php} ae");
|
||||
$this->assertEquals('aa hallo ae', $content);
|
||||
}
|
||||
/**
|
||||
* test {php no cache}illegal option
|
||||
* @expectedException SmartyCompilerException
|
||||
* @expectedExceptionMessage illegal value of option flag "no cache"
|
||||
*
|
||||
*/
|
||||
public function testPHP_Tag_IllegalOption()
|
||||
{
|
||||
$content = $this->smartyBC->fetch("string:aa {php no cache} echo 'hallo'; {/php} ae");
|
||||
}
|
||||
|
||||
/**
|
||||
* test { php}{/php} tag
|
||||
* PHP_Tag Literal
|
||||
*/
|
||||
public function testPHP_Tag_Literal()
|
||||
{
|
||||
$content = $this->smartyBC->fetch("string:aa { php} echo 'hallo'; {/php} ae");
|
||||
$this->assertEquals('aa { php} echo \'hallo\'; {/php} ae', $content);
|
||||
}
|
||||
/**
|
||||
* test unmatched {php} tag
|
||||
* @expectedException SmartyCompilerException
|
||||
* @expectedExceptionMessage Missing {/php} closing tag
|
||||
*
|
||||
*/
|
||||
public function testPHP_Tag_unmatch()
|
||||
{
|
||||
$content = $this->smartyBC->fetch("string:aa {php} echo 'hallo'; ae");
|
||||
}
|
||||
/**
|
||||
* test unmatched {/php} tag
|
||||
* @expectedException SmartyCompilerException
|
||||
* @expectedExceptionMessage Missing {php} open tag
|
||||
*
|
||||
*/
|
||||
public function testPHP_TagOpen_unmatch()
|
||||
{
|
||||
$content = $this->smartyBC->fetch("string:aa {/php} ae");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user