mirror of
https://github.com/smarty-php/smarty.git
synced 2025-10-19 23:45:20 +02:00
124 lines
3.1 KiB
PHP
124 lines
3.1 KiB
PHP
![]() |
<?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'));
|
||
|
}
|
||
|
|
||
|
}
|