#283246 by Damien Tournoud: simpletest should start from a clean user. From: Damien Tournoud --- modules/simpletest/drupal_web_test_case.php | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-) diff --git modules/simpletest/drupal_web_test_case.php modules/simpletest/drupal_web_test_case.php index f14dc40..ef6203d 100644 --- modules/simpletest/drupal_web_test_case.php +++ modules/simpletest/drupal_web_test_case.php @@ -92,6 +92,13 @@ class DrupalWebTestCase { protected $originalFileDirectory = NULL; /** + * The original user, before it was changed to a clean uid = 1 for testing purposes. + * + * @var object + */ + protected $originalUser = NULL; + + /** * Current results of this test case. * * @var Array @@ -779,7 +786,7 @@ class DrupalWebTestCase { * List of modules to enable for the duration of the test. */ protected function setUp() { - global $db_prefix; + global $db_prefix, $user; // Store necessary current values before switching to prefixed database. $this->originalPrefix = $db_prefix; @@ -814,6 +821,11 @@ class DrupalWebTestCase { $this->refreshVariables(); $this->checkPermissions(array(), TRUE); + // Log in with a clean $user. + $this->originalUser = $user; + drupal_save_session(FALSE); + $user = user_load(array('uid' => 1)); + // Restore necessary variables. variable_set('install_profile', 'default'); variable_set('install_task', 'profile-finished'); @@ -860,7 +872,7 @@ class DrupalWebTestCase { * and reset the database prefix. */ protected function tearDown() { - global $db_prefix; + global $db_prefix, $user; if (preg_match('/simpletest\d+/', $db_prefix)) { // Delete temporary files directory and reset files directory path. simpletest_clean_temporary_directory(file_directory_path()); @@ -876,6 +888,10 @@ class DrupalWebTestCase { // Return the database prefix to the original. $db_prefix = $this->originalPrefix; + // Return the user to the original one. + $user = $this->originalUser; + drupal_save_session(TRUE); + // Ensure that the internal logged in variable is reset. $this->isLoggedIn = FALSE;