You are here

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

Test setting a single value to a directive.

@covers ::setDirective @covers ::hasDirective @covers ::getDirective @covers ::isValidDirectiveName @covers ::validateDirectiveName @covers ::getHeaderValue

File

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

Class

CspTest
Test manipulating directives in a policy.

Namespace

Drupal\Tests\csp\Unit

Code

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