From 8149c44997facf1fa7b406dfcd3fdad8f61afd34 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 2 Apr 2018 15:19:23 +0200 Subject: [PATCH] close #4 --- TplBlock.php | 32 +++++++++++--------------------- test/TplBlockTest.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/TplBlock.php b/TplBlock.php index e4b9c72..33d1b68 100644 --- a/TplBlock.php +++ b/TplBlock.php @@ -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; } diff --git a/test/TplBlockTest.php b/test/TplBlockTest.php index 04ee1ca..e8ba250 100644 --- a/test/TplBlockTest.php +++ b/test/TplBlockTest.php @@ -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 + + have to be shown + + SHOULD be shown + + WONT to be shown + "; + $tpl = new TplBlock(); + $tpl->applyTplStr($str); + } + public function testNonConsistentTemplateNonStrictMode(){ + $str = " + Bhah blah wpooie456 + + have to be shown + + SHOULD be shown + + WONT to be shown + "; + $tpl = new TplBlock(); + $tpl-> dontStrictMode(); + $this->assertContains("wpooie456",$tpl-> applyTplStr($str)); + } }