2015-06-05 20:17:55 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Simpletest behaviors.
|
|
|
|
*/
|
|
|
|
|
2009-04-27 20:19:38 +00:00
|
|
|
(function ($) {
|
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
2014-03-25 21:42:11 +00:00
|
|
|
* Collapses table rows followed by group rows on the test listing page.
|
2015-06-05 20:17:55 +00:00
|
|
|
*
|
|
|
|
* @type {Drupal~behavior}
|
2015-08-29 06:29:40 +00:00
|
|
|
*
|
|
|
|
* @prop {Drupal~behaviorAttach} attach
|
|
|
|
* Attach collapse behavior on the test listing page.
|
2014-01-27 21:41:32 +00:00
|
|
|
*/
|
2014-03-25 21:42:11 +00:00
|
|
|
Drupal.behaviors.simpleTestGroupCollapse = {
|
2014-01-27 21:41:32 +00:00
|
|
|
attach: function (context) {
|
2015-03-23 10:29:17 +00:00
|
|
|
$(context).find('.simpletest-group').once('simpletest-group-collapse').each(function () {
|
2014-03-25 21:42:11 +00:00
|
|
|
var $group = $(this);
|
|
|
|
var $image = $group.find('.simpletest-image');
|
|
|
|
$image
|
|
|
|
.html(drupalSettings.simpleTest.images[0])
|
|
|
|
.on('click', function () {
|
|
|
|
var $tests = $group.nextUntil('.simpletest-group');
|
|
|
|
var expand = !$group.hasClass('expanded');
|
|
|
|
$group.toggleClass('expanded', expand);
|
|
|
|
$tests.toggleClass('js-hide', !expand);
|
|
|
|
$image.html(drupalSettings.simpleTest.images[+expand]);
|
|
|
|
});
|
2012-04-18 03:29:51 +00:00
|
|
|
});
|
2014-01-27 21:41:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-03-25 21:42:11 +00:00
|
|
|
* Toggles test checkboxes to match the group checkbox.
|
2015-06-05 20:17:55 +00:00
|
|
|
*
|
|
|
|
* @type {Drupal~behavior}
|
2015-08-29 06:29:40 +00:00
|
|
|
*
|
|
|
|
* @prop {Drupal~behaviorAttach} attach
|
|
|
|
* Attaches behavior for selecting all tests in a group.
|
2014-01-27 21:41:32 +00:00
|
|
|
*/
|
|
|
|
Drupal.behaviors.simpleTestSelectAll = {
|
|
|
|
attach: function (context) {
|
2015-03-23 10:29:17 +00:00
|
|
|
$(context).find('.simpletest-group').once('simpletest-group-select-all').each(function () {
|
2014-03-25 21:42:11 +00:00
|
|
|
var $group = $(this);
|
|
|
|
var $cell = $group.find('.simpletest-group-select-all');
|
|
|
|
var $groupCheckbox = $('<input type="checkbox" id="' + $cell.attr('id') + '-group-select-all" class="form-checkbox" />');
|
|
|
|
var $testCheckboxes = $group.nextUntil('.simpletest-group').find('input[type=checkbox]');
|
|
|
|
$cell.append($groupCheckbox);
|
|
|
|
|
|
|
|
// Toggle the test checkboxes when the group checkbox is toggled.
|
|
|
|
$groupCheckbox.on('change', function () {
|
2014-01-27 21:41:32 +00:00
|
|
|
var checked = $(this).prop('checked');
|
2014-03-25 21:42:11 +00:00
|
|
|
$testCheckboxes.prop('checked', checked);
|
2014-01-27 21:41:32 +00:00
|
|
|
});
|
|
|
|
|
2014-03-25 21:42:11 +00:00
|
|
|
// Update the group checkbox when a test checkbox is toggled.
|
|
|
|
function updateGroupCheckbox() {
|
|
|
|
var allChecked = true;
|
|
|
|
$testCheckboxes.each(function () {
|
|
|
|
if (!$(this).prop('checked')) {
|
|
|
|
allChecked = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$groupCheckbox.prop('checked', allChecked);
|
2009-01-19 10:15:54 +00:00
|
|
|
}
|
2014-07-02 18:48:06 +00:00
|
|
|
|
2014-03-25 21:42:11 +00:00
|
|
|
$testCheckboxes.on('change', updateGroupCheckbox);
|
2009-01-19 10:15:54 +00:00
|
|
|
});
|
2014-01-27 21:41:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filters the test list table by a text input search string.
|
|
|
|
*
|
|
|
|
* Text search input: input.table-filter-text
|
|
|
|
* Target table: input.table-filter-text[data-table]
|
|
|
|
* Source text: .table-filter-text-source
|
2015-06-05 20:17:55 +00:00
|
|
|
*
|
|
|
|
* @type {Drupal~behavior}
|
2015-08-29 06:29:40 +00:00
|
|
|
*
|
|
|
|
* @prop {Drupal~behaviorAttach} attach
|
|
|
|
* Attaches the filter behavior the the text input element.
|
2014-01-27 21:41:32 +00:00
|
|
|
*/
|
|
|
|
Drupal.behaviors.simpletestTableFilterByText = {
|
|
|
|
attach: function (context) {
|
|
|
|
var $input = $('input.table-filter-text').once('table-filter-text');
|
|
|
|
var $table = $($input.attr('data-table'));
|
|
|
|
var $rows;
|
|
|
|
var searched = false;
|
|
|
|
|
|
|
|
function filterTestList(e) {
|
|
|
|
var query = $(e.target).val().toLowerCase();
|
|
|
|
|
|
|
|
function showTestRow(index, row) {
|
|
|
|
var $row = $(row);
|
|
|
|
var $sources = $row.find('.table-filter-text-source');
|
|
|
|
var textMatch = $sources.text().toLowerCase().indexOf(query) !== -1;
|
|
|
|
$row.closest('tr').toggle(textMatch);
|
|
|
|
}
|
2009-01-19 10:15:54 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
// Filter if the length of the query is at least 3 characters.
|
|
|
|
if (query.length >= 3) {
|
2015-08-29 06:29:40 +00:00
|
|
|
// Indicate that a search has been performed, and hide the
|
|
|
|
// "select all" checkbox.
|
2014-01-27 21:41:32 +00:00
|
|
|
searched = true;
|
|
|
|
$('#simpletest-form-table thead th.select-all input').hide();
|
2009-01-19 10:15:54 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
$rows.each(showTestRow);
|
|
|
|
}
|
|
|
|
// Restore to the original state if any searching has occurred.
|
|
|
|
else if (searched) {
|
|
|
|
searched = false;
|
|
|
|
$('#simpletest-form-table thead th.select-all input').show();
|
2014-03-25 21:42:11 +00:00
|
|
|
// Restore all rows to their original display state.
|
|
|
|
$rows.css('display', '');
|
2014-01-27 21:41:32 +00:00
|
|
|
}
|
2013-06-19 19:51:04 +00:00
|
|
|
}
|
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
if ($table.length) {
|
|
|
|
$rows = $table.find('tbody tr');
|
|
|
|
$input.trigger('focus').on('keyup', Drupal.debounce(filterTestList, 200));
|
2013-06-19 19:51:04 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-27 21:41:32 +00:00
|
|
|
};
|
2013-06-19 19:51:04 +00:00
|
|
|
|
2009-02-18 13:46:55 +00:00
|
|
|
})(jQuery);
|