Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
--TEST--
2
uri.phpt: Unit tests for Validate::uri()
3
--FILE--
4
<?php
5
// $Id: uri.phpt 202483 2005-12-09 14:59:04Z toggg $
6
// Validate test script
7
$noYes = array('NO', 'YES');
8
require 'Validate.php';
9
 
10
echo "Test Validate::uri()\n";
11
 
12
$uris = array(
13
        // with no options (no domain_check and no allowed_schemes
14
        'not @ goodurl123' , // NOK
15
        'http://www.example.com//', // OK
16
        'http://www.example.com/', // OK
17
        'http://www.ics.uci.edu/pub/ietf/uri/#Related' , // OK
18
        'http://user:password@www.ics.uci.edu:8080/pub/ietf/uri;rfc2396?test=ok&end=next#Related' , // OK
19
        '//127.0.0.1', // OK
20
        '//127.0.333.1', // NOK
21
        'http://user:password@127.0.0.1:8080/pub/ietf/uri;rfc2396?test=ok&end=next#Related' , // OK
22
        '127.0.0.1', // NOK
23
        '//example.org/tkik-wkik_rss.php?ver=2http://www.hyperlecture.info//http://www.hyperlecture.info/accueil', // NOK default strict
24
        // minus serie
25
        '//example-minus.com', // OK
26
        '//example.co-m', // NOK (allowed by the rfc2396 but absent from TLDs)
27
        '//example-.com', // NOK
28
        '//-example.com', // NOK
29
        '//-.com', // NOK
30
        '//example.-com', // NOK
31
        '//-example.com-', // NOK
32
        // Try dns lookup
33
        array('//php.net', 'domain_check' => true), // OK
34
        array('//example.gor', 'domain_check' => true), // NOK
35
        // Try schemes lookup
36
        array('//example.org', 'allowed_schemes' => array('ftp', 'http')), // NOK
37
        array('http://example.org', 'allowed_schemes' => array('ftp', 'http')), // OK
38
        array('http://php.net', 'allowed_schemes' => array('ftp', 'http'),
39
                                    'domain_check' => true), // OK
40
        array(
41
        '//example.org/tkik-wkik_rss.php?ver=2http://www.hyperlecture.info//http://www.hyperlecture.info/accueil',
42
            'strict' => ''), // OK
43
/* the bjori's sequence */
44
        'http://domain.tld//', // OK
45
        'http://domain.tld/.', // OK
46
        'http://domain.tld/./folder/.././/.folder/subfolder/../../', // OK
47
        'http://domain.tld//./' // OK
48
    );
49
 
50
foreach ($uris as $uri) {
51
    if (is_array($uri)) {
52
        $options = $uri;
53
        unset($options[0]);
54
        echo "{$uri[0]}: schemes(" .
55
            (isset($options['allowed_schemes']) ?
56
                implode(',', $options['allowed_schemes']) : '') .") with".
57
            (isset($options['domain_check']) && $options['domain_check'] ?
58
                             '' : 'out') . ' domain check : '.
59
            (isset($options['strict']) ? "(strict : {$options['strict']}) " : '') .
60
            $noYes[Validate::uri($uri[0], $options )]."\n";
61
    } else {
62
        echo "{$uri}: ".
63
            $noYes[Validate::uri($uri)]."\n";
64
    }
65
}
66
?>
67
--EXPECT--
68
Test Validate::uri()
69
not @ goodurl123: NO
70
http://www.example.com//: YES
71
http://www.example.com/: YES
72
http://www.ics.uci.edu/pub/ietf/uri/#Related: YES
73
http://user:password@www.ics.uci.edu:8080/pub/ietf/uri;rfc2396?test=ok&end=next#Related: YES
74
//127.0.0.1: YES
75
//127.0.333.1: NO
76
http://user:password@127.0.0.1:8080/pub/ietf/uri;rfc2396?test=ok&end=next#Related: YES
77
127.0.0.1: NO
78
//example.org/tkik-wkik_rss.php?ver=2http://www.hyperlecture.info//http://www.hyperlecture.info/accueil: NO
79
//example-minus.com: YES
80
//example.co-m: NO
81
//example-.com: NO
82
//-example.com: NO
83
//-.com: NO
84
//example.-com: NO
85
//-example.com-: NO
86
//php.net: schemes() with domain check : YES
87
//example.gor: schemes() with domain check : NO
88
//example.org: schemes(ftp,http) without domain check : NO
89
http://example.org: schemes(ftp,http) without domain check : YES
90
http://php.net: schemes(ftp,http) with domain check : YES
91
//example.org/tkik-wkik_rss.php?ver=2http://www.hyperlecture.info//http://www.hyperlecture.info/accueil: schemes() without domain check : (strict : ) YES
92
http://domain.tld//: YES
93
http://domain.tld/.: YES
94
http://domain.tld/./folder/.././/.folder/subfolder/../../: YES
95
http://domain.tld//./: YES