Commit 3893c017 authored by webchick's avatar webchick

#838438 follow-up by Damien Tournoud: db_prefix is no longer a global, wrong...

#838438 follow-up by Damien Tournoud: db_prefix is no longer a global, wrong path given to drupal_var_export() function file.
parent 8e6d6e38
......@@ -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();
}
/**
......
......@@ -29,7 +29,7 @@
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";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment