예제 #1
0
 /**
  * @dataProvider getTestDocuments
  */
 public function testParseFile($from, $to)
 {
     if (!is_file($to)) {
         $this->markTestSkipped("Comparision file '{$to}' not yet defined.");
     }
     $tokenizer = new ezcDocumentBBCodeTokenizer();
     $parser = new ezcDocumentBBCodeParser();
     $parser->options->errorReporting = E_PARSE | E_ERROR | E_WARNING;
     $ast = $parser->parse($tokenizer->tokenizeFile($from));
     $expected = (include $to);
     // Store test file, to have something to compare on failure
     $tempDir = $this->createTempDir('bbcode_parser_') . '/';
     file_put_contents($tempDir . basename($to), "<?php\n\nreturn " . var_export($ast, true) . ";\n\n");
     $this->assertEquals($expected, $ast, 'Extracted ast do not match expected ast.');
     // Remove tempdir, when nothing failed.
     $this->removeTempDir();
 }
예제 #2
0
파일: bbcode.php 프로젝트: bmdevel/ezc
 /**
  * Validate the input string
  *
  * Validate the input string against the specification of the current
  * document format.
  *
  * Returns true, if the validation succeded, and an array with
  * ezcDocumentValidationError objects otherwise.
  *
  * @param string $string
  * @return mixed
  */
 public function validateString($string)
 {
     $tokenizer = new ezcDocumentBBCodeTokenizer();
     $parser = new ezcDocumentBBCodeParser();
     // Only halt on parse errors, and collect all other errors.
     $parser->options->errorReporting = E_PARSE;
     $errors = array();
     $ast = null;
     try {
         // Try to parse the document and keep the parse tree for evetual
         // checking for decoration errors
         $ast = $parser->parse($tokenizer->tokenizeString($string));
     } catch (ezcDocumentParserException $e) {
         $errors[] = $e;
     }
     // Get errors and notices from parsed document
     $errors = array_merge($errors, $parser->errors);
     // If we had no parse error until now, we also try to decorate the
     // document, which may leed to another class of errors.
     if ($ast !== null) {
         $oldErrorReporting = $this->options->errorReporting;
         $this->options->errorReporting = E_PARSE;
         try {
             $visitor = new ezcDocumentBBCodeDocbookVisitor($this, $this->path);
             $visitor->visit($ast, $this->path);
             // Get errors and notices from parsed document
             $errors = array_merge($errors, $visitor->getErrors());
         } catch (ezcDocumentVisitException $e) {
             $errors[] = $e;
         }
         // Reset error reporting
         $this->options->errorReporting = $oldErrorReporting;
     }
     if (count($errors) === 0) {
         // If no problem could be found, jsut return true
         return true;
     } else {
         // Transform aggregated errors into validation errors
         foreach ($errors as $nr => $error) {
             $errors[$nr] = ezcDocumentValidationError::createFromException($error);
         }
         return $errors;
     }
 }