Localisation updates from http://translatewiki.net.
[mediawiki.git] / tests / selenium / SeleniumConfig.php
blob0823275c17c1fcba518ee5967d80a38a8ed12fba
1 <?php
2 if ( !defined( 'SELENIUMTEST' ) ) {
3 die( 1 );
6 class SeleniumConfig {
8 /**
9 * Retreives the Selenium configuration values from an ini file.
10 * See sample config file in selenium_settings.ini.sample
13 public static function getSeleniumSettings( &$seleniumSettings,
14 &$seleniumBrowsers,
15 &$seleniumTestSuites,
16 $seleniumConfigFile = null ) {
17 if ( strlen( $seleniumConfigFile ) == 0 ) {
18 global $wgSeleniumConfigFile;
19 if ( isset( $wgSeleniumConfigFile ) ) {
20 $seleniumConfigFile = $wgSeleniumConfigFile;
24 if ( strlen( $seleniumConfigFile ) == 0 || !file_exists( $seleniumConfigFile ) ) {
25 throw new MWException( "Unable to read local Selenium Settings from " . $seleniumConfigFile . "\n" );
28 $configArray = parse_ini_file( $seleniumConfigFile, true );
29 if ( $configArray === false ) {
30 throw new MWException( "Error parsing " . $seleniumConfigFile . "\n" );
33 if ( array_key_exists( 'SeleniumSettings', $configArray ) ) {
34 wfSuppressWarnings();
35 //we may need to change how this is set. But for now leave it in the ini file
36 $seleniumBrowsers = $configArray['SeleniumSettings']['browsers'];
38 $seleniumSettings['host'] = $configArray['SeleniumSettings']['host'];
39 $seleniumSettings['port'] = $configArray['SeleniumSettings']['port'];
40 $seleniumSettings['wikiUrl'] = $configArray['SeleniumSettings']['wikiUrl'];
41 $seleniumSettings['username'] = $configArray['SeleniumSettings']['username'];
42 $seleniumSettings['userPassword'] = $configArray['SeleniumSettings']['userPassword'];
43 $seleniumSettings['testBrowser'] = $configArray['SeleniumSettings']['testBrowser'];
44 $seleniumSettings['startserver'] = $configArray['SeleniumSettings']['startserver'];
45 $seleniumSettings['stopserver'] = $configArray['SeleniumSettings']['stopserver'];
46 $seleniumSettings['seleniumserverexecpath'] = $configArray['SeleniumSettings']['seleniumserverexecpath'];
47 $seleniumSettings['jUnitLogFile'] = $configArray['SeleniumSettings']['jUnitLogFile'];
48 $seleniumSettings['runAgainstGrid'] = $configArray['SeleniumSettings']['runAgainstGrid'];
50 wfRestoreWarnings();
52 if ( array_key_exists( 'SeleniumTests', $configArray ) ) {
53 wfSuppressWarnings();
54 $seleniumTestSuites = $configArray['SeleniumTests']['testSuite'];
55 wfRestoreWarnings();
57 return true;
60 private static function parse_ini_line( $iniLine ) {
61 static $specialValues = array( 'false' => false, 'true' => true, 'null' => null );
62 list( $key, $value ) = explode( '=', $iniLine, 2 );
63 $key = trim( $key );
64 $value = trim( $value );
66 if ( isset( $specialValues[$value] ) ) {
67 $value = $specialValues[$value];
68 } else {
69 $value = trim( $value, '"' );
72 /* Support one-level arrays */
73 if ( preg_match( '/^([A-Za-z]+)\[([A-Za-z]+)\]/', $key, $m ) ) {
74 $key = $m[1];
75 $value = array( $m[2] => $value );
78 return array( $key => $value );