You are here

function SecurepagesTest::_testPathNorms in Secure Pages 8

Test path normalization checks.

1 call to SecurepagesTest::_testPathNorms()
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 335
Contains \Drupal\securepages\Tests\SecurepagesTest.

Class

SecurepagesTest
Test Secure Pages redirects.

Namespace

Drupal\securepages\Tests

Code

function _testPathNorms() {
  $config = \Drupal::configFactory()
    ->getEditable('securepages.settings');
  $config
    ->set('switch', TRUE)
    ->set('pages', [
    '/user',
  ])
    ->save();

  // Test mixed-case path.
  $this
    ->drupalGet('UsEr');
  $this
    ->assertUrl('UsEr', [
    'https' => TRUE,
    'absolute' => TRUE,
  ]);
  $this
    ->assertFieldByXPath('//form[@id="user-login" and starts-with(@action, "/")]', NULL, 'The user login form action is https.');

  // Test that a trailing slash will not force a protected form's action to
  // http. A http based 'user/' path will become 'user' when doing the
  // redirect, so best to ensure that the test gets the right conditions the
  // path should be https based.
  $this
    ->drupalGet('user/', [
    'https' => TRUE,
    'absolute' => TRUE,
  ]);
  $this
    ->assertUrl('user/', [
    'https' => TRUE,
    'absolute' => TRUE,
  ]);
  $this
    ->assertFieldByXPath('//form[@id="user-login" and starts-with(@action, "/")]', NULL, 'The user login form action is https.');

  // Clean up.
  $config
    ->set('switch', FALSe)
    ->set('pages', $this->pages_default)
    ->save();
}