You are here

function drush_patterns_test_regular_expression in Patterns 7.2

1 string reference to 'drush_patterns_test_regular_expression'
patterns_drush_command in ./patterns.drush.inc
Implements hook_drush_command().

File

./patterns.drush.inc, line 660
Drush Patterns module commands

Code

function drush_patterns_test_regular_expression($test_re = '') {
  module_load_include('module', 'simpletest');
  module_load_include('inc', 'simpletest', 'simpletest.pages');
  global $verbose, $color;
  $verbose = is_null(drush_get_option('detail')) ? FALSE : TRUE;
  $color = is_null(drush_get_option('color')) ? FALSE : TRUE;
  $error_on_fail = is_null(drush_get_option('error-on-fail')) ? FALSE : TRUE;
  if (!preg_match("/^\\/.*\\//", $test_re)) {
    $test_re = "/{$test_re}/";
  }
  $all_test_classes = simpletest_test_get_all();

  //print_r($all_test_classes);

  // Check that the test class parameter has been set.
  if (empty($test_re)) {
    drush_print("\nAvailable test groups & classes");
    drush_print("-------------------------------");
    $current_group = '';
    foreach ($all_test_classes as $class => $details) {
      if (class_exists($class) && method_exists($class, 'getInfo')) {
        $info = call_user_func(array(
          $class,
          'getInfo',
        ));
        if ($info['group'] != $current_group) {
          $current_group = $info['group'];
          drush_print('[' . $current_group . ']');
        }
        drush_print("\t" . $class . ' - ' . $info['name']);
      }
    }
    return;
  }

  // Find test classes that match
  foreach ($all_test_classes as $class => $details) {
    if (class_exists($class) && method_exists($class, 'getInfo')) {
      if (preg_match($test_re, $class)) {
        $info = call_user_func(array(
          $class,
          'getInfo',
        ));
        $matching_classes[$class] = $info;
      }
    }
  }
  $matching_classes = $all_test_classes['Patterns'];

  //print_r($matching_classes);
  $tests_list = array();
  foreach ($matching_classes as $class_name => $details) {
    if (class_exists($class_name)) {
      $tests_list[] = $class_name;
    }
  }

  //print_r($matching_classes);

  // Limit the number of tests for now
  $tests_list = array(
    //$tests_list[0],
    $tests_list[1],
  );
  $total_tests = count($tests_list);
  $test_id = simpletest_run_tests($tests_list, 'drupal');
  $batch =& batch_get();
  $batch['progressive'] = FALSE;
  drush_backend_batch_process();
  $results = simpletest_result_get($test_id);

  //print_r($results);
  $analysis = _patterns_drush_test_check_results($results);

  //print_r($analysis);
  $fail = FALSE;
  foreach ($analysis as $area => $failed) {
    if ($failed > 0) {
      $fail = TRUE;
      drush_set_error($area . ' ' . $failed . ' tests failed');
    }
  }
  if ($failed) {
    exit(1);
  }
  else {
    exit(0);
  }
}