Index: trunk/phase3/includes/SeleniumWebSettings.php |
— | — | @@ -4,19 +4,26 @@ |
5 | 5 | * For details on how to configure a wiki for a Selenium test, see: |
6 | 6 | * http://www.mediawiki.org/wiki/SeleniumFramework#Test_Wiki_configuration |
7 | 7 | */ |
8 | | -if ( !$wgEnableSelenium ) { |
9 | | - return; |
| 8 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 9 | + die( 1 ); |
10 | 10 | } |
| 11 | + |
| 12 | +$fname = 'SeleniumWebSettings.php'; |
| 13 | +wfProfileIn( $fname ); |
| 14 | + |
11 | 15 | $cookiePrefix = $wgSitename . "-"; |
12 | | -$name = $cookiePrefix . "Selenium"; |
| 16 | +$cookieName = $cookiePrefix . "Selenium"; |
13 | 17 | |
14 | 18 | //if we find a request parameter containing the test name, set a cookie with the test name |
15 | | -if ( array_key_exists( 'setupTestSuite', $_GET) ) { |
16 | | - //TODO: do a check for valid testsuite names |
| 19 | +if ( isset( $_GET['setupTestSuite'] ) ) { |
17 | 20 | $setupTestSuiteName = $_GET['setupTestSuite']; |
| 21 | + |
| 22 | + if ( preg_match( '/[^a-zA-Z0-9_-]/', $setupTestSuiteName ) || !isset( $wgSeleniumTestConfigs[$setupTestSuiteName] ) ) { |
| 23 | + return; |
| 24 | + } |
18 | 25 | if ( strlen( $setupTestSuiteName) > 0 ) { |
19 | 26 | $expire = time() + 600; |
20 | | - setcookie( $name, |
| 27 | + setcookie( $cookieName, |
21 | 28 | $setupTestSuiteName, |
22 | 29 | $expire, |
23 | 30 | $wgCookiePath, |
— | — | @@ -26,9 +33,9 @@ |
27 | 34 | } |
28 | 35 | } |
29 | 36 | //clear the cookie based on a request param |
30 | | -if ( array_key_exists( 'clearTestSuite', $_GET) ) { |
| 37 | +if ( isset( $_GET['clearTestSuite'] ) ) { |
31 | 38 | $expire = time() - 600; |
32 | | - setcookie( $name, |
| 39 | + setcookie( $cookieName, |
33 | 40 | '', |
34 | 41 | $expire, |
35 | 42 | $wgCookiePath, |
— | — | @@ -38,32 +45,28 @@ |
39 | 46 | } |
40 | 47 | |
41 | 48 | //if a cookie is found, run the appropriate callback to get the config params. |
42 | | -if ( array_key_exists( $name, $_COOKIE) ) { |
43 | | - $testSuiteName = $_COOKIE[$name]; |
| 49 | +if ( isset( $_COOKIE[$cookieName] ) ) { |
| 50 | + $testSuiteName = $_COOKIE[$cookieName]; |
| 51 | + if ( !isset( $wgSeleniumTestConfigs[$testSuiteName] ) ) { |
| 52 | + return; |
| 53 | + } |
44 | 54 | $testIncludes = array(); //array containing all the includes needed for this test |
45 | | - $testGlobalConfigs = array(); //an array containg all the global configs needed for this test |
46 | | - if ( isset( $wgSeleniumTestConfigs ) && array_key_exists($testSuiteName, $wgSeleniumTestConfigs) ) { |
47 | | - $callback = $wgSeleniumTestConfigs[$testSuiteName]; |
48 | | - call_user_func_array( $callback, array( &$testIncludes, &$testGlobalConfigs)); |
49 | | - } |
| 55 | + $testGlobalConfigs = array(); //an array containg all the global configs needed for this test |
| 56 | + $callback = $wgSeleniumTestConfigs[$testSuiteName]; |
| 57 | + call_user_func_array( $callback, array( &$testIncludes, &$testGlobalConfigs)); |
50 | 58 | |
51 | 59 | foreach ( $testIncludes as $includeFile ) { |
52 | 60 | $file = $IP . '/' . $includeFile; |
53 | 61 | require_once( $file ); |
54 | 62 | } |
55 | 63 | foreach ( $testGlobalConfigs as $key => $value ) { |
56 | | - if ( is_array( $value ) ) { |
| 64 | + if ( is_array( $value ) ) { |
| 65 | + $GLOBALS[$key] = array_merge( $GLOBALS[$key], $value ); |
57 | 66 | |
58 | | - $configArray = array(); |
59 | | - if ( isset( $GLOBALS[$key] ) ) { |
60 | | - $configArray = $GLOBALS[$key]; |
61 | | - } |
62 | | - foreach ( $value as $configKey => $configValue ) { |
63 | | - $configArray[$configKey] = $configValue; |
64 | | - } |
65 | | - $GLOBALS[$key] = $configArray; |
66 | 67 | } else { |
67 | 68 | $GLOBALS[$key] = $value; |
68 | 69 | } |
69 | 70 | } |
70 | | -} |
\ No newline at end of file |
| 71 | +} |
| 72 | + |
| 73 | +wfProfileOut( $fname ); |