Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / admin / report / simpletest / index.php
blob974966e419605bd0398a7a5640b66431ac02ca42
1 <?php
2 /**
3 * Run the unit tests.
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
12 /** */
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');
19 require_login();
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';
27 // CGI arguments
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);
33 // Print the header.
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);
50 if ($showsearch) {
51 print_heading('Searching for test cases');
53 flush();
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);
64 $ok = true;
65 if (is_file($path)) {
66 $test->addTestFile($path);
67 } else if (is_dir($path)){
68 $test->findTestFiles($path);
69 } else {
70 print_simple_box(get_string('pathdoesnotexist', $langfile, $path), '', '', '', '', 'errorbox');
71 $ok = false;
74 // If we have something to test, do it.
75 if ($ok) {
76 if ($path == $CFG->dirroot) {
77 $title = get_string('moodleunittests', $langfile, get_string('all', $langfile));
78 } else {
79 $title = get_string('moodleunittests', $langfile, $displaypath);
81 print_heading($title);
82 $test->run($reporter);
85 $formheader = get_string('retest', $langfile);
86 } else {
87 $displaypath = '';
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>';
98 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" />';
101 echo '</p>';
102 echo '<input type="submit" value="' . get_string('runtests', $langfile) . '" />';
103 echo '</fieldset>';
104 echo '</form>';
105 print_simple_box_end();
107 // Footer.
108 admin_externalpage_print_footer();