function SecurepagesTest::_testRoles in Secure Pages 8
Test role-based switching.
1 call to SecurepagesTest::_testRoles()
- SecurepagesTest::testSecurePages in src/
Tests/ SecurepagesTest.php - Runs all the tests in a sequence to avoid multiple re-installs.
File
- src/
Tests/ SecurepagesTest.php, line 306 - Contains \Drupal\securepages\Tests\SecurepagesTest.
Class
- SecurepagesTest
- Test Secure Pages redirects.
Namespace
Drupal\securepages\TestsCode
function _testRoles() {
$account = $this
->drupalCreateUser([
'access content',
]);
$role = current($account
->getRoles(TRUE));
$this
->drupalLoginHttps($account);
$config = \Drupal::configFactory()
->getEditable('securepages.settings');
$config
->set('switch', TRUE)
->set('roles', [
$role,
])
->set('pages', [
'/admin*',
])
->save();
// Visit the home page and /user with HTTPS and confirm that redirection happens.
$this
->drupalGet('', [
'https' => FALSE,
]);
$this
->assertResponse(200);
$this
->assertUrl(Url::fromRoute('<front>', [], [
'https' => TRUE,
'absolute' => TRUE,
]));
$this
->drupalGet('user', [
'https' => FALSE,
]);
$this
->assertResponse(200);
$this
->assertUrl(Url::fromRoute('user.page', [], [
'https' => TRUE,
'absolute' => TRUE,
]));
// Test that forms actions aren't switched back to http.
$node = $this
->drupalCreateNode([
'type' => 'article',
'promote' => 1,
]);
$this
->drupalGet('node/' . $node
->id(), [
'https' => TRUE,
]);
$this
->assertFieldByXPath('//form[@class="comment-form" and starts-with(@action, "/")]', NULL, "The comment form action is https.");
// Clean up.
$config
->set('switch', FALSE)
->set('roles', [])
->set('pages', $this->pages_default)
->save();
$this
->drupalLogout();
}