mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
update resource tests
This commit is contained in:
@@ -246,7 +246,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty
|
|||||||
$this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result,
|
$this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result,
|
||||||
$testName . ' - fetch() failure');
|
$testName . ' - fetch() failure');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function data(){
|
public function data(){
|
||||||
return array(
|
return array(
|
||||||
/*
|
/*
|
||||||
|
@@ -63,17 +63,17 @@ class FileResourceTest extends PHPUnit_Smarty
|
|||||||
$this->assertFalse($this->smarty->templateExists('notthere.tpl'));
|
$this->assertFalse($this->smarty->templateExists('notthere.tpl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException SmartyException
|
||||||
|
* @expectedExceptionMessage Unable to
|
||||||
|
* @expectedExceptionMessage notthere.tpl
|
||||||
|
*
|
||||||
|
* test not existing file
|
||||||
|
*/
|
||||||
public function testTemplateFileNotExists3()
|
public function testTemplateFileNotExists3()
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
$result = $this->smarty->fetch('notthere.tpl');
|
|
||||||
}
|
|
||||||
catch (Exception $e) {
|
|
||||||
$this->assertContains('Unable to load template file \'notthere.tpl\'', $e->getMessage());
|
|
||||||
|
|
||||||
return;
|
$result = $this->smarty->fetch('notthere.tpl');
|
||||||
}
|
|
||||||
$this->fail('Exception for not existing template is missing');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetTemplateTimestamp()
|
public function testGetTemplateTimestamp()
|
||||||
@@ -209,32 +209,31 @@ class FileResourceTest extends PHPUnit_Smarty
|
|||||||
$result = $this->smarty->fetch('sub/relative.tpl');
|
$result = $this->smarty->fetch('sub/relative.tpl');
|
||||||
$this->assertContains('hello world', $result);
|
$this->assertContains('hello world', $result);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @expectedException SmartyException
|
||||||
|
* @expectedExceptionMessage Unable to
|
||||||
|
* @expectedExceptionMessage notthereh.tpl
|
||||||
|
* @runInSeparateProcess
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
*
|
||||||
|
* test relative include fail
|
||||||
|
*/
|
||||||
public function testRelativeIncludeFail()
|
public function testRelativeIncludeFail()
|
||||||
{
|
{
|
||||||
try {
|
$result = $this->smarty->fetch('relative_sub.tpl');
|
||||||
$this->smarty->fetch('relative_sub.tpl');
|
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
/**
|
||||||
$this->assertContains(htmlentities("Unable to load template"), $e->getMessage());
|
* @expectedException SmartyException
|
||||||
|
* @expectedExceptionMessage ./hello.tpl
|
||||||
return;
|
* @runInSeparateProcess
|
||||||
}
|
* @preserveGlobalState disabled
|
||||||
$this->fail('Exception for unknown relative filepath has not been raised.');
|
*
|
||||||
}
|
* test relative include fail other dir
|
||||||
|
*/
|
||||||
public function testRelativeIncludeFailOtherDir()
|
public function testRelativeIncludeFailOtherDir()
|
||||||
{
|
{
|
||||||
$this->smarty->addTemplateDir('./templates_2');
|
$this->smarty->addTemplateDir('./templates_2');
|
||||||
try {
|
$result = $this->smarty->fetch('relative_notexist.tpl');
|
||||||
$this->smarty->fetch('relative_notexist.tpl');
|
|
||||||
}
|
|
||||||
catch (Exception $e) {
|
|
||||||
$this->assertContains("Unable to load template", $e->getMessage());
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->fail('Exception for unknown relative filepath has not been raised.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -359,25 +358,26 @@ class FileResourceTest extends PHPUnit_Smarty
|
|||||||
$dn = dirname(__FILE__);
|
$dn = dirname(__FILE__);
|
||||||
$this->smarty->setCompileDir($dn . '/templates_c/');
|
$this->smarty->setCompileDir($dn . '/templates_c/');
|
||||||
$this->smarty->setCacheDir($dn . '/cache/');
|
$this->smarty->setCacheDir($dn . '/cache/');
|
||||||
$this->smarty->setTemplateDir(array(
|
$this->smarty->setTemplateDir(array($dn . '/templates/relativity/theory/',));
|
||||||
$dn . '/templates/relativity/theory/',
|
|
||||||
));
|
|
||||||
|
|
||||||
$map = array(
|
$map = array('foo.tpl' => 'theory', './foo.tpl' => 'theory', '././foo.tpl' => 'theory',
|
||||||
'foo.tpl' => 'theory',
|
'.././foo.tpl' => 'relativity', './../foo.tpl' => 'relativity',
|
||||||
'./foo.tpl' => 'theory',
|
'einstein/foo.tpl' => 'einstein', './einstein/foo.tpl' => 'einstein',
|
||||||
'././foo.tpl' => 'theory',
|
'../theory/einstein/foo.tpl' => 'einstein', 'templates/relativity/relativity.tpl' => 'relativity',
|
||||||
'../foo.tpl' => 'relativity',
|
'./templates/relativity/relativity.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->_relativeMap($map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRelativity2()
|
||||||
|
{
|
||||||
|
$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(
|
$this->smarty->setTemplateDir(array(
|
||||||
'./templates/relativity/theory/',
|
'./templates/relativity/theory/',
|
||||||
@@ -438,25 +438,30 @@ class FileResourceTest extends PHPUnit_Smarty
|
|||||||
|
|
||||||
$this->smarty->setCompileDir($dn . '/templates_c/');
|
$this->smarty->setCompileDir($dn . '/templates_c/');
|
||||||
$this->smarty->setCacheDir($dn . '/cache/');
|
$this->smarty->setCacheDir($dn . '/cache/');
|
||||||
$this->smarty->setTemplateDir(array(
|
$this->smarty->setTemplateDir(array($dn . '/templates/relativity/theory/einstein/',));
|
||||||
$dn . '/templates/relativity/theory/einstein/',
|
|
||||||
));
|
|
||||||
|
|
||||||
$map = array(
|
$map = array('foo.tpl' => 'einstein', './foo.tpl' => 'einstein', '././foo.tpl' => 'einstein',
|
||||||
'foo.tpl' => 'einstein',
|
'../foo.tpl' => 'theory', '.././foo.tpl' => 'theory', './../foo.tpl' => 'theory',
|
||||||
'./foo.tpl' => 'einstein',
|
'../../foo.tpl' => 'relativity',);
|
||||||
'././foo.tpl' => 'einstein',
|
|
||||||
'../foo.tpl' => 'theory',
|
|
||||||
'.././foo.tpl' => 'theory',
|
|
||||||
'./../foo.tpl' => 'theory',
|
|
||||||
'../../foo.tpl' => 'relativity',
|
|
||||||
);
|
|
||||||
|
|
||||||
chdir($dn . '/templates/relativity/theory/');
|
chdir($dn . '/templates/relativity/theory/');
|
||||||
|
$this->smarty->setTemplateDir(array($dn . '/templates/relativity/theory/einstein/',));
|
||||||
|
$this->_relativeMap($map, $cwd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRelativityPrecedence2()
|
||||||
|
{
|
||||||
|
$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(
|
$this->smarty->setTemplateDir(array(
|
||||||
$dn . '/templates/relativity/theory/einstein/',
|
$dn . '/templates/relativity/theory/einstein/',
|
||||||
));
|
));
|
||||||
$this->_relativeMap($map, $cwd);
|
|
||||||
|
|
||||||
$map = array(
|
$map = array(
|
||||||
'../theory.tpl' => 'theory',
|
'../theory.tpl' => 'theory',
|
||||||
@@ -484,34 +489,47 @@ class FileResourceTest extends PHPUnit_Smarty
|
|||||||
|
|
||||||
$this->smarty->setCompileDir($dn . '/templates_c/');
|
$this->smarty->setCompileDir($dn . '/templates_c/');
|
||||||
$this->smarty->setCacheDir($dn . '/cache/');
|
$this->smarty->setCacheDir($dn . '/cache/');
|
||||||
$this->smarty->setTemplateDir(array(
|
$this->smarty->setTemplateDir(array('../..',));
|
||||||
'../..',
|
|
||||||
));
|
|
||||||
|
|
||||||
$map = array(
|
$map = array('foo.tpl' => 'relativity', './foo.tpl' => 'relativity', '././foo.tpl' => 'relativity',);
|
||||||
'foo.tpl' => 'relativity',
|
|
||||||
'./foo.tpl' => 'relativity',
|
|
||||||
'././foo.tpl' => 'relativity',
|
|
||||||
);
|
|
||||||
|
|
||||||
chdir($dn . '/templates/relativity/theory/einstein');
|
chdir($dn . '/templates/relativity/theory/einstein');
|
||||||
$this->smarty->setTemplateDir(array(
|
$this->smarty->setTemplateDir(array('../..',));
|
||||||
'../..',
|
|
||||||
));
|
|
||||||
$this->_relativeMap($map, $cwd);
|
$this->_relativeMap($map, $cwd);
|
||||||
|
}
|
||||||
|
|
||||||
$map = array(
|
public function testRelativityRelRel2()
|
||||||
'relativity.tpl' => 'relativity',
|
{
|
||||||
'./relativity.tpl' => 'relativity',
|
$this->smarty->security_policy = null;
|
||||||
'theory/theory.tpl' => 'theory',
|
|
||||||
'./theory/theory.tpl' => 'theory',
|
$cwd = getcwd();
|
||||||
);
|
$dn = dirname(__FILE__);
|
||||||
|
|
||||||
|
$this->smarty->setCompileDir($dn . '/templates_c/');
|
||||||
|
$this->smarty->setCacheDir($dn . '/cache/');
|
||||||
|
$this->smarty->setTemplateDir(array('../..',));
|
||||||
|
|
||||||
|
$map =
|
||||||
|
array('relativity.tpl' => 'relativity', './relativity.tpl' => 'relativity', 'theory/theory.tpl' => 'theory',
|
||||||
|
'./theory/theory.tpl' => 'theory',);
|
||||||
|
|
||||||
chdir($dn . '/templates/relativity/theory/einstein/');
|
chdir($dn . '/templates/relativity/theory/einstein/');
|
||||||
|
$this->smarty->setTemplateDir(array('../..',));
|
||||||
|
$this->_relativeMap($map, $cwd);
|
||||||
|
}
|
||||||
|
public function testRelativityRelRel3()
|
||||||
|
{
|
||||||
|
$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(
|
$this->smarty->setTemplateDir(array(
|
||||||
'../..',
|
'../..',
|
||||||
));
|
));
|
||||||
$this->_relativeMap($map, $cwd);
|
|
||||||
|
|
||||||
$map = array(
|
$map = array(
|
||||||
'foo.tpl' => 'theory',
|
'foo.tpl' => 'theory',
|
||||||
|
@@ -137,19 +137,19 @@ class StreamResourceTest extends PHPUnit_Smarty
|
|||||||
{
|
{
|
||||||
$this->assertFalse($this->smarty->templateExists('global:notthere'));
|
$this->assertFalse($this->smarty->templateExists('global:notthere'));
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @expectedException SmartyException
|
||||||
|
* @expectedExceptionMessage 'global:notthere'
|
||||||
|
* @runInSeparateProcess
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
*
|
||||||
|
* test not existing template
|
||||||
|
*/
|
||||||
|
|
||||||
public function testTemplateStramNotExists3()
|
public function testTemplateStramNotExists3()
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
$result = $this->smarty->fetch('global:notthere');
|
$result = $this->smarty->fetch('global:notthere');
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
|
||||||
$this->assertContains('Unable to load template global \'notthere\'', $e->getMessage());
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->fail('Exception for not existing template is missing');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test writeCachedContent
|
* test writeCachedContent
|
||||||
|
@@ -190,4 +190,9 @@ class StringResourceTest extends PHPUnit_Smarty
|
|||||||
$tpl = $this->smarty->createTemplate('string:base64:eyJmb29iYXIifGVzY2FwZX0=');
|
$tpl = $this->smarty->createTemplate('string:base64:eyJmb29iYXIifGVzY2FwZX0=');
|
||||||
$this->assertEquals('foobar', $tpl->fetch());
|
$this->assertEquals('foobar', $tpl->fetch());
|
||||||
}
|
}
|
||||||
|
public function testClearCompiled()
|
||||||
|
{
|
||||||
|
$this->smarty->fetch('string:string:hello uwe');
|
||||||
|
$this->assertEquals(1, $this->smarty->clearCompiledTemplate('string:'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user