-
Notifications
You must be signed in to change notification settings - Fork 701
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CompileCheck test and extra note on how it works in docs
- Loading branch information
Showing
2 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
tests/UnitTests/SmartyMethodsTests/CompileCheck/CompileCheckTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')); | ||
} | ||
|
||
} |