r79079 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79078‎ | r79079 | r79080 >
Date:18:53, 27 December 2010
Author:platonides
Status:ok
Tags:
Comment:
Get rid of a different configuration file syntax for PHP 5.2
Directly parse them in php.
Modified paths:
  • /trunk/phase3/tests/selenium/SeleniumConfig.php (modified) (history)
  • /trunk/phase3/tests/selenium/selenium_settings.ini.php52.sample (deleted) (history)
  • /trunk/phase3/tests/selenium/selenium_settings_grid.ini.sample (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/selenium/selenium_settings.ini.php52.sample
@@ -1,23 +0,0 @@
2 -[browsers]
3 -
4 -firefox = "*firefox"
5 -iexploreproxy = "*iexploreproxy"
6 -chrome = "*chrome"
7 -
8 -[SeleniumSettings]
9 -
10 -host = "localhost"
11 -port = "4444"
12 -wikiUrl = "http://localhost/mediawiki/latest_trunk/trunk/phase3"
13 -username = "Wikiadmin"
14 -userPassword = "Wikiadminpw"
15 -testBrowser = "firefox"
16 -startserver =
17 -stopserver =
18 -jUnitLogFile =
19 -runAgainstGrid = false
20 -
21 -[testSuite]
22 -
23 -SimpleSeleniumTestSuite = "tests/selenium/suites/SimpleSeleniumTestSuite.php"
24 -WikiEditorTestSuite = "extensions/WikiEditor/selenium/WikiEditorTestSuite.php"
Index: trunk/phase3/tests/selenium/selenium_settings_grid.ini.sample
@@ -9,6 +9,6 @@
1010 jUnitLogFile =
1111 runAgainstGrid = true
1212
13 -[testSuite]
 13+[SeleniumTests]
1414
15 -SimpleSeleniumTestSuite = "tests/selenium/suites/SimpleSeleniumTestSuite.php"
\ No newline at end of file
 15+testSuite[SimpleSeleniumTestSuite] = "tests/selenium/suites/SimpleSeleniumTestSuite.php"
Index: trunk/phase3/tests/selenium/SeleniumConfig.php
@@ -61,28 +61,54 @@
6262 return true;
6363 }
6464
65 - private static function parse_5_2_ini_file ( $ConfigFile ) {
66 -
67 - $configArray = parse_ini_file( $ConfigFile, true );
68 - if ( $configArray === false ) return false;
69 -
70 - // PHP 5.2 ini files have [browsers] and [testSuite] sections
71 - // to get around lack of support for array keys. It then
72 - // inserts the section arrays into the appropriate places in
73 - // the SeleniumSettings and SeleniumTests arrays.
74 -
75 - if ( isset( $configArray['browsers'] ) ) {
76 - $configArray['SeleniumSettings']['browsers'] = $configArray['browsers'];
77 - unset ( $configArray['browsers'] );
 65+ /**
 66+ * PHP 5.2 parse_ini_file() doesn't have support for array keys.
 67+ * This function parses simple ini files with such syntax using just
 68+ * 5.2 functions.
 69+ */
 70+ private static function parse_5_2_ini_file( $ConfigFile ) {
 71+ $file = fopen( $ConfigFile, "rt" );
 72+ if ( !$file ) {
 73+ return false;
7874 }
79 -
80 - if ( isset( $configArray['testSuite'] ) ) {
81 - $configArray['SeleniumTests']['testSuite'] = $configArray['testSuite'];
82 - unset ( $configArray['testSuite'] );
 75+ $header = '';
 76+
 77+ $configArray = array();
 78+
 79+ while ( ( $line = fgets( $file ) ) !== false ) {
 80+ $line = strtok( $line, "\r\n" );
 81+
 82+ if ( !$line || $line[0] == ';' ) continue;
 83+
 84+ if ( $line[0] == '[' && substr( $line, -1 ) == ']' ) {
 85+ $header = substr( $line, 1, -1 );
 86+ $configArray[$header] = array();
 87+ } else {
 88+ $configArray[$header] = array_merge_recursive( $configArray[$header], self::parse_ini_line( $line ) );
 89+ }
8390 }
84 -
 91+ var_dump($configArray);
8592 return $configArray;
 93+ }
8694
 95+ private static function parse_ini_line( $iniLine ) {
 96+ static $specialValues = array( 'false' => false, 'true' => true, 'null' => null );
 97+ list( $key, $value ) = explode( '=', $iniLine, 2 );
 98+ $key = trim( $key );
 99+ $value = trim( $value );
 100+
 101+ if ( isset( $specialValues[$value] ) ) {
 102+ $value = $specialValues[$value];
 103+ } else {
 104+ $value = trim( $value, '"' );
 105+ }
 106+
 107+ /* Support one-level arrays */
 108+ if ( preg_match( '/^([A-Za-z]+)\[([A-Za-z]+)\]/', $key, $m ) ) {
 109+ $key = $m[1];
 110+ $value = array( $m[2] => $value );
 111+ }
 112+
 113+ return array( $key => $value );
87114 }
88 -
89115 }

Status & tagging log