reverted: --- b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -48,11 +48,6 @@ protected $curlHandle; /** - * An array of other session curlHandles. - */ - protected $curlHandles = array(); - - /** * The headers of the page currently loaded in the internal browser. * * @var Array @@ -105,11 +100,6 @@ protected $loggedInUser = FALSE; /** - * A collection of other logged in users. - */ - protected $loggedInUsers = array(); - - /** * The current cookie file used by cURL. * * We do not reuse the cookies in further runs, so we do not need a file @@ -3277,83 +3267,6 @@ } /** - * Initialise a new unique session. - * - * @return string - * Unique identifier for the session just stored. - * It is the cookiefile name. - */ - protected function stashSession() { - if (empty($this->cookieFile)) { - // No session to stash. - return; - } - - // The session_id is the current cookieFile. - $session_id = $this->cookieFile; - - $this->curlHandles[$session_id] = $this->curlHandle; - $this->loggedInUsers[$session_id] = $this->loggedInUser; - - // Reset Curl. - unset($this->curlHandle); - $this->loggedInUser = FALSE; - - // Set a new unique cookie filename. - do { - $this->cookieFile = $this->public_files_directory . '/' . $this->randomName() . '.jar'; - } - while (isset($this->curlHandles[$this->cookieFile])); - - return $session_id; - } - - /** - * Restore a previously stashed session. - * - * @param string $session_id - * The session to restore as returned by stashSession(); - * This is also the path to the cookie file. - * - * @return string - * The old session id that was replaced. - */ - protected function restoreSession($session_id) { - $old_session_id = NULL; - - if (isset($this->curlHandle)) { - $old_session_id = $this->stashSession(); - } - - // Restore the specified session. - $this->curlHandle = $this->curlHandles[$session_id]; - $this->cookieFile = $session_id; - $this->loggedInUser = $this->loggedInUsers[$session_id]; - - return $old_session_id; - } - - /** - * Close all stashed sessions and the current session. - */ - protected function closeAllSessions() { - foreach ($this->curlHandles as $cookie_file => $curl_handle) { - if (isset($curl_handle)) { - curl_close($curl_handle); - } - } - - // Make the server forget all sessions. - db_truncate('sessions')->execute(); - - $this->curlHandles = array(); - $this->loggedInUsers = array(); - $this->loggedInUser = FALSE; - $this->cookieFile = $this->public_files_directory . '/' . $this->randomName() . '.jar'; - unset($this->curlHandle); - } - - /** * Creates a mock request and sets it on the generator. * * This is used to manipulate how the generator generates paths during tests. only in patch2: unchanged: --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -10,22 +10,19 @@ use Drupal\Component\Serialization\Json; use Drupal\Component\Serialization\Yaml; use Drupal\Component\Utility\Crypt; -use Drupal\Component\Utility\NestedArray; +use Drupal\Component\Utility\Random; use Drupal\Component\Utility\String; use Drupal\Core\Cache\Cache; use Drupal\Core\DependencyInjection\YamlFileLoader; use Drupal\Core\DrupalKernel; use Drupal\Core\Database\Database; -use Drupal\Core\Database\ConnectionNotDefinedException; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Render\Element; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AnonymousUserSession; use Drupal\Core\Session\UserSession; use Drupal\Core\Site\Settings; use Drupal\Core\StreamWrapper\PublicStream; -use Drupal\Core\Datetime\DrupalDateTime; use Drupal\block\Entity\Block; use Symfony\Component\HttpFoundation\Request; use Drupal\user\Entity\Role; @@ -61,6 +58,11 @@ protected $curlHandle; /** + * An array of other session curlHandles. + */ + protected $curlHandles = array(); + + /** * The headers of the page currently loaded in the internal browser. * * @var Array @@ -85,6 +87,11 @@ protected $loggedInUser = FALSE; /** + * A collection of other logged in users. + */ + protected $loggedInUsers = array(); + + /** * The current cookie file used by cURL. * * We do not reuse the cookies in further runs, so we do not need a file @@ -2717,4 +2724,82 @@ protected function prepareRequestForGenerator($clean_urls = TRUE, $override_serv return $request; } + + /** + * Initialise a new unique session. + * + * @return string + * Unique identifier for the session just stored. + * It is the cookiefile name. + */ + protected function stashSession() { + if (empty($this->cookieFile)) { + // No session to stash. + return; + } + + // The session_id is the current cookieFile. + $session_id = $this->cookieFile; + + $this->curlHandles[$session_id] = $this->curlHandle; + $this->loggedInUsers[$session_id] = $this->loggedInUser; + + // Reset Curl. + unset($this->curlHandle); + $this->loggedInUser = FALSE; + $random = new Random(); + // Set a new unique cookie filename. + do { + $this->cookieFile = $this->public_files_directory . '/' . $random->name() . '.jar'; + } + while (isset($this->curlHandles[$this->cookieFile])); + + return $session_id; + } + + /** + * Restore a previously stashed session. + * + * @param string $session_id + * The session to restore as returned by stashSession(); + * This is also the path to the cookie file. + * + * @return string + * The old session id that was replaced. + */ + protected function restoreSession($session_id) { + $old_session_id = NULL; + + if (isset($this->curlHandle)) { + $old_session_id = $this->stashSession(); + } + + // Restore the specified session. + $this->curlHandle = $this->curlHandles[$session_id]; + $this->cookieFile = $session_id; + $this->loggedInUser = $this->loggedInUsers[$session_id]; + + return $old_session_id; + } + + /** + * Close all stashed sessions and the current session. + */ + protected function closeAllSessions() { + foreach ($this->curlHandles as $cookie_file => $curl_handle) { + if (isset($curl_handle)) { + curl_close($curl_handle); + } + } + + // Make the server forget all sessions. + db_truncate('sessions')->execute(); + + $random = new Random(); + $this->curlHandles = array(); + $this->loggedInUsers = array(); + $this->loggedInUser = FALSE; + $this->cookieFile = $this->public_files_directory . '/' . $random->name() . '.jar'; + unset($this->curlHandle); + } }