mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-08 08:11:39 +01:00
* Removed unneeded files and replace dummy.txt with .gitignore files * Synced unit tests with master codebase, noted TODO's, fixed phpunit scripts and travis config * fix php7.4 deprecation and remove php7.4 from travis allow_failures since php7.4 is current stable Co-authored-by: Uwe Tews <uwe.tews@googlemail.com> Co-authored-by: Uwe Tews <uwe.tews@gmail.com> Co-authored-by: AnrDaemon <anrdaemon@yandex.ru>
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()
|
|
{
|
|
$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;
|
|
}
|
|
}
|
|
}
|