| 1 |
lars |
1 |
--TEST--
|
|
|
2 |
File_Sitemap: Validate different possible input parameters.
|
|
|
3 |
--FILE--
|
|
|
4 |
<?php
|
|
|
5 |
require_once "File/Sitemap.php";
|
|
|
6 |
|
|
|
7 |
$sm = new File_Sitemap();
|
|
|
8 |
|
|
|
9 |
echo "1 validate loc\n--------------------\n";
|
|
|
10 |
|
|
|
11 |
$u = array('http://www.php.net/', 'ftp://ftp.php.net/file.txt', 'https://secure.php.net/',
|
|
|
12 |
'http://pear.php.net/manual/en/core.pear.pear-exception.intro.php',
|
|
|
13 |
'http://mysite.net/caractères_spéciaux.php', 'http://mysite.net/query.php?a=0&b=1&c=4',
|
|
|
14 |
'www.google.com', 'abcde', 'rsync:///myserver.net');
|
|
|
15 |
foreach ($u as $uu) {
|
|
|
16 |
echo $uu.": ";
|
|
|
17 |
try {
|
|
|
18 |
$sm->add($uu);
|
|
|
19 |
echo "OK\n";
|
|
|
20 |
}
|
|
|
21 |
catch (File_Sitemap_Exception $e)
|
|
|
22 |
{
|
|
|
23 |
echo "Exception: ".$e->getCode().": ".$e->getMessage()."\n";
|
|
|
24 |
}
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
echo "2 validate lastmod\n--------------------\n";
|
|
|
28 |
|
|
|
29 |
$lm = array('2008', '2008-04', '2008-04-12', '2008-04-12T18:20Z', '2008-04-12T18:20+05:00',
|
|
|
30 |
'2008-04-12T18:20:31-04:00', '2008-04-12T18:20:31.118-04:00', 'Apr. 12, 2008', '20h27',
|
|
|
31 |
'abcdef');
|
|
|
32 |
foreach ($lm as $lmlm) {
|
|
|
33 |
echo $lmlm.": ";
|
|
|
34 |
try {
|
|
|
35 |
$sm->add("http://www.php.net/", 0.5, null, $lmlm);
|
|
|
36 |
echo "OK\n";
|
|
|
37 |
}
|
|
|
38 |
catch (File_Sitemap_Exception $e)
|
|
|
39 |
{
|
|
|
40 |
echo "Exception: ".$e->getCode().": ".$e->getMessage()."\n";
|
|
|
41 |
}
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
echo "3 validate changefreq\n--------------------\n";
|
|
|
45 |
|
|
|
46 |
$cf = array('always', 'hourly', 'daily', 'weekly', 'monthly',
|
|
|
47 |
'yearly', 'never', 0, 'stchroumph');
|
|
|
48 |
foreach ($cf as $cfcf) {
|
|
|
49 |
echo $cfcf.": ";
|
|
|
50 |
try {
|
|
|
51 |
$sm->add("http://www.php.net/", 0.5, $cfcf);
|
|
|
52 |
echo "OK\n";
|
|
|
53 |
}
|
|
|
54 |
catch (File_Sitemap_Exception $e)
|
|
|
55 |
{
|
|
|
56 |
echo "Exception: ".$e->getCode().": ".$e->getMessage()."\n";
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
echo "4 validate priority\n--------------------\n";
|
|
|
61 |
|
|
|
62 |
$p = array(-1, 0, 0.5, 0.8, 1, 2, "-1", "0", "0.0", ".5", "0.85", "1.2", "a");
|
|
|
63 |
foreach ($p as $pp) {
|
|
|
64 |
echo $pp.": ";
|
|
|
65 |
try {
|
|
|
66 |
$sm->add("http://www.php.net/", $pp);
|
|
|
67 |
echo "OK\n";
|
|
|
68 |
}
|
|
|
69 |
catch (File_Sitemap_Exception $e)
|
|
|
70 |
{
|
|
|
71 |
echo "Exception: ".$e->getCode().": ".$e->getMessage()."\n";
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
?>
|
|
|
76 |
--EXPECT--
|
|
|
77 |
1 validate loc
|
|
|
78 |
--------------------
|
|
|
79 |
http://www.php.net/: OK
|
|
|
80 |
ftp://ftp.php.net/file.txt: OK
|
|
|
81 |
https://secure.php.net/: OK
|
|
|
82 |
http://pear.php.net/manual/en/core.pear.pear-exception.intro.php: OK
|
|
|
83 |
http://mysite.net/caractères_spéciaux.php: OK
|
|
|
84 |
http://mysite.net/query.php?a=0&b=1&c=4: OK
|
|
|
85 |
www.google.com: Exception: 2000: URL must begin with a protocol (http, https, ftp).
|
|
|
86 |
abcde: Exception: 2000: URL must begin with a protocol (http, https, ftp).
|
|
|
87 |
rsync:///myserver.net: Exception: 2000: URL must begin with a protocol (http, https, ftp).
|
|
|
88 |
2 validate lastmod
|
|
|
89 |
--------------------
|
|
|
90 |
2008: OK
|
|
|
91 |
2008-04: OK
|
|
|
92 |
2008-04-12: OK
|
|
|
93 |
2008-04-12T18:20Z: OK
|
|
|
94 |
2008-04-12T18:20+05:00: OK
|
|
|
95 |
2008-04-12T18:20:31-04:00: OK
|
|
|
96 |
2008-04-12T18:20:31.118-04:00: OK
|
|
|
97 |
Apr. 12, 2008: OK
|
|
|
98 |
20h27: Exception: 2000: unable to parse date time string.
|
|
|
99 |
abcdef: Exception: 2000: unable to parse date time string.
|
|
|
100 |
3 validate changefreq
|
|
|
101 |
--------------------
|
|
|
102 |
always: OK
|
|
|
103 |
hourly: OK
|
|
|
104 |
daily: OK
|
|
|
105 |
weekly: OK
|
|
|
106 |
monthly: OK
|
|
|
107 |
yearly: OK
|
|
|
108 |
never: OK
|
|
|
109 |
0: Exception: 2000: changefreq must be one of always, hourly, daily, weekly, monthly, yearly or never.
|
|
|
110 |
stchroumph: Exception: 2000: changefreq must be one of always, hourly, daily, weekly, monthly, yearly or never.
|
|
|
111 |
4 validate priority
|
|
|
112 |
--------------------
|
|
|
113 |
-1: OK
|
|
|
114 |
0: OK
|
|
|
115 |
0.5: OK
|
|
|
116 |
0.8: OK
|
|
|
117 |
1: OK
|
|
|
118 |
2: OK
|
|
|
119 |
-1: OK
|
|
|
120 |
0: OK
|
|
|
121 |
0.0: OK
|
|
|
122 |
.5: OK
|
|
|
123 |
0.85: OK
|
|
|
124 |
1.2: OK
|
|
|
125 |
a: Exception: 2000: priority must be a number between 0.0 and 1.0.
|