5 * @copyright © 2006 The Open University
6 * @author N.D.Freear@open.ac.uk, T.J.Hunt@open.ac.uk
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
9 * @package SimpleTestEx
13 require_once(dirname(__FILE__
).'/../../../config.php');
14 require_once($CFG->libdir
.'/adminlib.php');
15 require_once($CFG->libdir
.'/simpletestlib.php');
16 require_once('ex_simple_test.php');
17 require_once('ex_reporter.php');
20 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
, SITEID
));
22 /* The UNITTEST constant can be checked elsewhere if you need to know
23 * when your code is being run as part of a unit test. */
24 define('UNITTEST', true);
25 $langfile = 'simpletest';
28 $path = optional_param('path', null, PARAM_PATH
);
29 $showpasses = optional_param('showpasses', false, PARAM_BOOL
);
30 $showsearch = optional_param('showsearch', false, PARAM_BOOL
);
31 $thorough = optional_param('thorough', false, PARAM_BOOL
);
34 admin_externalpage_setup('reportsimpletest');
35 $strtitle = get_string('unittests', $langfile);
36 admin_externalpage_print_header();
38 if (!is_null($path)) {
39 // Create the group of tests.
40 $test =& new AutoGroupTest($showsearch, $thorough);
42 // OU specific. We use the _nonproject folder for stuff we want to
43 // keep in CVS, but which is not really relevant. It does no harm
44 // to leave this here.
45 $test->addIgnoreFolder($CFG->dirroot
. '/_nonproject');
47 // Make the reporter, which is what displays the results.
48 $reporter = new ExHtmlReporter($showpasses);
51 print_heading('Searching for test cases');
55 // Work out what to test.
56 if (substr($path, 0, 1) == '/') {
57 $path = substr($path, 1);
59 $path = $CFG->dirroot
. '/' . $path;
60 if (substr($path, -1) == '/') {
61 $path = substr($path, 0, -1);
63 $displaypath = substr($path, strlen($CFG->dirroot
) +
1);
66 $test->addTestFile($path);
67 } else if (is_dir($path)){
68 $test->findTestFiles($path);
70 print_simple_box(get_string('pathdoesnotexist', $langfile, $path), '', '', '', '', 'errorbox');
74 // If we have something to test, do it.
76 if ($path == $CFG->dirroot
) {
77 $title = get_string('moodleunittests', $langfile, get_string('all', $langfile));
79 $title = get_string('moodleunittests', $langfile, $displaypath);
81 print_heading($title);
82 $test->run($reporter);
85 $formheader = get_string('retest', $langfile);
88 $formheader = get_string('rununittests', $langfile);
90 // Print the form for adjusting options.
91 print_simple_box_start('center', '70%');
92 echo '<form method="get" action="index.php">';
93 echo '<fieldset class="invisiblefieldset">';
94 print_heading($formheader);
95 echo '<p>'; print_checkbox('showpasses', 1, $showpasses, get_string('showpasses', $langfile)); echo '</p>';
96 echo '<p>'; print_checkbox('showsearch', 1, $showsearch, get_string('showsearch', $langfile)); echo '</p>';
97 echo '<p>'; print_checkbox('thorough', 1, $thorough, get_string('thorough', $langfile)); echo '</p>';
99 echo '<label for="path">', get_string('onlytest', $langfile), '</label> ';
100 echo '<input type="text" id="path" name="path" value="', $displaypath, '" size="40" />';
102 echo '<input type="submit" value="' . get_string('runtests', $langfile) . '" />';
105 print_simple_box_end();
108 admin_externalpage_print_footer();