summaryrefslogtreecommitdiff
path: root/includes/SeleniumWebSettings.php
blob: 8afb26dab94e2b7d0e94685d71480c82148a7394 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/*
 * Dynamically change configuration variables based on the test suite name and a cookie value.
 * For details on how to configure a wiki for a Selenium test, see:
 * http://www.mediawiki.org/wiki/SeleniumFramework#Test_Wiki_configuration
 */
if ( !defined( 'MEDIAWIKI' ) ) {
	die( 1 );
}

$fname = 'SeleniumWebSettings.php';
wfProfileIn( $fname );

$cookiePrefix = $wgSitename . "-";
$cookieName = $cookiePrefix . "Selenium";

//if we find a request parameter containing the test name, set a cookie with the test name
if ( isset( $_GET['setupTestSuite'] ) ) {
	$setupTestSuiteName = $_GET['setupTestSuite'];
	
	if ( preg_match( '/[^a-zA-Z0-9_-]/', $setupTestSuiteName ) || !isset( $wgSeleniumTestConfigs[$setupTestSuiteName] ) ) {
		return;
	}
	if ( strlen( $setupTestSuiteName) > 0 ) {
		$expire = time() + 600;
		setcookie( $cookieName,
			$setupTestSuiteName,
			$expire,
			$wgCookiePath,
			$wgCookieDomain,
			$wgCookieSecure,
			true );
	}
}
//clear the cookie based on a request param
if ( isset( $_GET['clearTestSuite'] ) ) {
		$expire = time() - 600; 
		setcookie( $cookieName,
			'',
			$expire,
			$wgCookiePath,
			$wgCookieDomain,
			$wgCookieSecure,
			true );
}

//if a cookie is found, run the appropriate callback to get the config params.
if ( isset( $_COOKIE[$cookieName] ) ) {		
	$testSuiteName = $_COOKIE[$cookieName];
	if ( !isset( $wgSeleniumTestConfigs[$testSuiteName] ) ) {
		return;
	}
	$testIncludes = array(); //array containing all the includes needed for this test
	$testGlobalConfigs = array(); //an array containg all the global configs needed for this test
	$callback = $wgSeleniumTestConfigs[$testSuiteName]; 
	call_user_func_array( $callback, array( &$testIncludes, &$testGlobalConfigs));
      
	foreach ( $testIncludes as $includeFile ) {
		$file = $IP . '/' . $includeFile;
		require_once( $file );
	}
	foreach ( $testGlobalConfigs as $key => $value ) {
		if ( is_array( $value ) ) {		
			$GLOBALS[$key] = array_merge( $GLOBALS[$key], $value );
			
		} else {
			$GLOBALS[$key] = $value;
		}
	}
}

wfProfileOut( $fname );