Skip to content
Snippets Groups Projects
Commit a7d66871 authored by Angie Byron's avatar Angie Byron
Browse files

#283246 by Damien Tournoud, Dave Reid, drewish, boombatower: Store original...

#283246 by Damien Tournoud, Dave Reid, drewish, boombatower: Store original user when prior to running tests.
parent 574a2e47
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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;
......
......@@ -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'));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment