r90802 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90801‎ | r90802 | r90803 >
Date:23:27, 25 June 2011
Author:ashley
Status:ok
Tags:
Comment:
coding style tweaks + removed some PHP4-isms
Modified paths:
  • /trunk/phase3/includes/SeleniumWebSettings.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SeleniumWebSettings.php
@@ -1,5 +1,5 @@
22 <?php
3 -/*
 3+/**
44 * Dynamically change configuration variables based on the test suite name and a cookie value.
55 * For details on how to configure a wiki for a Selenium test, see:
66 * http://www.mediawiki.org/wiki/SeleniumFramework#Test_Wiki_configuration
@@ -13,38 +13,44 @@
1414 $fname = 'SeleniumWebSettings.php';
1515 wfProfileIn( $fname );
1616
17 -$cookiePrefix = $wgSitename . "-";
18 -$cookieName = $cookiePrefix . "Selenium";
 17+$cookiePrefix = $wgSitename . '-';
 18+$cookieName = $cookiePrefix . 'Selenium';
1919
20 -// this is a fallback sql file
 20+// this is a fallback SQL file
2121 $testSqlFile = false;
2222 $testImageZip = false;
2323
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
2525 if ( isset( $_GET['setupTestSuite'] ) ) {
2626 $setupTestSuiteName = $_GET['setupTestSuite'];
2727
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+ {
2933 return;
3034 }
31 - if ( strlen( $setupTestSuiteName) > 0 ) {
 35+ if ( strlen( $setupTestSuiteName ) > 0 ) {
3236 $expire = time() + 600;
33 - setcookie( $cookieName,
 37+ setcookie(
 38+ $cookieName,
3439 $setupTestSuiteName,
3540 $expire,
3641 $wgCookiePath,
3742 $wgCookieDomain,
3843 $wgCookieSecure,
39 - true );
 44+ true
 45+ );
4046 }
4147
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
4450 $testResourceFiles = array(); // an array containing all the resource files needed for this test
4551 $callback = $wgSeleniumTestConfigs[$setupTestSuiteName];
4652 call_user_func_array( $callback, array( &$testIncludes, &$testGlobalConfigs, &$testResourceFiles));
4753
48 - if ( isset($testResourceFiles['images']) ) {
 54+ if ( isset( $testResourceFiles['images'] ) ) {
4955 $testImageZip = $testResourceFiles['images'];
5056 }
5157
@@ -57,32 +63,34 @@
5864 }
5965 }
6066
61 -//clear the cookie based on a request param
 67+// clear the cookie based on a request param
6268 if ( isset( $_GET['clearTestSuite'] ) ) {
6369 $testSuiteName = getTestSuiteNameFromCookie( $cookieName );
6470
6571 $expire = time() - 600;
66 - setcookie( $cookieName,
 72+ setcookie(
 73+ $cookieName,
6774 '',
6875 $expire,
6976 $wgCookiePath,
7077 $wgCookieDomain,
7178 $wgCookieSecure,
72 - true );
 79+ true
 80+ );
7381
7482 $testResourceName = getTestResourceNameFromTestSuiteName( $testSuiteName );
7583 teardownTestResources( $testResourceName );
7684 }
7785
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.
7987 if ( isset( $_COOKIE[$cookieName] ) ) {
8088 $testSuiteName = getTestSuiteNameFromCookie( $cookieName );
8189 if ( !isset( $wgSeleniumTestConfigs[$testSuiteName] ) ) {
8290 return;
8391 }
8492
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
8795 $testResourceFiles = array(); // an array containing all the resource files needed for this test
8896 $callback = $wgSeleniumTestConfigs[$testSuiteName];
8997 call_user_func_array( $callback, array( &$testIncludes, &$testGlobalConfigs, &$testResourceFiles));
@@ -134,21 +142,21 @@
135143
136144 // Basic security. Do not allow to drop productive database.
137145 if ( $testResourceName == $wgDBname ) {
138 - die( "Cannot override productive database." );
 146+ die( 'Cannot override productive database.' );
139147 }
140148 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.' );
142150 }
143151
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 );
148156
149 - // do not set the new db name before database is setup
 157+ // do not set the new DB name before database is setup
150158 $wgDBname = $testResourceName;
151159 $dbw->selectDB( $testResourceName );
152 - // populate from sql file
 160+ // populate from SQL file
153161 if ( $testSqlFile ) {
154162 $dbw->sourceFile( $testSqlFile );
155163 }
@@ -169,8 +177,8 @@
170178
171179 function teardownTestResources( $testResourceName ) {
172180 // 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 );
175183
176184 $testUploadPath = getTestUploadPathFromResourceName( $testResourceName );
177185 // remove test image dir
@@ -190,7 +198,7 @@
191199 $wgDBuser = $wgDBtestuser;
192200 $wgDBpassword = $wgDBtestpassword;
193201
194 - $testUploadPath = getTestUploadPathFromResourceName( $testResourceName );
 202+ $testUploadPath = getTestUploadPathFromResourceName( $testResourceName );
195203 $wgUploadPath = $testUploadPath;
196204 }
197205
@@ -200,10 +208,10 @@
201209 $objects = scandir( $dir );
202210 foreach ( $objects as $object ) {
203211 if ( $object != "." && $object != ".." ) {
204 - if ( filetype( $dir."/".$object ) == "dir" ) {
205 - wfRecursiveRemoveDir( $dir."/".$object );
 212+ if ( filetype( $dir . '/' . $object ) == "dir" ) {
 213+ wfRecursiveRemoveDir( $dir . '/' . $object );
206214 } else {
207 - unlink( $dir."/".$object );
 215+ unlink( $dir . '/' . $object );
208216 }
209217 }
210218 }

Status & tagging log