assertSessionCookieOnClient example

/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Tests \Drupal\Core\Cache\Context\SessionExistsCacheContext::getContext(). */
  public function testCacheContext() {
    // 1. No session (anonymous).     $this->assertSessionCookieOnClient(FALSE);
    $this->drupalGet(Url::fromRoute('<front>'));
    $this->assertSessionCookieOnClient(FALSE);
    $this->assertSession()->pageTextContains('Session does not exist!');
    $this->assertSession()->responseContains('[session.exists]=0');

    // 2. Session (authenticated).     $this->assertSessionCookieOnClient(FALSE);
    $this->drupalLogin($this->rootUser);
    $this->assertSessionCookieOnClient(TRUE);
    $this->assertSession()->pageTextContains('Session exists!');
    $this->assertSession()->responseContains('[session.exists]=1');
    
Home | Imprint | This part of the site doesn't use cookies.