You are here

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

Test style-src-elem fallback if default-src enabled.

@covers ::onCspPolicyAlter

File

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

Class

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

Namespace

Drupal\Tests\csp\Unit\EventSubscriber

Code

public function testCkeditorStyleDefaultFallback() {
  $policy = new Csp();
  $policy
    ->setDirective('default-src', [
    Csp::POLICY_SELF,
  ]);
  $this->response
    ->method('getAttachments')
    ->willReturn([
    'library' => [
      'ckeditor/drupal.ckeditor',
    ],
  ]);
  $alterEvent = new PolicyAlterEvent($policy, $this->response);
  $this->coreCspSubscriber
    ->onCspPolicyAlter($alterEvent);
  $this
    ->assertEquals([
    Csp::POLICY_SELF,
    Csp::POLICY_UNSAFE_INLINE,
  ], $alterEvent
    ->getPolicy()
    ->getDirective('style-src'));
  $this
    ->assertEquals([
    Csp::POLICY_SELF,
    Csp::POLICY_UNSAFE_INLINE,
  ], array_unique($alterEvent
    ->getPolicy()
    ->getDirective('style-src-attr')));
  $this
    ->assertEquals([
    Csp::POLICY_SELF,
    Csp::POLICY_UNSAFE_INLINE,
  ], array_unique($alterEvent
    ->getPolicy()
    ->getDirective('style-src-elem')));
}