[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/general/ -> general_languagelint.test.php (source)

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