Merge "Ensure <h5> and <h6> have different computed font size"
[lhc/web/wiklou.git] / tests / selenium / SeleniumConfig.php
1 <?php
2 if ( !defined( 'SELENIUMTEST' ) ) {
3 die( 1 );
4 }
5
6 class SeleniumConfig {
7
8 /**
9 * Retreives the Selenium configuration values from an ini file.
10 * See sample config file in selenium_settings.ini.sample
11 *
12 */
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;
21 }
22 }
23
24 if ( strlen( $seleniumConfigFile ) == 0 || !file_exists( $seleniumConfigFile ) ) {
25 throw new MWException( "Unable to read local Selenium Settings from " . $seleniumConfigFile . "\n" );
26 }
27
28 $configArray = parse_ini_file( $seleniumConfigFile, true );
29 if ( $configArray === false ) {
30 throw new MWException( "Error parsing " . $seleniumConfigFile . "\n" );
31 }
32
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'];
37
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'];
49
50 wfRestoreWarnings();
51 }
52 if ( array_key_exists( 'SeleniumTests', $configArray ) ) {
53 wfSuppressWarnings();
54 $seleniumTestSuites = $configArray['SeleniumTests']['testSuite'];
55 wfRestoreWarnings();
56 }
57 return true;
58 }
59
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 );
65
66 if ( isset( $specialValues[$value] ) ) {
67 $value = $specialValues[$value];
68 } else {
69 $value = trim( $value, '"' );
70 }
71
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 );
76 }
77
78 return array( $key => $value );
79 }
80 }