function VariationCacheTest::testSingleVariation

Same name in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Cache/VariationCacheTest.php \Drupal\Tests\Core\Cache\VariationCacheTest::testSingleVariation()

Tests a cache item that only ever varies by one context.

@covers ::get @covers ::set

File

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

Class

VariationCacheTest
@coversDefaultClass \Drupal\Core\Cache\VariationCache @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function testSingleVariation() : void {
    $cacheability = $this->housingTypeCacheability;
    $house_data = [
        'apartment' => 'You have a nice apartment',
        'house' => 'You have a nice house',
    ];
    foreach ($house_data as $housing_type => $data) {
        $this->housingType = $housing_type;
        $this->assertVariationCacheMiss($cacheability);
        $this->setVariationCacheItem($data, $cacheability, $cacheability);
        $this->assertVariationCacheItem($data, $cacheability, $cacheability);
        $this->assertCacheBackendItem("{$this->cacheIdBase}:ht.{$housing_type}", $data, $cacheability);
    }
}

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