~ubuntu-branches/ubuntu/trusty/mediawiki/trusty

« back to all changes in this revision

Viewing changes to tests/selenium/SeleniumConfig.php

  • Committer: Package Import Robot
  • Author(s): Thorsten Glaser
  • Date: 2014-03-28 09:56:29 UTC
  • mfrom: (1.3.14)
  • Revision ID: package-import@ubuntu.com-20140328095629-1526y9tchdd507id
Tags: 1:1.19.14+dfsg-1
* New upstream security fix release (Closes: #742857):
  - (bug 62497) SECURITY: Add CSRF token on Special:ChangePassword
  - (bug 62467) Set a title for the context during import on the cli
* Use upstream-provided signing key bundle

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
14
        public static function getSeleniumSettings ( &$seleniumSettings,
 
15
                        &$seleniumBrowsers,
 
16
                        &$seleniumTestSuites,
 
17
                        $seleniumConfigFile = null ) {
 
18
                if ( strlen( $seleniumConfigFile ) == 0 ) {
 
19
                        global $wgSeleniumConfigFile;
 
20
                        if ( isset( $wgSeleniumConfigFile ) ) $seleniumConfigFile =  $wgSeleniumConfigFile ;
 
21
                }
 
22
 
 
23
                if ( strlen( $seleniumConfigFile ) == 0 || !file_exists( $seleniumConfigFile ) ) {
 
24
                        throw new MWException( "Unable to read local Selenium Settings from " . $seleniumConfigFile . "\n" );
 
25
                }
 
26
 
 
27
                if ( !defined( 'PHP_VERSION_ID' ) ||
 
28
                        ( PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3 ) ) {
 
29
                        $configArray = self::parse_5_2_ini_file( $seleniumConfigFile );
 
30
                } else {
 
31
                        $configArray = parse_ini_file( $seleniumConfigFile, true );
 
32
                }
 
33
                if ( $configArray === false ) {
 
34
                        throw new MWException( "Error parsing " . $seleniumConfigFile . "\n" );
 
35
                }
 
36
 
 
37
                if ( array_key_exists( 'SeleniumSettings', $configArray)  ) {
 
38
                        wfSuppressWarnings();
 
39
                        //we may need to change how this is set. But for now leave it in the ini file
 
40
                        $seleniumBrowsers = $configArray['SeleniumSettings']['browsers'];
 
41
 
 
42
                        $seleniumSettings['host'] = $configArray['SeleniumSettings']['host'];
 
43
                        $seleniumSettings['port'] = $configArray['SeleniumSettings']['port'];
 
44
                        $seleniumSettings['wikiUrl'] = $configArray['SeleniumSettings']['wikiUrl'];
 
45
                        $seleniumSettings['username'] = $configArray['SeleniumSettings']['username'];
 
46
                        $seleniumSettings['userPassword'] = $configArray['SeleniumSettings']['userPassword'];
 
47
                        $seleniumSettings['testBrowser'] = $configArray['SeleniumSettings']['testBrowser'];
 
48
                        $seleniumSettings['startserver'] = $configArray['SeleniumSettings']['startserver'];
 
49
                        $seleniumSettings['stopserver'] = $configArray['SeleniumSettings']['stopserver'];
 
50
                        $seleniumSettings['seleniumserverexecpath'] = $configArray['SeleniumSettings']['seleniumserverexecpath'];
 
51
                        $seleniumSettings['jUnitLogFile'] = $configArray['SeleniumSettings']['jUnitLogFile'];
 
52
                        $seleniumSettings['runAgainstGrid'] = $configArray['SeleniumSettings']['runAgainstGrid'];
 
53
 
 
54
                        wfRestoreWarnings();
 
55
                }
 
56
                if ( array_key_exists( 'SeleniumTests', $configArray)  ) {
 
57
                        wfSuppressWarnings();
 
58
                        $seleniumTestSuites = $configArray['SeleniumTests']['testSuite'];
 
59
                        wfRestoreWarnings();
 
60
                }
 
61
                return true;
 
62
        }
 
63
 
 
64
        /**
 
65
         * PHP 5.2 parse_ini_file() doesn't have support for array keys.
 
66
         * This function parses simple ini files with such syntax using just
 
67
         * 5.2 functions.
 
68
         */
 
69
        private static function parse_5_2_ini_file( $ConfigFile ) {
 
70
                $file = fopen( $ConfigFile, "rt" );
 
71
                if ( !$file ) {
 
72
                        return false;
 
73
                }
 
74
                $header = '';
 
75
 
 
76
                $configArray = array();
 
77
 
 
78
                while ( ( $line = fgets( $file ) ) !== false ) {
 
79
                        $line = strtok( $line, "\r\n" );
 
80
 
 
81
                        if ( !$line || $line[0] == ';' ) continue;
 
82
 
 
83
                        if ( $line[0] == '[' && substr( $line, -1 ) == ']' ) {
 
84
                                $header = substr( $line, 1, -1 );
 
85
                                $configArray[$header] = array();
 
86
                        } else {
 
87
                                $configArray[$header] = array_merge_recursive( $configArray[$header], self::parse_ini_line( $line ) );
 
88
                        }
 
89
                }
 
90
                return $configArray;
 
91
        }
 
92
 
 
93
        private static function parse_ini_line( $iniLine ) {
 
94
                static $specialValues = array( 'false' => false, 'true' => true, 'null' => null );
 
95
                list( $key, $value ) = explode( '=', $iniLine, 2 );
 
96
                $key = trim( $key );
 
97
                $value = trim( $value );
 
98
 
 
99
                if ( isset( $specialValues[$value] ) ) {
 
100
                        $value = $specialValues[$value];
 
101
                } else {
 
102
                        $value = trim( $value, '"' );
 
103
                }
 
104
 
 
105
                /* Support one-level arrays */
 
106
                if ( preg_match( '/^([A-Za-z]+)\[([A-Za-z]+)\]/', $key, $m ) ) {
 
107
                        $key = $m[1];
 
108
                        $value = array( $m[2] => $value );
 
109
                }
 
110
 
 
111
                return array( $key => $value );
 
112
        }
 
113
}