update config tests

This commit is contained in:
uwetews
2016-08-07 12:57:48 +02:00
parent f8420363b8
commit fd8f010b05
25 changed files with 127 additions and 38 deletions

View File

@@ -61,7 +61,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty
{ {
$this->smarty->registerDefaultConfigHandler('configHandlerData'); $this->smarty->registerDefaultConfigHandler('configHandlerData');
$this->smarty->configLoad('foo.conf'); $this->smarty->configLoad('foo.conf');
$this->assertEquals("bar", $this->smarty->fetch('eval:{#foo#}')); $this->assertEquals("bar", $this->smarty->fetch('foo.tpl'));
} }
/** /**
@@ -74,7 +74,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty
{ {
$this->smarty->registerDefaultConfigHandler('configHandlerFile'); $this->smarty->registerDefaultConfigHandler('configHandlerFile');
$this->smarty->configLoad('foo.conf'); $this->smarty->configLoad('foo.conf');
$this->assertEquals("123.4", $this->smarty->fetch('eval:{#Number#}')); $this->assertEquals("123.4", $this->smarty->fetch('number.tpl'));
} }
/** /**
@@ -87,7 +87,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty
{ {
$this->smarty->registerDefaultConfigHandler('configHandlerFile'); $this->smarty->registerDefaultConfigHandler('configHandlerFile');
$this->smarty->configLoad('fo.conf'); $this->smarty->configLoad('fo.conf');
$this->assertEquals("123.4", $this->smarty->fetch('eval:{#Number#}')); $this->assertEquals("123.4", $this->smarty->fetch('number.tpl'));
} }
/** /**

View File

@@ -0,0 +1 @@
{#foo#}

View File

@@ -0,0 +1 @@
{#Number#}

View File

@@ -39,7 +39,7 @@ class ConfigVarTest extends PHPUnit_Smarty
public function testConfigNumber() public function testConfigNumber()
{ {
$this->smarty->configLoad('test.conf'); $this->smarty->configLoad('test.conf');
$this->assertEquals("123.4", $this->smarty->fetch('eval:{#Number#}')); $this->assertEquals("123.4", $this->smarty->fetch('number.tpl'));
} }
/** /**
@@ -51,7 +51,7 @@ class ConfigVarTest extends PHPUnit_Smarty
public function testConfigText() public function testConfigText()
{ {
$this->smarty->configLoad('test.conf'); $this->smarty->configLoad('test.conf');
$this->assertEquals("123bvc", $this->smarty->fetch('eval:{#text#}')); $this->assertEquals("123bvc", $this->smarty->fetch('text.tpl'));
} }
/** /**
@@ -75,7 +75,7 @@ class ConfigVarTest extends PHPUnit_Smarty
public function testConfigVariableGlobalSections() public function testConfigVariableGlobalSections()
{ {
$this->smarty->configLoad('test.conf'); $this->smarty->configLoad('test.conf');
$this->assertEquals("Welcome to Smarty! Global Section1 Global Section2", $this->smarty->fetch('eval:{#title#} {#sec1#} {#sec2#}')); $this->assertEquals("Welcome to Smarty! Global Section1 Global Section2", $this->smarty->fetch('sec1sec2.tpl'));
} }
/** /**
@@ -87,7 +87,7 @@ class ConfigVarTest extends PHPUnit_Smarty
public function testConfigVariableSection2() public function testConfigVariableSection2()
{ {
$this->smarty->configLoad('test.conf', 'section2'); $this->smarty->configLoad('test.conf', 'section2');
$this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('eval:{#title#} {#sec1#} {#sec2#}')); $this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('sec1sec2.tpl'));
} }
/** /**
@@ -99,7 +99,7 @@ class ConfigVarTest extends PHPUnit_Smarty
public function testConfigVariableSectionSpecialChar() public function testConfigVariableSectionSpecialChar()
{ {
$this->smarty->configLoad('test.conf', '/'); $this->smarty->configLoad('test.conf', '/');
$this->assertEquals("Welcome to Smarty! special char", $this->smarty->fetch('eval:{#title#} {#sec#}')); $this->assertEquals("Welcome to Smarty! special char", $this->smarty->fetch('sec.tpl'));
} }
/** /**
@@ -111,7 +111,7 @@ class ConfigVarTest extends PHPUnit_Smarty
public function testConfigVariableSectionFooBar() public function testConfigVariableSectionFooBar()
{ {
$this->smarty->configLoad('test.conf', 'foo/bar'); $this->smarty->configLoad('test.conf', 'foo/bar');
$this->assertEquals("Welcome to Smarty! section foo/bar", $this->smarty->fetch('eval:{#title#} {#sec#}')); $this->assertEquals("Welcome to Smarty! section foo/bar", $this->smarty->fetch('sec.tpl'));
} }
/** /**
@@ -123,9 +123,9 @@ class ConfigVarTest extends PHPUnit_Smarty
public function testConfigDifferentScope() public function testConfigDifferentScope()
{ {
$this->smarty->configLoad('test.conf', 'section2'); $this->smarty->configLoad('test.conf', 'section2');
$tpl = $this->smarty->createTemplate('eval:{#title#} {#sec1#} {#sec2#}'); $tpl = $this->smarty->createTemplate('sec1sec2.tpl');
$tpl->configLoad('test.conf', 'section1'); $tpl->configLoad('test.conf', 'section1');
$this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('eval:{#title#} {#sec1#} {#sec2#}')); $this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('sec1sec2.tpl'));
$this->assertEquals("Welcome to Smarty! Hello Section1 Global Section2", $this->smarty->fetch($tpl)); $this->assertEquals("Welcome to Smarty! Hello Section1 Global Section2", $this->smarty->fetch($tpl));
} }
@@ -140,7 +140,7 @@ class ConfigVarTest extends PHPUnit_Smarty
{ {
$this->smarty->config_read_hidden = true; $this->smarty->config_read_hidden = true;
$this->smarty->configLoad('test.conf', 'hidden'); $this->smarty->configLoad('test.conf', 'hidden');
$this->assertEquals("Welcome to Smarty!Hidden Section", $this->smarty->fetch('eval:{#title#}{#hiddentext#}')); $this->assertEquals("Welcome to Smarty!Hidden Section", $this->smarty->fetch('hidden.tpl'));
} }
/** /**
@@ -155,7 +155,7 @@ class ConfigVarTest extends PHPUnit_Smarty
$this->smarty->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE)); $this->smarty->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE));
$this->smarty->config_read_hidden = false; $this->smarty->config_read_hidden = false;
$this->smarty->configLoad('test.conf', 'hidden'); $this->smarty->configLoad('test.conf', 'hidden');
$this->assertEquals("Welcome to Smarty!", $this->smarty->fetch('eval:{#title#}{#hiddentext#}')); $this->assertEquals("Welcome to Smarty!", $this->smarty->fetch('hidden.tpl'));
} }
/** /**
@@ -223,7 +223,7 @@ class ConfigVarTest extends PHPUnit_Smarty
{ {
$data = $this->smarty->createData(); $data = $this->smarty->createData();
$data->configLoad('test.conf'); $data->configLoad('test.conf');
$this->assertEquals("123bvc", $this->smarty->fetch('eval:{#text#}', $data)); $this->assertEquals("123bvc", $this->smarty->fetch('text.tpl', $data));
} }
/** /**
@@ -294,7 +294,7 @@ class ConfigVarTest extends PHPUnit_Smarty
*/ */
public function testConfigTextTemplate() public function testConfigTextTemplate()
{ {
$tpl = $this->smarty->createTemplate('eval:{#text#}'); $tpl = $this->smarty->createTemplate('text.tpl');
$tpl->configLoad('test.conf'); $tpl->configLoad('test.conf');
$this->assertEquals("123bvc", $this->smarty->fetch($tpl)); $this->assertEquals("123bvc", $this->smarty->fetch($tpl));
} }
@@ -307,7 +307,7 @@ class ConfigVarTest extends PHPUnit_Smarty
*/ */
public function testConfigGetSingleConfigVarTemplate() public function testConfigGetSingleConfigVarTemplate()
{ {
$tpl = $this->smarty->createTemplate('eval:{#text#}'); $tpl = $this->smarty->createTemplate('text.tpl');
$tpl->configLoad('test.conf'); $tpl->configLoad('test.conf');
$this->assertEquals("Welcome to Smarty!", $tpl->getConfigVars('title')); $this->assertEquals("Welcome to Smarty!", $tpl->getConfigVars('title'));
} }
@@ -320,7 +320,7 @@ class ConfigVarTest extends PHPUnit_Smarty
*/ */
public function testConfigGetAllConfigVarsTemplate() public function testConfigGetAllConfigVarsTemplate()
{ {
$tpl = $this->smarty->createTemplate('eval:{#text#}'); $tpl = $this->smarty->createTemplate('text.tpl');
$tpl->configLoad('test.conf'); $tpl->configLoad('test.conf');
$vars = $tpl->getConfigVars(); $vars = $tpl->getConfigVars();
$this->assertTrue(is_array($vars)); $this->assertTrue(is_array($vars));
@@ -336,7 +336,7 @@ class ConfigVarTest extends PHPUnit_Smarty
*/ */
public function testConfigClearSingleConfigVarTemplate() public function testConfigClearSingleConfigVarTemplate()
{ {
$tpl = $this->smarty->createTemplate('eval:{#text#}'); $tpl = $this->smarty->createTemplate('text.tpl');
$tpl->configLoad('test.conf'); $tpl->configLoad('test.conf');
$tpl->clearConfig('title'); $tpl->clearConfig('title');
$this->assertEquals("", $tpl->getConfigVars('title')); $this->assertEquals("", $tpl->getConfigVars('title'));
@@ -351,7 +351,7 @@ class ConfigVarTest extends PHPUnit_Smarty
*/ */
public function testConfigClearConfigAllTemplate() public function testConfigClearConfigAllTemplate()
{ {
$tpl = $this->smarty->createTemplate('eval:{#text#}'); $tpl = $this->smarty->createTemplate('text.tpl');
$tpl->configLoad('test.conf'); $tpl->configLoad('test.conf');
$tpl->clearConfig(); $tpl->clearConfig();
$vars = $tpl->getConfigVars(); $vars = $tpl->getConfigVars();
@@ -369,25 +369,25 @@ class ConfigVarTest extends PHPUnit_Smarty
{ {
$file = realpath($this->smarty->getConfigDir(0) . 'test.conf'); $file = realpath($this->smarty->getConfigDir(0) . 'test.conf');
$this->smarty->configLoad($file); $this->smarty->configLoad($file);
$this->assertEquals("123.4", $this->smarty->fetch('eval:{#Number#}')); $this->assertEquals("123.4", $this->smarty->fetch('number.tpl'));
} }
public function testConfigResourceDb4() public function testConfigResourceDb4()
{ {
$this->smarty->addPluginsDir(dirname(__FILE__) . "/PHPunitplugins/"); $this->smarty->addPluginsDir(dirname(__FILE__) . "/PHPunitplugins/");
$this->smarty->configLoad('db4:foo.conf'); $this->smarty->configLoad('db4:foo.conf');
$this->assertEquals("bar", $this->smarty->fetch('eval:{#foo#}')); $this->assertEquals("bar", $this->smarty->fetch('foo.tpl'));
} }
public function testConfigUndefinedSilent() public function testConfigUndefinedSilent()
{ {
$this->assertEquals("", $this->smarty->fetch('eval:{#foo#}')); $this->assertEquals("", $this->smarty->fetch('foo.tpl'));
} }
public function testConfigUndefinedNotice() public function testConfigUndefinedNotice()
{ {
$this->smarty->error_unassigned = true; $this->smarty->error_unassigned = true;
try { try {
$this->assertEquals("", $this->smarty->fetch('eval:{#foo#}')); $this->assertEquals("", $this->smarty->fetch('foo.tpl'));
} }
catch (Exception $e) { catch (Exception $e) {
$this->assertEquals('Undefined variable: foo', $e->getMessage()); $this->assertEquals('Undefined variable: foo', $e->getMessage());

View File

@@ -0,0 +1,49 @@
title = Welcome to Smarty!
overwrite = Overwrite1
overwrite = Overwrite2
booleanon = on
Intro = """This is a value that spans more
than one line. you must enclose
it in triple quotes."""
Number = 123.4
text = 123bvc
line = 123 This is a line
sec1 = Global Section1
sec2 = Global Section2
sec = Global char
[/]
sec = special char
[foo/bar]
sec = section foo/bar
[section1]
sec1 = Hello Section1
[section2]
sec2 = 'Hello Section2'
[.hidden]
hiddentext = Hidden Section
#Comment
# Comment with a space first line first
#Comment line starting with space
# Space before and after #
#The line below only contains a #
#
#
# title = This is not the correct title
#[section1]
#sec1 = Wrong text

View File

@@ -0,0 +1 @@
{#foo#}

View File

@@ -0,0 +1 @@
{#title#}{#hiddentext#}

View File

@@ -0,0 +1 @@
{#Number#}

View File

@@ -0,0 +1 @@
{#title#} {#sec#}

View File

@@ -0,0 +1 @@
{#title#} {#sec1#} {#sec2#}

View File

@@ -0,0 +1 @@
{#text#}

View File

@@ -46,6 +46,28 @@ class CompileConfigLoadTest extends PHPUnit_Smarty
{ {
$this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('001_section2.tpl')); $this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('001_section2.tpl'));
} }
/**
* @run InSeparateProcess
* @preserveGlobalState disabled
*
* test {load_config} loading section2
*/
public function testConfigVariableSection2Template_0012()
{
$this->smarty->caching = true;
$this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('001_section2.tpl'));
}
/**
* @run InSeparateProcess
* @preserveGlobalState disabled
*
* test {load_config} loading section2
*/
public function testConfigVariableInclude_003()
{
$this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('003_section2.tpl'));
}
/** /**
* @runInSeparateProcess * @runInSeparateProcess
@@ -64,10 +86,10 @@ class CompileConfigLoadTest extends PHPUnit_Smarty
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled
*/ */
public function testConfigVariableAllSectionsTemplate() public function testConfigVariableAllSectionsTemplate_004()
{ {
$this->smarty->setConfigOverwrite(true); $this->smarty->setConfigOverwrite(true);
$this->assertEquals("Welcome to Smarty! Global Section1 Global Section2", $this->smarty->fetch('eval:{config_load file=\'test.conf\'}{#title#} {#sec1#} {#sec2#}')); $this->assertEquals("Welcome to Smarty! Global Section1 Global Section2", $this->smarty->fetch('004_allsection.tpl'));
} }
/** /**
@@ -76,18 +98,18 @@ class CompileConfigLoadTest extends PHPUnit_Smarty
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled
*/ */
public function testConfigVariableOverwrite() public function testConfigVariableOverwrite_005()
{ {
$this->assertEquals("Overwrite2", $this->smarty->fetch('eval:{config_load file=\'test.conf\'}{#overwrite#}')); $this->assertEquals("Overwrite2", $this->smarty->fetch('005_overwrite.tpl'));
} }
/** /**
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled
*/ */
public function testConfigVariableOverwrite2() public function testConfigVariableOverwrite_006()
{ {
$this->assertEquals("Overwrite3", $this->smarty->fetch('eval:{config_load file=\'test.conf\'}{config_load file=\'test2.conf\'}{#overwrite#}')); $this->assertEquals("Overwrite3", $this->smarty->fetch('006_overwrite.tpl'));
} }
/** /**
@@ -96,10 +118,10 @@ class CompileConfigLoadTest extends PHPUnit_Smarty
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled
*/ */
public function testConfigVariableOverwriteFalse() public function testConfigVariableOverwrite_007()
{ {
$this->smarty->setConfigOverwrite(false); $this->smarty->setConfigOverwrite(false);
$this->assertEquals("Overwrite1Overwrite2Overwrite3Welcome to Smarty! Global Section1 Global Section2", $this->smarty->fetch('eval:{config_load file=\'test.conf\'}{config_load file=\'test2.conf\'}{foreach #overwrite# as $over}{$over}{/foreach}{#title#} {#sec1#} {#sec2#}')); $this->assertEquals("Overwrite1 Overwrite2 Overwrite3 ", $this->smarty->fetch('007_overwrite.tpl'));
} }
/** /**
@@ -108,10 +130,11 @@ class CompileConfigLoadTest extends PHPUnit_Smarty
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled
*/ */
public function testConfigVariableBooleanizeOn() public function testConfigVariableBooleanizeOn_008()
{ {
$this->smarty->setConfigBooleanize(true); $this->smarty->setConfigBooleanize(true);
$this->assertEquals("passed", $this->smarty->fetch('eval:{config_load file=\'test.conf\'}{if #booleanon# === true}passed{/if}')); $this->smarty->assign('expected', true);
$this->assertEquals("passed", $this->smarty->fetch('008_booleanize.tpl'));
} }
/** /**
@@ -120,10 +143,11 @@ class CompileConfigLoadTest extends PHPUnit_Smarty
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled
*/ */
public function testConfigVariableBooleanizeOff() public function testConfigVariableBooleanizeOff_008()
{ {
$this->smarty->setConfigBooleanize(false); $this->smarty->setConfigBooleanize(false);
$this->assertEquals("passed", $this->smarty->fetch('eval:{config_load file=\'test.conf\'}{if #booleanon# == \'on\'}passed{/if}')); $this->smarty->assign('expected', 'on');
$this->assertEquals("passed", $this->smarty->fetch('008_booleanize.tpl'));
} }
/** /**
@@ -131,8 +155,8 @@ class CompileConfigLoadTest extends PHPUnit_Smarty
* @expectedExceptionMessage Syntax error in config file * @expectedExceptionMessage Syntax error in config file
* test config file syntax error * test config file syntax error
*/ */
public function testConfigSyntaxError() public function testConfigSyntaxError_009()
{ {
$this->smarty->fetch('eval:{config_load file=\'test_error.conf\'}'); $this->smarty->fetch('009_error.tpl');
} }
} }

View File

@@ -0,0 +1 @@
{config_load file='test.conf' section='section2'}{#title#} {#sec1#} {include '003_include.tpl'}

View File

@@ -0,0 +1 @@
{config_load 'test.conf'}{#title#} {#sec1#} {#sec2#}

View File

@@ -0,0 +1 @@
{config_load 'test.conf'}{#overwrite#}

View File

@@ -0,0 +1 @@
{config_load 'test.conf'}{config_load 'test2.conf'}{#overwrite#}

View File

@@ -0,0 +1 @@
{config_load 'test.conf'}{config_load 'test2.conf'}{foreach #overwrite# as $over}{$over} {/foreach}

View File

@@ -0,0 +1 @@
{config_load 'test.conf'}{if #booleanon# === $expected}passed{/if}

View File

@@ -0,0 +1 @@
{config_load 'test_error.conf'}