You are here

public function AutologoutAjaxTestCase::testStayloggedInByAjax in Automated Logout 7.4

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

Test ajax stay logged in callbacks work as expected.

File

tests/autologout.test, line 556
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.
  $result = $this
    ->drupalGet('autologout_ahah_set_last');
  $this
    ->assertResponse(200, t('autologout_ahah_set_last is accessible when logged in.'));
  $result = json_decode($result);
  $this
    ->assertEqual('insert', $result[1]->command, t('autologout_ajax_set_last returns an insert command for adding the jstimer onto the page'));
  $this
    ->assertEqual('#timer', $result[1]->selector, t('autologout_ajax_set_last specifies the #timer selector.'));

  // 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.
  $result = $this
    ->drupalGet('autologout_ahah_set_last');
  $result = json_decode($result);
  $this
    ->assertEqual($result[1]->command, 'alert', t('When logged out, autologout_ajax_set_last returns the normal Drupal ajax alert.'));
}