function SecurePagesTestCase::_testRoles in Secure Pages 8
Same name and namespace in other branches
- 6.2 securepages.test \SecurePagesTestCase::_testRoles()
- 6 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 312 - Provides SimpleTests for Secure Pages module.
Class
- SecurePagesTestCase
- @file Provides SimpleTests for Secure Pages module.
Code
function _testRoles() {
// Undo the setUp() function.
variable_del('securepages');
// 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($role);
$this
->loginHTTPS($this->web_user);
$edit = array(
'securepages_enable' => 1,
'securepages_switch' => 1,
"securepages_roles[{$role}]" => 1,
);
$this
->drupalPost('admin/config/system/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(url('', array(
'https' => TRUE,
'absolute' => TRUE,
)));
$this
->drupalGet('node', array(
'https' => FALSE,
));
$this
->assertResponse(200);
$this
->assertUrl(url('', array(
'https' => TRUE,
'absolute' => TRUE,
)));
// Test that forms actions aren't switched back to http.
$node = $this
->drupalCreateNode(array(
'type' => 'article',
'promote' => 1,
));
$this
->drupalGet('node/' . $node->nid, array(
'https' => TRUE,
));
$this
->assertFieldByXPath('//form[@class="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();
}