2013-01-25 18:36:16 +04:00
< ? php
2013-04-04 10:56:44 +04:00
use Cytro\Render ,
Cytro\FSProvider as FS ;
2013-01-25 18:36:16 +04:00
2013-04-04 10:56:44 +04:00
class CytroTest extends \Cytro\TestCase {
2013-01-25 18:36:16 +04:00
public function testAddRender () {
$test = $this ;
2013-04-04 10:56:44 +04:00
$this -> cytro -> addTemplate ( new Render ( $this -> cytro , function ( $tpl ) use ( $test ) {
2013-01-25 18:36:16 +04:00
/** @var \PHPUnit_Framework_TestCase $test */
2013-04-04 10:56:44 +04:00
$test -> assertInstanceOf ( 'Cytro\Render' , $tpl );
2013-01-25 18:36:16 +04:00
echo " Inline render " ;
2013-02-13 20:51:27 +04:00
}, array (
2013-02-22 00:05:20 +04:00
" name " => 'render.tpl' ,
" scm " => false
2013-02-13 20:51:27 +04:00
)));
2013-01-25 18:36:16 +04:00
2013-04-04 10:56:44 +04:00
$this -> assertSame ( " Inline render " , $this -> cytro -> fetch ( 'render.tpl' , array ()));
2013-01-25 18:36:16 +04:00
}
public function testCompileFile () {
$a = array (
" a " => " a " ,
" b " => " b "
);
2013-02-22 00:05:20 +04:00
$this -> tpl ( 'template1.tpl' , 'Template 1 a' );
$this -> tpl ( 'template2.tpl' , 'Template 2 b' );
2013-04-04 10:56:44 +04:00
$this -> assertSame ( " Template 1 a " , $this -> cytro -> fetch ( 'template1.tpl' , $a ));
$this -> assertSame ( " Template 2 b " , $this -> cytro -> fetch ( 'template2.tpl' , $a ));
$this -> assertInstanceOf ( 'Cytro\Render' , $this -> cytro -> getTemplate ( 'template1.tpl' ));
$this -> assertInstanceOf ( 'Cytro\Render' , $this -> cytro -> getTemplate ( 'template2.tpl' ));
$this -> assertSame ( 3 , iterator_count ( new FilesystemIterator ( CYTRO_RESOURCES . '/compile' )));
2013-01-25 18:36:16 +04:00
}
public function testStorage () {
2013-02-22 00:05:20 +04:00
$this -> tpl ( 'custom.tpl' , 'Custom template' );
2013-04-04 10:56:44 +04:00
$this -> assertSame ( " Custom template " , $this -> cytro -> fetch ( 'custom.tpl' , array ()));
2013-04-28 18:08:57 +04:00
//$this->cytro->clearCompiledTemplate('custom.tpl', false);
2013-01-25 18:36:16 +04:00
2013-04-28 18:08:57 +04:00
//$this->assertSame("Custom template", $this->cytro->fetch('custom.tpl', array()));
2013-01-25 18:36:16 +04:00
2013-02-22 00:05:20 +04:00
$this -> tpl ( 'custom.tpl' , 'Custom template 2' );
2013-04-04 10:56:44 +04:00
$this -> assertSame ( " Custom template " , $this -> cytro -> fetch ( 'custom.tpl' , array ()));
2013-01-25 18:36:16 +04:00
}
public function testCheckMTime () {
2013-04-04 10:56:44 +04:00
$this -> cytro -> setOptions ( Cytro :: FORCE_COMPILE );
2013-02-22 00:05:20 +04:00
$this -> tpl ( 'custom.tpl' , 'Custom template' );
2013-04-04 10:56:44 +04:00
$this -> assertSame ( " Custom template " , $this -> cytro -> fetch ( 'custom.tpl' , array ()));
2013-01-25 18:36:16 +04:00
sleep ( 1 );
2013-02-22 00:05:20 +04:00
$this -> tpl ( 'custom.tpl' , 'Custom template (new)' );
2013-04-04 10:56:44 +04:00
$this -> assertSame ( " Custom template (new) " , $this -> cytro -> fetch ( 'custom.tpl' , array ()));
2013-01-25 18:36:16 +04:00
}
public function testForceCompile () {
2013-04-04 10:56:44 +04:00
$this -> cytro -> setOptions ( Cytro :: FORCE_COMPILE );
2013-02-22 00:05:20 +04:00
$this -> tpl ( 'custom.tpl' , 'Custom template' );
2013-04-04 10:56:44 +04:00
$this -> assertSame ( " Custom template " , $this -> cytro -> fetch ( 'custom.tpl' , array ()));
2013-02-22 00:05:20 +04:00
$this -> tpl ( 'custom.tpl' , 'Custom template (new)' );
2013-04-04 10:56:44 +04:00
$this -> assertSame ( " Custom template (new) " , $this -> cytro -> fetch ( 'custom.tpl' , array ()));
2013-01-25 18:36:16 +04:00
}
public function testSetModifier () {
2013-04-04 10:56:44 +04:00
$this -> cytro -> addModifier ( " mymod " , " myMod " );
2013-02-22 00:05:20 +04:00
$this -> tpl ( 'custom.tpl' , 'Custom modifier {$a|mymod}' );
2013-04-04 10:56:44 +04:00
$this -> assertSame ( " Custom modifier (myMod)Custom(/myMod) " , $this -> cytro -> fetch ( 'custom.tpl' , array ( " a " => " Custom " )));
2013-01-25 18:36:16 +04:00
}
2013-03-14 21:45:00 +04:00
/**
* @ group add_functions
*/
2013-01-25 18:36:16 +04:00
public function testSetFunctions () {
2013-04-04 10:56:44 +04:00
$this -> cytro -> setOptions ( Cytro :: FORCE_COMPILE );
$this -> cytro -> addFunction ( " myfunc " , " myFunc " );
$this -> cytro -> addBlockFunction ( " myblockfunc " , " myBlockFunc " );
2013-02-22 00:05:20 +04:00
$this -> tpl ( 'custom.tpl' , 'Custom function {myfunc name="foo"}' );
2013-04-04 10:56:44 +04:00
$this -> assertSame ( " Custom function MyFunc:foo " , $this -> cytro -> fetch ( 'custom.tpl' , array ()));
2013-02-22 00:05:20 +04:00
$this -> tpl ( 'custom.tpl' , 'Custom function {myblockfunc name="foo"} this block1 {/myblockfunc}' );
2013-04-04 10:56:44 +04:00
$this -> assertSame ( " Custom function Block:foo:this block1:Block " , $this -> cytro -> fetch ( 'custom.tpl' , array ()));
2013-01-25 18:36:16 +04:00
}
public function testSetCompilers () {
2013-04-04 10:56:44 +04:00
$this -> cytro -> setOptions ( Cytro :: FORCE_COMPILE );
$this -> cytro -> addCompiler ( " mycompiler " , 'myCompiler' );
$this -> cytro -> addBlockCompiler ( " myblockcompiler " , 'myBlockCompilerOpen' , 'myBlockCompilerClose' , array (
2013-01-25 18:36:16 +04:00
'tag' => 'myBlockCompilerTag'
));
2013-02-22 00:05:20 +04:00
$this -> tpl ( 'custom.tpl' , 'Custom compiler {mycompiler name="bar"}' );
2013-04-04 10:56:44 +04:00
$this -> assertSame ( " Custom compiler PHP_VERSION: " . PHP_VERSION . " (for bar) " , $this -> cytro -> fetch ( 'custom.tpl' , array ()));
2013-02-22 00:05:20 +04:00
$this -> tpl ( 'custom.tpl' , 'Custom compiler {myblockcompiler name="bar"} block1 {tag name="baz"} block2 {/myblockcompiler}' );
2013-04-04 10:56:44 +04:00
$this -> assertSame ( " Custom compiler PHP_VERSION: " . PHP_VERSION . " (for bar) block1 Tag baz of compiler block2 End of compiler " , $this -> cytro -> fetch ( 'custom.tpl' , array ()));
2013-01-25 18:36:16 +04:00
}
}
?>