File: multiple.phpt

package info (click to toggle)
php-validate 0.8.5-4.2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 244 kB
  • sloc: php: 758; xml: 492; makefile: 2
file content (53 lines) | stat: -rw-r--r-- 1,470 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
--TEST--
multiple.phpt: Unit tests for 'Validate.php' without extension (credit card)
--FILE--
<?php
// $Id$
// Validate test script
$noYes = array('NO', 'YES');

require_once 'Validate.php';

$types = array(
    'myemail'    => array('type' => 'email'),
    'myemail1'   => array('type' => 'email'),
    'no'         => array('type' => 'number', array('min' => -8, 'max' => -7)),
    'teststring' => array('type' => 'string', array('format' => VALIDATE_ALPHA)),
    'test10844'  => array('type' => 'string', 'format' => '0-9'),
    'date'       => array('type' => 'date',   array('format' => '%d%m%Y'))
);

$data  = array(
    array(
    'myemail' => 'webmaster@google.com', // OK
    'myemail1' => 'webmaster.@google.com', // NOK
    'no' => '-8', // OK
    'teststring' => 'PEARrocks', // OK
    'test10844' => 'dsfasdf', // NOK
    'date' => '12121996' // OK
    )
);

echo "Test Validate_Multiple\n";
echo "**********************\n\n";
foreach ($data as $value) {
    $res = Validate::multiple($value, $types);
    foreach ($value as $fld=>$val) {
        echo "{$fld}: {$val} =>".(isset($res[$fld])? $noYes[$res[$fld]]: 'null')."\n";
    }
    echo "*****************************************\n\n";
}

?>
--EXPECT--
Test Validate_Multiple
**********************

myemail: webmaster@google.com =>YES
myemail1: webmaster.@google.com =>NO
no: -8 =>YES
teststring: PEARrocks =>YES
test10844: dsfasdf =>NO
date: 12121996 =>YES
*****************************************