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