Exemplo n.º 1
0
 public function testErrorPrinterWithCompositeValidator()
 {
     $v = new KeyValueSetValidator();
     $out = $v->getValidationOutput();
     $pr = $out->getErrorPrinter();
     $this->assertFalse(is_null($pr));
 }
Exemplo n.º 2
0
 public function testCollectedValuesWithCompoundedValidators()
 {
     $nameV = new SizeRangeValidator(new KeyValue("name", "fabs"), 6, 20, "", "");
     $surnameV = new SizeRangeValidator(new KeyValue("surname", "test"), 2, 20, "", "");
     $surnameV2 = new AlphaNumericalValidator(new KeyValue("surname", "test"), "");
     $composite2 = new KeyValueSetValidator();
     $composite2->addValidator(new NumericalValidator(new KeyValue("age", "12"), ""));
     $this->composite->addValidator($nameV);
     $this->composite->addValidator($surnameV);
     $this->composite->addValidator($surnameV2);
     $this->composite->addValidator($composite2);
     $collected = $this->composite->getCollectedValues();
     $this->assertEquals(count($collected), 3);
     $this->assertEquals($collected["name"], "fabs");
     $this->assertEquals($collected["surname"], "test");
     $this->assertEquals($collected["age"], "12");
 }
Exemplo n.º 3
0
      <?php 
include_once '../../src/phpv/autoload.php';
use phpv\input\KeyValue;
use phpv\validator\set\KeyValueSetValidator;
use phpv\validator\single\native\SizeRangeValidator;
use phpv\validator\single\native\DiversityValidator;
use phpv\validator\single\native\OneOfTheseValuesValidator;
use phpv\validator\single\native\TautologicValidator;
use phpv\validator\single\native\AlphaNumericalValidator;
use phpv\validator\single\native\AtLeastOnePositiveValidator;
use phpv\output\printer\HTMLErrorPrinter;
$output = null;
$valid = false;
if (isset($_POST["submit"])) {
    $form = new KeyValueSetValidator(new HTMLErrorPrinter());
    $name = KeyValue::obtainFromHTTP("name");
    $password = KeyValue::obtainFromHTTP("password");
    $gender = KeyValue::obtainFromHTTP("gender");
    $browser = KeyValue::obtainFromHTTP("browser");
    $thoughts = KeyValue::obtainFromHTTP("thoughts");
    $football = KeyValue::obtainFromHTTP("football");
    $tennis = KeyValue::obtainFromHTTP("tennis");
    $swimming = KeyValue::obtainFromHTTP("swimming");
    $nameValidator = new SizeRangeValidator($name, "name `%value%` must be between 3 and 20", 3, 20);
    $nameValidator2 = new AlphaNumericalValidator($name, "name must be alphanumerical");
    $passwordValidator = new SizeRangeValidator($password, "password between 3 and 20", 3, 20);
    $genderValidator = new OneOfTheseValuesValidator($gender, "only 'male' or 'female' are permitted", array("m", "f"));
    $browserValidator = new DiversityValidator($browser, "choose your browser of choice", "-");
    $thoughtsValidator = new SizeRangeValidator($thoughts, "keep thoughts between 20 and 100 chars", 20, 100);
    $footballValidator = new TautologicValidator($football);
Exemplo n.º 4
0
<?php

include_once '../../src/phpv/autoload.php';
use phpv\input\KeyValue;
use phpv\validator\set\KeyValueSetValidator;
use phpv\validator\single\native\SizeRangeValidator;
use phpv\validator\single\native\AlphaNumericalValidator;
use phpv\output\printer\CLIErrorPrinter;
$form = new KeyValueSetValidator(new CLIErrorPrinter());
$name = KeyValue::obtainFromCLI(0);
$nameValidator = new SizeRangeValidator($name, "the name must contain between 3 and 20 chars [provided > '%value%']", 3, 20);
$nameValidator2 = new AlphaNumericalValidator($name, "the name must not contain weird symbols [provided > '%value%']");
$form->addValidator($nameValidator);
$form->addValidator($nameValidator2);
$output = $form->getValidationOutput();
if ($output->isValid()) {
    fwrite(STDOUT, "Name is valid" . PHP_EOL);
} else {
    fwrite(STDOUT, $output->displayErrors());
}
Exemplo n.º 5
0
         <div class="col">
            <label>your name:</label>
            <input type="text" name="name" />

            <label>your password:</label>
            <input type="password" name="password" />

            <label>your gender:</label>
            <input type="radio" name="gender" value="m" checked="checked" /> male
            <input type="radio" name="gender" value="f" /> female
            <input type="radio" name="gender" value="non" /> non-permitted-value

            <label>your favourite browser:</label>

            <?php 
echo KeyValueSetValidator::select("browser", array("b1" => "firefox", "b2" => "chrome", "b3" => "ie", "b4" => "opera", "b5" => "safari"));
?>

            <p>
               <input type="submit" name="submit" value="submit" />
            </p>

         </div>

         <div class="col">

            <label>Tell me what you think:</label>
            <textarea name="thoughts" rows="5" cols="40"></textarea>

            <label>What sports do you like?</label>
            <input type="checkbox" name="football" /> football