mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-15 15:09:51 +01:00
Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly.
This commit is contained in:
@@ -64,7 +64,7 @@ class PHPUnit_Smarty extends PHPUnit\Framework\TestCase
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
error_reporting(E_ALL & ~E_STRICT);
|
||||
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_USER_DEPRECATED);
|
||||
self::$init = true;
|
||||
self::$pluginsdir =self::getSmartyPluginsDir();
|
||||
}
|
||||
|
||||
@@ -40,32 +40,9 @@ class SecurityTest extends PHPUnit_Smarty
|
||||
/**
|
||||
* test trusted PHP function
|
||||
*/
|
||||
public function testTrustedPHPFunction()
|
||||
public function testTrustedFunction()
|
||||
{
|
||||
$this->assertEquals("5", $this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{sizeof($foo)}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test not trusted PHP function
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function testNotTrustedPHPFunction()
|
||||
{
|
||||
$this->expectException(\Smarty\Exception::class);
|
||||
$this->expectExceptionMessage('PHP function \'sizeof\' not allowed by security setting');
|
||||
$this->smarty->security_policy->php_functions = array('null');
|
||||
$this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{sizeof($foo)}');
|
||||
}
|
||||
|
||||
/**
|
||||
* test not trusted PHP function at disabled security
|
||||
*/
|
||||
public function testDisabledTrustedPHPFunction()
|
||||
{
|
||||
$this->smarty->security_policy->php_functions = array('null');
|
||||
$this->smarty->disableSecurity();
|
||||
$this->assertEquals("5", $this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{sizeof($foo)}'));
|
||||
$this->assertEquals("5", $this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{count($foo)}'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +51,7 @@ class SecurityTest extends PHPUnit_Smarty
|
||||
*/
|
||||
public function testTrustedModifier()
|
||||
{
|
||||
$this->assertEquals("5", @$this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{$foo|@sizeof}'));
|
||||
$this->assertEquals("5", @$this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{$foo|@count}'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,21 +64,9 @@ class SecurityTest extends PHPUnit_Smarty
|
||||
{
|
||||
$this->expectException(\Smarty\Exception::class);
|
||||
$this->expectExceptionMessage('modifier \'sizeof\' not allowed by security setting');
|
||||
$this->smarty->security_policy->php_modifiers = array('null');
|
||||
@$this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{$foo|@sizeof}');
|
||||
}
|
||||
|
||||
/**
|
||||
* test not trusted modifier at disabled security
|
||||
* @deprecated
|
||||
*/
|
||||
public function testDisabledTrustedModifier()
|
||||
{
|
||||
$this->smarty->security_policy->php_modifiers = array('null');
|
||||
$this->smarty->disableSecurity();
|
||||
@$this->assertEquals("5", $this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{$foo|@sizeof}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test allowed tags
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace UnitTests\TemplateSource\TagTests\PluginFunction;
|
||||
class CountTest extends \PHPUnit_Smarty {
|
||||
|
||||
public function setUp(): void {
|
||||
$this->setUpSmarty(__DIR__);
|
||||
}
|
||||
|
||||
public function testBasicSyntax() {
|
||||
$this->assertEquals('3', $this->smarty->fetch("string:{count([1,2,3])}"));
|
||||
}
|
||||
|
||||
public function testNonRecursive() {
|
||||
$this->assertEquals('3', $this->smarty->fetch("string:{count([1,2,[3,4]])}"));
|
||||
}
|
||||
|
||||
public function testRecursive() {
|
||||
$this->assertEquals('5', $this->smarty->fetch("string:{count([1,2,[3,4]], 1)}"));
|
||||
}
|
||||
|
||||
public function testInvalidParameters() {
|
||||
$this->expectException(\Smarty\Exception::class);
|
||||
$this->expectExceptionMessage('Invalid number of arguments');
|
||||
$this->assertEquals("", $this->smarty->fetch("string:{count()}"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace UnitTests\TemplateSource\TagTests\PluginFunction;
|
||||
class EmptyTest extends \PHPUnit_Smarty {
|
||||
|
||||
public function setUp(): void {
|
||||
$this->setUpSmarty(__DIR__);
|
||||
}
|
||||
|
||||
public function testBasicSyntax() {
|
||||
$this->assertEquals("yay", $this->smarty->fetch("string:{if empty(\$noSuch)}yay{/if}"));
|
||||
}
|
||||
|
||||
public function testEmptyStringIsEmpty() {
|
||||
$this->assertEquals("yay", $this->smarty->fetch("string:{if empty('')}yay{/if}"));
|
||||
}
|
||||
|
||||
public function testFalseIsEmpty() {
|
||||
$this->smarty->assign('test', false);
|
||||
$this->assertEquals("yay", $this->smarty->fetch("string:{if empty(\$test)}yay{/if}"));
|
||||
}
|
||||
|
||||
public function testIntZeroIsEmpty() {
|
||||
$this->smarty->assign('test', 0);
|
||||
$this->assertEquals("yay", $this->smarty->fetch("string:{if empty(\$test)}yay{/if}"));
|
||||
}
|
||||
|
||||
public function testStringZeroIsEmpty() {
|
||||
$this->smarty->assign('test', '0');
|
||||
$this->assertEquals("yay", $this->smarty->fetch("string:{if empty(\$test)}yay{/if}"));
|
||||
}
|
||||
|
||||
public function testIntThreeIsNotEmpty() {
|
||||
$this->smarty->assign('test', 3);
|
||||
$this->assertEquals("nay", $this->smarty->fetch("string:{if empty(\$test)}yay{else}nay{/if}"));
|
||||
}
|
||||
|
||||
public function testInvalidParameters() {
|
||||
$this->expectException(\Smarty\Exception::class);
|
||||
$this->expectExceptionMessage('Invalid number of arguments');
|
||||
$this->assertEquals("", $this->smarty->fetch("string:{empty(3, 'foo')}"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
class InArrayTest extends \PHPUnit_Smarty {
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(__DIR__);
|
||||
}
|
||||
|
||||
public function testBasicSyntax()
|
||||
{
|
||||
$this->assertEquals("yay", $this->smarty->fetch("string:{if in_array(3,[3])}yay{/if}"));
|
||||
}
|
||||
|
||||
public function testNotInArray()
|
||||
{
|
||||
$this->assertEquals("nay", $this->smarty->fetch("string:{if in_array(2,[3])}yay{else}nay{/if}"));
|
||||
}
|
||||
|
||||
public function testInvalidParameters()
|
||||
{
|
||||
$this->expectException(\Smarty\Exception::class);
|
||||
$this->expectExceptionMessage('Invalid number of arguments');
|
||||
$this->assertEquals("", $this->smarty->fetch("string:{in_array('foo')}"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace UnitTests\TemplateSource\TagTests\PluginFunction;
|
||||
class IsArrayTest extends \PHPUnit_Smarty {
|
||||
|
||||
public function setUp(): void {
|
||||
$this->setUpSmarty(__DIR__);
|
||||
}
|
||||
|
||||
public function testBasicSyntax() {
|
||||
$this->assertEquals("yay", $this->smarty->fetch("string:{if is_array([3])}yay{/if}"));
|
||||
}
|
||||
|
||||
public function testIntNotIsArray() {
|
||||
$this->assertEquals("nay", $this->smarty->fetch("string:{if is_array(2)}yay{else}nay{/if}"));
|
||||
}
|
||||
|
||||
public function testStringNotIsArray() {
|
||||
$this->assertEquals("nay", $this->smarty->fetch("string:{if is_array('foo')}yay{else}nay{/if}"));
|
||||
}
|
||||
|
||||
public function testInvalidParameters() {
|
||||
$this->expectException(\Smarty\Exception::class);
|
||||
$this->expectExceptionMessage('Invalid number of arguments');
|
||||
$this->assertEquals("", $this->smarty->fetch("string:{is_array(3, 'foo')}"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace UnitTests\TemplateSource\TagTests\PluginFunction;
|
||||
class IssetTest extends \PHPUnit_Smarty {
|
||||
|
||||
public function setUp(): void {
|
||||
$this->setUpSmarty(__DIR__);
|
||||
}
|
||||
|
||||
public function testBasicSyntax() {
|
||||
$this->assertEquals("nay", $this->smarty->fetch("string:{if isset(\$noSuch)}yay{else}nay{/if}"));
|
||||
}
|
||||
|
||||
public function testEmptyStringIsset() {
|
||||
$this->assertEquals("yay", $this->smarty->fetch("string:{if isset('')}yay{/if}"));
|
||||
}
|
||||
|
||||
public function testFalseIsset() {
|
||||
$this->smarty->assign('test', false);
|
||||
$this->assertEquals("yay", $this->smarty->fetch("string:{if isset(\$test)}yay{/if}"));
|
||||
}
|
||||
|
||||
public function testIntZeroIsset() {
|
||||
$this->smarty->assign('test', 0);
|
||||
$this->assertEquals("yay", $this->smarty->fetch("string:{if isset(\$test)}yay{/if}"));
|
||||
}
|
||||
|
||||
public function testMultivar() {
|
||||
$this->smarty->assign('test', 0);
|
||||
$this->smarty->assign('test2', 'pizza');
|
||||
$this->assertEquals("yay", $this->smarty->fetch("string:{if isset(\$test, \$test2)}yay{/if}"));
|
||||
}
|
||||
|
||||
public function testMultivarOneNotset() {
|
||||
$this->smarty->assign('test', 0);
|
||||
$this->assertEquals("nay", $this->smarty->fetch("string:{if isset(\$test, \$test2)}yay{else}nay{/if}"));
|
||||
}
|
||||
|
||||
public function testInvalidParameters() {
|
||||
$this->expectException(\Smarty\Exception::class);
|
||||
$this->expectExceptionMessage('Invalid number of arguments');
|
||||
$this->assertEquals("", $this->smarty->fetch("string:{empty(3, 'foo')}"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace UnitTests\TemplateSource\TagTests\PluginFunction;
|
||||
class TimeTest extends \PHPUnit_Smarty {
|
||||
|
||||
public function setUp(): void {
|
||||
$this->setUpSmarty(__DIR__);
|
||||
}
|
||||
|
||||
public function testBasicSyntax() {
|
||||
$this->assertStringMatchesFormat('%d', $this->smarty->fetch("string:{time()}"));
|
||||
}
|
||||
|
||||
public function testInvalidParameters() {
|
||||
$this->expectException(\Smarty\Exception::class);
|
||||
$this->expectExceptionMessage('Invalid number of arguments');
|
||||
$this->assertEquals("", $this->smarty->fetch("string:{time(3, 'foo')}"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user