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