function CacheableMetadataTest::providerTestMerge

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php \Drupal\Tests\Core\Cache\CacheableMetadataTest::providerTestMerge()
  2. 10 core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php \Drupal\Tests\Core\Cache\CacheableMetadataTest::providerTestMerge()
  3. 11.x core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php \Drupal\Tests\Core\Cache\CacheableMetadataTest::providerTestMerge()

Provides test data for testMerge().

Return value

array

File

core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php, line 69

Class

CacheableMetadataTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Cache%21CacheableMetadata.php/class/CacheableMetadata/8.9.x" title="Defines a generic class for passing cacheability metadata." class="local">\Drupal\Core\Cache\CacheableMetadata</a> @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function providerTestMerge() {
    return [
        // All empty.
[
            new CacheableMetadata(),
            new CacheableMetadata(),
            new CacheableMetadata(),
        ],
        // Cache contexts.
[
            (new CacheableMetadata())->setCacheContexts([
                'foo',
            ]),
            (new CacheableMetadata())->setCacheContexts([
                'bar',
            ]),
            (new CacheableMetadata())->setCacheContexts([
                'bar',
                'foo',
            ]),
        ],
        // Cache tags.
[
            (new CacheableMetadata())->setCacheTags([
                'foo',
            ]),
            (new CacheableMetadata())->setCacheTags([
                'bar',
            ]),
            (new CacheableMetadata())->setCacheTags([
                'bar',
                'foo',
            ]),
        ],
        // Cache max-ages.
[
            (new CacheableMetadata())->setCacheMaxAge(60),
            (new CacheableMetadata())->setCacheMaxAge(Cache::PERMANENT),
            (new CacheableMetadata())->setCacheMaxAge(60),
        ],
    ];
}

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