permit alph-numeric and fix unit test

This commit is contained in:
Gnieark 2018-03-21 19:03:56 +01:00
parent bb11d05e7e
commit d4b06736f2
3 changed files with 23 additions and 3 deletions

View File

@ -31,9 +31,13 @@ class TplBlock {
public function __construct($name = NULL){
$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 = '/'
. self::blockStartStart
. ' *([a-z][a-z.]*) *'
. ' *([a-z][a-z0-9.]*) *'
. self::blockStartEnd
. '(.*?)'
. self::blockEndStart
@ -66,7 +70,6 @@ class TplBlock {
}
private function subBlockRegex($prefix, $blocName,$trim = true) {
echo "t".$trim;
return '/'
. self::blockStartStart
. preg_quote($prefix . $blocName)

View File

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

View File

@ -34,6 +34,7 @@ class TplBlockTest extends TestCase{
)
);
$this->assertEquals("Hello Gnieark", $tpl->apply_tpl_file("temp.txt"));
unlink("temp.txt");
}
//test blocs
@ -55,4 +56,21 @@ class TplBlockTest extends TestCase{
$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");
}
}