You are here

function SecurePagesTestCase::_testAnonymous in Secure Pages 8

Same name and namespace in other branches
  1. 6.2 securepages.test \SecurePagesTestCase::_testAnonymous()
  2. 6 securepages.test \SecurePagesTestCase::_testAnonymous()
  3. 7 securepages.test \SecurePagesTestCase::_testAnonymous()

Tests for anonymous browsing with securepages.

1 call to SecurePagesTestCase::_testAnonymous()
SecurePagesTestCase::testSecurePages in ./securepages.test
Runs all the test functions. These are run from a single outer function to avoid multiple re-installs by simpletest.

File

./securepages.test, line 118
Provides SimpleTests for Secure Pages module.

Class

SecurePagesTestCase
@file Provides SimpleTests for Secure Pages module.

Code

function _testAnonymous() {

  // Visit the home page and /node with plain HTTP.
  $this
    ->drupalGet('', array(
    'https' => FALSE,
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl(url('', array(
    'https' => FALSE,
    'absolute' => TRUE,
  )));
  $this
    ->drupalGet('node', array(
    'https' => FALSE,
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl(url('node', array(
    'https' => FALSE,
    'absolute' => TRUE,
  )));

  // Visit the login page and confirm that browser is redirected to HTTPS.
  $this
    ->drupalGet('user', array(
    'https' => FALSE,
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl(url('user', array(
    'https' => TRUE,
    'absolute' => TRUE,
  )));

  // Visit the home page and /node with HTTPS and confirm that no redirection happens.
  $this
    ->drupalGet('', array(
    'https' => TRUE,
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl(url('', array(
    'https' => TRUE,
    'absolute' => TRUE,
  )));
  $this
    ->drupalGet('node', array(
    'https' => TRUE,
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl(url('node', array(
    'https' => TRUE,
    'absolute' => TRUE,
  )));

  // Enable "Switch back to http pages when there are no matches".
  variable_set('securepages_switch', TRUE);

  // Visit the home page and /node with HTTPS and confirm that switch-back happens.
  $this
    ->drupalGet('', array(
    'https' => TRUE,
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl(url('', array(
    'https' => FALSE,
    'absolute' => TRUE,
  )));
  $this
    ->drupalGet('node', array(
    'https' => TRUE,
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl(url('', array(
    'https' => FALSE,
    'absolute' => TRUE,
  )));

  // Clean up
  variable_del('securepages_pages');
}