mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-08 16:21:39 +01:00
Adds support for PHP8.0, dropping support for PHP7.0 and below.
Backwards incompatible changes:
- Dropped support for php asp tags in templates (removed from php since php7.0)
- Dropped deprecated API calls that where only accessible through SmartyBC
- Dropped support for {php} and {include_php} tags and embedded PHP in templates. Embedded PHP will now be passed through as is.
- Removed all PHP_VERSION_ID and compare_version checks and conditional code blocks that are now no longer required
- Dropped deprecated SMARTY_RESOURCE_CHAR_SET and SMARTY_RESOURCE_DATE_FORMAT constants
- Dropped deprecated Smarty::muteExpectedErrors and Smarty::unmuteExpectedErrors API methods
- Dropped deprecated $smarty->getVariable() method. Use $smarty->getTemplateVars() instead.
- $smarty->registerResource() no longer accepts an array of callback functions
See the changelog for more details.
Switched CI from Travis to Github CI.
107 lines
3.0 KiB
PHP
107 lines
3.0 KiB
PHP
<?php
|
|
/**
|
|
* Smarty PHPunit tests compilation of registered object functions
|
|
*
|
|
* @package PHPunit
|
|
* @author Uwe Tews
|
|
*/
|
|
|
|
/**
|
|
* class for registered object function tests
|
|
*
|
|
* @runTestsInSeparateProcess
|
|
* @preserveGlobalState disabled
|
|
* @backupStaticAttributes enabled
|
|
*/
|
|
class CompileRegisteredObjectFunctionTest extends PHPUnit_Smarty
|
|
{
|
|
public function setUp(): void
|
|
{
|
|
$this->setUpSmarty(dirname(__FILE__));
|
|
|
|
$this->smarty->setForceCompile(true);
|
|
$this->smarty->disableSecurity();
|
|
$this->object = new RegObject;
|
|
$this->smarty->registerObject('objecttest', $this->object, 'myhello', true, 'myblock');
|
|
$this->smarty->registerObject('objectprop', $this->object);
|
|
}
|
|
|
|
|
|
public function testInit()
|
|
{
|
|
$this->cleanDirs();
|
|
}
|
|
/**
|
|
* test resgistered object as function
|
|
*/
|
|
public function testRegisteredObjectFunction()
|
|
{
|
|
$tpl = $this->smarty->createTemplate('eval:{objecttest->myhello}');
|
|
$this->assertEquals('hello world', $this->smarty->fetch($tpl));
|
|
}
|
|
|
|
/**
|
|
* test resgistered object as function with modifier
|
|
*/
|
|
public function testRegisteredObjectFunctionModifier()
|
|
{
|
|
$tpl = $this->smarty->createTemplate('eval:{objecttest->myhello|truncate:6}');
|
|
$this->assertEquals('hel...', $this->smarty->fetch($tpl));
|
|
}
|
|
|
|
/**
|
|
* test resgistered object as block function
|
|
*/
|
|
public function testRegisteredObjectBlockFunction()
|
|
{
|
|
$tpl = $this->smarty->createTemplate('eval:{objecttest->myblock}hello world{/objecttest->myblock}');
|
|
$this->assertEquals('block test', $this->smarty->fetch($tpl));
|
|
}
|
|
|
|
public function testRegisteredObjectBlockFunctionModifier1()
|
|
{
|
|
$tpl = $this->smarty->createTemplate('eval:{objecttest->myblock}hello world{/objecttest->myblock|strtoupper}');
|
|
$this->assertEquals(strtoupper('block test'), $this->smarty->fetch($tpl));
|
|
}
|
|
|
|
public function testRegisteredObjectBlockFunctionModifier2()
|
|
{
|
|
$tpl = $this->smarty->createTemplate('eval:{objecttest->myblock}hello world{/objecttest->myblock|default:""|strtoupper}');
|
|
$this->assertEquals(strtoupper('block test'), $this->smarty->fetch($tpl));
|
|
}
|
|
// TODO
|
|
|
|
/**
|
|
public function testRegisteredObjectProperty()
|
|
{
|
|
$tpl = $this->smarty->createTemplate('eval:{objectprop->prop}');
|
|
$this->assertEquals('hello world', $this->smarty->fetch($tpl));
|
|
}
|
|
|
|
public function testRegisteredObjectPropertyAssign()
|
|
{
|
|
$tpl = $this->smarty->createTemplate('eval:{objectprop->prop assign="foo"}{$foo}');
|
|
$this->assertEquals('hello world', $this->smarty->fetch($tpl));
|
|
}
|
|
*/
|
|
}
|
|
|
|
Class RegObject
|
|
{
|
|
public $prop = 'hello world';
|
|
|
|
public function myhello($params)
|
|
{
|
|
return 'hello world';
|
|
}
|
|
|
|
public function myblock($params, $content, &$smarty_tpl, &$repeat)
|
|
{
|
|
if (isset($content)) {
|
|
$output = str_replace('hello world', 'block test', $content);
|
|
|
|
return $output;
|
|
}
|
|
}
|
|
}
|