mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-08 00:01:38 +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.
114 lines
3.2 KiB
PHP
114 lines
3.2 KiB
PHP
<?php
|
|
/**
|
|
* Smarty PHPunit tests deault template handler
|
|
*
|
|
* @package PHPunit
|
|
* @author Uwe Tews
|
|
*/
|
|
|
|
/**
|
|
* class for block plugin tests
|
|
*
|
|
* @runTestsInSeparateProcess
|
|
* @preserveGlobalState disabled
|
|
* @backupStaticAttributes enabled
|
|
*/
|
|
class DefaultTemplateHandlerTest extends PHPUnit_Smarty
|
|
{
|
|
public function setUp(): void
|
|
{
|
|
$this->setUpSmarty(dirname(__FILE__));
|
|
$this->smarty->setForceCompile(true);
|
|
$this->smarty->disableSecurity();
|
|
}
|
|
|
|
|
|
public function testInit()
|
|
{
|
|
$this->cleanDirs();
|
|
}
|
|
/**
|
|
* test error on unknow template
|
|
*/
|
|
public function testUnknownTemplate()
|
|
{
|
|
try {
|
|
$this->smarty->fetch('foo.tpl');
|
|
}
|
|
catch (Exception $e) {
|
|
$this->assertStringContainsString('Unable to load template', $e->getMessage());
|
|
|
|
return;
|
|
}
|
|
$this->fail('Exception for none existing template has not been raised.');
|
|
}
|
|
|
|
/**
|
|
* test error on registration on none existent handler function.
|
|
*/
|
|
public function testRegisterNoneExistentHandlerFunction()
|
|
{
|
|
try {
|
|
$this->smarty->registerDefaultTemplateHandler('foo');
|
|
}
|
|
catch (Exception $e) {
|
|
$this->assertStringContainsString("Default template handler", $e->getMessage());
|
|
$this->assertStringContainsString("not callable", $e->getMessage());
|
|
|
|
return;
|
|
}
|
|
$this->fail('Exception for none callable function has not been raised.');
|
|
}
|
|
/**
|
|
* test replacement by default template handler
|
|
*/
|
|
/**
|
|
* public function testDefaultTemplateHandlerReplacement()
|
|
* {
|
|
* $this->smarty->register->defaultTemplateHandler('my_template_handler');
|
|
* $this->assertEquals("Recsource foo.tpl of type file not found", $this->smarty->fetch('foo.tpl'));
|
|
* }
|
|
*/
|
|
public function testDefaultTemplateHandlerReplacementByTemplateFile()
|
|
{
|
|
$this->smarty->registerDefaultTemplateHandler('my_template_handler_file');
|
|
$this->assertEquals("hello world", $this->smarty->fetch('foo.tpl'));
|
|
}
|
|
|
|
/**
|
|
* test default template handler returning fals
|
|
*/
|
|
public function testDefaultTemplateHandlerReturningFalse()
|
|
{
|
|
$this->smarty->registerDefaultTemplateHandler('my_false');
|
|
try {
|
|
$this->smarty->fetch('foo.tpl');
|
|
}
|
|
catch (Exception $e) {
|
|
$this->assertStringContainsString('Default handler: No template default content for \'file:foo.tpl\'', $e->getMessage());
|
|
|
|
return;
|
|
}
|
|
$this->fail('Exception for none existing template has not been raised.');
|
|
}
|
|
}
|
|
|
|
function my_template_handler($resource_type, $resource_name, &$template_source, &$template_timestamp, Smarty $smarty)
|
|
{
|
|
$output = "Recsource $resource_name of type $resource_type not found";
|
|
$template_source = $output;
|
|
$template_timestamp = time();
|
|
|
|
return true;
|
|
}
|
|
|
|
function my_template_handler_file($resource_type, $resource_name, &$template_source, &$template_timestamp, Smarty $smarty)
|
|
{
|
|
return $smarty->getTemplateDir(0) . 'helloworld.tpl';
|
|
}
|
|
|
|
function my_false($resource_type, $resource_name, &$template_source, &$template_timestamp, Smarty $smarty)
|
|
{
|
|
return false;
|
|
}
|