public function AutologoutAjaxTestCase::testAutologoutByAjax in Automated Logout 7.4
Same name and namespace in other branches
- 6.4 tests/autologout.test \AutologoutAjaxTestCase::testAutologoutByAjax()
Test ajax logout callbacks work as expected.
File
- tests/
autologout.test, line 517 - Simpletest tests for autologout.
Class
- AutologoutAjaxTestCase
- Test the Autologout ajax endpoints.
Code
public function testAutologoutByAjax() {
variable_set('autologout_timeout', 100);
variable_set('autologout_padding', 10);
// 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.'));
// Test the time remaining callback works as expected.
$result = $this
->drupalGet('autologout_ajax_get_time_left');
$this
->assertResponse(200, t('autologout_ajax_get_time_left is accessible when logged in'));
$result = json_decode($result);
$this
->assertEqual('insert', $result[1]->command, t('autologout_ajax_get_time_left returns an insert command for adding the jstimer onto the page'));
$this
->assertEqual('#timer', $result[1]->selector, t('autologout_ajax_get_time_left specifies the #timer selector.'));
$this
->assert(!empty($result[2]->settings->time) && is_int($result[2]->settings->time) && $result[2]->settings->time > 0, t('autologout_ajax_get_time_left returns the remaining time as a positive integer'));
// Test that ajax logout works as expected.
$json_string = $this
->drupalGet('autologout_ahah_logout');
$this
->assertResponse(200, t('autologout_ahah_logout is accessible when logged in'));
// Check we are now logged out.
$this
->drupalGet('node');
$this
->assertResponse(200, t('Homepage is accessible'));
$this
->assertNoText(t('Log out'), t('User is no longer logged in.'));
// Check further get time remaining requests return access denied.
$result = $this
->drupalGet('autologout_ajax_get_time_left');
$result = json_decode($result);
$this
->assertEqual($result[1]->command, 'alert', t('When logged out, autologout_ajax_get_time_left returns the normal Drupal ajax alert.'));
// Check further logout requests result in access denied.
$this
->drupalGet('autologout_ahah_logout');
$this
->assertResponse(403, t('autologout_ahah logout is not accessible when logged out.'));
}