function MemcacheSessionTestCase::testEmptyAnonymousSession in Zircon Profile 8
Same name and namespace in other branches
- 8.0 modules/memcache/tests/memcache-session.test \MemcacheSessionTestCase::testEmptyAnonymousSession()
Test that empty anonymous sessions are destroyed.
File
- modules/
memcache/ tests/ memcache-session.test, line 138 - Provides SimpleTests for core session handling functionality.
Class
- MemcacheSessionTestCase
- @file Provides SimpleTests for core session handling functionality.
Code
function testEmptyAnonymousSession() {
// Verify that no session is automatically created for anonymous user.
$this
->drupalGet('');
$this
->assertSessionCookie(FALSE);
$this
->assertSessionEmpty(TRUE);
// The same behavior is expected when caching is enabled.
variable_set('cache', TRUE);
$this
->drupalGet('');
$this
->assertSessionCookie(FALSE);
$this
->assertSessionEmpty(TRUE);
$this
->assertEqual($this
->drupalGetHeader('X-Drupal-Cache'), 'MISS', t('Page was not cached.'));
// Start a new session by setting a message.
$this
->drupalGet('session-test/set-message');
$this
->assertSessionCookie(TRUE);
$this
->assertTrue($this
->drupalGetHeader('Set-Cookie'), t('New session was started.'));
// Display the message, during the same request the session is destroyed
// and the session cookie is unset.
$this
->drupalGet('');
$this
->assertSessionCookie(FALSE);
$this
->assertSessionEmpty(FALSE);
$this
->assertFalse($this
->drupalGetHeader('X-Drupal-Cache'), t('Caching was bypassed.'));
$this
->assertText(t('This is a dummy message.'), t('Message was displayed.'));
$this
->assertTrue(preg_match('/SESS\\w+=deleted/', $this
->drupalGetHeader('Set-Cookie')), t('Session cookie was deleted.'));
// Verify that session was destroyed.
$this
->drupalGet('');
$this
->assertSessionCookie(FALSE);
$this
->assertSessionEmpty(TRUE);
$this
->assertNoText(t('This is a dummy message.'), t('Message was not cached.'));
$this
->assertEqual($this
->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.'));
$this
->assertFalse($this
->drupalGetHeader('Set-Cookie'), t('New session was not started.'));
// Verify that no session is created if drupal_save_session(FALSE) is called.
$this
->drupalGet('session-test/set-message-but-dont-save');
$this
->assertSessionCookie(FALSE);
$this
->assertSessionEmpty(TRUE);
// Verify that no message is displayed.
$this
->drupalGet('');
$this
->assertSessionCookie(FALSE);
$this
->assertSessionEmpty(TRUE);
$this
->assertNoText(t('This is a dummy message.'), t('The message was not saved.'));
}