diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index 43795c98849419fe61b7d994160140df5144ff17..60382b6bf50715927e007329b4399fd414f87803 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -91,6 +91,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. * @@ -779,7 +786,7 @@ protected function drupalLogout() { * 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 @@ protected function setUp() { $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 @@ protected function refreshVariables() { * 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 @@ protected function tearDown() { // 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; diff --git a/modules/simpletest/tests/session.test b/modules/simpletest/tests/session.test index 85a1bb80da09b8ed10b433b3a153224b75d8cdb6..ec27378e3ceb6c00a4f00473effac4821f8c90f0 100644 --- a/modules/simpletest/tests/session.test +++ b/modules/simpletest/tests/session.test @@ -23,7 +23,7 @@ class SessionTestCase extends DrupalWebTestCase { * Tests for drupal_save_session() and drupal_session_regenerate(). */ function testSessionSaveRegenerate() { - $this->assertTrue(drupal_save_session(), t('drupal_save_session() correctly returns TRUE when initially called with no arguments.'), t('Session')); + $this->assertFalse(drupal_save_session(), t('drupal_save_session() correctly returns FALSE (inside of testing framework) when initially called with no arguments.'), t('Session')); $this->assertFalse(drupal_save_session(FALSE), t('drupal_save_session() correctly returns FALSE when called with FALSE.'), t('Session')); $this->assertFalse(drupal_save_session(), t('drupal_save_session() correctly returns FALSE when saving has been disabled.'), t('Session')); $this->assertTrue(drupal_save_session(TRUE), t('drupal_save_session() correctly returns TRUE when called with TRUE.'), t('Session'));