From 09892a3484abb676fa5270ce6dada0c347e59fc0 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 19 Mar 2010 13:09:41 -0600 Subject: [PATCH] Test script improvements. Standardize error messages. Add checks for framework libraries and registry.php. Die immediately if not found. There is no reason to continue running the test script if these basic Horde elements are not correctly set up. --- horde/test.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/horde/test.php b/horde/test.php index 1c7135903..87eb7c021 100644 --- a/horde/test.php +++ b/horde/test.php @@ -19,6 +19,23 @@ * @author Michael Slusarz */ +/* Function to output fatal error message. */ +function _hordeTestError($msg) +{ + exit('ERROR

' . htmlspecialchars($msg) . '

'); +} + +/* If we can't find the Autoloader, then the framework is not setup. A user + * must at least correctly install the framework. */ +if (!@include_once 'Horde/Autoloader.php') { + _hordeTestError('Could not find Horde\'s framework libraries. Please read horde/docs/INSTALL for information on how to install these libraries.'); +} + +/* Similarly, registry.php needs to exist. */ +if (!file_exists(dirname(__FILE__) . '/config/registry.php')) { + _hordeTestError('Could not find horde/config/registry.php. Please make sure this file exists. Read horde/docs/INSTALL for further information.'); +} + require_once dirname(__FILE__) . '/lib/Application.php'; try { Horde_Registry::appInit('horde', array('authentication' => 'none')); @@ -29,22 +46,19 @@ try { } if (!empty($conf['testdisable'])) { - echo '

Horde test scripts have been disabled in the local configuration.

'; - exit; + _hordeTestError('Horde test scripts have been disabled in the local configuration.'); } /* We should have loaded the String class, from the Horde_Util package. If it * isn't defined, then we're not finding some critical libraries. */ if (!class_exists('Horde_String')) { - echo '

Required Horde libraries were not found. If PHP\'s error_reporting setting is high enough and display_errors is on, there should be error messages printed above that may help you in debugging the problem. If you are simply missing these files, then you need to install the framework module.

'; - exit; + _hordeTestError('Required Horde libraries were not found. If PHP\'s error_reporting setting is high enough and display_errors is on, there should be error messages printed above that may help you in debugging the problem. If you are simply missing these files, then you need to install the framework module.'); } /* Initialize the Horde_Test:: class. */ if (!class_exists('Horde_Test')) { /* Try and provide enough information to debug the missing file. */ - echo '

Unable to find the Horde_Test library. Your Horde installation may be missing critical files, or PHP may not have sufficient permissions to include files. There may be error messages printed above this message that will help you in debugging the problem.

'; - exit; + _hordeTestError('Unable to find the Horde_Test library. Your Horde installation may be missing critical files, or PHP may not have sufficient permissions to include files. There may be error messages printed above this message that will help you in debugging the problem.'); } /* Load the application. */ @@ -59,8 +73,7 @@ if ($app != 'horde') { } $classname = ucfirst($app) . '_Test'; if (!class_exists($classname)) { - echo '

No tests found for ' . ucfirst($app) . ' [' . $app_name . '].

'; - exit; + _hordeTestError('No tests found for ' . ucfirst($app) . ' [' . $app_name . '].'); } $test_ob = new $classname(); -- 2.11.0