close #4
master
Gnieark 6 years ago committed by GitHub
commit 9b65ed9f32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -207,19 +207,6 @@ class TplBlock
. '/is';
}
/**
* Make some tests to check template consistency.
* Return error message if needed, return 1 otherwise.
*
* @param string $str the string to check
* @return string message
*/
public function checkConsistency($str){
return 1;
}
/**
* Shake the template string and input vars then returns the parsed text.
*
@ -231,14 +218,6 @@ class TplBlock
*/
public function applyTplStr($str, $subBlocsPath = "")
{
if($this->strictMode){
$consistency = self::checkConsistency($str);
if($consistency <> 1 ){
throw new \UnexpectedValueException($consistency);
}
}
// Replace all simple vars.
$prefix = $subBlocsPath === "" ? "" : $subBlocsPath . ".";
@ -278,6 +257,17 @@ class TplBlock
$str = preg_replace( "/" .self::STARTENCLOSURE .'([a-z][a-z0-9.]*)' .self::ENDENCLOSURE ."/", '', $str );
}
//check if loops patterns are still presents
if (($this->strictMode)
&& (
preg_match( "/".self::BLOCKSTARTSTART."/", $str)
|| preg_match( "/".self::BLOCKENDSTART."/", $str)
)
){
throw new \UnexpectedValueException("Template string not consistent");
}
return $str;
}

@ -183,5 +183,37 @@ class TplBlockTest extends TestCase
$this->assertFalse(strpos("name", $resultWithReplace));
}
/**
* Test if error on non consistent tpl.
* @expectedException UnexpectedValueException
*/
public function testNonConsistentTemplate(){
$str = "
Bhah blah wpooie456
<!-- BEGIN bloc -->
have to be shown
<!-- BEGIN blocTwo -->
SHOULD be shown
<!-- END bloc -->
WONT to be shown
<!-- END blocTwo -->";
$tpl = new TplBlock();
$tpl->applyTplStr($str);
}
public function testNonConsistentTemplateNonStrictMode(){
$str = "
Bhah blah wpooie456
<!-- BEGIN bloc -->
have to be shown
<!-- BEGIN blocTwo -->
SHOULD be shown
<!-- END bloc -->
WONT to be shown
<!-- END blocTwo -->";
$tpl = new TplBlock();
$tpl-> dontStrictMode();
$this->assertContains("wpooie456",$tpl-> applyTplStr($str));
}
}

Loading…
Cancel
Save