function VariationCacheTest::assertCacheBackendItem

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

Asserts that an item was properly stored in the cache backend.

Parameters

string $cid: The cache ID that should have been used.

mixed $data: The data that should have been stored.

\Drupal\Core\Cache\CacheableMetadata|null $cacheability: (optional) The cacheability that should have been used. Does not apply when checking for cache redirects.

4 calls to VariationCacheTest::assertCacheBackendItem()
VariationCacheTest::testNestedVariations in core/tests/Drupal/Tests/Core/Cache/VariationCacheTest.php
Tests a cache item that has nested variations.
VariationCacheTest::testNestedVariationsSelfHealing in core/tests/Drupal/Tests/Core/Cache/VariationCacheTest.php
Tests a cache item that has nested variations that trigger self-healing.
VariationCacheTest::testSingleVariation in core/tests/Drupal/Tests/Core/Cache/VariationCacheTest.php
Tests a cache item that only ever varies by one context.
VariationCacheTest::testSplitVariationsSelfHealing in core/tests/Drupal/Tests/Core/Cache/VariationCacheTest.php
Tests self-healing for a cache item that has split variations.

File

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

Class

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

Namespace

Drupal\Tests\Core\Cache

Code

protected function assertCacheBackendItem(string $cid, $data, ?CacheableMetadata $cacheability = NULL) {
    $cache_backend_item = $this->memoryBackend
        ->get($cid);
    $this->assertNotFalse($cache_backend_item, 'The data was stored and retrieved successfully.');
    $this->assertEquals($data, $cache_backend_item->data, 'Cache item contains the right data.');
    if ($data instanceof CacheRedirect) {
        $this->assertSame([], $cache_backend_item->tags, 'A cache redirect does not use cache tags.');
        $this->assertSame(-1, $cache_backend_item->expire, 'A cache redirect is stored indefinitely.');
    }
    else {
        $this->assertSame($cacheability->getCacheTags(), $cache_backend_item->tags, 'Cache item uses the right cache tags.');
    }
}

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