2d3a630b |
1 | <?php |
4b4abf93 |
2 | |
2d3a630b |
3 | /** |
4 | * SquirrelMail time zone library - time zone validation script. |
5 | * |
4b28020b |
6 | * @copyright 2005-2023 The SquirrelMail Project Team |
4b4abf93 |
7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
2d3a630b |
8 | * @version $Id$ |
9 | * @package squirrelmail |
10 | * @subpackage timezones |
11 | */ |
12 | |
13 | /** @ignore */ |
14 | define('SM_PATH','../../'); |
15 | |
16 | /** Send http header */ |
17 | header('Content-Type: text/plain'); |
18 | |
19 | /** Information about script */ |
20 | echo "--------------------------------------------\n" |
21 | ." SquirrelMail time zone library test script\n" |
22 | ."--------------------------------------------\n"; |
23 | |
24 | /** load SM config */ |
25 | unset($time_zone_type); |
26 | if (file_exists(SM_PATH.'config/config.php')) { |
27 | include(SM_PATH.'config/config.php'); |
28 | } else { |
29 | echo "SquirrelMail configuration file is missing.\n"; |
30 | exit(); |
31 | } |
32 | |
33 | /** |
34 | * Script does not test, if standard time zone libraries are missing. |
35 | * If they are missing or corrupted - php can fail, scream and show |
36 | * finger or other parts of interpreter. |
37 | */ |
38 | |
39 | /** load original reference */ |
40 | include(SM_PATH.'include/timezones/standard_orig.php'); |
41 | |
42 | /** move timezones to different array */ |
43 | $aTimeZonesOrig = $aTimeZones; |
44 | unset($aTimeZones); |
45 | |
46 | if (! isset($time_zone_type) || $time_zone_type == 0 || $time_zone_type == 1) { |
47 | /** load new time zone library */ |
48 | include(SM_PATH.'include/timezones/standard.php'); |
49 | } elseif ($time_zone_type == 2 || $time_zone_type == 3) { |
50 | /** load custom time zone library */ |
51 | $aTimeZones=array(); |
52 | if (file_exists(SM_PATH . 'config/timezones.php')) { |
53 | include(SM_PATH.'config/timezones.php'); |
54 | } else { |
55 | echo "ERROR: config/timezones.php is missing.\n"; |
56 | exit(); |
57 | } |
58 | } else { |
59 | echo "ERROR: invalid value in time_zone_type configuration.\n"; |
60 | exit(); |
61 | } |
62 | |
63 | if (! isset($aTimeZones) || ! is_array($aTimeZones) || empty($aTimeZones)) { |
64 | echo "ERROR: timezones array is missing or empty.\n"; |
65 | exit(); |
66 | } |
67 | |
68 | $error = false; |
69 | |
70 | /** test backward compatibility */ |
71 | echo "Testing backward compatibility:\n" |
72 | ." Failed time zones:\n"; |
73 | foreach ($aTimeZonesOrig as $TzKey => $TzData) { |
74 | if (! isset($aTimeZones[$TzKey])) { |
75 | echo ' '.$TzKey."\n"; |
76 | $error = true; |
77 | } |
78 | } |
79 | if (! $error) { |
80 | echo " none. Looking good.\n"; |
81 | } else { |
82 | // error is not fatal, but test should fail only with limited custom time zone sets |
83 | } |
84 | |
85 | echo "\n"; |
86 | |
87 | /** test forward compatibility */ |
88 | $error = false; |
89 | echo "Testing forward compatibility:\n" |
90 | ." New time zones:\n"; |
91 | foreach ($aTimeZones as $TzKey => $TzData) { |
92 | if (! isset($aTimeZonesOrig[$TzKey])) { |
93 | echo ' '.$TzKey."\n"; |
94 | $error = true; |
95 | } |
96 | } |
97 | if (! $error) { |
98 | echo " no new time zones.\n"; |
99 | } else { |
100 | // error is not fatal. test should show new time zones, that are not |
101 | // present in timezones.cfg |
102 | } |
103 | |
104 | echo "\n"; |
105 | |
106 | /** test links */ |
107 | $error = false; |
108 | echo "Testing time zone links:\n" |
109 | ." Failed time zone links:\n"; |
110 | foreach ($aTimeZones as $TzKey => $TzData) { |
111 | if (isset($TzData['LINK']) && ! isset($aTimeZones[$TzData['LINK']]['TZ'])) { |
112 | echo ' '.$TzKey.' = '.$TzData['LINK']."\n"; |
113 | $error = true; |
114 | } |
115 | } |
116 | if (! $error) { |
117 | echo " none. Looking good.\n"; |
118 | } else { |
119 | // error is fatal. 'LINK' should always reffer to existing 'TZ' entries |
120 | } |
121 | |
122 | echo "\n"; |
123 | |
124 | /** Test TZ subkeys */ |
125 | $error = false; |
126 | echo "Testing time zone TZ subkeys:\n" |
127 | ." Failed time zone TZ subkeys:\n"; |
128 | foreach ($aTimeZones as $TzKey => $TzData) { |
129 | if (! isset($TzData['LINK']) && ! isset($TzData['TZ'])) { |
130 | echo ' '.$TzKey."\n"; |
131 | $error = true; |
132 | } |
133 | } |
134 | if (! $error) { |
135 | echo " none. Looking good.\n"; |
136 | } else { |
137 | // LINK or TZ are required for strict time zones. Interface won't break, but |
138 | // any error means inconsistency in time zone array. |
139 | } |
140 | |
141 | echo "\n"; |
142 | |
143 | /** Test NAME subkeys */ |
144 | $error = false; |
145 | echo "Testing time zone NAME subkeys:\n" |
146 | ." Time zones without NAME subkeys:\n"; |
147 | foreach ($aTimeZones as $TzKey => $TzData) { |
148 | if (isset($TzData['TZ']) && ! isset($TzData['NAME'])) { |
149 | echo ' '.$TzKey."\n"; |
150 | $error = true; |
151 | } |
152 | } |
153 | if (! $error) { |
154 | echo " none.\n"; |
155 | } else { |
156 | // error is not fatal. It would be nice if all geographic locations |
157 | // use some human readable name |
158 | } |
159 | |
160 | echo "\n"; |
161 | |
f1e423b2 |
162 | /** Test NAME subkeys */ |
163 | $error = false; |
164 | echo " Time zones with empty NAME subkeys:\n"; |
165 | foreach ($aTimeZones as $TzKey => $TzData) { |
166 | if (isset($TzData['NAME']) && empty($TzData['NAME'])) { |
167 | echo ' '.$TzKey."\n"; |
168 | $error = true; |
169 | } |
170 | } |
171 | if (! $error) { |
172 | echo " none. Looking good\n"; |
173 | } else { |
174 | // error is fatal. NAME should not be empty string. |
175 | } |
176 | |
177 | echo "\n"; |
178 | |
2d3a630b |
179 | /** Test TZ subkeys with UCT/UTC/GMT offsets */ |
180 | $error = false; |
181 | echo "Testing TZ subkeys with UCT/UTC/GMT offsets:\n" |
182 | ." Time zones UCT/UTC/GMT offsets:\n"; |
183 | foreach ($aTimeZones as $TzKey => $TzData) { |
184 | if (isset($TzData['TZ']) && preg_match("/^(UCT)|(UTC)|(GMT).+/i",$TzData['TZ'])) { |
185 | echo ' '.$TzKey.' = '.$TzData['TZ']."\n"; |
186 | $error = true; |
187 | } |
188 | } |
189 | if (! $error) { |
190 | echo " none.\n"; |
191 | } else { |
192 | // I think error is fatal for UCT with offsets. date('T',time()) is corrupted. |
193 | } |
194 | |
195 | echo "\n"; |
196 | |
197 | /** Test TZ subkeys with custom TZ values and no offsets */ |
198 | $error = false; |
199 | echo "Testing TZ subkeys with custom TZ values and no offsets:\n" |
200 | ." Time zones with custom TZ values and no offsets:\n"; |
201 | foreach ($aTimeZones as $TzKey => $TzData) { |
202 | if (isset($TzData['TZ']) && |
203 | ! preg_match("/^((UCT)|(UTC)|(GMT).+)|(GMT)$/i",$TzData['TZ']) && |
204 | preg_match("/^[a-z]+$/i",$TzData['TZ'])) { |
205 | echo ' '.$TzKey.' = '.$TzData['TZ']."\n"; |
206 | $error = true; |
207 | } |
208 | } |
209 | if (! $error) { |
210 | echo " none.\n"; |
211 | } else { |
212 | // I think error is fatal. Time zone formating requires time zone name and offset from GMT. |
213 | } |
214 | |
215 | echo "\n"; |
216 | |
217 | echo "Done!\n"; |