mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Done accessor
This commit is contained in:
@ -161,13 +161,13 @@ class TestCase extends \PHPUnit_Framework_TestCase
|
||||
$this->fail("Code $code must be invalid");
|
||||
}
|
||||
|
||||
public function assertRender($tpl, $result, $debug = false)
|
||||
public function assertRender($tpl, $result, array $vars = array(), $debug = false)
|
||||
{
|
||||
$template = $this->fenom->compileCode($tpl);
|
||||
if ($debug) {
|
||||
print_r("\nDEBUG $tpl:\n" . $template->getBody());
|
||||
}
|
||||
$this->assertSame($result, $template->fetch($this->values));
|
||||
$this->assertSame($result, $template->fetch($vars + $this->values));
|
||||
return $template;
|
||||
}
|
||||
|
||||
|
@ -97,8 +97,23 @@ class AccessorTest extends TestCase
|
||||
public static function providerPHP() {
|
||||
return array(
|
||||
array('$.php.strrev("string")', strrev("string")),
|
||||
array('$.php.strrev("string")', strrev("string"), 'str*'),
|
||||
array('$.php.strrev("string")', strrev("string"), 'strrev'),
|
||||
array('$.php.get_current_user', get_current_user()),
|
||||
array('$.php.Fenom.helper_func("string", 12)', helper_func("string", 12)),
|
||||
array('$.php.Fenom.helper_func("string", 12)', helper_func("string", 12), 'Fenom\\*'),
|
||||
array('$.php.Fenom.helper_func("string", 12)', helper_func("string", 12), 'Fenom\helper_func'),
|
||||
array('$.php.Fenom.helper_func("string", 12)', helper_func("string", 12), '*helper_func'),
|
||||
array('$.php.Fenom.helper_func("string", 12)', helper_func("string", 12), '*'),
|
||||
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string")),
|
||||
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\*'),
|
||||
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\TestCase*'),
|
||||
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\TestCase::*'),
|
||||
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\*::dots'),
|
||||
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\*::*'),
|
||||
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\TestCase::dots'),
|
||||
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), '*::dots'),
|
||||
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), '*'),
|
||||
);
|
||||
}
|
||||
|
||||
@ -106,10 +121,45 @@ class AccessorTest extends TestCase
|
||||
* @dataProvider providerPHP
|
||||
* @group php
|
||||
*/
|
||||
public function testPHP($tpl, $result) {
|
||||
public function testPHP($tpl, $result, $mask = null) {
|
||||
if($mask) {
|
||||
$this->fenom->addCallFilter($mask);
|
||||
}
|
||||
$this->assertRender('{'.$tpl.'}', $result);
|
||||
}
|
||||
|
||||
public static function providerPHPInvalid() {
|
||||
return array(
|
||||
array('$.php.aaa("string")', 'Fenom\Error\CompileException', 'PHP method aaa does not exists'),
|
||||
array('$.php.strrev("string")', 'Fenom\Error\SecurityException', 'Callback strrev is not available by settings', 'strrevZ'),
|
||||
array('$.php.strrev("string")', 'Fenom\Error\SecurityException', 'Callback strrev is not available by settings', 'str*Z'),
|
||||
array('$.php.strrev("string")', 'Fenom\Error\SecurityException', 'Callback strrev is not available by settings', '*Z'),
|
||||
array('$.php.Fenom.aaa("string")', 'Fenom\Error\CompileException', 'PHP method Fenom.aaa does not exists'),
|
||||
array('$.php.Fenom.helper_func("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.helper_func is not available by settings', 'Reflection\*'),
|
||||
array('$.php.Fenom.helper_func("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.helper_func is not available by settings', 'Fenom\*Z'),
|
||||
array('$.php.Fenom.helper_func("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.helper_func is not available by settings', 'Fenom\*::*'),
|
||||
array('$.php.TestCase::aaa("string")', 'Fenom\Error\CompileException', 'PHP method TestCase::aaa does not exists'),
|
||||
array('$.php.Fenom.TestCase::aaa("string")', 'Fenom\Error\CompileException', 'PHP method Fenom.TestCase::aaa does not exists'),
|
||||
array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Reflection\*'),
|
||||
array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\*Z'),
|
||||
array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\*::get*'),
|
||||
array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\TestCase::get*'),
|
||||
array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\TestCase::*Z'),
|
||||
array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', '*::*Z'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerPHPInvalid
|
||||
* @group php
|
||||
*/
|
||||
public function testPHPInvalid($tpl, $exception, $message, $methods = null) {
|
||||
if($methods) {
|
||||
$this->fenom->addCallFilter($methods);
|
||||
}
|
||||
$this->execError('{'.$tpl.'}', $exception, $message);
|
||||
}
|
||||
|
||||
|
||||
public static function providerAccessor()
|
||||
{
|
||||
@ -133,7 +183,6 @@ class AccessorTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public static function providerAccessorInvalid()
|
||||
{
|
||||
return array(
|
||||
@ -141,4 +190,41 @@ class AccessorTest extends TestCase
|
||||
array('{$.get.one}', 'Fenom\Error\SecurityException', 'Accessor are disabled', \Fenom::DENY_ACCESSOR),
|
||||
);
|
||||
}
|
||||
|
||||
public static function providerFetch()
|
||||
{
|
||||
return array(
|
||||
array('{$.fetch("welcome.tpl")}'),
|
||||
array('{set $tpl = "welcome.tpl"}{$.fetch($tpl)}'),
|
||||
array('{$.fetch("welcome.tpl", ["username" => "Bzick", "email" => "bzick@dev.null"])}'),
|
||||
array('{set $tpl = "welcome.tpl"}{$.fetch($tpl, ["username" => "Bzick", "email" => "bzick@dev.null"])}'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group fetch
|
||||
* @dataProvider providerFetch
|
||||
*/
|
||||
public function testFetch($code)
|
||||
{
|
||||
$this->tpl('welcome.tpl', '<b>Welcome, {$username} ({$email})</b>');
|
||||
$values = array('username' => 'Bzick', 'email' => 'bzick@dev.null');
|
||||
$this->assertRender($code, $this->fenom->fetch('welcome.tpl', $values), $values);
|
||||
}
|
||||
|
||||
public static function providerFetchInvalid()
|
||||
{
|
||||
return array(
|
||||
array('{$.fetch("welcome_.tpl")}', 'Fenom\Error\CompileException', "Template welcome_.tpl not found"),
|
||||
array('{$.fetch("welcome_.tpl", [])}', 'Fenom\Error\CompileException', "Template welcome_.tpl not found"),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group fetchInvalid
|
||||
* @dataProvider providerFetchInvalid
|
||||
*/
|
||||
public function testFetchInvalidTpl($tpl, $exception, $message) {
|
||||
$this->execError($tpl, $exception, $message);
|
||||
}
|
||||
}
|
29
tests/cases/Fenom/SandboxTest.php
Normal file
29
tests/cases/Fenom/SandboxTest.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Fenom;
|
||||
|
||||
|
||||
class SandboxTest extends TestCase {
|
||||
|
||||
public function test()
|
||||
{
|
||||
|
||||
|
||||
// $this->assertEquals([1, 2, 4, "as" => 767, "df" => ["qert"]], [1, 2, 4, "as" => 767, "df" => ["qet"]]);
|
||||
// $this->fenom->addBlockCompiler('php', 'Fenom\Compiler::nope', function ($tokens, Tag $tag) {
|
||||
// return '<?php ' . $tag->cutContent();
|
||||
// });
|
||||
// $this->tpl('welcome.tpl', '{$a}');
|
||||
// try {
|
||||
// var_dump($this->fenom->compileCode('{$.fetch("welcome.tpl", ["a" => 1])}')->getBody());
|
||||
// } catch (\Exception $e) {
|
||||
// print_r($e->getMessage() . "\n" . $e->getTraceAsString());
|
||||
// while ($e->getPrevious()) {
|
||||
// $e = $e->getPrevious();
|
||||
// print_r("\n\n" . $e->getMessage() . " in {$e->getFile()}:{$e->getLine()}\n" . $e->getTraceAsString());
|
||||
// }
|
||||
// }
|
||||
// exit;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user