Index: trunk/phase3/includes/SeleniumWebSettings.php |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | <?php |
3 | | -/* |
| 3 | +/** |
4 | 4 | * Dynamically change configuration variables based on the test suite name and a cookie value. |
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 |
— | — | @@ -13,38 +13,44 @@ |
14 | 14 | $fname = 'SeleniumWebSettings.php'; |
15 | 15 | wfProfileIn( $fname ); |
16 | 16 | |
17 | | -$cookiePrefix = $wgSitename . "-"; |
18 | | -$cookieName = $cookiePrefix . "Selenium"; |
| 17 | +$cookiePrefix = $wgSitename . '-'; |
| 18 | +$cookieName = $cookiePrefix . 'Selenium'; |
19 | 19 | |
20 | | -// this is a fallback sql file |
| 20 | +// this is a fallback SQL file |
21 | 21 | $testSqlFile = false; |
22 | 22 | $testImageZip = false; |
23 | 23 | |
24 | | -//if we find a request parameter containing the test name, set a cookie with the test name |
| 24 | +// if we find a request parameter containing the test name, set a cookie with the test name |
25 | 25 | if ( isset( $_GET['setupTestSuite'] ) ) { |
26 | 26 | $setupTestSuiteName = $_GET['setupTestSuite']; |
27 | 27 | |
28 | | - if ( preg_match( '/[^a-zA-Z0-9_-]/', $setupTestSuiteName ) || !isset( $wgSeleniumTestConfigs[$setupTestSuiteName] ) ) { |
| 28 | + if ( |
| 29 | + preg_match( '/[^a-zA-Z0-9_-]/', $setupTestSuiteName ) || |
| 30 | + !isset( $wgSeleniumTestConfigs[$setupTestSuiteName] ) |
| 31 | + ) |
| 32 | + { |
29 | 33 | return; |
30 | 34 | } |
31 | | - if ( strlen( $setupTestSuiteName) > 0 ) { |
| 35 | + if ( strlen( $setupTestSuiteName ) > 0 ) { |
32 | 36 | $expire = time() + 600; |
33 | | - setcookie( $cookieName, |
| 37 | + setcookie( |
| 38 | + $cookieName, |
34 | 39 | $setupTestSuiteName, |
35 | 40 | $expire, |
36 | 41 | $wgCookiePath, |
37 | 42 | $wgCookieDomain, |
38 | 43 | $wgCookieSecure, |
39 | | - true ); |
| 44 | + true |
| 45 | + ); |
40 | 46 | } |
41 | 47 | |
42 | | - $testIncludes = array(); //array containing all the includes needed for this test |
43 | | - $testGlobalConfigs = array(); //an array containg all the global configs needed for this test |
| 48 | + $testIncludes = array(); // array containing all the includes needed for this test |
| 49 | + $testGlobalConfigs = array(); // an array containg all the global configs needed for this test |
44 | 50 | $testResourceFiles = array(); // an array containing all the resource files needed for this test |
45 | 51 | $callback = $wgSeleniumTestConfigs[$setupTestSuiteName]; |
46 | 52 | call_user_func_array( $callback, array( &$testIncludes, &$testGlobalConfigs, &$testResourceFiles)); |
47 | 53 | |
48 | | - if ( isset($testResourceFiles['images']) ) { |
| 54 | + if ( isset( $testResourceFiles['images'] ) ) { |
49 | 55 | $testImageZip = $testResourceFiles['images']; |
50 | 56 | } |
51 | 57 | |
— | — | @@ -57,32 +63,34 @@ |
58 | 64 | } |
59 | 65 | } |
60 | 66 | |
61 | | -//clear the cookie based on a request param |
| 67 | +// clear the cookie based on a request param |
62 | 68 | if ( isset( $_GET['clearTestSuite'] ) ) { |
63 | 69 | $testSuiteName = getTestSuiteNameFromCookie( $cookieName ); |
64 | 70 | |
65 | 71 | $expire = time() - 600; |
66 | | - setcookie( $cookieName, |
| 72 | + setcookie( |
| 73 | + $cookieName, |
67 | 74 | '', |
68 | 75 | $expire, |
69 | 76 | $wgCookiePath, |
70 | 77 | $wgCookieDomain, |
71 | 78 | $wgCookieSecure, |
72 | | - true ); |
| 79 | + true |
| 80 | + ); |
73 | 81 | |
74 | 82 | $testResourceName = getTestResourceNameFromTestSuiteName( $testSuiteName ); |
75 | 83 | teardownTestResources( $testResourceName ); |
76 | 84 | } |
77 | 85 | |
78 | | -//if a cookie is found, run the appropriate callback to get the config params. |
| 86 | +// if a cookie is found, run the appropriate callback to get the config params. |
79 | 87 | if ( isset( $_COOKIE[$cookieName] ) ) { |
80 | 88 | $testSuiteName = getTestSuiteNameFromCookie( $cookieName ); |
81 | 89 | if ( !isset( $wgSeleniumTestConfigs[$testSuiteName] ) ) { |
82 | 90 | return; |
83 | 91 | } |
84 | 92 | |
85 | | - $testIncludes = array(); //array containing all the includes needed for this test |
86 | | - $testGlobalConfigs = array(); //an array containg all the global configs needed for this test |
| 93 | + $testIncludes = array(); // array containing all the includes needed for this test |
| 94 | + $testGlobalConfigs = array(); // an array containg all the global configs needed for this test |
87 | 95 | $testResourceFiles = array(); // an array containing all the resource files needed for this test |
88 | 96 | $callback = $wgSeleniumTestConfigs[$testSuiteName]; |
89 | 97 | call_user_func_array( $callback, array( &$testIncludes, &$testGlobalConfigs, &$testResourceFiles)); |
— | — | @@ -134,21 +142,21 @@ |
135 | 143 | |
136 | 144 | // Basic security. Do not allow to drop productive database. |
137 | 145 | if ( $testResourceName == $wgDBname ) { |
138 | | - die( "Cannot override productive database." ); |
| 146 | + die( 'Cannot override productive database.' ); |
139 | 147 | } |
140 | 148 | if ( $testResourceName == '' ) { |
141 | | - die( "Cannot identify a test the resources should be installed for." ); |
| 149 | + die( 'Cannot identify a test the resources should be installed for.' ); |
142 | 150 | } |
143 | 151 | |
144 | | - //create tables |
145 | | - $dbw =& wfGetDB( DB_MASTER ); |
146 | | - $dbw->query( "DROP DATABASE IF EXISTS ".$testResourceName ); |
147 | | - $dbw->query( "CREATE DATABASE ".$testResourceName ); |
| 152 | + // create tables |
| 153 | + $dbw = wfGetDB( DB_MASTER ); |
| 154 | + $dbw->query( 'DROP DATABASE IF EXISTS ' . $testResourceName ); |
| 155 | + $dbw->query( 'CREATE DATABASE ' . $testResourceName ); |
148 | 156 | |
149 | | - // do not set the new db name before database is setup |
| 157 | + // do not set the new DB name before database is setup |
150 | 158 | $wgDBname = $testResourceName; |
151 | 159 | $dbw->selectDB( $testResourceName ); |
152 | | - // populate from sql file |
| 160 | + // populate from SQL file |
153 | 161 | if ( $testSqlFile ) { |
154 | 162 | $dbw->sourceFile( $testSqlFile ); |
155 | 163 | } |
— | — | @@ -169,8 +177,8 @@ |
170 | 178 | |
171 | 179 | function teardownTestResources( $testResourceName ) { |
172 | 180 | // remove test database |
173 | | - $dbw =& wfGetDB( DB_MASTER ); |
174 | | - $dbw->query( "DROP DATABASE IF EXISTS ".$testResourceName ); |
| 181 | + $dbw = wfGetDB( DB_MASTER ); |
| 182 | + $dbw->query( 'DROP DATABASE IF EXISTS ' . $testResourceName ); |
175 | 183 | |
176 | 184 | $testUploadPath = getTestUploadPathFromResourceName( $testResourceName ); |
177 | 185 | // remove test image dir |
— | — | @@ -190,7 +198,7 @@ |
191 | 199 | $wgDBuser = $wgDBtestuser; |
192 | 200 | $wgDBpassword = $wgDBtestpassword; |
193 | 201 | |
194 | | - $testUploadPath = getTestUploadPathFromResourceName( $testResourceName ); |
| 202 | + $testUploadPath = getTestUploadPathFromResourceName( $testResourceName ); |
195 | 203 | $wgUploadPath = $testUploadPath; |
196 | 204 | } |
197 | 205 | |
— | — | @@ -200,10 +208,10 @@ |
201 | 209 | $objects = scandir( $dir ); |
202 | 210 | foreach ( $objects as $object ) { |
203 | 211 | if ( $object != "." && $object != ".." ) { |
204 | | - if ( filetype( $dir."/".$object ) == "dir" ) { |
205 | | - wfRecursiveRemoveDir( $dir."/".$object ); |
| 212 | + if ( filetype( $dir . '/' . $object ) == "dir" ) { |
| 213 | + wfRecursiveRemoveDir( $dir . '/' . $object ); |
206 | 214 | } else { |
207 | | - unlink( $dir."/".$object ); |
| 215 | + unlink( $dir . '/' . $object ); |
208 | 216 | } |
209 | 217 | } |
210 | 218 | } |