You are here

public function ResponseCspSubscriberTest::testEmptyDirective in Content-Security-Policy 8

An empty or missing directive list should not output a header.

@covers ::onKernelResponse

File

tests/src/Unit/EventSubscriber/ResponseCspSubscriberTest.php, line 178

Class

ResponseCspSubscriberTest
@coversDefaultClass \Drupal\csp\EventSubscriber\ResponseCspSubscriber @group csp

Namespace

Drupal\Tests\csp\Unit\EventSubscriber

Code

public function testEmptyDirective() {

  /** @var \Drupal\Core\Config\ConfigFactoryInterface|\PHPUnit_Framework_MockObject_MockObject $configFactory */
  $configFactory = $this
    ->getConfigFactoryStub([
    'system.performance' => [
      'css.preprocess' => FALSE,
    ],
    'csp.settings' => [
      'report-only' => [
        'enable' => TRUE,
        'directives' => [],
      ],
      'enforce' => [
        'enable' => TRUE,
      ],
    ],
  ]);
  $subscriber = new ResponseCspSubscriber($configFactory, $this->libraryPolicy, $this->reportingHandlerPluginManager, $this->eventDispatcher);
  $this->response->headers
    ->expects($this
    ->never())
    ->method('set');
  $this->response
    ->getCacheableMetadata()
    ->expects($this
    ->once())
    ->method('addCacheTags')
    ->with([
    'config:csp.settings',
  ]);
  $subscriber
    ->onKernelResponse($this->event);
}