MDL-19579 code coverage - summary reporting
[moodle.git] / admin / report / unittest / 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/** */
52f81103 13require_once(dirname(__FILE__).'/../../../config.php');
bee4702d 14require_once($CFG->libdir.'/adminlib.php');
52f81103 15require_once($CFG->libdir.'/simpletestlib.php');
3ef8c936 16require_once('ex_simple_test.php');
17require_once('ex_reporter.php');
18
f68cb08b 19// Always run the unit tests in developer debug mode.
20$CFG->debug = DEBUG_DEVELOPER;
21error_reporting($CFG->debug);
d83b1d06 22raise_memory_limit('256M');
f68cb08b 23
84ebf08d 24// page parameters
25$path = optional_param('path', null, PARAM_PATH);
26$showpasses = optional_param('showpasses', false, PARAM_BOOL);
27$showsearch = optional_param('showsearch', false, PARAM_BOOL);
db5af934 28
84ebf08d 29admin_externalpage_setup('reportsimpletest', '', array('showpasses'=>$showpasses, 'showsearch'=>$showsearch));
d994ced2 30
31$langfile = 'simpletest';
32$unittest = true;
33
a230012c 34global $UNITTEST;
35$UNITTEST = new object();
36
3ef8c936 37// Print the header.
4f9c6e27 38$strtitle = get_string('unittests', $langfile);
bee4702d 39
aa4f6af4 40if (!is_null($path)) {
cc320976 41 // Turn off xmlstrictheaders during the unit test run.
42 $origxmlstrictheaders = !empty($CFG->xmlstrictheaders);
43 $CFG->xmlstrictheaders = false;
44 admin_externalpage_print_header();
45 $CFG->xmlstrictheaders = $origxmlstrictheaders;
46 unset($origxmlstrictheaders);
47
aa4f6af4 48 // Create the group of tests.
dbff568e 49 $test = new AutoGroupTest($showsearch);
eef868d1 50
51 // OU specific. We use the _nonproject folder for stuff we want to
aa4f6af4 52 // keep in CVS, but which is not really relevant. It does no harm
53 // to leave this here.
54 $test->addIgnoreFolder($CFG->dirroot . '/_nonproject');
eef868d1 55
aa4f6af4 56 // Make the reporter, which is what displays the results.
57 $reporter = new ExHtmlReporter($showpasses);
eef868d1 58
aa4f6af4 59 if ($showsearch) {
60 print_heading('Searching for test cases');
61 }
62 flush();
eef868d1 63
aa4f6af4 64 // Work out what to test.
65 if (substr($path, 0, 1) == '/') {
66 $path = substr($path, 1);
67 }
68 $path = $CFG->dirroot . '/' . $path;
69 if (substr($path, -1) == '/') {
70 $path = substr($path, 0, -1);
71 }
72 $displaypath = substr($path, strlen($CFG->dirroot) + 1);
73 $ok = true;
74 if (is_file($path)) {
75 $test->addTestFile($path);
76 } else if (is_dir($path)){
77 $test->findTestFiles($path);
3ef8c936 78 } else {
aa4f6af4 79 print_simple_box(get_string('pathdoesnotexist', $langfile, $path), '', '', '', '', 'errorbox');
80 $ok = false;
81 }
eef868d1 82
aa4f6af4 83 // If we have something to test, do it.
84 if ($ok) {
85 if ($path == $CFG->dirroot) {
86 $title = get_string('moodleunittests', $langfile, get_string('all', $langfile));
87 } else {
88 $title = get_string('moodleunittests', $langfile, $displaypath);
89 }
90 print_heading($title);
91 $test->run($reporter);
3ef8c936 92 }
3ef8c936 93
aa4f6af4 94 $formheader = get_string('retest', $langfile);
95} else {
96 $displaypath = '';
cc320976 97 admin_externalpage_print_header();
aa4f6af4 98 $formheader = get_string('rununittests', $langfile);
99}
3ef8c936 100// Print the form for adjusting options.
88f94e58 101print_box_start('generalbox boxwidthwide boxaligncenter');
d27a349b 102print_heading($formheader);
7203167d 103echo '<form method="get" action="index.php">';
f689ff1a 104echo '<fieldset class="invisiblefieldset">';
4f9c6e27 105echo '<p>'; print_checkbox('showpasses', 1, $showpasses, get_string('showpasses', $langfile)); echo '</p>';
106echo '<p>'; print_checkbox('showsearch', 1, $showsearch, get_string('showsearch', $langfile)); echo '</p>';
3ef8c936 107echo '<p>';
4f9c6e27 108 echo '<label for="path">', get_string('onlytest', $langfile), '</label> ';
bae3a75c 109 echo '<input type="text" id="path" name="path" value="', $displaypath, '" size="40" />';
3ef8c936 110echo '</p>';
4f9c6e27 111echo '<input type="submit" value="' . get_string('runtests', $langfile) . '" />';
f689ff1a 112echo '</fieldset>';
3ef8c936 113echo '</form>';
d27a349b 114print_box_end();
2d5b05c8 115
d27a349b 116print_box_start('generalbox boxwidthwide boxaligncenter');
db5af934 117if (true) {
118 echo "<p>Fake test tables are disabled for now, sorry</p>"; // DO NOT LOCALISE!!! to be removed soon
119
120} else if (empty($CFG->unittestprefix)) {
84ebf08d 121 print_heading(get_string('testdboperations', 'simpletest'));
122 // TODO: localise
123 echo '<p>Please add $CFG->unittestprefix="tst_"; or some other unique test table prefix if you want to execute all tests';
124
125} else {
d27a349b 126 print_heading(get_string('testdboperations', 'simpletest'));
127 echo '<p>'.get_string('unittestprefixsetting', 'simpletest', $CFG).'</p>';
2d5b05c8 128
d27a349b 129 echo '<form style="display:inline" method="get" action="index.php">';
2d5b05c8 130 echo '<fieldset class="invisiblefieldset">';
131 echo '<input type="hidden" name="setuptesttables" value="1" />';
132 echo '<input type="submit" value="' . get_string('reinstalltesttables', 'simpletest') . '" />';
133 echo '</fieldset>';
134 echo '</form>';
135}
bfaf310f 136print_box_end();
3ef8c936 137
d27a349b 138
3ef8c936 139// Footer.
1ae083e4 140admin_externalpage_print_footer();
3ef8c936 141
bee4702d 142?>