3 * Code quality unit tests that are fast enough to run each time.
5 * @copyright © 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
11 if (!defined('MOODLE_INTERNAL')) {
12 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
15 class code_test
extends UnitTestCase
{
19 var $extensions_to_ignore = array('exe', 'gif', 'ico', 'jpg', 'png', 'ttf');
20 var $ignore_folders = array();
24 $regexp = '/\.(' . implode('|', $this->extensions_to_ignore
) . ')$/';
25 $this->badstrings
= array();
26 $this->badstrings
['DONOT' . 'COMMIT'] = 'DONOT' . 'COMMIT'; // If we put the literal string here, it fails the test!
27 $this->badstrings
['trailing whitespace'] = "[\t ][\r\n]";
28 foreach ($this->badstrings
as $description => $ignored) {
29 $this->allok
[$description] = true;
31 recurseFolders($CFG->dirroot
, array($this, 'search_file_for_dnc'), $regexp, true);
32 foreach ($this->badstrings
as $description => $ignored) {
33 if ($this->allok
[$description]) {
34 $this->pass("No files contain $description.");
39 function search_file_for_dnc($filepath) {
40 $content = file_get_contents($filepath);
41 foreach ($this->badstrings
as $description => $badstring) {
42 $pass = (stripos($content, $badstring) === false);
44 $this->fail("File $filepath contains $description.");
45 $this->allok
[$description] = false;