public function CspSubscriberTest::testConnectFallback in Googalytics - Google Analytics 8
Test connect-src fallback if default-src enabled.
@covers ::onCspPolicyAlter
File
- tests/
src/ Unit/ EventSubscriber/ CspSubscriberTest.php, line 129
Class
- CspSubscriberTest
- Test for Content Security Policy event integration.
Namespace
Drupal\Tests\ga\Unit\EventSubscriberCode
public function testConnectFallback() {
$policy = new Csp();
$policy
->setDirective('default-src', [
Csp::POLICY_SELF,
]);
$alterEvent = new PolicyAlterEvent($policy, $this->response);
$subscriber = new CspSubscriber();
$subscriber
->onCspPolicyAlter($alterEvent);
$this
->assertArrayEquals([
Csp::POLICY_SELF,
], $alterEvent
->getPolicy()
->getDirective('default-src'));
$this
->assertArrayEquals([
Csp::POLICY_SELF,
CspSubscriber::TRACKING_DOMAIN,
], $alterEvent
->getPolicy()
->getDirective('connect-src'));
}