CompileCheck test and extra note on how it works in docs

This commit is contained in:
Simon Wisselink
2023-02-23 22:17:06 +01:00
parent 09d26579ce
commit 801d186ea4
2 changed files with 126 additions and 0 deletions

View File

@@ -13,6 +13,9 @@ changing), the compile check step is no longer needed. Be sure to set
change this to FALSE and a template file is changed, you will \*not\* change this to FALSE and a template file is changed, you will \*not\*
see the change since the template will not get recompiled. see the change since the template will not get recompiled.
Note that up to Smarty 4.x, Smarty will check for the existence of
the source template even if `$compile_check` is disabled.
If [`$caching`](#variable.caching) is enabled and `$compile_check` is If [`$caching`](#variable.caching) is enabled and `$compile_check` is
enabled, then the cache files will get regenerated if an involved enabled, then the cache files will get regenerated if an involved
template file or config file was updated. template file or config file was updated.

View File

@@ -0,0 +1,123 @@
<?php
/**
* Smarty PHPunit tests for compile check
*/
class CompileCheckTest extends PHPUnit_Smarty
{
public $methodName = null;
public function setUp(): void
{
$this->setUpSmarty(__DIR__);
$this->smarty->addTemplateDir('./templates_tmp');
$this->cleanDirs();
}
/**
* generate templates
*/
protected function makeFiles()
{
file_put_contents('./templates_tmp/t1.tpl', 'TPL1');
file_put_contents('./templates_tmp/t2.tpl', 'TPL2');
file_put_contents('./templates_tmp/base.tpl', '{include file="t1.tpl"}{include file="t2.tpl"}');
}
/**
* remove generated templates
*/
protected function removeFiles()
{
unlink('./templates_tmp/t1.tpl');
unlink('./templates_tmp/t2.tpl');
unlink('./templates_tmp/base.tpl');
}
/**
* reset, but leave the files alone
* @return void
*/
private function softResetSmarty() {
$this->smarty = new Smarty();
$this->smarty->addTemplateDir('./templates_tmp');
}
/**
* @group slow
*/
public function testCompileCheckOn0()
{
$this->makeFiles();
$this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl'));
$this->softResetSmarty();
$this->smarty->setCompileCheck(Smarty::COMPILECHECK_ON);
$this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl'));
}
/**
* @group slow
*/
public function testCompileCheckOn1()
{
$this->makeFiles();
$this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl'));
$this->softResetSmarty();
$this->smarty->setCompileCheck(Smarty::COMPILECHECK_ON);
unlink('./templates_tmp/base.tpl');
sleep(1);
$this->expectException(Exception::class);
$this->smarty->fetch('base.tpl');
}
/**
* @group slow
*/
public function testCompileCheckOn2()
{
$this->makeFiles();
$this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl'));
$this->softResetSmarty();
$this->smarty->setCompileCheck(Smarty::COMPILECHECK_ON);
sleep(1);
file_put_contents('./templates_tmp/base.tpl', 'hello');
$this->assertEquals('hello', $this->smarty->fetch('base.tpl'));
}
/**
* @group slow
*/
public function testCompileCheckOff0()
{
$this->makeFiles();
$this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl'));
$this->softResetSmarty();
$this->smarty->setCompileCheck(Smarty::COMPILECHECK_OFF);
$this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl'));
}
/**
* @group slow
*/
public function testCompileCheckOff2()
{
$this->makeFiles();
$this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl'));
$this->softResetSmarty();
$this->smarty->setCompileCheck(Smarty::COMPILECHECK_OFF);
sleep(1);
file_put_contents('./templates_tmp/base.tpl', 'hello');
$this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl'));
}
}