You are here

function SecurepagesTest::_testMatch in Secure Pages 8

Tests the securepages_match() function.

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

Class

SecurepagesTest
Test Secure Pages redirects.

Namespace

Drupal\securepages\Tests

Code

function _testMatch() {
  \Drupal::configFactory()
    ->getEditable('securepages.settings')
    ->set('ignore', [
    '*/autocomplete/*',
  ])
    ->save();
  $request = \Drupal::requestStack()
    ->getCurrentRequest();
  $test_request_is_https = $request
    ->isSecure();
  $this
    ->assertEqual(Securepages::matchPath('/user'), !$test_request_is_https, 'user matches.');
  $this
    ->assertEqual(Securepages::matchPath('/user/login'), !$test_request_is_https, 'user/login matches.');
  $this
    ->assertEqual(Securepages::matchPath('/admin/modules'), !$test_request_is_https, 'path admin/modules matches.');
  $this
    ->assertEqual(Securepages::matchPath('/node'), $test_request_is_https, 'path node does not match.');
  $request = \Drupal::requestStack()
    ->getCurrentRequest();
  $this
    ->assertEqual(Securepages::matchPath('/user/autocomplete/alice'), $test_request_is_https, 'autocomplete path is ignored.');

  // Clean up.
  \Drupal::configFactory()
    ->getEditable('securepages.settings')
    ->set('ignore', [])
    ->save();
}