2023-02-23 22:17:06 +01:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Smarty PHPunit tests for compile check
|
|
|
|
|
*/
|
|
|
|
|
class CompileCheckTest extends PHPUnit_Smarty
|
|
|
|
|
{
|
|
|
|
|
public function setUp(): void
|
|
|
|
|
{
|
|
|
|
|
$this->setUpSmarty(__DIR__);
|
|
|
|
|
$this->cleanDirs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* generate templates
|
|
|
|
|
*/
|
|
|
|
|
protected function makeFiles()
|
|
|
|
|
{
|
2026-04-13 21:36:33 +02:00
|
|
|
$this->makeTemplateFile('t1.tpl', 'TPL1');
|
|
|
|
|
$this->makeTemplateFile('t2.tpl', 'TPL2');
|
|
|
|
|
$this->makeTemplateFile('base.tpl', '{include file="t1.tpl"}{include file="t2.tpl"}');
|
2023-02-23 22:17:06 +01:00
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* remove generated templates
|
|
|
|
|
*/
|
|
|
|
|
protected function removeFiles()
|
|
|
|
|
{
|
2026-04-13 21:36:33 +02:00
|
|
|
$this->removeTemplateFile('t1.tpl');
|
|
|
|
|
$this->removeTemplateFile('t2.tpl');
|
|
|
|
|
$this->removeTemplateFile('base.tpl');
|
2023-02-23 22:17:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* reset, but leave the files alone
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
private function softResetSmarty() {
|
2026-04-13 21:36:33 +02:00
|
|
|
$this->setUpSmarty(__DIR__);
|
2023-02-23 22:17:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group slow
|
|
|
|
|
*/
|
|
|
|
|
public function testCompileCheckOn0()
|
|
|
|
|
{
|
|
|
|
|
$this->makeFiles();
|
|
|
|
|
$this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl'));
|
|
|
|
|
|
|
|
|
|
$this->softResetSmarty();
|
2023-08-08 00:04:14 +02:00
|
|
|
$this->smarty->setCompileCheck(\Smarty\Smarty::COMPILECHECK_ON);
|
2023-02-23 22:17:06 +01:00
|
|
|
|
|
|
|
|
$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();
|
2023-08-08 00:04:14 +02:00
|
|
|
$this->smarty->setCompileCheck(\Smarty\Smarty::COMPILECHECK_ON);
|
2023-02-23 22:17:06 +01:00
|
|
|
|
2026-04-13 21:36:33 +02:00
|
|
|
$this->removeTemplateFile('base.tpl');
|
2023-02-23 22:17:06 +01:00
|
|
|
sleep(1);
|
|
|
|
|
|
2023-08-08 00:04:14 +02:00
|
|
|
$this->expectException(\Smarty\Exception::class);
|
2023-02-23 22:17:06 +01:00
|
|
|
$this->smarty->fetch('base.tpl');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group slow
|
|
|
|
|
*/
|
|
|
|
|
public function testCompileCheckOn2()
|
|
|
|
|
{
|
|
|
|
|
$this->makeFiles();
|
|
|
|
|
$this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl'));
|
|
|
|
|
|
|
|
|
|
$this->softResetSmarty();
|
2023-08-08 00:04:14 +02:00
|
|
|
$this->smarty->setCompileCheck(\Smarty\Smarty::COMPILECHECK_ON);
|
2023-02-23 22:17:06 +01:00
|
|
|
|
|
|
|
|
sleep(1);
|
2026-04-13 21:36:33 +02:00
|
|
|
$this->makeTemplateFile('base.tpl', 'hello');
|
2023-02-23 22:17:06 +01:00
|
|
|
|
|
|
|
|
$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();
|
2023-08-08 00:04:14 +02:00
|
|
|
$this->smarty->setCompileCheck(\Smarty\Smarty::COMPILECHECK_OFF);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group slow
|
|
|
|
|
*/
|
|
|
|
|
public function testCompileCheckOff1()
|
|
|
|
|
{
|
|
|
|
|
$this->makeFiles();
|
|
|
|
|
$this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl'));
|
|
|
|
|
|
|
|
|
|
$this->softResetSmarty();
|
|
|
|
|
$this->smarty->setCompileCheck(\Smarty\Smarty::COMPILECHECK_OFF);
|
|
|
|
|
|
2026-04-13 21:36:33 +02:00
|
|
|
$this->removeTemplateFile('base.tpl');
|
2023-08-08 00:04:14 +02:00
|
|
|
sleep(1);
|
2023-02-23 22:17:06 +01:00
|
|
|
|
|
|
|
|
$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();
|
2023-08-08 00:04:14 +02:00
|
|
|
$this->smarty->setCompileCheck(\Smarty\Smarty::COMPILECHECK_OFF);
|
2023-02-23 22:17:06 +01:00
|
|
|
|
|
|
|
|
sleep(1);
|
2026-04-13 21:36:33 +02:00
|
|
|
$this->makeTemplateFile('base.tpl', 'hello');
|
2023-02-23 22:17:06 +01:00
|
|
|
|
|
|
|
|
$this->assertEquals('TPL1TPL2', $this->smarty->fetch('base.tpl'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|