protected function UpgradePathTestBase::prepareD8Session

Prepares the appropriate session for the release of Drupal being upgraded.

1 call to UpgradePathTestBase::prepareD8Session()
UpgradePathTestBase::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php
Overrides Drupal\simpletest\WebTestBase::setUp() for upgrade testing.
1 method overrides UpgradePathTestBase::prepareD8Session()

File

drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php, line 53
Definition of Drupal\system\Tests\Upgrade\UpgradePathTestBase.

Class

UpgradePathTestBase
Perform end-to-end tests of the upgrade path.

Namespace

Drupal\system\Tests\Upgrade

Code

protected function prepareD8Session() {

  // We need an IP when storing sessions
  // so add a dummy request in the container.
  $request = Request::create('http://example.com/');
  $request->server
    ->set('REMOTE_ADDR', '3.3.3.3');
  $this->container
    ->set('request', $request);

  // 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));

  // Force our way into the session of the child site.
  drupal_save_session(TRUE);
  _drupal_session_write($sid, '');
  drupal_save_session(FALSE);
}