You are here

public function CacheableResponseSubscriberTest::testHeaderValue in Akamai 8.3

Test that the header value is exactly as expected (space separated).

File

tests/src/Kernel/EventSubscriber/CacheableResponseSubscriberTest.php, line 34

Class

CacheableResponseSubscriberTest
Tests CacheableResponseSubscriber.

Namespace

Drupal\Tests\akamai\Kernel\EventSubscriber

Code

public function testHeaderValue() {
  $request = Request::create('/system/401');
  $config = $this
    ->config('akamai.settings');

  /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $kernel */
  $kernel = \Drupal::getContainer()
    ->get('http_kernel');
  $response = $kernel
    ->handle($request);

  // Verify header is not available by default.
  $this
    ->assertEqual(200, $response
    ->getStatusCode());
  $this
    ->assertEqual($response->headers
    ->has('Edge-Cache-Tag'), FALSE);

  // Verify header is available when enabled.
  $config
    ->set('edge_cache_tag_header', TRUE)
    ->save();
  $response = $kernel
    ->handle($request);
  $this
    ->assertEqual(200, $response
    ->getStatusCode());
  $this
    ->assertEqual($response->headers
    ->has('Edge-Cache-Tag'), TRUE);
  $this
    ->assertEqual($response->headers
    ->get('Edge-Cache-Tag'), 'config_user.role.anonymous,http_response,rendered');

  // Verify tag blacklisting.
  $config
    ->set('edge_cache_tag_header_blacklist', [
    'config:',
  ])
    ->save();
  $response = $kernel
    ->handle($request);
  $this
    ->assertEqual(200, $response
    ->getStatusCode());
  $this
    ->assertEqual($response->headers
    ->has('Edge-Cache-Tag'), TRUE);
  $this
    ->assertEqual($response->headers
    ->get('Edge-Cache-Tag'), 'http_response,rendered');

  // Setup the mock event subscriber.
  $subscriber = new MockSubscriber();
  $event_dispatcher = \Drupal::getContainer()
    ->get('event_dispatcher');
  $event_dispatcher
    ->addListener(AkamaiHeaderEvents::HEADER_CREATION, [
    $subscriber,
    'onHeaderCreation',
  ]);
  $response = $kernel
    ->handle($request);
  $this
    ->assertEqual(200, $response
    ->getStatusCode());
  $this
    ->assertEqual($response->headers
    ->has('Edge-Cache-Tag'), TRUE);
  $this
    ->assertEqual($response->headers
    ->get('Edge-Cache-Tag'), 'http_response,rendered,on_header_creation');
}