| 1 |
<?php
|
| 2 |
// $Id: test_it.php,v 1.20 2006/08/10 09:50:56 rokZlender Exp $
|
| 3 |
if ($argc != 2) {
|
| 4 |
die("Proper usage is test_it.php nid");
|
| 5 |
}
|
| 6 |
|
| 7 |
$test_it_path = realpath(dirname(__FILE__));
|
| 8 |
|
| 9 |
chdir(realpath(dirname(__FILE__) . '/../../'));
|
| 10 |
if (file_exists('./includes/bootstrap.inc')) {
|
| 11 |
include_once './includes/bootstrap.inc';
|
| 12 |
}
|
| 13 |
else {
|
| 14 |
chdir(getcwd() . '/../../');
|
| 15 |
if (file_exists('./includes/bootstrap.inc')) {
|
| 16 |
include_once './includes/bootstrap.inc';
|
| 17 |
}
|
| 18 |
else {
|
| 19 |
die("bootstrap.inc could not be loaded");
|
| 20 |
}
|
| 21 |
}
|
| 22 |
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
|
| 23 |
|
| 24 |
$node_id = $argv[1];
|
| 25 |
|
| 26 |
$drupal_dir = getcwd();
|
| 27 |
|
| 28 |
$node = node_load($node_id);
|
| 29 |
$patch_url = $node->patch_url;
|
| 30 |
$project_name = $node->project;
|
| 31 |
$version = $node->version;
|
| 32 |
$branch = getBranchName($version);
|
| 33 |
$msg = "";
|
| 34 |
$db_host = 'localhost';
|
| 35 |
$db_user = 'db_user';
|
| 36 |
$db_pass = 'db_pass';
|
| 37 |
$install_dir = variable_get('simpletestauto_install_dir', '');
|
| 38 |
$test_server_url = variable_get('simpletestauto_test_url', '');
|
| 39 |
$simpletest_lib_cvs = '-d:pserver:anonymous@simpletest.cvs.sourceforge.net:/cvsroot/simpletest';
|
| 40 |
|
| 41 |
$simpletest_modules = preg_split("/[\s,]+/", variable_get('simpletestauto_test_modules','').', simpletest');
|
| 42 |
$default_modules = array('block', 'comment', 'filter', 'help', 'menu', 'node', 'system', 'taxonomy', 'user', 'watchdog');
|
| 43 |
|
| 44 |
// Generate a unique instance name.
|
| 45 |
$instance = "test_" . time() . rand(0, 32767);
|
| 46 |
$instance_dir = $install_dir."/".$instance;
|
| 47 |
|
| 48 |
chdir($install_dir) || terminateTesting(1, $msg."Unable to chdir to $install_dir");
|
| 49 |
mkdir($instance_dir) || terminateTesting(1, $msg."Unable to mkdir $instance_dir\n");
|
| 50 |
mkdir($instance_dir.'/files') || terminateTesting(1, $msg."Unable to crate files dir\n");
|
| 51 |
|
| 52 |
$forbidden_dirs = array('.', '..', 'CVS');
|
| 53 |
if ($project_name == "Drupal") {
|
| 54 |
$forbidden_dirs[] = 'modules';
|
| 55 |
$patch_dir = $instance_dir;
|
| 56 |
} else {
|
| 57 |
$patch_dir = $instance_dir.'/modules/'.$project_name;
|
| 58 |
$simpletest_modules[] = $project_name;
|
| 59 |
}
|
| 60 |
$profile_modules = array_merge($default_modules, $simpletest_modules);
|
| 61 |
|
| 62 |
//Check out drupal core from cvs
|
| 63 |
$exec_cmd = 'cvs -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal co -d' . $instance.' -r ' . $branch . ' drupal';
|
| 64 |
exec($exec_cmd, $output, $status);
|
| 65 |
if ($status) {
|
| 66 |
terminateTesting(1, $msg."Unable to check Drupal branch $branch out of CVS.");
|
| 67 |
}
|
| 68 |
|
| 69 |
chdir($instance_dir) || terminateTesting(1, $msg."Unable to chdir to $instance_dir");
|
| 70 |
|
| 71 |
//Check out needed modules
|
| 72 |
foreach($simpletest_modules as $module) {
|
| 73 |
$exec_cmd = 'cvs -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib co -d modules/'.$module.' -r ' . $branch . ' contributions/modules/'.$module;
|
| 74 |
print($exec_cmd);
|
| 75 |
exec($exec_cmd, $output, $status);
|
| 76 |
if ($status) {
|
| 77 |
terminateTesting(1, $msg."Unable to check $module module branch $branch out of CVS. CMD: $exec_cmd");
|
| 78 |
}
|
| 79 |
}
|
| 80 |
|
| 81 |
chdir("modules/simpletest") || terminateTesting(1, $msg."Unable to chdir to modules/simpletest");
|
| 82 |
|
| 83 |
//delete some tests until they are fixed
|
| 84 |
unlink('tests/upload_tests.test');
|
| 85 |
unlink('tests/taxonomy.module.test');
|
| 86 |
|
| 87 |
// Check out simpletest library from their cvs
|
| 88 |
$exec_cmd = 'cvs -z3 '. $simpletest_lib_cvs .' co -d simpletest -P simpletest';
|
| 89 |
exec($exec_cmd, $output, $status);
|
| 90 |
if ($status) {
|
| 91 |
terminateTesting(1, $msg."Unable to check out simpletest libraries from CVS.");
|
| 92 |
}
|
| 93 |
|
| 94 |
chdir($instance_dir) || terminateTesting(1, $msg."Unable to chdir to $instance_dir");
|
| 95 |
|
| 96 |
//creating database
|
| 97 |
$exec_cmd = "mysqladmin -u $db_user -p$db_pass create $instance";
|
| 98 |
exec($exec_cmd, $output, $status);
|
| 99 |
if ($status) {
|
| 100 |
terminateTesting(1, $msg."Unable to create database $instance.");
|
| 101 |
}
|
| 102 |
print($exec_cmd);
|
| 103 |
//changing sed output to same file ends up with empty file thats why /tmp is used
|
| 104 |
$exec_cmd = 'sed "s/' .
|
| 105 |
preg_quote('mysql://username:password@localhost/databasename', '/') . '/' .
|
| 106 |
preg_quote('mysql://' . $db_user . ':' . $db_pass . '@localhost/' . $instance, '/' ) . '/; /' .
|
| 107 |
'# \$base_url/a\\' .
|
| 108 |
'$base_url = \''.
|
| 109 |
preg_quote($test_server_url . $instance, '/') . '\';" ' .
|
| 110 |
'sites/default/settings.php > /tmp/'.$instance.'settings.php; mv /tmp/'.$instance.'settings.php sites/default/settings.php';
|
| 111 |
|
| 112 |
exec($exec_cmd, $output, $status);
|
| 113 |
print($exec_cmd);
|
| 114 |
if ($status) {
|
| 115 |
terminateTesting(1, $msg."Unable to set this instance settings.");
|
| 116 |
}
|
| 117 |
|
| 118 |
$settings_file_content = file_get_contents('sites/default/settings.php');
|
| 119 |
if (!strstr($settings_file_content, $instance)) {
|
| 120 |
terminateTesting(1, $msg."Settings file was not modified correctly.");
|
| 121 |
}
|
| 122 |
|
| 123 |
installDrupal($version);
|
| 124 |
|
| 125 |
//inserting admin user
|
| 126 |
$exec_cmd = "mysql -u $db_user -p$db_pass $instance < $test_it_path/additions.mysql";
|
| 127 |
exec($exec_cmd, $output, $status);
|
| 128 |
if ($status) {
|
| 129 |
terminateTesting(1, $msg."Unable to insert additions into database.");
|
| 130 |
}
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
//applying patch
|
| 135 |
$exec_cmd = 'wget -O - '.$patch_url.' | patch -p0 ';
|
| 136 |
exec($exec_cmd, $outputPatch, $status);
|
| 137 |
if ($status) {
|
| 138 |
terminateTesting(1, "Unable to patch file.<br>" . implode("<br>", $outputPatch));
|
| 139 |
}
|
| 140 |
|
| 141 |
$test_result_file = '/tmp/'.$instance.'result.txt';
|
| 142 |
$exec_cmd = 'php modules/simpletest/run_all_tests.php > '.$test_result_file;
|
| 143 |
|
| 144 |
exec($exec_cmd, $output, $status);
|
| 145 |
|
| 146 |
$results = file_get_contents($test_result_file);
|
| 147 |
$msg .= $results;
|
| 148 |
|
| 149 |
if (!unlink($test_result_file)) {
|
| 150 |
terminateTesting(1, $msg."Failed to delete test result file");
|
| 151 |
}
|
| 152 |
|
| 153 |
terminateTesting(0, $msg);
|
| 154 |
|
| 155 |
/**
|
| 156 |
* Function that sends response to test server and calls exit
|
| 157 |
* @param return_address address of the server we would like to send results to
|
| 158 |
* @param node_id whihc node id is this response for
|
| 159 |
* @param exit_status arguemnt for exit call
|
| 160 |
* @param msg message string for sending to test server
|
| 161 |
*/
|
| 162 |
function terminateTesting($exit_status, $msg) {
|
| 163 |
global $drupal_dir, $return_address, $node_id, $output, $executed_commands, $debug;
|
| 164 |
$status = -1;
|
| 165 |
if ($exit_status == 0) {
|
| 166 |
$result = explode('\n', $msg);
|
| 167 |
$stats = $result[count($result)-1];
|
| 168 |
$stats = explode(', ', $stats);
|
| 169 |
$passes = 0;
|
| 170 |
$failes = 0;
|
| 171 |
foreach($stats as $stat) {
|
| 172 |
$stat = explode(': ', $stat);
|
| 173 |
switch ($stat[0]) {
|
| 174 |
case 'Passes':
|
| 175 |
$passes += $stat[1];
|
| 176 |
break;
|
| 177 |
case 'Failures':
|
| 178 |
case 'Exceptions':
|
| 179 |
$fails += $stat[1];
|
| 180 |
break;
|
| 181 |
}
|
| 182 |
}
|
| 183 |
if ($fails == 0 && $passes != 0) {
|
| 184 |
$status = 0;
|
| 185 |
}
|
| 186 |
else {
|
| 187 |
$status = 1;
|
| 188 |
}
|
| 189 |
}
|
| 190 |
if ($status == -1) {
|
| 191 |
$status == $exit_status;
|
| 192 |
}
|
| 193 |
fopen('.clean','w');
|
| 194 |
chdir($drupal_dir);
|
| 195 |
if ($debug) {
|
| 196 |
$commands = implode("<br>", $executed_commands);
|
| 197 |
$out = implode("<br>", $output);
|
| 198 |
$msg .= "Executed commands:<br>" . $commands . "<br>";
|
| 199 |
$msg .= "Output:<br>" . $out;
|
| 200 |
}
|
| 201 |
simpletestauto_writeResult($node_id, $msg, $status);
|
| 202 |
exit($exit_status);
|
| 203 |
}
|
| 204 |
|
| 205 |
/**
|
| 206 |
* Installs drupal
|
| 207 |
*/
|
| 208 |
function installDrupal($version) {
|
| 209 |
global $test_server_url, $instance, $profile_modules, $simpletest_modules, $db_user, $db_pass;
|
| 210 |
$output = NULL;
|
| 211 |
$status = NULL;
|
| 212 |
switch ($version) {
|
| 213 |
case 'HEAD':
|
| 214 |
enableTestModules($profile_modules, $version);
|
| 215 |
$exec_cmd = 'wget -O - '.$test_server_url.$instance.'/install.php?profile=test';
|
| 216 |
exec($exec_cmd, $output, $status);
|
| 217 |
if ($status) {
|
| 218 |
terminateTesting(1, "Unable to install drupal.");
|
| 219 |
}
|
| 220 |
break;
|
| 221 |
case '4.7':
|
| 222 |
$exec_cmd = "mysql -u $db_user -p$db_pass $instance < database/database.4.1.mysql";
|
| 223 |
exec($exec_cmd, $output, $status);
|
| 224 |
if ($status) {
|
| 225 |
terminateTesting(1, "Unable to insert tables into database.");
|
| 226 |
}
|
| 227 |
enableTestModules($simpletest_modules, $version);
|
| 228 |
break;
|
| 229 |
}
|
| 230 |
}
|
| 231 |
|
| 232 |
/**
|
| 233 |
* Returns a drupal branch name for that $version
|
| 234 |
* @param $version version of the branch
|
| 235 |
*/
|
| 236 |
function getBranchName($version) {
|
| 237 |
if ($version == 'HEAD') {
|
| 238 |
return 'HEAD';
|
| 239 |
}
|
| 240 |
return 'DRUPAL-'.str_replace(".", "-", $version);
|
| 241 |
}
|
| 242 |
|
| 243 |
/**
|
| 244 |
* creates a new profile file so that this modules
|
| 245 |
* are enabled at install time in drupal higher than 4.7
|
| 246 |
* @param $profile_modules array of modules that will be enabled
|
| 247 |
*/
|
| 248 |
function enableTestModules($modules, $version) {
|
| 249 |
global $instance_dir, $instance, $db_user, $db_pass;
|
| 250 |
$output = "";
|
| 251 |
$status = "";
|
| 252 |
chdir($instance_dir) || terminateTesting(1, "Unable to chdir to $instance_dir");
|
| 253 |
switch ($version) {
|
| 254 |
case 'HEAD':
|
| 255 |
//create test profile file so that all additional modules are enabled
|
| 256 |
$output = "<?php\nfunction test_profile_modules() {\n return array(";
|
| 257 |
foreach ($modules as $module) {
|
| 258 |
$output .= "\n'".$module."',";
|
| 259 |
}
|
| 260 |
$output .= "\n);\n}\n?>";
|
| 261 |
mkdir('profiles/test') || terminateTesting(1, "Unable to mkdir $instance_dir/profiles/test\n");
|
| 262 |
$handle = fopen("profiles/test/test.profile", "w");
|
| 263 |
if (fwrite($handle, $output) === FALSE) {
|
| 264 |
terminateTesting(1, "Could not write to test.profile.");
|
| 265 |
}
|
| 266 |
fclose($handle);
|
| 267 |
break;
|
| 268 |
case '4.7':
|
| 269 |
$output = "";
|
| 270 |
foreach ($modules as $module) {
|
| 271 |
$output .= "INSERT INTO system VALUES ('modules/$module/$module.module', '$module', 'module', '$module', 1, 0, 0, 0, 0);\n";
|
| 272 |
}
|
| 273 |
$handle = fopen("/tmp/$instance.sql", "w");
|
| 274 |
if (fwrite($handle, $output) === FALSE) {
|
| 275 |
terminateTesting(1, "Could not write additions to tmp file.");
|
| 276 |
}
|
| 277 |
fclose($handle);
|
| 278 |
$exec_cmd = "mysql -u $db_user -p$db_pass $instance < /tmp/$instance.sql";
|
| 279 |
exec($exec_cmd, $output, $status);
|
| 280 |
if ($status) {
|
| 281 |
terminateTesting(1, "Unable to execute $exec_cmd.");
|
| 282 |
}
|
| 283 |
break;
|
| 284 |
}
|
| 285 |
}
|
| 286 |
?>
|