MDL-10870 A few more fixes to the file.php page's navigation
[moodle-pu.git] / lib / simpletest / testcode.php
bloba39147c9cfa5f2e5731c49c4a103dab11d6922b6
1 <?php
2 /**
3 * Code quality unit tests that are fast enough to run each 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 code_test extends UnitTestCase {
16 var $allok = array();
18 var $badstrings;
19 var $extensions_to_ignore = array('exe', 'gif', 'ico', 'jpg', 'png', 'ttf');
20 var $ignore_folders = array();
22 function test_dnc() {
23 global $CFG;
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);
43 if (!$pass) {
44 $this->fail("File $filepath contains $description.");
45 $this->allok[$description] = false;