blob: c114626401ee0f6d996a7aae5c310e489562e230 (
plain)
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
|
<?php
class general_languagelint_test extends DokuWikiTest {
function test_core() {
$this->checkFiles(glob(DOKU_INC.'inc/lang/*/*.php'));
}
function test_plugins() {
$this->checkFiles(glob(DOKU_INC.'lib/plugins/*/lang/*/*.php'));
}
/**
* Run checks over the given PHP language files
*
* @param $files
*/
private function checkFiles($files){
foreach($files as $file){
// try to load the file
include $file;
// check it defines an array
$this->assertTrue(is_array($lang), $file);
unset($lang);
$this->checkUgly($file);
}
}
/**
* Checks if the file contains any ugly things like leading whitespace, BOM or trailing
* PHP closing mark
*
* @param $file
* @throws Exception
*/
private function checkUgly($file){
$content = rtrim(file_get_contents($file));
if(substr($content,0,5) != '<?php')
throw new Exception("$file does not start with '<?php' - check for BOM");
if(substr($content,-2) == '?>')
throw new Exception("$file ends with '?>' - remove it!");
}
}
|