diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index bec96c4..b595d2c 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -54,8 +54,8 @@ function simpletest_permission() { function simpletest_theme() { return array( 'simpletest_result_summary' => array( - 'render element' => 'form', - 'file' => 'simpletest.theme.inc', + 'variables' => array('label' => NULL, 'items' => array(), 'pass' => 0, 'fail' => 0, 'exception' => 0, 'debug' => 0), + 'template' => 'simpletest-result-summary', ), ); } @@ -72,14 +72,55 @@ function simpletest_js_alter(&$javascript) { } } +/** + * Prepares variables for simpletest result summary templates. + * + * Default template: simpletest-result-summary.html.twig. + * + * @param array $variables + * An associative array containing: + * - label: An optional label to be rendered before the results. + * - ok: The overall group result pass or fail. + * - pass: The number of passed test results. + * - fail: The number of failed test results. + * - exception: The number of exceptioned test results. + * - debug: The number of debugged test results. + */ +function template_preprocess_simpletest_result_summary(&$variables) { + $variables['items'] = _simpletest_build_summary_line($variables); +} + +/** + * Formats each test result type pluralized summary. + * + * @param array $summary + * A summary of the test results. + * + * @return array + * The pluralized test summary items. + */ +function _simpletest_build_summary_line($summary) { + $translation = \Drupal::translation(); + $items['pass'] = $translation->formatPlural($summary['pass'], '1 pass', '@count passes'); + $items['fail'] = $translation->formatPlural($summary['fail'], '1 fail', '@count fails'); + $items['exception'] = $translation->formatPlural($summary['exception'], '1 exception', '@count exceptions'); + if ($summary['debug']) { + $items['debug'] = $translation->formatPlural($summary['debug'], '1 debug message', '@count debug messages'); + } + return $items; +} + +/** + * Formats test result summaries into a comma separated string for run-tests.sh. + * + * @param array $summary + * A summary of the test results. + * + * @return string + * A concatenated string of the formatted test results. + */ function _simpletest_format_summary_line($summary) { - $parts = array(); - $parts[] = $summary['#pass'] == 1 ? '1 pass' : $summary['#pass'] . ' passes'; - $parts[] = $summary['#fail'] == 1 ? '1 fail' : $summary['#fail'] . ' fails'; - $parts[] = $summary['#exception'] == 1 ? '1 exception' : $summary['#exception'] . ' exceptions'; - if ($summary['#debug']) { - $parts[] = $summary['#debug'] == 1 ? '1 debug message' : $summary['#debug'] . ' debug messages'; - } + $parts = _simpletest_build_summary_line($summary); return implode(', ', $parts); } @@ -307,10 +348,19 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) { $test_results[$test_class]['#name'] = $info['name']; $items = array(); foreach (Element::children($test_results) as $class) { - array_unshift($items, '