You are here

public function CacheTest::testDynamicPageCache in Field Encryption 3.0.x

Test caching of encrypted fields on response level.

File

tests/src/Functional/CacheTest.php, line 47

Class

CacheTest
Tests field encryption caching.

Namespace

Drupal\Tests\field_encrypt\Functional

Code

public function testDynamicPageCache() {

  // Page should be uncacheable due to max-age = 0.
  $this
    ->drupalGet('node/' . $this->testNode
    ->id());
  $this
    ->assertEquals('UNCACHEABLE', $this
    ->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Page with encrypted fields is uncacheable.');

  // Set encrypted field as cacheable.
  $this
    ->drupalGet('admin/config/system/field-encrypt');
  $this
    ->submitForm([
    'make_entities_uncacheable' => FALSE,
  ], 'Save configuration');

  // Page is cacheable, but currently not cached.
  $this
    ->drupalGet('node/' . $this->testNode
    ->id());
  $this
    ->assertEquals('MISS', $this
    ->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Dynamic Page Cache MISS.');

  // Page is cacheable, and should be cached.
  $this
    ->drupalGet('node/' . $this->testNode
    ->id());
  $this
    ->assertEquals('HIT', $this
    ->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Dynamic Page Cache HIT.');
}