function SecurePagesTestCase::_testRoles in Secure Pages 6
Same name and namespace in other branches
- 8 securepages.test \SecurePagesTestCase::_testRoles()
 - 6.2 securepages.test \SecurePagesTestCase::_testRoles()
 - 7 securepages.test \SecurePagesTestCase::_testRoles()
 
Test role-based switching.
1 call to SecurePagesTestCase::_testRoles()
- 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 258  - Provides SimpleTests for Secure Pages module.
 
Class
- SecurePagesTestCase
 - @file Provides SimpleTests for Secure Pages module.
 
Code
function _testRoles() {
  // Enable securepages.
  $this->web_user = $this
    ->drupalCreateUser(array(
    'administer site configuration',
    'access administration pages',
    'access comments',
    'post comments',
  ));
  // Extract the role that was just generated.
  $role = $this->web_user->roles;
  unset($role[DRUPAL_AUTHENTICATED_RID]);
  $role = current(array_keys($role));
  $this
    ->loginHTTPS($this->web_user);
  $edit = array(
    'securepages_enable' => 1,
    'securepages_switch' => 1,
    "securepages_roles[{$role}]" => 1,
  );
  $this
    ->drupalPost('admin/build/securepages', $edit, t('Save configuration'), array(
    'https' => TRUE,
  ));
  $this
    ->assertRaw(t('The configuration options have been saved.'));
  // Visit the home page and /node with HTTPS and confirm that redirection happens.
  $this
    ->drupalGet('', array(
    'https' => FALSE,
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl($this
    ->_toHTTPS(url('', array(
    'absolute' => TRUE,
  ))));
  $this
    ->drupalGet($this
    ->_toHTTP(url('node')));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl($this
    ->_toHTTPS(url('', array(
    'absolute' => TRUE,
  ))));
  // Test that forms actions aren't switched back to http.
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'story',
    'promote' => 1,
  ));
  $this
    ->drupalGet($this
    ->_toHTTPS(url('node/' . $node->nid, array(
    'absolute' => TRUE,
  ))));
  $this
    ->assertFieldByXPath('//form[@id="comment-form" and starts-with(@action, "/")]', NULL, "The comment form action is https.");
  // Clean up
  variable_del('securepages_switch');
  variable_del('securepages_roles');
  $this
    ->drupalLogout();
}