X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles_versions%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=blobdiff_plain;f=includes%2FSeleniumWebSettings.php;h=0e4decfbe2d468afab4132fe467afc0d432f7882;hb=4477e5dbac5764af4b40d338e58f2975e34bd159;hp=7a838e9a7a66b9ac480294db28f7d4a616581c4c;hpb=935f67b7f1e433793fdcf4f4a66ab4a1c309afc8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SeleniumWebSettings.php b/includes/SeleniumWebSettings.php index 7a838e9a7a..0e4decfbe2 100644 --- a/includes/SeleniumWebSettings.php +++ b/includes/SeleniumWebSettings.php @@ -1,9 +1,28 @@ 0 ) { + if ( strlen( $setupTestSuiteName ) > 0 ) { $expire = time() + 600; - setcookie( $cookieName, + setcookie( + $cookieName, $setupTestSuiteName, $expire, $wgCookiePath, $wgCookieDomain, $wgCookieSecure, - true ); + true + ); } - - $testIncludes = array(); //array containing all the includes needed for this test - $testGlobalConfigs = array(); //an array containg all the global configs needed for this test + + $testIncludes = array(); // array containing all the includes needed for this test + $testGlobalConfigs = array(); // an array containg all the global configs needed for this test $testResourceFiles = array(); // an array containing all the resource files needed for this test $callback = $wgSeleniumTestConfigs[$setupTestSuiteName]; call_user_func_array( $callback, array( &$testIncludes, &$testGlobalConfigs, &$testResourceFiles)); - - if ( isset( $testResourceFiles['db'] ) ) { - $testSqlFile = $testResourceFiles['db']; - } - if ( isset($testResourceFiles['images']) ) { + + if ( isset( $testResourceFiles['images'] ) ) { $testImageZip = $testResourceFiles['images']; } - $testResourceName = getTestResourceNameFromTestSuiteName( $setupTestSuiteName ); - switchToTestResources( $testResourceName, false ); // false means do not switch database yet - setupTestResources( $testResourceName, $testSqlFile, $testImageZip ); + if ( isset( $testResourceFiles['db'] ) ) { + $testSqlFile = $testResourceFiles['db']; + $testResourceName = getTestResourceNameFromTestSuiteName( $setupTestSuiteName ); + + switchToTestResources( $testResourceName, false ); // false means do not switch database yet + setupTestResources( $testResourceName, $testSqlFile, $testImageZip ); + } } -//clear the cookie based on a request param +// clear the cookie based on a request param if ( isset( $_GET['clearTestSuite'] ) ) { $testSuiteName = getTestSuiteNameFromCookie( $cookieName ); - $expire = time() - 600; - setcookie( $cookieName, + $expire = time() - 600; + setcookie( + $cookieName, '', $expire, $wgCookiePath, $wgCookieDomain, $wgCookieSecure, - true ); - + true + ); + $testResourceName = getTestResourceNameFromTestSuiteName( $testSuiteName ); teardownTestResources( $testResourceName ); } -//if a cookie is found, run the appropriate callback to get the config params. -if ( isset( $_COOKIE[$cookieName] ) ) { +// if a cookie is found, run the appropriate callback to get the config params. +if ( isset( $_COOKIE[$cookieName] ) ) { $testSuiteName = getTestSuiteNameFromCookie( $cookieName ); if ( !isset( $wgSeleniumTestConfigs[$testSuiteName] ) ) { return; } - - $testResourceName = getTestResourceNameFromTestSuiteName( $testSuiteName ); - switchToTestResources( $testResourceName ); - - $testIncludes = array(); //array containing all the includes needed for this test - $testGlobalConfigs = array(); //an array containg all the global configs needed for this test + + $testIncludes = array(); // array containing all the includes needed for this test + $testGlobalConfigs = array(); // an array containg all the global configs needed for this test $testResourceFiles = array(); // an array containing all the resource files needed for this test - $callback = $wgSeleniumTestConfigs[$testSuiteName]; + $callback = $wgSeleniumTestConfigs[$testSuiteName]; call_user_func_array( $callback, array( &$testIncludes, &$testGlobalConfigs, &$testResourceFiles)); - + + if ( isset( $testResourceFiles['db'] ) ) { + $testResourceName = getTestResourceNameFromTestSuiteName( $testSuiteName ); + switchToTestResources( $testResourceName ); + } foreach ( $testIncludes as $includeFile ) { $file = $IP . '/' . $includeFile; require_once( $file ); } foreach ( $testGlobalConfigs as $key => $value ) { - if ( is_array( $value ) ) { + if ( is_array( $value ) ) { $GLOBALS[$key] = array_merge( $GLOBALS[$key], $value ); - } else { $GLOBALS[$key] = $value; } @@ -128,28 +156,25 @@ function getTestUploadPathFromResourceName( $testResourceName ) { } function setupTestResources( $testResourceName, $testSqlFile, $testImageZip ) { - global $wgDBname, $wgSeleniumUseTestResources; - - if ( !$wgSeleniumUseTestResources ) { - return false; - } + global $wgDBname; + // Basic security. Do not allow to drop productive database. - if ( $testResouceName == $wgDBname ) { - die( "Cannot override productive database." ); + if ( $testResourceName == $wgDBname ) { + die( 'Cannot override productive database.' ); } if ( $testResourceName == '' ) { - die( "Cannot identify a test the resources should be installed for." ); + die( 'Cannot identify a test the resources should be installed for.' ); } - - //create tables - $dbw =& wfGetDB( DB_MASTER ); - $dbw->query( "DROP DATABASE IF EXISTS ".$testResourceName ); - $dbw->query( "CREATE DATABASE ".$testResourceName ); - // do not set the new db name before database is setup + // create tables + $dbw = wfGetDB( DB_MASTER ); + $dbw->query( 'DROP DATABASE IF EXISTS ' . $testResourceName ); + $dbw->query( 'CREATE DATABASE ' . $testResourceName ); + + // do not set the new DB name before database is setup $wgDBname = $testResourceName; $dbw->selectDB( $testResourceName ); - // populate from sql file + // populate from SQL file if ( $testSqlFile ) { $dbw->sourceFile( $testSqlFile ); } @@ -169,14 +194,9 @@ function setupTestResources( $testResourceName, $testSqlFile, $testImageZip ) { } function teardownTestResources( $testResourceName ) { - global $wgSeleniumUseTestResources; - - if ( !$wgSeleniumUseTestResources ) { - return false; - } // remove test database - $dbw =& wfGetDB( DB_MASTER ); - $dbw->query( "DROP DATABASE IF EXISTS ".$testResourceName ); + $dbw = wfGetDB( DB_MASTER ); + $dbw->query( 'DROP DATABASE IF EXISTS ' . $testResourceName ); $testUploadPath = getTestUploadPathFromResourceName( $testResourceName ); // remove test image dir @@ -186,40 +206,16 @@ function teardownTestResources( $testResourceName ) { } function switchToTestResources( $testResourceName, $switchDB = true ) { - global $wgDBuser, $wgDBpassword, $wgDBname, $wgDBprefix; - global $wgDBtestuser, $wgDBtestpassword, $wgDBtestprefix; + global $wgDBuser, $wgDBpassword, $wgDBname; + global $wgDBtestuser, $wgDBtestpassword; global $wgUploadPath; - global $wgSeleniumUseTestResources; - - if ( !$wgSeleniumUseTestResources ) { - return false; - } if ( $switchDB ) { $wgDBname = $testResourceName; } $wgDBuser = $wgDBtestuser; $wgDBpassword = $wgDBtestpassword; - //$wgDBprefix = $wgDBtestprefix; - $testUploadPath = getTestUploadPathFromResourceName( $testResourceName ); + $testUploadPath = getTestUploadPathFromResourceName( $testResourceName ); $wgUploadPath = $testUploadPath; } - -function wfRecursiveRemoveDir( $dir ) { - // taken from http://de3.php.net/manual/en/function.rmdir.php#98622 - if ( is_dir( $dir ) ) { - $objects = scandir( $dir ); - foreach ( $objects as $object ) { - if ( $object != "." && $object != ".." ) { - if ( filetype( $dir."/".$object ) == "dir" ) { - wfRecursiveRemoveDir( $dir."/".$object ); - } else { - unlink( $dir."/".$object ); - } - } - } - reset( $objects ); - rmdir( $dir ); - } -} \ No newline at end of file