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