MediaWiki  REL1_19
SeleniumConfig.php
Go to the documentation of this file.
00001 <?php
00002 if ( !defined( 'SELENIUMTEST' ) ) {
00003         die( 1 );
00004 }
00005 
00006 class SeleniumConfig {
00007 
00014         public static function getSeleniumSettings ( &$seleniumSettings,
00015                         &$seleniumBrowsers,
00016                         &$seleniumTestSuites,
00017                         $seleniumConfigFile = null ) {
00018                 if ( strlen( $seleniumConfigFile ) == 0 ) {
00019                         global $wgSeleniumConfigFile;
00020                         if ( isset( $wgSeleniumConfigFile ) ) $seleniumConfigFile =  $wgSeleniumConfigFile ;
00021                 }
00022 
00023                 if ( strlen( $seleniumConfigFile ) == 0 || !file_exists( $seleniumConfigFile ) ) {
00024                         throw new MWException( "Unable to read local Selenium Settings from " . $seleniumConfigFile . "\n" );
00025                 }
00026 
00027                 if ( !defined( 'PHP_VERSION_ID' ) ||
00028                         ( PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3 ) ) {
00029                         $configArray = self::parse_5_2_ini_file( $seleniumConfigFile );
00030                 } else {
00031                         $configArray = parse_ini_file( $seleniumConfigFile, true );
00032                 }
00033                 if ( $configArray === false ) {
00034                         throw new MWException( "Error parsing " . $seleniumConfigFile . "\n" );
00035                 }
00036 
00037                 if ( array_key_exists( 'SeleniumSettings', $configArray)  ) {
00038                         wfSuppressWarnings();
00039                         //we may need to change how this is set. But for now leave it in the ini file
00040                         $seleniumBrowsers = $configArray['SeleniumSettings']['browsers'];
00041 
00042                         $seleniumSettings['host'] = $configArray['SeleniumSettings']['host'];
00043                         $seleniumSettings['port'] = $configArray['SeleniumSettings']['port'];
00044                         $seleniumSettings['wikiUrl'] = $configArray['SeleniumSettings']['wikiUrl'];
00045                         $seleniumSettings['username'] = $configArray['SeleniumSettings']['username'];
00046                         $seleniumSettings['userPassword'] = $configArray['SeleniumSettings']['userPassword'];
00047                         $seleniumSettings['testBrowser'] = $configArray['SeleniumSettings']['testBrowser'];
00048                         $seleniumSettings['startserver'] = $configArray['SeleniumSettings']['startserver'];
00049                         $seleniumSettings['stopserver'] = $configArray['SeleniumSettings']['stopserver'];
00050                         $seleniumSettings['seleniumserverexecpath'] = $configArray['SeleniumSettings']['seleniumserverexecpath'];
00051                         $seleniumSettings['jUnitLogFile'] = $configArray['SeleniumSettings']['jUnitLogFile'];
00052                         $seleniumSettings['runAgainstGrid'] = $configArray['SeleniumSettings']['runAgainstGrid'];
00053 
00054                         wfRestoreWarnings();
00055                 }
00056                 if ( array_key_exists( 'SeleniumTests', $configArray)  ) {
00057                         wfSuppressWarnings();
00058                         $seleniumTestSuites = $configArray['SeleniumTests']['testSuite'];
00059                         wfRestoreWarnings();
00060                 }
00061                 return true;
00062         }
00063 
00069         private static function parse_5_2_ini_file( $ConfigFile ) {
00070                 $file = fopen( $ConfigFile, "rt" );
00071                 if ( !$file ) {
00072                         return false;
00073                 }
00074                 $header = '';
00075 
00076                 $configArray = array();
00077 
00078                 while ( ( $line = fgets( $file ) ) !== false ) {
00079                         $line = strtok( $line, "\r\n" );
00080 
00081                         if ( !$line || $line[0] == ';' ) continue;
00082 
00083                         if ( $line[0] == '[' && substr( $line, -1 ) == ']' ) {
00084                                 $header = substr( $line, 1, -1 );
00085                                 $configArray[$header] = array();
00086                         } else {
00087                                 $configArray[$header] = array_merge_recursive( $configArray[$header], self::parse_ini_line( $line ) );
00088                         }
00089                 }
00090                 return $configArray;
00091         }
00092 
00093         private static function parse_ini_line( $iniLine ) {
00094                 static $specialValues = array( 'false' => false, 'true' => true, 'null' => null );
00095                 list( $key, $value ) = explode( '=', $iniLine, 2 );
00096                 $key = trim( $key );
00097                 $value = trim( $value );
00098 
00099                 if ( isset( $specialValues[$value] ) ) {
00100                         $value = $specialValues[$value];
00101                 } else {
00102                         $value = trim( $value, '"' );
00103                 }
00104 
00105                 /* Support one-level arrays */
00106                 if ( preg_match( '/^([A-Za-z]+)\[([A-Za-z]+)\]/', $key, $m ) ) {
00107                         $key = $m[1];
00108                         $value = array( $m[2] => $value );
00109                 }
00110 
00111                 return array( $key => $value );
00112         }
00113 }