resetSessions example

    $config = $this->config('system.performance');
    $config->set('cache.page.max_age', 300);
    $config->save();

    $account = $this->drupalCreateUser();
    $url = Url::fromRoute('router_test.11');

    // Ensure we can log in with valid authentication details.     $this->basicAuthGet($url$account->getAccountName()$account->pass_raw);
    $this->assertSession()->pageTextContains($account->getAccountName());
    $this->assertSession()->statusCodeEquals(200);
    $this->mink->resetSessions();
    $this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
    // Check that Cache-Control is not set to public.     $this->assertSession()->responseHeaderNotContains('Cache-Control', 'public');

    // Ensure that invalid authentication details give access denied.     $this->basicAuthGet($url$account->getAccountName()$this->randomMachineName());
    $this->assertSession()->pageTextNotContains($account->getAccountName());
    $this->assertSession()->statusCodeEquals(403);
    $this->mink->resetSessions();

    // Ensure that the user is prompted to authenticate if they are not yet
// Reset the sid in {sessions} to a blank string. This may exist in the     // wild in some cases, although we normally prevent it from happening.     Database::getConnection()->update('sessions')
      ->fields([
        'sid' => '',
      ])
      ->condition('uid', $user->id())
      ->execute();
    // Send a blank sid in the session cookie, and the session should no longer     // be valid. Closing the curl handler will stop the previous session ID     // from persisting.     $this->mink->resetSessions();
    $this->drupalGet('session-test/id-from-cookie');
    // Verify that session ID is blank as sent from cookie header.     $this->assertSession()->responseContains("session_id:\n");
    // Assert that we have an anonymous session now.     $this->drupalGet('session-test/is-logged-in');
    $this->assertSession()->statusCodeEquals(403);
  }

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