forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 23
/
testcode.php
50 lines (44 loc) · 1.74 KB
/
testcode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* Code quality unit tests that are fast enough to run each time.
*
* @copyright © 2006 The Open University
* @author [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package SimpleTestEx
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}
class code_test extends UnitTestCase {
var $allok = array();
var $badstrings;
var $extensions_to_ignore = array('exe', 'gif', 'ico', 'jpg', 'png', 'ttf', 'log');
var $ignore_folders = array();
function test_dnc() {
global $CFG;
$regexp = '/\.(' . implode('|', $this->extensions_to_ignore) . ')$/';
$this->badstrings = array();
$this->badstrings['DONOT' . 'COMMIT'] = 'DONOT' . 'COMMIT'; // If we put the literal string here, it fails the test!
$this->badstrings['trailing whitespace'] = "[\t ][\r\n]";
foreach ($this->badstrings as $description => $ignored) {
$this->allok[$description] = true;
}
recurseFolders($CFG->dirroot, array($this, 'search_file_for_dnc'), $regexp, true);
foreach ($this->badstrings as $description => $ignored) {
if ($this->allok[$description]) {
$this->pass("No files contain $description.");
}
}
}
function search_file_for_dnc($filepath) {
$content = file_get_contents($filepath);
foreach ($this->badstrings as $description => $badstring) {
$pass = (stripos($content, $badstring) === false);
if (!$pass) {
$this->fail("File $filepath contains $description.");
$this->allok[$description] = false;
}
}
}
}