This commit is contained in:
Uwe Tews
2015-05-04 03:07:10 +02:00
parent 0dea9f271c
commit fe8598515f
7 changed files with 356 additions and 84 deletions

View File

@@ -67,4 +67,14 @@ class DelimiterTest extends PHPUnit_Smarty
$this->assertEquals("hello world", $this->smarty->fetch($tpl)); $this->assertEquals("hello world", $this->smarty->fetch($tpl));
} }
/**
* test {= =} delimiter for conficts with option flags
*/
public function testDelimiter5()
{
$this->smarty->left_delimiter = '{=';
$this->smarty->right_delimiter = '=}';
$tpl = $this->smarty->createTemplate('eval:{=assign var=foo value="hello world" nocache=}{=$foo=}');
$this->assertEquals("hello world", $this->smarty->fetch($tpl));
}
} }

View File

@@ -235,6 +235,80 @@ class FileResourceTest extends PHPUnit_Smarty
$this->fail('Exception for unknown relative filepath has not been raised.'); $this->fail('Exception for unknown relative filepath has not been raised.');
} }
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testRelativeFetch()
{
$this->smarty->setTemplateDir(array(
dirname(__FILE__) . '/does-not-exist/',
dirname(__FILE__) . '/templates/sub/',
));
$this->smarty->security_policy = null;
$this->assertEquals('hello world', $this->smarty->fetch('./relative.tpl'));
}
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testRelativeFetch2()
{
$this->smarty->setTemplateDir(array(
dirname(__FILE__) . '/does-not-exist/',
dirname(__FILE__) . '/templates/sub/',
));
$this->smarty->security_policy = null;
$this->assertEquals('hello world', $this->smarty->fetch('../helloworld.tpl'));
}
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testRelativeFetchCwd()
{
$cwd = getcwd();
chdir(dirname(__FILE__) . '/templates/sub/');
$dn = dirname(__FILE__);
$this->smarty->setCompileDir($dn . '/templates_c/');
$this->smarty->setCacheDir($dn . '/cache/');
$this->smarty->setTemplateDir(array(
dirname(__FILE__) . '/does-not-exist/',
));
$this->smarty->security_policy = null;
$this->assertEquals('hello world', $this->smarty->fetch('./relative.tpl'));
chdir($cwd);
}
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testRelativeFetchCwd2()
{
$cwd = getcwd();
chdir(dirname(__FILE__) . '/templates/sub/');
$dn = dirname(__FILE__);
$this->smarty->setCompileDir($dn . '/templates_c/');
$this->smarty->setCacheDir($dn . '/cache/');
$this->smarty->setTemplateDir(array(
dirname(__FILE__) . '/does-not-exist/',
));
$this->smarty->security_policy = null;
$this->assertEquals('hello world', $this->smarty->fetch('../helloworld.tpl'));
chdir($cwd);
}
protected function _relativeMap($map, $cwd = null) protected function _relativeMap($map, $cwd = null)
{ {
foreach ($map as $file => $result) { foreach ($map as $file => $result) {
@@ -274,4 +348,203 @@ class FileResourceTest extends PHPUnit_Smarty
chdir($cwd); chdir($cwd);
} }
} }
public function testRelativity()
{
$this->smarty->security_policy = null;
$cwd = getcwd();
$dn = dirname(__FILE__);
$this->smarty->setCompileDir($dn . '/templates_c/');
$this->smarty->setCacheDir($dn . '/cache/');
$this->smarty->setTemplateDir(array(
$dn . '/templates/relativity/theory/',
));
$map = array(
'foo.tpl' => 'theory',
'./foo.tpl' => 'theory',
'././foo.tpl' => 'theory',
'../foo.tpl' => 'relativity',
'.././foo.tpl' => 'relativity',
'./../foo.tpl' => 'relativity',
'einstein/foo.tpl' => 'einstein',
'./einstein/foo.tpl' => 'einstein',
'../theory/einstein/foo.tpl' => 'einstein',
'templates/relativity/relativity.tpl' => 'relativity',
'./templates/relativity/relativity.tpl' => 'relativity',
);
$this->_relativeMap($map);
$this->smarty->setTemplateDir(array(
'templates/relativity/theory/',
));
$map = array(
'foo.tpl' => 'theory',
'./foo.tpl' => 'theory',
'././foo.tpl' => 'theory',
'../foo.tpl' => 'relativity',
'.././foo.tpl' => 'relativity',
'./../foo.tpl' => 'relativity',
'einstein/foo.tpl' => 'einstein',
'./einstein/foo.tpl' => 'einstein',
'../theory/einstein/foo.tpl' => 'einstein',
'templates/relativity/relativity.tpl' => 'relativity',
'./templates/relativity/relativity.tpl' => 'relativity',
);
$this->_relativeMap($map);
}
public function testRelativityCwd()
{
$this->smarty->security_policy = null;
$cwd = getcwd();
$dn = dirname(__FILE__);
$this->smarty->setCompileDir($dn . '/templates_c/');
$this->smarty->setCacheDir($dn . '/cache/');
$this->smarty->setTemplateDir(array(
$dn . '/templates/',
));
chdir($dn . '/templates/relativity/theory/');
$map = array(
'foo.tpl' => 'theory',
'./foo.tpl' => 'theory',
'././foo.tpl' => 'theory',
'../foo.tpl' => 'relativity',
'.././foo.tpl' => 'relativity',
'./../foo.tpl' => 'relativity',
'einstein/foo.tpl' => 'einstein',
'./einstein/foo.tpl' => 'einstein',
'../theory/einstein/foo.tpl' => 'einstein',
);
$this->_relativeMap($map, $cwd);
}
public function testRelativityPrecedence()
{
$this->smarty->security_policy = null;
$cwd = getcwd();
$dn = dirname(__FILE__);
$this->smarty->setCompileDir($dn . '/templates_c/');
$this->smarty->setCacheDir($dn . '/cache/');
$this->smarty->setTemplateDir(array(
$dn . '/templates/relativity/theory/einstein/',
));
$map = array(
'foo.tpl' => 'einstein',
'./foo.tpl' => 'einstein',
'././foo.tpl' => 'einstein',
'../foo.tpl' => 'theory',
'.././foo.tpl' => 'theory',
'./../foo.tpl' => 'theory',
'../../foo.tpl' => 'relativity',
);
chdir($dn . '/templates/relativity/theory/');
$this->_relativeMap($map, $cwd);
$map = array(
'../theory.tpl' => 'theory',
'./theory.tpl' => 'theory',
'../../relativity.tpl' => 'relativity',
'../relativity.tpl' => 'relativity',
'./einstein.tpl' => 'einstein',
'einstein/einstein.tpl' => 'einstein',
'./einstein/einstein.tpl' => 'einstein',
);
chdir($dn . '/templates/relativity/theory/');
$this->_relativeMap($map, $cwd);
}
public function testRelativityRelRel()
{
$this->smarty->security_policy = null;
$cwd = getcwd();
$dn = dirname(__FILE__);
$this->smarty->setCompileDir($dn . '/templates_c/');
$this->smarty->setCacheDir($dn . '/cache/');
$this->smarty->setTemplateDir(array(
'../..',
));
$map = array(
'foo.tpl' => 'relativity',
'./foo.tpl' => 'relativity',
'././foo.tpl' => 'relativity',
);
chdir($dn . '/templates/relativity/theory/einstein');
$this->_relativeMap($map, $cwd);
$map = array(
'relativity.tpl' => 'relativity',
'./relativity.tpl' => 'relativity',
'theory/theory.tpl' => 'theory',
'./theory/theory.tpl' => 'theory',
);
chdir($dn . '/templates/relativity/theory/einstein/');
$this->_relativeMap($map, $cwd);
$map = array(
'foo.tpl' => 'theory',
'./foo.tpl' => 'theory',
'theory.tpl' => 'theory',
'./theory.tpl' => 'theory',
'einstein/einstein.tpl' => 'einstein',
'./einstein/einstein.tpl' => 'einstein',
'../theory/einstein/einstein.tpl' => 'einstein',
'../relativity.tpl' => 'relativity',
'./../relativity.tpl' => 'relativity',
'.././relativity.tpl' => 'relativity',
);
$this->smarty->setTemplateDir(array(
'..',
));
chdir($dn . '/templates/relativity/theory/einstein/');
$this->_relativeMap($map, $cwd);
}
public function testRelativityRelRel1()
{
$this->smarty->security_policy = null;
$cwd = getcwd();
$dn = dirname(__FILE__);
$this->smarty->setCompileDir($dn . '/templates_c/');
$this->smarty->setCacheDir($dn . '/cache/');
$this->smarty->setTemplateDir(array(
'..',
));
$map = array(
'foo.tpl' => 'theory',
'./foo.tpl' => 'theory',
'theory.tpl' => 'theory',
'./theory.tpl' => 'theory',
'einstein/einstein.tpl' => 'einstein',
'./einstein/einstein.tpl' => 'einstein',
'../theory/einstein/einstein.tpl' => 'einstein',
'../relativity.tpl' => 'relativity',
'./../relativity.tpl' => 'relativity',
'.././relativity.tpl' => 'relativity',
);
chdir($dn . '/templates/relativity/theory/einstein/');
$this->_relativeMap($map, $cwd);
}
} }

View File

@@ -202,6 +202,17 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
$this->assertNotContains('should be hidden', $result); $this->assertNotContains('should be hidden', $result);
} }
/**
* test nested child block with hide and auto_literal = false
*/
public function testCompileBlockChildNestedHideAutoLiteralFalse_019()
{
$this->smarty->setAutoLiteral(false);
$result = $this->smarty->fetch('019_child_nested_hide_autoliteral.tpl');
$this->assertContains('nested block', $result);
$this->assertNotContains('should be hidden', $result);
}
/** /**
* test child/parent template chain starting in subtempates * test child/parent template chain starting in subtempates
*/ */
@@ -321,7 +332,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
/** /**
* @expectedException SmartyCompilerException * @expectedException SmartyCompilerException
* @expectedExceptionMessage Syntax Error in template ".\templates\025_parent.tpl" * @expectedExceptionMessage Syntax Error in template ".\templates\025_parent.tpl"
* @expectedExceptionMessage {$smarty.block.child} used out of context * @expectedExceptionMessage {$smarty.block.child} used out of context
* test {$this->smarty.block.child} outside {block] * test {$this->smarty.block.child} outside {block]
*/ */
@@ -332,7 +343,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
/** /**
* @expectedException SmartyCompilerException * @expectedException SmartyCompilerException
* @expectedExceptionMessage Syntax Error in template ".\templates\026_parent.tpl" * @expectedExceptionMessage Syntax Error in template ".\templates\026_parent.tpl"
* @expectedExceptionMessage $smarty.block is invalid * @expectedExceptionMessage $smarty.block is invalid
* test {$this->smarty.block.parent} outside {block] * test {$this->smarty.block.parent} outside {block]
*/ */
@@ -343,7 +354,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
/** /**
* @expectedException SmartyCompilerException * @expectedException SmartyCompilerException
* @expectedExceptionMessage Syntax Error in template ".\templates\027_parent.tpl" * @expectedExceptionMessage Syntax Error in template ".\templates\027_parent.tpl"
* @expectedExceptionMessage $smarty.block is invalid * @expectedExceptionMessage $smarty.block is invalid
* test {$this->smarty.block.parent} in parent template * test {$this->smarty.block.parent} in parent template
*/ */

View File

@@ -23,67 +23,48 @@ class AttributeTest extends PHPUnit_Smarty
{ {
$this->cleanDirs(); $this->cleanDirs();
} }
/** /**
* @expectedException SmartyCompilerException
* @expectedExceptionMessage Syntax Error in template "b8ecd121bbbc031241b1116a9db691a759eceadf"
* @expectedExceptionMessage missing "var" attribute
* test required attribute * test required attribute
*/ */
public function testRequiredAttributeVar() public function testRequiredAttributeVar()
{ {
try {
$this->smarty->fetch('string:{assign value=1}'); $this->smarty->fetch('string:{assign value=1}');
} }
catch (Exception $e) {
$this->assertContains('missing "var" attribute', $e->getMessage());
return;
}
$this->fail('Exception for required attribute "var" has not been raised.');
}
/** /**
* @expectedException SmartyCompilerException
* @expectedExceptionMessage Syntax Error in template "46d3649920e0043f055702ef3ceef0ecdc44b892"
* @expectedExceptionMessage unexpected "bar" attribute
* test unexpected attribute * test unexpected attribute
*/ */
public function testUnexpectedAttribute() public function testUnexpectedAttribute()
{ {
try {
$this->smarty->fetch('string:{assign var=foo value=1 bar=2}'); $this->smarty->fetch('string:{assign var=foo value=1 bar=2}');
} }
catch (Exception $e) {
$this->assertContains('unexpected "bar" attribute', $e->getMessage());
return;
}
$this->fail('Exception for unexpected attribute "bar" has not been raised.');
}
/** /**
* @expectedException SmartyCompilerException
* @expectedExceptionMessage Syntax Error in template "d6c824b50e89d8fe12b393ae8ab68daeb7b6c240"
* @expectedExceptionMessage illegal value of option flag "nocache"
* test illegal option value * test illegal option value
*/ */
public function testIllegalOptionValue() public function testIllegalOptionValue()
{ {
try {
$this->smarty->fetch('string:{assign var=foo value=1 nocache=buh}'); $this->smarty->fetch('string:{assign var=foo value=1 nocache=buh}');
} }
catch (Exception $e) {
$this->assertContains(htmlentities('illegal value of option flag'), $e->getMessage());
return;
}
$this->fail('Exception for illegal value of option flag has not been raised.');
}
/** /**
* @expectedException SmartyCompilerException
* @expectedExceptionMessage Syntax Error in template "a119616ffa139e7b1145b1cd36adbff7bc9be7cf"
* @expectedExceptionMessage too many shorthand attributes
* test too many shorthands * test too many shorthands
*/ */
public function testTooManyShorthands() public function testTooManyShorthands()
{ {
try {
$this->smarty->fetch('string:{assign foo 1 2}'); $this->smarty->fetch('string:{assign foo 1 2}');
} }
catch (Exception $e) {
$this->assertContains('too many shorthand attributes', $e->getMessage());
return;
}
$this->fail('Exception for too many shorthand attributes has not been raised.');
}
} }

View File

@@ -24,57 +24,40 @@ class CompileErrorTest extends PHPUnit_Smarty
} }
/** /**
* @expectedException SmartyException
* @expectedExceptionMessage Unable to load template file 'no.tpl' in 'eval:{include file='no.tpl'}'
* test none existing template file error * test none existing template file error
*/ */
public function testNoneExistingTemplateError() public function testNoneExistingTemplateError()
{ {
try {
$this->smarty->fetch('eval:{include file=\'no.tpl\'}'); $this->smarty->fetch('eval:{include file=\'no.tpl\'}');
} }
catch (Exception $e) {
$this->assertContains('Unable to load template', $e->getMessage());
return;
}
$this->fail('Exception for none existing template has not been raised.');
}
/**
* test unkown tag error
*/
public function testUnknownTagError()
{
try {
$this->smarty->fetch('eval:{unknown}');
}
catch (Exception $e) {
$this->assertContains('unknown tag "unknown"', $e->getMessage());
return;
}
$this->fail('Exception for unknown Smarty tag has not been raised.');
}
/**
* test unclosed tag error
*/
public function testUnclosedTagError()
{
try {
$this->smarty->fetch('eval:{if true}');
}
catch (Exception $e) {
$this->assertContains('unclosed {if} tag', $e->getMessage());
return;
}
$this->fail('Exception for unclosed Smarty tags has not been raised.');
}
/** /**
* @expectedException SmartyCompilerException * @expectedException SmartyCompilerException
* @expectedExceptionMessage Syntax Error in template "599a9cf0e3623a3206bd02a0f5c151d5f5f3f69e" * @expectedExceptionMessage Syntax Error in template "2510bcd51cbc69725f2c3d3484b2c70c00ddaeba"
* @expectedExceptionMessage Unexpected "}" * @expectedExceptionMessage unknown tag "unknown"
* test unkown tag error
*/
public function testUnknownTagError()
{
$this->smarty->fetch('eval:{unknown}');
}
/**
* @expectedException SmartyCompilerException
* @expectedExceptionMessage unclosed {if} tag
* test unclosed tag error
*/
public function testUnclosedTagError()
{
$this->smarty->fetch('eval:{if true}');
}
/**
* @expectedException SmartyCompilerException
* @expectedExceptionMessage Syntax Error in template "599a9cf0e3623a3206bd02a0f5c151d5f5f3f69e"
* @expectedExceptionMessage Unexpected "}"
* test syntax error * test syntax error
*/ */
public function testSyntaxError() public function testSyntaxError()

View File

@@ -166,8 +166,8 @@ class ModifierTest extends PHPUnit_Smarty
/** /**
* @expectedException SmartyCompilerException * @expectedException SmartyCompilerException
* @expectedExceptionMessage Syntax Error in template "4d2e368c483a648d14bbd59592da92aff3b96a2f" * @expectedExceptionMessage Syntax Error in template "4d2e368c483a648d14bbd59592da92aff3b96a2f"
* @expectedExceptionMessage unknown modifier "unknown" * @expectedExceptionMessage unknown modifier "unknown"
* test unknown modifier error * test unknown modifier error
*/ */
public function testUnknownModifier() public function testUnknownModifier()

View File

@@ -71,6 +71,20 @@ class DefaultPluginHandlerTest extends PHPUnit_Smarty
$this->smarty->assign('foo', 'bar'); $this->smarty->assign('foo', 'bar');
$this->assertEquals("localmodifier bar", $this->smarty->fetch('test_default_modifier.tpl')); $this->assertEquals("localmodifier bar", $this->smarty->fetch('test_default_modifier.tpl'));
} }
public function testDefaultModifierStaticClassMethodCaching1()
{
$this->smarty->assign('foo', 'bar');
$this->smarty->caching = 1;
$this->assertEquals("staticmodifier bar", $this->smarty->fetch('test_default_static_modifier.tpl'));
}
public function testDefaultModifierStaticClassMethodCaching2()
{
$this->smarty->assign('foo', 'bar');
$this->smarty->caching = 1;
$this->assertEquals("staticmodifier bar", $this->smarty->fetch('test_default_static_modifier.tpl'));
}
} }
function my_plugin_handler($tag, $type, $template, &$callback, &$script, &$cachable) function my_plugin_handler($tag, $type, $template, &$callback, &$script, &$cachable)