Update default handler teste

This commit is contained in:
uwetews
2016-08-05 21:22:23 +02:00
parent 3155e9ce8e
commit f8420363b8
2 changed files with 47 additions and 13 deletions

View File

@@ -10,7 +10,7 @@
* class for default config handler test * class for default config handler test
* *
* @runTestsInSeparateProcess * @runTestsInSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled
* @backupStaticAttributes enabled * @backupStaticAttributes enabled
*/ */
class DefaultConfigHandlerTest extends PHPUnit_Smarty class DefaultConfigHandlerTest extends PHPUnit_Smarty
@@ -29,9 +29,8 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty
/** /**
* @expectedException SmartyException * @expectedException SmartyException
* @expectedExceptionMessage Unable to read * @expectedExceptionMessage Unable to load config 'file:foo.conf'
* @expectedExceptionMessage file 'foo.conf' *
*
* test unknown config file * test unknown config file
*/ */
public function testUnknownConfigFile() public function testUnknownConfigFile()
@@ -54,7 +53,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty
/** /**
* test default config handler replacement (config data) * test default config handler replacement (config data)
* *
* @throws \Exception * @throws \Exception
* @throws \SmartyException * @throws \SmartyException
*/ */
@@ -80,21 +79,49 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty
/** /**
* @expectedException SmartyException * @expectedException SmartyException
* @expectedExceptionMessage Unable to read * @expectedExceptionMessage Unable to load config default file 'no.conf' for 'file:fo.conf'
* @expectedExceptionMessage file 'foo.conf' *
* *
*/
public function testDefaultConfigHandlerReplacementByConfigFileFail()
{
$this->smarty->registerDefaultConfigHandler('configHandlerFile');
$this->smarty->configLoad('fo.conf');
$this->assertEquals("123.4", $this->smarty->fetch('eval:{#Number#}'));
}
/**
* @expectedException SmartyException
* @expectedExceptionMessage Unable to load config 'file:foo.conf'
*
*
* test default config handler replacement (return false) * test default config handler replacement (return false)
* *
*/ */
public function testDefaultConfigHandlerReplacementReturningFalse() public function testDefaultConfigHandlerReplacementReturningFalse()
{ {
$this->smarty->configLoad('foo.conf'); $this->smarty->configLoad('foo.conf');
} }
/**
* @expectedException SmartyException
* @expectedExceptionMessage No config default content for 'file:bla.conf'
*
*
* test default config handler replacement (return false)
*
*/
public function testDefaultConfigHandlerReplacementReturningFalse1()
{
$this->smarty->registerDefaultConfigHandler('configHandlerData');
$this->smarty->configLoad('bla.conf');
}
} }
/** /**
* config handler returning config data * config handler returning config data
* *
* @param $resource_type * @param $resource_type
* @param $resource_name * @param $resource_name
* @param $config_source * @param $config_source
@@ -105,6 +132,9 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty
*/ */
function configHandlerData($resource_type, $resource_name, &$config_source, &$config_timestamp, Smarty $smarty) function configHandlerData($resource_type, $resource_name, &$config_source, &$config_timestamp, Smarty $smarty)
{ {
if ($resource_name !== 'foo.conf') {
return false;
}
$output = "foo = 'bar'\n"; $output = "foo = 'bar'\n";
$config_source = $output; $config_source = $output;
$config_timestamp = time(); $config_timestamp = time();
@@ -114,7 +144,7 @@ function configHandlerData($resource_type, $resource_name, &$config_source, &$co
/** /**
* config handler returning config file * config handler returning config file
* *
* @param $resource_type * @param $resource_type
* @param $resource_name * @param $resource_name
* @param $config_source * @param $config_source
@@ -125,12 +155,16 @@ function configHandlerData($resource_type, $resource_name, &$config_source, &$co
*/ */
function configHandlerFile($resource_type, $resource_name, &$config_source, &$config_timestamp, Smarty $smarty) 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'; return $smarty->getConfigDir(0) . 'test.conf';
} }
/** /**
* config handler returning false * config handler returning false
* *
* @param $resource_type * @param $resource_type
* @param $resource_name * @param $resource_name
* @param $config_source * @param $config_source

View File

@@ -85,7 +85,7 @@ class DefaultTemplateHandlerTest extends PHPUnit_Smarty
$this->smarty->fetch('foo.tpl'); $this->smarty->fetch('foo.tpl');
} }
catch (Exception $e) { catch (Exception $e) {
$this->assertContains('Unable to load template', $e->getMessage()); $this->assertContains('Default handler: No template default content for \'file:foo.tpl\'', $e->getMessage());
return; return;
} }