public function testValidate()
 {
     $this->assertFalse(HTML_Template_PHPLIB_Validator::validate());
     $this->assertTrue(HTML_Template_PHPLIB_Validator::validate(null, ''));
     //check blocks from string
     $arErrors = HTML_Template_PHPLIB_Validator::validate(null, '<!-- BEGIN block -->');
     $this->assertInternalType('array', $arErrors);
     $this->assertEquals(1, count($arErrors));
     //check blocks from file
     $name = tempnam('/tmp', 'HTML_Template_PHPLIB-test');
     file_put_contents($name, '<!-- BEGIN blo -->');
     $arErrors = HTML_Template_PHPLIB_Validator::validate($name);
     $this->assertInternalType('array', $arErrors);
     $this->assertEquals(1, count($arErrors));
     unlink($name);
     //variables are checked, too
     $arErrors = HTML_Template_PHPLIB_Validator::validate(null, '{PARTIAL');
     $this->assertInternalType('array', $arErrors);
     $this->assertEquals(1, count($arErrors));
 }
示例#2
0
 /**
  * Validates the files given on the cmdline
  *
  * @param array $args Command line arguments (files)
  *
  * @return void
  */
 function doValidate($args)
 {
     if (count($args) == 0) {
         $this->dieHard("No template files to validate\n", 1);
     }
     include_once 'HTML/Template/PHPLIB/Validator.php';
     $nError = 0;
     foreach ($args as $file) {
         if (file_exists($file)) {
             $arErrors = HTML_Template_PHPLIB_Validator::validate($file);
             if ($arErrors === true) {
                 echo 'No errors found in ' . $file . "\n";
                 $nError = 0;
             } else {
                 if ($arErrors === false) {
                     echo 'Some unexpected error in ' . $file . "\n";
                     $nError = 3;
                 } else {
                     echo count($arErrors) . ' errors in ' . $file . "\n";
                     foreach ($arErrors as $arError) {
                         echo ' Line #' . $arError['line'] . ': ' . $arError['message'] . "\n";
                     }
                     $nError = 10;
                 }
             }
         } else {
             echo 'File does not exist: ' . $file . "\n";
             $nError = 4;
         }
     }
     $this->dieHard('', $nError);
 }