MDL-10870 A few more fixes to the file.php page's navigation
[moodle-pu.git] / lib / simpletest / slowtestcode.php
blob0a5e8bb4bd9445ddfaa1e0ac126bbe7431a13283
1 <?php
2 /**
3 * Code quality unit tests that are so slow you don't want to run them every time.
5 * @copyright &copy; 2006 The Open University
6 * @author T.J.Hunt@open.ac.uk
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package SimpleTestEx
9 */
11 if (!defined('MOODLE_INTERNAL')) {
12 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
15 class slow_code_test extends UnitTestCase {
16 var $php_code_extensions = array('php', 'html', 'php\.inc');
17 var $ignore_folders = array();
18 var $phppath;
20 function prepend_dirroot($string) {
21 global $CFG;
22 return $CFG->dirroot . $string;
25 function test_php_syntax() {
26 global $CFG;
28 // See if we can run php from the command line:
29 $this->phppath = 'php';
30 if (!shell_exec($this->phppath . ' -v')) {
31 // If not, we can't do anything.
32 $this->fail('Cannot test PHP syntax because PHP is not on the path.');
33 return;
36 $regexp = '/\.(' . implode('|', $this->php_code_extensions) . ')$/';
37 $ignore = array_map(array($this, 'prepend_dirroot'), $this->ignore_folders);
38 recurseFolders($CFG->dirroot, array($this, 'syntax_check_file'), $regexp, false, $ignore);
41 var $dotcount = 0;
42 function syntax_check_file($filepath) {
43 // If you don't print something for each test, then for some reason the
44 // server hangs after a thousand files or so. It is very intermittent.
45 // Printing a space does not seem to be good enough.
46 echo '.';
47 if (++$this->dotcount % 100 == 0) {
48 echo '<br>';
50 flush();
51 $output = shell_exec($this->phppath . ' -d max_execution_time=5 -d short_open_tag= -l ' . escapeshellarg($filepath));
52 $this->assertTrue(strpos($output, 'No syntax errors detected') === 0, $output);
53 // This generates so many fails that it is currently useless.
54 // $this->assertTrue(stripos(file_get_contents($filepath), "\t") === false,
55 // "File $filepath contains a tab character.");