simpletest.theme.inc 4.86 KB
Newer Older
1 2 3 4 5 6 7 8
<?php

/**
 * @file
 * Page callbacks for simpletest module.
 */

/**
9
 * Returns HTML for a test list generated by simpletest_test_form() into a table.
10
 *
11 12
 * @param $variables
 *   An associative array containing:
13
 *   - table: A render element representing the table.
14
 *
15
 * @ingroup themeable
16
 */
17 18 19
function theme_simpletest_test_table($variables) {
  $table = $variables['table'];

20
  drupal_add_library('simpletest', 'drupal.simpletest');
21 22 23

  // Create header for test selection table.
  $header = array(
24
    array('class' => array('select-all')),
25 26
    array('data' => t('Test'), 'class' => array('simpletest_test')),
    array('data' => t('Description'), 'class' => array('simpletest_description')),
27 28 29 30 31
  );

  // Define the images used to expand/collapse the test groups.
  $js = array(
    'images' => array(
32 33
      theme('image', array('uri' => 'core/misc/menu-collapsed.png', 'width' => 7, 'height' => 7, 'alt' => t('Expand'), 'title' => t('Expand'))) . ' <a href="#" class="simpletest-collapse">(' . t('Expand') . ')</a>',
      theme('image', array('uri' => 'core/misc/menu-expanded.png', 'width' => 7, 'height' => 7, 'alt' => t('Collapse'), 'title' => t('Collapse'))) . ' <a href="#" class="simpletest-collapse">(' . t('Collapse') . ')</a>',
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    ),
  );

  // Cycle through each test group and create a row.
  $rows = array();
  foreach (element_children($table) as $key) {
    $element = &$table[$key];
    $row = array();

    // Make the class name safe for output on the page by replacing all
    // non-word/decimal characters with a dash (-).
    $test_class = strtolower(trim(preg_replace("/[^\w\d]/", "-", $key)));

    // Select the right "expand"/"collapse" image, depending on whether the
    // category is expanded (at least one test selected) or not.
49 50
    $collapsed = !empty($element['#collapsed']);
    $image_index = $collapsed ? 0 : 1;
51 52

    // Place-holder for checkboxes to select group of tests.
53
    $row[] = array('id' => $test_class, 'class' => array('simpletest-select-all'));
54 55 56

    // Expand/collapse image and group title.
    $row[] = array(
57 58 59
      'data' => '<div class="simpletest-image" id="simpletest-test-group-' . $test_class . '"></div>' .
        '<label for="' . $test_class . '-select-all" class="simpletest-group-label">' . $key . '</label>',
      'class' => array('simpletest-group-label'),
60 61
    );

62 63 64 65
    $row[] = array(
      'data' => '&nbsp;',
      'class' => array('simpletest-group-description'),
    );
66

67
    $rows[] = array('data' => $row, 'class' => array('simpletest-group'));
68 69 70 71 72 73 74 75 76

    // Add individual tests to group.
    $current_js = array(
      'testClass' => $test_class . '-test',
      'testNames' => array(),
      'imageDirection' => $image_index,
      'clickActive' => FALSE,
    );

77
    // Sorting $element by children's #title attribute instead of by class name.
78
    uasort($element, 'element_sort_by_title');
79

80 81 82 83 84
    // Cycle through each test within the current group.
    foreach (element_children($element) as $test_name) {
      $test = $element[$test_name];
      $row = array();

85
      $current_js['testNames'][] = $test['#id'];
86 87 88 89 90

      // Store test title and description so that checkbox won't render them.
      $title = $test['#title'];
      $description = $test['#description'];

91
      $test['#title_display'] = 'invisible';
92 93 94 95 96
      unset($test['#description']);

      // Test name is used to determine what tests to run.
      $test['#name'] = $test_name;

97 98 99 100 101 102
      $row[] = array(
        'data' => drupal_render($test),
        'class' => array('simpletest-test-select'),
      );
      $row[] = array(
        'data' => '<label for="' . $test['#id'] . '">' . $title . '</label>',
103
        'class' => array('simpletest-test-label', 'table-filter-text-source'),
104 105
      );
      $row[] = array(
106 107
        'data' => '<div class="description">' . format_string('@description (@class)', array('@description' => $description, '@class' => $test_name)) . '</div>',
        'class' => array('simpletest-test-description', 'table-filter-text-source'),
108
      );
109

110
      $rows[] = array('data' => $row, 'class' => array($test_class . '-test', ($collapsed ? 'js-hide' : '')));
111 112 113 114 115 116 117 118 119 120 121 122
    }
    $js['simpletest-test-group-' . $test_class] = $current_js;
    unset($table[$key]);
  }

  // Add js array of settings.
  drupal_add_js(array('simpleTest' => $js), 'setting');

  if (empty($rows)) {
    return '<strong>' . t('No tests to display.') . '</strong>';
  }
  else {
123
    return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'simpletest-form-table')));
124 125 126 127
  }
}

/**
128
 * Returns HTML for the summary status of a simpletest result.
129
 *
130 131 132 133 134
 * @param $variables
 *   An associative array containing:
 *   - form: A render element representing the form.
 *
 * @ingroup themeable
135
 */
136 137
function theme_simpletest_result_summary($variables) {
  $form = $variables['form'];
138
  return '<div class="simpletest-' . ($form['#ok'] ? 'pass' : 'fail') . '">' . _simpletest_format_summary_line($form) . '</div>';
139
}