Ejemplo n.º 1
0
 public function testValidationStrict()
 {
     $path = 'Configuration/tests/files/simple-errors.ini';
     $backend = new ezcConfigurationIniReader($path);
     $return = $backend->validate(true);
     $expected = new ezcConfigurationValidationResult($backend->getLocation(), $backend->getName(), $path);
     $expected->isValid = false;
     $item = new ezcConfigurationValidationItem(ezcConfigurationValidationItem::ERROR, $path, 8, false, "Invalid data: 'c8756*&%&^%&%\$&C%\$%C*@%C*\$'", "Invalid data: 'c8756*&%&^%&%\$&C%\$%C*@%C*\$'");
     $expected->appendItem($item);
     $this->assertEquals($expected, $return);
 }
Ejemplo n.º 2
0
 /**
  * Validates the configuration.
  *
  * Validates the configuration at the given location and returns the
  * validation result.
  *
  * If $strict is set it will not validate the file if it contains any
  * errors or warnings. If false it will allow warnings but not errors.
  *
  * @param bool $strict
  * @return ezcConfigurationValidationResult
  */
 public function validate($strict = false)
 {
     $parserType = $strict ? ezcConfigurationIniParser::VALIDATE_STRICT : ezcConfigurationIniParser::VALIDATE;
     $parser = new ezcConfigurationIniParser($parserType, $this->path);
     $validationResult = new ezcConfigurationValidationResult($this->location, $this->name, $this->path);
     foreach (new NoRewindIterator($parser) as $element) {
         if ($element instanceof ezcConfigurationIniItem) {
             throw new Exception("A validating parser emitted a configuration item, which should never happen");
         }
         if ($element instanceof ezcConfigurationValidationItem) {
             $validationResult->appendItem($element);
             if ($element->type == ezcConfigurationValidationItem::ERROR) {
                 $validationResult->isValid = false;
             } else {
                 if ($element->type == ezcConfigurationValidationItem::WARNING && $parserType == ezcConfigurationIniItem::VALIDATE_STRICT) {
                     $validationResult->isValid = false;
                 }
             }
         }
     }
     return $validationResult;
 }