mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Final renaming
Upd <extends> tests
This commit is contained in:
parent
897d2e1a97
commit
5d4d218942
@ -12,20 +12,20 @@ echo "Done\n";
|
||||
echo "Testing a lot output...\n";
|
||||
|
||||
Benchmark::runs("smarty3", 'echo/smarty.tpl', __DIR__.'/templates/echo/data.json');
|
||||
Benchmark::runs("twig", 'echo/twig.tpl', __DIR__.'/templates/echo/data.json');
|
||||
Benchmark::runs("aspect", 'echo/smarty.tpl', __DIR__.'/templates/echo/data.json');
|
||||
Benchmark::runs("twig", 'echo/twig.tpl', __DIR__.'/templates/echo/data.json');
|
||||
Benchmark::runs("cytro", 'echo/smarty.tpl', __DIR__.'/templates/echo/data.json');
|
||||
|
||||
echo "\nTesting 'foreach' of big array...\n";
|
||||
|
||||
Benchmark::runs("smarty3", 'foreach/smarty.tpl', __DIR__.'/templates/foreach/data.json');
|
||||
Benchmark::runs("twig", 'foreach/twig.tpl', __DIR__.'/templates/foreach/data.json');
|
||||
Benchmark::runs("aspect", 'foreach/smarty.tpl', __DIR__.'/templates/foreach/data.json');
|
||||
Benchmark::runs("twig", 'foreach/twig.tpl', __DIR__.'/templates/foreach/data.json');
|
||||
Benchmark::runs("cytro", 'foreach/smarty.tpl', __DIR__.'/templates/foreach/data.json');
|
||||
|
||||
echo "\nTesting deep 'inheritance'...\n";
|
||||
|
||||
Benchmark::runs("smarty3", 'inheritance/smarty/b100.tpl', __DIR__.'/templates/foreach/data.json');
|
||||
Benchmark::runs("twig", 'inheritance/twig/b100.tpl', __DIR__.'/templates/foreach/data.json');
|
||||
Benchmark::runs("aspect", 'inheritance/smarty/b100.tpl', __DIR__.'/templates/foreach/data.json');
|
||||
Benchmark::runs("twig", 'inheritance/twig/b100.tpl', __DIR__.'/templates/foreach/data.json');
|
||||
Benchmark::runs("cytro", 'inheritance/smarty/b100.tpl', __DIR__.'/templates/foreach/data.json');
|
||||
|
||||
echo "\nDone. Cleanup.\n";
|
||||
//passthru("rm -rf ".__DIR__."/compile/*");
|
||||
|
@ -43,7 +43,7 @@ class Benchmark {
|
||||
printf(self::$t, __FUNCTION__, $message, round(microtime(true)-$start, 4), round(memory_get_peak_usage()/1024/1024, 2));
|
||||
}
|
||||
|
||||
public static function aspect($tpl, $data, $double, $message) {
|
||||
public static function cytro($tpl, $data, $double, $message) {
|
||||
|
||||
$cytro = Cytro::factory(__DIR__.'/../templates', __DIR__."/../compile/");
|
||||
|
||||
@ -56,9 +56,14 @@ class Benchmark {
|
||||
}
|
||||
|
||||
public static function run($engine, $template, $data, $double, $message) {
|
||||
passthru(sprintf("php -dmemory_limit=512M %s/run.php --engine '%s' --template '%s' --data '%s' --message '%s' %s", __DIR__, $engine, $template, $data, $message, $double ? '--double' : ''));
|
||||
passthru(sprintf("php -dmemory_limit=512M -dxdebug.max_nesting_level=1024 %s/run.php --engine '%s' --template '%s' --data '%s' --message '%s' %s", __DIR__, $engine, $template, $data, $message, $double ? '--double' : ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $engine
|
||||
* @param $template
|
||||
* @param $data
|
||||
*/
|
||||
public static function runs($engine, $template, $data) {
|
||||
self::run($engine, $template, $data, false, '!compiled and !loaded');
|
||||
self::run($engine, $template, $data, false, ' compiled and !loaded');
|
||||
|
@ -3,7 +3,7 @@ Benchmark
|
||||
|
||||
To start benchmark run script `benchmark/run.php`.
|
||||
|
||||
### Smarty3 vs Twig vs Aspect
|
||||
### Smarty3 vs Twig vs Cytro
|
||||
|
||||
Print varaibles
|
||||
|
||||
|
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
namespace Cytro;
|
||||
use Cytro, Cytro\TestCase;
|
||||
use Symfony\Component\Process\Exception\LogicException;
|
||||
|
||||
class ExtendsTemplateTest extends TestCase {
|
||||
|
||||
public static function providerExtends($items) {
|
||||
return array(
|
||||
array("parent.tpl", "Parent. B1: {block b1}{/block}\nB2: {block 'b2'}empty {\$iteration}{/block}", $a,
|
||||
"Parent. B1: \nB2: empty 0"),
|
||||
array("child1.tpl", '{extends "parent.tpl"} {block b1}from child1 {$iteration}{/block} some trash', $a,
|
||||
"Parent. B1: from child1 1\nB2: empty 1"),
|
||||
array("child2.tpl", '{extends "child1.tpl"} {block "b2"}from child2 {$iteration}{/block} some {block b4}what is it?{/block} trash', $a,
|
||||
"Parent. B1: from child1 2\nB2: from child2 2"),
|
||||
array("child3.tpl", '{extends "child2.tpl"} {block \'b1\'}from child3 {$iteration}{/block} {block "b2"}from child3 {$iteration}{/block} some {block b4}what is it?{/block} trash', $a,
|
||||
"Parent. B1: from child3 3\nB2: from child3 3")
|
||||
);
|
||||
}
|
||||
|
||||
public static function providerDynamicExtends() {
|
||||
$data = self::providerExtends();
|
||||
$data[2][1] = str_replace('"b2"', '"b{$two}"', $data[2][1]);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
$this->cytro = Cytro::factory(CYTRO_RESOURCES.'/template', CYTRO_RESOURCES.'/compile');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerExtends
|
||||
* @param $name
|
||||
* @param $code
|
||||
* @param $vars
|
||||
* @param $result
|
||||
*/
|
||||
public function _testStaticExtends($name, $code, $vars, $result) {
|
||||
static $i = 0;
|
||||
$vars["iteration"] = $i++;
|
||||
$this->execTpl($name, $code, $vars, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerDynamicExtends
|
||||
* @param $name
|
||||
* @param $code
|
||||
* @param $vars
|
||||
* @param $result
|
||||
*/
|
||||
public function _testDynamicExtends($name, $code, $vars, $result) {
|
||||
static $i = 0;
|
||||
$vars["iteration"] = $i++;
|
||||
$this->execTpl($name, $code, $vars, $result, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group extends
|
||||
*/
|
||||
public function _testParentLevel() {
|
||||
//echo($this->aspect->getTemplate("parent.tpl")->_body); exit;
|
||||
$this->assertSame($this->cytro->fetch("parent.tpl", array("a" => "a char")), "Parent template\nBlock1: Block2: Block3: default");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group extends
|
||||
*/
|
||||
public function testChildLevel1() {
|
||||
//echo($this->aspect->fetch("child1.tpl", array("a" => "a char"))); exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group extends
|
||||
*/
|
||||
public function _testChildLevel3() {
|
||||
echo($this->cytro->getTemplate("child3.tpl")->getBody()); exit;
|
||||
}
|
||||
}
|
||||
|
151
tests/cases/Cytro/ExtendsTemplateTest.php
Normal file
151
tests/cases/Cytro/ExtendsTemplateTest.php
Normal file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
namespace Cytro;
|
||||
use Cytro, Cytro\TestCase;
|
||||
use Symfony\Component\Process\Exception\LogicException;
|
||||
|
||||
class ExtendsTemplateTest extends TestCase {
|
||||
|
||||
public static function templates() {
|
||||
return array(
|
||||
array(
|
||||
"name" => "level.0.tpl",
|
||||
"level" => 0,
|
||||
"blocks" => array(
|
||||
"b1" => "",
|
||||
"b2" => "empty 0"
|
||||
),
|
||||
"result" => array(
|
||||
"b1" => "",
|
||||
"b2" => "empty 0"
|
||||
),
|
||||
),
|
||||
array(
|
||||
"name" => "level.1.tpl",
|
||||
"level" => 1,
|
||||
"blocks" => array(
|
||||
"b1" => "from level 1"
|
||||
),
|
||||
"result" => array(
|
||||
"b1" => "from level 1",
|
||||
"b2" => "empty 0"
|
||||
),
|
||||
),
|
||||
array(
|
||||
"name" => "level.2.tpl",
|
||||
"level" => 2,
|
||||
"blocks" => array(
|
||||
"b2" => "from level 2",
|
||||
"b4" => "unused block"
|
||||
),
|
||||
"result" => array(
|
||||
"b1" => "from level 1",
|
||||
"b2" => "from level 2"
|
||||
),
|
||||
),
|
||||
array(
|
||||
"name" => "level.3.tpl",
|
||||
"level" => 3,
|
||||
"blocks" => array(
|
||||
"b1" => "from level 3",
|
||||
"b2" => "also from level 3"
|
||||
),
|
||||
"result" => array(
|
||||
"b1" => "from level 3",
|
||||
"b2" => "also from level 3"
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static function generate($block_mask, $extend_mask) {
|
||||
$t = array();
|
||||
foreach(self::templates() as $level => $tpl) {
|
||||
$src = 'level#'.$level.' ';
|
||||
foreach($tpl["blocks"] as $bname => &$bcode) {
|
||||
$src .= sprintf($block_mask, $bname, $bname.': '.$bcode)." level#$level ";
|
||||
}
|
||||
$dst = "level#0 ";
|
||||
foreach($tpl["result"] as $bname => &$bcode) {
|
||||
$dst .= $bname.': '.$bcode.' level#0 ';
|
||||
}
|
||||
if($level) {
|
||||
$src = sprintf($extend_mask, $level-1).' '.$src;
|
||||
}
|
||||
$t[ $tpl["name"] ] = array("src" => $src, "dst" => $dst);
|
||||
}
|
||||
return $t;
|
||||
}
|
||||
/**
|
||||
* @group static-extend
|
||||
*/
|
||||
public function testTemplateExtends() {
|
||||
foreach(self::generate('{block "%s"}%s{/block}', '{extends "level.%d.tpl"}') as $name => $tpl) {
|
||||
$this->tpl($name, $tpl["src"]);
|
||||
//var_dump($src, "----\n\n----", $dst);ob_flush();fgetc(STDIN);
|
||||
$this->assertSame($this->cytro->fetch($name, array()), $tpl["dst"]);
|
||||
}
|
||||
}
|
||||
|
||||
// public static function providerDynamicExtends() {
|
||||
// $tpls = array();
|
||||
// //foreach(self::templates() as $i => $tpl) {
|
||||
// // $tpls[] = array($tpl[0], );
|
||||
// //}
|
||||
// $data = self::providerExtends();
|
||||
// $data[2][1] = str_replace('"b2"', '"b{$two}"', $data[2][1]);
|
||||
// return $data;
|
||||
// }
|
||||
|
||||
// public function setUp() {
|
||||
// $this->cytro = Cytro::factory(CYTRO_RESOURCES.'/template', CYTRO_RESOURCES.'/compile');
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @dataProvider providerExtends
|
||||
// * @param $name
|
||||
// * @param $code
|
||||
// * @param $vars
|
||||
// * @param $result
|
||||
// */
|
||||
// public function testStaticExtends($name, $code, $vars, $result) {
|
||||
// static $i = 0;
|
||||
// $vars["iteration"] = $i++;
|
||||
// $this->execTpl($name, $code, $vars, $result);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @dataProvider providerDynamicExtends
|
||||
// * @param $name
|
||||
// * @param $code
|
||||
// * @param $vars
|
||||
// * @param $result
|
||||
// */
|
||||
// public function testDynamicExtends($name, $code, $vars, $result) {
|
||||
// static $i = 0;
|
||||
// $vars["iteration"] = $i++;
|
||||
// $this->execTpl($name, $code, $vars, $result, 0);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @group extends
|
||||
// */
|
||||
// public function _testParentLevel() {
|
||||
// //echo($this->aspect->getTemplate("parent.tpl")->_body); exit;
|
||||
// $this->assertSame($this->cytro->fetch("parent.tpl", array("a" => "a char")), "Parent template\nBlock1: Block2: Block3: default");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @group extends
|
||||
// */
|
||||
// public function testChildLevel1() {
|
||||
// //echo($this->aspect->fetch("child1.tpl", array("a" => "a char"))); exit;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @group extends
|
||||
// */
|
||||
// public function _testChildLevel3() {
|
||||
// echo($this->cytro->getTemplate("child3.tpl")->getBody()); exit;
|
||||
// }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user