You are here

function SecureSiteTest::testGuestSecond in Secure Site 5

Same name and namespace in other branches
  1. 6 tests/securesite.test \SecureSiteTest::testGuestSecond()

Check that guests get the correct page after previously logging in as a user

File

tests/securesite.test, line 335
Secure Site module unit tests

Class

SecureSiteTest
Unit tests for the Secure Site module

Code

function testGuestSecond() {
  $realm = variable_get('securesite_realm', variable_get('site_name', 'Drupal'));
  $privileged_user = $this
    ->drupalCreateUserRolePerm(array(
    'access content',
    'access secured pages',
  ));

  // Login as a privileged user first
  $this
    ->drupalVariableSet('securesite_enabled', SECURESITE_AUTH);
  $this
    ->drupalVariableSet('securesite_filter_pages_type', SECURESITE_WHITELIST);
  $this
    ->drupalVariableSet('securesite_filter_pages', '');
  $this
    ->drupalVariableSet('securesite_guest_name', 'foo');
  $this
    ->drupalVariableSet('securesite_guest_pass', 'bar');
  $this
    ->drupalGet(url(NULL, NULL, NULL, TRUE));
  $this
    ->assertResponse('401', t('Guest Mode: Guest Second') . ': %s');
  $this
    ->assertAuthentication('Basic');
  $this
    ->assertRealm($realm);
  $this
    ->authenticate($privileged_user->name, $privileged_user->pass_raw);
  $this
    ->assertResponse('200');
  $this
    ->assertNoAuthentication();
  $this
    ->assertNoText('User login');
  $this
    ->drupalGet(url('logout', NULL, NULL, TRUE));

  // Now, login as a guest
  $this
    ->assertResponse('401');
  $this
    ->assertAuthentication('Basic');
  $this
    ->assertRealm($realm);
  $this
    ->authenticate('foo', 'bar');
  $this
    ->assertResponse('200');
  $this
    ->assertNoAuthentication();
  $this
    ->assertText('User login');
}