2020-04-13 15:30:52 +02:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Smarty PHPunit tests for string resources
|
|
|
|
|
*
|
2023-08-08 00:04:14 +02:00
|
|
|
|
2020-04-13 15:30:52 +02:00
|
|
|
* @author Uwe Tews
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* class for string resource tests
|
|
|
|
|
*
|
2023-08-08 00:04:14 +02:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
2020-04-13 15:30:52 +02:00
|
|
|
*/
|
|
|
|
|
class StringResourceTest extends PHPUnit_Smarty
|
|
|
|
|
{
|
2021-10-13 12:15:17 +02:00
|
|
|
public function setUp(): void
|
2020-04-13 15:30:52 +02:00
|
|
|
{
|
2022-09-27 13:03:34 +03:00
|
|
|
$this->setUpSmarty(__DIR__);
|
2020-04-13 15:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function relative($path)
|
|
|
|
|
{
|
2022-09-27 13:03:34 +03:00
|
|
|
$path = str_replace(__DIR__, '.', $path);
|
2020-04-13 15:30:52 +02:00
|
|
|
if (DIRECTORY_SEPARATOR == "\\") {
|
|
|
|
|
$path = str_replace("\\", "/", $path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* test template string exits
|
|
|
|
|
*/
|
|
|
|
|
public function testTemplateStringExists1()
|
|
|
|
|
{
|
|
|
|
|
$tpl = $this->smarty->createTemplate('string:{$foo}');
|
2023-08-08 00:04:14 +02:00
|
|
|
$this->assertTrue($tpl->getSource()->exists);
|
2020-04-13 15:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testTemplateStringExists2()
|
|
|
|
|
{
|
|
|
|
|
$this->assertTrue($this->smarty->templateExists('string:{$foo}'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* test getTemplateFilepath
|
|
|
|
|
*/
|
|
|
|
|
public function testGetTemplateFilepath()
|
|
|
|
|
{
|
|
|
|
|
$tpl = $this->smarty->createTemplate('string:hello world');
|
2023-08-08 00:04:14 +02:00
|
|
|
$this->assertEquals('hello world', $tpl->getSource()->getResourceName());
|
2020-04-13 15:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* test getTemplateTimestamp
|
|
|
|
|
*/
|
|
|
|
|
public function testGetTemplateTimestamp()
|
|
|
|
|
{
|
|
|
|
|
$tpl = $this->smarty->createTemplate('string:hello world');
|
2023-08-08 00:04:14 +02:00
|
|
|
$this->assertTrue($tpl->getSource()->getTimeStamp());
|
2020-04-13 15:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* test getTemplateSource
|
|
|
|
|
*/
|
|
|
|
|
public function testGetTemplateSource()
|
|
|
|
|
{
|
|
|
|
|
$tpl = $this->smarty->createTemplate('string:hello world{$foo}');
|
2023-08-08 00:04:14 +02:00
|
|
|
$this->assertEquals('hello world{$foo}', $tpl->getSource()->getContent());
|
2020-04-13 15:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* test isEvaluated
|
|
|
|
|
*/
|
|
|
|
|
public function testIsEvaluated()
|
|
|
|
|
{
|
|
|
|
|
$tpl = $this->smarty->createTemplate('string:hello world');
|
2023-08-08 00:04:14 +02:00
|
|
|
$this->assertFalse($tpl->getSource()->handler->recompiled);
|
2020-04-13 15:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* test mustCompile
|
|
|
|
|
*/
|
|
|
|
|
public function testMustCompile()
|
|
|
|
|
{
|
|
|
|
|
$tpl = $this->smarty->createTemplate('string:hello world');
|
|
|
|
|
$this->assertTrue($tpl->mustCompile());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* test getCompiledTimestamp
|
|
|
|
|
*/
|
|
|
|
|
public function testGetCompiledTimestamp()
|
|
|
|
|
{
|
|
|
|
|
$tpl = $this->smarty->createTemplate('string:hello world');
|
2023-08-08 00:04:14 +02:00
|
|
|
$this->assertFalse($tpl->getCompiled()->getTimeStamp());
|
2020-04-13 15:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* test empty templates
|
|
|
|
|
*/
|
|
|
|
|
public function testEmptyTemplate()
|
|
|
|
|
{
|
|
|
|
|
$tpl = $this->smarty->createTemplate('string:');
|
|
|
|
|
$this->assertEquals('', $this->smarty->fetch($tpl));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* test getCachedTimestamp
|
|
|
|
|
*/
|
|
|
|
|
public function testGetCachedTimestamp()
|
|
|
|
|
{
|
|
|
|
|
$tpl = $this->smarty->createTemplate('string:hello world');
|
2023-08-08 00:04:14 +02:00
|
|
|
$this->assertFalse($tpl->getCached()->timestamp);
|
2020-04-13 15:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* test writeCachedContent
|
|
|
|
|
*/
|
|
|
|
|
public function testWriteCachedContent()
|
|
|
|
|
{
|
|
|
|
|
$tpl = $this->smarty->createTemplate('string:hello world');
|
|
|
|
|
$this->assertFalse($tpl->writeCachedContent('dummy'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* test isCached
|
|
|
|
|
*/
|
|
|
|
|
public function testIsCached()
|
|
|
|
|
{
|
|
|
|
|
$tpl = $this->smarty->createTemplate('string:hello world');
|
|
|
|
|
$this->assertFalse($tpl->isCached());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* test getRenderedTemplate
|
|
|
|
|
*/
|
|
|
|
|
public function testGetRenderedTemplate()
|
|
|
|
|
{
|
|
|
|
|
$tpl = $this->smarty->createTemplate('string:hello world');
|
|
|
|
|
$this->assertEquals('hello world', $tpl->fetch());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* test $smarty->is_cached
|
|
|
|
|
*/
|
|
|
|
|
public function testSmartyIsCached()
|
|
|
|
|
{
|
|
|
|
|
$this->smarty->caching = true;
|
|
|
|
|
$this->smarty->cache_lifetime = 20;
|
|
|
|
|
$tpl = $this->smarty->createTemplate('string:hello world');
|
|
|
|
|
$this->assertEquals('hello world', $this->smarty->fetch($tpl));
|
|
|
|
|
$this->assertTrue($this->smarty->isCached($tpl));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testUrlencodeTemplate()
|
|
|
|
|
{
|
|
|
|
|
$tpl = $this->smarty->createTemplate('string:urlencode:%7B%22foobar%22%7Cescape%7D');
|
|
|
|
|
$this->assertEquals('foobar', $tpl->fetch());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testBase64Template()
|
|
|
|
|
{
|
|
|
|
|
$tpl = $this->smarty->createTemplate('string:base64:eyJmb29iYXIifGVzY2FwZX0=');
|
|
|
|
|
$this->assertEquals('foobar', $tpl->fetch());
|
|
|
|
|
}
|
|
|
|
|
public function testClearCompiled()
|
|
|
|
|
{
|
|
|
|
|
$this->smarty->fetch('string:string:hello uwe');
|
|
|
|
|
$this->assertEquals(1, $this->smarty->clearCompiledTemplate('string:'));
|
|
|
|
|
}
|
|
|
|
|
}
|