/** * Validates a template file. * You can pass either a file name, or the file content. One of the parameters * needs to be !== null. * * @param string $strFile Template file name to check * @param string $strContent Template content to check * * @return mixed Boolean true if no errors have been found, array of * errors otherwise. An error is an array with keys * - 'short' (short error code, string) * - 'message' (readable message) * - 'line' (line number) * - 'code' (code that caused the error) * false if no file and content is given */ public static function validate($strFile = null, $strContent = null) { $arLines = HTML_Template_PHPLIB_Helper::getLines($strFile, $strContent); if ($arLines === false) { return false; } $arErrors = HTML_Template_PHPLIB_Validator::checkBlockDefinitions($arLines); $arErrors = array_merge($arErrors, HTML_Template_PHPLIB_Validator::checkVariables($arLines)); HTML_Template_PHPLIB_Validator::sortByLine($arErrors); return count($arErrors) == 0 ? true : $arErrors; }
public function testCheckBlockDefinitionsWrongNesting() { $cont = <<<EOT <!-- BEGIN one --> <!-- BEGIN two --> <!-- END one --> <!-- END two --> EOT; $arErrors = HTML_Template_PHPLIB_Validator::checkBlockDefinitions(HTML_Template_PHPLIB_Helper::getLines(null, $cont)); $arErrors = self::stripMessages($arErrors); $this->assertEquals(array(array('short' => 'WRONG_NESTING', 'line' => 3, 'code' => '<!-- END one -->')), $arErrors); }