These files still need tidying
[moodle.git] / admin / report / simpletest / index.php
CommitLineData
3ef8c936 1<?php
2/**
3 * Run the unit tests.
4 *
5 * @copyright &copy; 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
8 * @version $Id$
9 * @package SimpleTestEx
10 */
11
12/** */
13require_once(dirname(__FILE__) . '/../../../config.php');
14require_once($CFG->libdir . '/moodlelib.php');
15require_once('ex_simple_test.php');
16require_once('ex_reporter.php');
17
18/* The UNITTEST constant can be checked elsewhere if you need to know
19 * when your code is being run as part of a unit test. */
20define('UNITTEST', true);
4f9c6e27 21$langfile = 'simpletest';
3ef8c936 22
23require_login();
41d7209c 24require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
3ef8c936 25// CGI arguments
26$path = optional_param('path', '', PARAM_PATH);
27$showpasses = optional_param('showpasses', false, PARAM_BOOL);
28$showsearch = optional_param('showsearch', false, PARAM_BOOL);
29$thorough = optional_param('thorough', false, PARAM_BOOL);
30
31// Create the group of tests.
32$test =& new AutoGroupTest($showsearch, $thorough);
33
34// OU specific. We use the _nonproject folder for stuff we want to
35// keep in CVS, but which is not really relevant. It does no harm
36// to leave this here.
37$test->addIgnoreFolder($CFG->dirroot . '/_nonproject');
38
39// Make the reporter, which is what displays the results.
40$reporter = new ExHtmlReporter($showpasses);
41
42// Print the header.
4f9c6e27 43$strtitle = get_string('unittests', $langfile);
3ef8c936 44$stradmin = get_string('administration');
45print_header("$SITE->shortname: $strtitle", $SITE->fullname,
46 '<a href="../../index.php">' . get_string('administration') . '</a> -> ' .
47 '<a href="../../misc.php">' . get_string('miscellaneous') . '</a> -> ' .
48 '<a href="../../report.php">' . get_string('reports') . '</a> -> ' .
49 $strtitle, '', '<style type="text/css">' . $reporter->_getCss() . '</style>');
50if ($showsearch) {
51 print_heading('Searching for test cases');
52}
53flush();
54
55// Work out what to test.
56if (substr($path, 0, 1) == '/') {
57 $path = substr($path, 1);
58}
59$path = $CFG->dirroot . '/' . $path;
60if (substr($path, -1) == '/') {
61 $path = substr($path, 0, -1);
62}
63$displaypath = substr($path, strlen($CFG->dirroot) + 1);
64$ok = true;
65if (is_file($path)) {
66 $test->addTestFile($path);
67} else if (is_dir($path)){
68 $test->findTestFiles($path);
69} else {
4f9c6e27 70 print_simple_box(get_string('pathdoesnotexist', $langfile, $path), '', '', '', '', 'errorbox');
3ef8c936 71 $ok = false;
72}
73
74// If we have something to test, do it.
75if ($ok) {
76 if ($path == $CFG->dirroot) {
4f9c6e27 77 $title = get_string('moodleunittests', $langfile, get_string('all', $langfile));
3ef8c936 78 } else {
4f9c6e27 79 $title = get_string('moodleunittests', $langfile, $displaypath);
3ef8c936 80 }
81 print_heading($title);
82 $test->run($reporter);
83}
84
85// Print the form for adjusting options.
86print_simple_box_start('center', '70%');
87echo '<form method="GET" action="index.php">';
4f9c6e27 88print_heading(get_string('retest', $langfile));
89echo '<p>'; print_checkbox('showpasses', 1, $showpasses, get_string('showpasses', $langfile)); echo '</p>';
90echo '<p>'; print_checkbox('showsearch', 1, $showsearch, get_string('showsearch', $langfile)); echo '</p>';
91echo '<p>'; print_checkbox('thorough', 1, $thorough, get_string('thorough', $langfile)); echo '</p>';
3ef8c936 92echo '<p>';
4f9c6e27 93 echo '<label for="path">', get_string('onlytest', $langfile), '</label> ';
3ef8c936 94 echo '<input type="text" id="path" name="path" value="', $displaypath, '" size="60" />';
95echo '</p>';
4f9c6e27 96echo '<input type="submit" value="' . get_string('runtests', $langfile) . '" />';
3ef8c936 97echo '</form>';
98print_simple_box_end();
99
100// Footer.
101print_footer();
102
103?>