| 1 |
<?php |
<?php |
| 2 |
// $Id: project_issue_file_review.review.inc,v 1.8 2008/09/26 04:15:23 boombatower Exp $ |
// $Id: project_issue_file_review.review.inc,v 1.9 2008/09/30 21:53:50 boombatower Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* Automatically review patches attached to issues. |
* Automatically review patches attached to issues. |
| 67 |
|
|
| 68 |
// Install HEAD. |
// Install HEAD. |
| 69 |
if (!project_issue_file_review_review_install()) { |
if (!project_issue_file_review_review_install()) { |
| 70 |
// Inform master server that could install HEAD. |
// Inform master server that could not install HEAD. |
| 71 |
project_issue_file_review_review_send($file_id, FALSE, 'Failed to install HEAD.'); |
project_issue_file_review_review_send($file_id, FALSE, 'Failed to install HEAD.'); |
| 72 |
return; |
return; |
| 73 |
} |
} |
| 74 |
|
|
| 75 |
|
// Run tests. |
| 76 |
|
if (!project_issue_file_review_review_run_tests()) { |
| 77 |
|
// Inform master server that could not run tests. |
| 78 |
|
project_issue_file_review_review_send($file_id, FALSE, 'Failed to run tests.'); |
| 79 |
|
return; |
| 80 |
|
} |
| 81 |
|
|
| 82 |
// TODO Send actual review. |
// TODO Send actual review. |
| 83 |
project_issue_file_review_review_send($file_id, TRUE, 'Great file!'); |
project_issue_file_review_review_send($file_id, TRUE, 'Great file!'); |
| 84 |
} |
} |
| 183 |
* @return boolean Success. |
* @return boolean Success. |
| 184 |
*/ |
*/ |
| 185 |
function project_issue_file_review_review_install() { |
function project_issue_file_review_review_install() { |
| 186 |
global $db_url, $base_url; |
global $db_url; |
| 187 |
|
|
| 188 |
// Ensure we can run site by using symbolic link. |
// Ensure we can run site by using symbolic link. |
| 189 |
if (!file_exists('./checkout')) { |
if (!file_exists('./checkout')) { |
| 206 |
project_issue_file_review_review_working_directory(TRUE); |
project_issue_file_review_review_working_directory(TRUE); |
| 207 |
|
|
| 208 |
require_once drupal_get_path('module', 'simpletest') . '/drupal_web_test_case.php'; |
require_once drupal_get_path('module', 'simpletest') . '/drupal_web_test_case.php'; |
| 209 |
|
project_issue_file_review_review_path(); |
| 210 |
|
|
| 211 |
// Install Drupal. |
// Install Drupal. |
|
$checkout_url = variable_get('project_issue_file_review_checkout_url', 'http://localhost/~jimmy/checkout'); |
|
| 212 |
$d = new DrupalWebTestCase(); |
$d = new DrupalWebTestCase(); |
| 213 |
|
|
| 214 |
// Step: Select an installation profile. |
// Step: Select an installation profile. |
| 215 |
// Step: Choose language. |
// Step: Choose language. |
| 216 |
$d->drupalGet($base_url . '/checkout/install.php?profile=default&locale=en'); |
$d->drupalGet('install.php', array('query' => 'profile=default&locale=en')); |
| 217 |
|
|
| 218 |
// Step: Database configuration. |
// Step: Database configuration. |
| 219 |
$url = parse_url($db_url); |
$url = parse_url($db_url); |
| 227 |
// Call the installer script several times to simulate redirects that aren't supported by SimpleTest. |
// Call the installer script several times to simulate redirects that aren't supported by SimpleTest. |
| 228 |
$i = 0; |
$i = 0; |
| 229 |
do { |
do { |
| 230 |
$d->drupalGet($base_url . '/checkout/install.php?profile=default&locale=en&id=1&op=do_nojs'); |
$d->drupalGet('install.php', array('query' => 'profile=default&locale=en&id=1&op=do_nojs')); |
| 231 |
$done = strpos($d->drupalGetContent(), 'Remaining 0 of 10'); |
$done = strpos($d->drupalGetContent(), 'Remaining 0 of 10'); |
| 232 |
$i++; |
$i++; |
| 233 |
sleep(1); |
sleep(1); |
| 234 |
} while ($done === FALSE && $i < 5); |
} while ($done === FALSE && $i < 5); |
| 235 |
|
|
| 236 |
// Finalize installation batch. |
// Finalize installation batch. |
| 237 |
$d->drupalGet($base_url . '/checkout/install.php?profile=default&locale=en&id=1&op=finished'); |
$d->drupalGet('install.php', array('query' => 'profile=default&locale=en&id=1&op=finished')); |
| 238 |
|
|
| 239 |
// Step: Site configuration. |
// Step: Site configuration. |
| 240 |
$edit = array(); |
$edit = array(); |
| 248 |
$edit['update_status_module[1]'] = FALSE; |
$edit['update_status_module[1]'] = FALSE; |
| 249 |
$d->drupalPost(NULL, $edit, t('Save and continue')); |
$d->drupalPost(NULL, $edit, t('Save and continue')); |
| 250 |
|
|
| 251 |
|
// Record password use later. |
| 252 |
|
project_issue_file_review_review_admin_pass($pass); |
| 253 |
|
|
| 254 |
// Step: Finished. |
// Step: Finished. |
| 255 |
$d->assertText(t('Drupal installation complete')); |
$d->assertText(t('Drupal installation complete')); |
| 256 |
|
|
| 257 |
// Clear SimpleTest results. |
// Clear SimpleTest results. |
| 258 |
simpletest_clean_results_table(); |
simpletest_clean_results_table(); |
| 259 |
|
|
| 260 |
|
project_issue_file_review_review_path(TRUE); |
| 261 |
|
|
| 262 |
// Make sure that site installed correctly. |
// Make sure that site installed correctly. |
| 263 |
return ($d->_results['#exception'] + $d->_results['#fail']) == 0; |
return ($d->_results['#exception'] + $d->_results['#fail']) == 0; |
| 264 |
} |
} |
| 265 |
|
|
| 266 |
/** |
/** |
| 267 |
|
* Run tests on Drupal HEAD. |
| 268 |
|
* |
| 269 |
|
* @return boolean Success. |
| 270 |
|
*/ |
| 271 |
|
function project_issue_file_review_review_run_tests() { |
| 272 |
|
project_issue_file_review_review_path(); |
| 273 |
|
$pass = project_issue_file_review_review_admin_pass(); |
| 274 |
|
|
| 275 |
|
$d = new DrupalWebTestCase(); |
| 276 |
|
|
| 277 |
|
// Login as admin. |
| 278 |
|
$user = new stdClass(); |
| 279 |
|
$user->name = 'admin'; |
| 280 |
|
$user->pass_raw = $pass; |
| 281 |
|
$d->drupalLogin($user); |
| 282 |
|
|
| 283 |
|
// Enable SimpleTest. |
| 284 |
|
$edit = array(); |
| 285 |
|
$edit['modules[Core - optional][simpletest][enable]'] = TRUE; |
| 286 |
|
$d->drupalPost('admin/build/modules', $edit, t('Save configuration')); |
| 287 |
|
|
| 288 |
|
// Run tests. |
| 289 |
|
$edit = array(); |
| 290 |
|
$edit['PHPFitlerTestCase'] = TRUE; |
| 291 |
|
$d->drupalPost('admin/build/testing', $edit, t('Run tests')); |
| 292 |
|
|
| 293 |
|
project_issue_file_review_review_path(TRUE); |
| 294 |
|
|
| 295 |
|
return ($d->_results['#exception'] + $d->_results['#fail']) == 0; |
| 296 |
|
} |
| 297 |
|
|
| 298 |
|
/** |
| 299 |
* Cleanup after reviewing file and set the slave status to free. |
* Cleanup after reviewing file and set the slave status to free. |
| 300 |
*/ |
*/ |
| 301 |
function project_issue_file_review_review_cleanup() { |
function project_issue_file_review_review_cleanup() { |
| 346 |
} |
} |
| 347 |
|
|
| 348 |
/** |
/** |
| 349 |
|
* Set the original, Drupal set, or base_url and base_path to /checkout. |
| 350 |
|
* |
| 351 |
|
* @param boolean $original Original path. |
| 352 |
|
*/ |
| 353 |
|
function project_issue_file_review_review_path($original = FALSE) { |
| 354 |
|
global $base_url, $base_path; |
| 355 |
|
static $base_url_original, $base_path_original; |
| 356 |
|
|
| 357 |
|
if (!isset($base_url_original) || !isset($base_path_original)) { |
| 358 |
|
$base_url_original = $base_url; |
| 359 |
|
$base_path_original = $base_path; |
| 360 |
|
} |
| 361 |
|
|
| 362 |
|
if ($original) { |
| 363 |
|
$base_url = $base_url_original; |
| 364 |
|
$base_path = $base_path_original; |
| 365 |
|
} |
| 366 |
|
else { |
| 367 |
|
$base_url .= '/checkout'; |
| 368 |
|
$base_path = '/checkout'; |
| 369 |
|
} |
| 370 |
|
} |
| 371 |
|
|
| 372 |
|
/** |
| 373 |
|
* Store or retreive password. |
| 374 |
|
* |
| 375 |
|
* @param string $password Password to store. |
| 376 |
|
* @return string Stored password. |
| 377 |
|
*/ |
| 378 |
|
function project_issue_file_review_review_admin_pass($password = NULL) { |
| 379 |
|
static $_password; |
| 380 |
|
|
| 381 |
|
if ($password) { |
| 382 |
|
$_password = $password; |
| 383 |
|
} |
| 384 |
|
return $_password; |
| 385 |
|
} |
| 386 |
|
|
| 387 |
|
/** |
| 388 |
* Execute a system command in the background. |
* Execute a system command in the background. |
| 389 |
*/ |
*/ |
| 390 |
function project_issue_file_review_review_exec_background($command) { |
function project_issue_file_review_review_exec_background($command) { |