You are here

public function AutoLogoutByRoleTestCase::testAutoLogoutTimeoutByRoleWhenAuthenticatedRoleHasATimeoutAuthenticatedIsLargerThanRole in Automated Logout 7.4

Check the role timeout prescendence works when multiple roles have timeouts.

File

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

Class

AutoLogoutByRoleTestCase
Tests the autologout's features.

Code

public function testAutoLogoutTimeoutByRoleWhenAuthenticatedRoleHasATimeoutAuthenticatedIsLargerThanRole() {

  // Standard logout time is 60 seconds.
  variable_set("autologout_timeout", '60');

  // Enable role based logouts.
  variable_set("autologout_role_logout", '1');

  // Role logout time is set to 10 seconds.
  variable_set("autologout_role_{$this->role->rid}", '1');
  variable_set("autologout_role_{$this->role->rid}_timeout", '10');

  // Authenticated role has its own logout at 20 seconds.
  $authenticated_role = user_role_load_by_name('authenticated user');
  variable_set("autologout_role_{$authenticated_role->rid}", '1');
  variable_set("autologout_role_{$authenticated_role->rid}_timeout", '20');
  $user_timeout = _autologout_get_user_timeout($this->user->uid);
  $this
    ->assertEqual($user_timeout, 10, "The users timeout {$user_timeout} is equal to their role timeout of 10");

  // Check that the user can access the page after initial login.
  $this
    ->drupalGet('/');
  $this
    ->assertText(t('Log out'), t('User is still logged in.'));

  // Wait for the role timeout period to elapse.
  sleep(16);

  // Check we are now logged out.
  $this
    ->drupalGet('/');
  $this
    ->assertNoText(t('Log out'), t('User is no longer logged in.'));
  $this
    ->assertText(t('You have been logged out due to inactivity.'), t('User sees inactivity message.'));
}