assertSessionEmpty example

public function testEmptyAnonymousSession() {
    // Disable the dynamic_page_cache module; it'd cause session_test's debug     // output (that is added in     // SessionTestSubscriber::onKernelResponseSessionTest()) to not be added.     $this->container->get('module_installer')->uninstall(['dynamic_page_cache']);

    // Verify that no session is automatically created for anonymous user when     // page caching is disabled.     $this->container->get('module_installer')->uninstall(['page_cache']);
    $this->drupalGet('');
    $this->assertSessionCookie(FALSE);
    $this->assertSessionEmpty(TRUE);

    // The same behavior is expected when caching is enabled.     $this->container->get('module_installer')->install(['page_cache']);
    $config = $this->config('system.performance');
    $config->set('cache.page.max_age', 300);
    $config->save();
    $this->drupalGet('');
    $this->assertSessionCookie(FALSE);
    // @todo Reinstate when REQUEST and RESPONSE events fire for cached pages.     // $this->assertSessionEmpty(TRUE);     $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');

    
Home | Imprint | This part of the site doesn't use cookies.