### Eclipse Workspace Patch 1.0
#P simpletest
Index: simpletest.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/simpletest.js,v
retrieving revision 1.2
diff -u -r1.2 simpletest.js
--- simpletest.js 18 Sep 2007 15:30:06 -0000 1.2
+++ simpletest.js 6 Apr 2008 00:53:05 -0000
@@ -1,34 +1,68 @@
// $Id: simpletest.js,v 1.2 2007/09/18 15:30:06 rokZlender Exp $
-/**
- * Creates a select all checkbox before in every test group fieldset
- */
+
$(document).ready(function() {
- $('.select_all').each(function() {
- var legend = $('> legend', this);
- var cbs = $('fieldset :checkbox', this);
- var collapsed = 1;
- var selectAllChecked = 1;
- var cbInitialValue = "";
+ // Adds expand-collapse functionality.
+ $('img.simpletest-menu-collapse').click(function(){
+ if($(this).data('collapsed') == 1){
+ $(this).data('collapsed', 0);
+ this.src = '/misc/menu-expanded.png';
+ }else{
+ $(this).data('collapsed',1);
+ this.src = '/misc/menu-collapsed.png';
+ }
+ // Toggle all of the trs.
+ $("tr."+this.id.replace(/\-menu\-collapse/,'')+"-test").toggle();
+ });
- for (i=0; i < cbs.length; i++) {
- if (!cbs[i].checked) {
+ $('.select-all').each(function() {
+ var checkbox = $('');
+ $('#'+ this.id).html(checkbox);
+
+ var checkboxes = $('.'+ this.id +'-test');
+ var selectAllChecked = 1;
+ var collapsed = 1;
+ for (var i = 0; i < checkboxes.length; i++) {
+ if (!checkboxes[i].checked) {
selectAllChecked = 0;
}
else {
collapsed = 0;
}
}
- if (!collapsed && !selectAllChecked)
- $('fieldset', this).removeClass('collapsed');
-
- var item = $('
').html(''+'Select all tests in group '+ legend.html() +'
');
- // finds all checkboxes in group fieldset and selects them or deselects
- item.find(':checkbox').attr('checked', selectAllChecked).click(function() {
- $(this).parents('fieldset:first').find('fieldset :checkbox').attr('checked', this.checked);
+ // Finds all checkboxes for particular test group and sets them to the "check all" state.
+ checkbox.attr('checked', selectAllChecked).click(function() {
+ // If it's checked, make sure that we can see all the sub-tests.
+ if(this.checked){
+ $(this.parentNode.parentNode).find("img.simpletest-menu-collapse").each(function(){
+ if($(this).data('collapsed') != 0){
+ $(this).data('collapsed',1);
+ $(this).click();
+ }
+ });
+ }
+ var rows = $('.'+ this.id +'-test');
+ for (var i = 0; i < rows.length; i++) {
+ $(rows[i]).find(':checkbox').attr('checked', this.checked);
+ }
}).end();
-
- // add select all checkbox
- legend.after(item);
});
-});
\ No newline at end of file
+
+ // Set the initial state of the expand-collapse.
+ $('img.simpletest-menu-collapse').each(function(){
+ //only set the state if it has not been set previously
+ if($(this).data('collapsed') == undefined){
+ $(this).data('collapsed',1);
+ // See if any of the child checkboxes are checked and expand the menu if they are.
+ var doCheck = false;
+ $("tr."+this.id.replace(/\-menu\-collapse/,'')+"-test").find("input").each(function(){
+ if(this.checked){
+ doCheck = true;
+ }
+ })
+ if(doCheck){
+ $(this).click()
+ }
+ }
+ });
+});
Index: simpletest.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/simpletest.module,v
retrieving revision 1.43
diff -u -r1.43 simpletest.module
--- simpletest.module 6 Apr 2008 00:23:10 -0000 1.43
+++ simpletest.module 6 Apr 2008 00:53:06 -0000
@@ -44,6 +44,17 @@
}
/**
+ * Implemenation of hook_theme().
+ */
+function simpletest_theme() {
+ return array(
+ 'simpletest_overview_form' => array(
+ 'arguments' => array('form' => NULL)
+ ),
+ );
+}
+
+/**
* Try to load the simepletest
* @return boolean TRUE if the load succeeded
*/
@@ -121,7 +132,9 @@
* Form callback; make the form to run tests
*/
function simpletest_overview_form() {
- $output = array();
+ $output = array(
+ "#theme" => 'simpletest_overview_form'
+ );
$total_test = &simpletest_get_total_test();
@@ -242,6 +255,62 @@
}
/**
+ * Theme the SimpleTest form that provides test selection.
+ *
+ * @ingroup themeable
+ */
+function theme_simpletest_overview_form($form) {
+ $header = array(
+ t('Test'),
+ t('Description'),
+ array('data' => t('Run'), 'class' => 'checkbox')
+ );
+
+ // Go through each test group and create a row.
+ $rows = array();
+ foreach (element_children($form) as $gid) {
+ if (isset($form[$gid]['tests'])) {
+ $element = &$form[$gid];
+ $test_class = strtolower(trim(preg_replace("/[^\w\d]/","-",$element["#title"])));
+
+ $row = array();
+ $row[] = array(
+ 'data' => theme('image', 'misc/menu-collapsed.png', 'Menu Collapse', 'Menu Collapse', array('id' => $test_class .'-menu-collapse', 'class' => 'simpletest-menu-collapse')) .
+ ' ',
+ 'style' => 'font-weight: bold;'
+ );
+ $row[] = $element['#description'];
+ $row[] = array('id' => $test_class, 'class' => 'select-all');
+ $rows[] = array('data' => $row, 'class' => 'odd');
+
+ // Go through each test in the group and create table rows setting them to invisible.
+ foreach (element_children($element['tests']) as $test_name) {
+ $test = $element['tests'][$test_name];
+ $row = array();
+ $row[] = theme('indentation', 1) .'';
+ $row[] = $test['#description'];
+
+ unset($test['#title']);
+ unset($test['#description']);
+ $test['#name'] = $test_name;
+ $row[] = drupal_render($test);
+ $row = array('data' => $row, 'style' => 'display:none;', 'class' => $test_class .'-test');
+ $rows[] = $row;
+ }
+ unset($form[$gid]); // Remove test group from form.
+ }
+ }
+ // Output test groups.
+ $output = '';
+ $output .= theme('table', $header, $rows, array());
+
+ // Output the rest of the form, excluded test groups which have been removed.
+ $output .= drupal_render($form);
+
+ return $output;
+}
+
+/**
* Actually runs tests
* @param array $testlist list of tests to run or DEFAULT NULL run all tests
* @param boolean $html_reporter true if you want results in simple html, FALSE for full drupal page