function SecurepagesTest::_testPathAlias in Secure Pages 8
Test redirection on aliased paths.
1 call to SecurepagesTest::_testPathAlias()
- 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 236 - Contains \Drupal\securepages\Tests\SecurepagesTest.
Class
- SecurepagesTest
- Test Secure Pages redirects.
Namespace
Drupal\securepages\TestsCode
function _testPathAlias() {
$config = \Drupal::configFactory()
->getEditable('securepages.settings');
$config
->set('pages', [
'/node/*',
'/user*',
])
->save();
// Create test user and login.
$this
->drupalLogin($this
->drupalCreateUser([
'administer url aliases',
'create url aliases',
]));
// Create test node.
$node = $this
->drupalCreateNode();
// Create alias.
$edit = [];
$edit['source'] = 'node/' . $node
->id();
$edit['alias'] = $this
->randomMachineName();
$this
->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));
// Short-circuit redirects within the simpletest browser.
$maximum_redirects = $this->maximumRedirects;
$this->maximumRedirects = 0;
$this
->drupalGet($edit['alias'], [
'absolute' => TRUE,
'https' => FALSE,
]);
$this
->assertResponse(302);
$this
->assertEqual($this
->drupalGetHeader('Location'), Url::fromRoute('<front>', [], [
'https' => TRUE,
'absolute' => TRUE,
])
->toString() . $edit['alias']);
// Clean up.
$this->maximumRedirects = $maximum_redirects;
$this
->drupalLogout();
$config
->set('pages', $this->pages_default)
->save();
}