|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00027 define('NO_OUTPUT_BUFFERING', true); 00028 00029 require(dirname(__FILE__) . '/../../../config.php'); 00030 require_once($CFG->libdir.'/adminlib.php'); 00031 require_once('simpletestlib.php'); 00032 require_once('simpletestcoveragelib.php'); 00033 require_once('ex_simple_test.php'); 00034 require_once('ex_reporter.php'); 00035 00036 // Always run the unit tests in developer debug mode. 00037 $CFG->debug = DEBUG_DEVELOPER; 00038 error_reporting($CFG->debug); 00039 raise_memory_limit(MEMORY_EXTRA); 00040 00041 // page parameters 00042 $path = optional_param('path', null, PARAM_PATH); 00043 $showpasses = optional_param('showpasses', false, PARAM_BOOL); 00044 $codecoverage = optional_param('codecoverage', false, PARAM_BOOL); 00045 $showsearch = optional_param('showsearch', false, PARAM_BOOL); 00046 00047 admin_externalpage_setup('toolsimpletest', '', array('showpasses'=>$showpasses, 'showsearch'=>$showsearch)); 00048 00049 $unittest = true; 00050 00051 global $UNITTEST; 00052 $UNITTEST = new stdClass(); 00053 00054 // This limit is the time allowed per individual test function. Please do not 00055 // increase this value. If you get a PHP time limit when running unit tests, 00056 // find the unit test which is running slowly, and either make it faster, 00057 // split it into multiple tests, or call set_time_limit within that test. 00058 define('TIME_ALLOWED_PER_UNIT_TEST', 60); 00059 00060 // Print the header. 00061 $strtitle = get_string('unittests', 'tool_unittest'); 00062 00063 if (!is_null($path)) { 00064 //trim so user doesn't get an error if they include a space on the end of the path (ie by pasting path) 00065 $path = trim($path); 00066 00067 // Turn off xmlstrictheaders during the unit test run. 00068 $origxmlstrictheaders = !empty($CFG->xmlstrictheaders); 00069 $CFG->xmlstrictheaders = false; 00070 echo $OUTPUT->header(); 00071 $CFG->xmlstrictheaders = $origxmlstrictheaders; 00072 unset($origxmlstrictheaders); 00073 00074 // Create the group of tests. 00075 $test = new autogroup_test_coverage($showsearch, true, $codecoverage, 'Moodle Unit Tests Code Coverage Report', 'unittest'); 00076 00077 // OU specific. We use the _nonproject folder for stuff we want to 00078 // keep in CVS, but which is not really relevant. It does no harm 00079 // to leave this here. 00080 $test->addIgnoreFolder($CFG->dirroot . '/_nonproject'); 00081 00082 // Make the reporter, which is what displays the results. 00083 $reporter = new ExHtmlReporter($showpasses); 00084 00085 if ($showsearch) { 00086 echo $OUTPUT->heading('Searching for test cases'); 00087 } 00088 flush(); 00089 00090 // Work out what to test. 00091 if (substr($path, 0, 1) == '/') { 00092 $path = substr($path, 1); 00093 } 00094 $path = $CFG->dirroot . '/' . $path; 00095 if (substr($path, -1) == '/') { 00096 $path = substr($path, 0, -1); 00097 } 00098 $displaypath = substr($path, strlen($CFG->dirroot) + 1); 00099 $ok = true; 00100 if (is_file($path)) { 00101 $test->addTestFile($path); 00102 } else if (is_dir($path)){ 00103 $test->findTestFiles($path); 00104 } else { 00105 echo $OUTPUT->box(get_string('pathdoesnotexist', 'tool_unittest', $path), 'errorbox'); 00106 $ok = false; 00107 } 00108 00109 // If we have something to test, do it. 00110 if ($ok) { 00111 if ($path == $CFG->dirroot) { 00112 $title = get_string('moodleunittests', 'tool_unittest', get_string('all', 'tool_unittest')); 00113 } else { 00114 $title = get_string('moodleunittests', 'tool_unittest', $displaypath); 00115 } 00116 echo $OUTPUT->heading($title); 00117 $test->run($reporter); 00118 } 00119 00120 $formheader = get_string('retest', 'tool_unittest'); 00121 } else { 00122 $displaypath = ''; 00123 echo $OUTPUT->header(); 00124 $formheader = get_string('rununittests', 'tool_unittest'); 00125 } 00126 // Print the form for adjusting options. 00127 echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); 00128 echo $OUTPUT->heading($formheader); 00129 echo '<form method="get" action="index.php">'; 00130 echo '<fieldset class="invisiblefieldset">'; 00131 echo '<p>'.html_writer::checkbox('showpasses', 1, $showpasses, get_string('showpasses', 'tool_unittest')).'</p>'; 00132 echo '<p>'.html_writer::checkbox('showsearch', 1, $showsearch, get_string('showsearch', 'tool_unittest')).'</p>'; 00133 if (moodle_coverage_recorder::can_run_codecoverage()) { 00134 echo '<p>'.html_writer::checkbox('codecoverage', 1, $codecoverage, get_string('codecoverageanalysis', 'tool_unittest')).'</p>'; 00135 } else { 00136 echo '<p>'; print_string('codecoveragedisabled', 'tool_unittest'); echo '<input type="hidden" name="codecoverage" value="0" /></p>'; 00137 } 00138 echo '<p>'; 00139 echo '<label for="path">', get_string('onlytest', 'tool_unittest'), '</label> '; 00140 echo '<input type="text" id="path" name="path" value="', $displaypath, '" size="40" />'; 00141 echo '</p>'; 00142 echo '<input type="submit" value="' . get_string('runtests', 'tool_unittest') . '" />'; 00143 echo '</fieldset>'; 00144 echo '</form>'; 00145 echo $OUTPUT->box_end(); 00146 00147 $otherpages = array(); 00148 $otherpages['PDF lib test'] = new moodle_url('/admin/tool/unittest/other/pdflibtestpage.php'); 00149 if (debugging('', DEBUG_DEVELOPER)) { 00150 $otherpages['TODO checker'] = new moodle_url('/admin/tool/unittest/other/todochecker.php'); 00151 } 00152 00153 // print list of extra test pages that are not simpletests, 00154 // not everything there is good enough to show to our users 00155 if ($otherpages) { 00156 echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); 00157 echo $OUTPUT->heading(get_string('othertestpages', 'tool_unittest')); 00158 echo '<ul>'; 00159 foreach ($otherpages as $name=>$url) { 00160 echo '<li>'.html_writer::link($url, $name).'</li>'; 00161 } 00162 echo '</ul>'; 00163 echo $OUTPUT->box_end(); 00164 } 00165 00166 00167 // Print link to latest code coverage for this report type 00168 if (is_null($path) || !$codecoverage) { 00169 moodle_coverage_reporter::print_link_to_latest('unittest'); 00170 } 00171 00172 // Footer. 00173 echo $OUTPUT->footer();