summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2014-01-24 17:50:40 +0100
committerAndreas Gohr <andi@splitbrain.org>2014-01-24 17:50:40 +0100
commit05f1af55e0303f33fa6f046eeaa221f1b2a32066 (patch)
tree6e7c70641f0da90b8ac436dd1b5d68e5bf52d4ec
parent975e2a1982518e206667387f0540ce46e5c482ca (diff)
downloadrpg-05f1af55e0303f33fa6f046eeaa221f1b2a32066.tar.gz
rpg-05f1af55e0303f33fa6f046eeaa221f1b2a32066.tar.bz2
add unit test to check language files for validity
this should help with applying pull requests that do come not from the translation interface as it makes sure the files will be at least syntactically correct.
-rw-r--r--_test/tests/general/general_languagelint.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/_test/tests/general/general_languagelint.php b/_test/tests/general/general_languagelint.php
new file mode 100644
index 000000000..c11462640
--- /dev/null
+++ b/_test/tests/general/general_languagelint.php
@@ -0,0 +1,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!");
+ }
+
+}