You are here

public function Ie9CspSubscriberTest::testPreprocessEnabled in Content-Security-Policy 8

Test that style directive are not modified if CSS preprocessing is enabled.

@covers ::onCspPolicyAlter

File

tests/src/Unit/EventSubscriber/Ie9CspSubscriberTest.php, line 135

Class

Ie9CspSubscriberTest
@coversDefaultClass \Drupal\csp\EventSubscriber\Ie9CspSubscriber @group csp

Namespace

Drupal\Tests\csp\Unit\EventSubscriber

Code

public function testPreprocessEnabled() {
  $this->moduleHandler
    ->method('moduleExists')
    ->willReturn($this
    ->callback(function ($parameter) {
    return $parameter === 'ie9';
  }));

  /** @var \Drupal\Core\Config\ConfigFactoryInterface|\PHPUnit_Framework_MockObject_MockObject $configFactory */
  $configFactory = $this
    ->getConfigFactoryStub([
    'system.performance' => [
      'css.preprocess' => TRUE,
    ],
  ]);
  $policy = new Csp();
  $policy
    ->setDirective('default-src', [
    Csp::POLICY_ANY,
  ]);
  $policy
    ->setDirective('style-src', [
    Csp::POLICY_SELF,
  ]);
  $policy
    ->setDirective('style-src-attr', [
    Csp::POLICY_SELF,
  ]);
  $policy
    ->setDirective('style-src-elem', [
    Csp::POLICY_SELF,
  ]);
  $alterEvent = new PolicyAlterEvent($policy, $this->response);
  $subscriber = new Ie9CspSubscriber($configFactory, $this->moduleHandler);
  $subscriber
    ->onCspPolicyAlter($alterEvent);
  $this
    ->assertEquals([
    Csp::POLICY_SELF,
  ], $alterEvent
    ->getPolicy()
    ->getDirective('style-src'));
  $this
    ->assertEquals([
    Csp::POLICY_SELF,
  ], $alterEvent
    ->getPolicy()
    ->getDirective('style-src-attr'));
  $this
    ->assertEquals([
    Csp::POLICY_SELF,
  ], $alterEvent
    ->getPolicy()
    ->getDirective('style-src-elem'));
}