You are here

public function CoffeeTest::testCoffeeCacheTagsInvalidation in Coffee 8

Tests coffee configuration cache tags invalidation.

File

tests/src/Functional/CoffeeTest.php, line 92

Class

CoffeeTest
Tests Coffee module functionality.

Namespace

Drupal\Tests\coffee\Functional

Code

public function testCoffeeCacheTagsInvalidation() {
  $coffee_cache_tag = 'config:coffee.configuration';

  // Coffee is not loaded for users without the adequate permission,
  // so no cache tags for coffee configuration are added.
  $this
    ->drupalGet('');
  $this
    ->assertSession()
    ->responseHeaderNotContains('X-Drupal-Cache-Tags', $coffee_cache_tag);

  // Make sure that the coffee configuration cache tags are present
  // for users with the adequate permission.
  $this
    ->drupalLogin($this->coffeeUser);
  $this
    ->drupalGet('');
  $this
    ->assertSession()
    ->responseHeaderContains('X-Drupal-Cache-Tags', $coffee_cache_tag);
  $settings = $this
    ->getDrupalSettings();
  $this
    ->assertEquals(7, $settings['coffee']['maxResults']);

  // Trigger a config save which should clear the page cache, so we should get
  // the fresh configuration settings.
  $max_results = 10;
  $this
    ->config('coffee.configuration')
    ->set('max_results', $max_results)
    ->save();
  $this
    ->drupalGet('');
  $this
    ->assertSession()
    ->responseHeaderContains('X-Drupal-Cache-Tags', $coffee_cache_tag);
  $settings = $this
    ->getDrupalSettings();
  $this
    ->assertEquals($max_results, $settings['coffee']['maxResults']);
}