View source
<?php
class DrupalReporter extends SimpleReporter {
var $_output_error = '';
var $_character_set;
var $_fails_stack = array(
0,
);
var $_exceptions_stack = array(
0,
);
var $_passes_stack = array(
0,
);
var $_progress_stack = array(
0,
);
var $test_info_stack = array();
var $form;
var $form_depth = array();
var $current_field_set = array();
var $content_count = 0;
var $weight = -10;
var $test_stack = array();
function DrupalReporter($character_set = 'ISO-8859-1') {
$this
->SimpleReporter();
drupal_add_css(drupal_get_path('module', 'simpletest') . '/simpletest.css');
$this->_character_set = $character_set;
}
function paintHeader($test_name) {
}
function paintFooter($test_name) {
$ok = $this
->getFailCount() + $this
->getExceptionCount() == 0;
$class = $ok ? 'simpletest-pass' : 'simpletest-fail';
$this
->writeContent('<strong>' . $this
->getPassCount() . '</strong> passes, <strong>' . $this
->getFailCount() . '</strong> fails and <strong>' . $this
->getExceptionCount() . '<strong> exceptions.');
}
function paintPass($message) {
parent::paintPass($message);
$this->test_stack[] = array(
'data' => array(
$this
->_htmlEntities($message),
'OK',
),
'class' => 'simpletest-pass',
);
}
function paintFail($message) {
parent::paintFail($message);
$this->test_stack[] = array(
'data' => array(
$this
->_htmlEntities($message),
'FAIL',
),
'class' => 'simpletest-fail',
);
}
function paintError($message) {
parent::paintError($message);
$this->test_stack[] = array(
'data' => array(
$this
->_htmlEntities($message),
'EXCEPTION',
),
'class' => 'simpletest-fail',
);
}
function paintGroupStart($test_name, $size, $extra = '') {
$this->_progress_stack[] = $this->_progress;
$this->_progress = 0;
$this->_exceptions_stack[] = $this->_exceptions;
$this->_exceptions = 0;
$this->_fails_stack[] = $this->_fails;
$this->_fails = 0;
$this->_passes_stack[] = $this->_passes;
$this->_passes = 0;
$this->form_depth[] = $test_name;
$this
->writeToLastField($this->form, array(
'#type' => 'fieldset',
'#title' => $test_name,
'#weight' => $this->weight++,
), $this->form_depth);
if (!isset($this->_size)) {
$this->_size = $size;
}
if (($c = count($this->test_info_stack)) > 0) {
$info = $this->test_info_stack[$c - 1];
$this
->writeContent('<strong>' . $info['name'] . '</strong>: ' . $info['desc'], $this
->getParentWeight());
}
$this->_test_stack[] = $test_name;
}
function paintCaseStart($test_name) {
$this->_progress++;
$this
->paintGroupStart($test_name, 1);
}
function paintGroupEnd($test_name) {
array_pop($this->_test_stack);
$ok = $this
->getFailCount() + $this
->getExceptionCount() == 0;
$class = $ok ? "simpletest-pass" : "simpletest-fail";
$parent_weight = $this
->getParentWeight() - 0.5;
if ($this->_output_stack_id == 2 && $this->_output_stack[$this->_output_stack_id]['size'] == 1) {
$this
->writeContent(format_plural($this
->getTestCaseProgress(), '1 test case complete: ', '@count test cases complete: '), -10);
$parent_weight = $this
->getParentWeight() - 0.5;
$this
->writeContent('<strong>' . $this
->getPassCount() . '</strong> passes, <strong>' . $this
->getFailCount() . '</strong> fails and <strong>' . $this
->getExceptionCount() . '</strong> exceptions.', $parent_weight, $class);
array_pop($this->form_depth);
}
else {
$collapsed = $ok ? TRUE : FALSE;
if ($this
->getTestCaseProgress()) {
$this
->writeContent(format_plural($this
->getTestCaseProgress(), '1 test case complete: ', '@count test cases complete: '), -10);
$use_grouping = FALSE;
}
else {
$use_grouping = TRUE;
}
$write = array(
'#collapsible' => $use_grouping,
'#collapsed' => $collapsed,
);
$this
->writeToLastField($this->form, $write, $this->form_depth);
$this
->writeContent('<strong>' . $this
->getPassCount() . '</strong> passes, <strong>' . $this
->getFailCount() . '</strong> fails and <strong>' . $this
->getExceptionCount() . '</strong> exceptions.', $parent_weight, $class);
if (count($this->test_stack) != 0) {
$this
->writeContent(theme('table', array(), $this->test_stack));
unset($this->test_stack);
}
array_pop($this->form_depth);
}
$this->_progress += array_pop($this->_progress_stack);
$this->_exceptions += array_pop($this->_exceptions_stack);
$this->_fails += array_pop($this->_fails_stack);
$this->_passes += array_pop($this->_passes_stack);
}
function paintCaseEnd($test_name) {
$this
->paintGroupEnd($test_name);
}
function _htmlEntities($message) {
return htmlentities($message, ENT_COMPAT, $this->_character_set);
}
function getOutput() {
return drupal_get_form('unit_tests', $this);
}
function writeToLastField(&$form, $attr, $keys) {
while (count($keys) != 0) {
$value = array_shift($keys);
if (isset($form[$value])) {
if (count($keys) == 0) {
$form[$value] += $attr;
}
else {
$this
->writeToLastField($form[$value], $attr, $keys);
}
$keys = array();
}
else {
$form[$value] = $attr;
}
}
}
function writeContent($msg, $weight = NULL, $class = 'simpletest') {
if (!$weight) {
$weight = $this->weight++;
}
$write['content' . $this->content_count++] = array(
'#value' => '<div class=' . $class . '>' . $msg . '</div>',
'#weight' => $weight,
);
$this
->writeToLastField($this->form, $write, $this->form_depth);
}
function getParentWeight($form = NULL, $keys = NULL) {
if (!isset($form)) {
$form = $this->form;
}
if (!isset($keys)) {
$keys = $this->form_depth;
}
if (count($keys) != 0) {
$value = array_shift($keys);
return $this
->getParentWeight($form[$value], $keys);
}
return $form['#weight'];
}
}
function unit_tests($reporter) {
return $reporter->form;
}