Ejemplo n.º 1
0
 public function validate()
 {
     $validation = parent::validate();
     if ($validation) {
         if (!isset($this->args['required']) || !$this->args['required']) {
             if ($this->value == '') {
                 return true;
             }
         }
         $url_absolute_preg = "/https?:\\/\\/(www\\.)?([a-zA-Z0-9-_]+)\\.([a-zA-Z0-9]{2,4})([\\/\\s])?/i";
         if (!preg_match($url_absolute_preg, $this->value)) {
             /* on vérifie alors que c'est une URL locale
              * A optimiser !!!
              *  */
             $path_match = "/^\\/(([a-zA-Z0-9])+\\/?)+(([a-zA-Z0-9])+\\.?([a-zA-Z0-9]){0,3})?\$/i";
             //vérifie qu'une URL ressemble à /path/to/file.php
             if (!preg_match($path_match, $this->value)) {
                 $this->error_msg = $this->label . ' n\'est pas une URL valide.';
                 return false;
             } else {
                 return true;
             }
         } else {
             return true;
         }
     }
     return $validation;
 }
Ejemplo n.º 2
0
 public function test_validation_input()
 {
     $name = 'nom';
     $value = 'test';
     $text = new Text($name, $value);
     $retour = $text->validate();
     $this->assertTrue($retour);
     $args = array('required' => true);
     $text = new Text($name, $value, null, $args);
     $retour = $text->validate();
     $this->assertTrue($retour);
     $text = new Text($name, null, null, $args);
     $retour = $text->validate();
     $this->assertFalse($retour);
     $text = new Text($name);
     $retour = $text->validate();
     $this->assertTrue($retour);
     $text = new Text($name, array('test' => 'test'));
     $retour = $text->validate();
     $this->assertFalse($retour);
 }