You are here

public function ProductVariationFieldInjectionTest::testStoreCacheContext in Commerce Core 8.2

Tests caching of injected fields.

File

modules/product/tests/src/Functional/ProductVariationFieldInjectionTest.php, line 158

Class

ProductVariationFieldInjectionTest
Tests the product variation field display injection.

Namespace

Drupal\Tests\commerce_product\Functional

Code

public function testStoreCacheContext() {
  $this
    ->drupalGet($this->product
    ->toUrl());
  $this
    ->assertSession()
    ->responseHeaderContains('X-Drupal-Cache-Contexts', 'store');
  $this
    ->assertSession()
    ->responseHeaderContains('X-Drupal-Dynamic-Cache', 'MISS');
  $this
    ->drupalGet($this->product
    ->toUrl());
  $this
    ->assertSession()
    ->responseHeaderContains('X-Drupal-Dynamic-Cache', 'HIT');

  // Change the default store which will change the cache context.
  $this
    ->assertFalse($this->stores[0]
    ->isDefault());
  $this->stores[0]
    ->setDefault(TRUE);
  $this->stores[0]
    ->save();
  $this
    ->drupalGet($this->product
    ->toUrl());
  $this
    ->assertSession()
    ->responseHeaderContains('X-Drupal-Dynamic-Cache', 'MISS');
}