major whitespace cleanup - fixed tabs
[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
3ef8c936 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. */
24define('UNITTEST', true);
4f9c6e27 25$langfile = 'simpletest';
3ef8c936 26
3ef8c936 27// CGI arguments
aa4f6af4 28$path = optional_param('path', null, PARAM_PATH);
3ef8c936 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
3ef8c936 33// Print the header.
aa4f6af4 34$adminroot = admin_get_root();
35admin_externalpage_setup('reportsimpletest', $adminroot);
4f9c6e27 36$strtitle = get_string('unittests', $langfile);
bee4702d 37admin_externalpage_print_header($adminroot);
38
aa4f6af4 39if (!is_null($path)) {
40 // Create the group of tests.
41 $test =& new AutoGroupTest($showsearch, $thorough);
42
43 // OU specific. We use the _nonproject folder for stuff we want to
44 // keep in CVS, but which is not really relevant. It does no harm
45 // to leave this here.
46 $test->addIgnoreFolder($CFG->dirroot . '/_nonproject');
47
48 // Make the reporter, which is what displays the results.
49 $reporter = new ExHtmlReporter($showpasses);
50
51 if ($showsearch) {
52 print_heading('Searching for test cases');
53 }
54 flush();
55
56 // Work out what to test.
57 if (substr($path, 0, 1) == '/') {
58 $path = substr($path, 1);
59 }
60 $path = $CFG->dirroot . '/' . $path;
61 if (substr($path, -1) == '/') {
62 $path = substr($path, 0, -1);
63 }
64 $displaypath = substr($path, strlen($CFG->dirroot) + 1);
65 $ok = true;
66 if (is_file($path)) {
67 $test->addTestFile($path);
68 } else if (is_dir($path)){
69 $test->findTestFiles($path);
3ef8c936 70 } else {
aa4f6af4 71 print_simple_box(get_string('pathdoesnotexist', $langfile, $path), '', '', '', '', 'errorbox');
72 $ok = false;
73 }
74
75 // If we have something to test, do it.
76 if ($ok) {
77 if ($path == $CFG->dirroot) {
78 $title = get_string('moodleunittests', $langfile, get_string('all', $langfile));
79 } else {
80 $title = get_string('moodleunittests', $langfile, $displaypath);
81 }
82 print_heading($title);
83 $test->run($reporter);
3ef8c936 84 }
3ef8c936 85
aa4f6af4 86 $formheader = get_string('retest', $langfile);
87} else {
88 $displaypath = '';
89 $formheader = get_string('rununittests', $langfile);
90}
3ef8c936 91// Print the form for adjusting options.
92print_simple_box_start('center', '70%');
93echo '<form method="GET" action="index.php">';
aa4f6af4 94print_heading($formheader);
4f9c6e27 95echo '<p>'; print_checkbox('showpasses', 1, $showpasses, get_string('showpasses', $langfile)); echo '</p>';
96echo '<p>'; print_checkbox('showsearch', 1, $showsearch, get_string('showsearch', $langfile)); echo '</p>';
97echo '<p>'; print_checkbox('thorough', 1, $thorough, get_string('thorough', $langfile)); echo '</p>';
3ef8c936 98echo '<p>';
4f9c6e27 99 echo '<label for="path">', get_string('onlytest', $langfile), '</label> ';
3ef8c936 100 echo '<input type="text" id="path" name="path" value="', $displaypath, '" size="60" />';
101echo '</p>';
4f9c6e27 102echo '<input type="submit" value="' . get_string('runtests', $langfile) . '" />';
3ef8c936 103echo '</form>';
104print_simple_box_end();
105
106// Footer.
bee4702d 107admin_externalpage_print_footer($adminroot);
3ef8c936 108
bee4702d 109?>