You are here

function SecureSiteTest::testGuestFirstClean in Secure Site 6

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

Check that users get the correct page after previously logging in as a guest

File

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

Class

SecureSiteTest
Unit tests for the Secure Site module

Code

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

  // Login as a guest 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, array(
    'absolute' => TRUE,
  )));
  $this
    ->assertResponse('401', t('Guest Mode: Guest First Clean') . ': %s');
  $this
    ->assertAuthentication('Basic');
  $this
    ->assertRealm($realm);
  $this
    ->authenticate('foo', 'bar');
  $this
    ->assertResponse('200');
  $this
    ->assertNoAuthentication();
  $this
    ->assertText('User login');

  // Now, force guest logout, restart, and login as a privileged user
  $this
    ->ageCookies(3600 * 24 * 30);
  $this
    ->restart();
  $this
    ->drupalGet(url(NULL, array(
    'absolute' => TRUE,
  )));
  $this
    ->assertResponse('401');
  $this
    ->assertAuthentication('Basic');
  $this
    ->assertRealm($realm);
  $this
    ->authenticate($privileged_user->name, $privileged_user->pass_raw);
  $this
    ->assertResponse('200');
  $this
    ->assertNoAuthentication();
  $this
    ->assertNoText('User login');

  // TODO: Remove the following line once this test passes
  cache_clear_all();
}