You are here

public function AutologoutAjaxTestCase::testStayloggedInByAjax in Automated Logout 6.4

Same name and namespace in other branches
  1. 7.4 tests/autologout.test \AutologoutAjaxTestCase::testStayloggedInByAjax()

Test ajax stay logged in callbacks work as expected.

File

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

Class

AutologoutAjaxTestCase
Test the Autologout ajax endpoints.

Code

public function testStayloggedInByAjax() {
  variable_set('autologout_timeout', 20);
  variable_set('autologout_padding', 5);

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

  // Sleep for half the timeout.
  sleep(14);

  // Test that ajax stay logged in works.
  $this
    ->drupalGet('autologout_ahah_set_last');
  $this
    ->assertResponse(200, t('autologout_ahah_set_last is accessible when logged in.'));

  // Sleep for half the timeout again.
  sleep(14);

  // Check we are still logged in.
  $this
    ->drupalGet('node');
  $this
    ->assertResponse(200, t('Homepage is accessible'));
  $this
    ->assertText(t('Log out'), t('User is still logged in.'));

  // Logout.
  $this
    ->drupalGet('autologout_ahah_logout');
  $this
    ->assertResponse(200, t('autologout_ahah_logout is accessible when logged in.'));

  // Check further requests to set last result in 403.
  $this
    ->drupalGet('autologout_ahah_set_last');
  $this
    ->assertResponse(403, t('autologout_ahah_set_last is not accessible when logged out.'));
}