setDefaultSessionName example


  protected function initMink() {
    $client = new DrupalTestBrowser();
    $client->followMetaRefresh(TRUE);
    $driver = new BrowserKitDriver($client);
    $session = new Session($driver);
    $this->mink = new Mink();
    $this->mink->registerSession('default', $session);
    $this->mink->setDefaultSessionName('default');
    $session->start();
    return $session;
  }

  /** * Get the Mink instance. * * Use the Mink object to perform assertions against the content returned by a * request. * * @return \Behat\Mink\Mink * The Mink object. */
// Switch browser cookie to anonymous user, then back to user 1.     $session_cookie_name = $this->getSessionName();
    $session_cookie_value = $session->getCookie($session_cookie_name);
    $session->restart();
    $this->initFrontPage();
    // Session restart always resets all the cookies by design, so we need to     // add the old session cookie again.     $session->setCookie($session_cookie_name$session_cookie_value);
    // Verify that the session data persists through browser close.     $this->drupalGet('session-test/get');
    $this->assertSession()->pageTextContains($value_1);
    $this->mink->setDefaultSessionName('default');

    // Logout the user and make sure the stored value no longer persists.     $this->drupalLogout();
    $this->sessionReset();
    // Verify that after logout, previous user's session data is not available.     $this->drupalGet('session-test/get');
    $this->assertSession()->pageTextNotContains($value_1);

    // Now try to store some data as an anonymous user.     $value_3 = $this->randomMachineName();
    // Verify that session data is stored for anonymous user.
$handler_stack->push($this->getResponseLogHandler());

      $driver->getClient()->setClient($client);
    }

    $selectors_handler = new SelectorsHandler([
      'hidden_field_selector' => new HiddenFieldSelector(),
    ]);
    $session = new Session($driver$selectors_handler);
    $this->mink = new Mink();
    $this->mink->registerSession('default', $session);
    $this->mink->setDefaultSessionName('default');
    $this->registerSessions();

    $this->initFrontPage();

    // Copies cookies from the current environment, for example, XDEBUG_SESSION     // in order to support Xdebug.     // @see BrowserTestBase::initFrontPage()     $cookies = $this->extractCookiesFromRequest(\Drupal::request());
    foreach ($cookies as $cookie_name => $values) {
      foreach ($values as $value) {
        $session->setCookie($cookie_name$value);
      }
Home | Imprint | This part of the site doesn't use cookies.