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