2006-06-30 14:59:05 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Run the unit tests.
|
|
|
|
*
|
|
|
|
* @copyright © 2006 The Open University
|
|
|
|
* @author N.D.Freear@open.ac.uk, T.J.Hunt@open.ac.uk
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
|
* @version $Id$
|
|
|
|
* @package SimpleTestEx
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** */
|
2007-06-09 16:17:33 +00:00
|
|
|
require_once(dirname(__FILE__).'/../../../config.php');
|
2006-09-03 14:45:57 +00:00
|
|
|
require_once($CFG->libdir.'/adminlib.php');
|
2007-06-09 16:17:33 +00:00
|
|
|
require_once($CFG->libdir.'/simpletestlib.php');
|
2006-06-30 14:59:05 +00:00
|
|
|
require_once('ex_simple_test.php');
|
|
|
|
require_once('ex_reporter.php');
|
|
|
|
|
2009-03-23 04:12:37 +00:00
|
|
|
// Always run the unit tests in developer debug mode.
|
|
|
|
$CFG->debug = DEBUG_DEVELOPER;
|
|
|
|
error_reporting($CFG->debug);
|
|
|
|
|
2009-01-10 16:06:53 +00:00
|
|
|
// page parameters
|
|
|
|
$path = optional_param('path', null, PARAM_PATH);
|
|
|
|
$showpasses = optional_param('showpasses', false, PARAM_BOOL);
|
|
|
|
$showsearch = optional_param('showsearch', false, PARAM_BOOL);
|
2009-01-11 11:19:52 +00:00
|
|
|
|
2009-01-10 16:06:53 +00:00
|
|
|
admin_externalpage_setup('reportsimpletest', '', array('showpasses'=>$showpasses, 'showsearch'=>$showsearch));
|
2008-11-26 19:27:39 +00:00
|
|
|
|
|
|
|
$langfile = 'simpletest';
|
|
|
|
$unittest = true;
|
|
|
|
|
2008-06-13 08:35:29 +00:00
|
|
|
global $UNITTEST;
|
|
|
|
$UNITTEST = new object();
|
|
|
|
|
2006-06-30 14:59:05 +00:00
|
|
|
// Print the header.
|
2006-07-03 10:04:04 +00:00
|
|
|
$strtitle = get_string('unittests', $langfile);
|
2006-09-03 14:45:57 +00:00
|
|
|
|
2006-09-13 16:19:56 +00:00
|
|
|
if (!is_null($path)) {
|
2009-03-10 07:54:15 +00:00
|
|
|
// Turn off xmlstrictheaders during the unit test run.
|
|
|
|
$origxmlstrictheaders = !empty($CFG->xmlstrictheaders);
|
|
|
|
$CFG->xmlstrictheaders = false;
|
|
|
|
admin_externalpage_print_header();
|
|
|
|
$CFG->xmlstrictheaders = $origxmlstrictheaders;
|
|
|
|
unset($origxmlstrictheaders);
|
|
|
|
|
2006-09-13 16:19:56 +00:00
|
|
|
// Create the group of tests.
|
2009-01-10 14:02:31 +00:00
|
|
|
$test = new AutoGroupTest($showsearch);
|
2006-09-20 21:00:45 +00:00
|
|
|
|
|
|
|
// OU specific. We use the _nonproject folder for stuff we want to
|
2006-09-13 16:19:56 +00:00
|
|
|
// keep in CVS, but which is not really relevant. It does no harm
|
|
|
|
// to leave this here.
|
|
|
|
$test->addIgnoreFolder($CFG->dirroot . '/_nonproject');
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2006-09-13 16:19:56 +00:00
|
|
|
// Make the reporter, which is what displays the results.
|
|
|
|
$reporter = new ExHtmlReporter($showpasses);
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2006-09-13 16:19:56 +00:00
|
|
|
if ($showsearch) {
|
|
|
|
print_heading('Searching for test cases');
|
|
|
|
}
|
|
|
|
flush();
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2006-09-13 16:19:56 +00:00
|
|
|
// Work out what to test.
|
|
|
|
if (substr($path, 0, 1) == '/') {
|
|
|
|
$path = substr($path, 1);
|
|
|
|
}
|
|
|
|
$path = $CFG->dirroot . '/' . $path;
|
|
|
|
if (substr($path, -1) == '/') {
|
|
|
|
$path = substr($path, 0, -1);
|
|
|
|
}
|
|
|
|
$displaypath = substr($path, strlen($CFG->dirroot) + 1);
|
|
|
|
$ok = true;
|
|
|
|
if (is_file($path)) {
|
|
|
|
$test->addTestFile($path);
|
|
|
|
} else if (is_dir($path)){
|
|
|
|
$test->findTestFiles($path);
|
2006-06-30 14:59:05 +00:00
|
|
|
} else {
|
2006-09-13 16:19:56 +00:00
|
|
|
print_simple_box(get_string('pathdoesnotexist', $langfile, $path), '', '', '', '', 'errorbox');
|
|
|
|
$ok = false;
|
|
|
|
}
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2006-09-13 16:19:56 +00:00
|
|
|
// If we have something to test, do it.
|
|
|
|
if ($ok) {
|
|
|
|
if ($path == $CFG->dirroot) {
|
|
|
|
$title = get_string('moodleunittests', $langfile, get_string('all', $langfile));
|
|
|
|
} else {
|
|
|
|
$title = get_string('moodleunittests', $langfile, $displaypath);
|
|
|
|
}
|
|
|
|
print_heading($title);
|
|
|
|
$test->run($reporter);
|
2006-06-30 14:59:05 +00:00
|
|
|
}
|
|
|
|
|
2006-09-13 16:19:56 +00:00
|
|
|
$formheader = get_string('retest', $langfile);
|
|
|
|
} else {
|
|
|
|
$displaypath = '';
|
2009-03-10 07:54:15 +00:00
|
|
|
admin_externalpage_print_header();
|
2006-09-13 16:19:56 +00:00
|
|
|
$formheader = get_string('rununittests', $langfile);
|
|
|
|
}
|
2006-06-30 14:59:05 +00:00
|
|
|
// Print the form for adjusting options.
|
2008-09-05 07:44:07 +00:00
|
|
|
print_box_start('generalbox boxwidthwide boxaligncenter');
|
2008-09-23 06:42:18 +00:00
|
|
|
print_heading($formheader);
|
2006-11-30 09:32:46 +00:00
|
|
|
echo '<form method="get" action="index.php">';
|
2007-01-09 12:32:51 +00:00
|
|
|
echo '<fieldset class="invisiblefieldset">';
|
2006-07-03 10:04:04 +00:00
|
|
|
echo '<p>'; print_checkbox('showpasses', 1, $showpasses, get_string('showpasses', $langfile)); echo '</p>';
|
|
|
|
echo '<p>'; print_checkbox('showsearch', 1, $showsearch, get_string('showsearch', $langfile)); echo '</p>';
|
2006-06-30 14:59:05 +00:00
|
|
|
echo '<p>';
|
2006-07-03 10:04:04 +00:00
|
|
|
echo '<label for="path">', get_string('onlytest', $langfile), '</label> ';
|
2007-01-15 08:02:10 +00:00
|
|
|
echo '<input type="text" id="path" name="path" value="', $displaypath, '" size="40" />';
|
2006-06-30 14:59:05 +00:00
|
|
|
echo '</p>';
|
2006-07-03 10:04:04 +00:00
|
|
|
echo '<input type="submit" value="' . get_string('runtests', $langfile) . '" />';
|
2007-01-09 12:32:51 +00:00
|
|
|
echo '</fieldset>';
|
2006-06-30 14:59:05 +00:00
|
|
|
echo '</form>';
|
2008-09-23 06:42:18 +00:00
|
|
|
print_box_end();
|
2008-09-22 08:54:33 +00:00
|
|
|
|
2008-09-23 06:42:18 +00:00
|
|
|
print_box_start('generalbox boxwidthwide boxaligncenter');
|
2009-01-11 11:19:52 +00:00
|
|
|
if (true) {
|
|
|
|
echo "<p>Fake test tables are disabled for now, sorry</p>"; // DO NOT LOCALISE!!! to be removed soon
|
|
|
|
|
|
|
|
} else if (empty($CFG->unittestprefix)) {
|
2009-01-10 16:06:53 +00:00
|
|
|
print_heading(get_string('testdboperations', 'simpletest'));
|
|
|
|
// TODO: localise
|
|
|
|
echo '<p>Please add $CFG->unittestprefix="tst_"; or some other unique test table prefix if you want to execute all tests';
|
|
|
|
|
|
|
|
} else {
|
2008-09-23 06:42:18 +00:00
|
|
|
print_heading(get_string('testdboperations', 'simpletest'));
|
|
|
|
echo '<p>'.get_string('unittestprefixsetting', 'simpletest', $CFG).'</p>';
|
2008-09-22 08:54:33 +00:00
|
|
|
|
2008-09-23 06:42:18 +00:00
|
|
|
echo '<form style="display:inline" method="get" action="index.php">';
|
2008-09-22 08:54:33 +00:00
|
|
|
echo '<fieldset class="invisiblefieldset">';
|
|
|
|
echo '<input type="hidden" name="setuptesttables" value="1" />';
|
|
|
|
echo '<input type="submit" value="' . get_string('reinstalltesttables', 'simpletest') . '" />';
|
|
|
|
echo '</fieldset>';
|
|
|
|
echo '</form>';
|
|
|
|
}
|
2008-09-05 07:26:01 +00:00
|
|
|
print_box_end();
|
2006-06-30 14:59:05 +00:00
|
|
|
|
2008-09-23 06:42:18 +00:00
|
|
|
|
2006-06-30 14:59:05 +00:00
|
|
|
// Footer.
|
2007-04-30 17:08:34 +00:00
|
|
|
admin_externalpage_print_footer();
|
2006-06-30 14:59:05 +00:00
|
|
|
|
2006-09-03 14:45:57 +00:00
|
|
|
?>
|