/**
  * Test combining validation results together
  */
 public function testCombineResults()
 {
     $result = new ValidationResult();
     $anotherresult = new ValidationResult();
     $yetanotherresult = new ValidationResult();
     $anotherresult->error("Eat with your mouth closed", "EATING101");
     $yetanotherresult->error("You didn't wash your hands", "BECLEAN");
     $this->assertTrue($result->valid());
     $this->assertFalse($anotherresult->valid());
     $this->assertFalse($yetanotherresult->valid());
     $result->combineAnd($anotherresult)->combineAnd($yetanotherresult);
     $this->assertFalse($result->valid());
     $this->assertEquals(array("EATING101" => "Eat with your mouth closed", "BECLEAN" => "You didn't wash your hands"), $result->messageList());
 }
Ejemplo n.º 2
0
 /**
  * Validate the owner object - check for existence of infinite loops.
  *
  * @param ValidationResult $validationResult
  */
 public function validate(ValidationResult $validationResult)
 {
     // The object is new, won't be looping.
     if (!$this->owner->ID) {
         return;
     }
     // The object has no parent, won't be looping.
     if (!$this->owner->ParentID) {
         return;
     }
     // The parent has not changed, skip the check for performance reasons.
     if (!$this->owner->isChanged('ParentID')) {
         return;
     }
     // Walk the hierarchy upwards until we reach the top, or until we reach the originating node again.
     $node = $this->owner;
     while ($node) {
         if ($node->ParentID == $this->owner->ID) {
             // Hierarchy is looping.
             $validationResult->error(_t('Hierarchy.InfiniteLoopNotAllowed', 'Infinite loop found within the "{type}" hierarchy. Please change the parent to resolve this', 'First argument is the class that makes up the hierarchy.', array('type' => $this->owner->class)), 'INFINITE_LOOP');
             break;
         }
         $node = $node->ParentID ? $node->Parent() : null;
     }
     // At this point the $validationResult contains the response.
 }
Ejemplo n.º 3
0
 /**
  * Hook to validate this record against a validation result
  *
  * @param ValidationResult $result
  * @param string $filename Optional filename to validate. If omitted, the current value is validated.
  * @return bool Valid flag
  */
 public function validate(ValidationResult $result, $filename = null)
 {
     if (empty($filename)) {
         $filename = $this->getFilename();
     }
     if (empty($filename) || $this->isValidFilename($filename)) {
         return true;
     }
     // Check allowed extensions
     $extensions = $this->getAllowedExtensions();
     if (empty($extensions)) {
         $extensions = File::config()->allowed_extensions;
     }
     sort($extensions);
     $message = _t('File.INVALIDEXTENSION', 'Extension is not allowed (valid: {extensions})', 'Argument 1: Comma-separated list of valid extensions', array('extensions' => wordwrap(implode(', ', $extensions))));
     $result->error($message);
     return false;
 }