mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-07 15:51:37 +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.
167 lines
4.5 KiB
PHP
167 lines
4.5 KiB
PHP
<?php
|
|
/**
|
|
* Smarty PHPUnit tests default config handler
|
|
*
|
|
* @package PHPunit
|
|
* @author Uwe Tews
|
|
*/
|
|
|
|
/**
|
|
* class for default config handler test
|
|
*
|
|
* @runTestsInSeparateProcess
|
|
* @preserveGlobalState disabled
|
|
* @backupStaticAttributes enabled
|
|
*/
|
|
class DefaultConfigHandlerTest extends PHPUnit_Smarty
|
|
{
|
|
|
|
/**
|
|
* Sets up the fixture
|
|
* This method is called before a test is executed.
|
|
*
|
|
*/
|
|
public function setUp(): void
|
|
{
|
|
$this->setUpSmarty(dirname(__FILE__));
|
|
$this->smarty->setForceCompile(true);
|
|
}
|
|
|
|
/**
|
|
* test unknown config file
|
|
*/
|
|
public function testUnknownConfigFile()
|
|
{
|
|
$this->expectException('SmartyException');
|
|
$this->expectExceptionMessage('Unable to load config \'file:foo.conf\'');
|
|
$this->smarty->configLoad('foo.conf');
|
|
}
|
|
|
|
/**
|
|
* test register unknown default config handler
|
|
*/
|
|
public function testRegisterUnknownDefaultConfigHandler()
|
|
{
|
|
$this->expectException('SmartyException');
|
|
$this->expectExceptionMessage('Default config handler');
|
|
$this->expectExceptionMessage('not callable');
|
|
$this->smarty->registerDefaultConfigHandler('foo');
|
|
}
|
|
|
|
/**
|
|
* test default config handler replacement (config data)
|
|
*
|
|
* @throws \Exception
|
|
* @throws \SmartyException
|
|
*/
|
|
public function testDefaultConfigHandlerReplacement()
|
|
{
|
|
$this->smarty->registerDefaultConfigHandler('configHandlerData');
|
|
$this->smarty->configLoad('foo.conf');
|
|
$this->assertEquals("bar", $this->smarty->fetch('foo.tpl'));
|
|
}
|
|
|
|
/**
|
|
* test default config handler replacement (other config file)
|
|
*
|
|
* @throws \Exception
|
|
* @throws \SmartyException
|
|
*/
|
|
public function testDefaultConfigHandlerReplacementByConfigFile()
|
|
{
|
|
$this->smarty->registerDefaultConfigHandler('configHandlerFile');
|
|
$this->smarty->configLoad('foo.conf');
|
|
$this->assertEquals("123.4", $this->smarty->fetch('number.tpl'));
|
|
}
|
|
|
|
public function testDefaultConfigHandlerReplacementByConfigFileFail()
|
|
{
|
|
$this->expectException('SmartyException');
|
|
$this->expectExceptionMessage("Unable to load config default file 'no.conf' for 'file:fo.conf'");
|
|
$this->smarty->registerDefaultConfigHandler('configHandlerFile');
|
|
$this->smarty->configLoad('fo.conf');
|
|
$this->assertEquals("123.4", $this->smarty->fetch('number.tpl'));
|
|
}
|
|
|
|
/**
|
|
* test default config handler replacement (return false)
|
|
*/
|
|
public function testDefaultConfigHandlerReplacementReturningFalse()
|
|
{
|
|
$this->expectException('SmartyException');
|
|
$this->expectExceptionMessage('Unable to load config \'file:foo.conf\'');
|
|
$this->smarty->configLoad('foo.conf');
|
|
}
|
|
|
|
/**
|
|
* test default config handler replacement (return false)
|
|
*/
|
|
public function testDefaultConfigHandlerReplacementReturningFalse1()
|
|
{
|
|
$this->expectException('SmartyException');
|
|
$this->expectExceptionMessage('No config default content for \'file:bla.conf\'');
|
|
$this->smarty->registerDefaultConfigHandler('configHandlerData');
|
|
$this->smarty->configLoad('bla.conf');
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* config handler returning config data
|
|
*
|
|
* @param $resource_type
|
|
* @param $resource_name
|
|
* @param $config_source
|
|
* @param $config_timestamp
|
|
* @param \Smarty $smarty
|
|
*
|
|
* @return bool
|
|
*/
|
|
function configHandlerData($resource_type, $resource_name, &$config_source, &$config_timestamp, Smarty $smarty)
|
|
{
|
|
if ($resource_name !== 'foo.conf') {
|
|
return false;
|
|
}
|
|
$output = "foo = 'bar'\n";
|
|
$config_source = $output;
|
|
$config_timestamp = time();
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* config handler returning config file
|
|
*
|
|
* @param $resource_type
|
|
* @param $resource_name
|
|
* @param $config_source
|
|
* @param $config_timestamp
|
|
* @param \Smarty $smarty
|
|
*
|
|
* @return string
|
|
*/
|
|
function configHandlerFile($resource_type, $resource_name, &$config_source, &$config_timestamp, Smarty $smarty)
|
|
{
|
|
if ($resource_name !== 'foo.conf') {
|
|
return 'no.conf';
|
|
}
|
|
|
|
return $smarty->getConfigDir(0) . 'test.conf';
|
|
}
|
|
|
|
/**
|
|
* config handler returning false
|
|
*
|
|
* @param $resource_type
|
|
* @param $resource_name
|
|
* @param $config_source
|
|
* @param $config_timestamp
|
|
* @param \Smarty $smarty
|
|
*
|
|
* @return bool
|
|
*/
|
|
function configHandlerFalse($resource_type, $resource_name, &$config_source, &$config_timestamp, Smarty $smarty)
|
|
{
|
|
return false;
|
|
}
|