You are here

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

Test that setting an empty value removes a directive.

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

File

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

Class

CspTest
Test manipulating directives in a policy.

Namespace

Drupal\Tests\csp\Unit

Code

public function testSetEmpty() {
  $policy = new Csp();
  $policy
    ->setDirective('default-src', Csp::POLICY_SELF);
  $policy
    ->setDirective('script-src', [
    Csp::POLICY_SELF,
  ]);
  $policy
    ->setDirective('script-src', []);
  $this
    ->assertEquals("default-src 'self'", $policy
    ->getHeaderValue());
  $policy = new Csp();
  $policy
    ->setDirective('default-src', Csp::POLICY_SELF);
  $policy
    ->setDirective('script-src', [
    Csp::POLICY_SELF,
  ]);
  $policy
    ->setDirective('script-src', '');
  $this
    ->assertEquals("default-src 'self'", $policy
    ->getHeaderValue());
}