1 <?php |
|
2 /** |
|
3 * Smarty Internal TestInstall |
|
4 * Test Smarty installation |
|
5 * |
|
6 * @package Smarty |
|
7 * @subpackage Utilities |
|
8 * @author Uwe Tews |
|
9 */ |
|
10 |
|
11 /** |
|
12 * TestInstall class |
|
13 * |
|
14 * @package Smarty |
|
15 * @subpackage Utilities |
|
16 */ |
|
17 class Smarty_Internal_TestInstall { |
|
18 /** |
|
19 * diagnose Smarty setup |
|
20 * If $errors is secified, the diagnostic report will be appended to the array, rather than being output. |
|
21 * |
|
22 * @param Smarty $smarty Smarty instance to test |
|
23 * @param array $errors array to push results into rather than outputting them |
|
24 * |
|
25 * @return bool status, true if everything is fine, false else |
|
26 */ |
|
27 public static function testInstall(Smarty $smarty, &$errors = null) { |
|
28 $status = true; |
|
29 |
|
30 if ($errors === null) { |
|
31 echo "<PRE>\n"; |
|
32 echo "Smarty Installation test...\n"; |
|
33 echo "Testing template directory...\n"; |
|
34 } |
|
35 |
|
36 $_stream_resolve_include_path = function_exists('stream_resolve_include_path'); |
|
37 |
|
38 // test if all registered template_dir are accessible |
|
39 foreach ($smarty->getTemplateDir() as $template_dir) { |
|
40 $_template_dir = $template_dir; |
|
41 $template_dir = realpath($template_dir); |
|
42 // resolve include_path or fail existence |
|
43 if (!$template_dir) { |
|
44 if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_template_dir)) { |
|
45 // try PHP include_path |
|
46 if ($_stream_resolve_include_path) { |
|
47 $template_dir = stream_resolve_include_path($_template_dir); |
|
48 } else { |
|
49 $template_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_template_dir); |
|
50 } |
|
51 |
|
52 if ($template_dir !== false) { |
|
53 if ($errors === null) { |
|
54 echo "$template_dir is OK.\n"; |
|
55 } |
|
56 |
|
57 continue; |
|
58 } else { |
|
59 $status = false; |
|
60 $message = "FAILED: $_template_dir does not exist (and couldn't be found in include_path either)"; |
|
61 if ($errors === null) { |
|
62 echo $message . ".\n"; |
|
63 } else { |
|
64 $errors['template_dir'] = $message; |
|
65 } |
|
66 |
|
67 continue; |
|
68 } |
|
69 } else { |
|
70 $status = false; |
|
71 $message = "FAILED: $_template_dir does not exist"; |
|
72 if ($errors === null) { |
|
73 echo $message . ".\n"; |
|
74 } else { |
|
75 $errors['template_dir'] = $message; |
|
76 } |
|
77 |
|
78 continue; |
|
79 } |
|
80 } |
|
81 |
|
82 if (!is_dir($template_dir)) { |
|
83 $status = false; |
|
84 $message = "FAILED: $template_dir is not a directory"; |
|
85 if ($errors === null) { |
|
86 echo $message . ".\n"; |
|
87 } else { |
|
88 $errors['template_dir'] = $message; |
|
89 } |
|
90 } elseif (!is_readable($template_dir)) { |
|
91 $status = false; |
|
92 $message = "FAILED: $template_dir is not readable"; |
|
93 if ($errors === null) { |
|
94 echo $message . ".\n"; |
|
95 } else { |
|
96 $errors['template_dir'] = $message; |
|
97 } |
|
98 } else { |
|
99 if ($errors === null) { |
|
100 echo "$template_dir is OK.\n"; |
|
101 } |
|
102 } |
|
103 } |
|
104 |
|
105 if ($errors === null) { |
|
106 echo "Testing compile directory...\n"; |
|
107 } |
|
108 |
|
109 // test if registered compile_dir is accessible |
|
110 $__compile_dir = $smarty->getCompileDir(); |
|
111 $_compile_dir = realpath($__compile_dir); |
|
112 if (!$_compile_dir) { |
|
113 $status = false; |
|
114 $message = "FAILED: {$__compile_dir} does not exist"; |
|
115 if ($errors === null) { |
|
116 echo $message . ".\n"; |
|
117 } else { |
|
118 $errors['compile_dir'] = $message; |
|
119 } |
|
120 } elseif (!is_dir($_compile_dir)) { |
|
121 $status = false; |
|
122 $message = "FAILED: {$_compile_dir} is not a directory"; |
|
123 if ($errors === null) { |
|
124 echo $message . ".\n"; |
|
125 } else { |
|
126 $errors['compile_dir'] = $message; |
|
127 } |
|
128 } elseif (!is_readable($_compile_dir)) { |
|
129 $status = false; |
|
130 $message = "FAILED: {$_compile_dir} is not readable"; |
|
131 if ($errors === null) { |
|
132 echo $message . ".\n"; |
|
133 } else { |
|
134 $errors['compile_dir'] = $message; |
|
135 } |
|
136 } elseif (!is_writable($_compile_dir)) { |
|
137 $status = false; |
|
138 $message = "FAILED: {$_compile_dir} is not writable"; |
|
139 if ($errors === null) { |
|
140 echo $message . ".\n"; |
|
141 } else { |
|
142 $errors['compile_dir'] = $message; |
|
143 } |
|
144 } else { |
|
145 if ($errors === null) { |
|
146 echo "{$_compile_dir} is OK.\n"; |
|
147 } |
|
148 } |
|
149 |
|
150 if ($errors === null) { |
|
151 echo "Testing plugins directory...\n"; |
|
152 } |
|
153 |
|
154 // test if all registered plugins_dir are accessible |
|
155 // and if core plugins directory is still registered |
|
156 $_core_plugins_dir = realpath(dirname(__FILE__) . '/../plugins'); |
|
157 $_core_plugins_available = false; |
|
158 foreach ($smarty->getPluginsDir() as $plugin_dir) { |
|
159 $_plugin_dir = $plugin_dir; |
|
160 $plugin_dir = realpath($plugin_dir); |
|
161 // resolve include_path or fail existence |
|
162 if (!$plugin_dir) { |
|
163 if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) { |
|
164 // try PHP include_path |
|
165 if ($_stream_resolve_include_path) { |
|
166 $plugin_dir = stream_resolve_include_path($_plugin_dir); |
|
167 } else { |
|
168 $plugin_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_plugin_dir); |
|
169 } |
|
170 |
|
171 if ($plugin_dir !== false) { |
|
172 if ($errors === null) { |
|
173 echo "$plugin_dir is OK.\n"; |
|
174 } |
|
175 |
|
176 continue; |
|
177 } else { |
|
178 $status = false; |
|
179 $message = "FAILED: $_plugin_dir does not exist (and couldn't be found in include_path either)"; |
|
180 if ($errors === null) { |
|
181 echo $message . ".\n"; |
|
182 } else { |
|
183 $errors['plugins_dir'] = $message; |
|
184 } |
|
185 |
|
186 continue; |
|
187 } |
|
188 } else { |
|
189 $status = false; |
|
190 $message = "FAILED: $_plugin_dir does not exist"; |
|
191 if ($errors === null) { |
|
192 echo $message . ".\n"; |
|
193 } else { |
|
194 $errors['plugins_dir'] = $message; |
|
195 } |
|
196 |
|
197 continue; |
|
198 } |
|
199 } |
|
200 |
|
201 if (!is_dir($plugin_dir)) { |
|
202 $status = false; |
|
203 $message = "FAILED: $plugin_dir is not a directory"; |
|
204 if ($errors === null) { |
|
205 echo $message . ".\n"; |
|
206 } else { |
|
207 $errors['plugins_dir'] = $message; |
|
208 } |
|
209 } elseif (!is_readable($plugin_dir)) { |
|
210 $status = false; |
|
211 $message = "FAILED: $plugin_dir is not readable"; |
|
212 if ($errors === null) { |
|
213 echo $message . ".\n"; |
|
214 } else { |
|
215 $errors['plugins_dir'] = $message; |
|
216 } |
|
217 } elseif ($_core_plugins_dir && $_core_plugins_dir == realpath($plugin_dir)) { |
|
218 $_core_plugins_available = true; |
|
219 if ($errors === null) { |
|
220 echo "$plugin_dir is OK.\n"; |
|
221 } |
|
222 } else { |
|
223 if ($errors === null) { |
|
224 echo "$plugin_dir is OK.\n"; |
|
225 } |
|
226 } |
|
227 } |
|
228 if (!$_core_plugins_available) { |
|
229 $status = false; |
|
230 $message = "WARNING: Smarty's own libs/plugins is not available"; |
|
231 if ($errors === null) { |
|
232 echo $message . ".\n"; |
|
233 } elseif (!isset($errors['plugins_dir'])) { |
|
234 $errors['plugins_dir'] = $message; |
|
235 } |
|
236 } |
|
237 |
|
238 if ($errors === null) { |
|
239 echo "Testing cache directory...\n"; |
|
240 } |
|
241 |
|
242 // test if all registered cache_dir is accessible |
|
243 $__cache_dir = $smarty->getCacheDir(); |
|
244 $_cache_dir = realpath($__cache_dir); |
|
245 if (!$_cache_dir) { |
|
246 $status = false; |
|
247 $message = "FAILED: {$__cache_dir} does not exist"; |
|
248 if ($errors === null) { |
|
249 echo $message . ".\n"; |
|
250 } else { |
|
251 $errors['cache_dir'] = $message; |
|
252 } |
|
253 } elseif (!is_dir($_cache_dir)) { |
|
254 $status = false; |
|
255 $message = "FAILED: {$_cache_dir} is not a directory"; |
|
256 if ($errors === null) { |
|
257 echo $message . ".\n"; |
|
258 } else { |
|
259 $errors['cache_dir'] = $message; |
|
260 } |
|
261 } elseif (!is_readable($_cache_dir)) { |
|
262 $status = false; |
|
263 $message = "FAILED: {$_cache_dir} is not readable"; |
|
264 if ($errors === null) { |
|
265 echo $message . ".\n"; |
|
266 } else { |
|
267 $errors['cache_dir'] = $message; |
|
268 } |
|
269 } elseif (!is_writable($_cache_dir)) { |
|
270 $status = false; |
|
271 $message = "FAILED: {$_cache_dir} is not writable"; |
|
272 if ($errors === null) { |
|
273 echo $message . ".\n"; |
|
274 } else { |
|
275 $errors['cache_dir'] = $message; |
|
276 } |
|
277 } else { |
|
278 if ($errors === null) { |
|
279 echo "{$_cache_dir} is OK.\n"; |
|
280 } |
|
281 } |
|
282 |
|
283 if ($errors === null) { |
|
284 echo "Testing configs directory...\n"; |
|
285 } |
|
286 |
|
287 // test if all registered config_dir are accessible |
|
288 foreach ($smarty->getConfigDir() as $config_dir) { |
|
289 $_config_dir = $config_dir; |
|
290 $config_dir = realpath($config_dir); |
|
291 // resolve include_path or fail existence |
|
292 if (!$config_dir) { |
|
293 if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) { |
|
294 // try PHP include_path |
|
295 if ($_stream_resolve_include_path) { |
|
296 $config_dir = stream_resolve_include_path($_config_dir); |
|
297 } else { |
|
298 $config_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_config_dir); |
|
299 } |
|
300 |
|
301 if ($config_dir !== false) { |
|
302 if ($errors === null) { |
|
303 echo "$config_dir is OK.\n"; |
|
304 } |
|
305 |
|
306 continue; |
|
307 } else { |
|
308 $status = false; |
|
309 $message = "FAILED: $_config_dir does not exist (and couldn't be found in include_path either)"; |
|
310 if ($errors === null) { |
|
311 echo $message . ".\n"; |
|
312 } else { |
|
313 $errors['config_dir'] = $message; |
|
314 } |
|
315 |
|
316 continue; |
|
317 } |
|
318 } else { |
|
319 $status = false; |
|
320 $message = "FAILED: $_config_dir does not exist"; |
|
321 if ($errors === null) { |
|
322 echo $message . ".\n"; |
|
323 } else { |
|
324 $errors['config_dir'] = $message; |
|
325 } |
|
326 |
|
327 continue; |
|
328 } |
|
329 } |
|
330 |
|
331 if (!is_dir($config_dir)) { |
|
332 $status = false; |
|
333 $message = "FAILED: $config_dir is not a directory"; |
|
334 if ($errors === null) { |
|
335 echo $message . ".\n"; |
|
336 } else { |
|
337 $errors['config_dir'] = $message; |
|
338 } |
|
339 } elseif (!is_readable($config_dir)) { |
|
340 $status = false; |
|
341 $message = "FAILED: $config_dir is not readable"; |
|
342 if ($errors === null) { |
|
343 echo $message . ".\n"; |
|
344 } else { |
|
345 $errors['config_dir'] = $message; |
|
346 } |
|
347 } else { |
|
348 if ($errors === null) { |
|
349 echo "$config_dir is OK.\n"; |
|
350 } |
|
351 } |
|
352 } |
|
353 |
|
354 if ($errors === null) { |
|
355 echo "Testing sysplugin files...\n"; |
|
356 } |
|
357 // test if sysplugins are available |
|
358 $source = SMARTY_SYSPLUGINS_DIR; |
|
359 if (is_dir($source)) { |
|
360 $expected = array( |
|
361 "smarty_cacheresource.php" => true, |
|
362 "smarty_cacheresource_custom.php" => true, |
|
363 "smarty_cacheresource_keyvaluestore.php" => true, |
|
364 "smarty_data.php" => true, |
|
365 "smarty_internal_cacheresource_file.php" => true, |
|
366 "smarty_internal_compile_append.php" => true, |
|
367 "smarty_internal_compile_assign.php" => true, |
|
368 "smarty_internal_compile_block.php" => true, |
|
369 "smarty_internal_compile_break.php" => true, |
|
370 "smarty_internal_compile_call.php" => true, |
|
371 "smarty_internal_compile_capture.php" => true, |
|
372 "smarty_internal_compile_config_load.php" => true, |
|
373 "smarty_internal_compile_continue.php" => true, |
|
374 "smarty_internal_compile_debug.php" => true, |
|
375 "smarty_internal_compile_eval.php" => true, |
|
376 "smarty_internal_compile_extends.php" => true, |
|
377 "smarty_internal_compile_for.php" => true, |
|
378 "smarty_internal_compile_foreach.php" => true, |
|
379 "smarty_internal_compile_function.php" => true, |
|
380 "smarty_internal_compile_if.php" => true, |
|
381 "smarty_internal_compile_include.php" => true, |
|
382 "smarty_internal_compile_include_php.php" => true, |
|
383 "smarty_internal_compile_insert.php" => true, |
|
384 "smarty_internal_compile_ldelim.php" => true, |
|
385 "smarty_internal_compile_nocache.php" => true, |
|
386 "smarty_internal_compile_private_block_plugin.php" => true, |
|
387 "smarty_internal_compile_private_function_plugin.php" => true, |
|
388 "smarty_internal_compile_private_modifier.php" => true, |
|
389 "smarty_internal_compile_private_object_block_function.php" => true, |
|
390 "smarty_internal_compile_private_object_function.php" => true, |
|
391 "smarty_internal_compile_private_print_expression.php" => true, |
|
392 "smarty_internal_compile_private_registered_block.php" => true, |
|
393 "smarty_internal_compile_private_registered_function.php" => true, |
|
394 "smarty_internal_compile_private_special_variable.php" => true, |
|
395 "smarty_internal_compile_rdelim.php" => true, |
|
396 "smarty_internal_compile_section.php" => true, |
|
397 "smarty_internal_compile_setfilter.php" => true, |
|
398 "smarty_internal_compile_while.php" => true, |
|
399 "smarty_internal_compilebase.php" => true, |
|
400 "smarty_internal_config_file_compiler.php" => true, |
|
401 "smarty_internal_configfilelexer.php" => true, |
|
402 "smarty_internal_configfileparser.php" => true, |
|
403 "smarty_internal_data.php" => true, |
|
404 "smarty_internal_debug.php" => true, |
|
405 "smarty_internal_extension_codeframe.php" => true, |
|
406 "smarty_internal_extension_config.php" => true, |
|
407 "smarty_internal_extension_defaulttemplatehandler.php" => true, |
|
408 "smarty_internal_filter_handler.php" => true, |
|
409 "smarty_internal_function_call_handler.php" => true, |
|
410 "smarty_internal_get_include_path.php" => true, |
|
411 "smarty_internal_nocache_insert.php" => true, |
|
412 "smarty_internal_parsetree.php" => true, |
|
413 "smarty_internal_parsetree_code.php" => true, |
|
414 "smarty_internal_parsetree_dq.php" => true, |
|
415 "smarty_internal_parsetree_dqcontent.php" => true, |
|
416 "smarty_internal_parsetree_tag.php" => true, |
|
417 "smarty_internal_parsetree_template.php" => true, |
|
418 "smarty_internal_parsetree_text.php" => true, |
|
419 "smarty_internal_resource_eval.php" => true, |
|
420 "smarty_internal_resource_extends.php" => true, |
|
421 "smarty_internal_resource_file.php" => true, |
|
422 "smarty_internal_resource_php.php" => true, |
|
423 "smarty_internal_resource_registered.php" => true, |
|
424 "smarty_internal_resource_stream.php" => true, |
|
425 "smarty_internal_resource_string.php" => true, |
|
426 "smarty_internal_smartytemplatecompiler.php" => true, |
|
427 "smarty_internal_template.php" => true, |
|
428 "smarty_internal_templatebase.php" => true, |
|
429 "smarty_internal_templatecompilerbase.php" => true, |
|
430 "smarty_internal_templatelexer.php" => true, |
|
431 "smarty_internal_templateparser.php" => true, |
|
432 "smarty_internal_utility.php" => true, |
|
433 "smarty_internal_write_file.php" => true, |
|
434 "smarty_resource.php" => true, |
|
435 "smarty_resource_custom.php" => true, |
|
436 "smarty_resource_recompiled.php" => true, |
|
437 "smarty_resource_uncompiled.php" => true, |
|
438 "smarty_security.php" => true, |
|
439 "smarty_template_cached.php" => true, |
|
440 "smarty_template_compiled.php" => true, |
|
441 "smarty_template_config.php" => true, |
|
442 "smarty_template_source.php" => true, |
|
443 "smarty_undefined_variable.php" => true, |
|
444 "smarty_variable.php" => true, |
|
445 "smartycompilerexception.php" => true, |
|
446 "smartyexception.php" => true, |
|
447 ); |
|
448 $iterator = new DirectoryIterator($source); |
|
449 foreach ($iterator as $file) { |
|
450 if (!$file->isDot()) { |
|
451 $filename = $file->getFilename(); |
|
452 if (isset($expected[$filename])) { |
|
453 unset($expected[$filename]); |
|
454 } |
|
455 } |
|
456 } |
|
457 if ($expected) { |
|
458 $status = false; |
|
459 $message = "FAILED: files missing from libs/sysplugins: " . join(', ', array_keys($expected)); |
|
460 if ($errors === null) { |
|
461 echo $message . ".\n"; |
|
462 } else { |
|
463 $errors['sysplugins'] = $message; |
|
464 } |
|
465 } elseif ($errors === null) { |
|
466 echo "... OK\n"; |
|
467 } |
|
468 } else { |
|
469 $status = false; |
|
470 $message = "FAILED: " . SMARTY_SYSPLUGINS_DIR . ' is not a directory'; |
|
471 if ($errors === null) { |
|
472 echo $message . ".\n"; |
|
473 } else { |
|
474 $errors['sysplugins_dir_constant'] = $message; |
|
475 } |
|
476 } |
|
477 |
|
478 if ($errors === null) { |
|
479 echo "Testing plugin files...\n"; |
|
480 } |
|
481 // test if core plugins are available |
|
482 $source = SMARTY_PLUGINS_DIR; |
|
483 if (is_dir($source)) { |
|
484 $expected = array( |
|
485 "block.textformat.php" => true, |
|
486 "function.counter.php" => true, |
|
487 "function.cycle.php" => true, |
|
488 "function.fetch.php" => true, |
|
489 "function.html_checkboxes.php" => true, |
|
490 "function.html_image.php" => true, |
|
491 "function.html_options.php" => true, |
|
492 "function.html_radios.php" => true, |
|
493 "function.html_select_date.php" => true, |
|
494 "function.html_select_time.php" => true, |
|
495 "function.html_table.php" => true, |
|
496 "function.mailto.php" => true, |
|
497 "function.math.php" => true, |
|
498 "modifier.capitalize.php" => true, |
|
499 "modifier.date_format.php" => true, |
|
500 "modifier.debug_print_var.php" => true, |
|
501 "modifier.escape.php" => true, |
|
502 "modifier.regex_replace.php" => true, |
|
503 "modifier.replace.php" => true, |
|
504 "modifier.spacify.php" => true, |
|
505 "modifier.truncate.php" => true, |
|
506 "modifiercompiler.cat.php" => true, |
|
507 "modifiercompiler.count_characters.php" => true, |
|
508 "modifiercompiler.count_paragraphs.php" => true, |
|
509 "modifiercompiler.count_sentences.php" => true, |
|
510 "modifiercompiler.count_words.php" => true, |
|
511 "modifiercompiler.default.php" => true, |
|
512 "modifiercompiler.escape.php" => true, |
|
513 "modifiercompiler.from_charset.php" => true, |
|
514 "modifiercompiler.indent.php" => true, |
|
515 "modifiercompiler.lower.php" => true, |
|
516 "modifiercompiler.noprint.php" => true, |
|
517 "modifiercompiler.string_format.php" => true, |
|
518 "modifiercompiler.strip.php" => true, |
|
519 "modifiercompiler.strip_tags.php" => true, |
|
520 "modifiercompiler.to_charset.php" => true, |
|
521 "modifiercompiler.unescape.php" => true, |
|
522 "modifiercompiler.upper.php" => true, |
|
523 "modifiercompiler.wordwrap.php" => true, |
|
524 "outputfilter.trimwhitespace.php" => true, |
|
525 "shared.escape_special_chars.php" => true, |
|
526 "shared.literal_compiler_param.php" => true, |
|
527 "shared.make_timestamp.php" => true, |
|
528 "shared.mb_str_replace.php" => true, |
|
529 "shared.mb_unicode.php" => true, |
|
530 "shared.mb_wordwrap.php" => true, |
|
531 "variablefilter.htmlspecialchars.php" => true, |
|
532 ); |
|
533 $iterator = new DirectoryIterator($source); |
|
534 foreach ($iterator as $file) { |
|
535 if (!$file->isDot()) { |
|
536 $filename = $file->getFilename(); |
|
537 if (isset($expected[$filename])) { |
|
538 unset($expected[$filename]); |
|
539 } |
|
540 } |
|
541 } |
|
542 if ($expected) { |
|
543 $status = false; |
|
544 $message = "FAILED: files missing from libs/plugins: " . join(', ', array_keys($expected)); |
|
545 if ($errors === null) { |
|
546 echo $message . ".\n"; |
|
547 } else { |
|
548 $errors['plugins'] = $message; |
|
549 } |
|
550 } elseif ($errors === null) { |
|
551 echo "... OK\n"; |
|
552 } |
|
553 } else { |
|
554 $status = false; |
|
555 $message = "FAILED: " . SMARTY_PLUGINS_DIR . ' is not a directory'; |
|
556 if ($errors === null) { |
|
557 echo $message . ".\n"; |
|
558 } else { |
|
559 $errors['plugins_dir_constant'] = $message; |
|
560 } |
|
561 } |
|
562 |
|
563 if ($errors === null) { |
|
564 echo "Tests complete.\n"; |
|
565 echo "</PRE>\n"; |
|
566 } |
|
567 |
|
568 return $status; |
|
569 } |
|
570 } |
|