diff --git a/client/pifr_client.module b/client/pifr_client.module index ec49647..62064c6 100644 --- a/client/pifr_client.module +++ b/client/pifr_client.module @@ -19,7 +19,8 @@ define('PIFR_CHART_REPOSITORY', variable_get('pifr_chart_repository', 'git://git define('PIFR_MULTIVARIATE_REPOSITORY', variable_get('pifr_multivariate_repository', 'git://git.drupal.org/project/multivariate.git')); define('PIFR_SIMPLETEST_REPOSITORY', variable_get('pifr_simpletest_repository', 'git://git.drupal.org/project/chart.git')); define('PIFR_MENU_REWRITE_REPOSITORY', variable_get('pifr_menu_rewrite_repository', 'git://git.drupal.org/project/menu_rewrite.git')); - +define('PIFR_DRUPAL6_CURRENTBRANCH', '6.22'); +define('PIFR_DRUPAL7_CURRENTBRANCH', '7.x'); /** * The location of the PHP executable to be used when running tests. diff --git a/client/pifr_client.review.inc b/client/pifr_client.review.inc index 3cfabfb..bc65fa3 100644 --- a/client/pifr_client.review.inc +++ b/client/pifr_client.review.inc @@ -1,7 +1,7 @@ 'fieldset', - '#title' => t('Run'), + '#title' => t('Test Type'), ); - $form['run']['type'] = array( + $form['testtype']['test'] = array( '#type' => 'select', - '#title' => t('Type'), - '#description' => t('Full suite will be effected by the debug setting which can be set manually or auto ' . - 'triggered by the presence of SimpleTest.'), + '#title' => t('Select test plugin'), + '#options' => array( + 'simpletest' => t('SimpleTest'), + 'coder' => t('Code Review'), + ), + '#default_value' => 'pifr_simpletest', + '#description' => t('Represents the review plugin which will be invoked for this test.'), + ); + $form['testtype']['target'] = array( + '#type' => 'radios', + '#title' => t('Test Type'), '#options' => array( - 'default' => t('Default - Drupal 7, full suite'), - 'quick' => t('Quick - Drupal 7, NonDefaultBlockAdmin test case'), - 'fail' => t('Fail - Drupal 7, full suite, PHP exceptions'), - 'd6' => t('Drupal 6 - Several dependencies, full suite'), + 'core' => 'Core', + 'branch' => 'Project Branch', + 'file' => 'File', + 'patch' => 'Patch', ), + '#description' => t('Represents the object type which this test will target. (For Simpletest tests, File and Patch are equivalent.)'), + '#default_value' => 'branch', + ); + $form['testtype']['interrupt'] = array( + '#type' => 'checkbox', + '#title' => t('Interrupt any existing tests in progress'), ); - $form['run']['op'] = array( + + $form['testtype']['selecttype'] = array( '#type' => 'submit', - '#value' => t('Run'), + '#value' => t('Next >>'), ); return $form; } /** - * Run the pre-built tests. + * Client review form validation + */ +function pifr_client_review_form_validate($form, &$form_state) { + + // Ensure testbot is not actively testing + if (variable_get('pifr_client_test', FALSE)) { + module_load_include('inc', 'pifr_client', 'pifr_client.cron'); + + $test = variable_get('pifr_client_test', FALSE); + if ($form_state['values']['interrupt'] == TRUE) { + // Reset client to prepare for next test. + watchdog('pifr_client', 'Reset client to allow for local test run (t: @test_id).', array('@test_id' => $test['test_id'])); + pifr_client_cron_clear_variables(); + pifr_client_cron_test_processes_kill(pifr_client_cron_test_processes_get()); + } + else { + form_set_error('form', t('Unable to test due to an existing test in progress (t: @test_id).', array('@test_id' => $test['test_id']))); + } + } + + if (isset($form_state['storage']['plugin'])) { + switch ($form_state['storage']['plugin']) { + case 'coder': + // Coder Form Validation Steps + pifr_client_review_form_validate_coder($form, &$form_state); + break; + case 'simpletest': + default: + // Simpletest Form Validation Steps + pifr_client_review_form_validate_simpletest($form, &$form_state); + break; + } + } +} + +/** + * Client review form submission */ function pifr_client_review_form_submit($form, &$form_state) { - // Set the test variable so that the admin interface reacts accordingly. - $test = pifr_client_review_pre_built_test($form_state['values']['type']); - variable_set('pifr_client_test', $test); - // Keep track of how long review has been running. - variable_set('pifr_client_test_start', time()); + if ($form_state['clicked_button']['#id'] == 'edit-selecttype') { + // Handle plugin selection submission + $form_state['storage']['plugin'] = check_plain($form_state['values']['test']); + $form_state['storage']['target'] = check_plain($form_state['values']['target']); + } + else { + switch ($form_state['storage']['plugin']) { + case 'coder': + // Coder Form Submission Steps + pifr_client_review_form_submit_coder($form, $form_state); + break; + case 'simpletest': + default: + // Simpletest Form Submission Steps + pifr_client_review_form_submit_simpletest($form, $form_state); + break; + } + $form_state['rebuild'] = TRUE; + unset($form_state['storage']['plugin']); + } +} - if ($review = pifr_client_review_load($test)) { - $review->run(); +/** + * Client simpletest review form. + */ +function pifr_client_review_form_simpletest(&$form_state) { + $form = array(); - // Display test information. - drupal_set_message('Test: ' . pifr_client_review_export($test)); - drupal_set_message('Results: ' . pifr_client_review_export($review->get_result())); + $form['runsimpletest'] = array( + '#type' => 'fieldset', + '#title' => t('Customize Simpletest Test Parameters'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + ); - variable_del('pifr_client_test'); - variable_del('pfir_client_test_start'); + $form['runsimpletest']['version'] = array( + '#type' => 'select', + '#title' => t('Drupal Core Version'), + '#options' => array( + 'd6' => t('Drupal 6'), + 'd7' => t('Drupal 7'), + ), + '#default_value' => 'd7', + ); + + switch ($form_state['storage']['target']) { + case 'core': + $form['runsimpletest']['coretest'] = array( + '#type' => 'radios', + '#title' => t('Type of core test to run'), + '#options' => array( + t('Full suite (All test cases)'), + t('Quick test (Single test case)'), + t('Failure scenario (Apply bad patch)'), + ), + '#default_value' => 0, + '#description' => t('Full suite will be effected by the debug setting which can be set manually or auto triggered by the presence of SimpleTest.'), + ); + + // No additional parameters required for a 'core' review + break; + case 'file': + case 'patch': + $form['branchtests']['patchfile'] = array( + '#type' => 'file', + '#title' => t('Upload patch file'), + '#size' => 40, + '#weight' => 5, + ); + $form['#attributes']['enctype'] = "multipart/form-data"; + default: + $form['branchtests'] = array( + '#type' => 'fieldset', + '#title' => t('Identify Review Target'), + '#collapsible' => FALSE, + ); + + $desc = t('Please enter the Git repository location for the project which contains the branch to test.'); + $desc .= ' ' . t('This may be a full project link such as git://git.drupal.org/project/drupal.git,'); + $desc .= ' ' . t('or a sandbox project link such as git://git.drupal.org/sandbox/username/12345678.git.'); + + $form['branchtests']['repository'] = array( + '#type' => 'textfield', + '#title' => t('Project Repository'), + '#description' => $desc, + ); + + $desc = t('Please indicate the branch for which you want to run the test.'); + $desc .= ' ' . t('This value must match an existing tag or branch within your Git repository.'); + $desc .= ' ' . t('(Valid entries are listed under the "tags" and "heads" labels on the project repository summary page.)'); + + $form['branchtests']['branch'] = array( + '#type' => 'textfield', + '#title' => t('Project Branch'), + '#description' => $desc, + ); } + + $form['op'] = array( + '#type' => 'submit', + '#value' => t('Run Test'), + ); + + return $form; } /** - * Get a pre-built test, given the $type. - * - * @param string $type Test type, 'default', 'quick', 'fail', 'd6'. - * @return array Pre-built test information array. + * Validate the client simpletest review form. */ -function pifr_client_review_pre_built_test($type) { - // Get the default arguments to be passed to client. +function pifr_client_review_form_validate_simpletest($form, &$form_state) { + +} + +/** + * Submit the client simpletest review form. + */ +function pifr_client_review_form_submit_simpletest($form, &$form_state) { + // Get the default arguments to be passed to client module_load_include('review.inc', 'pifr_server'); $plugin = pifr_server_review_plugin_load('pifr_simpletest'); $default = $plugin->argument_default_get(); - if ($type == 'default' || $type == 'quick' || $type == 'fail') { - // Provide Drupal HEAD repository and blank patch. - $test = array( - 'test_id' => 17, - 'review' => array( - 'plugin' => 'pifr_simpletest', - 'argument' => $default, + // Generate basic simpletest $test array + $test = array( + 'test_id' => 17, + 'review' => array( + 'plugin' => 'pifr_simpletest', + 'argument' => $default, + ), + 'vcs' => array( + 'main' => array( + 'repository' => array( + 'type' => 'git', + 'url' => variable_get('pifr_drupal_repository', 'git://git.drupal.org/project/drupal.git'), + ), + 'vcs_identifier' => variable_get('pifr_confirmation_vcs_id', '7.2'), ), - 'vcs' => array( - 'main' => array( - 'repository' => array( - 'type' => 'git', - 'url' => variable_get('pifr_drupal_repository', 'git://git.drupal.org/project/drupal.git'), - ), - 'vcs_identifier' => variable_get('pifr_confirmation_vcs_id', '7.2'), + 'dependencies' => array(), + ), + 'files' => array(), + ); + + // Update vcs_identifier (and dependencies if needed) + if ($form_state['values']['version'] == 'd6') { + $test['vcs']['main']['vcs_identifier'] = PIFR_DRUPAL6_CURRENTBRANCH; + $test['review']['argument']['drupal.core.version'] = 6; + // Update dependencies + $test['vcs']['dependencies'] = array( + array( + 'repository' => array( + 'type' => 'git', + 'url' => variable_get('pifr_multivariate_repository', 'git://git.drupal.org/project/multivariate.git'), ), - 'dependencies' => array(), + 'vcs_identifier' => 'master', // GITMIGRATION Fragile ), - 'files' => array( - url(drupal_get_path('module', 'pifr_simpletest') . '/confirmation/pass.patch', array('absolute' => TRUE)), + array( + 'repository' => array( + 'type' => 'git', + 'url' => variable_get('pifr_chart_repository', 'git://git.drupal.org/project/chart.git'), + ), + 'vcs_identifier' => '6.x-1.3', // GITMIGRATION Fragile ), ); + } + elseif ($form_state['values']['version'] == 'd7') { + $test['vcs']['main']['vcs_identifier'] = PIFR_DRUPAL7_CURRENTBRANCH; + $test['review']['argument']['drupal.core.version'] = 7; + } + // Update with user-specific values + switch($form_state['storage']['target']) { + case 'patch': + case 'file': + $test['files'][] = file_create_url(file_create_path('localpatches') . '/' . $form_state['values']['file']->filename); + case 'branch': + // Update the 'dependencies' section with the project to be reviewed + $test['vcs']['dependencies'][] = array( + 'repository' => array( + 'type' => 'git', + 'url' => check_plain($form_state['values']['repository']), + ), + 'vcs_identifier' => check_plain($form_state['values']['branch']), + ); + break; + case 'core': + if ($form_state['values']['coretest'] == 1) { + // Quick test + if ($form_state['values']['version'] == 'd7') { + $test['review']['argument']['simpletest.tests'] = array('NonDefaultBlockAdmin'); + } + elseif ($form_state['values']['version'] == 'd6') { + $test['review']['argument']['simpletest.tests'] = array('SimpleTestFolderTestCase'); + } + } + elseif ($form_state['values']['coretest'] == 2) { + // Failure Scenario + $test['files'] = array( + url(drupal_get_path('module', 'pifr_simpletest') . '/confirmation/fail.patch', array('absolute' => TRUE)), + ); + } + break; + default: + break; + } - // Provide quickest test. - if ($type == 'quick') { - $test['review']['argument']['simpletest.tests'] = array('NonDefaultBlockAdmin'); - } - elseif ($type == 'fail') { - $test['files'] = array( - url(drupal_get_path('module', 'pifr_simpletest') . '/confirmation/fail.patch', array('absolute' => TRUE)), + // Set the test variable so that the admin interface reacts accordingly. + variable_set('pifr_client_test', $test); + + if ($review = pifr_client_review_load($test)) { + variable_set('pifr_client_test_start', time()); + $review->run(); + + // Display test information. + drupal_set_message('Test: ' . pifr_client_review_export($test)); + drupal_set_message('Results: ' . pifr_client_review_export($review->get_result())); + + variable_del('pifr_client_test'); + } +} + +/** + * Client coder review form. + */ +function pifr_client_review_form_coder(&$form_state) { + $form = array(); + + $form['runcoder'] = array( + '#type' => 'fieldset', + '#title' => t('Customize Coder Test Parameters'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + ); + + $form['runcoder']['version'] = array( + '#type' => 'select', + '#title' => t('Drupal Core Version'), + '#options' => array( + 'd6' => t('Drupal 6'), + 'd7' => t('Drupal 7'), + ), + '#default_value' => 'd7', + ); + + $reviews = array( + 'style' => t('Drupal Coding Standards'), + 'comment' => t('Drupal Commenting Standards'), + 'sql' => t('Drupal SQL Standards'), + 'security' => t('Drupal Security Standards'), + 'i18n' => t('Internationalization'), + 'coder_tough_love' => t('Coder Tough Love'), + ); + $form['runcoder']['reviews'] = array( + '#type' => 'checkboxes', + '#title' => t('Coder Reviews to run'), + '#options' => $reviews, + '#description' => t('Represents which Coder review components to enable for this test.'), + '#default_value' => array('style', 'comment', 'sql', 'security', 'i18n'), + ); + + $form['runcoder']['severity'] = array( + '#type' => 'radios', + '#title' => t('Coder Severity warning level'), + '#options' => array( + 'minor (most warnings)', + 'normal', + 'critical (fewest warnings)', + ), + '#default_value' => 1, + '#description' => t('Represents the severity level of errors which will be considered a failed test'), + ); + + switch ($form_state['storage']['target']) { + case 'core': + // No additional parameters required for a 'core' review + break; + default: + $form['branchtests'] = array( + '#type' => 'fieldset', + '#title' => t('Identify Review Target'), + '#collapsible' => FALSE, + ); + + $desc = t('Please enter the Git repository location for the project which contains the branch to test.'); + $desc .= ' ' . t('This may be a full project link such as git://git.drupal.org/project/drupal.git,'); + $desc .= ' ' . t('or a sandbox project link such as git://git.drupal.org/sandbox/username/12345678.git.'); + + $form['branchtests']['repository'] = array( + '#type' => 'textfield', + '#title' => t('Project Repository'), + '#description' => $desc, + ); + + $desc = t('Please indicate the branch for which you want to run the test.'); + $desc .= ' ' . t('This value must match an existing tag or branch within your Git repository.'); + $desc .= ' ' . t('(Valid entries are listed under the "tags" and "heads" labels on the project repository summary page.)'); + + $form['branchtests']['branch'] = array( + '#type' => 'textfield', + '#title' => t('Project Branch'), + '#description' => $desc, ); + } + + // Add the 'file' or 'patch' form fields as needed + if ($form_state['storage']['target'] == 'file') { + + $desc = t('Please supply the name and path of the file (relative to the git project directory above) which you want code reviewed.'); + $desc .= ' ' . t('(For example, if you want to review the "needsreview.inc" file in your module "includes" directory, enter "includes/needsreview.inc".)'); + + $form['branchtests']['filename'] = array( + '#type' => 'textfield', + '#title' => t('Project File (Path + Name)'), + '#description' => $desc, + '#weight' => 5, + ); + } + elseif ($form_state['storage']['target'] == 'patch') { + $form['branchtests']['patchfile'] = array( + '#type' => 'file', + '#title' => t('Upload patch file'), + '#size' => 40, + ); + $form['#attributes']['enctype'] = "multipart/form-data"; + } + + + $form['op'] = array( + '#type' => 'submit', + '#value' => t('Run Test'), + ); + + return $form; +} + +/** + * Validate the client coder review form + */ +function pifr_client_review_form_validate_coder($form, &$form_state) { + // At least one coder review must be checked + if (count($form_state['values']['reviews']) < 1) { + form_set_error('reviews', 'Please select at least one coder review component'); + } + // Target-specific validation + + if (isset($form_state['storage']['target'])) { + switch ($form_state['storage']['target']) { + case 'patch': + if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name']['patchfile'])) { + // Verify our local patches directory exists + $path = file_create_path("localpatches"); + file_check_directory($path, FILE_CREATE_DIRECTORY); + // Attempt to save the uploaded patch file + $file = file_save_upload('patchfile', array('pifr_client_validate_patchname' => array($_FILES['files'])), $path, FILE_EXISTS_REPLACE); + // Set error if file was not uploaded + if (!$file) { + form_set_error('patchfile', 'Error uploading patch file.'); + return; + } + // Set files to form_state for processing + $form_state['values']['file'] = $file; + } + default: + break; } } - elseif ($type == 'd6') { - // Contrib test with dependencies. - $test = array( - 'test_id' => 17, - 'review' => array( - 'plugin' => 'pifr_simpletest', - 'argument' => array( - 'drupal.core.version' => 6, - ) + $default, - ), - 'vcs' => array( - 'main' => array( - 'repository' => array( - 'type' => 'git', - 'url' => variable_get('pifr_drupal_repository', 'git://git.drupal.org/project/drupal.git'), - ), - 'vcs_identifier' => '6.x', - ), - 'dependencies' => array( - array( - 'repository' => array( - 'type' => 'git', - 'url' => variable_get('pifr_multivariate_repository', 'git://git.drupal.org/project/multivariate.git'), - ), - 'vcs_identifier' => 'master', // GITMIGRATION Fragile - ), - array( - 'repository' => array( - 'type' => 'git', - 'url' => variable_get('pifr_chart_repository', 'git://git.drupal.org/project/chart.git'), - ), - 'vcs_identifier' => '6.x-1.x', // GITMIGRATION Fragile - ), +} + +/** + * Validate patch file name + */ +function pifr_client_validate_patchname($files) { + if (substr($files->filename, strlen($files->filename) - 6, 6) != '.patch') { + return array('Invalid extension on patch file.'); + } + return array(); +} + +/** + * Submit the client coder review form + */ +function pifr_client_review_form_submit_coder($form, &$form_state) { + // Get the default arguments to be passed to client. + module_load_include('review.inc', 'pifr_server'); + $plugin = pifr_server_review_plugin_load('pifr_coder'); + $default = $plugin->argument_default_get(); + // Generate basic coder $test array + $test = array( + 'test_id' => 17, + 'review' => array( + 'plugin' => 'pifr_coder', + 'argument' => $default, + ), + 'vcs' => array( + 'main' => array( + 'repository' => array( + 'type' => 'git', + 'url' => variable_get('pifr_drupal_repository', 'git://git.drupal.org/project/drupal.git'), ), + 'vcs_identifier' => variable_get('pifr_confirmation_vcs_id', '7.x'), ), - 'files' => array( - url(drupal_get_path('module', 'pifr_simpletest') . '/confirmation/pass.patch', array('absolute' => TRUE)), - ), - ); + 'dependencies' => array(), + ), + 'files' => array(), + ); + + // Update vcs_identifier + if ($form_state['values']['version'] == 'd6') { + $test['vcs']['main']['vcs_identifier'] = PIFR_DRUPAL6_CURRENTBRANCH; + $test['review']['argument']['drupal.core.version'] = 6; + } + elseif ($form_state['values']['version'] == 'd7') { + $test['vcs']['main']['vcs_identifier'] = PIFR_DRUPAL7_CURRENTBRANCH; + $test['review']['argument']['drupal.core.version'] = 7; + } + // Update with user-specific values + switch ($form_state['storage']['target']) { + case 'branch': + // Update the 'vcs' section with the project to be reviewed. + // No need to clone a full drupal install for code review! + $test['vcs']['main']['repository']['url'] = check_plain($form_state['values']['repository']); + $test['vcs']['main']['vcs_identifier'] = check_plain($form_state['values']['branch']); + break; + case 'file': + // Update the 'vcs' section with the project to be reviewed. + // No need to clone a full drupal install for code review! + $test['vcs']['main']['repository']['url'] = check_plain($form_state['values']['repository']); + $test['vcs']['main']['vcs_identifier'] = check_plain($form_state['values']['branch']); + $test['review']['argument']['test.files'][] = check_plain($form_state['values']['filename']); + break; + case 'patch': + $test['vcs']['main']['repository']['url'] = check_plain($form_state['values']['repository']); + $test['vcs']['main']['vcs_identifier'] = check_plain($form_state['values']['branch']); + // We stored the file in /localpatches in the files directory + $test['files'][] = file_create_url(file_create_path('localpatches') . '/' . $form_state['values']['file']->filename); + break; + default: + break; + } + + // Update coder.reviews + $test['review']['argument']['coder.reviews'] = $form_state['values']['reviews']; + + // Update coder.severity + switch ($form_state['values']['severity']) { + case 0: + $test['review']['argument']['coder.severity'] = SEVERITY_MINOR; + break; + case 1: + $test['review']['argument']['coder.severity'] = SEVERITY_NORMAL; + break; + case 2: + $test['review']['argument']['coder.severity'] = SEVERITY_CRITICAL; + break; + } + + variable_set('pifr_client_test', $test); + + if ($review = pifr_client_review_load($test)) { + variable_set('pifr_client_test_start', time()); + $review->run(); + + // Display test information. + drupal_set_message('Test: ' . pifr_client_review_export($test)); + drupal_set_message('Results: ' . pifr_client_review_export($review->get_result())); + + variable_del('pifr_client_test'); + variable_del('pifr_client_test_start'); } - return $test; } /** @@ -250,3 +677,4 @@ function pifr_client_review_pre_built_test($type) { function pifr_client_review_export($var) { return '
' . highlight_string("", TRUE) . '
'; } + diff --git a/review/drupal/pifr_drupal.client.inc b/review/drupal/pifr_drupal.client.inc index cf82163..3633b56 100644 --- a/review/drupal/pifr_drupal.client.inc +++ b/review/drupal/pifr_drupal.client.inc @@ -47,59 +47,64 @@ class pifr_client_review_pifr_drupal extends pifr_client_review { pifr_debug('Test(%test_id) request received:
%test
', array('%test_id' => $this->test['test_id'], '%test' => print_r($test, TRUE))); $this->log('core_url = [' . $this->core_url . ']; Test repository = [' . $this->test['vcs']['main']['repository']['url'] . ']'); - if ($this->test['vcs']['main']['repository']['url'] != $this->core_url) { - // Main repository is not core, so this must be a module test. Move the - // module repository (main) to the dependencies and find the core - // repository in the dependencies and move it to main. - $this->test['vcs']['dependencies'][] = $this->test['vcs']['main']; - - // Store the project name 'simpletest' for use when applying patches. - $this->project_directory = basename($this->test['vcs']['main']['repository']['url']); - $this->project_directory = preg_replace('/\.git$/', '', $this->project_directory); - $this->log('Project directory is [' . $this->project_directory . ']'); - - - foreach ($this->test['vcs']['dependencies'] as $key => $dependency) { - if ($dependency['repository']['url'] == $this->arguments['drupal.core.url']) { - $this->test['vcs']['main'] = $dependency; - unset($this->test['vcs']['dependencies'][$key]); - break; + + + + if ($this->test['review']['plugin'] == 'pifr_simpletest') { + if ($this->test['vcs']['main']['repository']['url'] != $this->core_url) { + // Main repository is not core, so this must be a module test. Move the + // module repository (main) to the dependencies and find the core + // repository in the dependencies and move it to main. + $this->test['vcs']['dependencies'][] = $this->test['vcs']['main']; + + // Store the project name 'simpletest' for use when applying patches. + $this->project_directory = basename($this->test['vcs']['main']['repository']['url']); + $this->project_directory = preg_replace('/\.git$/', '', $this->project_directory); + $this->log('Project directory is [' . $this->project_directory . ']'); + + + foreach ($this->test['vcs']['dependencies'] as $key => $dependency) { + if ($dependency['repository']['url'] == $this->arguments['drupal.core.url']) { + $this->test['vcs']['main'] = $dependency; + unset($this->test['vcs']['dependencies'][$key]); + break; + } } } - } - // Add SimpleTest as dependencies, unless it has already been added. - if ($this->test['review']['argument']['drupal.core.version'] == 6) { - $simpletest_url = variable_get('pifr_simpletest_repository', 'git://git.drupal.org/project/simpletest.git'); - $found = FALSE; - foreach ($this->test['vcs']['dependencies'] as $key => $dependency) { - if ($dependency['repository']['url'] == $simpletest_url) { - $found = TRUE; - break; + // Add SimpleTest as dependencies, unless it has already been added. + if ($this->test['review']['argument']['drupal.core.version'] == 6) { + $simpletest_url = variable_get('pifr_simpletest_repository', 'git://git.drupal.org/project/simpletest.git'); + $found = FALSE; + foreach ($this->test['vcs']['dependencies'] as $key => $dependency) { + if ($dependency['repository']['url'] == $simpletest_url) { + $found = TRUE; + break; + } + } + + if (!$found) { + // Since SimpleTest is not included in Drupal 6 it needs to be checked + // out from contrib. + $this->test['vcs']['dependencies'][] = array( + 'repository' => array( + 'type' => 'git', + 'url' => $simpletest_url, + ), + 'vcs_identifier' => '6.x-2.x', + ); } } - - if (!$found) { - // Since SimpleTest is not included in Drupal 6 it needs to be checked - // out from contrib. - $this->test['vcs']['dependencies'][] = array( - 'repository' => array( - 'type' => 'git', - 'url' => $simpletest_url, - ), - 'vcs_identifier' => '6.x-2.x', - ); + + // Set the dependency directory. + $this->arguments['test.directory.dependency'] = $this->module_directory; + + // If the main project is not Drupal core then all patches should be + // applied from the root of the primary dependency or project directory. + if (!empty($this->project_directory)) { + $this->arguments['test.directory.apply'] = $this->module_directory . '/' . $this->project_directory; } } - - // Set the dependency directory. - $this->arguments['test.directory.dependency'] = $this->module_directory; - - // If the main project is not Drupal core then all patches should be - // applied from the root of the primary dependency or project directory. - if (!empty($this->project_directory)) { - $this->arguments['test.directory.apply'] = $this->module_directory . '/' . $this->project_directory; - } }