Commit 05ff0c42 authored by catch's avatar catch

Issue #2067991 by alexpott: Fixed XDEBUG_SESSION cookie causes upgrade path tests to fail.

parent 80d9f5c8
......@@ -175,6 +175,13 @@ abstract class WebTestBase extends TestBase {
*/
protected $kernel;
/**
* Cookies to set on curl requests.
*
* @var array
*/
protected $curlCookies = array();
/**
* Constructor for \Drupal\simpletest\WebTestBase.
*/
......@@ -971,8 +978,10 @@ protected function tearDown() {
$this->loggedInUser = FALSE;
$this->additionalCurlOptions = array();
// Close the CURL handler.
// Close the CURL handler and reset the cookies array used for upgrade
// testing so test classes containing multiple tests are not polluted.
$this->curlClose();
$this->curlCookies = array();
}
/**
......@@ -1070,6 +1079,10 @@ protected function curlExec($curl_options, $redirect = FALSE) {
$curl_options[CURLOPT_HTTPHEADER][] = 'Expect:';
}
$cookies = array();
if (!empty($this->curlCookies)) {
$cookies = $this->curlCookies;
}
// In order to debug webtests you need to either set a cookie or have the
// xdebug session in the URL. If the developer listens to connection on the
// parent site, by default the cookie is not forwarded to the client side,
......@@ -1077,6 +1090,11 @@ protected function curlExec($curl_options, $redirect = FALSE) {
// this bit of information is forwarded. Make sure that the debugger listens
// to at least three external connections.
if (isset($_COOKIE['XDEBUG_SESSION'])) {
$cookies[] = 'XDEBUG_SESSION=' . $_COOKIE['XDEBUG_SESSION'];
}
// Merge additional cookies in.
if (!empty($cookies)) {
$curl_options += array(
CURLOPT_COOKIE => '',
);
......@@ -1084,7 +1102,7 @@ protected function curlExec($curl_options, $redirect = FALSE) {
if (!empty($curl_options[CURLOPT_COOKIE])) {
$curl_options[CURLOPT_COOKIE] = rtrim($curl_options[CURLOPT_COOKIE], '; ') . '; ';
}
$curl_options[CURLOPT_COOKIE] .= 'XDEBUG_SESSION=' . $_COOKIE['XDEBUG_SESSION'] . '; ';
$curl_options[CURLOPT_COOKIE] .= implode('; ', $cookies) . ';';
}
curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options);
......
......@@ -61,7 +61,7 @@ protected function prepareD8Session() {
// Generate and set a D7-compatible session cookie.
$this->curlInitialize();
$sid = Crypt::hashBase64(uniqid(mt_rand(), TRUE) . Crypt::randomBytes(55));
curl_setopt($this->curlHandle, CURLOPT_COOKIE, rawurlencode(session_name()) . '=' . rawurlencode($sid));
$this->curlCookies[] = rawurlencode(session_name()) . '=' . rawurlencode($sid);
// Force our way into the session of the child site.
drupal_save_session(TRUE);
......
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