You are here

public function AutologoutTestSessionCleanupOnLogin::testSessionCleanupAtLogin in Automated Logout 7.4

Test that stale sessions are cleaned up at login.

File

tests/autologout.test, line 44
Simpletest tests for autologout.

Class

AutologoutTestSessionCleanupOnLogin
Test session cleanup on login.

Code

public function testSessionCleanupAtLogin() {

  // For the purposes of the test, set the timeout periods to 5 seconds.
  variable_set('autologout_timeout', 5);
  variable_set('autologout_padding', 0);

  // Login in session 1.
  $this
    ->drupalLogin($this->privileged_user);

  // Check one active session.
  $sessions = $this
    ->getSessions($this->privileged_user);
  $this
    ->assertEqual(1, count($sessions), t('After initial login there is one active session'));

  // Switch sessions.
  $session1 = $this
    ->stashSession();

  // Login to session 2.
  $this
    ->drupalLogin($this->privileged_user);

  // Check two active sessions.
  $sessions = $this
    ->getSessions($this->privileged_user);
  $this
    ->assertEqual(2, count($sessions), t('After second login there is now two active session'));

  // Switch sessions.
  $session2 = $this
    ->stashSession();

  // Wait for sessions to expire.
  sleep(6);

  // Login to session 3.
  $this
    ->drupalLogin($this->privileged_user);

  // Check one active session.
  $sessions = $this
    ->getSessions($this->privileged_user);
  $this
    ->assertEqual(1, count($sessions), t('After third login, there is 1 active session, two stale sessions were cleaned up.'));

  // Switch back to session 1 and check no longer logged in.
  $this
    ->restoreSession($session1);
  $this
    ->drupalGet('node');
  $this
    ->assertNoText(t('Log out'), t('User is no longer logged in on session 1.'));
  $this
    ->closeAllSessions();
}