You are here

public function WebformBlockCacheTest::testAuthenticatedAndRestrictedVisitIsCacheable in Webform 8.5

Same name and namespace in other branches
  1. 6.x tests/src/Functional/WebformBlockCacheTest.php \Drupal\Tests\webform\Functional\WebformBlockCacheTest::testAuthenticatedAndRestrictedVisitIsCacheable()

Test that if an Webform is access restricted the page can still be cached.

File

tests/src/Functional/WebformBlockCacheTest.php, line 79

Class

WebformBlockCacheTest
These tests proof that the webform block which renders the webform as a block provides the correct cache tags / cache contexts so that cachability works.

Namespace

Drupal\Tests\webform\Functional

Code

public function testAuthenticatedAndRestrictedVisitIsCacheable() {

  /** @var \Drupal\webform\WebformAccessRulesManagerInterface $access_rules_manager */
  $access_rules_manager = \Drupal::service('webform.access_rules_manager');
  $default_access_rules = $access_rules_manager
    ->getDefaultAccessRules();
  $access_rules = [
    'create' => [
      'roles' => [],
      'users' => [],
      'permissions' => [
        'access content',
      ],
    ],
  ] + $default_access_rules;
  Webform::load('contact')
    ->setAccessRules($access_rules)
    ->save();
  $this
    ->drupalLogin($this->authenticatedUser);
  $this
    ->drupalGet('/node/1');
  $this
    ->assertSession()
    ->responseContains('Contact');
  $this
    ->assertEquals('MISS', $this
    ->drupalGetHeader('X-Drupal-Dynamic-Cache'));
  $this
    ->drupalGet('/node/1');
  $this
    ->assertEquals('HIT', $this
    ->drupalGetHeader('X-Drupal-Dynamic-Cache'));
}