You are here

public function CoreCspSubscriberTest::testUmamiFont in Content-Security-Policy 8

Test that including umami modifies enabled font directive.

@covers ::onCspPolicyAlter

File

tests/src/Unit/EventSubscriber/CoreCspSubscriberTest.php, line 342

Class

CoreCspSubscriberTest
@coversDefaultClass \Drupal\csp\EventSubscriber\CoreCspSubscriber @group csp

Namespace

Drupal\Tests\csp\Unit\EventSubscriber

Code

public function testUmamiFont() {
  $policy = new Csp();
  $policy
    ->setDirective('default-src', [
    Csp::POLICY_ANY,
  ]);
  $policy
    ->setDirective('font-src', []);
  $this->response
    ->method('getAttachments')
    ->willReturn([
    'library' => [
      'umami/webfonts',
    ],
  ]);
  $alterEvent = new PolicyAlterEvent($policy, $this->response);
  $this->coreCspSubscriber
    ->onCspPolicyAlter($alterEvent);
  $this
    ->assertEquals([
    'https://fonts.gstatic.com',
  ], $alterEvent
    ->getPolicy()
    ->getDirective('font-src'));
}