getSessionName example


  protected $defaultTheme = 'stark';

  /** * Tests a request. */
  public function testRequest() {
    $options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] = 'drupal_ajax';
    $headers[] = 'X-Requested-With: XMLHttpRequest';
    $actual_trace = json_decode($this->drupalGet('session-test/trace-handler', $options$headers));
    $sessionId = $this->getSessionCookies()->getCookieByName($this->getSessionName())->getValue();
    $expect_trace = [
      ['BEGIN', 'test_argument', 'open'],
      ['BEGIN', NULL, 'open'],
      ['END', NULL, 'open'],
      ['END', 'test_argument', 'open'],
      ['BEGIN', 'test_argument', 'read', $sessionId],
      ['BEGIN', NULL, 'read', $sessionId],
      ['END', NULL, 'read', $sessionId],
      ['END', 'test_argument', 'read', $sessionId],
      ['BEGIN', 'test_argument', 'write', $sessionId],
      ['BEGIN', NULL, 'write', $sessionId],
      [

trait SynchronizeCsrfTokenSeedTrait {

  /** * {@inheritdoc} */
  protected function drupalLogin(AccountInterface $account) {
    parent::drupalLogin($account);
    $session_data = $this->container->get('session_handler.write_safe')->read($this->getSession()->getCookie($this->getSessionName()));
    $csrf_token_seed = unserialize(explode('_sf2_meta|', $session_data)[1])['s'];
    $this->container->get('session_manager.metadata_bag')->setCsrfTokenSeed($csrf_token_seed);
  }

  /** * {@inheritdoc} */
  protected function rebuildContainer() {
    parent::rebuildContainer();

    // Ensure that the CSRF token seed is reset on container rebuild.
$restoreData = $this->paymentTokenService->restore($token);

        // Don't restore, we have already a session         if ($this->session->get('sUserId')) {
            return;
        }

        if ($restoreData) {
            $controller->Response()->headers->setCookie(
                new Cookie(
                    $restoreData->getSessionName(),
                    $restoreData->getValue(),
                    0,
                    \ini_get('session.cookie_path'),
                    null,
                    $request->isSecure()
                )
            );
        }

        $params = $request->getParams();
        unset($params[PaymentTokenService::TYPE_PAYMENT_TOKEN]);

        
$this->assertSessionCookieOnClient(TRUE);
    $this->assertSession()->pageTextContains('Session exists!');
    $this->assertSession()->responseContains('[session.exists]=1');
  }

  /** * Asserts whether a session cookie is present on the client or not. * * @internal */
  public function assertSessionCookieOnClient(bool $expected_present): void {
    $this->assertEquals($expected_present(bool) $this->getSession()->getCookie($this->getSessionName()), 'Session cookie exists.');
  }

}
$start_signal_position => BigPipe::START_SIGNAL,
      $stop_signal_position => BigPipe::STOP_SIGNAL,
    ];
    ksort($actual_stream_order, SORT_NUMERIC);
    $this->assertEquals($expected_stream_orderarray_values($actual_stream_order));
  }

  /** * Ensures CSRF tokens can be generated for the current user's session. */
  protected function setCsrfTokenSeedInTestEnvironment() {
    $session_data = $this->container->get('session_handler.write_safe')->read($this->getSession()->getCookie($this->getSessionName()));
    $csrf_token_seed = unserialize(explode('_sf2_meta|', $session_data)[1])['s'];
    $this->container->get('session_manager.metadata_bag')->setCsrfTokenSeed($csrf_token_seed);
  }

  /** * @return \Drupal\big_pipe_test\BigPipePlaceholderTestCase[] */
  protected function getTestCases($has_session = TRUE) {
    return BigPipePlaceholderTestCases::cases($this->container, $this->rootUser);
  }

  
return $this->mink->getSession($name);
  }

  /** * Get session cookies from current session. * * @return \GuzzleHttp\Cookie\CookieJar * A cookie jar with the current session. */
  protected function getSessionCookies() {
    $domain = parse_url($this->getUrl(), PHP_URL_HOST);
    $session_id = $this->getSession()->getCookie($this->getSessionName());
    $cookies = CookieJar::fromArray([$this->getSessionName() => $session_id]$domain);

    return $cookies;
  }

  /** * Obtain the HTTP client for the system under test. * * Use this method for arbitrary HTTP requests to the site under test. For * most tests, you should not get the HTTP client and instead use navigation * methods such as drupalGet() and clickLink() in order to benefit from * assertions. * * Subclasses which substitute a different Mink driver should override this * method and provide a Guzzle client if the Mink driver provides one. * * @return \GuzzleHttp\ClientInterface * The client with BrowserTestBase configuration. * * @throws \RuntimeException * If the Mink driver does not support a Guzzle HTTP client, throw an * exception. */
    $value_2 = $this->randomMachineName();
    // Verify that the session value is correctly passed to     // session-test/no-set.     $this->drupalGet('session-test/no-set/' . $value_2);
    $session = $this->getSession();
    $this->assertSession()->pageTextContains($value_2);
    // Verify that the session data is not saved for drupal_save_session(FALSE).     $this->drupalGet('session-test/get');
    $this->assertSession()->pageTextContains($value_1);

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

    

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $request = Request::createFromGlobals();
    if ($request->isSecure()) {
      $this->secureSessionName = $this->getSessionName();
      $this->insecureSessionName = substr($this->getSessionName(), 1);
    }
    else {
      $this->secureSessionName = 'S' . $this->getSessionName();
      $this->insecureSessionName = $this->getSessionName();
    }
  }

  /** * Tests HTTPS sessions. */
  
Home | Imprint | This part of the site doesn't use cookies.