public function testNotExistantFile()
 {
     try {
         $tokenizer = new ezcDocumentRstTokenizer();
         $tokens = $tokenizer->tokenizeFile(dirname(__FILE__) . '/files/rst/tokenizer/not_existant_file.txt');
         $this->fail('Expected ezcBaseFileNotFoundException.');
     } catch (ezcBaseFileNotFoundException $e) {
         /* Expected */
     }
 }
Esempio n. 2
0
 /**
  * @dataProvider getErroneousTestDocuments
  */
 public function testParseErroneousRstFile($file, $message)
 {
     $tokenizer = new ezcDocumentRstTokenizer();
     $parser = new ezcDocumentRstParser();
     try {
         $document = $parser->parse($tokenizer->tokenizeFile($file));
         $this->fail('Expected ezcDocumentRstParserException.');
     } catch (ezcDocumentParserException $e) {
         $this->assertSame($message, $e->getMessage(), 'Different parse error expected.');
     }
 }
Esempio n. 3
0
 /**
  * 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 ezcDocumentRstTokenizer();
     $parser = new ezcDocumentRstParser();
     // 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 ezcDocumentRstDocbookVisitor($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;
     }
 }