CacheableResponseSubscriberTest.php in Akamai 8.3
File
tests/src/Kernel/EventSubscriber/CacheableResponseSubscriberTest.php
View source
<?php
namespace Drupal\Tests\akamai\Kernel\EventSubscriber;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
use Drupal\akamai\Event\AkamaiHeaderEvents;
class CacheableResponseSubscriberTest extends KernelTestBase {
public static $modules = [
'system',
'akamai',
];
protected function setUp() {
parent::setUp();
$this
->installConfig([
'akamai',
]);
}
public function testHeaderValue() {
$request = Request::create('/system/401');
$config = $this
->config('akamai.settings');
$kernel = \Drupal::getContainer()
->get('http_kernel');
$response = $kernel
->handle($request);
$this
->assertEqual(200, $response
->getStatusCode());
$this
->assertEqual($response->headers
->has('Edge-Cache-Tag'), FALSE);
$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');
$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');
$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');
}
}