summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-06-29 00:21:00 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-06-29 00:21:00 +0000
commit3893c01799989452adad08a7636bf71e276da046 (patch)
tree0d28900e7e782d87bf4d8712aaef991e164f3ce4
parent8e6d6e38ac5600a91fe121603cf457c138305f73 (diff)
downloadbrdo-3893c01799989452adad08a7636bf71e276da046.tar.gz
brdo-3893c01799989452adad08a7636bf71e276da046.tar.bz2
#838438 follow-up by Damien Tournoud: db_prefix is no longer a global, wrong path given to drupal_var_export() function file.
-rw-r--r--modules/simpletest/tests/upgrade/upgrade.test102
-rw-r--r--scripts/dump-database-d6.sh2
2 files changed, 54 insertions, 50 deletions
diff --git a/modules/simpletest/tests/upgrade/upgrade.test b/modules/simpletest/tests/upgrade/upgrade.test
index f02321ce6..2f9b497ed 100644
--- a/modules/simpletest/tests/upgrade/upgrade.test
+++ b/modules/simpletest/tests/upgrade/upgrade.test
@@ -25,28 +25,36 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
* Override of DrupalWebTestCase::setUp() specialized for upgrade testing.
*/
protected function setUp() {
- global $db_prefix, $user, $language, $conf, $databases;
+ global $user, $language, $conf;
// Reset flags.
$this->upgradedSite = FALSE;
$this->upgradeErrors = array();
+ // Generate a temporary prefixed database to ensure that tests have a clean starting point.
+ $this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000);
+ db_update('simpletest_test_id')
+ ->fields(array('last_prefix' => $this->databasePrefix))
+ ->condition('test_id', $this->testId)
+ ->execute();
+
+ // Clone the current connection and replace the current prefix.
+ $connection_info = Database::getConnectionInfo('default');
+ Database::renameConnection('default', 'simpletest_original_default');
+ foreach ($connection_info as $target => $value) {
+ $connection_info[$target]['prefix'] = array(
+ 'default' => $value['prefix']['default'] . $this->databasePrefix,
+ );
+ }
+ Database::addConnectionInfo('default', 'default', $connection_info['default']);
+
// Store necessary current values before switching to prefixed database.
$this->originalLanguage = $language;
$this->originalLanguageDefault = variable_get('language_default');
- $this->originalPrefix = $db_prefix;
$this->originalFileDirectory = file_directory_path();
$this->originalProfile = drupal_get_profile();
$clean_url_original = variable_get('clean_url', 0);
- // Generate temporary prefixed database to ensure that tests have a clean starting point.
- $db_prefix_new = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}');
- db_update('simpletest_test_id')
- ->fields(array('last_prefix' => $db_prefix_new))
- ->condition('test_id', $this->testId)
- ->execute();
- $db_prefix = $db_prefix_new;
-
// Unregister the registry.
// This is required to make sure that the database layer works properly.
spl_autoload_unregister('drupal_autoload_class');
@@ -55,7 +63,7 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
// Create test directories ahead of installation so fatal errors and debug
// information can be logged during installation process.
// Use mock files directories with the same prefix as the database.
- $public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($db_prefix, 10);
+ $public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10);
$private_files_directory = $public_files_directory . '/private';
$temp_files_directory = $private_files_directory . '/temp';
@@ -108,56 +116,52 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
* Override of DrupalWebTestCase::tearDown() specialized for upgrade testing.
*/
protected function tearDown() {
- global $db_prefix, $user, $language;
+ global $user, $language;
// In case a fatal error occured that was not in the test process read the
// log to pick up any fatal errors.
- $db_prefix_temp = $db_prefix;
- $db_prefix = $this->originalPrefix;
- simpletest_log_read($this->testId, $db_prefix, get_class($this), TRUE);
- $db_prefix = $db_prefix_temp;
-
- if (preg_match('/simpletest\d+/', $db_prefix)) {
- // Delete temporary files directory.
- file_unmanaged_delete_recursive($this->originalFileDirectory . '/simpletest/' . substr($db_prefix, 10));
-
- // Remove all prefixed tables (all the tables in the schema).
- $tables = db_find_tables($this->originalPrefix . '%');
- foreach ($tables as $table) {
- db_drop_table($table);
- }
+ simpletest_log_read($this->testId, $this->databasePrefix, get_class($this), TRUE);
- // Return the database prefix to the original.
- $db_prefix = $this->originalPrefix;
+ // Delete temporary files directory.
+ file_unmanaged_delete_recursive($this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10));
- // Return the user to the original one.
- $user = $this->originalUser;
- drupal_save_session(TRUE);
+ // Get back to the original connection.
+ Database::removeConnection('default');
+ Database::renameConnection('simpletest_original_default', 'default');
- // Ensure that internal logged in variable and cURL options are reset.
- $this->loggedInUser = FALSE;
- $this->additionalCurlOptions = array();
+ // Remove all prefixed tables.
+ $tables = db_find_tables($this->databasePrefix . '%');
+ foreach ($tables as $table) {
+ db_drop_table($table);
+ }
- // Reload module list and implementations to ensure that test module hooks
- // aren't called after tests.
- module_list(TRUE);
- module_implements('', FALSE, TRUE);
+ // Return the user to the original one.
+ $user = $this->originalUser;
+ drupal_save_session(TRUE);
- // Reset the Field API.
- field_cache_clear();
+ // Ensure that internal logged in variable and cURL options are reset.
+ $this->loggedInUser = FALSE;
+ $this->additionalCurlOptions = array();
- // Rebuild caches.
- parent::refreshVariables();
+ // Reload module list and implementations to ensure that test module hooks
+ // aren't called after tests.
+ module_list(TRUE);
+ module_implements('', FALSE, TRUE);
- // Reset language.
- $language = $this->originalLanguage;
- if ($this->originalLanguageDefault) {
- $GLOBALS['conf']['language_default'] = $this->originalLanguageDefault;
- }
+ // Reset the Field API.
+ field_cache_clear();
+
+ // Rebuild caches.
+ parent::refreshVariables();
- // Close the CURL handler.
- $this->curlClose();
+ // Reset language.
+ $language = $this->originalLanguage;
+ if ($this->originalLanguageDefault) {
+ $GLOBALS['conf']['language_default'] = $this->originalLanguageDefault;
}
+
+ // Close the CURL handler.
+ $this->curlClose();
}
/**
diff --git a/scripts/dump-database-d6.sh b/scripts/dump-database-d6.sh
index ff21aedf2..7bcca95c1 100644
--- a/scripts/dump-database-d6.sh
+++ b/scripts/dump-database-d6.sh
@@ -29,7 +29,7 @@ include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Include the utility drupal_var_export() function.
-include_once dirname(__FILE__) . '/../includes/variable.inc';
+include_once dirname(__FILE__) . '/../includes/utility.inc';
// Output the PHP header.
$output = "<?php\n\n";