cvs: pear /HTML_Template_PHPLIB/HTML/Template/PHPLIB Validator.php /HTML_Template_PHPLIB/tests HTML_Template_PHPLIB_ValidatorTest.php
| From: | Christian Weiske | Date: | Mon, 01 Oct 2007 17:02:58 +0000 |
| Subject: | cvs: pear /HTML_Template_PHPLIB/HTML/Template/PHPLIB Validator.php /HTML_Template_PHPLIB/tests HTML_Template_PHPLIB_ValidatorTest.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-48738@lists.php.net to get a copy of this message | ||
cweiske Mon Oct 1 17:02:58 2007 UTC
Modified files:
/pear/HTML_Template_PHPLIB/HTML/Template/PHPLIB Validator.php
/pear/HTML_Template_PHPLIB/tests
HTML_Template_PHPLIB_ValidatorTest.php
Log:
Check if opening/closing blocks match
http://cvs.php.net/viewvc.cgi/pear/HTML_Template_PHPLIB/HTML/Template/PHPLIB/Validator.php?r1=1.1&r2=1.2&diff_format=u
Index: pear/HTML_Template_PHPLIB/HTML/Template/PHPLIB/Validator.php
diff -u pear/HTML_Template_PHPLIB/HTML/Template/PHPLIB/Validator.php:1.1
pear/HTML_Template_PHPLIB/HTML/Template/PHPLIB/Validator.php:1.2
--- pear/HTML_Template_PHPLIB/HTML/Template/PHPLIB/Validator.php:1.1 Mon Oct 1 16:42:25 2007
+++ pear/HTML_Template_PHPLIB/HTML/Template/PHPLIB/Validator.php Mon Oct 1 17:02:58 2007
@@ -89,7 +89,46 @@
/**
* Check if all open blocks have a close counterpart
*/
-
+ foreach ($arBlockOpen as $strBlockName => $arLines) {
+ if (count($arLines) > 1) {
+ $arErrors[] = array(
+ 'short' => 'DUPLICATE_BLOCK',
+ 'message' => 'Block "' . $strBlockName .
'" is opened'
+ . ' several times on lines ' . implode(', ',
$arLines),
+ 'line' => $arLines[0],
+ 'code' => $strBlockName
+ );
+ }
+ if (!isset($arBlockClose[$strBlockName])) {
+ $arErrors[] = array(
+ 'short' => 'UNFINISHED_BLOCK',
+ 'message' => 'Block "' . $strBlockName .
'" is not closed.',
+ 'line' => $arLines[0],
+ 'code' => $strBlockName
+ );
+ }
+ }
+ foreach ($arBlockClose as $strBlockName => $arLines) {
+ if (count($arLines) > 1) {
+ $arErrors[] = array(
+ 'short' => 'DUPLICATE_BLOCK',
+ 'message' => 'Block "' . $strBlockName .
'" is closed'
+ . ' several times on lines ' . implode(', ',
$arLines),
+ 'line' => $arLines[0],
+ 'code' => $strBlockName
+ );
+ }
+ if (!isset($arBlockOpen[$strBlockName])) {
+ $arErrors[] = array(
+ 'short' => 'UNFINISHED_BLOCK',
+ 'message' => 'Block "' . $strBlockName .
'" is closed but not opened.',
+ 'line' => $arLines[0],
+ 'code' => $strBlockName
+ );
+ }
+ }
+
+ //TODO: Check proper nesting
return $arErrors;
}//function checkBlockDefinitions($strContent)
http://cvs.php.net/viewvc.cgi/pear/HTML_Template_PHPLIB/tests/HTML_Template_PHPLIB_ValidatorTest.php?r1=1.1&r2=1.2&diff_format=u
Index: pear/HTML_Template_PHPLIB/tests/HTML_Template_PHPLIB_ValidatorTest.php
diff -u pear/HTML_Template_PHPLIB/tests/HTML_Template_PHPLIB_ValidatorTest.php:1.1
pear/HTML_Template_PHPLIB/tests/HTML_Template_PHPLIB_ValidatorTest.php:1.2
--- pear/HTML_Template_PHPLIB/tests/HTML_Template_PHPLIB_ValidatorTest.php:1.1 Mon Oct 1 16:42:25
2007
+++ pear/HTML_Template_PHPLIB/tests/HTML_Template_PHPLIB_ValidatorTest.php Mon Oct 1 17:02:58 2007
@@ -149,10 +149,50 @@
),
$arErrors
);
+
+ //missing opening or closing blocks
+ $cont = <<<EOT
+<!-- BEGIN one -->
+<!-- BEGIN two -->
+<!-- END two -->
+<!-- END three -->
+<!-- BEGIN four -->
+<!-- BEGIN four -->
+<!-- END four -->
+<!-- BEGIN five -->
+<!-- END five -->
+<!-- END five -->
+EOT;
+ $arErrors = HTML_Template_PHPLIB_Validator::checkBlockDefinitions($cont);
+ $arErrors = self::stripMessages($arErrors);
+ $this->assertEquals(
+array (
+ array (
+ 'short' => 'UNFINISHED_BLOCK',
+ 'line' => 1,
+ 'code' => 'one',
+ ),
+ array (
+ 'short' => 'DUPLICATE_BLOCK',
+ 'line' => 5,
+ 'code' => 'four',
+ ),
+ array (
+ 'short' => 'UNFINISHED_BLOCK',
+ 'line' => 4,
+ 'code' => 'three',
+ ),
+ array (
+ 'short' => 'DUPLICATE_BLOCK',
+ 'line' => 9,
+ 'code' => 'five',
+ ),
+),
+ $arErrors
+ );
}
-
protected static function stripMessages($arErrors)
{
foreach ($arErrors as $nId => &$arError) {