You are here

public function AutologoutTest::testAutologoutDefaultTimeoutAccessDeniedToAdmin in Automated Logout 8

Tests a user is logged out and denied access to admin pages.

File

tests/src/Functional/AutologoutTest.php, line 145

Class

AutologoutTest
Tests the autologout's features.

Namespace

Drupal\Tests\autologout\Functional

Code

public function testAutologoutDefaultTimeoutAccessDeniedToAdmin() {
  $autologout_settings = $this->configFactory
    ->getEditable('autologout.settings');

  // Enforce auto logout of admin pages.
  $autologout_settings
    ->set('enforce_admin', FALSE)
    ->save();

  // Check that the user can access the page after login.
  $this
    ->drupalGet('admin/reports/status');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  self::assertTrue($this
    ->drupalUserIsLoggedIn($this->privilegedUser));

  // Wait for timeout period to elapse.
  sleep(15);

  // Check we are now logged out.
  $this
    ->drupalGet('admin/reports/status');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  self::assertFalse($this
    ->drupalUserIsLoggedIn($this->privilegedUser));
  $this
    ->assertSession()
    ->pageTextContains($this
    ->t('You have been logged out due to inactivity.'));
}