MDL-20204 new html_writer::checkbox fixed
[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
3ef8c936 8 * @package SimpleTestEx
9 */
10
11/** */
52f81103 12require_once(dirname(__FILE__).'/../../../config.php');
bee4702d 13require_once($CFG->libdir.'/adminlib.php');
e2074b8b 14require_once($CFG->libdir.'/simpletestcoveragelib.php');
3ef8c936 15require_once('ex_simple_test.php');
16require_once('ex_reporter.php');
17
f68cb08b 18// Always run the unit tests in developer debug mode.
19$CFG->debug = DEBUG_DEVELOPER;
20error_reporting($CFG->debug);
d83b1d06 21raise_memory_limit('256M');
f68cb08b 22
84ebf08d 23// page parameters
e2074b8b 24$path = optional_param('path', null, PARAM_PATH);
25$showpasses = optional_param('showpasses', false, PARAM_BOOL);
26$codecoverage = optional_param('codecoverage', 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.
e2074b8b 49 $test = new autogroup_test_coverage($showsearch, true, $codecoverage, 'Moodle Unit Tests Code Coverage Report', 'unittest');
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) {
2fff8846 60 echo $OUTPUT->heading('Searching for test cases');
aa4f6af4 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 {
8fbce1c8 79 echo $OUTPUT->box(get_string('pathdoesnotexist', $langfile, $path), 'errorbox');
aa4f6af4 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 }
2fff8846 90 echo $OUTPUT->heading($title);
e2074b8b 91 set_time_limit(300); // 5 mins
aa4f6af4 92 $test->run($reporter);
3ef8c936 93 }
3ef8c936 94
aa4f6af4 95 $formheader = get_string('retest', $langfile);
96} else {
97 $displaypath = '';
cc320976 98 admin_externalpage_print_header();
aa4f6af4 99 $formheader = get_string('rununittests', $langfile);
100}
3ef8c936 101// Print the form for adjusting options.
5d902b5d 102echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
2fff8846 103echo $OUTPUT->heading($formheader);
7203167d 104echo '<form method="get" action="index.php">';
f689ff1a 105echo '<fieldset class="invisiblefieldset">';
bfe57417 106echo '<p>'; echo $OUTPUT->checkbox(html_select_option::make_checkbox(1, $showpasses, get_string('showpasses', $langfile)), 'showpasses') ; echo '</p>';
107echo '<p>'; echo $OUTPUT->checkbox(html_select_option::make_checkbox(1, $showsearch, get_string('showsearch', $langfile)), 'showsearch') ; echo '</p>';
e2074b8b 108if (moodle_coverage_recorder::can_run_codecoverage()) {
bfe57417 109 echo '<p>'; echo $OUTPUT->checkbox(html_select_option::make_checkbox(1, $codecoverage, get_string('codecoverageanalysis', 'simpletest')), 'codecoverage') ; echo '</p>';
e2074b8b 110} else {
111 echo '<p>'; print_string('codecoveragedisabled', 'simpletest'); echo '<input type="hidden" name="codecoverage" value="0" /></p>';
112}
3ef8c936 113echo '<p>';
4f9c6e27 114 echo '<label for="path">', get_string('onlytest', $langfile), '</label> ';
bae3a75c 115 echo '<input type="text" id="path" name="path" value="', $displaypath, '" size="40" />';
3ef8c936 116echo '</p>';
4f9c6e27 117echo '<input type="submit" value="' . get_string('runtests', $langfile) . '" />';
f689ff1a 118echo '</fieldset>';
3ef8c936 119echo '</form>';
5d902b5d 120echo $OUTPUT->box_end();
2d5b05c8 121
e5d06af2 122// Print link to latest code coverage for this report type
123if (is_null($path) || !$codecoverage) {
124 moodle_coverage_reporter::print_link_to_latest('unittest');
125}
d27a349b 126
3ef8c936 127// Footer.
73d6f52f 128echo $OUTPUT->footer();