1*0ef04790SAndreas Gohr<?php 2*0ef04790SAndreas Gohr 3*0ef04790SAndreas Gohrclass general_languagelint_test extends DokuWikiTest { 4*0ef04790SAndreas Gohr 5*0ef04790SAndreas Gohr 6*0ef04790SAndreas Gohr function test_core() { 7*0ef04790SAndreas Gohr $this->checkFiles(glob(DOKU_INC.'inc/lang/*/*.php')); 8*0ef04790SAndreas Gohr } 9*0ef04790SAndreas Gohr 10*0ef04790SAndreas Gohr function test_plugins() { 11*0ef04790SAndreas Gohr $this->checkFiles(glob(DOKU_INC.'lib/plugins/*/lang/*/*.php')); 12*0ef04790SAndreas Gohr } 13*0ef04790SAndreas Gohr 14*0ef04790SAndreas Gohr /** 15*0ef04790SAndreas Gohr * Run checks over the given PHP language files 16*0ef04790SAndreas Gohr * 17*0ef04790SAndreas Gohr * @param $files 18*0ef04790SAndreas Gohr */ 19*0ef04790SAndreas Gohr private function checkFiles($files){ 20*0ef04790SAndreas Gohr foreach($files as $file){ 21*0ef04790SAndreas Gohr // try to load the file 22*0ef04790SAndreas Gohr include $file; 23*0ef04790SAndreas Gohr // check it defines an array 24*0ef04790SAndreas Gohr $this->assertTrue(is_array($lang), $file); 25*0ef04790SAndreas Gohr unset($lang); 26*0ef04790SAndreas Gohr 27*0ef04790SAndreas Gohr $this->checkUgly($file); 28*0ef04790SAndreas Gohr } 29*0ef04790SAndreas Gohr } 30*0ef04790SAndreas Gohr 31*0ef04790SAndreas Gohr /** 32*0ef04790SAndreas Gohr * Checks if the file contains any ugly things like leading whitespace, BOM or trailing 33*0ef04790SAndreas Gohr * PHP closing mark 34*0ef04790SAndreas Gohr * 35*0ef04790SAndreas Gohr * @param $file 36*0ef04790SAndreas Gohr * @throws Exception 37*0ef04790SAndreas Gohr */ 38*0ef04790SAndreas Gohr private function checkUgly($file){ 39*0ef04790SAndreas Gohr $content = rtrim(file_get_contents($file)); 40*0ef04790SAndreas Gohr if(substr($content,0,5) != '<?php') 41*0ef04790SAndreas Gohr throw new Exception("$file does not start with '<?php' - check for BOM"); 42*0ef04790SAndreas Gohr 43*0ef04790SAndreas Gohr if(substr($content,-2) == '?>') 44*0ef04790SAndreas Gohr throw new Exception("$file ends with '?>' - remove it!"); 45*0ef04790SAndreas Gohr } 46*0ef04790SAndreas Gohr 47*0ef04790SAndreas Gohr} 48