You are here

function _simpletest_batch_operation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/simpletest.module \_simpletest_batch_operation()

Implements callback_batch_operation().

1 string reference to '_simpletest_batch_operation'
simpletest_run_tests in core/modules/simpletest/simpletest.module
Runs tests.

File

core/modules/simpletest/simpletest.module, line 337
Provides testing functionality.

Code

function _simpletest_batch_operation($test_list_init, $test_id, &$context) {
  simpletest_classloader_register();

  // Get working values.
  if (!isset($context['sandbox']['max'])) {

    // First iteration: initialize working values.
    $test_list = $test_list_init;
    $context['sandbox']['max'] = count($test_list);
    $test_results = array(
      '#pass' => 0,
      '#fail' => 0,
      '#exception' => 0,
      '#debug' => 0,
    );
  }
  else {

    // Nth iteration: get the current values where we last stored them.
    $test_list = $context['sandbox']['tests'];
    $test_results = $context['sandbox']['test_results'];
  }
  $max = $context['sandbox']['max'];

  // Perform the next test.
  $test_class = array_shift($test_list);
  $test = new $test_class($test_id);
  $test
    ->run();
  $size = count($test_list);
  $info = TestDiscovery::getTestInfo($test_class);
  \Drupal::moduleHandler()
    ->invokeAll('test_finished', array(
    $test->results,
  ));

  // Gather results and compose the report.
  $test_results[$test_class] = $test->results;
  foreach ($test_results[$test_class] as $key => $value) {
    $test_results[$key] += $value;
  }
  $test_results[$test_class]['#name'] = $info['name'];
  $items = array();
  foreach (Element::children($test_results) as $class) {
    $class_test_result = $test_results[$class] + array(
      '#theme' => 'simpletest_result_summary',
      '#label' => t($test_results[$class]['#name'] . ':'),
    );
    array_unshift($items, drupal_render($class_test_result));
  }
  $context['message'] = t('Processed test @num of @max - %test.', array(
    '%test' => $info['name'],
    '@num' => $max - $size,
    '@max' => $max,
  ));
  $overall_results = $test_results + array(
    '#theme' => 'simpletest_result_summary',
    '#label' => t('Overall results:'),
  );
  $context['message'] .= drupal_render($overall_results);
  $item_list = array(
    '#theme' => 'item_list',
    '#items' => $items,
  );
  $context['message'] .= drupal_render($item_list);

  // Save working values for the next iteration.
  $context['sandbox']['tests'] = $test_list;
  $context['sandbox']['test_results'] = $test_results;

  // The test_id is the only thing we need to save for the report page.
  $context['results']['test_id'] = $test_id;

  // Multistep processing: report progress.
  $context['finished'] = 1 - $size / $max;
}