public function CoreCspSubscriberTest::testCkeditorStyleElemFallback in Content-Security-Policy 8
Test style-src-elem fallback if style-src enabled.
@covers ::onCspPolicyAlter
File
- tests/
src/ Unit/ EventSubscriber/ CoreCspSubscriberTest.php, line 273
Class
- CoreCspSubscriberTest
- @coversDefaultClass \Drupal\csp\EventSubscriber\CoreCspSubscriber @group csp
Namespace
Drupal\Tests\csp\Unit\EventSubscriberCode
public function testCkeditorStyleElemFallback() {
$policy = new Csp();
$policy
->setDirective('default-src', [
Csp::POLICY_ANY,
]);
$policy
->setDirective('style-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')));
}