mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Remove {unser} and add tests
This commit is contained in:
@@ -209,6 +209,7 @@ class TemplateTest extends TestCase
|
||||
array('If: {$a != 5 => 4} end', 'Fenom\Error\CompileException', "Unexpected token '=>'"),
|
||||
array('If: {$a + (*6)} end', 'Fenom\Error\CompileException', "Unexpected token '*'"),
|
||||
array('If: {$a + ( 6} end', 'Fenom\Error\CompileException', "Unexpected end of expression, expect ')'"),
|
||||
array('If: {$a end', 'Fenom\Error\CompileException', "Unclosed tag in line"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -684,6 +685,7 @@ class TemplateTest extends TestCase
|
||||
array('{if null is set} block1 {else} block2 {/if}', 'block2'),
|
||||
array('{if 0 is empty} block1 {else} block2 {/if}', 'block1'),
|
||||
array('{if "" is empty} block1 {else} block2 {/if}', 'block1'),
|
||||
array('{if [] is empty} block1 {else} block2 {/if}', 'block1'),
|
||||
array('{if "data" is empty} block1 {else} block2 {/if}', 'block2'),
|
||||
array('{if time() is not empty} block1 {else} block2 {/if}', 'block1'),
|
||||
// is empty
|
||||
@@ -700,8 +702,10 @@ class TemplateTest extends TestCase
|
||||
// event, odd
|
||||
array('{if $one is odd} block1 {else} block2 {/if}', 'block1'),
|
||||
array('{if $one is even} block1 {else} block2 {/if}', 'block2'),
|
||||
array('{if ($one + 1) is even} block1 {else} block2 {/if}', 'block1'),
|
||||
array('{if $two is even} block1 {else} block2 {/if}', 'block1'),
|
||||
array('{if $two is odd} block1 {else} block2 {/if}', 'block2'),
|
||||
array('{if ($two+1) is odd} block1 {else} block2 {/if}', 'block1'),
|
||||
// template
|
||||
array('{if "welcome.tpl" is template} block1 {else} block2 {/if}', 'block1'),
|
||||
array('{if "welcome2.tpl" is template} block1 {else} block2 {/if}', 'block2'),
|
||||
@@ -754,13 +758,19 @@ class TemplateTest extends TestCase
|
||||
array('{$.get.one?}', '1'),
|
||||
array('{$.get.one is set}', '1'),
|
||||
array('{$.get.two is empty}', '1'),
|
||||
|
||||
array('{$.version}', Fenom::VERSION),
|
||||
array('{$.tpl?}', '1'),
|
||||
array('{$.tpl.name}', 'runtime.tpl'),
|
||||
array('{$.tpl.time}', '0'),
|
||||
array('{$.tpl.schema}', ''),
|
||||
);
|
||||
}
|
||||
|
||||
public function _testSandbox()
|
||||
{
|
||||
try {
|
||||
var_dump($this->fenom->setOptions(Fenom::FORCE_VERIFY)->compileCode('{if $unexist} block1 {else} block2 {/if}')->getBody());
|
||||
var_dump($this->fenom->setOptions(Fenom::FORCE_VERIFY)->addFilter(function ($txt) {return $txt;})->compileCode('- <?php {$a} ?> -')->fetch(['a' => 1]));
|
||||
} catch (\Exception $e) {
|
||||
print_r($e->getMessage() . "\n" . $e->getTraceAsString());
|
||||
}
|
||||
@@ -840,7 +850,10 @@ class TemplateTest extends TestCase
|
||||
public function testInsert($code, $vars, $result)
|
||||
{
|
||||
$this->values = $vars;
|
||||
$tpl = $this->assertRender($code, $result);
|
||||
$this->tpl("insert.tpl", $code);
|
||||
$tpl = $this->fenom->getTemplate('insert.tpl');
|
||||
$this->assertSame($result, $tpl->fetch($vars));
|
||||
$this->assertTrue($tpl->isValid());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace Fenom;
|
||||
use Fenom\Error\UnexpectedTokenException;
|
||||
use Fenom\Tokenizer;
|
||||
|
||||
class TokenizerTest extends \PHPUnit_Framework_TestCase
|
||||
@@ -35,6 +36,7 @@ class TokenizerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertSame("sin", $tokens->getNext($tokens::MACRO_STRING));
|
||||
$this->assertSame("sin", $tokens->current());
|
||||
$this->assertTrue($tokens->isPrev(":"));
|
||||
$this->assertSame(T_STRING, $tokens->key());
|
||||
$this->assertTrue($tokens->is(T_STRING));
|
||||
$this->assertTrue($tokens->is($tokens::MACRO_STRING));
|
||||
@@ -46,6 +48,9 @@ class TokenizerTest extends \PHPUnit_Framework_TestCase
|
||||
$tokens->next();
|
||||
$tokens->next();
|
||||
$this->assertSame("+", $tokens->getNext($tokens::MACRO_BINARY));
|
||||
|
||||
$this->assertSame($code, $tokens->getSnippetAsString(-100, 100));
|
||||
$this->assertSame('+', $tokens->getSnippetAsString(100, -100));
|
||||
}
|
||||
|
||||
public function testSkip()
|
||||
@@ -65,4 +70,5 @@ class TokenizerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(T_LNUMBER, $tokens->key());
|
||||
$tokens->next();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,17 @@ class FenomTest extends \Fenom\TestCase
|
||||
$fenom->clearAllCompiles();
|
||||
}
|
||||
|
||||
public function testFactory() {
|
||||
$time = $this->tpl('temp.tpl', 'Template 1 a');
|
||||
$fenom = Fenom::factory($provider = new \Fenom\Provider(FENOM_RESOURCES . '/template'), FENOM_RESOURCES . '/compile', Fenom::AUTO_ESCAPE);
|
||||
$this->assertInstanceOf('Fenom\Template', $tpl = $fenom->getTemplate('temp.tpl'));
|
||||
$this->assertSame($provider, $tpl->getProvider());
|
||||
$this->assertSame('temp.tpl', $tpl->getBaseName());
|
||||
$this->assertSame('temp.tpl', $tpl->getName());
|
||||
$this->assertSame($time, $tpl->getTime());
|
||||
$fenom->clearAllCompiles();
|
||||
}
|
||||
|
||||
public function testCompileFile()
|
||||
{
|
||||
$a = array(
|
||||
@@ -148,7 +159,8 @@ class FenomTest extends \Fenom\TestCase
|
||||
return "|--- $text ---|";
|
||||
});
|
||||
|
||||
$this->assertSame('+++ |--- == hello ---||--- world == ---| +++', $this->fenom->compileCode('hello {var $user} god {/var} world')->fetch(array()));
|
||||
$this->assertSame('+++ |--- == hello ---||--- world == ---| +++', $this->fenom->compileCode('hello {var $user} misterio {/var} world')->fetch(array()));
|
||||
$this->assertSame('+++ |--- == hello ---||--- world == ---| +++', $this->fenom->compileCode('hello {var $user} <?php misterio ?> {/var} world')->fetch(array()));
|
||||
}
|
||||
|
||||
public function testAddInlineCompilerSmart() {
|
||||
|
||||
Reference in New Issue
Block a user