29 error_reporting(E_ALL);
30 if (ini_get(
'memory_limit') !=
'-1') ini_set(
'memory_limit',
'-1');
31 if (php_sapi_name() !=
'cli') {
32 trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
37 $help .=
"Syntax: system_check.php [ARGS]\n";
38 $help .=
"Where [ARGS] can be:\n";
39 $help .=
"\t--system=[MATRIX_ROOT]\tThe path to the matrix system\n";
40 $help .=
"\t--verbose\t\tShow more detailed errors\n";
41 $help .=
"\t--colours\t\tUse colours\n";
42 $help .=
"\t--stats\t\t\tShow statistics for this process\n";
43 $help .=
"\t--help\t\t\tShow this help screen\n";
44 $help .=
"\t--execute\t\tMake a script execute it's action if it has one\n";
45 $help .=
"\t[test_to_run]\n";
52 $tests_to_run = Array();
56 foreach ($_SERVER[
'argv'] as $placement => $argument) {
57 if (!empty($placement)) {
58 $argument = ltrim($argument,
'-');
59 if (strpos($argument,
'=') != FALSE) {
60 list($command, $parameter) = explode(
'=', $argument);
67 $SYSTEM_ROOT = $parameter;
86 $tests_to_run[] = $command;
91 if (empty($SYSTEM_ROOT)) {
92 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
97 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
98 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
103 define(
'SQ_SYSTEM_ROOT', $SYSTEM_ROOT);
104 require_once SQ_SYSTEM_ROOT.
'/core/include/init.inc';
105 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
108 mem_check(NULL, TRUE);
109 speed_check(
'', FALSE, FALSE);
112 $root_user = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
113 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
114 $GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user);
117 $test_dir = dirname(__FILE__).
'/system_tests';
118 $tests = list_files($test_dir.
'/*.inc');
119 foreach ($tests as $test) {
121 if (!preg_match(
'/^test(.*)\.inc$/i', $test))
continue;
123 $test_basename = basename($test,
'.inc');
124 if (!empty($tests_to_run)) {
125 if (!in_array($test_basename, $tests_to_run)) {
130 include_once $test_dir.
'/'.$test;
131 $class_name = str_replace(
'_',
' ', $test_basename);
132 $class_name = ucwords($class_name);
133 $class_name = str_replace(
' ',
'_', $class_name);
136 $runTestMethod = TRUE;
138 if (method_exists($class_name,
'execute')) {
139 $status = call_user_func_array(Array($class_name,
'execute'), Array(&$messages, &$errors));
140 $runTestMethod = FALSE;
142 echo
"Test " . $test .
" doesn't have an 'execute' option.\n";
146 if ($runTestMethod) {
147 $status = call_user_func_array(Array($class_name,
'test'), Array(&$messages, &$errors));
150 $name = call_user_func_array(Array($class_name,
'getName'), Array());
152 showStatus($name, $status, $messages, $errors, $VERBOSE, $COLOURS);
156 $GLOBALS[
'SQ_SYSTEM']->restoreCurrentUser();
157 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
161 echo
"Memory Usage: ".mem_check(NULL, TRUE).
"\n";
163 speed_check(
'', FALSE, FALSE);
181 function showStatus($name, $status, $messages=Array(), $errors=Array(), $verbose=FALSE, $colours=TRUE)
185 $statusOk =
"\033[50G[ \033[1;32mOK\033[0m ]";
186 $statusErr =
"\033[50G[ \033[1;31m!!\033[0m ]";
187 $statusWarn =
"\033[50G[ \033[1;33m??\033[0m ]";
188 $statusInfo =
"\033[50G[ \033[1;34minfo\033[0m ]";
190 $statusOk =
"\033[50G[ OK ]";
191 $statusErr =
"\033[50G[ !! ]";
192 $statusWarn =
"\033[50G[ ?? ]";
193 $statusInfo =
"\033[50G[ info ]";
198 if (is_bool($status)) {
199 echo ($status) ? $statusOk : $statusErr;
218 if (($status !== TRUE || $status !==
'1') && !empty($messages)) {
220 foreach ($messages as $message) {
221 echo
"\t".$message.
"\n";
226 if (($status !== TRUE || $status !==
'1') && $verbose && !empty($errors)) {
228 foreach ($errors as $error) {
229 echo
"\t".$error.
"\n";