Esempio n. 1
0
 /**
  * @covers \Erebot\DOM
  */
 public function testValidationFailure()
 {
     $dom = new \Erebot\DOM();
     $this->assertTrue($dom->load(__DIR__ . DIRECTORY_SEPARATOR . 'nok.xml'));
     $this->assertFalse($dom->relaxNGValidate(__DIR__ . DIRECTORY_SEPARATOR . 'test.rng'));
     $errors = $dom->getErrors();
     $this->assertSame(1, count($errors));
     // Inspect the error's contents.
     $this->assertSame(LIBXML_ERR_ERROR, $errors[0]->level);
     $this->assertSame('Wrong answer to life, the universe and everything', $errors[0]->message);
     $this->assertSame(__DIR__ . DIRECTORY_SEPARATOR . 'nok.xml', $errors[0]->file);
     $this->assertSame(2, $errors[0]->line);
     $this->assertSame('/Root', $errors[0]->path);
 }
Esempio n. 2
0
 /**
  * Parses a template into a DOM.
  *
  * \param string $source
  *      Template to parse.
  *
  * \retval Erebot::DOM
  *      DOM object constructed
  *      from the template.
  *
  * \throw ::InvalidArgumentException
  *      The template was malformed
  *      or invalid.
  */
 protected static function parseTemplate($source)
 {
     $source = '<msg xmlns="http://www.erebot.net/xmlns/erebot/styling">' . $source . '</msg>';
     $schema = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'styling.rng';
     $dom = new \Erebot\DOM();
     $dom->substituteEntities = true;
     $dom->resolveExternals = false;
     $dom->recover = true;
     $ue = libxml_use_internal_errors(true);
     $dom->loadXML($source);
     $valid = $dom->relaxNGValidate($schema);
     $errors = $dom->getErrors();
     libxml_use_internal_errors($ue);
     if (!$valid || count($errors)) {
         // Some unpredicted error occurred,
         // show some (hopefully) useful information.
         if (class_exists('\\Plop')) {
             $logger = \Plop::getInstance();
             $logger->error(print_r($errors, true));
         }
         throw new \InvalidArgumentException('Error while validating the message');
     }
     return $dom;
 }