function VariationCacheTest::testIncompatibleChainedRedirectsException

Same name and namespace in other branches
  1. main core/tests/Drupal/Tests/Core/Cache/VariationCacheTest.php \Drupal\Tests\Core\Cache\VariationCacheTest::testIncompatibleChainedRedirectsException()

Tests the same as above, but with more redirects.

@legacy-covers ::get @legacy-covers ::set

Attributes

#[Depends('testIncompatibleRedirectsException')]

File

core/tests/Drupal/Tests/Core/Cache/VariationCacheTest.php, line 519

Class

VariationCacheTest
Tests Drupal\Core\Cache\VariationCache.

Namespace

Drupal\Tests\Core\Cache

Code

public function testIncompatibleChainedRedirectsException() : void {
  // @todo Remove in Drupal 12.0.0. For more information, see:
  //   https://www.drupal.org/project/drupal/issues/3468921
  set_error_handler(static function (int $errno, string $errstr) : never {
    throw new \LogicException($errstr, $errno);
  }, E_USER_WARNING);
  $this->expectException(\LogicException::class);
  $this->expectExceptionMessageIs('Trying to overwrite a cache redirect for "your:housing:situation:gt.garden:ht.house" with one that has nothing in common, old one at address "house.type, garden.type" was pointing to "house.orientation", new one points to "solar.type".');
  $this->housingType = 'house';
  $house_cacheability = (new CacheableMetadata())->setCacheContexts([
    'house.type',
  ]);
  $this->gardenType = 'no-garden';
  $garden_cacheability = (new CacheableMetadata())->setCacheContexts([
    'house.type',
    'garden.type',
  ]);
  // This should set a redirect at ht.house specifying garden.type. So the
  // redirects below should find this redirect to be fine before getting to
  // the problematic one.
  $this->setVariationCacheItem('You have a nice house with no garden!', $garden_cacheability, $house_cacheability);
  $this->gardenType = 'garden';
  $this->houseOrientation = 'north';
  $orientation_cacheability = (new CacheableMetadata())->setCacheContexts([
    'house.type',
    'garden.type',
    'house.orientation',
  ]);
  $this->solarType = 'solar';
  $solar_cacheability = (new CacheableMetadata())->setCacheContexts([
    'house.type',
    'garden.type',
    'solar.type',
  ]);
  $this->setVariationCacheItem('You have a nice north-facing house with a garden!', $orientation_cacheability, $house_cacheability);
  try {
    $this->setVariationCacheItem('You have a nice house with solar panels and a garden!', $solar_cacheability, $house_cacheability);
  } finally {
    restore_error_handler();
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.