You are here

public function CspTest::testSetMultiple in Content-Security-Policy 8

Test that a directive is overridden when set with a new value.

@covers ::setDirective @covers ::isValidDirectiveName @covers ::getHeaderValue

File

tests/src/Unit/CspTest.php, line 174

Class

CspTest
Test manipulating directives in a policy.

Namespace

Drupal\Tests\csp\Unit

Code

public function testSetMultiple() {
  $policy = new Csp();
  $policy
    ->setDirective('default-src', Csp::POLICY_ANY);
  $policy
    ->setDirective('default-src', [
    Csp::POLICY_SELF,
    'one.example.com',
  ]);
  $policy
    ->setDirective('script-src', Csp::POLICY_SELF . ' two.example.com');
  $policy
    ->setDirective('upgrade-insecure-requests', TRUE);
  $policy
    ->setDirective('report-uri', 'example.com/report-uri');
  $this
    ->assertEquals("upgrade-insecure-requests; default-src 'self' one.example.com; script-src 'self' two.example.com; report-uri example.com/report-uri", $policy
    ->getHeaderValue());
}