3 * Smarty Internal TestInstall
4 * Test Smarty installation
7 * @subpackage Utilities
15 * @subpackage Utilities
17 class Smarty_Internal_TestInstall
20 * diagnose Smarty setup
21 * If $errors is secified, the diagnostic report will be appended to the array, rather than being output.
23 * @param \Smarty $smarty
24 * @param array $errors array to push results into rather than outputting them
26 * @return bool status, true if everything is fine, false else
28 public static function testInstall(Smarty $smarty, &$errors = null)
32 if ($errors === null) {
34 echo "Smarty Installation test...\n";
35 echo "Testing template directory...\n";
38 $_stream_resolve_include_path = function_exists('stream_resolve_include_path');
40 // test if all registered template_dir are accessible
41 foreach ($smarty->getTemplateDir() as $template_dir) {
42 $_template_dir = $template_dir;
43 $template_dir = realpath($template_dir);
44 // resolve include_path or fail existence
46 if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_template_dir)) {
47 // try PHP include_path
48 if ($_stream_resolve_include_path) {
49 $template_dir = stream_resolve_include_path($_template_dir);
51 $template_dir = $smarty->ext->_getIncludePath->getIncludePath($_template_dir, null, $smarty);
54 if ($template_dir !== false) {
55 if ($errors === null) {
56 echo "$template_dir is OK.\n";
63 "FAILED: $_template_dir does not exist (and couldn't be found in include_path either)";
64 if ($errors === null) {
65 echo $message . ".\n";
67 $errors[ 'template_dir' ] = $message;
74 $message = "FAILED: $_template_dir does not exist";
75 if ($errors === null) {
76 echo $message . ".\n";
78 $errors[ 'template_dir' ] = $message;
85 if (!is_dir($template_dir)) {
87 $message = "FAILED: $template_dir is not a directory";
88 if ($errors === null) {
89 echo $message . ".\n";
91 $errors[ 'template_dir' ] = $message;
93 } elseif (!is_readable($template_dir)) {
95 $message = "FAILED: $template_dir is not readable";
96 if ($errors === null) {
97 echo $message . ".\n";
99 $errors[ 'template_dir' ] = $message;
102 if ($errors === null) {
103 echo "$template_dir is OK.\n";
108 if ($errors === null) {
109 echo "Testing compile directory...\n";
112 // test if registered compile_dir is accessible
113 $__compile_dir = $smarty->getCompileDir();
114 $_compile_dir = realpath($__compile_dir);
115 if (!$_compile_dir) {
117 $message = "FAILED: {$__compile_dir} does not exist";
118 if ($errors === null) {
119 echo $message . ".\n";
121 $errors[ 'compile_dir' ] = $message;
123 } elseif (!is_dir($_compile_dir)) {
125 $message = "FAILED: {$_compile_dir} is not a directory";
126 if ($errors === null) {
127 echo $message . ".\n";
129 $errors[ 'compile_dir' ] = $message;
131 } elseif (!is_readable($_compile_dir)) {
133 $message = "FAILED: {$_compile_dir} is not readable";
134 if ($errors === null) {
135 echo $message . ".\n";
137 $errors[ 'compile_dir' ] = $message;
139 } elseif (!is_writable($_compile_dir)) {
141 $message = "FAILED: {$_compile_dir} is not writable";
142 if ($errors === null) {
143 echo $message . ".\n";
145 $errors[ 'compile_dir' ] = $message;
148 if ($errors === null) {
149 echo "{$_compile_dir} is OK.\n";
153 if ($errors === null) {
154 echo "Testing plugins directory...\n";
157 // test if all registered plugins_dir are accessible
158 // and if core plugins directory is still registered
159 $_core_plugins_dir = realpath(dirname(__FILE__) . '/../plugins');
160 $_core_plugins_available = false;
161 foreach ($smarty->getPluginsDir() as $plugin_dir) {
162 $_plugin_dir = $plugin_dir;
163 $plugin_dir = realpath($plugin_dir);
164 // resolve include_path or fail existence
166 if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) {
167 // try PHP include_path
168 if ($_stream_resolve_include_path) {
169 $plugin_dir = stream_resolve_include_path($_plugin_dir);
171 $plugin_dir = $smarty->ext->_getIncludePath->getIncludePath($_plugin_dir, null, $smarty);
174 if ($plugin_dir !== false) {
175 if ($errors === null) {
176 echo "$plugin_dir is OK.\n";
182 $message = "FAILED: $_plugin_dir does not exist (and couldn't be found in include_path either)";
183 if ($errors === null) {
184 echo $message . ".\n";
186 $errors[ 'plugins_dir' ] = $message;
193 $message = "FAILED: $_plugin_dir does not exist";
194 if ($errors === null) {
195 echo $message . ".\n";
197 $errors[ 'plugins_dir' ] = $message;
204 if (!is_dir($plugin_dir)) {
206 $message = "FAILED: $plugin_dir is not a directory";
207 if ($errors === null) {
208 echo $message . ".\n";
210 $errors[ 'plugins_dir' ] = $message;
212 } elseif (!is_readable($plugin_dir)) {
214 $message = "FAILED: $plugin_dir is not readable";
215 if ($errors === null) {
216 echo $message . ".\n";
218 $errors[ 'plugins_dir' ] = $message;
220 } elseif ($_core_plugins_dir && $_core_plugins_dir == realpath($plugin_dir)) {
221 $_core_plugins_available = true;
222 if ($errors === null) {
223 echo "$plugin_dir is OK.\n";
226 if ($errors === null) {
227 echo "$plugin_dir is OK.\n";
231 if (!$_core_plugins_available) {
233 $message = "WARNING: Smarty's own libs/plugins is not available";
234 if ($errors === null) {
235 echo $message . ".\n";
236 } elseif (!isset($errors[ 'plugins_dir' ])) {
237 $errors[ 'plugins_dir' ] = $message;
241 if ($errors === null) {
242 echo "Testing cache directory...\n";
245 // test if all registered cache_dir is accessible
246 $__cache_dir = $smarty->getCacheDir();
247 $_cache_dir = realpath($__cache_dir);
250 $message = "FAILED: {$__cache_dir} does not exist";
251 if ($errors === null) {
252 echo $message . ".\n";
254 $errors[ 'cache_dir' ] = $message;
256 } elseif (!is_dir($_cache_dir)) {
258 $message = "FAILED: {$_cache_dir} is not a directory";
259 if ($errors === null) {
260 echo $message . ".\n";
262 $errors[ 'cache_dir' ] = $message;
264 } elseif (!is_readable($_cache_dir)) {
266 $message = "FAILED: {$_cache_dir} is not readable";
267 if ($errors === null) {
268 echo $message . ".\n";
270 $errors[ 'cache_dir' ] = $message;
272 } elseif (!is_writable($_cache_dir)) {
274 $message = "FAILED: {$_cache_dir} is not writable";
275 if ($errors === null) {
276 echo $message . ".\n";
278 $errors[ 'cache_dir' ] = $message;
281 if ($errors === null) {
282 echo "{$_cache_dir} is OK.\n";
286 if ($errors === null) {
287 echo "Testing configs directory...\n";
290 // test if all registered config_dir are accessible
291 foreach ($smarty->getConfigDir() as $config_dir) {
292 $_config_dir = $config_dir;
293 // resolve include_path or fail existence
295 if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) {
296 // try PHP include_path
297 if ($_stream_resolve_include_path) {
298 $config_dir = stream_resolve_include_path($_config_dir);
300 $config_dir = $smarty->ext->_getIncludePath->getIncludePath($_config_dir, null, $smarty);
303 if ($config_dir !== false) {
304 if ($errors === null) {
305 echo "$config_dir is OK.\n";
311 $message = "FAILED: $_config_dir does not exist (and couldn't be found in include_path either)";
312 if ($errors === null) {
313 echo $message . ".\n";
315 $errors[ 'config_dir' ] = $message;
322 $message = "FAILED: $_config_dir does not exist";
323 if ($errors === null) {
324 echo $message . ".\n";
326 $errors[ 'config_dir' ] = $message;
333 if (!is_dir($config_dir)) {
335 $message = "FAILED: $config_dir is not a directory";
336 if ($errors === null) {
337 echo $message . ".\n";
339 $errors[ 'config_dir' ] = $message;
341 } elseif (!is_readable($config_dir)) {
343 $message = "FAILED: $config_dir is not readable";
344 if ($errors === null) {
345 echo $message . ".\n";
347 $errors[ 'config_dir' ] = $message;
350 if ($errors === null) {
351 echo "$config_dir is OK.\n";
356 if ($errors === null) {
357 echo "Testing sysplugin files...\n";
359 // test if sysplugins are available
360 $source = SMARTY_SYSPLUGINS_DIR;
361 if (is_dir($source)) {
362 $expectedSysplugins = array('smartycompilerexception.php' => true, 'smartyexception.php' => true,
363 'smarty_cacheresource.php' => true, 'smarty_cacheresource_custom.php' => true,
364 'smarty_cacheresource_keyvaluestore.php' => true, 'smarty_data.php' => true,
365 'smarty_internal_block.php' => true,
366 'smarty_internal_cacheresource_file.php' => true,
367 'smarty_internal_compilebase.php' => true,
368 'smarty_internal_compile_append.php' => true,
369 'smarty_internal_compile_assign.php' => true,
370 'smarty_internal_compile_block.php' => true,
371 'smarty_internal_compile_block_child.php' => true,
372 'smarty_internal_compile_block_parent.php' => true,
373 'smarty_internal_compile_break.php' => true,
374 'smarty_internal_compile_call.php' => true,
375 'smarty_internal_compile_capture.php' => true,
376 'smarty_internal_compile_config_load.php' => true,
377 'smarty_internal_compile_continue.php' => true,
378 'smarty_internal_compile_debug.php' => true,
379 'smarty_internal_compile_eval.php' => true,
380 'smarty_internal_compile_extends.php' => true,
381 'smarty_internal_compile_for.php' => true,
382 'smarty_internal_compile_foreach.php' => true,
383 'smarty_internal_compile_function.php' => true,
384 'smarty_internal_compile_if.php' => true,
385 'smarty_internal_compile_include.php' => true,
386 'smarty_internal_compile_include_php.php' => true,
387 'smarty_internal_compile_insert.php' => true,
388 'smarty_internal_compile_ldelim.php' => true,
389 'smarty_internal_compile_make_nocache.php' => true,
390 'smarty_internal_compile_nocache.php' => true,
391 'smarty_internal_compile_private_block_plugin.php' => true,
392 'smarty_internal_compile_private_foreachsection.php' => true,
393 'smarty_internal_compile_private_function_plugin.php' => true,
394 'smarty_internal_compile_private_modifier.php' => true,
395 'smarty_internal_compile_private_object_block_function.php' => true,
396 'smarty_internal_compile_private_object_function.php' => true,
397 'smarty_internal_compile_private_php.php' => true,
398 'smarty_internal_compile_private_print_expression.php' => true,
399 'smarty_internal_compile_private_registered_block.php' => true,
400 'smarty_internal_compile_private_registered_function.php' => true,
401 'smarty_internal_compile_private_special_variable.php' => true,
402 'smarty_internal_compile_rdelim.php' => true,
403 'smarty_internal_compile_section.php' => true,
404 'smarty_internal_compile_setfilter.php' => true,
405 'smarty_internal_compile_shared_inheritance.php' => true,
406 'smarty_internal_compile_while.php' => true,
407 'smarty_internal_configfilelexer.php' => true,
408 'smarty_internal_configfileparser.php' => true,
409 'smarty_internal_config_file_compiler.php' => true,
410 'smarty_internal_data.php' => true, 'smarty_internal_debug.php' => true,
411 'smarty_internal_extension_handler.php' => true,
412 'smarty_internal_method_addautoloadfilters.php' => true,
413 'smarty_internal_method_adddefaultmodifiers.php' => true,
414 'smarty_internal_method_append.php' => true,
415 'smarty_internal_method_appendbyref.php' => true,
416 'smarty_internal_method_assignbyref.php' => true,
417 'smarty_internal_method_assignglobal.php' => true,
418 'smarty_internal_method_clearallassign.php' => true,
419 'smarty_internal_method_clearallcache.php' => true,
420 'smarty_internal_method_clearassign.php' => true,
421 'smarty_internal_method_clearcache.php' => true,
422 'smarty_internal_method_clearcompiledtemplate.php' => true,
423 'smarty_internal_method_clearconfig.php' => true,
424 'smarty_internal_method_compileallconfig.php' => true,
425 'smarty_internal_method_compilealltemplates.php' => true,
426 'smarty_internal_method_configload.php' => true,
427 'smarty_internal_method_createdata.php' => true,
428 'smarty_internal_method_getautoloadfilters.php' => true,
429 'smarty_internal_method_getconfigvariable.php' => true,
430 'smarty_internal_method_getconfigvars.php' => true,
431 'smarty_internal_method_getdebugtemplate.php' => true,
432 'smarty_internal_method_getdefaultmodifiers.php' => true,
433 'smarty_internal_method_getglobal.php' => true,
434 'smarty_internal_method_getregisteredobject.php' => true,
435 'smarty_internal_method_getstreamvariable.php' => true,
436 'smarty_internal_method_gettags.php' => true,
437 'smarty_internal_method_gettemplatevars.php' => true,
438 'smarty_internal_method_loadfilter.php' => true,
439 'smarty_internal_method_loadplugin.php' => true,
440 'smarty_internal_method_mustcompile.php' => true,
441 'smarty_internal_method_registercacheresource.php' => true,
442 'smarty_internal_method_registerclass.php' => true,
443 'smarty_internal_method_registerdefaultconfighandler.php' => true,
444 'smarty_internal_method_registerdefaultpluginhandler.php' => true,
445 'smarty_internal_method_registerdefaulttemplatehandler.php' => true,
446 'smarty_internal_method_registerfilter.php' => true,
447 'smarty_internal_method_registerobject.php' => true,
448 'smarty_internal_method_registerplugin.php' => true,
449 'smarty_internal_method_registerresource.php' => true,
450 'smarty_internal_method_setautoloadfilters.php' => true,
451 'smarty_internal_method_setdebugtemplate.php' => true,
452 'smarty_internal_method_setdefaultmodifiers.php' => true,
453 'smarty_internal_method_unloadfilter.php' => true,
454 'smarty_internal_method_unregistercacheresource.php' => true,
455 'smarty_internal_method_unregisterfilter.php' => true,
456 'smarty_internal_method_unregisterobject.php' => true,
457 'smarty_internal_method_unregisterplugin.php' => true,
458 'smarty_internal_method_unregisterresource.php' => true,
459 'smarty_internal_nocache_insert.php' => true,
460 'smarty_internal_parsetree.php' => true,
461 'smarty_internal_parsetree_code.php' => true,
462 'smarty_internal_parsetree_dq.php' => true,
463 'smarty_internal_parsetree_dqcontent.php' => true,
464 'smarty_internal_parsetree_tag.php' => true,
465 'smarty_internal_parsetree_template.php' => true,
466 'smarty_internal_parsetree_text.php' => true,
467 'smarty_internal_resource_eval.php' => true,
468 'smarty_internal_resource_extends.php' => true,
469 'smarty_internal_resource_file.php' => true,
470 'smarty_internal_resource_php.php' => true,
471 'smarty_internal_resource_registered.php' => true,
472 'smarty_internal_resource_stream.php' => true,
473 'smarty_internal_resource_string.php' => true,
474 'smarty_internal_runtime_cachemodify.php' => true,
475 'smarty_internal_runtime_cacheresourcefile.php' => true,
476 'smarty_internal_runtime_capture.php' => true,
477 'smarty_internal_runtime_codeframe.php' => true,
478 'smarty_internal_runtime_filterhandler.php' => true,
479 'smarty_internal_runtime_foreach.php' => true,
480 'smarty_internal_runtime_getincludepath.php' => true,
481 'smarty_internal_runtime_inheritance.php' => true,
482 'smarty_internal_runtime_make_nocache.php' => true,
483 'smarty_internal_runtime_tplfunction.php' => true,
484 'smarty_internal_runtime_updatecache.php' => true,
485 'smarty_internal_runtime_updatescope.php' => true,
486 'smarty_internal_runtime_writefile.php' => true,
487 'smarty_internal_smartytemplatecompiler.php' => true,
488 'smarty_internal_template.php' => true,
489 'smarty_internal_templatebase.php' => true,
490 'smarty_internal_templatecompilerbase.php' => true,
491 'smarty_internal_templatelexer.php' => true,
492 'smarty_internal_templateparser.php' => true,
493 'smarty_internal_testinstall.php' => true,
494 'smarty_internal_undefined.php' => true, 'smarty_resource.php' => true,
495 'smarty_resource_custom.php' => true, 'smarty_resource_recompiled.php' => true,
496 'smarty_resource_uncompiled.php' => true, 'smarty_security.php' => true,
497 'smarty_template_cached.php' => true, 'smarty_template_compiled.php' => true,
498 'smarty_template_config.php' => true,
499 'smarty_template_resource_base.php' => true,
500 'smarty_template_source.php' => true, 'smarty_undefined_variable.php' => true,
501 'smarty_variable.php' => true,);
502 $iterator = new DirectoryIterator($source);
503 foreach ($iterator as $file) {
504 if (!$file->isDot()) {
505 $filename = $file->getFilename();
506 if (isset($expectedSysplugins[ $filename ])) {
507 unset($expectedSysplugins[ $filename ]);
511 if ($expectedSysplugins) {
513 $message = "FAILED: files missing from libs/sysplugins: " . join(', ', array_keys($expectedSysplugins));
514 if ($errors === null) {
515 echo $message . ".\n";
517 $errors[ 'sysplugins' ] = $message;
519 } elseif ($errors === null) {
524 $message = "FAILED: " . SMARTY_SYSPLUGINS_DIR . ' is not a directory';
525 if ($errors === null) {
526 echo $message . ".\n";
528 $errors[ 'sysplugins_dir_constant' ] = $message;
532 if ($errors === null) {
533 echo "Testing plugin files...\n";
535 // test if core plugins are available
536 $source = SMARTY_PLUGINS_DIR;
537 if (is_dir($source)) {
539 array('block.textformat.php' => true, 'function.counter.php' => true, 'function.cycle.php' => true,
540 'function.fetch.php' => true, 'function.html_checkboxes.php' => true,
541 'function.html_image.php' => true, 'function.html_options.php' => true,
542 'function.html_radios.php' => true, 'function.html_select_date.php' => true,
543 'function.html_select_time.php' => true, 'function.html_table.php' => true,
544 'function.mailto.php' => true, 'function.math.php' => true, 'modifier.capitalize.php' => true,
545 'modifier.date_format.php' => true, 'modifier.debug_print_var.php' => true,
546 'modifier.escape.php' => true, 'modifier.regex_replace.php' => true,
547 'modifier.replace.php' => true, 'modifier.spacify.php' => true, 'modifier.truncate.php' => true,
548 'modifiercompiler.cat.php' => true, 'modifiercompiler.count_characters.php' => true,
549 'modifiercompiler.count_paragraphs.php' => true, 'modifiercompiler.count_sentences.php' => true,
550 'modifiercompiler.count_words.php' => true, 'modifiercompiler.default.php' => true,
551 'modifiercompiler.escape.php' => true, 'modifiercompiler.from_charset.php' => true,
552 'modifiercompiler.indent.php' => true, 'modifiercompiler.lower.php' => true,
553 'modifiercompiler.noprint.php' => true, 'modifiercompiler.string_format.php' => true,
554 'modifiercompiler.strip.php' => true, 'modifiercompiler.strip_tags.php' => true,
555 'modifiercompiler.to_charset.php' => true, 'modifiercompiler.unescape.php' => true,
556 'modifiercompiler.upper.php' => true, 'modifiercompiler.wordwrap.php' => true,
557 'outputfilter.trimwhitespace.php' => true, 'shared.escape_special_chars.php' => true,
558 'shared.literal_compiler_param.php' => true, 'shared.make_timestamp.php' => true,
559 'shared.mb_str_replace.php' => true, 'shared.mb_unicode.php' => true,
560 'shared.mb_wordwrap.php' => true, 'variablefilter.htmlspecialchars.php' => true,);
561 $iterator = new DirectoryIterator($source);
562 foreach ($iterator as $file) {
563 if (!$file->isDot()) {
564 $filename = $file->getFilename();
565 if (isset($expectedPlugins[ $filename ])) {
566 unset($expectedPlugins[ $filename ]);
570 if ($expectedPlugins) {
572 $message = "FAILED: files missing from libs/plugins: " . join(', ', array_keys($expectedPlugins));
573 if ($errors === null) {
574 echo $message . ".\n";
576 $errors[ 'plugins' ] = $message;
578 } elseif ($errors === null) {
583 $message = "FAILED: " . SMARTY_PLUGINS_DIR . ' is not a directory';
584 if ($errors === null) {
585 echo $message . ".\n";
587 $errors[ 'plugins_dir_constant' ] = $message;
591 if ($errors === null) {
592 echo "Tests complete.\n";