|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00011 if (!defined('MOODLE_INTERNAL')) { 00012 die('Direct access to this script is forbidden.'); 00013 } 00014 00015 class code_test extends UnitTestCase { 00016 var $allok = array(); 00017 00018 var $badstrings; 00019 var $extensions_to_ignore = array('exe', 'gif', 'ico', 'jpg', 'png', 'ttf', 'log'); 00020 var $ignore_folders = array(); 00021 00022 function test_dnc() { 00023 global $CFG; 00024 $regexp = '/\.(' . implode('|', $this->extensions_to_ignore) . ')$/'; 00025 $this->badstrings = array(); 00026 $this->badstrings['DONOT' . 'COMMIT'] = 'DONOT' . 'COMMIT'; // If we put the literal string here, it fails the test! 00027 $this->badstrings['trailing whitespace'] = "[\t ][\r\n]"; 00028 foreach ($this->badstrings as $description => $ignored) { 00029 $this->allok[$description] = true; 00030 } 00031 recurseFolders($CFG->dirroot, array($this, 'search_file_for_dnc'), $regexp, true); 00032 foreach ($this->badstrings as $description => $ignored) { 00033 if ($this->allok[$description]) { 00034 $this->pass("No files contain $description."); 00035 } 00036 } 00037 } 00038 00039 function search_file_for_dnc($filepath) { 00040 $content = file_get_contents($filepath); 00041 foreach ($this->badstrings as $description => $badstring) { 00042 $pass = (stripos($content, $badstring) === false); 00043 if (!$pass) { 00044 $this->fail("File $filepath contains $description."); 00045 $this->allok[$description] = false; 00046 } 00047 } 00048 } 00049 } 00050