mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Rename Cytro to Fenom
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
namespace Cytro;
|
||||
use Cytro, Cytro\FSProvider as FS;
|
||||
namespace Fenom;
|
||||
use Fenom, Fenom\Provider as FS;
|
||||
|
||||
class TestCase extends \PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @var Cytro
|
||||
* @var Fenom
|
||||
*/
|
||||
public $cytro;
|
||||
public $fenom;
|
||||
|
||||
public $values = array(
|
||||
"one" => 1,
|
||||
@@ -18,14 +18,14 @@ class TestCase extends \PHPUnit_Framework_TestCase {
|
||||
);
|
||||
|
||||
public function setUp() {
|
||||
if(!file_exists(CYTRO_RESOURCES.'/compile')) {
|
||||
mkdir(CYTRO_RESOURCES.'/compile', 0777, true);
|
||||
if(!file_exists(FENOM_RESOURCES.'/compile')) {
|
||||
mkdir(FENOM_RESOURCES.'/compile', 0777, true);
|
||||
} else {
|
||||
FS::clean(CYTRO_RESOURCES.'/compile/');
|
||||
FS::clean(FENOM_RESOURCES.'/compile/');
|
||||
}
|
||||
$this->cytro = Cytro::factory(CYTRO_RESOURCES.'/template', CYTRO_RESOURCES.'/compile');
|
||||
$this->cytro->addModifier('dots', __CLASS__.'::dots');
|
||||
$this->cytro->addModifier('concat', __CLASS__.'::concat');
|
||||
$this->fenom = Fenom::factory(FENOM_RESOURCES.'/template', FENOM_RESOURCES.'/compile');
|
||||
$this->fenom->addModifier('dots', __CLASS__.'::dots');
|
||||
$this->fenom->addModifier('concat', __CLASS__.'::concat');
|
||||
}
|
||||
|
||||
public static function dots($value) {
|
||||
@@ -37,15 +37,15 @@ class TestCase extends \PHPUnit_Framework_TestCase {
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass() {
|
||||
if(!file_exists(CYTRO_RESOURCES.'/template')) {
|
||||
mkdir(CYTRO_RESOURCES.'/template', 0777, true);
|
||||
if(!file_exists(FENOM_RESOURCES.'/template')) {
|
||||
mkdir(FENOM_RESOURCES.'/template', 0777, true);
|
||||
} else {
|
||||
FS::clean(CYTRO_RESOURCES.'/template/');
|
||||
FS::clean(FENOM_RESOURCES.'/template/');
|
||||
}
|
||||
}
|
||||
|
||||
public function tpl($name, $code) {
|
||||
file_put_contents(CYTRO_RESOURCES.'/template/'.$name, $code);
|
||||
file_put_contents(FENOM_RESOURCES.'/template/'.$name, $code);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +57,7 @@ class TestCase extends \PHPUnit_Framework_TestCase {
|
||||
* @param bool $dump dump source and result code (for debug)
|
||||
*/
|
||||
public function exec($code, $vars, $result, $dump = false) {
|
||||
$tpl = $this->cytro->compileCode($code, "runtime.tpl");
|
||||
$tpl = $this->fenom->compileCode($code, "runtime.tpl");
|
||||
if($dump) {
|
||||
echo "\n========= DUMP BEGIN ===========\n".$code."\n--- to ---\n".$tpl->getBody()."\n========= DUMP END =============\n";
|
||||
}
|
||||
@@ -66,7 +66,7 @@ class TestCase extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
public function execTpl($name, $code, $vars, $result, $dump = false) {
|
||||
$this->tpl($name, $code);
|
||||
$tpl = $this->cytro->getTemplate($name);
|
||||
$tpl = $this->fenom->getTemplate($name);
|
||||
if($dump) {
|
||||
echo "\n========= DUMP BEGIN ===========\n".$code."\n--- to ---\n".$tpl->getBody()."\n========= DUMP END =============\n";
|
||||
}
|
||||
@@ -78,25 +78,25 @@ class TestCase extends \PHPUnit_Framework_TestCase {
|
||||
* @param string $code source of the template
|
||||
* @param string $exception exception class
|
||||
* @param string $message exception message
|
||||
* @param int $options Cytro's options
|
||||
* @param int $options Fenom's options
|
||||
*/
|
||||
public function execError($code, $exception, $message, $options = 0) {
|
||||
$opt = $this->cytro->getOptions();
|
||||
$this->cytro->setOptions($options);
|
||||
$opt = $this->fenom->getOptions();
|
||||
$this->fenom->setOptions($options);
|
||||
try {
|
||||
$this->cytro->compileCode($code, "inline.tpl");
|
||||
$this->fenom->compileCode($code, "inline.tpl");
|
||||
} catch(\Exception $e) {
|
||||
$this->assertSame($exception, get_class($e), "Exception $code");
|
||||
$this->assertStringStartsWith($message, $e->getMessage());
|
||||
$this->cytro->setOptions($opt);
|
||||
$this->fenom->setOptions($opt);
|
||||
return;
|
||||
}
|
||||
$this->cytro->setOptions($opt);
|
||||
$this->fenom->setOptions($opt);
|
||||
$this->fail("Code $code must be invalid");
|
||||
}
|
||||
|
||||
public function assertRender($tpl, $result, $debug = false) {
|
||||
$template = $this->cytro->compileCode($tpl);
|
||||
$template = $this->fenom->compileCode($tpl);
|
||||
if($debug) {
|
||||
print_r("$tpl:\n".$template->getBody());
|
||||
}
|
||||
|
@@ -4,9 +4,9 @@ require_once __DIR__."/../vendor/autoload.php";
|
||||
|
||||
|
||||
|
||||
define('CYTRO_RESOURCES', __DIR__."/resources");
|
||||
define('FENOM_RESOURCES', __DIR__."/resources");
|
||||
|
||||
require_once CYTRO_RESOURCES."/actions.php";
|
||||
require_once FENOM_RESOURCES."/actions.php";
|
||||
require_once __DIR__."/TestCase.php";
|
||||
|
||||
function drop() {
|
||||
|
@@ -1,22 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Cytro\Render,
|
||||
Cytro\FSProvider as FS;
|
||||
use Fenom\Render,
|
||||
Fenom\Provider as FS;
|
||||
|
||||
class CytroTest extends \Cytro\TestCase {
|
||||
class FenomTest extends \Fenom\TestCase {
|
||||
|
||||
public function testAddRender() {
|
||||
$test = $this;
|
||||
$this->cytro->addTemplate(new Render($this->cytro, function($tpl) use ($test) {
|
||||
$this->fenom->addTemplate(new Render($this->fenom, function($tpl) use ($test) {
|
||||
/** @var \PHPUnit_Framework_TestCase $test */
|
||||
$test->assertInstanceOf('Cytro\Render', $tpl);
|
||||
$test->assertInstanceOf('Fenom\Render', $tpl);
|
||||
echo "Inline render";
|
||||
}, array(
|
||||
"name" => 'render.tpl',
|
||||
"scm" => false
|
||||
)));
|
||||
|
||||
$this->assertSame("Inline render", $this->cytro->fetch('render.tpl', array()));
|
||||
$this->assertSame("Inline render", $this->fenom->fetch('render.tpl', array()));
|
||||
}
|
||||
|
||||
public function testCompileFile() {
|
||||
@@ -26,71 +26,71 @@ class CytroTest extends \Cytro\TestCase {
|
||||
);
|
||||
$this->tpl('template1.tpl', 'Template 1 a');
|
||||
$this->tpl('template2.tpl', 'Template 2 b');
|
||||
$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')));
|
||||
$this->assertSame("Template 1 a", $this->fenom->fetch('template1.tpl', $a));
|
||||
$this->assertSame("Template 2 b", $this->fenom->fetch('template2.tpl', $a));
|
||||
$this->assertInstanceOf('Fenom\Render', $this->fenom->getTemplate('template1.tpl'));
|
||||
$this->assertInstanceOf('Fenom\Render', $this->fenom->getTemplate('template2.tpl'));
|
||||
$this->assertSame(3, iterator_count(new FilesystemIterator(FENOM_RESOURCES.'/compile')));
|
||||
}
|
||||
|
||||
public function testStorage() {
|
||||
$this->tpl('custom.tpl', 'Custom template');
|
||||
$this->assertSame("Custom template", $this->cytro->fetch('custom.tpl', array()));
|
||||
//$this->cytro->clearCompiledTemplate('custom.tpl', false);
|
||||
$this->assertSame("Custom template", $this->fenom->fetch('custom.tpl', array()));
|
||||
//$this->fenom->clearCompiledTemplate('custom.tpl', false);
|
||||
|
||||
//$this->assertSame("Custom template", $this->cytro->fetch('custom.tpl', array()));
|
||||
//$this->assertSame("Custom template", $this->fenom->fetch('custom.tpl', array()));
|
||||
|
||||
$this->tpl('custom.tpl', 'Custom template 2');
|
||||
$this->assertSame("Custom template", $this->cytro->fetch('custom.tpl', array()));
|
||||
$this->assertSame("Custom template", $this->fenom->fetch('custom.tpl', array()));
|
||||
}
|
||||
|
||||
public function testCheckMTime() {
|
||||
$this->cytro->setOptions(Cytro::FORCE_COMPILE);
|
||||
$this->fenom->setOptions(Fenom::FORCE_COMPILE);
|
||||
$this->tpl('custom.tpl', 'Custom template');
|
||||
$this->assertSame("Custom template", $this->cytro->fetch('custom.tpl', array()));
|
||||
$this->assertSame("Custom template", $this->fenom->fetch('custom.tpl', array()));
|
||||
|
||||
sleep(1);
|
||||
$this->tpl('custom.tpl', 'Custom template (new)');
|
||||
$this->assertSame("Custom template (new)", $this->cytro->fetch('custom.tpl', array()));
|
||||
$this->assertSame("Custom template (new)", $this->fenom->fetch('custom.tpl', array()));
|
||||
}
|
||||
|
||||
public function testForceCompile() {
|
||||
$this->cytro->setOptions(Cytro::FORCE_COMPILE);
|
||||
$this->fenom->setOptions(Fenom::FORCE_COMPILE);
|
||||
$this->tpl('custom.tpl', 'Custom template');
|
||||
$this->assertSame("Custom template", $this->cytro->fetch('custom.tpl', array()));
|
||||
$this->assertSame("Custom template", $this->fenom->fetch('custom.tpl', array()));
|
||||
$this->tpl('custom.tpl', 'Custom template (new)');
|
||||
$this->assertSame("Custom template (new)", $this->cytro->fetch('custom.tpl', array()));
|
||||
$this->assertSame("Custom template (new)", $this->fenom->fetch('custom.tpl', array()));
|
||||
}
|
||||
|
||||
public function testSetModifier() {
|
||||
$this->cytro->addModifier("mymod", "myMod");
|
||||
$this->fenom->addModifier("mymod", "myMod");
|
||||
$this->tpl('custom.tpl', 'Custom modifier {$a|mymod}');
|
||||
$this->assertSame("Custom modifier (myMod)Custom(/myMod)", $this->cytro->fetch('custom.tpl', array("a" => "Custom")));
|
||||
$this->assertSame("Custom modifier (myMod)Custom(/myMod)", $this->fenom->fetch('custom.tpl', array("a" => "Custom")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group add_functions
|
||||
*/
|
||||
public function testSetFunctions() {
|
||||
$this->cytro->setOptions(Cytro::FORCE_COMPILE);
|
||||
$this->cytro->addFunction("myfunc", "myFunc");
|
||||
$this->cytro->addBlockFunction("myblockfunc", "myBlockFunc");
|
||||
$this->fenom->setOptions(Fenom::FORCE_COMPILE);
|
||||
$this->fenom->addFunction("myfunc", "myFunc");
|
||||
$this->fenom->addBlockFunction("myblockfunc", "myBlockFunc");
|
||||
$this->tpl('custom.tpl', 'Custom function {myfunc name="foo"}');
|
||||
$this->assertSame("Custom function MyFunc:foo", $this->cytro->fetch('custom.tpl', array()));
|
||||
$this->assertSame("Custom function MyFunc:foo", $this->fenom->fetch('custom.tpl', array()));
|
||||
$this->tpl('custom.tpl', 'Custom function {myblockfunc name="foo"} this block1 {/myblockfunc}');
|
||||
$this->assertSame("Custom function Block:foo:this block1:Block", $this->cytro->fetch('custom.tpl', array()));
|
||||
$this->assertSame("Custom function Block:foo:this block1:Block", $this->fenom->fetch('custom.tpl', array()));
|
||||
}
|
||||
|
||||
public function testSetCompilers() {
|
||||
$this->cytro->setOptions(Cytro::FORCE_COMPILE);
|
||||
$this->cytro->addCompiler("mycompiler", 'myCompiler');
|
||||
$this->cytro->addBlockCompiler("myblockcompiler", 'myBlockCompilerOpen', 'myBlockCompilerClose', array(
|
||||
$this->fenom->setOptions(Fenom::FORCE_COMPILE);
|
||||
$this->fenom->addCompiler("mycompiler", 'myCompiler');
|
||||
$this->fenom->addBlockCompiler("myblockcompiler", 'myBlockCompilerOpen', 'myBlockCompilerClose', array(
|
||||
'tag' => 'myBlockCompilerTag'
|
||||
));
|
||||
$this->tpl('custom.tpl', 'Custom compiler {mycompiler name="bar"}');
|
||||
$this->assertSame("Custom compiler PHP_VERSION: ".PHP_VERSION." (for bar)", $this->cytro->fetch('custom.tpl', array()));
|
||||
$this->assertSame("Custom compiler PHP_VERSION: ".PHP_VERSION." (for bar)", $this->fenom->fetch('custom.tpl', array()));
|
||||
$this->tpl('custom.tpl', 'Custom compiler {myblockcompiler name="bar"} block1 {tag name="baz"} block2 {/myblockcompiler}');
|
||||
$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()));
|
||||
$this->assertSame("Custom compiler PHP_VERSION: ".PHP_VERSION." (for bar) block1 Tag baz of compiler block2 End of compiler", $this->fenom->fetch('custom.tpl', array()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Cytro;
|
||||
namespace Fenom;
|
||||
|
||||
|
||||
class CommentTest extends TestCase {
|
@@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Cytro;
|
||||
namespace Fenom;
|
||||
|
||||
|
||||
class CustomProviderTest extends TestCase {
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->cytro->addProvider("my", new FSProvider(CYTRO_RESOURCES.'/provider'));
|
||||
$this->fenom->addProvider("my", new Provider(FENOM_RESOURCES.'/provider'));
|
||||
}
|
||||
|
||||
public function testCustom() {
|
@@ -1,13 +1,13 @@
|
||||
<?php
|
||||
namespace Cytro;
|
||||
use Cytro, Cytro\TestCase;
|
||||
namespace Fenom;
|
||||
use Fenom, Fenom\TestCase;
|
||||
|
||||
class ExtendsTemplateTest extends TestCase {
|
||||
|
||||
public function _testSandbox() {
|
||||
$this->cytro = Cytro::factory(CYTRO_RESOURCES.'/provider', CYTRO_RESOURCES.'/compile');
|
||||
$this->fenom = Fenom::factory(FENOM_RESOURCES.'/provider', FENOM_RESOURCES.'/compile');
|
||||
try {
|
||||
print_r($this->cytro->getTemplate('use/child.tpl')->getBody());
|
||||
print_r($this->fenom->getTemplate('use/child.tpl')->getBody());
|
||||
} catch (\Exception $e) {
|
||||
echo "$e";
|
||||
}
|
||||
@@ -114,24 +114,24 @@ class ExtendsTemplateTest extends TestCase {
|
||||
$tpls = self::generate('{block "%s"}%s{/block}', '{extends "level.%d.tpl"}', self::templates($vars));
|
||||
foreach($tpls as $name => $tpl) {
|
||||
$this->tpl($name, $tpl["src"]);
|
||||
$this->assertSame($this->cytro->fetch($name, $vars), $tpl["dst"]);
|
||||
$this->assertSame($this->fenom->fetch($name, $vars), $tpl["dst"]);
|
||||
}
|
||||
return;
|
||||
$vars["default"]++;
|
||||
$this->cytro->flush();
|
||||
$this->fenom->flush();
|
||||
$tpls = self::generate('{block "{$%s}"}%s{/block}', '{extends "level.%d.tpl"}', self::templates($vars));
|
||||
arsort($tpls);
|
||||
foreach($tpls as $name => $tpl) {
|
||||
$this->tpl("d.".$name, $tpl["src"]);
|
||||
$this->assertSame($this->cytro->fetch("d.".$name, $vars), $tpl["dst"]);
|
||||
$this->assertSame($this->fenom->fetch("d.".$name, $vars), $tpl["dst"]);
|
||||
}
|
||||
$vars["default"]++;
|
||||
$this->cytro->flush();
|
||||
$this->fenom->flush();
|
||||
$tpls = self::generate('{block "%s"}%s{/block}', '{extends "$level.%d.tpl"}', self::templates($vars));
|
||||
arsort($tpls);
|
||||
foreach($tpls as $name => $tpl) {
|
||||
$this->tpl("x.".$name, $tpl["src"]);
|
||||
$this->assertSame($this->cytro->fetch("x.".$name, $vars), $tpl["dst"]);
|
||||
$this->assertSame($this->fenom->fetch("x.".$name, $vars), $tpl["dst"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,8 +139,8 @@ class ExtendsTemplateTest extends TestCase {
|
||||
* @group use
|
||||
*/
|
||||
public function testUse() {
|
||||
$this->cytro = Cytro::factory(CYTRO_RESOURCES.'/provider', CYTRO_RESOURCES.'/compile');
|
||||
$this->assertSame("<html>\n block 1 blocks \n block 2 child \n</html>", $this->cytro->fetch('use/child.tpl'));
|
||||
$this->fenom = Fenom::factory(FENOM_RESOURCES.'/provider', FENOM_RESOURCES.'/compile');
|
||||
$this->assertSame("<html>\n block 1 blocks \n block 2 child \n</html>", $this->fenom->fetch('use/child.tpl'));
|
||||
}
|
||||
|
||||
public function _testParent() {
|
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace Cytro;
|
||||
namespace Fenom;
|
||||
|
||||
class MacrosTest extends TestCase {
|
||||
|
||||
@@ -45,30 +45,30 @@ class MacrosTest extends TestCase {
|
||||
}
|
||||
|
||||
public function testMacros() {
|
||||
$tpl = $this->cytro->compile('math.tpl');
|
||||
$tpl = $this->fenom->compile('math.tpl');
|
||||
|
||||
$this->assertStringStartsWith('x + y = ', trim($tpl->macros["plus"]["body"]));
|
||||
$this->assertSame('Math: x + y = 5 , x - y - z = 6', Modifier::strip($tpl->fetch(array()), true));
|
||||
}
|
||||
|
||||
public function testImport() {
|
||||
$tpl = $this->cytro->compile('import.tpl');
|
||||
$tpl = $this->fenom->compile('import.tpl');
|
||||
|
||||
$this->assertSame('Imp: x + y = 3 , x - y - z = 3', Modifier::strip($tpl->fetch(array()), true));
|
||||
}
|
||||
|
||||
public function testImportCustom() {
|
||||
$tpl = $this->cytro->compile('import_custom.tpl');
|
||||
$tpl = $this->fenom->compile('import_custom.tpl');
|
||||
|
||||
$this->assertSame('a: x + y = 3 , x - y - z = 3 , new minus macros .', Modifier::strip($tpl->fetch(array()), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedExceptionMessage Undefined macro 'plus'
|
||||
* @expectedException \Cytro\CompileException
|
||||
* @expectedException \Fenom\CompileException
|
||||
*/
|
||||
public function testImportMiss() {
|
||||
$tpl = $this->cytro->compile('import_miss.tpl');
|
||||
$tpl = $this->fenom->compile('import_miss.tpl');
|
||||
|
||||
$this->assertSame('a: x + y = 3 , x - y - z = 3 , new minus macros .', Modifier::strip($tpl->fetch(array()), true));
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace Cytro;
|
||||
namespace Fenom;
|
||||
|
||||
|
||||
class ModifiersTest extends TestCase {
|
||||
@@ -34,7 +34,7 @@ class ModifiersTest extends TestCase {
|
||||
* @param bool $middle
|
||||
*/
|
||||
public function testTruncate($in, $out, $count, $delim = '...', $by_words = false, $middle = false) {
|
||||
$tpl = $this->cytro->compileCode('{$text|truncate:$count:$delim:$by_words:$middle}');
|
||||
$tpl = $this->fenom->compileCode('{$text|truncate:$count:$delim:$by_words:$middle}');
|
||||
$this->assertEquals($out, $tpl->fetch(array(
|
||||
"text" => $in,
|
||||
"count" => $count,
|
||||
@@ -65,7 +65,7 @@ class ModifiersTest extends TestCase {
|
||||
* @param $out
|
||||
*/
|
||||
public function testUpLow($modifier, $in, $out) {
|
||||
$tpl = $this->cytro->compileCode('{$text|'.$modifier.'}');
|
||||
$tpl = $this->fenom->compileCode('{$text|'.$modifier.'}');
|
||||
$this->assertEquals($out, $tpl->fetch(array(
|
||||
"text" => $in,
|
||||
)));
|
||||
@@ -91,7 +91,7 @@ class ModifiersTest extends TestCase {
|
||||
* @param $out
|
||||
*/
|
||||
public function testLength($in, $out) {
|
||||
$tpl = $this->cytro->compileCode('{$data|length}');
|
||||
$tpl = $this->fenom->compileCode('{$data|length}');
|
||||
$this->assertEquals($out, $tpl->fetch(array(
|
||||
"data" => $in,
|
||||
)));
|
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
namespace Cytro;
|
||||
use Cytro;
|
||||
namespace Fenom;
|
||||
use Fenom;
|
||||
|
||||
class FSProviderTest extends \Cytro\TestCase {
|
||||
class FSProviderTest extends \Fenom\TestCase {
|
||||
/**
|
||||
* @var FSProvider
|
||||
* @var Provider
|
||||
*/
|
||||
public $provider;
|
||||
|
||||
@@ -12,7 +12,7 @@ class FSProviderTest extends \Cytro\TestCase {
|
||||
parent::setUp();
|
||||
$this->tpl("template1.tpl", 'Template 1 {$a}');
|
||||
$this->tpl("template2.tpl", 'Template 2 {$a}');
|
||||
$this->provider = new FSProvider(CYTRO_RESOURCES.'/template');
|
||||
$this->provider = new Provider(FENOM_RESOURCES.'/template');
|
||||
}
|
||||
|
||||
public function testIsTemplateExists() {
|
||||
@@ -23,8 +23,8 @@ class FSProviderTest extends \Cytro\TestCase {
|
||||
public function testGetSource() {
|
||||
$src = $this->provider->getSource("template1.tpl", $time);
|
||||
clearstatcache();
|
||||
$this->assertEquals(file_get_contents(CYTRO_RESOURCES.'/template/template1.tpl'), $src);
|
||||
$this->assertEquals(filemtime(CYTRO_RESOURCES.'/template/template1.tpl'), $time);
|
||||
$this->assertEquals(file_get_contents(FENOM_RESOURCES.'/template/template1.tpl'), $src);
|
||||
$this->assertEquals(filemtime(FENOM_RESOURCES.'/template/template1.tpl'), $time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ class FSProviderTest extends \Cytro\TestCase {
|
||||
public function testGetLastModified() {
|
||||
$time = $this->provider->getLastModified("template1.tpl");
|
||||
clearstatcache();
|
||||
$this->assertEquals(filemtime(CYTRO_RESOURCES.'/template/template1.tpl'), $time);
|
||||
$this->assertEquals(filemtime(FENOM_RESOURCES.'/template/template1.tpl'), $time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +52,7 @@ class FSProviderTest extends \Cytro\TestCase {
|
||||
$this->assertSame($tpls, array_keys($times));
|
||||
clearstatcache();
|
||||
foreach($times as $template => $time) {
|
||||
$this->assertEquals(filemtime(CYTRO_RESOURCES."/template/$template"), $time);
|
||||
$this->assertEquals(filemtime(FENOM_RESOURCES."/template/$template"), $time);
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace Cytro;
|
||||
use Cytro,
|
||||
Cytro\Render;
|
||||
namespace Fenom;
|
||||
use Fenom,
|
||||
Fenom\Render;
|
||||
|
||||
class RenderTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
@@ -11,7 +11,7 @@ class RenderTest extends \PHPUnit_Framework_TestCase {
|
||||
public static $render;
|
||||
|
||||
public static function setUpBeforeClass() {
|
||||
self::$render = new Render(Cytro::factory("."), function ($tpl) {
|
||||
self::$render = new Render(Fenom::factory("."), function ($tpl) {
|
||||
echo "It is render's function ".$tpl["render"];
|
||||
}, array(
|
||||
"name" => "render.tpl"
|
||||
@@ -19,7 +19,7 @@ class RenderTest extends \PHPUnit_Framework_TestCase {
|
||||
}
|
||||
|
||||
public function testCreate() {
|
||||
$r = new Render(Cytro::factory("."), function () {
|
||||
$r = new Render(Fenom::factory("."), function () {
|
||||
echo "Test render";
|
||||
}, array(
|
||||
"name" => "test.render.tpl"
|
||||
@@ -43,7 +43,7 @@ class RenderTest extends \PHPUnit_Framework_TestCase {
|
||||
* @expectedExceptionMessage template error
|
||||
*/
|
||||
public function testFetchException() {
|
||||
$render = new Render(Cytro::factory("."), function () {
|
||||
$render = new Render(Fenom::factory("."), function () {
|
||||
echo "error";
|
||||
throw new \RuntimeException("template error");
|
||||
}, array(
|
@@ -1,23 +1,23 @@
|
||||
<?php
|
||||
namespace Cytro;
|
||||
namespace Fenom;
|
||||
|
||||
class ScopeTest extends TestCase {
|
||||
public function openTag($tokenizer, $scope) {
|
||||
$this->assertInstanceOf('Cytro\Tokenizer', $tokenizer);
|
||||
$this->assertInstanceOf('Cytro\Scope', $scope);
|
||||
$this->assertInstanceOf('Fenom\Tokenizer', $tokenizer);
|
||||
$this->assertInstanceOf('Fenom\Scope', $scope);
|
||||
$scope["value"] = true;
|
||||
return "open-tag";
|
||||
}
|
||||
|
||||
public function closeTag($tokenizer, $scope) {
|
||||
$this->assertInstanceOf('Cytro\Tokenizer', $tokenizer);
|
||||
$this->assertInstanceOf('Cytro\Scope', $scope);
|
||||
$this->assertInstanceOf('Fenom\Tokenizer', $tokenizer);
|
||||
$this->assertInstanceOf('Fenom\Scope', $scope);
|
||||
$this->assertTrue($scope["value"]);
|
||||
return "close-tag";
|
||||
}
|
||||
|
||||
public function testBlock() {
|
||||
/*$scope = new Scope($this->cytro, new Template($this->cytro), 1, array(
|
||||
/*$scope = new Scope($this->fenom, new Template($this->fenom), 1, array(
|
||||
"open" => array($this, "openTag"),
|
||||
"close" => array($this, "closeTag")
|
||||
), 0);
|
@@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Cytro;
|
||||
namespace Fenom;
|
||||
|
||||
|
||||
class TagsTest extends TestCase {
|
||||
|
||||
public function _testSandbox() {
|
||||
try {
|
||||
var_dump($this->cytro->compileCode('{for $i=0 to=5}{cycle ["one", "two"]}, {/for}')->getBody());
|
||||
var_dump($this->fenom->compileCode('{for $i=0 to=5}{cycle ["one", "two"]}, {/for}')->getBody());
|
||||
} catch(\Exception $e) {
|
||||
echo "$e";
|
||||
}
|
@@ -1,19 +1,19 @@
|
||||
<?php
|
||||
namespace Cytro;
|
||||
use Cytro\Template,
|
||||
Cytro,
|
||||
Cytro\Render;
|
||||
namespace Fenom;
|
||||
use Fenom\Template,
|
||||
Fenom,
|
||||
Fenom\Render;
|
||||
|
||||
/**
|
||||
* Test template parsing
|
||||
*
|
||||
* @package Cytro
|
||||
* @package Fenom
|
||||
*/
|
||||
class TemplateTest extends TestCase {
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->cytro->addTemplate(new Render($this->cytro, function ($tpl) {
|
||||
$this->fenom->addTemplate(new Render($this->fenom, function ($tpl) {
|
||||
echo "<b>Welcome, ".$tpl["username"]." (".$tpl["email"].")</b>";
|
||||
}, array(
|
||||
"name" => "welcome.tpl"
|
||||
@@ -76,14 +76,14 @@ class TemplateTest extends TestCase {
|
||||
|
||||
public static function providerVarsInvalid() {
|
||||
return array(
|
||||
array('hello, {$a.}!', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('hello, {$b[c}!', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('hello, {$b.c]}!', 'Cytro\CompileException', "Unexpected token ']'"),
|
||||
array('hello, {$b[ ]}!', 'Cytro\CompileException', "Unexpected token ']'"),
|
||||
array('hello, {$b[9/].c}!', 'Cytro\CompileException', "Unexpected token ']'"),
|
||||
array('hello, {$b[3]$c}!', 'Cytro\CompileException', "Unexpected token '\$c'"),
|
||||
array('hello, {$b[3]c}!', 'Cytro\CompileException', "Unexpected token 'c'"),
|
||||
array('hello, {$b.obj->valid()}!', 'Cytro\SecurityException', "Forbidden to call methods", Cytro::DENY_METHODS),
|
||||
array('hello, {$a.}!', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
array('hello, {$b[c}!', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
array('hello, {$b.c]}!', 'Fenom\CompileException', "Unexpected token ']'"),
|
||||
array('hello, {$b[ ]}!', 'Fenom\CompileException', "Unexpected token ']'"),
|
||||
array('hello, {$b[9/].c}!', 'Fenom\CompileException', "Unexpected token ']'"),
|
||||
array('hello, {$b[3]$c}!', 'Fenom\CompileException', "Unexpected token '\$c'"),
|
||||
array('hello, {$b[3]c}!', 'Fenom\CompileException', "Unexpected token 'c'"),
|
||||
array('hello, {$b.obj->valid()}!', 'Fenom\SecurityException', "Forbidden to call methods", Fenom::DENY_METHODS),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -138,12 +138,12 @@ class TemplateTest extends TestCase {
|
||||
|
||||
public static function providerModifiersInvalid() {
|
||||
return array(
|
||||
array('Mod: {$lorem|}!', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('Mod: {$lorem|str_rot13}!', 'Cytro\CompileException', "Modifier str_rot13 not found", Cytro::DENY_INLINE_FUNCS),
|
||||
array('Mod: {$lorem|my_encode}!', 'Cytro\CompileException', "Modifier my_encode not found"),
|
||||
array('Mod: {$lorem|truncate:}!', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('Mod: {$lorem|truncate:abs}!', 'Cytro\CompileException', "Unexpected token 'abs'"),
|
||||
array('Mod: {$lorem|truncate:80|}!', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('Mod: {$lorem|}!', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
array('Mod: {$lorem|str_rot13}!', 'Fenom\CompileException', "Modifier str_rot13 not found", Fenom::DENY_INLINE_FUNCS),
|
||||
array('Mod: {$lorem|my_encode}!', 'Fenom\CompileException', "Modifier my_encode not found"),
|
||||
array('Mod: {$lorem|truncate:}!', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
array('Mod: {$lorem|truncate:abs}!', 'Fenom\CompileException', "Unexpected token 'abs'"),
|
||||
array('Mod: {$lorem|truncate:80|}!', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -185,15 +185,15 @@ class TemplateTest extends TestCase {
|
||||
|
||||
public static function providerExpressionsInvalid() {
|
||||
return array(
|
||||
array('If: {-"hi"} end', 'Cytro\CompileException', "Unexpected token '-'"),
|
||||
array('If: {($a++)++} end', 'Cytro\CompileException', "Unexpected token '++'"),
|
||||
array('If: {$a + * $c} end', 'Cytro\CompileException', "Unexpected token '*'"),
|
||||
array('If: {/$a} end', 'Cytro\CompileException', "Unexpected token '\$a'"),
|
||||
array('If: {$a == 5 > 4} end', 'Cytro\CompileException', "Unexpected token '>'"),
|
||||
array('If: {$a != 5 <= 4} end', 'Cytro\CompileException', "Unexpected token '<='"),
|
||||
array('If: {$a != 5 => 4} end', 'Cytro\CompileException', "Unexpected token '=>'"),
|
||||
array('If: {$a + (*6)} end', 'Cytro\CompileException', "Unexpected token '*'"),
|
||||
array('If: {$a + ( 6} end', 'Cytro\CompileException', "Brackets don't match"),
|
||||
array('If: {-"hi"} end', 'Fenom\CompileException', "Unexpected token '-'"),
|
||||
array('If: {($a++)++} end', 'Fenom\CompileException', "Unexpected token '++'"),
|
||||
array('If: {$a + * $c} end', 'Fenom\CompileException', "Unexpected token '*'"),
|
||||
array('If: {/$a} end', 'Fenom\CompileException', "Unexpected token '\$a'"),
|
||||
array('If: {$a == 5 > 4} end', 'Fenom\CompileException', "Unexpected token '>'"),
|
||||
array('If: {$a != 5 <= 4} end', 'Fenom\CompileException', "Unexpected token '<='"),
|
||||
array('If: {$a != 5 => 4} end', 'Fenom\CompileException', "Unexpected token '=>'"),
|
||||
array('If: {$a + (*6)} end', 'Fenom\CompileException', "Unexpected token '*'"),
|
||||
array('If: {$a + ( 6} end', 'Fenom\CompileException', "Brackets don't match"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -230,8 +230,8 @@ class TemplateTest extends TestCase {
|
||||
|
||||
public static function providerIncludeInvalid() {
|
||||
return array(
|
||||
array('Include {include} template', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('Include {include another="welcome.tpl"} template', 'Cytro\CompileException', "Unexpected token '='"),
|
||||
array('Include {include} template', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
array('Include {include another="welcome.tpl"} template', 'Fenom\CompileException', "Unexpected token '='"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -271,10 +271,10 @@ class TemplateTest extends TestCase {
|
||||
|
||||
public static function providerIfInvalid() {
|
||||
return array(
|
||||
array('If: {if} block1 {/if} end', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('If: {if 1} block1 {elseif} block2 {/if} end', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('If: {if 1} block1 {else} block2 {elseif 0} block3 {/if} end', 'Cytro\CompileException', "Incorrect use of the tag {elseif}"),
|
||||
array('If: {if 1} block1 {else} block2 {/if} block3 {elseif 0} end', 'Cytro\CompileException', "Unexpected tag 'elseif' (this tag can be used with 'if')"),
|
||||
array('If: {if} block1 {/if} end', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
array('If: {if 1} block1 {elseif} block2 {/if} end', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
array('If: {if 1} block1 {else} block2 {elseif 0} block3 {/if} end', 'Fenom\CompileException', "Incorrect use of the tag {elseif}"),
|
||||
array('If: {if 1} block1 {else} block2 {/if} block3 {elseif 0} end', 'Fenom\CompileException', "Unexpected tag 'elseif' (this tag can be used with 'if')"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -312,20 +312,20 @@ class TemplateTest extends TestCase {
|
||||
|
||||
public static function providerCreateVarInvalid() {
|
||||
return array(
|
||||
array('Create: {var $v} Result: {$v} end', 'Cytro\CompileException', "Unclosed tag: {var} opened"),
|
||||
array('Create: {var $v = } Result: {$v} end', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('Create: {var $v = 1++} Result: {$v} end', 'Cytro\CompileException', "Unexpected token '++'"),
|
||||
array('Create: {var $v = c} Result: {$v} end', 'Cytro\CompileException', "Unexpected token 'c'"),
|
||||
array('Create: {var $v = ($a)++} Result: {$v} end', 'Cytro\CompileException', "Unexpected token '++'"),
|
||||
array('Create: {var $v = --$a++} Result: {$v} end', 'Cytro\CompileException', "Unexpected token '++'"),
|
||||
array('Create: {var $v = $a|upper++} Result: {$v} end', 'Cytro\CompileException', "Unexpected token '++'"),
|
||||
array('Create: {var $v = max($a,2)++} Result: {$v} end', 'Cytro\CompileException', "Unexpected token '++'"),
|
||||
array('Create: {var $v = max($a,2)} Result: {$v} end', 'Cytro\CompileException', "Modifier max not found", Cytro::DENY_INLINE_FUNCS),
|
||||
array('Create: {var $v = 4*} Result: {$v} end', 'Cytro\CompileException', "Unexpected token '*'"),
|
||||
array('Create: {var $v = ""$a} Result: {$v} end', 'Cytro\CompileException', "Unexpected token '\$a'"),
|
||||
array('Create: {var $v = [1,2} Result: {$v} end', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('Create: {var $v = empty(2)} Result: {$v} end', 'Cytro\CompileException', "Unexpected token 2, isset() and empty() accept only variables"),
|
||||
array('Create: {var $v = isset(2)} Result: {$v} end', 'Cytro\CompileException', "Unexpected token 2, isset() and empty() accept only variables"),
|
||||
array('Create: {var $v} Result: {$v} end', 'Fenom\CompileException', "Unclosed tag: {var} opened"),
|
||||
array('Create: {var $v = } Result: {$v} end', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
array('Create: {var $v = 1++} Result: {$v} end', 'Fenom\CompileException', "Unexpected token '++'"),
|
||||
array('Create: {var $v = c} Result: {$v} end', 'Fenom\CompileException', "Unexpected token 'c'"),
|
||||
array('Create: {var $v = ($a)++} Result: {$v} end', 'Fenom\CompileException', "Unexpected token '++'"),
|
||||
array('Create: {var $v = --$a++} Result: {$v} end', 'Fenom\CompileException', "Unexpected token '++'"),
|
||||
array('Create: {var $v = $a|upper++} Result: {$v} end', 'Fenom\CompileException', "Unexpected token '++'"),
|
||||
array('Create: {var $v = max($a,2)++} Result: {$v} end', 'Fenom\CompileException', "Unexpected token '++'"),
|
||||
array('Create: {var $v = max($a,2)} Result: {$v} end', 'Fenom\CompileException', "Modifier max not found", Fenom::DENY_INLINE_FUNCS),
|
||||
array('Create: {var $v = 4*} Result: {$v} end', 'Fenom\CompileException', "Unexpected token '*'"),
|
||||
array('Create: {var $v = ""$a} Result: {$v} end', 'Fenom\CompileException', "Unexpected token '\$a'"),
|
||||
array('Create: {var $v = [1,2} Result: {$v} end', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
array('Create: {var $v = empty(2)} Result: {$v} end', 'Fenom\CompileException', "Unexpected token 2, isset() and empty() accept only variables"),
|
||||
array('Create: {var $v = isset(2)} Result: {$v} end', 'Fenom\CompileException', "Unexpected token 2, isset() and empty() accept only variables"),
|
||||
|
||||
);
|
||||
}
|
||||
@@ -418,27 +418,27 @@ class TemplateTest extends TestCase {
|
||||
|
||||
public static function providerForeachInvalid() {
|
||||
return array(
|
||||
array('Foreach: {foreach} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected end of tag {foreach}"),
|
||||
array('Foreach: {foreach $list} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('Foreach: {foreach $list+1 as $e} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '+'"),
|
||||
array('Foreach: {foreach array_random() as $e} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token 'array_random'"),
|
||||
array('Foreach: {foreach $list as $e+1} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '+'"),
|
||||
array('Foreach: {foreach $list as $k+1 => $e} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '+'"),
|
||||
array('Foreach: {foreach $list as max($i,1) => $e} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token 'max'"),
|
||||
array('Foreach: {foreach $list as max($e,1)} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token 'max'"),
|
||||
array('Foreach: {foreach $list => $e} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '=>'"),
|
||||
array('Foreach: {foreach $list $k => $e} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '\$k'"),
|
||||
array('Foreach: {foreach $list as $k =>} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('Foreach: {foreach last=$l $list as $e } {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token 'last' in tag {foreach}"),
|
||||
array('Foreach: {foreach $list as $e unknown=1} {$e}, {/foreach} end', 'Cytro\CompileException', "Unknown parameter 'unknown'"),
|
||||
array('Foreach: {foreach $list as $e index=$i+1} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '+'"),
|
||||
array('Foreach: {foreach $list as $e first=$f+1} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '+'"),
|
||||
array('Foreach: {foreach $list as $e last=$l+1} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '+'"),
|
||||
array('Foreach: {foreach $list as $e index=max($i,1)} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token 'max'"),
|
||||
array('Foreach: {foreach $list as $e first=max($i,1)} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token 'max'"),
|
||||
array('Foreach: {foreach $list as $e last=max($i,1)} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token 'max'"),
|
||||
array('Foreach: {foreach $list as $e} {$e}, {foreachelse} {break} {/foreach} end', 'Cytro\CompileException', "Improper usage of the tag {break}"),
|
||||
array('Foreach: {foreach $list as $e} {$e}, {foreachelse} {continue} {/foreach} end', 'Cytro\CompileException', "Improper usage of the tag {continue}"),
|
||||
array('Foreach: {foreach} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected end of tag {foreach}"),
|
||||
array('Foreach: {foreach $list} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
array('Foreach: {foreach $list+1 as $e} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected token '+'"),
|
||||
array('Foreach: {foreach array_random() as $e} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected token 'array_random'"),
|
||||
array('Foreach: {foreach $list as $e+1} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected token '+'"),
|
||||
array('Foreach: {foreach $list as $k+1 => $e} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected token '+'"),
|
||||
array('Foreach: {foreach $list as max($i,1) => $e} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected token 'max'"),
|
||||
array('Foreach: {foreach $list as max($e,1)} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected token 'max'"),
|
||||
array('Foreach: {foreach $list => $e} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected token '=>'"),
|
||||
array('Foreach: {foreach $list $k => $e} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected token '\$k'"),
|
||||
array('Foreach: {foreach $list as $k =>} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
array('Foreach: {foreach last=$l $list as $e } {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected token 'last' in tag {foreach}"),
|
||||
array('Foreach: {foreach $list as $e unknown=1} {$e}, {/foreach} end', 'Fenom\CompileException', "Unknown parameter 'unknown'"),
|
||||
array('Foreach: {foreach $list as $e index=$i+1} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected token '+'"),
|
||||
array('Foreach: {foreach $list as $e first=$f+1} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected token '+'"),
|
||||
array('Foreach: {foreach $list as $e last=$l+1} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected token '+'"),
|
||||
array('Foreach: {foreach $list as $e index=max($i,1)} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected token 'max'"),
|
||||
array('Foreach: {foreach $list as $e first=max($i,1)} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected token 'max'"),
|
||||
array('Foreach: {foreach $list as $e last=max($i,1)} {$e}, {/foreach} end', 'Fenom\CompileException', "Unexpected token 'max'"),
|
||||
array('Foreach: {foreach $list as $e} {$e}, {foreachelse} {break} {/foreach} end', 'Fenom\CompileException', "Improper usage of the tag {break}"),
|
||||
array('Foreach: {foreach $list as $e} {$e}, {foreachelse} {continue} {/foreach} end', 'Fenom\CompileException', "Improper usage of the tag {continue}"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -483,9 +483,9 @@ class TemplateTest extends TestCase {
|
||||
|
||||
public static function providerSwitchInvalid() {
|
||||
return array(
|
||||
array('Switch: {switch}{case 1} one {break}{/switch} end', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('Switch: {switch 1}{case} one {break}{/switch} end', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('Switch: {switch 1}{break}{case} one {/switch} end', 'Cytro\CompileException', "Improper usage of the tag {break}"),
|
||||
array('Switch: {switch}{case 1} one {break}{/switch} end', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
array('Switch: {switch 1}{case} one {break}{/switch} end', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
array('Switch: {switch 1}{break}{case} one {/switch} end', 'Fenom\CompileException', "Improper usage of the tag {break}"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -501,7 +501,7 @@ class TemplateTest extends TestCase {
|
||||
|
||||
public static function providerWhileInvalid() {
|
||||
return array(
|
||||
array('While: {while} block {/while} end', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('While: {while} block {/while} end', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -529,29 +529,29 @@ class TemplateTest extends TestCase {
|
||||
|
||||
public static function providerForInvalid() {
|
||||
return array(
|
||||
array('For: {for} block1 {/for} end', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('For: {for $a=} block1 {/for} end', 'Cytro\CompileException', "Unexpected end of expression"),
|
||||
array('For: {for $a+1=3 to=6} block1 {/for} end', 'Cytro\CompileException', "Unexpected token '+'"),
|
||||
array('For: {for max($a,$b)=3 to=6} block1 {/for} end', 'Cytro\CompileException', "Unexpected token 'max'"),
|
||||
array('For: {for to=6 $a=3} block1 {/for} end', 'Cytro\CompileException', "Unexpected token 'to'"),
|
||||
array('For: {for index=$i $a=3 to=6} block1 {/for} end', 'Cytro\CompileException', "Unexpected token 'index'"),
|
||||
array('For: {for first=$i $a=3 to=6} block1 {/for} end', 'Cytro\CompileException', "Unexpected token 'first'"),
|
||||
array('For: {for last=$i $a=3 to=6} block1 {/for} end', 'Cytro\CompileException', "Unexpected token 'last'"),
|
||||
array('For: {for $a=4 to=6 unk=4} block1 {/for} end', 'Cytro\CompileException', "Unknown parameter 'unk'"),
|
||||
array('For: {for $a=4 to=6} $a: {$a}, {forelse} {break} {/for} end', 'Cytro\CompileException', "Improper usage of the tag {break}"),
|
||||
array('For: {for $a=4 to=6} $a: {$a}, {forelse} {continue} {/for} end', 'Cytro\CompileException', "Improper usage of the tag {continue}"),
|
||||
array('For: {for} block1 {/for} end', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
array('For: {for $a=} block1 {/for} end', 'Fenom\CompileException', "Unexpected end of expression"),
|
||||
array('For: {for $a+1=3 to=6} block1 {/for} end', 'Fenom\CompileException', "Unexpected token '+'"),
|
||||
array('For: {for max($a,$b)=3 to=6} block1 {/for} end', 'Fenom\CompileException', "Unexpected token 'max'"),
|
||||
array('For: {for to=6 $a=3} block1 {/for} end', 'Fenom\CompileException', "Unexpected token 'to'"),
|
||||
array('For: {for index=$i $a=3 to=6} block1 {/for} end', 'Fenom\CompileException', "Unexpected token 'index'"),
|
||||
array('For: {for first=$i $a=3 to=6} block1 {/for} end', 'Fenom\CompileException', "Unexpected token 'first'"),
|
||||
array('For: {for last=$i $a=3 to=6} block1 {/for} end', 'Fenom\CompileException', "Unexpected token 'last'"),
|
||||
array('For: {for $a=4 to=6 unk=4} block1 {/for} end', 'Fenom\CompileException', "Unknown parameter 'unk'"),
|
||||
array('For: {for $a=4 to=6} $a: {$a}, {forelse} {break} {/for} end', 'Fenom\CompileException', "Improper usage of the tag {break}"),
|
||||
array('For: {for $a=4 to=6} $a: {$a}, {forelse} {continue} {/for} end', 'Fenom\CompileException', "Improper usage of the tag {continue}"),
|
||||
);
|
||||
}
|
||||
|
||||
public static function providerLayersInvalid() {
|
||||
return array(
|
||||
array('Layers: {foreach $list as $e} block1 {if 1} {foreachelse} {/if} {/foreach} end', 'Cytro\CompileException', "Unexpected tag 'foreachelse' (this tag can be used with 'foreach')"),
|
||||
array('Layers: {foreach $list as $e} block1 {if 1} {/foreach} {/if} end', 'Cytro\CompileException', "Unexpected closing of the tag 'foreach'"),
|
||||
array('Layers: {for $a=4 to=6} block1 {if 1} {forelse} {/if} {/for} end', 'Cytro\CompileException', "Unexpected tag 'forelse' (this tag can be used with 'for')"),
|
||||
array('Layers: {for $a=4 to=6} block1 {if 1} {/for} {/if} end', 'Cytro\CompileException', "Unexpected closing of the tag 'for'"),
|
||||
array('Layers: {switch 1} {if 1} {case 1} {/if} {/switch} end', 'Cytro\CompileException', "Unexpected tag 'case' (this tag can be used with 'switch')"),
|
||||
array('Layers: {/switch} end', 'Cytro\CompileException', "Unexpected closing of the tag 'switch'"),
|
||||
array('Layers: {if 1} end', 'Cytro\CompileException', "Unclosed tag: {if}"),
|
||||
array('Layers: {foreach $list as $e} block1 {if 1} {foreachelse} {/if} {/foreach} end', 'Fenom\CompileException', "Unexpected tag 'foreachelse' (this tag can be used with 'foreach')"),
|
||||
array('Layers: {foreach $list as $e} block1 {if 1} {/foreach} {/if} end', 'Fenom\CompileException', "Unexpected closing of the tag 'foreach'"),
|
||||
array('Layers: {for $a=4 to=6} block1 {if 1} {forelse} {/if} {/for} end', 'Fenom\CompileException', "Unexpected tag 'forelse' (this tag can be used with 'for')"),
|
||||
array('Layers: {for $a=4 to=6} block1 {if 1} {/for} {/if} end', 'Fenom\CompileException', "Unexpected closing of the tag 'for'"),
|
||||
array('Layers: {switch 1} {if 1} {case 1} {/if} {/switch} end', 'Fenom\CompileException', "Unexpected tag 'case' (this tag can be used with 'switch')"),
|
||||
array('Layers: {/switch} end', 'Fenom\CompileException', "Unexpected closing of the tag 'switch'"),
|
||||
array('Layers: {if 1} end', 'Fenom\CompileException', "Unclosed tag: {if}"),
|
||||
);
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
namespace Cytro;
|
||||
use Cytro\Tokenizer;
|
||||
namespace Fenom;
|
||||
use Fenom\Tokenizer;
|
||||
|
||||
class TokenizerTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
@@ -54,7 +54,7 @@ class TokenizerTest extends \PHPUnit_Framework_TestCase {
|
||||
try {
|
||||
$tokens->skip(T_STRING)->skip('(')->skip(':');
|
||||
} catch(\Exception $e) {
|
||||
$this->assertInstanceOf('Cytro\UnexpectedTokenException', $e);
|
||||
$this->assertInstanceOf('Fenom\UnexpectedTokenException', $e);
|
||||
$this->assertStringStartsWith("Unexpected token '3' in expression, expect ':'", $e->getMessage());
|
||||
}
|
||||
$this->assertTrue($tokens->valid());
|
@@ -12,20 +12,20 @@ function myBlockFunc($params, $content) {
|
||||
return "Block:".$params["name"].':'.trim($content).':Block';
|
||||
}
|
||||
|
||||
function myCompiler(Cytro\Tokenizer $tokenizer, Cytro\Template $tpl) {
|
||||
function myCompiler(Fenom\Tokenizer $tokenizer, Fenom\Template $tpl) {
|
||||
$p = $tpl->parseParams($tokenizer);
|
||||
return 'echo "PHP_VERSION: ".PHP_VERSION." (for ".'.$p["name"].'.")";';
|
||||
}
|
||||
|
||||
function myBlockCompilerOpen(Cytro\Tokenizer $tokenizer, Cytro\Scope $scope) {
|
||||
function myBlockCompilerOpen(Fenom\Tokenizer $tokenizer, Fenom\Scope $scope) {
|
||||
return myCompiler($tokenizer, $scope->tpl);
|
||||
}
|
||||
|
||||
function myBlockCompilerClose(Cytro\Tokenizer $tokenizer, Cytro\Scope $scope) {
|
||||
function myBlockCompilerClose(Fenom\Tokenizer $tokenizer, Fenom\Scope $scope) {
|
||||
return 'echo "End of compiler";';
|
||||
}
|
||||
|
||||
function myBlockCompilerTag(Cytro\Tokenizer $tokenizer, Cytro\Scope $scope) {
|
||||
function myBlockCompilerTag(Fenom\Tokenizer $tokenizer, Fenom\Scope $scope) {
|
||||
$p = $scope->tpl->parseParams($tokenizer);
|
||||
return 'echo "Tag ".'.$p["name"].'." of compiler";';
|
||||
}
|
Reference in New Issue
Block a user