permit alph-numeric and fix unit test

master
Gnieark 6 years ago
parent bb11d05e7e
commit d4b06736f2

@ -31,9 +31,13 @@ class TplBlock {
public function __construct($name = NULL){ public function __construct($name = NULL){
$this->name = $name; $this->name = $name;
if(!is_null($name) && !ctype_alnum($name)){
throw new InvalidTemplateException("Only alpha-numerics chars are allowed on the block name");
return false;
}
$this->unusedRegex = '/' $this->unusedRegex = '/'
. self::blockStartStart . self::blockStartStart
. ' *([a-z][a-z.]*) *' . ' *([a-z][a-z0-9.]*) *'
. self::blockStartEnd . self::blockStartEnd
. '(.*?)' . '(.*?)'
. self::blockEndStart . self::blockEndStart
@ -66,7 +70,6 @@ class TplBlock {
} }
private function subBlockRegex($prefix, $blocName,$trim = true) { private function subBlockRegex($prefix, $blocName,$trim = true) {
echo "t".$trim;
return '/' return '/'
. self::blockStartStart . self::blockStartStart
. preg_quote($prefix . $blocName) . preg_quote($prefix . $blocName)

@ -1 +0,0 @@
Hello {{name}}

@ -34,6 +34,7 @@ class TplBlockTest extends TestCase{
) )
); );
$this->assertEquals("Hello Gnieark", $tpl->apply_tpl_file("temp.txt")); $this->assertEquals("Hello Gnieark", $tpl->apply_tpl_file("temp.txt"));
unlink("temp.txt");
} }
//test blocs //test blocs
@ -55,4 +56,21 @@ class TplBlockTest extends TestCase{
$this->assertFalse(strpos("WONT",$str)); $this->assertFalse(strpos("WONT",$str));
} }
//test if error on blocks names WTF
/**
* @expectedException InvalidTemplateException
*/
public function testIfErrorOnForbiddenName(){
$tpl = new TplBlock("kjsd54 65");
}
//test if error on blocks names WTF
/**
* @expectedException InvalidTemplateException
*/
public function testIfErrorOnForbiddenNameAgain(){
$tpl = new TplBlock("kjsd54.5");
}
} }
Loading…
Cancel
Save